Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmWhileCommand.cxx
blobf94104dc8e57d918c1fae591fa649de75ba07259
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmWhileCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2009-01-21 14:49:00 $
7 Version: $Revision: 1.16 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmWhileCommand.h"
18 #include "cmIfCommand.h"
20 bool cmWhileFunctionBlocker::
21 IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
22 cmExecutionStatus &inStatus)
24 // at end of for each execute recorded commands
25 if (!cmSystemTools::Strucmp(lff.Name.c_str(),"while"))
27 // record the number of while commands past this one
28 this->Depth++;
30 else if (!cmSystemTools::Strucmp(lff.Name.c_str(),"endwhile"))
32 // if this is the endwhile for this while loop then execute
33 if (!this->Depth)
35 // Remove the function blocker for this scope or bail.
36 cmsys::auto_ptr<cmFunctionBlocker>
37 fb(mf.RemoveFunctionBlocker(this, lff));
38 if(!fb.get()) { return false; }
40 std::string errorString;
42 std::vector<std::string> expandedArguments;
43 mf.ExpandArguments(this->Args, expandedArguments);
44 bool isTrue =
45 cmIfCommand::IsTrue(expandedArguments,errorString,&mf);
47 while (isTrue)
49 // Invoke all the functions that were collected in the block.
50 for(unsigned int c = 0; c < this->Functions.size(); ++c)
52 cmExecutionStatus status;
53 mf.ExecuteCommand(this->Functions[c],status);
54 if (status.GetReturnInvoked())
56 inStatus.SetReturnInvoked(true);
57 return true;
59 if (status.GetBreakInvoked())
61 return true;
64 expandedArguments.clear();
65 mf.ExpandArguments(this->Args, expandedArguments);
66 isTrue =
67 cmIfCommand::IsTrue(expandedArguments,errorString,&mf);
69 return true;
71 else
73 // decrement for each nested while that ends
74 this->Depth--;
78 // record the command
79 this->Functions.push_back(lff);
81 // always return true
82 return true;
85 bool cmWhileFunctionBlocker::
86 ShouldRemove(const cmListFileFunction& lff, cmMakefile& )
88 if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endwhile"))
90 // if the endwhile has arguments, then make sure
91 // they match the arguments of the matching while
92 if (lff.Arguments.size() == 0 ||
93 lff.Arguments == this->Args)
95 return true;
98 return false;
101 bool cmWhileCommand
102 ::InvokeInitialPass(const std::vector<cmListFileArgument>& args,
103 cmExecutionStatus &)
105 if(args.size() < 1)
107 this->SetError("called with incorrect number of arguments");
108 return false;
111 // create a function blocker
112 cmWhileFunctionBlocker *f = new cmWhileFunctionBlocker();
113 f->Args = args;
114 this->Makefile->AddFunctionBlocker(f);
116 return true;