cmGeneratorExpressionEvaluator.h 3.8 KB

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