summaryrefslogtreecommitdiffstats
path: root/Source/cmIfCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-09-25 12:52:55 (GMT)
committerBrad King <brad.king@kitware.com>2020-09-28 13:49:08 (GMT)
commitdc49abcb89d7c5a99f7955f16f9b0ccaadc585be (patch)
tree156e6b3cc53472b38ac820f75bd3a5a1c9f5c047 /Source/cmIfCommand.cxx
parent68af831505450a34ddd4bf767844bc3890eb52e5 (diff)
downloadCMake-dc49abcb89d7c5a99f7955f16f9b0ccaadc585be.zip
CMake-dc49abcb89d7c5a99f7955f16f9b0ccaadc585be.tar.gz
CMake-dc49abcb89d7c5a99f7955f16f9b0ccaadc585be.tar.bz2
if,while: Clarify condition backtrace construction
Evaluation of the `elseif`, `else`, and `while` commands takes place during function blocker evaluation before any actual command execution takes place. Therefore they do not have an entry in the backtrace stack. Each of their implementations needs to construct an extra backtrace entry to use in error messages and such. Each of them used a slightly different approach due to evolution over time. Clean up their construction of the extra backtrace entry and use a named variable to contain it for clarity.
Diffstat (limited to 'Source/cmIfCommand.cxx')
-rw-r--r--Source/cmIfCommand.cxx16
1 files changed, 9 insertions, 7 deletions
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx
index 9930a85..557817c 100644
--- a/Source/cmIfCommand.cxx
+++ b/Source/cmIfCommand.cxx
@@ -75,10 +75,12 @@ bool cmIfFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
if (scopeDepth == 0 && func.Name.Lower == "else") {
if (this->ElseSeen) {
- cmListFileBacktrace bt = mf.GetBacktrace(func);
+ cmListFileBacktrace elseBT = mf.GetBacktrace().Push(
+ cmListFileContext{ func.Name.Original,
+ this->GetStartingContext().FilePath, func.Line });
mf.GetCMakeInstance()->IssueMessage(
MessageType::FATAL_ERROR,
- "A duplicate ELSE command was found inside an IF block.", bt);
+ "A duplicate ELSE command was found inside an IF block.", elseBT);
cmSystemTools::SetFatalErrorOccured();
return true;
}
@@ -93,11 +95,12 @@ bool cmIfFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
mf.PrintCommandTrace(func);
}
} else if (scopeDepth == 0 && func.Name.Lower == "elseif") {
+ cmListFileBacktrace elseifBT = mf.GetBacktrace().Push(cmListFileContext{
+ func.Name.Original, this->GetStartingContext().FilePath, func.Line });
if (this->ElseSeen) {
- cmListFileBacktrace bt = mf.GetBacktrace(func);
mf.GetCMakeInstance()->IssueMessage(
MessageType::FATAL_ERROR,
- "An ELSEIF command was found after an ELSE command.", bt);
+ "An ELSEIF command was found after an ELSE command.", elseifBT);
cmSystemTools::SetFatalErrorOccured();
return true;
}
@@ -122,7 +125,7 @@ bool cmIfFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
func, this->GetStartingContext().FilePath);
cmConditionEvaluator conditionEvaluator(mf, conditionContext,
- mf.GetBacktrace(func));
+ elseifBT);
bool isTrue =
conditionEvaluator.IsTrue(expandedArguments, errorString, messType);
@@ -130,8 +133,7 @@ bool cmIfFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
if (!errorString.empty()) {
std::string err =
cmStrCat(cmIfCommandError(expandedArguments), errorString);
- cmListFileBacktrace bt = mf.GetBacktrace(func);
- mf.GetCMakeInstance()->IssueMessage(messType, err, bt);
+ mf.GetCMakeInstance()->IssueMessage(messType, err, elseifBT);
if (messType == MessageType::FATAL_ERROR) {
cmSystemTools::SetFatalErrorOccured();
return true;