cmGeneratorExpression.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  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. #include "cmGeneratorExpression.h"
  11. #include "cmMakefile.h"
  12. #include "cmTarget.h"
  13. #include <cmsys/String.h>
  14. #include "cmGeneratorExpressionEvaluator.h"
  15. #include "cmGeneratorExpressionLexer.h"
  16. #include "cmGeneratorExpressionParser.h"
  17. #include "cmGeneratorExpressionDAGChecker.h"
  18. //----------------------------------------------------------------------------
  19. cmGeneratorExpression::cmGeneratorExpression(
  20. cmListFileBacktrace const& backtrace):
  21. Backtrace(backtrace), CompiledExpression(0)
  22. {
  23. }
  24. //----------------------------------------------------------------------------
  25. const cmCompiledGeneratorExpression &
  26. cmGeneratorExpression::Parse(std::string const& input)
  27. {
  28. return this->Parse(input.c_str());
  29. }
  30. //----------------------------------------------------------------------------
  31. const cmCompiledGeneratorExpression &
  32. cmGeneratorExpression::Parse(const char* input)
  33. {
  34. cmGeneratorExpressionLexer l;
  35. std::vector<cmGeneratorExpressionToken> tokens = l.Tokenize(input);
  36. bool needsParsing = l.GetSawGeneratorExpression();
  37. std::vector<cmGeneratorExpressionEvaluator*> evaluators;
  38. if (needsParsing)
  39. {
  40. cmGeneratorExpressionParser p(tokens);
  41. p.Parse(evaluators);
  42. }
  43. delete this->CompiledExpression;
  44. this->CompiledExpression = new cmCompiledGeneratorExpression(
  45. this->Backtrace,
  46. evaluators,
  47. input,
  48. needsParsing);
  49. return *this->CompiledExpression;
  50. }
  51. cmGeneratorExpression::~cmGeneratorExpression()
  52. {
  53. delete this->CompiledExpression;
  54. }
  55. //----------------------------------------------------------------------------
  56. const char *cmCompiledGeneratorExpression::Evaluate(
  57. cmMakefile* mf, const char* config, bool quiet,
  58. cmGeneratorTarget *target,
  59. cmGeneratorExpressionDAGChecker *dagChecker) const
  60. {
  61. if (!this->NeedsParsing)
  62. {
  63. return this->Input;
  64. }
  65. this->Output = "";
  66. std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
  67. = this->Evaluators.begin();
  68. const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
  69. = this->Evaluators.end();
  70. cmGeneratorExpressionContext context;
  71. context.Makefile = mf;
  72. context.Config = config;
  73. context.Quiet = quiet;
  74. context.HadError = false;
  75. context.Target = target;
  76. context.Backtrace = this->Backtrace;
  77. for ( ; it != end; ++it)
  78. {
  79. this->Output += (*it)->Evaluate(&context, dagChecker);
  80. if (context.HadError)
  81. {
  82. this->Output = "";
  83. break;
  84. }
  85. }
  86. this->Targets = context.Targets;
  87. // TODO: Return a std::string from here instead?
  88. return this->Output.c_str();
  89. }
  90. cmCompiledGeneratorExpression::cmCompiledGeneratorExpression(
  91. cmListFileBacktrace const& backtrace,
  92. const std::vector<cmGeneratorExpressionEvaluator*> &evaluators,
  93. const char *input, bool needsParsing)
  94. : Backtrace(backtrace), Evaluators(evaluators), Input(input),
  95. NeedsParsing(needsParsing)
  96. {
  97. }
  98. //----------------------------------------------------------------------------
  99. cmCompiledGeneratorExpression::~cmCompiledGeneratorExpression()
  100. {
  101. std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
  102. = this->Evaluators.begin();
  103. const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
  104. = this->Evaluators.end();
  105. for ( ; it != end; ++it)
  106. {
  107. delete *it;
  108. }
  109. }