cmGeneratorExpressionEvaluator.h 4.5 KB

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