Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmFunctionBlocker.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst 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
#include "cmake.h"
15
16
bool cmFunctionBlocker::IsFunctionBlocked(cmListFileFunction const& lff,
17
                                          cmExecutionStatus& status)
18
0
{
19
0
  if (lff.LowerCaseName() == this->StartCommandName()) {
20
0
    this->ScopeDepth++;
21
0
  } else if (lff.LowerCaseName() == this->EndCommandName()) {
22
0
    this->ScopeDepth--;
23
0
    if (this->ScopeDepth == 0U) {
24
0
      cmMakefile& mf = status.GetMakefile();
25
0
      auto self = mf.RemoveFunctionBlocker();
26
0
      assert(self.get() == this);
27
28
0
      cmListFileContext const& lfc = this->GetStartingContext();
29
0
      cmListFileContext closingContext =
30
0
        cmListFileContext::FromListFileFunction(lff, lfc.FilePath);
31
0
      if (this->EndCommandSupportsArguments() &&
32
0
          !this->ArgumentsMatch(lff, mf)) {
33
0
        std::ostringstream e;
34
        /* clang-format off */
35
0
        e << "A logical block opening on the line\n"
36
0
          << "  " << lfc << "\n"
37
0
          << "closes on the line\n"
38
0
          << "  " << closingContext << "\n"
39
0
          << "with mis-matching arguments.";  // noqa: spellcheck disable-line
40
        /* clang-format on */
41
0
        mf.IssueMessage(MessageType::AUTHOR_WARNING, e.str());
42
0
      } else if (!this->EndCommandSupportsArguments() &&
43
0
                 !lff.Arguments().empty()) {
44
0
        std::ostringstream e;
45
        /* clang-format off */
46
0
        e << "A logical block closing on the line\n"
47
0
          "  " << closingContext << "\n"
48
0
          "has unexpected arguments.";
49
        /* clang-format on */
50
0
        mf.IssueMessage(MessageType::AUTHOR_WARNING, e.str());
51
0
      }
52
53
0
      bool replayResult = this->Replay(std::move(this->Functions), status);
54
0
      cmListFileBacktrace endCommandBT =
55
0
        mf.GetBacktrace().Push(closingContext);
56
      // if trace is enabled, print a (trivially) evaluated "end" statement
57
0
      if (mf.GetCMakeInstance()->GetTrace()) {
58
0
        mf.PrintCommandTrace(lff, endCommandBT,
59
0
                             cmMakefile::CommandMissingFromStack::Yes);
60
0
      }
61
0
      return replayResult;
62
0
    }
63
0
  }
64
65
0
  this->Functions.push_back(lff);
66
0
  return true;
67
0
}