resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmFunctionBlocker.cxx
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #include "cmFunctionBlocker.h"
4
5 #include <cassert>
6 #include <memory> // IWYU pragma: keep
7 #include <sstream>
8 #include <string> // IWYU pragma: keep
9 #include <utility>
10
11 #include "cmExecutionStatus.h"
12 #include "cmMakefile.h"
13 #include "cmMessageType.h"
14
15 bool cmFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
16                                           cmExecutionStatus& status)
17 {
18   if (lff.LowerCaseName() == this->StartCommandName()) {
19     this->ScopeDepth++;
20   } else if (lff.LowerCaseName() == this->EndCommandName()) {
21     this->ScopeDepth--;
22     if (this->ScopeDepth == 0U) {
23       cmMakefile& mf = status.GetMakefile();
24       auto self = mf.RemoveFunctionBlocker();
25       assert(self.get() == this);
26
27       cmListFileContext const& lfc = this->GetStartingContext();
28       cmListFileContext closingContext =
29         cmListFileContext::FromListFileFunction(lff, lfc.FilePath);
30       if (this->EndCommandSupportsArguments() &&
31           !this->ArgumentsMatch(lff, mf)) {
32         std::ostringstream e;
33         /* clang-format off */
34         e << "A logical block opening on the line\n"
35           << "  " << lfc << "\n"
36           << "closes on the line\n"
37           << "  " << closingContext << "\n"
38           << "with mis-matching arguments.";
39         /* clang-format on */
40         mf.IssueMessage(MessageType::AUTHOR_WARNING, e.str());
41       } else if (!this->EndCommandSupportsArguments() &&
42                  !lff.Arguments().empty()) {
43         std::ostringstream e;
44         /* clang-format off */
45         e << "A logical block closing on the line\n"
46           "  " << closingContext << "\n"
47           "has unexpected arguments.";
48         /* clang-format on */
49         mf.IssueMessage(MessageType::AUTHOR_WARNING, e.str());
50       }
51
52       return this->Replay(std::move(this->Functions), status);
53     }
54   }
55
56   this->Functions.push_back(lff);
57   return true;
58 }