cmGeneratorExpressionEvaluator.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. };
  30. struct cmGeneratorExpressionDAGChecker;
  31. struct cmGeneratorExpressionNode;
  32. //----------------------------------------------------------------------------
  33. struct cmGeneratorExpressionEvaluator
  34. {
  35. cmGeneratorExpressionEvaluator() {}
  36. virtual ~cmGeneratorExpressionEvaluator() {}
  37. enum Type
  38. {
  39. Text,
  40. Generator
  41. };
  42. virtual Type GetType() const = 0;
  43. virtual std::string Evaluate(cmGeneratorExpressionContext *context,
  44. cmGeneratorExpressionDAGChecker *) const = 0;
  45. private:
  46. cmGeneratorExpressionEvaluator(const cmGeneratorExpressionEvaluator &);
  47. void operator=(const cmGeneratorExpressionEvaluator &);
  48. };
  49. struct TextContent : public cmGeneratorExpressionEvaluator
  50. {
  51. TextContent(const char *start, unsigned int length)
  52. : Content(start), Length(length)
  53. {
  54. }
  55. std::string Evaluate(cmGeneratorExpressionContext *,
  56. cmGeneratorExpressionDAGChecker *) const
  57. {
  58. return std::string(this->Content, this->Length);
  59. }
  60. Type GetType() const
  61. {
  62. return cmGeneratorExpressionEvaluator::Text;
  63. }
  64. void Extend(unsigned int length)
  65. {
  66. this->Length += length;
  67. }
  68. unsigned int GetLength()
  69. {
  70. return this->Length;
  71. }
  72. private:
  73. const char *Content;
  74. unsigned int Length;
  75. };
  76. //----------------------------------------------------------------------------
  77. struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator
  78. {
  79. GeneratorExpressionContent(const char *startContent, unsigned int length);
  80. void SetIdentifier(std::vector<cmGeneratorExpressionEvaluator*> identifier)
  81. {
  82. this->IdentifierChildren = identifier;
  83. }
  84. void SetParameters(
  85. std::vector<std::vector<cmGeneratorExpressionEvaluator*> > parameters)
  86. {
  87. this->ParamChildren = parameters;
  88. }
  89. Type GetType() const
  90. {
  91. return cmGeneratorExpressionEvaluator::Generator;
  92. }
  93. std::string Evaluate(cmGeneratorExpressionContext *context,
  94. cmGeneratorExpressionDAGChecker *) const;
  95. std::string GetOriginalExpression() const;
  96. ~GeneratorExpressionContent();
  97. private:
  98. std::string EvaluateParameters(const cmGeneratorExpressionNode *node,
  99. const std::string &identifier,
  100. cmGeneratorExpressionContext *context,
  101. cmGeneratorExpressionDAGChecker *dagChecker,
  102. std::vector<std::string> &parameters) const;
  103. private:
  104. std::vector<cmGeneratorExpressionEvaluator*> IdentifierChildren;
  105. std::vector<std::vector<cmGeneratorExpressionEvaluator*> > ParamChildren;
  106. const char *StartContent;
  107. unsigned int ContentLength;
  108. };
  109. #endif