cmGeneratorExpressionEvaluator.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. cmListFileBacktrace Backtrace;
  20. std::set<cmTarget*> DependTargets;
  21. std::set<cmTarget const*> AllTargets;
  22. std::set<std::string> SeenTargetProperties;
  23. cmMakefile *Makefile;
  24. std::string Config;
  25. cmTarget const* HeadTarget; // The target whose property is being evaluated.
  26. cmTarget const* CurrentTarget; // The dependent of HeadTarget which appears
  27. // directly or indirectly in the property.
  28. bool Quiet;
  29. bool HadError;
  30. bool HadContextSensitiveCondition;
  31. bool EvaluateForBuildsystem;
  32. };
  33. struct cmGeneratorExpressionDAGChecker;
  34. struct cmGeneratorExpressionNode;
  35. //----------------------------------------------------------------------------
  36. struct cmGeneratorExpressionEvaluator
  37. {
  38. cmGeneratorExpressionEvaluator() {}
  39. virtual ~cmGeneratorExpressionEvaluator() {}
  40. enum Type
  41. {
  42. Text,
  43. Generator
  44. };
  45. virtual Type GetType() const = 0;
  46. virtual std::string Evaluate(cmGeneratorExpressionContext *context,
  47. cmGeneratorExpressionDAGChecker *) const = 0;
  48. private:
  49. cmGeneratorExpressionEvaluator(const cmGeneratorExpressionEvaluator &);
  50. void operator=(const cmGeneratorExpressionEvaluator &);
  51. };
  52. struct TextContent : public cmGeneratorExpressionEvaluator
  53. {
  54. TextContent(const char *start, size_t length)
  55. : Content(start), Length(length)
  56. {
  57. }
  58. std::string Evaluate(cmGeneratorExpressionContext *,
  59. cmGeneratorExpressionDAGChecker *) const
  60. {
  61. return std::string(this->Content, this->Length);
  62. }
  63. Type GetType() const
  64. {
  65. return cmGeneratorExpressionEvaluator::Text;
  66. }
  67. void Extend(size_t length)
  68. {
  69. this->Length += length;
  70. }
  71. size_t GetLength()
  72. {
  73. return this->Length;
  74. }
  75. private:
  76. const char *Content;
  77. size_t Length;
  78. };
  79. //----------------------------------------------------------------------------
  80. struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator
  81. {
  82. GeneratorExpressionContent(const char *startContent, size_t length);
  83. void SetIdentifier(std::vector<cmGeneratorExpressionEvaluator*> identifier)
  84. {
  85. this->IdentifierChildren = identifier;
  86. }
  87. void SetParameters(
  88. std::vector<std::vector<cmGeneratorExpressionEvaluator*> > parameters)
  89. {
  90. this->ParamChildren = parameters;
  91. }
  92. Type GetType() const
  93. {
  94. return cmGeneratorExpressionEvaluator::Generator;
  95. }
  96. std::string Evaluate(cmGeneratorExpressionContext *context,
  97. cmGeneratorExpressionDAGChecker *) const;
  98. std::string GetOriginalExpression() const;
  99. ~GeneratorExpressionContent();
  100. private:
  101. std::string EvaluateParameters(const cmGeneratorExpressionNode *node,
  102. const std::string &identifier,
  103. cmGeneratorExpressionContext *context,
  104. cmGeneratorExpressionDAGChecker *dagChecker,
  105. std::vector<std::string> &parameters) const;
  106. std::string ProcessArbitraryContent(
  107. const cmGeneratorExpressionNode *node,
  108. const std::string &identifier,
  109. cmGeneratorExpressionContext *context,
  110. cmGeneratorExpressionDAGChecker *dagChecker,
  111. std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
  112. pit) const;
  113. private:
  114. std::vector<cmGeneratorExpressionEvaluator*> IdentifierChildren;
  115. std::vector<std::vector<cmGeneratorExpressionEvaluator*> > ParamChildren;
  116. const char *StartContent;
  117. size_t ContentLength;
  118. };
  119. #endif