1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmWhileCommand.cxx,v $
6 Date: $Date: 2009-06-12 14:07:05 $
7 Version: $Revision: 1.18 $
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
30 else if (!cmSystemTools::Strucmp(lff
.Name
.c_str(),"endwhile"))
32 // if this is the endwhile for this while loop then execute
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 cmake::MessageType messageType
;
46 cmIfCommand::IsTrue(expandedArguments
,errorString
,
51 if (errorString
.size())
53 std::string err
= "had incorrect arguments: ";
55 for(i
=0; i
< this->Args
.size(); ++i
)
57 err
+= (this->Args
[i
].Quoted
?"\"":"");
58 err
+= this->Args
[i
].Value
;
59 err
+= (this->Args
[i
].Quoted
?"\"":"");
65 mf
.IssueMessage(messageType
, err
);
66 if (messageType
== cmake::FATAL_ERROR
)
68 cmSystemTools::SetFatalErrorOccured();
73 // Invoke all the functions that were collected in the block.
74 for(unsigned int c
= 0; c
< this->Functions
.size(); ++c
)
76 cmExecutionStatus status
;
77 mf
.ExecuteCommand(this->Functions
[c
],status
);
78 if (status
.GetReturnInvoked())
80 inStatus
.SetReturnInvoked(true);
83 if (status
.GetBreakInvoked())
87 if(cmSystemTools::GetFatalErrorOccured() )
92 expandedArguments
.clear();
93 mf
.ExpandArguments(this->Args
, expandedArguments
);
95 cmIfCommand::IsTrue(expandedArguments
,errorString
,
102 // decrement for each nested while that ends
107 // record the command
108 this->Functions
.push_back(lff
);
110 // always return true
114 bool cmWhileFunctionBlocker::
115 ShouldRemove(const cmListFileFunction
& lff
, cmMakefile
& )
117 if(!cmSystemTools::Strucmp(lff
.Name
.c_str(),"endwhile"))
119 // if the endwhile has arguments, then make sure
120 // they match the arguments of the matching while
121 if (lff
.Arguments
.size() == 0 ||
122 lff
.Arguments
== this->Args
)
131 ::InvokeInitialPass(const std::vector
<cmListFileArgument
>& args
,
136 this->SetError("called with incorrect number of arguments");
140 // create a function blocker
141 cmWhileFunctionBlocker
*f
= new cmWhileFunctionBlocker();
143 this->Makefile
->AddFunctionBlocker(f
);