cmGeneratorExpressionEvaluator.h 3.9 KB

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