Browse Source

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.
Brad King 10 years ago
parent
commit
32821bb319
1 changed files with 32 additions and 61 deletions
  1. 32 61
      Source/cmMacroCommand.cxx

+ 32 - 61
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;