cmGeneratorExpressionEvaluator.h 4.2 KB

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