cmGeneratorExpressionEvaluator.h 3.6 KB

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