cmGeneratorExpression.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. //----------------------------------------------------------------------------
  18. cmGeneratorExpression::cmGeneratorExpression(
  19. cmMakefile* mf, const char* config,
  20. cmListFileBacktrace const& backtrace, bool quiet):
  21. Makefile(mf), Config(config), Backtrace(backtrace), Quiet(quiet),
  22. NeedsParsing(true)
  23. {
  24. }
  25. //----------------------------------------------------------------------------
  26. const char* cmGeneratorExpression::Process(std::string const& input)
  27. {
  28. return this->Process(input.c_str());
  29. }
  30. //----------------------------------------------------------------------------
  31. const char* cmGeneratorExpression::Process(const char* input)
  32. {
  33. this->Parse(input);
  34. return this->Evaluate(this->Makefile, this->Config, this->Quiet);
  35. }
  36. //----------------------------------------------------------------------------
  37. void cmGeneratorExpression::Parse(const char* input)
  38. {
  39. this->Evaluators.clear();
  40. this->Input = input;
  41. cmGeneratorExpressionLexer l;
  42. std::vector<cmGeneratorExpressionToken> tokens = l.Tokenize(this->Input);
  43. this->NeedsParsing = l.GetSawGeneratorExpression();
  44. if (!this->NeedsParsing)
  45. {
  46. return;
  47. }
  48. cmGeneratorExpressionParser p(tokens);
  49. p.Parse(this->Evaluators);
  50. }
  51. //----------------------------------------------------------------------------
  52. const char *cmGeneratorExpression::Evaluate(
  53. cmMakefile* mf, const char* config, bool quiet)
  54. {
  55. if (!this->NeedsParsing)
  56. {
  57. return this->Input;
  58. }
  59. this->Output = "";
  60. std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
  61. = this->Evaluators.begin();
  62. const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
  63. = this->Evaluators.end();
  64. cmGeneratorExpressionContext context;
  65. context.Makefile = mf;
  66. context.Config = config;
  67. context.Quiet = quiet;
  68. context.HadError = false;
  69. context.Backtrace = this->Backtrace;
  70. for ( ; it != end; ++it)
  71. {
  72. this->Output += (*it)->Evaluate(&context);
  73. if (context.HadError)
  74. {
  75. this->Output = "";
  76. break;
  77. }
  78. }
  79. this->Targets = context.Targets;
  80. // TODO: Return a std::string from here instead?
  81. return this->Output.c_str();
  82. }
  83. //----------------------------------------------------------------------------
  84. cmGeneratorExpression::~cmGeneratorExpression()
  85. {
  86. std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
  87. = this->Evaluators.begin();
  88. const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
  89. = this->Evaluators.end();
  90. for ( ; it != end; ++it)
  91. {
  92. delete *it;
  93. }
  94. }