cmGeneratorExpressionEvaluator.h 3.2 KB

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