cmConditionEvaluator.h 3.21 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3 4 5
#ifndef cmConditionEvaluator_h
#define cmConditionEvaluator_h

6
#include "cmConfigure.h" // IWYU pragma: keep
7 8 9 10 11

#include <list>
#include <string>
#include <vector>

12
#include "cmExpandedCommandArgument.h"
13
#include "cmListFileCache.h"
14
#include "cmMessageType.h"
15
#include "cmPolicies.h"
16

17
class cmMakefile;
18

19 20 21
class cmConditionEvaluator
{
public:
22
  typedef std::list<cmExpandedCommandArgument> cmArgumentList;
23

wahikihiki's avatar
wahikihiki committed
24 25
  cmConditionEvaluator(cmMakefile& makefile, cmListFileContext context,
                       cmListFileBacktrace bt);
26 27 28 29

  // this is a shared function for both If and Else to determine if the
  // arguments were valid, and if so, was the response true. If there is
  // an error, the errorString will be set.
30
  bool IsTrue(const std::vector<cmExpandedCommandArgument>& args,
31
              std::string& errorString, MessageType& status);
32 33

private:
34 35
  // Filter the given variable definition based on policy CMP0054.
  const char* GetDefinitionIfUnquoted(
36
    const cmExpandedCommandArgument& argument) const;
37

38
  const char* GetVariableOrString(
39
    const cmExpandedCommandArgument& argument) const;
40 41

  bool IsKeyword(std::string const& keyword,
42 43 44 45 46 47 48 49 50
                 cmExpandedCommandArgument& argument) const;

  bool GetBooleanValue(cmExpandedCommandArgument& arg) const;

  bool GetBooleanValueOld(cmExpandedCommandArgument const& arg,
                          bool one) const;

  bool GetBooleanValueWithAutoDereference(cmExpandedCommandArgument& newArg,
                                          std::string& errorString,
51
                                          MessageType& status,
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
                                          bool oneArg = false) const;

  void IncrementArguments(cmArgumentList& newArgs,
                          cmArgumentList::iterator& argP1,
                          cmArgumentList::iterator& argP2) const;

  void HandlePredicate(bool value, int& reducible,
                       cmArgumentList::iterator& arg, cmArgumentList& newArgs,
                       cmArgumentList::iterator& argP1,
                       cmArgumentList::iterator& argP2) const;

  void HandleBinaryOp(bool value, int& reducible,
                      cmArgumentList::iterator& arg, cmArgumentList& newArgs,
                      cmArgumentList::iterator& argP1,
                      cmArgumentList::iterator& argP2);

  bool HandleLevel0(cmArgumentList& newArgs, std::string& errorString,
69
                    MessageType& status);
70

71
  bool HandleLevel1(cmArgumentList& newArgs, std::string&, MessageType&);
72 73

  bool HandleLevel2(cmArgumentList& newArgs, std::string& errorString,
74
                    MessageType& status);
75 76

  bool HandleLevel3(cmArgumentList& newArgs, std::string& errorString,
77
                    MessageType& status);
78 79

  bool HandleLevel4(cmArgumentList& newArgs, std::string& errorString,
80
                    MessageType& status);
81 82

  cmMakefile& Makefile;
83 84
  cmListFileContext ExecutionContext;
  cmListFileBacktrace Backtrace;
85
  cmPolicies::PolicyStatus Policy12Status;
86
  cmPolicies::PolicyStatus Policy54Status;
87
  cmPolicies::PolicyStatus Policy57Status;
88
  cmPolicies::PolicyStatus Policy64Status;
89 90 91
};

#endif