cmListFileBacktrace: Remove unused "bottom" entry

All uses of `GetBottom` by clients have been removed, so drop the
method and its supporting infrastructure.
This commit is contained in:
Brad King
2021-12-07 16:26:58 -05:00
parent 56dc22d488
commit 7b677dbb92
4 changed files with 6 additions and 60 deletions

View File

@@ -2183,7 +2183,7 @@ bool cmCTestTestHandler::SetTestsProperties(
// Ensure we have complete triples otherwise the data is corrupt.
if (triples.size() % 3 == 0) {
cmState state(cmState::Unknown);
rt.Backtrace = cmListFileBacktrace(state.CreateBaseSnapshot());
rt.Backtrace = cmListFileBacktrace();
// the first entry represents the top of the trace so we need to
// reconstruct the backtrace in reverse

View File

@@ -443,45 +443,19 @@ cm::optional<cmListFileContext> cmListFileParser::CheckNesting() const
return cm::nullopt;
}
// We hold either the bottom scope of a directory or a call/file context.
// Discriminate these cases via the parent pointer.
// We hold a call/file context.
struct cmListFileBacktrace::Entry
{
Entry(cmStateSnapshot bottom)
: Bottom(bottom)
{
}
Entry(std::shared_ptr<Entry const> parent, cmListFileContext lfc)
: Context(std::move(lfc))
, Parent(std::move(parent))
{
}
~Entry()
{
if (this->Parent) {
this->Context.~cmListFileContext();
} else {
this->Bottom.~cmStateSnapshot();
}
}
bool IsBottom() const { return !this->Parent; }
union
{
cmStateSnapshot Bottom;
cmListFileContext Context;
};
cmListFileContext Context;
std::shared_ptr<Entry const> Parent;
};
cmListFileBacktrace::cmListFileBacktrace(cmStateSnapshot const& snapshot)
: TopEntry(std::make_shared<Entry const>(snapshot.GetCallStackBottom()))
{
}
/* NOLINTNEXTLINE(performance-unnecessary-value-param) */
cmListFileBacktrace::cmListFileBacktrace(std::shared_ptr<Entry const> parent,
cmListFileContext const& lfc)
@@ -494,18 +468,6 @@ cmListFileBacktrace::cmListFileBacktrace(std::shared_ptr<Entry const> top)
{
}
cmStateSnapshot cmListFileBacktrace::GetBottom() const
{
cmStateSnapshot bottom;
if (Entry const* cur = this->TopEntry.get()) {
while (Entry const* parent = cur->Parent.get()) {
cur = parent;
}
bottom = cur->Bottom;
}
return bottom;
}
cmListFileBacktrace cmListFileBacktrace::Push(std::string const& file) const
{
// We are entering a file-level scope but have not yet reached
@@ -520,22 +482,18 @@ cmListFileBacktrace cmListFileBacktrace::Push(std::string const& file) const
cmListFileBacktrace cmListFileBacktrace::Push(
cmListFileContext const& lfc) const
{
assert(this->TopEntry);
assert(!this->TopEntry->IsBottom() || this->TopEntry->Bottom.IsValid());
return cmListFileBacktrace(this->TopEntry, lfc);
}
cmListFileBacktrace cmListFileBacktrace::Pop() const
{
assert(this->TopEntry);
assert(!this->TopEntry->IsBottom());
return cmListFileBacktrace(this->TopEntry->Parent);
}
cmListFileContext const& cmListFileBacktrace::Top() const
{
assert(this->TopEntry);
assert(!this->TopEntry->IsBottom());
return this->TopEntry->Context;
}
@@ -543,7 +501,7 @@ size_t cmListFileBacktrace::Depth() const
{
size_t depth = 0;
if (Entry const* cur = this->TopEntry.get()) {
for (; !cur->IsBottom(); cur = cur->Parent.get()) {
for (; cur; cur = cur->Parent.get()) {
++depth;
}
}
@@ -552,7 +510,7 @@ size_t cmListFileBacktrace::Depth() const
bool cmListFileBacktrace::Empty() const
{
return !this->TopEntry || this->TopEntry->IsBottom();
return !this->TopEntry;
}
std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)

View File

@@ -13,7 +13,6 @@
#include <cm/optional>
#include "cmStateSnapshot.h"
#include "cmSystemTools.h"
/** \class cmListFileCache
@@ -164,23 +163,13 @@ private:
class cmListFileBacktrace
{
public:
// Default-constructed backtrace may not be used until after
// set via assignment from a backtrace constructed with a
// valid snapshot.
// Default-constructed backtrace is empty.
cmListFileBacktrace() = default;
// Construct an empty backtrace whose bottom sits in the directory
// indicated by the given valid snapshot.
cmListFileBacktrace(cmStateSnapshot const& snapshot);
cmStateSnapshot GetBottom() const;
// Get a backtrace with the given file scope added to the top.
// May not be called until after construction with a valid snapshot.
cmListFileBacktrace Push(std::string const& file) const;
// Get a backtrace with the given call context added to the top.
// May not be called until after construction with a valid snapshot.
cmListFileBacktrace Push(cmListFileContext const& lfc) const;
// Get a backtrace with the top level removed.

View File

@@ -79,7 +79,6 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
cmStateSnapshot const& snapshot)
: GlobalGenerator(globalGenerator)
, StateSnapshot(snapshot)
, Backtrace(snapshot)
{
this->IsSourceFileTryCompile = false;