cmGeneratorExpressionEvaluator.h 3.2 KB

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