summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-01-26 13:04:52 +0000
committerKitware Robot <kwrobot@kitware.com>2022-01-26 08:05:01 -0500
commitdbfa449f080774fa24eaa5fa2edbee2d32405db3 (patch)
tree7a64268d168d612ed5b9b4158148c313d43465ed
parent8732639b79854427d7695923760440363e1a053e (diff)
parent4959276c02ca5abf5775c608cc35dc8e09a8cc0a (diff)
downloadcmake-dbfa449f080774fa24eaa5fa2edbee2d32405db3.tar.gz
Merge topic 'parser-cleanup'
4959276c02 cmListFileCache: Remove cmCommandContext 0386641142 cmListFileCache: Rename FromCommandContext to FromListFileFunction 3c4fa4c892 cmListFileCache: Move cmListFileFunction earlier Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !6899
-rw-r--r--Source/cmFunctionBlocker.cxx2
-rw-r--r--Source/cmListFileCache.cxx28
-rw-r--r--Source/cmListFileCache.h122
-rw-r--r--Source/cmMakefile.cxx2
4 files changed, 68 insertions, 86 deletions
diff --git a/Source/cmFunctionBlocker.cxx b/Source/cmFunctionBlocker.cxx
index d4666d73fc..40e692d0eb 100644
--- a/Source/cmFunctionBlocker.cxx
+++ b/Source/cmFunctionBlocker.cxx
@@ -27,7 +27,7 @@ bool cmFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
if (!this->ArgumentsMatch(lff, mf)) {
cmListFileContext const& lfc = this->GetStartingContext();
cmListFileContext closingContext =
- cmListFileContext::FromCommandContext(lff, lfc.FilePath);
+ cmListFileContext::FromListFileFunction(lff, lfc.FilePath);
std::ostringstream e;
/* clang-format off */
e << "A logical block opening on the line\n"
diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx
index 9f8a18fc45..3da266deaa 100644
--- a/Source/cmListFileCache.cxx
+++ b/Source/cmListFileCache.cxx
@@ -369,68 +369,68 @@ cm::optional<cmListFileContext> cmListFileParser::CheckNesting() const
if (name == "if") {
stack.push_back({
NestingStateEnum::If,
- cmListFileContext::FromCommandContext(func, this->FileName),
+ cmListFileContext::FromListFileFunction(func, this->FileName),
});
} else if (name == "elseif") {
if (!TopIs(stack, NestingStateEnum::If)) {
- return cmListFileContext::FromCommandContext(func, this->FileName);
+ return cmListFileContext::FromListFileFunction(func, this->FileName);
}
stack.back() = {
NestingStateEnum::If,
- cmListFileContext::FromCommandContext(func, this->FileName),
+ cmListFileContext::FromListFileFunction(func, this->FileName),
};
} else if (name == "else") {
if (!TopIs(stack, NestingStateEnum::If)) {
- return cmListFileContext::FromCommandContext(func, this->FileName);
+ return cmListFileContext::FromListFileFunction(func, this->FileName);
}
stack.back() = {
NestingStateEnum::Else,
- cmListFileContext::FromCommandContext(func, this->FileName),
+ cmListFileContext::FromListFileFunction(func, this->FileName),
};
} else if (name == "endif") {
if (!TopIs(stack, NestingStateEnum::If) &&
!TopIs(stack, NestingStateEnum::Else)) {
- return cmListFileContext::FromCommandContext(func, this->FileName);
+ return cmListFileContext::FromListFileFunction(func, this->FileName);
}
stack.pop_back();
} else if (name == "while") {
stack.push_back({
NestingStateEnum::While,
- cmListFileContext::FromCommandContext(func, this->FileName),
+ cmListFileContext::FromListFileFunction(func, this->FileName),
});
} else if (name == "endwhile") {
if (!TopIs(stack, NestingStateEnum::While)) {
- return cmListFileContext::FromCommandContext(func, this->FileName);
+ return cmListFileContext::FromListFileFunction(func, this->FileName);
}
stack.pop_back();
} else if (name == "foreach") {
stack.push_back({
NestingStateEnum::Foreach,
- cmListFileContext::FromCommandContext(func, this->FileName),
+ cmListFileContext::FromListFileFunction(func, this->FileName),
});
} else if (name == "endforeach") {
if (!TopIs(stack, NestingStateEnum::Foreach)) {
- return cmListFileContext::FromCommandContext(func, this->FileName);
+ return cmListFileContext::FromListFileFunction(func, this->FileName);
}
stack.pop_back();
} else if (name == "function") {
stack.push_back({
NestingStateEnum::Function,
- cmListFileContext::FromCommandContext(func, this->FileName),
+ cmListFileContext::FromListFileFunction(func, this->FileName),
});
} else if (name == "endfunction") {
if (!TopIs(stack, NestingStateEnum::Function)) {
- return cmListFileContext::FromCommandContext(func, this->FileName);
+ return cmListFileContext::FromListFileFunction(func, this->FileName);
}
stack.pop_back();
} else if (name == "macro") {
stack.push_back({
NestingStateEnum::Macro,
- cmListFileContext::FromCommandContext(func, this->FileName),
+ cmListFileContext::FromListFileFunction(func, this->FileName),
});
} else if (name == "endmacro") {
if (!TopIs(stack, NestingStateEnum::Macro)) {
- return cmListFileContext::FromCommandContext(func, this->FileName);
+ return cmListFileContext::FromListFileFunction(func, this->FileName);
}
stack.pop_back();
}
diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h
index 4a52876e1c..5d45027a7b 100644
--- a/Source/cmListFileCache.h
+++ b/Source/cmListFileCache.h
@@ -23,28 +23,6 @@
class cmMessenger;
-struct cmCommandContext
-{
- struct cmCommandName
- {
- std::string Original;
- std::string Lower;
- cmCommandName() = default;
- cmCommandName(std::string name)
- : Original(std::move(name))
- , Lower(cmSystemTools::LowerCase(this->Original))
- {
- }
- } Name;
- long Line = 0;
- cmCommandContext() = default;
- cmCommandContext(std::string name, long line)
- : Name(std::move(name))
- , Line(line)
- {
- }
-};
-
struct cmListFileArgument
{
enum Delimiter
@@ -70,6 +48,54 @@ struct cmListFileArgument
long Line = 0;
};
+class cmListFileFunction
+{
+public:
+ cmListFileFunction(std::string name, long line,
+ std::vector<cmListFileArgument> args)
+ : Impl{ std::make_shared<Implementation>(std::move(name), line,
+ std::move(args)) }
+ {
+ }
+
+ std::string const& OriginalName() const noexcept
+ {
+ return this->Impl->OriginalName;
+ }
+
+ std::string const& LowerCaseName() const noexcept
+ {
+ return this->Impl->LowerCaseName;
+ }
+
+ long Line() const noexcept { return this->Impl->Line; }
+
+ std::vector<cmListFileArgument> const& Arguments() const noexcept
+ {
+ return this->Impl->Arguments;
+ }
+
+private:
+ struct Implementation
+ {
+ Implementation(std::string name, long line,
+ std::vector<cmListFileArgument> args)
+ : OriginalName{ std::move(name) }
+ , LowerCaseName{ cmSystemTools::LowerCase(this->OriginalName) }
+ , Line{ line }
+ , Arguments{ std::move(args) }
+ {
+ }
+
+ std::string OriginalName;
+ std::string LowerCaseName;
+ long Line = 0;
+ std::vector<cmListFileArgument> Arguments;
+ };
+
+ std::shared_ptr<Implementation const> Impl;
+};
+
class cmListFileContext
{
public:
@@ -99,14 +125,14 @@ public:
{
}
- static cmListFileContext FromCommandContext(
- cmCommandContext const& lfcc, std::string const& fileName,
+ static cmListFileContext FromListFileFunction(
+ cmListFileFunction const& lff, std::string const& fileName,
cm::optional<std::string> deferId = {})
{
cmListFileContext lfc;
lfc.FilePath = fileName;
- lfc.Line = lfcc.Line;
- lfc.Name = lfcc.Name.Original;
+ lfc.Line = lff.Line();
+ lfc.Name = lff.OriginalName();
lfc.DeferId = std::move(deferId);
return lfc;
}
@@ -117,50 +143,6 @@ bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs);
bool operator==(cmListFileContext const& lhs, cmListFileContext const& rhs);
bool operator!=(cmListFileContext const& lhs, cmListFileContext const& rhs);
-class cmListFileFunction
-{
-public:
- cmListFileFunction(std::string name, long line,
- std::vector<cmListFileArgument> args)
- : Impl{ std::make_shared<Implementation>(std::move(name), line,
- std::move(args)) }
- {
- }
-
- std::string const& OriginalName() const noexcept
- {
- return this->Impl->Name.Original;
- }
-
- std::string const& LowerCaseName() const noexcept
- {
- return this->Impl->Name.Lower;
- }
-
- long Line() const noexcept { return this->Impl->Line; }
-
- std::vector<cmListFileArgument> const& Arguments() const noexcept
- {
- return this->Impl->Arguments;
- }
-
- operator cmCommandContext const&() const noexcept { return *this->Impl; }
-
-private:
- struct Implementation : public cmCommandContext
- {
- Implementation(std::string name, long line,
- std::vector<cmListFileArgument> args)
- : cmCommandContext{ std::move(name), line }
- , Arguments{ std::move(args) }
- {
- }
- std::vector<cmListFileArgument> Arguments;
- };
-
- std::shared_ptr<Implementation const> Impl;
-};
-
// Represent a backtrace (call stack). Provide value semantics
// but use efficient reference-counting underneath to avoid copies.
class cmListFileBacktrace
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index cc687b1ab8..68e61bb166 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -339,7 +339,7 @@ public:
cm::optional<std::string> deferId, cmExecutionStatus& status)
: Makefile(mf)
{
- cmListFileContext const& lfc = cmListFileContext::FromCommandContext(
+ cmListFileContext const& lfc = cmListFileContext::FromListFileFunction(
lff, this->Makefile->StateSnapshot.GetExecutionListFile(),
std::move(deferId));
this->Makefile->Backtrace = this->Makefile->Backtrace.Push(lfc);