diff options
author | Brad King <brad.king@kitware.com> | 2015-02-12 16:53:11 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2015-02-12 16:53:11 (GMT) |
commit | 32821bb3190a9539ebe98fb7dfa0ba7c7a890ff7 (patch) | |
tree | 63c24dfd0ca0446bc206f1bc747bb5d92a544e37 | |
parent | e6ae3c6ae0540de51b3d615aea3abd49ccc70a34 (diff) | |
parent | b5f98e5012ef53ee6746c42131fc66892bfff717 (diff) | |
download | CMake-32821bb3190a9539ebe98fb7dfa0ba7c7a890ff7.zip CMake-32821bb3190a9539ebe98fb7dfa0ba7c7a890ff7.tar.gz CMake-32821bb3190a9539ebe98fb7dfa0ba7c7a890ff7.tar.bz2 |
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.
-rw-r--r-- | Source/cmMacroCommand.cxx | 93 |
1 files changed, 32 insertions, 61 deletions
diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 8f6364d..29e8cb1 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -84,10 +84,6 @@ bool cmMacroHelperCommand::InvokeInitialPass std::vector<std::string> 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 // required by the signature if (expandedArgs.size() < this->Args.size() - 1) @@ -111,11 +107,24 @@ bool cmMacroHelperCommand::InvokeInitialPass argcDefStream << expandedArgs.size(); std::string argcDef = argcDefStream.str(); - // declare varuiables for ARGV ARGN but do not compute until needed - std::string argvDef; - std::string argnDef; - bool argnDefInitialized = false; - bool argvDefInitialized = false; + std::vector<std::string>::const_iterator eit + = expandedArgs.begin() + (this->Args.size() - 1); + std::string expandedArgn = cmJoin(cmRange(eit, expandedArgs.end()), ";"); + std::string expandedArgv = cmJoin(expandedArgs, ";"); + 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()) { 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 // not stored and the original values may be freed k->FilePath = this->FilePath.c_str(); - if(k->Delim == cmListFileArgument::Bracket) - { - arg.Value = k->Value; - } - else + + cmListFileArgument arg; + arg.Value = k->Value; + if(k->Delim != cmListFileArgument::Bracket) { - tmps = k->Value; // replace formal arguments - for (unsigned int j = 1; j < this->Args.size(); ++j) + for (unsigned int j = 0; j < variables.size(); ++j) { - variable = "${"; - variable += this->Args[j]; - variable += "}"; - cmSystemTools::ReplaceString(tmps, variable.c_str(), - expandedArgs[j-1].c_str()); + cmSystemTools::ReplaceString(arg.Value, variables[j].c_str(), + expandedArgs[j].c_str()); } // replace argc - cmSystemTools::ReplaceString(tmps, "${ARGC}",argcDef.c_str()); + cmSystemTools::ReplaceString(arg.Value, "${ARGC}",argcDef.c_str()); - // repleace ARGN - if (tmps.find("${ARGN}") != std::string::npos) - { - if (!argnDefInitialized) - { - 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()); - } + cmSystemTools::ReplaceString(arg.Value, "${ARGN}", + expandedArgn.c_str()); + cmSystemTools::ReplaceString(arg.Value, "${ARGV}", + expandedArgv.c_str()); // if the current argument of the current function has ${ARGV in it // 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) { - sprintf(argvName,"${ARGV%i}",t); - cmSystemTools::ReplaceString(tmps, argvName, + cmSystemTools::ReplaceString(arg.Value, argVs[t].c_str(), expandedArgs[t].c_str()); } } - - arg.Value = tmps; } arg.Delim = k->Delim; arg.FilePath = k->FilePath; |