cmGeneratorExpressionEvaluator.h 3.0 KB

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