[cfe-commits] r67676 - in /cfe/trunk: include/clang/Driver/ArgList.h include/clang/Driver/Compilation.h include/clang/Driver/Driver.h include/clang/Driver/Option.h include/clang/Driver/Options.h include/clang/Driver/ToolChain.h lib/Driver/ArgList.cpp lib/Driver/Compilation.cpp lib/Driver/Driver.cpp lib/Driver/OptTable.cpp lib/Driver/Option.cpp lib/Driver/ToolChains.cpp lib/Driver/ToolChains.h

Daniel Dunbar daniel at zuster.org
Tue Mar 24 21:13:46 PDT 2009


Author: ddunbar
Date: Tue Mar 24 23:13:45 2009
New Revision: 67676

URL: http://llvm.org/viewvc/llvm-project?rev=67676&view=rev
Log:
Driver: Prep for tool chain specific argument translation.
 - Lift ArgList to a base class for InputArgList and DerivedArgList.
 
 - This is not a great decomposition, but it does embed the
   translation into the type system, and keep things efficient for
   tool chains that don't want to do any translation.

 - No intended functionality change.

Eventually I hope to get rid of tool chain specific translation and
have each tool do the right thing, but for now this is the easiest way
to match gcc precisely (which is good for testing).

Modified:
    cfe/trunk/include/clang/Driver/ArgList.h
    cfe/trunk/include/clang/Driver/Compilation.h
    cfe/trunk/include/clang/Driver/Driver.h
    cfe/trunk/include/clang/Driver/Option.h
    cfe/trunk/include/clang/Driver/Options.h
    cfe/trunk/include/clang/Driver/ToolChain.h
    cfe/trunk/lib/Driver/ArgList.cpp
    cfe/trunk/lib/Driver/Compilation.cpp
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Driver/OptTable.cpp
    cfe/trunk/lib/Driver/Option.cpp
    cfe/trunk/lib/Driver/ToolChains.cpp
    cfe/trunk/lib/Driver/ToolChains.h

Modified: cfe/trunk/include/clang/Driver/ArgList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ArgList.h?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/ArgList.h (original)
+++ cfe/trunk/include/clang/Driver/ArgList.h Tue Mar 24 23:13:45 2009
@@ -36,30 +36,23 @@
     typedef arglist_type::const_reverse_iterator const_reverse_iterator;
 
   private:
-    /// List of argument strings used by the contained Args.
-    ///
-    /// This is mutable since we treat the ArgList as being the list
-    /// of Args, and allow routines to add new strings (to have a
-    /// convenient place to store the memory) via MakeIndex.
-    mutable ArgStringList ArgStrings;
-
-    /// Strings for synthesized arguments.
-    ///
-    /// This is mutable since we treat the ArgList as being the list
-    /// of Args, and allow routines to add new strings (to have a
-    /// convenient place to store the memory) via MakeIndex.
-    mutable std::list<std::string> SynthesizedStrings;
-
     /// The full list of arguments.
-    arglist_type Args;
+    arglist_type &Args;
 
-    /// The number of original input argument strings.
-    unsigned NumInputArgStrings;
+  protected:
+    ArgList(arglist_type &Args);
 
   public:
-    ArgList(const char **ArgBegin, const char **ArgEnd);
-    ArgList(const ArgList &);
-    ~ArgList();
+    virtual ~ArgList();
+
+    /// @name Arg Access
+    /// @{
+
+    /// append - Append \arg A to the arg list.
+    void append(Arg *A);
+
+    arglist_type &getArgs() { return Args; }
+    const arglist_type &getArgs() const { return Args; }
 
     unsigned size() const { return Args.size(); }
 
@@ -74,16 +67,6 @@
     
     const_reverse_iterator rbegin() const { return Args.rbegin(); }
     const_reverse_iterator rend() const { return Args.rend(); }
-    
-    /// append - Append \arg A to the arg list, taking ownership.
-    void append(Arg *A);
-
-    /// getArgString - Return the input argument string at \arg Index.
-    const char *getArgString(unsigned Index) const { return ArgStrings[Index]; }
-
-    /// getNumInputArgStrings - Return the number of original input
-    /// argument strings.
-    unsigned getNumInputArgStrings() const { return NumInputArgStrings; }
 
     /// hasArg - Does the arg list contain any option matching \arg Id.
     ///
@@ -98,36 +81,8 @@
     Arg *getLastArg(options::ID Id, bool Claim=true) const;
     Arg *getLastArg(options::ID Id0, options::ID Id1, bool Claim=true) const;
 
-    /// @name Arg Synthesis
-    /// @{
-
-  private:    
-    /// MakeIndex - Get an index for the given string(s).
-    unsigned MakeIndex(const char *String0) const;
-    unsigned MakeIndex(const char *String0, const char *String1) const;
-
-  public:
-    /// MakeArgString - Construct a constant string pointer whose
-    /// lifetime will match that of the ArgList.
-    const char *MakeArgString(const char *Str) const;
-
-    /// MakeFlagArg - Construct a new FlagArg for the given option
-    /// \arg Id.
-    Arg *MakeFlagArg(const Option *Opt) const;
-
-    /// MakePositionalArg - Construct a new Positional arg for the
-    /// given option \arg Id, with the provided \arg Value.
-    Arg *MakePositionalArg(const Option *Opt, const char *Value) const;
-
-    /// MakeSeparateArg - Construct a new Positional arg for the
-    /// given option \arg Id, with the provided \arg Value.
-    Arg *MakeSeparateArg(const Option *Opt, const char *Value) const;
-
-    /// MakeJoinedArg - Construct a new Positional arg for the
-    /// given option \arg Id, with the provided \arg Value.
-    Arg *MakeJoinedArg(const Option *Opt, const char *Value) const;
-
-    /// @}
+    /// getArgString - Return the input argument string at \arg Index.
+    virtual const char *getArgString(unsigned Index) const = 0;
     /// @name Translation Utilities
     /// @{
 
@@ -156,7 +111,114 @@
                          options::ID Id1) const;
 
     /// @}
+    /// @name Arg Synthesis
+    /// @{
+
+    /// MakeArgString - Construct a constant string pointer whose
+    /// lifetime will match that of the ArgList.
+    virtual const char *MakeArgString(const char *Str) const = 0;
+
+    /// @}
   };
+
+  class InputArgList : public ArgList  {
+  private:
+    /// The internal list of arguments.
+    arglist_type ActualArgs;
+
+    /// List of argument strings used by the contained Args.
+    ///
+    /// This is mutable since we treat the ArgList as being the list
+    /// of Args, and allow routines to add new strings (to have a
+    /// convenient place to store the memory) via MakeIndex.
+    mutable ArgStringList ArgStrings;
+
+    /// Strings for synthesized arguments.
+    ///
+    /// This is mutable since we treat the ArgList as being the list
+    /// of Args, and allow routines to add new strings (to have a
+    /// convenient place to store the memory) via MakeIndex.
+    mutable std::list<std::string> SynthesizedStrings;
+
+    /// The number of original input argument strings.
+    unsigned NumInputArgStrings;
+
+  public:
+    InputArgList(const char **ArgBegin, const char **ArgEnd);
+    InputArgList(const ArgList &);
+    ~InputArgList();
+
+    virtual const char *getArgString(unsigned Index) const { 
+      return ArgStrings[Index]; 
+    }
+
+    /// getNumInputArgStrings - Return the number of original input
+    /// argument strings.
+    unsigned getNumInputArgStrings() const { return NumInputArgStrings; }
+
+    /// @name Arg Synthesis
+    /// @{
+
+  public:
+    /// MakeIndex - Get an index for the given string(s).
+    unsigned MakeIndex(const char *String0) const;
+    unsigned MakeIndex(const char *String0, const char *String1) const;
+
+    virtual const char *MakeArgString(const char *Str) const;
+
+    /// @}
+  };
+
+  /// DerivedArgList - An ordered collection of driver arguments,
+  /// whose storage may be in another argument list.
+  class DerivedArgList : public ArgList {
+    InputArgList &BaseArgs;
+
+    /// The internal list of arguments.
+    arglist_type ActualArgs;
+
+    /// The list of arguments we synthesized.
+    arglist_type SynthesizedArgs;
+
+    /// Is this only a proxy for the base ArgList?
+    bool OnlyProxy;
+
+  public:
+    /// Construct a new derived arg list from \arg BaseArgs.
+    ///
+    /// \param OnlyProxy - If true, this is only a proxy for the base
+    /// list (to adapt the type), and it's Args list is unused.
+    DerivedArgList(InputArgList &BaseArgs, bool OnlyProxy);
+    ~DerivedArgList();
+
+    virtual const char *getArgString(unsigned Index) const {
+      return BaseArgs.getArgString(Index); 
+    }
+
+    /// @name Arg Synthesis
+    /// @{
+
+    virtual const char *MakeArgString(const char *Str) const;
+
+    /// MakeFlagArg - Construct a new FlagArg for the given option
+    /// \arg Id.
+    Arg *MakeFlagArg(const Option *Opt) const;
+
+    /// MakePositionalArg - Construct a new Positional arg for the
+    /// given option \arg Id, with the provided \arg Value.
+    Arg *MakePositionalArg(const Option *Opt, const char *Value) const;
+
+    /// MakeSeparateArg - Construct a new Positional arg for the
+    /// given option \arg Id, with the provided \arg Value.
+    Arg *MakeSeparateArg(const Option *Opt, const char *Value) const;
+
+    /// MakeJoinedArg - Construct a new Positional arg for the
+    /// given option \arg Id, with the provided \arg Value.
+    Arg *MakeJoinedArg(const Option *Opt, const char *Value) const;
+
+    /// @}
+  };
+
 } // end namespace driver
 } // end namespace clang
 

Modified: cfe/trunk/include/clang/Driver/Compilation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Compilation.h?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Compilation.h (original)
+++ cfe/trunk/include/clang/Driver/Compilation.h Tue Mar 24 23:13:45 2009
@@ -22,8 +22,9 @@
 
 namespace clang {
 namespace driver {
-  class ArgList;
+  class DerivedArgList;
   class Driver;
+  class InputArgList;
   class JobList;
   class ToolChain;
 
@@ -37,7 +38,7 @@
   ToolChain &DefaultToolChain;
 
   /// The original (untranslated) input argument list.
-  ArgList *Args;
+  InputArgList *Args;
 
   /// The list of actions.
   ActionList Actions;
@@ -46,7 +47,7 @@
   JobList Jobs;
 
   /// Cache of translated arguments for a particular tool chain.
-  llvm::DenseMap<const ToolChain*, ArgList*> TCArgs;
+  llvm::DenseMap<const ToolChain*, DerivedArgList*> TCArgs;
 
   /// Temporary files which should be removed on exit.
   ArgStringList TempFiles;
@@ -55,24 +56,24 @@
   ArgStringList ResultFiles;
 
 public:
-  Compilation(Driver &D, ToolChain &DefaultToolChain, ArgList *Args);
+  Compilation(Driver &D, ToolChain &DefaultToolChain, InputArgList *Args);
   ~Compilation();
 
   const Driver &getDriver() const { return TheDriver; }
 
   const ToolChain &getDefaultToolChain() const { return DefaultToolChain; }
 
-  const ArgList &getArgs() const { return *Args; }
+  const InputArgList &getArgs() const { return *Args; }
 
   ActionList &getActions() { return Actions; }
   const ActionList &getActions() const { return Actions; }
 
   JobList &getJobs() { return Jobs; }
 
-  /// getArgsForToolChain - Return the argument list, possibly
-  /// translated by the tool chain \arg TC (or by the default tool
-  /// chain, if TC is not specified).
-  const ArgList &getArgsForToolChain(const ToolChain *TC = 0);
+  /// getArgsForToolChain - Return the derived argument list for the
+  /// tool chain \arg TC (or the default tool chain, if TC is not
+  /// specified).
+  const DerivedArgList &getArgsForToolChain(const ToolChain *TC = 0);
 
   /// addTempFile - Add a file to remove on exit, and returns its
   /// argument.

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Tue Mar 24 23:13:45 2009
@@ -27,6 +27,7 @@
   class ArgList;
   class Compilation;
   class HostInfo;
+  class InputArgList;
   class InputInfo;
   class JobAction;
   class OptTable;
@@ -130,7 +131,7 @@
 
   /// ParseArgStrings - Parse the given list of strings into an
   /// ArgList.
-  ArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd);
+  InputArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd);
 
   /// BuildActions - Construct the list of actions to perform for the
   /// given arguments, which are only done for a single architecture.

Modified: cfe/trunk/include/clang/Driver/Option.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Option.h?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Option.h (original)
+++ cfe/trunk/include/clang/Driver/Option.h Tue Mar 24 23:13:45 2009
@@ -22,7 +22,7 @@
 namespace clang {
 namespace driver {
   class Arg;
-  class ArgList;
+  class InputArgList;
   class OptionGroup;
   
   /// Option - Abstract representation for a single form of driver
@@ -140,7 +140,7 @@
     /// If the option accepts the current argument, accept() sets
     /// Index to the position where argument parsing should resume
     /// (even if the argument is missing values).
-    virtual Arg *accept(const ArgList &Args, unsigned &Index) const = 0;
+    virtual Arg *accept(const InputArgList &Args, unsigned &Index) const = 0;
     
     void dump() const;
 
@@ -153,7 +153,7 @@
   public:
     OptionGroup(options::ID ID, const char *Name, const OptionGroup *Group);
 
-    virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
+    virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
 
     static bool classof(const Option *O) { 
       return O->getKind() == Option::GroupClass; 
@@ -168,7 +168,7 @@
   public:
     InputOption();
 
-    virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
+    virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
 
     static bool classof(const Option *O) { 
       return O->getKind() == Option::InputClass; 
@@ -181,7 +181,7 @@
   public:
     UnknownOption();
 
-    virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
+    virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
 
     static bool classof(const Option *O) { 
       return O->getKind() == Option::UnknownClass; 
@@ -196,7 +196,7 @@
     FlagOption(options::ID ID, const char *Name, const OptionGroup *Group, 
                const Option *Alias);
 
-    virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
+    virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
 
     static bool classof(const Option *O) { 
       return O->getKind() == Option::FlagClass; 
@@ -209,7 +209,7 @@
     JoinedOption(options::ID ID, const char *Name, const OptionGroup *Group, 
                  const Option *Alias);
 
-    virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
+    virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
 
     static bool classof(const Option *O) { 
       return O->getKind() == Option::JoinedClass; 
@@ -222,7 +222,7 @@
     SeparateOption(options::ID ID, const char *Name, const OptionGroup *Group, 
                    const Option *Alias);
 
-    virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
+    virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
 
     static bool classof(const Option *O) { 
       return O->getKind() == Option::SeparateClass; 
@@ -235,7 +235,7 @@
     CommaJoinedOption(options::ID ID, const char *Name, 
                       const OptionGroup *Group, const Option *Alias);
 
-    virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
+    virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
 
     static bool classof(const Option *O) { 
       return O->getKind() == Option::CommaJoinedClass; 
@@ -256,7 +256,7 @@
 
     unsigned getNumArgs() const { return NumArgs; }
 
-    virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
+    virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
 
     static bool classof(const Option *O) { 
       return O->getKind() == Option::MultiArgClass; 
@@ -271,7 +271,7 @@
     JoinedOrSeparateOption(options::ID ID, const char *Name, 
                            const OptionGroup *Group, const Option *Alias);
 
-    virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
+    virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
 
     static bool classof(const Option *O) { 
       return O->getKind() == Option::JoinedOrSeparateClass; 
@@ -286,7 +286,7 @@
     JoinedAndSeparateOption(options::ID ID, const char *Name, 
                             const OptionGroup *Group, const Option *Alias);
 
-    virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
+    virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
 
     static bool classof(const Option *O) { 
       return O->getKind() == Option::JoinedAndSeparateClass; 

Modified: cfe/trunk/include/clang/Driver/Options.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.h?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Options.h (original)
+++ cfe/trunk/include/clang/Driver/Options.h Tue Mar 24 23:13:45 2009
@@ -15,8 +15,8 @@
 namespace options {
   enum ID {
     OPT_INVALID = 0, // This is not an option ID.
-    OPT_INPUT,      // Reserved ID for input option.
-    OPT_UNKNOWN,    // Reserved ID for unknown option.
+    OPT_INPUT,       // Reserved ID for input option.
+    OPT_UNKNOWN,     // Reserved ID for unknown option.
 #define OPTION(NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM) OPT_##ID,
 #include "clang/Driver/Options.def"
     LastOption
@@ -25,7 +25,7 @@
 }
   
   class Arg;
-  class ArgList;
+  class InputArgList;
   class Option;
 
   /// OptTable - Provide access to the Option info table.
@@ -70,7 +70,7 @@
     /// \return - The parsed argument, or 0 if the argument is missing
     /// values (in which case Index still points at the conceptual
     /// next argument string to parse).
-    Arg *ParseOneArg(const ArgList &Args, unsigned &Index) const;
+    Arg *ParseOneArg(const InputArgList &Args, unsigned &Index) const;
   };
 }
 }

Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Tue Mar 24 23:13:45 2009
@@ -16,9 +16,10 @@
 
 namespace clang {
 namespace driver {
-  class ArgList;
   class Compilation;
+  class DerivedArgList;
   class HostInfo;
+  class InputArgList;
   class JobAction;
   class Tool;
 
@@ -63,10 +64,7 @@
 
   /// TranslateArgs - Create a new derived argument list for any
   /// argument translations this ToolChain may wish to perform.
-  ///
-  /// The client implementation is free to return Args directly if no
-  /// translations need to be performed.
-  virtual ArgList *TranslateArgs(ArgList &Args) const = 0;
+  virtual DerivedArgList *TranslateArgs(InputArgList &Args) const = 0;
 
   /// SelectTool - Choose a tool to use to handle the action \arg JA.
   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const = 0;

Modified: cfe/trunk/lib/Driver/ArgList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ArgList.cpp?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/ArgList.cpp (original)
+++ cfe/trunk/lib/Driver/ArgList.cpp Tue Mar 24 23:13:45 2009
@@ -13,22 +13,13 @@
 
 using namespace clang::driver;
 
-ArgList::ArgList(const char **ArgBegin, const char **ArgEnd) 
-  : NumInputArgStrings(ArgEnd - ArgBegin) 
-{
-  ArgStrings.append(ArgBegin, ArgEnd);
+ArgList::ArgList(arglist_type &_Args) : Args(_Args) {
 }
 
 ArgList::~ArgList() {
-  for (iterator it = begin(), ie = end(); it != ie; ++it)
-    delete *it;
 }
 
 void ArgList::append(Arg *A) {
-  if (A->getOption().isUnsupported()) {
-    assert(0 && "FIXME: unsupported unsupported.");
-  }
-
   Args.push_back(A);
 }
 
@@ -68,46 +59,6 @@
   return Default;
 }
 
-unsigned ArgList::MakeIndex(const char *String0) const {
-  unsigned Index = ArgStrings.size();
-
-  // Tuck away so we have a reliable const char *.
-  SynthesizedStrings.push_back(String0);
-  ArgStrings.push_back(SynthesizedStrings.back().c_str());
-
-  return Index;
-}
-
-unsigned ArgList::MakeIndex(const char *String0, const char *String1) const {
-  unsigned Index0 = MakeIndex(String0);
-  unsigned Index1 = MakeIndex(String1);
-  assert(Index0 + 1 == Index1 && "Unexpected non-consecutive indices!");
-  (void) Index1;
-  return Index0;
-}
-
-const char *ArgList::MakeArgString(const char *Str) const {
-  return getArgString(MakeIndex(Str));
-}
-
-Arg *ArgList::MakeFlagArg(const Option *Opt) const {
-  return new FlagArg(Opt, MakeIndex(Opt->getName()));
-}
-
-Arg *ArgList::MakePositionalArg(const Option *Opt, const char *Value) const {
-  return new PositionalArg(Opt, MakeIndex(Value));
-}
-
-Arg *ArgList::MakeSeparateArg(const Option *Opt, const char *Value) const {
-  return new SeparateArg(Opt, MakeIndex(Opt->getName(), Value), 1);
-}
-
-Arg *ArgList::MakeJoinedArg(const Option *Opt, const char *Value) const {
-  std::string Joined(Opt->getName());
-  Joined += Value;
-  return new JoinedArg(Opt, MakeIndex(Joined.c_str()));
-}
-
 void ArgList::AddLastArg(ArgStringList &Output, options::ID Id) const {
   if (Arg *A = getLastArg(Id)) {
     A->claim();
@@ -175,3 +126,80 @@
     }
   }
 }
+
+//
+
+InputArgList::InputArgList(const char **ArgBegin, const char **ArgEnd) 
+  : ArgList(ActualArgs), NumInputArgStrings(ArgEnd - ArgBegin) 
+{
+  ArgStrings.append(ArgBegin, ArgEnd);
+}
+
+InputArgList::~InputArgList() {
+  // An InputArgList always owns its arguments.
+  for (iterator it = begin(), ie = end(); it != ie; ++it)
+    delete *it;
+}
+
+unsigned InputArgList::MakeIndex(const char *String0) const {
+  unsigned Index = ArgStrings.size();
+
+  // Tuck away so we have a reliable const char *.
+  SynthesizedStrings.push_back(String0);
+  ArgStrings.push_back(SynthesizedStrings.back().c_str());
+
+  return Index;
+}
+
+unsigned InputArgList::MakeIndex(const char *String0, 
+                                 const char *String1) const {
+  unsigned Index0 = MakeIndex(String0);
+  unsigned Index1 = MakeIndex(String1);
+  assert(Index0 + 1 == Index1 && "Unexpected non-consecutive indices!");
+  (void) Index1;
+  return Index0;
+}
+
+const char *InputArgList::MakeArgString(const char *Str) const {
+  return getArgString(MakeIndex(Str));
+}
+
+//
+
+DerivedArgList::DerivedArgList(InputArgList &_BaseArgs, bool _OnlyProxy)
+  : ArgList(_OnlyProxy ? _BaseArgs.getArgs() : ActualArgs),
+    BaseArgs(_BaseArgs), OnlyProxy(_OnlyProxy)
+{
+}
+
+DerivedArgList::~DerivedArgList() {
+  // We only own the arguments we explicitly synthesized.
+  for (iterator it = SynthesizedArgs.begin(), ie = SynthesizedArgs.end(); 
+       it != ie; ++it)
+    delete *it;
+}
+
+const char *DerivedArgList::MakeArgString(const char *Str) const {
+  return BaseArgs.MakeArgString(Str);
+}
+
+Arg *DerivedArgList::MakeFlagArg(const Option *Opt) const {
+  return new FlagArg(Opt, BaseArgs.MakeIndex(Opt->getName()));
+}
+
+Arg *DerivedArgList::MakePositionalArg(const Option *Opt, 
+                                       const char *Value) const {
+  return new PositionalArg(Opt, BaseArgs.MakeIndex(Value));
+}
+
+Arg *DerivedArgList::MakeSeparateArg(const Option *Opt, 
+                                     const char *Value) const {
+  return new SeparateArg(Opt, BaseArgs.MakeIndex(Opt->getName(), Value), 1);
+}
+
+Arg *DerivedArgList::MakeJoinedArg(const Option *Opt, 
+                                   const char *Value) const {
+  std::string Joined(Opt->getName());
+  Joined += Value;
+  return new JoinedArg(Opt, BaseArgs.MakeIndex(Joined.c_str()));
+}

Modified: cfe/trunk/lib/Driver/Compilation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Compilation.cpp?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Compilation.cpp (original)
+++ cfe/trunk/lib/Driver/Compilation.cpp Tue Mar 24 23:13:45 2009
@@ -23,7 +23,7 @@
 
 Compilation::Compilation(Driver &D,
                          ToolChain &_DefaultToolChain,
-                         ArgList *_Args) 
+                         InputArgList *_Args) 
   : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args) {
 }
 
@@ -31,12 +31,9 @@
   delete Args;
   
   // Free any derived arg lists.
-  for (llvm::DenseMap<const ToolChain*, ArgList*>::iterator 
-         it = TCArgs.begin(), ie = TCArgs.end(); it != ie; ++it) {
-    ArgList *A = it->second;
-    if (A != Args)
-      delete Args;
-  }
+  for (llvm::DenseMap<const ToolChain*, DerivedArgList*>::iterator 
+         it = TCArgs.begin(), ie = TCArgs.end(); it != ie; ++it)
+    delete it->second;
 
   // Free the actions, if built.
   for (ActionList::iterator it = Actions.begin(), ie = Actions.end(); 
@@ -44,11 +41,11 @@
     delete *it;
 }
 
-const ArgList &Compilation::getArgsForToolChain(const ToolChain *TC) {
+const DerivedArgList &Compilation::getArgsForToolChain(const ToolChain *TC) {
   if (!TC)
     TC = &DefaultToolChain;
 
-  ArgList *&Entry = TCArgs[TC];
+  DerivedArgList *&Entry = TCArgs[TC];
   if (!Entry)
     Entry = TC->TranslateArgs(*Args);
 

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Mar 24 23:13:45 2009
@@ -56,9 +56,10 @@
   delete Host;
 }
 
-ArgList *Driver::ParseArgStrings(const char **ArgBegin, const char **ArgEnd) {
+InputArgList *Driver::ParseArgStrings(const char **ArgBegin, 
+                                      const char **ArgEnd) {
   llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
-  ArgList *Args = new ArgList(ArgBegin, ArgEnd);
+  InputArgList *Args = new InputArgList(ArgBegin, ArgEnd);
   
   // FIXME: Handle '@' args (or at least error on them).
 
@@ -171,7 +172,7 @@
     }
   }
 
-  ArgList *Args = ParseArgStrings(Start, End);
+  InputArgList *Args = ParseArgStrings(Start, End);
 
   Host = GetHostInfo(HostTriple);
 
@@ -851,8 +852,8 @@
     }
     llvm::errs() << "], output: " << Result.getAsString() << "\n";
   } else {
-    const ArgList &TCArgs = C.getArgsForToolChain(TC);
-    T.ConstructJob(C, *JA, *Dest, Result, InputInfos, TCArgs, LinkingOutput);
+    T.ConstructJob(C, *JA, *Dest, Result, InputInfos, 
+                   C.getArgsForToolChain(TC), LinkingOutput);
   }
 }
 

Modified: cfe/trunk/lib/Driver/OptTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/OptTable.cpp?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/OptTable.cpp (original)
+++ cfe/trunk/lib/Driver/OptTable.cpp Tue Mar 24 23:13:45 2009
@@ -208,7 +208,7 @@
   return StrCmpOptionName(Name, I.Name) == -1;
 }
 
-Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index) const {
+Arg *OptTable::ParseOneArg(const InputArgList &Args, unsigned &Index) const {
   unsigned Prev = Index;
   const char *Str = Args.getArgString(Index);
 

Modified: cfe/trunk/lib/Driver/Option.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Option.cpp?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Option.cpp (original)
+++ cfe/trunk/lib/Driver/Option.cpp Tue Mar 24 23:13:45 2009
@@ -107,7 +107,7 @@
   : Option(Option::GroupClass, ID, Name, Group, 0) {
 }
 
-Arg *OptionGroup::accept(const ArgList &Args, unsigned &Index) const {
+Arg *OptionGroup::accept(const InputArgList &Args, unsigned &Index) const {
   assert(0 && "accept() should never be called on an OptionGroup");
   return 0;
 }
@@ -116,7 +116,7 @@
   : Option(Option::InputClass, options::OPT_INPUT, "<input>", 0, 0) {
 }
 
-Arg *InputOption::accept(const ArgList &Args, unsigned &Index) const {
+Arg *InputOption::accept(const InputArgList &Args, unsigned &Index) const {
   assert(0 && "accept() should never be called on an InputOption");
   return 0;
 }
@@ -125,7 +125,7 @@
   : Option(Option::UnknownClass, options::OPT_UNKNOWN, "<unknown>", 0, 0) {
 }
 
-Arg *UnknownOption::accept(const ArgList &Args, unsigned &Index) const {
+Arg *UnknownOption::accept(const InputArgList &Args, unsigned &Index) const {
   assert(0 && "accept() should never be called on an UnknownOption");
   return 0;
 }
@@ -135,7 +135,7 @@
   : Option(Option::FlagClass, ID, Name, Group, Alias) {
 }
 
-Arg *FlagOption::accept(const ArgList &Args, unsigned &Index) const {
+Arg *FlagOption::accept(const InputArgList &Args, unsigned &Index) const {
   // Matches iff this is an exact match.  
   // FIXME: Avoid strlen.
   if (strlen(getName()) != strlen(Args.getArgString(Index)))
@@ -149,7 +149,7 @@
   : Option(Option::JoinedClass, ID, Name, Group, Alias) {
 }
 
-Arg *JoinedOption::accept(const ArgList &Args, unsigned &Index) const {
+Arg *JoinedOption::accept(const InputArgList &Args, unsigned &Index) const {
   // Always matches.
   return new JoinedArg(this, Index++);
 }
@@ -160,7 +160,8 @@
   : Option(Option::CommaJoinedClass, ID, Name, Group, Alias) {
 }
 
-Arg *CommaJoinedOption::accept(const ArgList &Args, unsigned &Index) const {
+Arg *CommaJoinedOption::accept(const InputArgList &Args, 
+                               unsigned &Index) const {
   // Always matches. We count the commas now so we can answer
   // getNumValues easily.
   
@@ -175,7 +176,7 @@
   : Option(Option::SeparateClass, ID, Name, Group, Alias) {
 }
 
-Arg *SeparateOption::accept(const ArgList &Args, unsigned &Index) const {
+Arg *SeparateOption::accept(const InputArgList &Args, unsigned &Index) const {
   // Matches iff this is an exact match.  
   // FIXME: Avoid strlen.
   if (strlen(getName()) != strlen(Args.getArgString(Index)))
@@ -195,7 +196,7 @@
   assert(NumArgs > 1  && "Invalid MultiArgOption!");
 }
 
-Arg *MultiArgOption::accept(const ArgList &Args, unsigned &Index) const {
+Arg *MultiArgOption::accept(const InputArgList &Args, unsigned &Index) const {
   // Matches iff this is an exact match.  
   // FIXME: Avoid strlen.
   if (strlen(getName()) != strlen(Args.getArgString(Index)))
@@ -214,7 +215,7 @@
   : Option(Option::JoinedOrSeparateClass, ID, Name, Group, Alias) {
 }
 
-Arg *JoinedOrSeparateOption::accept(const ArgList &Args, 
+Arg *JoinedOrSeparateOption::accept(const InputArgList &Args, 
                                     unsigned &Index) const {
   // If this is not an exact match, it is a joined arg.
   // FIXME: Avoid strlen.
@@ -236,7 +237,7 @@
   : Option(Option::JoinedAndSeparateClass, ID, Name, Group, Alias) {
 }
 
-Arg *JoinedAndSeparateOption::accept(const ArgList &Args, 
+Arg *JoinedAndSeparateOption::accept(const InputArgList &Args, 
                                      unsigned &Index) const {
   // Always matches.
 

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Tue Mar 24 23:13:45 2009
@@ -9,6 +9,8 @@
 
 #include "ToolChains.h"
 
+#include "clang/Driver/Arg.h"
+#include "clang/Driver/ArgList.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/HostInfo.h"
 
@@ -122,9 +124,9 @@
   return *T;
 }
 
-ArgList *Darwin_X86::TranslateArgs(ArgList &Args) const { 
+DerivedArgList *Darwin_X86::TranslateArgs(InputArgList &Args) const { 
   // FIXME: Implement!
-  return &Args;
+  return new DerivedArgList(Args, true);
 } 
 
 bool Darwin_X86::IsMathErrnoDefault() const { 
@@ -223,3 +225,7 @@
 const char *Generic_GCC::GetForcedPicModel() const {
   return 0;
 }
+
+DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args) const {
+  return new DerivedArgList(Args, true);
+}

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=67676&r1=67675&r2=67676&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Tue Mar 24 23:13:45 2009
@@ -33,7 +33,7 @@
               const char *OS);
   ~Generic_GCC();
 
-  virtual ArgList *TranslateArgs(ArgList &Args) const { return &Args; }
+  virtual DerivedArgList *TranslateArgs(InputArgList &Args) const;
 
   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
 
@@ -62,7 +62,7 @@
              const unsigned (&GCCVersion)[3]);
   ~Darwin_X86();
 
-  virtual ArgList *TranslateArgs(ArgList &Args) const;
+  virtual DerivedArgList *TranslateArgs(InputArgList &Args) const;
 
   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
 





More information about the cfe-commits mailing list