cmWhileCommand.cxx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmWhileCommand.h"
  14. #include "cmIfCommand.h"
  15. bool cmWhileFunctionBlocker::
  16. IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
  17. {
  18. // Prevent recusion and don't let this blocker block its own
  19. // commands.
  20. if (this->Executing)
  21. {
  22. return false;
  23. }
  24. // at end of for each execute recorded commands
  25. if (cmSystemTools::LowerCase(lff.Name) == "endwhile")
  26. {
  27. char* errorString = 0;
  28. std::vector<std::string> expandedArguments;
  29. mf.ExpandArguments(this->Args, expandedArguments);
  30. bool isTrue =
  31. cmIfCommand::IsTrue(expandedArguments,&errorString,&mf);
  32. this->Executing = true;
  33. while (isTrue)
  34. {
  35. // Invoke all the functions that were collected in the block.
  36. for(unsigned int c = 0; c < this->Functions.size(); ++c)
  37. {
  38. mf.ExecuteCommand(this->Functions[c]);
  39. }
  40. expandedArguments.clear();
  41. mf.ExpandArguments(this->Args, expandedArguments);
  42. isTrue =
  43. cmIfCommand::IsTrue(expandedArguments,&errorString,&mf);
  44. }
  45. mf.RemoveFunctionBlocker(lff);
  46. return true;
  47. }
  48. // record the command
  49. this->Functions.push_back(lff);
  50. // always return true
  51. return true;
  52. }
  53. bool cmWhileFunctionBlocker::
  54. ShouldRemove(const cmListFileFunction& lff, cmMakefile& )
  55. {
  56. if(cmSystemTools::LowerCase(lff.Name) == "endwhile")
  57. {
  58. if (lff.Arguments == this->Args)
  59. {
  60. return true;
  61. }
  62. }
  63. return false;
  64. }
  65. void cmWhileFunctionBlocker::
  66. ScopeEnded(cmMakefile &mf)
  67. {
  68. cmSystemTools::Error(
  69. "The end of a CMakeLists file was reached with a WHILE statement that "
  70. "was not closed properly. Within the directory: ",
  71. mf.GetCurrentDirectory());
  72. }
  73. bool cmWhileCommand::InvokeInitialPass(
  74. const std::vector<cmListFileArgument>& args)
  75. {
  76. if(args.size() < 1)
  77. {
  78. this->SetError("called with incorrect number of arguments");
  79. return false;
  80. }
  81. // create a function blocker
  82. cmWhileFunctionBlocker *f = new cmWhileFunctionBlocker();
  83. f->Args = args;
  84. this->Makefile->AddFunctionBlocker(f);
  85. return true;
  86. }