cmGeneratorExpressionEvaluator.h 3.6 KB

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