1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #pragma once
4 
5 #include "cmConfigure.h" // IWYU pragma: keep
6 
7 #include <string>
8 #include <vector>
9 
10 #include <cmext/string_view>
11 
12 #include "cmListFileCache.h"
13 #include "cmMessageType.h"
14 #include "cmPolicies.h"
15 #include "cmValue.h"
16 
17 class cmExpandedCommandArgument;
18 class cmMakefile;
19 
20 class cmConditionEvaluator
21 {
22 public:
23   cmConditionEvaluator(cmMakefile& makefile, cmListFileBacktrace bt);
24 
25   // this is a shared function for both If and Else to determine if the
26   // arguments were valid, and if so, was the response true. If there is
27   // an error, the errorString will be set.
28   bool IsTrue(const std::vector<cmExpandedCommandArgument>& args,
29               std::string& errorString, MessageType& status);
30 
31 private:
32   class cmArgumentList;
33 
34   // Filter the given variable definition based on policy CMP0054.
35   cmValue GetDefinitionIfUnquoted(
36     const cmExpandedCommandArgument& argument) const;
37 
38   cmValue GetVariableOrString(const cmExpandedCommandArgument& argument) const;
39 
40   bool IsKeyword(cm::static_string_view keyword,
41                  const cmExpandedCommandArgument& argument) const;
42 
43   bool GetBooleanValue(cmExpandedCommandArgument& arg) const;
44 
45   bool GetBooleanValueOld(cmExpandedCommandArgument const& arg,
46                           bool one) const;
47 
48   bool GetBooleanValueWithAutoDereference(cmExpandedCommandArgument& newArg,
49                                           std::string& errorString,
50                                           MessageType& status,
51                                           bool oneArg = false) const;
52 
53   template <int N>
54   int matchKeysImpl(const cmExpandedCommandArgument&);
55 
56   template <int N, typename T, typename... Keys>
57   int matchKeysImpl(const cmExpandedCommandArgument&, T, Keys...);
58 
59   template <typename... Keys>
60   int matchKeys(const cmExpandedCommandArgument&, Keys...);
61 
62   bool HandleLevel0(cmArgumentList& newArgs, std::string& errorString,
63                     MessageType& status);
64 
65   bool HandleLevel1(cmArgumentList& newArgs, std::string&, MessageType&);
66 
67   bool HandleLevel2(cmArgumentList& newArgs, std::string& errorString,
68                     MessageType& status);
69 
70   bool HandleLevel3(cmArgumentList& newArgs, std::string& errorString,
71                     MessageType& status);
72 
73   bool HandleLevel4(cmArgumentList& newArgs, std::string& errorString,
74                     MessageType& status);
75 
76   cmMakefile& Makefile;
77   cmListFileBacktrace Backtrace;
78   cmPolicies::PolicyStatus Policy12Status;
79   cmPolicies::PolicyStatus Policy54Status;
80   cmPolicies::PolicyStatus Policy57Status;
81   cmPolicies::PolicyStatus Policy64Status;
82 };
83