Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmGeneratorExpressionEvaluator.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2012 Stephen Kelly <steveire@gmail.com>
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmGeneratorExpressionEvaluator_h
13 #define cmGeneratorExpressionEvaluator_h
14
15 #include <vector>
16 #include <string>
17
18 #include "cmListFileCache.h"
19
20 class cmTarget;
21
22 //----------------------------------------------------------------------------
23 struct cmGeneratorExpressionContext
24 {
25   cmListFileBacktrace Backtrace;
26   std::set<cmTarget*> DependTargets;
27   std::set<cmTarget*> AllTargets;
28   std::set<cmStdString> SeenTargetProperties;
29   cmMakefile *Makefile;
30   const char *Config;
31   cmTarget *HeadTarget; // The target whose property is being evaluated.
32   cmTarget *CurrentTarget; // The dependent of HeadTarget which appears
33                            // directly or indirectly in the property.
34   bool Quiet;
35   bool HadError;
36   bool HadContextSensitiveCondition;
37 };
38
39 struct cmGeneratorExpressionDAGChecker;
40 struct cmGeneratorExpressionNode;
41
42 //----------------------------------------------------------------------------
43 struct cmGeneratorExpressionEvaluator
44 {
45   cmGeneratorExpressionEvaluator() {}
46   virtual ~cmGeneratorExpressionEvaluator() {}
47
48   enum Type
49   {
50     Text,
51     Generator
52   };
53
54   virtual Type GetType() const = 0;
55
56   virtual std::string Evaluate(cmGeneratorExpressionContext *context,
57                               cmGeneratorExpressionDAGChecker *) const = 0;
58
59 private:
60   cmGeneratorExpressionEvaluator(const cmGeneratorExpressionEvaluator &);
61   void operator=(const cmGeneratorExpressionEvaluator &);
62 };
63
64 struct TextContent : public cmGeneratorExpressionEvaluator
65 {
66   TextContent(const char *start, unsigned int length)
67     : Content(start), Length(length)
68   {
69
70   }
71
72   std::string Evaluate(cmGeneratorExpressionContext *,
73                        cmGeneratorExpressionDAGChecker *) const
74   {
75     return std::string(this->Content, this->Length);
76   }
77
78   Type GetType() const
79   {
80     return cmGeneratorExpressionEvaluator::Text;
81   }
82
83   void Extend(unsigned int length)
84   {
85     this->Length += length;
86   }
87
88   unsigned int GetLength()
89   {
90     return this->Length;
91   }
92
93 private:
94   const char *Content;
95   unsigned int Length;
96 };
97
98 //----------------------------------------------------------------------------
99 struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator
100 {
101   GeneratorExpressionContent(const char *startContent, unsigned int length);
102   void SetIdentifier(std::vector<cmGeneratorExpressionEvaluator*> identifier)
103   {
104     this->IdentifierChildren = identifier;
105   }
106
107   void SetParameters(
108         std::vector<std::vector<cmGeneratorExpressionEvaluator*> > parameters)
109   {
110     this->ParamChildren = parameters;
111   }
112
113   Type GetType() const
114   {
115     return cmGeneratorExpressionEvaluator::Generator;
116   }
117
118   std::string Evaluate(cmGeneratorExpressionContext *context,
119                        cmGeneratorExpressionDAGChecker *) const;
120
121   std::string GetOriginalExpression() const;
122
123   ~GeneratorExpressionContent();
124
125 private:
126   std::string EvaluateParameters(const cmGeneratorExpressionNode *node,
127                                  const std::string &identifier,
128                                  cmGeneratorExpressionContext *context,
129                                  cmGeneratorExpressionDAGChecker *dagChecker,
130                                  std::vector<std::string> &parameters) const;
131
132   std::string ProcessArbitraryContent(
133     const cmGeneratorExpressionNode *node,
134     const std::string &identifier,
135     cmGeneratorExpressionContext *context,
136     cmGeneratorExpressionDAGChecker *dagChecker,
137     std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
138     pit) const;
139
140 private:
141   std::vector<cmGeneratorExpressionEvaluator*> IdentifierChildren;
142   std::vector<std::vector<cmGeneratorExpressionEvaluator*> > ParamChildren;
143   const char *StartContent;
144   unsigned int ContentLength;
145 };
146
147 #endif