Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmDefinitions.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 <string>
8
#include <unordered_map>
9
#include <vector>
10
11
#include <cm/string_view>
12
13
#include "cmLinkedTree.h"
14
#include "cmString.hxx"
15
#include "cmValue.h"
16
17
/** \class cmDefinitions
18
 * \brief Store a scope of variable definitions for CMake language.
19
 *
20
 * This stores the state of variable definitions (set or unset) for
21
 * one scope.  Sets are always local.  Gets search parent scopes
22
 * transitively and save results locally.
23
 */
24
class cmDefinitions
25
{
26
  using StackIter = cmLinkedTree<cmDefinitions>::iterator;
27
28
public:
29
  // -- Static member functions
30
31
  static cmValue Get(std::string const& key, StackIter begin, StackIter end);
32
33
  static void Raise(std::string const& key, StackIter begin, StackIter end);
34
35
  static bool HasKey(std::string const& key, StackIter begin, StackIter end);
36
37
  static std::vector<std::string> ClosureKeys(StackIter begin, StackIter end);
38
39
  static cmDefinitions MakeClosure(StackIter begin, StackIter end);
40
41
  // -- Member functions
42
43
  /** Set a value associated with a key.  */
44
  void Set(std::string const& key, cm::string_view value);
45
46
  /** Unset a definition.  */
47
  void Unset(std::string const& key);
48
49
private:
50
  /** String with existence boolean.  */
51
  struct Def
52
  {
53
  public:
54
95
    Def() = default;
55
    Def(cm::string_view value)
56
97
      : Value(value)
57
97
    {
58
97
    }
59
    cm::String Value;
60
  };
61
  static Def NoDef;
62
63
  std::unordered_map<cm::String, Def> Map;
64
65
  static Def const& GetInternal(std::string const& key, StackIter begin,
66
                                StackIter end, bool raise);
67
};