cmGeneratorExpressionEvaluator.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 <cmConfigure.h>
  13. #include <stddef.h>
  14. #include <string>
  15. #include <vector>
  16. struct cmGeneratorExpressionContext;
  17. struct cmGeneratorExpressionDAGChecker;
  18. struct cmGeneratorExpressionNode;
  19. struct cmGeneratorExpressionEvaluator
  20. {
  21. cmGeneratorExpressionEvaluator() {}
  22. virtual ~cmGeneratorExpressionEvaluator() {}
  23. enum Type
  24. {
  25. Text,
  26. Generator
  27. };
  28. virtual Type GetType() const = 0;
  29. virtual std::string Evaluate(cmGeneratorExpressionContext* context,
  30. cmGeneratorExpressionDAGChecker*) const = 0;
  31. private:
  32. cmGeneratorExpressionEvaluator(const cmGeneratorExpressionEvaluator&);
  33. void operator=(const cmGeneratorExpressionEvaluator&);
  34. };
  35. struct TextContent : public cmGeneratorExpressionEvaluator
  36. {
  37. TextContent(const char* start, size_t length)
  38. : Content(start)
  39. , Length(length)
  40. {
  41. }
  42. std::string Evaluate(cmGeneratorExpressionContext*,
  43. cmGeneratorExpressionDAGChecker*) const CM_OVERRIDE
  44. {
  45. return std::string(this->Content, this->Length);
  46. }
  47. Type GetType() const CM_OVERRIDE
  48. {
  49. return cmGeneratorExpressionEvaluator::Text;
  50. }
  51. void Extend(size_t length) { this->Length += length; }
  52. size_t GetLength() { return this->Length; }
  53. private:
  54. const char* Content;
  55. size_t Length;
  56. };
  57. struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator
  58. {
  59. GeneratorExpressionContent(const char* startContent, size_t length);
  60. void SetIdentifier(std::vector<cmGeneratorExpressionEvaluator*> identifier)
  61. {
  62. this->IdentifierChildren = identifier;
  63. }
  64. void SetParameters(
  65. std::vector<std::vector<cmGeneratorExpressionEvaluator*> > parameters)
  66. {
  67. this->ParamChildren = parameters;
  68. }
  69. Type GetType() const CM_OVERRIDE
  70. {
  71. return cmGeneratorExpressionEvaluator::Generator;
  72. }
  73. std::string Evaluate(cmGeneratorExpressionContext* context,
  74. cmGeneratorExpressionDAGChecker*) const CM_OVERRIDE;
  75. std::string GetOriginalExpression() const;
  76. ~GeneratorExpressionContent() CM_OVERRIDE;
  77. private:
  78. std::string EvaluateParameters(const cmGeneratorExpressionNode* node,
  79. const std::string& identifier,
  80. cmGeneratorExpressionContext* context,
  81. cmGeneratorExpressionDAGChecker* dagChecker,
  82. std::vector<std::string>& parameters) const;
  83. std::string ProcessArbitraryContent(
  84. const cmGeneratorExpressionNode* node, const std::string& identifier,
  85. cmGeneratorExpressionContext* context,
  86. cmGeneratorExpressionDAGChecker* dagChecker,
  87. std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
  88. pit) const;
  89. private:
  90. std::vector<cmGeneratorExpressionEvaluator*> IdentifierChildren;
  91. std::vector<std::vector<cmGeneratorExpressionEvaluator*> > ParamChildren;
  92. const char* StartContent;
  93. size_t ContentLength;
  94. };
  95. #endif