Merge topic 'clean-up-cmMacroCommand'

b5f98e50 cmMacroCommand: Manipulate target string directly.
83414d5a cmMacroCommand: Move computation of ARGV%n names out of double loop.
9a1f8f35 cmMacroCommand: Move ARGV replacement out of condition.
4aa7bd2a cmMacroCommand: Remove condition around ARGN replacement.
6774c92b cmMacroCommand: Declare tmps in the scope that it's used.
2c4a7298 cmMacroCommand: Declare arg in the scope that it is used.
a551851a cmMacroCommand: Inline variable computation.
f79c0f76 cmMacroCommand: Compute variables outside of two loops.
8e0827b6 cmMacroCommand: Remove intermediate arg variables.
f2c49f59 cmMacroCommand: Remove condition around ARGN computation.
3250a7e5 cmMacroCommand: Remove conditional append of semicolon.
081a13f7 cmMacroCommand: Declare arg variables where used and initialized.
17b5ebd3 cmMacroCommand: Join the args strings outside of the loops.
This commit is contained in:
Brad King 2015-02-12 11:53:11 -05:00 committed by CMake Topic Stage
commit 32821bb319
1 changed files with 32 additions and 61 deletions

View File

@ -84,10 +84,6 @@ bool cmMacroHelperCommand::InvokeInitialPass
std::vector<std::string> expandedArgs; std::vector<std::string> expandedArgs;
this->Makefile->ExpandArguments(args, expandedArgs); this->Makefile->ExpandArguments(args, expandedArgs);
std::string tmps;
cmListFileArgument arg;
std::string variable;
// make sure the number of arguments passed is at least the number // make sure the number of arguments passed is at least the number
// required by the signature // required by the signature
if (expandedArgs.size() < this->Args.size() - 1) if (expandedArgs.size() < this->Args.size() - 1)
@ -111,11 +107,24 @@ bool cmMacroHelperCommand::InvokeInitialPass
argcDefStream << expandedArgs.size(); argcDefStream << expandedArgs.size();
std::string argcDef = argcDefStream.str(); std::string argcDef = argcDefStream.str();
// declare varuiables for ARGV ARGN but do not compute until needed std::vector<std::string>::const_iterator eit
std::string argvDef; = expandedArgs.begin() + (this->Args.size() - 1);
std::string argnDef; std::string expandedArgn = cmJoin(cmRange(eit, expandedArgs.end()), ";");
bool argnDefInitialized = false; std::string expandedArgv = cmJoin(expandedArgs, ";");
bool argvDefInitialized = false; std::vector<std::string> variables;
variables.reserve(this->Args.size() - 1);
for (unsigned int j = 1; j < this->Args.size(); ++j)
{
variables.push_back("${" + this->Args[j] + "}");
}
std::vector<std::string> argVs;
argVs.reserve(expandedArgs.size());
char argvName[60];
for (unsigned int j = 0; j < expandedArgs.size(); ++j)
{
sprintf(argvName,"${ARGV%i}",j);
argVs.push_back(argvName);
}
if(!this->Functions.empty()) if(!this->Functions.empty())
{ {
this->FilePath = this->Functions[0].FilePath; this->FilePath = this->Functions[0].FilePath;
@ -140,73 +149,35 @@ bool cmMacroHelperCommand::InvokeInitialPass
// Set the FilePath on the arguments to match the function since it is // Set the FilePath on the arguments to match the function since it is
// not stored and the original values may be freed // not stored and the original values may be freed
k->FilePath = this->FilePath.c_str(); k->FilePath = this->FilePath.c_str();
if(k->Delim == cmListFileArgument::Bracket)
{ cmListFileArgument arg;
arg.Value = k->Value; arg.Value = k->Value;
} if(k->Delim != cmListFileArgument::Bracket)
else
{ {
tmps = k->Value;
// replace formal arguments // replace formal arguments
for (unsigned int j = 1; j < this->Args.size(); ++j) for (unsigned int j = 0; j < variables.size(); ++j)
{ {
variable = "${"; cmSystemTools::ReplaceString(arg.Value, variables[j].c_str(),
variable += this->Args[j]; expandedArgs[j].c_str());
variable += "}";
cmSystemTools::ReplaceString(tmps, variable.c_str(),
expandedArgs[j-1].c_str());
} }
// replace argc // replace argc
cmSystemTools::ReplaceString(tmps, "${ARGC}",argcDef.c_str()); cmSystemTools::ReplaceString(arg.Value, "${ARGC}",argcDef.c_str());
// repleace ARGN cmSystemTools::ReplaceString(arg.Value, "${ARGN}",
if (tmps.find("${ARGN}") != std::string::npos) expandedArgn.c_str());
{ cmSystemTools::ReplaceString(arg.Value, "${ARGV}",
if (!argnDefInitialized) expandedArgv.c_str());
{
if (expandedArgs.size() > this->Args.size() - 1)
{
if (!argnDef.empty() && !expandedArgs.empty())
{
argnDef += ";";
}
std::vector<std::string>::const_iterator eit
= expandedArgs.begin() + (this->Args.size() - 1);
argnDef += cmJoin(cmRange(eit, expandedArgs.end()), ";");
}
argnDefInitialized = true;
}
cmSystemTools::ReplaceString(tmps, "${ARGN}", argnDef.c_str());
}
// if the current argument of the current function has ${ARGV in it // if the current argument of the current function has ${ARGV in it
// then try replacing ARGV values // then try replacing ARGV values
if (tmps.find("${ARGV") != std::string::npos) if (arg.Value.find("${ARGV") != std::string::npos)
{ {
char argvName[60];
// repleace ARGV, compute it only once
if (!argvDefInitialized)
{
if (!argvDef.empty() && !expandedArgs.empty())
{
argvDef += ";";
}
argvDef += cmJoin(expandedArgs, ";");
argvDefInitialized = true;
}
cmSystemTools::ReplaceString(tmps, "${ARGV}", argvDef.c_str());
// also replace the ARGV1 ARGV2 ... etc
for (unsigned int t = 0; t < expandedArgs.size(); ++t) for (unsigned int t = 0; t < expandedArgs.size(); ++t)
{ {
sprintf(argvName,"${ARGV%i}",t); cmSystemTools::ReplaceString(arg.Value, argVs[t].c_str(),
cmSystemTools::ReplaceString(tmps, argvName,
expandedArgs[t].c_str()); expandedArgs[t].c_str());
} }
} }
arg.Value = tmps;
} }
arg.Delim = k->Delim; arg.Delim = k->Delim;
arg.FilePath = k->FilePath; arg.FilePath = k->FilePath;