cmake/Source/cmFunctionBlocker.cxx

59 lines
2.0 KiB
C++
Raw Normal View History

2020-02-01 23:06:01 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmFunctionBlocker.h"
#include <cassert>
2020-08-30 11:54:41 +02:00
#include <memory> // IWYU pragma: keep
2020-02-01 23:06:01 +01:00
#include <sstream>
2020-08-30 11:54:41 +02:00
#include <string> // IWYU pragma: keep
2020-02-01 23:06:01 +01:00
#include <utility>
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
bool cmFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
cmExecutionStatus& status)
{
2021-09-14 00:13:48 +02:00
if (lff.LowerCaseName() == this->StartCommandName()) {
2020-02-01 23:06:01 +01:00
this->ScopeDepth++;
2021-09-14 00:13:48 +02:00
} else if (lff.LowerCaseName() == this->EndCommandName()) {
2020-02-01 23:06:01 +01:00
this->ScopeDepth--;
if (this->ScopeDepth == 0U) {
cmMakefile& mf = status.GetMakefile();
auto self = mf.RemoveFunctionBlocker();
assert(self.get() == this);
2022-11-16 20:14:03 +01:00
cmListFileContext const& lfc = this->GetStartingContext();
cmListFileContext closingContext =
cmListFileContext::FromListFileFunction(lff, lfc.FilePath);
if (this->EndCommandSupportsArguments() &&
!this->ArgumentsMatch(lff, mf)) {
2020-02-01 23:06:01 +01:00
std::ostringstream e;
/* clang-format off */
e << "A logical block opening on the line\n"
<< " " << lfc << "\n"
<< "closes on the line\n"
<< " " << closingContext << "\n"
<< "with mis-matching arguments.";
/* clang-format on */
mf.IssueMessage(MessageType::AUTHOR_WARNING, e.str());
2022-11-16 20:14:03 +01:00
} else if (!this->EndCommandSupportsArguments() &&
!lff.Arguments().empty()) {
std::ostringstream e;
/* clang-format off */
e << "A logical block closing on the line\n"
" " << closingContext << "\n"
"has unexpected arguments.";
/* clang-format on */
mf.IssueMessage(MessageType::AUTHOR_WARNING, e.str());
2020-02-01 23:06:01 +01:00
}
return this->Replay(std::move(this->Functions), status);
}
}
this->Functions.push_back(lff);
return true;
}