Coverage Report

Created: 2026-03-12 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmGeneratorExpressionEvaluator.h
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
#pragma once
4
5
#include "cmConfigure.h" // IWYU pragma: keep
6
7
#include <cstddef>
8
#include <memory>
9
#include <string>
10
#include <utility>
11
#include <vector>
12
13
namespace cm {
14
namespace GenEx {
15
struct Evaluation;
16
}
17
}
18
19
struct cmGeneratorExpressionDAGChecker;
20
struct cmGeneratorExpressionNode;
21
22
struct cmGeneratorExpressionEvaluator
23
{
24
0
  cmGeneratorExpressionEvaluator() = default;
25
0
  virtual ~cmGeneratorExpressionEvaluator() = default;
26
27
  cmGeneratorExpressionEvaluator(cmGeneratorExpressionEvaluator const&) =
28
    delete;
29
  cmGeneratorExpressionEvaluator& operator=(
30
    cmGeneratorExpressionEvaluator const&) = delete;
31
32
  enum Type
33
  {
34
    Text,
35
    Generator
36
  };
37
38
  virtual Type GetType() const = 0;
39
40
  virtual std::string Evaluate(cm::GenEx::Evaluation* eval,
41
                               cmGeneratorExpressionDAGChecker*) const = 0;
42
};
43
44
using cmGeneratorExpressionEvaluatorVector =
45
  std::vector<std::unique_ptr<cmGeneratorExpressionEvaluator>>;
46
47
struct TextContent : public cmGeneratorExpressionEvaluator
48
{
49
  TextContent(char const* start, size_t length)
50
0
    : Content(start)
51
0
    , Length(length)
52
0
  {
53
0
  }
54
55
  std::string Evaluate(cm::GenEx::Evaluation*,
56
                       cmGeneratorExpressionDAGChecker*) const override
57
0
  {
58
0
    return std::string(this->Content, this->Length);
59
0
  }
60
61
  Type GetType() const override
62
0
  {
63
0
    return cmGeneratorExpressionEvaluator::Text;
64
0
  }
65
66
0
  void Extend(size_t length) { this->Length += length; }
67
68
0
  size_t GetLength() const { return this->Length; }
69
70
private:
71
  char const* Content;
72
  size_t Length;
73
};
74
75
struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator
76
{
77
  GeneratorExpressionContent(char const* startContent, size_t length);
78
79
  void SetIdentifier(cmGeneratorExpressionEvaluatorVector&& identifier)
80
0
  {
81
0
    this->IdentifierChildren = std::move(identifier);
82
0
  }
83
84
  void SetParameters(
85
    std::vector<cmGeneratorExpressionEvaluatorVector>&& parameters)
86
0
  {
87
0
    this->ParamChildren = std::move(parameters);
88
0
  }
89
90
  Type GetType() const override
91
0
  {
92
0
    return cmGeneratorExpressionEvaluator::Generator;
93
0
  }
94
95
  std::string Evaluate(cm::GenEx::Evaluation* eval,
96
                       cmGeneratorExpressionDAGChecker*) const override;
97
98
  std::string GetOriginalExpression() const;
99
100
  ~GeneratorExpressionContent() override;
101
102
private:
103
  std::string EvaluateParameters(cmGeneratorExpressionNode const* node,
104
                                 std::string const& identifier,
105
                                 cm::GenEx::Evaluation* eval,
106
                                 cmGeneratorExpressionDAGChecker* dagChecker,
107
                                 std::vector<std::string>& parameters) const;
108
109
  std::string ProcessArbitraryContent(
110
    cmGeneratorExpressionNode const* node, std::string const& identifier,
111
    cm::GenEx::Evaluation* eval, cmGeneratorExpressionDAGChecker* dagChecker,
112
    std::vector<cmGeneratorExpressionEvaluatorVector>::const_iterator pit)
113
    const;
114
115
  cmGeneratorExpressionEvaluatorVector IdentifierChildren;
116
  std::vector<cmGeneratorExpressionEvaluatorVector> ParamChildren;
117
  char const* StartContent;
118
  size_t ContentLength;
119
};