[Cmake-commits] [cmake-commits] king committed cmForEachCommand.cxx 1.30 1.31 cmForEachCommand.h 1.21 1.22

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Mar 17 15:10:17 EDT 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv11323/Source

Modified Files:
	cmForEachCommand.cxx cmForEachCommand.h 
Log Message:
ENH: New foreach(<var> IN ...) mode

This creates a new mode of the foreach command which allows precise
iteration even over empty elements.  This mode may be safely extended
with more keyword arguments in the future.  The cost now is possibly
breaking scripts that iterate over a list of items beginning with 'IN',
but there is no other way to extend the syntax in a readable way.


Index: cmForEachCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmForEachCommand.cxx,v
retrieving revision 1.30
retrieving revision 1.31
diff -C 2 -d -r1.30 -r1.31
*** cmForEachCommand.cxx	21 Jan 2009 14:49:00 -0000	1.30
--- cmForEachCommand.cxx	17 Mar 2009 19:10:15 -0000	1.31
***************
*** 17,20 ****
--- 17,22 ----
  #include "cmForEachCommand.h"
  
+ #include <cmsys/auto_ptr.hxx>
+ 
  bool cmForEachFunctionBlocker::
  IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
***************
*** 117,120 ****
--- 119,126 ----
      return false;
      }
+   if(args.size() > 1 && args[1] == "IN")
+     {
+     return this->HandleInMode(args);
+     }
    
    // create a function blocker
***************
*** 198,199 ****
--- 204,247 ----
  }
  
+ //----------------------------------------------------------------------------
+ bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args)
+ {
+   cmsys::auto_ptr<cmForEachFunctionBlocker> f(new cmForEachFunctionBlocker());
+   f->Args.push_back(args[0]);
+ 
+   enum Doing { DoingNone, DoingLists, DoingItems };
+   Doing doing = DoingNone;
+   for(unsigned int i=2; i < args.size(); ++i)
+     {
+     if(doing == DoingItems)
+       {
+       f->Args.push_back(args[i]);
+       }
+     else if(args[i] == "LISTS")
+       {
+       doing = DoingLists;
+       }
+     else if(args[i] == "ITEMS")
+       {
+       doing = DoingItems;
+       }
+     else if(doing == DoingLists)
+       {
+       const char* value = this->Makefile->GetDefinition(args[i].c_str());
+       if(value && *value)
+         {
+         cmSystemTools::ExpandListArgument(value, f->Args, true);
+         }
+       }
+     else
+       {
+       cmOStringStream e;
+       e << "Unknown argument:\n" << "  " << args[i] << "\n";
+       this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+       return true;
+       }
+     }
+ 
+   this->Makefile->AddFunctionBlocker(f.release()); // TODO: pass auto_ptr
+   return true;
+ }

Index: cmForEachCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmForEachCommand.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -C 2 -d -r1.21 -r1.22
*** cmForEachCommand.h	21 Jan 2009 14:48:16 -0000	1.21
--- cmForEachCommand.h	17 Mar 2009 19:10:15 -0000	1.22
***************
*** 95,100 ****
        "    ...\n"
        "  endforeach(loop_var)\n"
-       "  foreach(loop_var RANGE total)\n"
-       "  foreach(loop_var RANGE start stop [step])\n"
        "All commands between foreach and the matching endforeach are recorded "
        "without being invoked.  Once the endforeach is evaluated, the "
--- 95,98 ----
***************
*** 103,106 ****
--- 101,106 ----
        "\"${loop_var}\" will be set as a variable with "
        "the current value in the list.\n"
+       "  foreach(loop_var RANGE total)\n"
+       "  foreach(loop_var RANGE start stop [step])\n"
        "Foreach can also iterate over a generated range of numbers. "
        "There are three types of this iteration:\n"
***************
*** 110,117 ****
        "the first number to the second number.\n"
        "* The third optional number is the increment used to iterate from "
!       "the first number to the second number.";
      }
    
    cmTypeMacro(cmForEachCommand, cmCommand);
  };
  
--- 110,128 ----
        "the first number to the second number.\n"
        "* The third optional number is the increment used to iterate from "
!       "the first number to the second number."
!       "\n"
!       "  foreach(loop_var IN [LISTS [list1 [...]]]\n"
!       "                      [ITEMS [item1 [...]]])\n"
!       "Iterates over a precise list of items.  "
!       "The LISTS option names list-valued variables to be traversed, "
!       "including empty elements (an empty string is a zero-length list).  "
!       "The ITEMS option ends argument parsing and includes all arguments "
!       "following it in the iteration."
!       ;
      }
    
    cmTypeMacro(cmForEachCommand, cmCommand);
+ private:
+   bool HandleInMode(std::vector<std::string> const& args);
  };
  



More information about the Cmake-commits mailing list