ENH: allow loose loop constructs
This commit is contained in:
parent
095e975c81
commit
29a03db7ce
|
@ -26,13 +26,17 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (cmSystemTools::LowerCase(lff.Name) == "foreach")
|
||||
{
|
||||
// record the number of nested foreach commands
|
||||
this->Depth++;
|
||||
}
|
||||
else if (cmSystemTools::LowerCase(lff.Name) == "endforeach")
|
||||
{
|
||||
// if this is the endofreach for this statement
|
||||
if (!this->Depth)
|
||||
{
|
||||
// at end of for each execute recorded commands
|
||||
if (cmSystemTools::LowerCase(lff.Name) == "endforeach")
|
||||
{
|
||||
std::vector<std::string> expandedArguments;
|
||||
mf.ExpandArguments(lff.Arguments, expandedArguments);
|
||||
if(!expandedArguments.empty() && (expandedArguments[0] == this->Args[0]))
|
||||
{
|
||||
// store the old value
|
||||
std::string oldDef;
|
||||
if (mf.GetDefinition(this->Args[0].c_str()))
|
||||
|
@ -60,6 +64,11 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
|||
mf.RemoveFunctionBlocker(lff);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// close out a nested foreach
|
||||
this->Depth--;
|
||||
}
|
||||
}
|
||||
|
||||
// record the command
|
||||
|
@ -76,7 +85,9 @@ ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf)
|
|||
{
|
||||
std::vector<std::string> expandedArguments;
|
||||
mf.ExpandArguments(lff.Arguments, expandedArguments);
|
||||
if(!expandedArguments.empty() && (expandedArguments[0] == this->Args[0]))
|
||||
if ((!expandedArguments.empty() &&
|
||||
(expandedArguments[0] == this->Args[0]))
|
||||
|| mf.IsOn("CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
class cmForEachFunctionBlocker : public cmFunctionBlocker
|
||||
{
|
||||
public:
|
||||
cmForEachFunctionBlocker() {this->Executing = false;}
|
||||
cmForEachFunctionBlocker() {this->Executing = false; Depth = 0;}
|
||||
virtual ~cmForEachFunctionBlocker() {}
|
||||
virtual bool IsFunctionBlocked(const cmListFileFunction& lff,
|
||||
cmMakefile &mf);
|
||||
|
@ -39,6 +39,8 @@ public:
|
|||
std::vector<std::string> Args;
|
||||
std::vector<cmListFileFunction> Functions;
|
||||
bool Executing;
|
||||
private:
|
||||
int Depth;
|
||||
};
|
||||
|
||||
/** \class cmForEachCommand
|
||||
|
|
|
@ -34,8 +34,6 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
|||
if (cmSystemTools::LowerCase(lff.Name) == "else" ||
|
||||
cmSystemTools::LowerCase(lff.Name) == "endif")
|
||||
{
|
||||
if (args == this->Args)
|
||||
{
|
||||
// if it was an else statement then we should change state
|
||||
// and block this Else Command
|
||||
if (cmSystemTools::LowerCase(lff.Name) == "else")
|
||||
|
@ -48,39 +46,22 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
|||
mf.RemoveFunctionBlocker(lff);
|
||||
return true;
|
||||
}
|
||||
else if(args.empty())
|
||||
{
|
||||
std::string err = "Empty arguments for ";
|
||||
err += name;
|
||||
err += ". Did you mean ";
|
||||
err += name;
|
||||
err += "( ";
|
||||
for(std::vector<cmListFileArgument>::const_iterator a =
|
||||
this->Args.begin();
|
||||
a != this->Args.end();++a)
|
||||
{
|
||||
err += (a->Quoted?"\"":"");
|
||||
err += a->Value;
|
||||
err += (a->Quoted?"\"":"");
|
||||
err += " ";
|
||||
}
|
||||
err += ")?";
|
||||
cmSystemTools::Error(err.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return this->IsBlocking;
|
||||
}
|
||||
|
||||
bool cmIfFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
|
||||
cmMakefile&)
|
||||
cmMakefile& mf)
|
||||
{
|
||||
if (cmSystemTools::LowerCase(lff.Name) == "endif")
|
||||
{
|
||||
if (lff.Arguments == this->Args)
|
||||
if (mf.IsOn("CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS")
|
||||
|| lff.Arguments == this->Args)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,15 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
|||
}
|
||||
|
||||
// at end of for each execute recorded commands
|
||||
if (cmSystemTools::LowerCase(lff.Name) == "endwhile")
|
||||
if (cmSystemTools::LowerCase(lff.Name) == "while")
|
||||
{
|
||||
// record the number of while commands past this one
|
||||
this->Depth++;
|
||||
}
|
||||
else if (cmSystemTools::LowerCase(lff.Name) == "endwhile")
|
||||
{
|
||||
// if this is the endwhile for this while loop then execute
|
||||
if (!this->Depth)
|
||||
{
|
||||
char* errorString = 0;
|
||||
|
||||
|
@ -53,6 +61,12 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
|||
mf.RemoveFunctionBlocker(lff);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// decrement for each nested while that ends
|
||||
this->Depth--;
|
||||
}
|
||||
}
|
||||
|
||||
// record the command
|
||||
this->Functions.push_back(lff);
|
||||
|
@ -62,11 +76,12 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
|||
}
|
||||
|
||||
bool cmWhileFunctionBlocker::
|
||||
ShouldRemove(const cmListFileFunction& lff, cmMakefile& )
|
||||
ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf)
|
||||
{
|
||||
if(cmSystemTools::LowerCase(lff.Name) == "endwhile")
|
||||
{
|
||||
if (lff.Arguments == this->Args)
|
||||
if (lff.Arguments == this->Args
|
||||
|| mf.IsOn("CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
class cmWhileFunctionBlocker : public cmFunctionBlocker
|
||||
{
|
||||
public:
|
||||
cmWhileFunctionBlocker() {Executing = false;}
|
||||
cmWhileFunctionBlocker() {Executing = false; Depth=0;}
|
||||
virtual ~cmWhileFunctionBlocker() {}
|
||||
virtual bool IsFunctionBlocked(const cmListFileFunction& lff,
|
||||
cmMakefile &mf);
|
||||
|
@ -39,6 +39,8 @@ public:
|
|||
std::vector<cmListFileArgument> Args;
|
||||
std::vector<cmListFileFunction> Functions;
|
||||
bool Executing;
|
||||
private:
|
||||
int Depth;
|
||||
};
|
||||
|
||||
/** \class cmWhileCommand
|
||||
|
|
Loading…
Reference in New Issue