cmGeneratorExpressionEvaluator.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 "cmListFileCache.h"
  13. #include "cmGeneratorExpressionContext.h"
  14. #include <vector>
  15. #include <string>
  16. struct cmGeneratorExpressionDAGChecker;
  17. struct cmGeneratorExpressionNode;
  18. //----------------------------------------------------------------------------
  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), Length(length)
  39. {
  40. }
  41. std::string Evaluate(cmGeneratorExpressionContext *,
  42. cmGeneratorExpressionDAGChecker *) const
  43. {
  44. return std::string(this->Content, this->Length);
  45. }
  46. Type GetType() const
  47. {
  48. return cmGeneratorExpressionEvaluator::Text;
  49. }
  50. void Extend(size_t length)
  51. {
  52. this->Length += length;
  53. }
  54. size_t GetLength()
  55. {
  56. return this->Length;
  57. }
  58. private:
  59. const char *Content;
  60. size_t Length;
  61. };
  62. //----------------------------------------------------------------------------
  63. struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator
  64. {
  65. GeneratorExpressionContent(const char *startContent, size_t length);
  66. void SetIdentifier(std::vector<cmGeneratorExpressionEvaluator*> identifier)
  67. {
  68. this->IdentifierChildren = identifier;
  69. }
  70. void SetParameters(
  71. std::vector<std::vector<cmGeneratorExpressionEvaluator*> > parameters)
  72. {
  73. this->ParamChildren = parameters;
  74. }
  75. Type GetType() const
  76. {
  77. return cmGeneratorExpressionEvaluator::Generator;
  78. }
  79. std::string Evaluate(cmGeneratorExpressionContext *context,
  80. cmGeneratorExpressionDAGChecker *) const;
  81. std::string GetOriginalExpression() const;
  82. ~GeneratorExpressionContent();
  83. private:
  84. std::string EvaluateParameters(const cmGeneratorExpressionNode *node,
  85. const std::string &identifier,
  86. cmGeneratorExpressionContext *context,
  87. cmGeneratorExpressionDAGChecker *dagChecker,
  88. std::vector<std::string> &parameters) const;
  89. std::string ProcessArbitraryContent(
  90. const cmGeneratorExpressionNode *node,
  91. const std::string &identifier,
  92. cmGeneratorExpressionContext *context,
  93. cmGeneratorExpressionDAGChecker *dagChecker,
  94. std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
  95. pit) const;
  96. private:
  97. std::vector<cmGeneratorExpressionEvaluator*> IdentifierChildren;
  98. std::vector<std::vector<cmGeneratorExpressionEvaluator*> > ParamChildren;
  99. const char *StartContent;
  100. size_t ContentLength;
  101. };
  102. #endif