fixed if statements inside a foreach

This commit is contained in:
Ken Martin 2002-07-17 10:48:39 -04:00
parent 3d3caacf9e
commit fcc410de44
6 changed files with 26 additions and 17 deletions

View File

@ -21,10 +21,16 @@ bool cmForEachFunctionBlocker::
IsFunctionBlocked(const char *name, const std::vector<std::string> &args, IsFunctionBlocked(const char *name, const std::vector<std::string> &args,
cmMakefile &mf) cmMakefile &mf)
{ {
// prevent recusion and don't let this blobker blobk its own commands
if (m_Executing)
{
return false;
}
// at end of for each execute recorded commands // at end of for each execute recorded commands
if (!strcmp(name,"ENDFOREACH") && args[0] == m_Args[0]) if (!strcmp(name,"ENDFOREACH") && args[0] == m_Args[0])
{ {
m_Executing = true;
std::string variable = "${"; std::string variable = "${";
variable += m_Args[0]; variable += m_Args[0];
variable += "}"; variable += "}";
@ -90,7 +96,7 @@ bool cmForEachCommand::InitialPass(std::vector<std::string> const& argsIn)
std::vector<std::string> args; std::vector<std::string> args;
cmSystemTools::ExpandListArguments(argsIn, args); cmSystemTools::ExpandListArguments(argsIn, args);
if(args.size() < 2 ) if(args.size() < 1)
{ {
this->SetError("called with incorrect number of arguments"); this->SetError("called with incorrect number of arguments");
return false; return false;

View File

@ -29,7 +29,7 @@
class cmForEachFunctionBlocker : public cmFunctionBlocker class cmForEachFunctionBlocker : public cmFunctionBlocker
{ {
public: public:
cmForEachFunctionBlocker() {} cmForEachFunctionBlocker() {m_Executing = false;}
virtual ~cmForEachFunctionBlocker() {} virtual ~cmForEachFunctionBlocker() {}
virtual bool IsFunctionBlocked(const char *name, virtual bool IsFunctionBlocked(const char *name,
const std::vector<std::string> &args, const std::vector<std::string> &args,
@ -44,6 +44,7 @@ public:
std::vector<std::string> m_Args; std::vector<std::string> m_Args;
std::vector<std::string> m_Commands; std::vector<std::string> m_Commands;
std::vector<std::vector<std::string> > m_CommandArguments; std::vector<std::vector<std::string> > m_CommandArguments;
bool m_Executing;
}; };
/** \class cmForEachCommand /** \class cmForEachCommand

View File

@ -193,6 +193,12 @@ bool cmMakefile::CommandExists(const char* name) const
void cmMakefile::ExecuteCommand(std::string &name, void cmMakefile::ExecuteCommand(std::string &name,
std::vector<std::string> const& arguments) std::vector<std::string> const& arguments)
{ {
// quick return if blocked
if(this->IsFunctionBlocked(name.c_str(), arguments))
{
return;
}
// execute the command
RegisteredCommandsMap::iterator pos = m_Commands.find(name); RegisteredCommandsMap::iterator pos = m_Commands.find(name);
if(pos != m_Commands.end()) if(pos != m_Commands.end())
{ {
@ -342,13 +348,9 @@ bool cmMakefile::ReadListFile(const char* filename, const char* external)
for(size_t i =0; i < numberFunctions; ++i) for(size_t i =0; i < numberFunctions; ++i)
{ {
cmListFileFunction& curFunction = lf->m_Functions[i]; cmListFileFunction& curFunction = lf->m_Functions[i];
if(!this->IsFunctionBlocked(curFunction.m_Name.c_str(),
curFunction.m_Arguments))
{
this->ExecuteCommand(curFunction.m_Name, this->ExecuteCommand(curFunction.m_Name,
curFunction.m_Arguments); curFunction.m_Arguments);
} }
}
// send scope ended to and funciton blockers // send scope ended to and funciton blockers
if (filename) if (filename)

View File

@ -164,13 +164,13 @@ REMOVE(REMOVE_STRING ${removeVar1} f)
# Test an IF inside a FOREACH. # Test an IF inside a FOREACH.
# #
FOREACH(x "a") FOREACH(x "a")
IF(1) IF(${x} MATCHES "a")
# Should always execute. # Should always execute.
SET(IF_INSIDE_FOREACH_THEN_EXECUTED 1) SET(IF_INSIDE_FOREACH_THEN_EXECUTED 1)
ELSE(1) ELSE(${x} MATCHES "a")
# Should never execute. # Should never execute.
SET(IF_INSIDE_FOREACH_ELSE_EXECUTED 1) SET(IF_INSIDE_FOREACH_ELSE_EXECUTED 1)
ENDIF(1) ENDIF(${x} MATCHES "a")
ENDFOREACH(x) ENDFOREACH(x)

View File

@ -164,13 +164,13 @@ REMOVE(REMOVE_STRING ${removeVar1} f)
# Test an IF inside a FOREACH. # Test an IF inside a FOREACH.
# #
FOREACH(x "a") FOREACH(x "a")
IF(1) IF(${x} MATCHES "a")
# Should always execute. # Should always execute.
SET(IF_INSIDE_FOREACH_THEN_EXECUTED 1) SET(IF_INSIDE_FOREACH_THEN_EXECUTED 1)
ELSE(1) ELSE(${x} MATCHES "a")
# Should never execute. # Should never execute.
SET(IF_INSIDE_FOREACH_ELSE_EXECUTED 1) SET(IF_INSIDE_FOREACH_ELSE_EXECUTED 1)
ENDIF(1) ENDIF(${x} MATCHES "a")
ENDFOREACH(x) ENDFOREACH(x)

View File

@ -164,13 +164,13 @@ REMOVE(REMOVE_STRING ${removeVar1} f)
# Test an IF inside a FOREACH. # Test an IF inside a FOREACH.
# #
FOREACH(x "a") FOREACH(x "a")
IF(1) IF(${x} MATCHES "a")
# Should always execute. # Should always execute.
SET(IF_INSIDE_FOREACH_THEN_EXECUTED 1) SET(IF_INSIDE_FOREACH_THEN_EXECUTED 1)
ELSE(1) ELSE(${x} MATCHES "a")
# Should never execute. # Should never execute.
SET(IF_INSIDE_FOREACH_ELSE_EXECUTED 1) SET(IF_INSIDE_FOREACH_ELSE_EXECUTED 1)
ENDIF(1) ENDIF(${x} MATCHES "a")
ENDFOREACH(x) ENDFOREACH(x)