[cfe-commits] r68020 - in /cfe/trunk: include/clang/Driver/Arg.h include/clang/Driver/ArgList.h lib/Driver/Arg.cpp lib/Driver/ArgList.cpp lib/Driver/ToolChains.cpp

Daniel Dunbar daniel at zuster.org
Sun Mar 29 15:29:06 PDT 2009


Author: ddunbar
Date: Sun Mar 29 17:29:05 2009
New Revision: 68020

URL: http://llvm.org/viewvc/llvm-project?rev=68020&view=rev
Log:
Driver: Track which original arguments an arg is derived from, so that
we can properly claim arguments, even if they have been translated by
the tool chain.

Modified:
    cfe/trunk/include/clang/Driver/Arg.h
    cfe/trunk/include/clang/Driver/ArgList.h
    cfe/trunk/lib/Driver/Arg.cpp
    cfe/trunk/lib/Driver/ArgList.cpp
    cfe/trunk/lib/Driver/ToolChains.cpp

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

==============================================================================
--- cfe/trunk/include/clang/Driver/Arg.h (original)
+++ cfe/trunk/include/clang/Driver/Arg.h Sun Mar 29 17:29:05 2009
@@ -50,6 +50,10 @@
     /// The option this argument is an instance of.
     const Option *Opt;
     
+    /// The argument this argument was derived from (during tool chain
+    /// argument translation), if any.
+    const Arg *BaseArg;
+
     /// The index at which this argument appears in the containing
     /// ArgList.
     unsigned Index;
@@ -60,25 +64,34 @@
     mutable bool Claimed;
 
   protected:
-    Arg(ArgClass Kind, const Option *Opt, unsigned Index);
+    Arg(ArgClass Kind, const Option *Opt, unsigned Index,
+        const Arg *BaseArg = 0);
     
   public:
     Arg(const Arg &);
     virtual ~Arg();
 
     ArgClass getKind() const { return Kind; }
-
     const Option &getOption() const { return *Opt; }
-
     unsigned getIndex() const { return Index; }
+    
+    /// getBaseArg - Return the base argument which generated this
+    /// arg; this is either the argument itself or the argument it was
+    /// derived from during tool chain specific argument translation.
+    const Arg &getBaseArg() const { 
+      return BaseArg ? *BaseArg : *this; 
+    }
+    void setBaseArg(const Arg *_BaseArg) {
+      BaseArg = _BaseArg;
+    }
 
-    bool isClaimed() const { return Claimed; }
+    bool isClaimed() const { return getBaseArg().Claimed; }
 
     /// claim - Set the Arg claimed bit.
     
     // FIXME: We need to deal with derived arguments and set the bit
     // in the original argument; not the derived one.
-    void claim() const { Claimed = true; }
+    void claim() const { getBaseArg().Claimed = true; }
 
     virtual unsigned getNumValues() const = 0;
     virtual const char *getValue(const ArgList &Args, unsigned N=0) const = 0;
@@ -104,7 +117,7 @@
   /// FlagArg - An argument with no value.
   class FlagArg : public Arg {
   public:
-    FlagArg(const Option *Opt, unsigned Index);
+    FlagArg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0);
 
     virtual void render(const ArgList &Args, ArgStringList &Output) const;
 
@@ -120,7 +133,7 @@
   /// PositionalArg - A simple positional argument.
   class PositionalArg : public Arg {
   public:
-    PositionalArg(const Option *Opt, unsigned Index);
+    PositionalArg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0);
 
     virtual void render(const ArgList &Args, ArgStringList &Output) const;
 
@@ -137,7 +150,7 @@
   /// (suffixed) to the option.
   class JoinedArg : public Arg {
   public:
-    JoinedArg(const Option *Opt, unsigned Index);
+    JoinedArg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0);
 
     virtual void render(const ArgList &Args, ArgStringList &Output) const;
 
@@ -156,7 +169,8 @@
     unsigned NumValues;
 
   public:
-    SeparateArg(const Option *Opt, unsigned Index, unsigned NumValues);
+    SeparateArg(const Option *Opt, unsigned Index, unsigned NumValues, 
+                const Arg *BaseArg = 0);
 
     virtual void render(const ArgList &Args, ArgStringList &Output) const;
 
@@ -179,7 +193,8 @@
     std::vector<std::string> Values;
 
   public:
-    CommaJoinedArg(const Option *Opt, unsigned Index, const char *Str);
+    CommaJoinedArg(const Option *Opt, unsigned Index, const char *Str, 
+                   const Arg *BaseArg = 0);
 
     virtual void render(const ArgList &Args, ArgStringList &Output) const;
 
@@ -196,7 +211,8 @@
   /// values.
   class JoinedAndSeparateArg : public Arg {
   public:
-    JoinedAndSeparateArg(const Option *Opt, unsigned Index);
+    JoinedAndSeparateArg(const Option *Opt, unsigned Index, 
+                         const Arg *BaseArg = 0);
 
     virtual void render(const ArgList &Args, ArgStringList &Output) const;
 

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

==============================================================================
--- cfe/trunk/include/clang/Driver/ArgList.h (original)
+++ cfe/trunk/include/clang/Driver/ArgList.h Sun Mar 29 17:29:05 2009
@@ -208,19 +208,22 @@
 
     /// MakeFlagArg - Construct a new FlagArg for the given option
     /// \arg Id.
-    Arg *MakeFlagArg(const Option *Opt) const;
+    Arg *MakeFlagArg(const Arg *BaseArg, 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;
+    Arg *MakePositionalArg(const Arg *BaseArg, 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;
+    Arg *MakeSeparateArg(const Arg *BaseArg, 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;
+    Arg *MakeJoinedArg(const Arg *BaseArg, const Option *Opt, 
+                       const char *Value) const;
 
     /// @}
   };

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

==============================================================================
--- cfe/trunk/lib/Driver/Arg.cpp (original)
+++ cfe/trunk/lib/Driver/Arg.cpp Sun Mar 29 17:29:05 2009
@@ -14,11 +14,9 @@
 
 using namespace clang::driver;
 
-Arg::Arg(ArgClass _Kind, const Option *_Opt, unsigned _Index) 
-  : Kind(_Kind),
-    Opt(_Opt),
-    Index(_Index),
-    Claimed(false)
+Arg::Arg(ArgClass _Kind, const Option *_Opt, unsigned _Index, 
+         const Arg *_BaseArg) 
+  : Kind(_Kind), Opt(_Opt), BaseArg(_BaseArg), Index(_Index), Claimed(false)
 {
 }
 
@@ -76,8 +74,8 @@
     Output.push_back(getValue(Args, i));
 }
 
-FlagArg::FlagArg(const Option *Opt, unsigned Index)
-  : Arg(FlagClass, Opt, Index) {
+FlagArg::FlagArg(const Option *Opt, unsigned Index, const Arg *BaseArg)
+  : Arg(FlagClass, Opt, Index, BaseArg) {
 }
 
 void FlagArg::render(const ArgList &Args, ArgStringList &Output) const {
@@ -89,8 +87,9 @@
   return 0;
 }
 
-PositionalArg::PositionalArg(const Option *Opt, unsigned Index)
-  : Arg(PositionalClass, Opt, Index) {
+PositionalArg::PositionalArg(const Option *Opt, unsigned Index, 
+                             const Arg *BaseArg)
+  : Arg(PositionalClass, Opt, Index, BaseArg) {
 }
 
 void PositionalArg::render(const ArgList &Args, ArgStringList &Output) const {
@@ -102,8 +101,8 @@
   return Args.getArgString(getIndex());
 }
 
-JoinedArg::JoinedArg(const Option *Opt, unsigned Index)
-  : Arg(JoinedClass, Opt, Index) {
+JoinedArg::JoinedArg(const Option *Opt, unsigned Index, const Arg *BaseArg)
+  : Arg(JoinedClass, Opt, Index, BaseArg) {
 }
 
 void JoinedArg::render(const ArgList &Args, ArgStringList &Output) const {
@@ -122,8 +121,8 @@
 }
 
 CommaJoinedArg::CommaJoinedArg(const Option *Opt, unsigned Index, 
-                               const char *Str)
-  : Arg(CommaJoinedClass, Opt, Index) {
+                               const char *Str, const Arg *BaseArg)
+  : Arg(CommaJoinedClass, Opt, Index, BaseArg) {
   const char *Prev = Str;  
   for (;; ++Str) {
     char c = *Str;
@@ -149,8 +148,9 @@
   return Values[N].c_str();
 }
 
-SeparateArg::SeparateArg(const Option *Opt, unsigned Index, unsigned _NumValues)
-  : Arg(SeparateClass, Opt, Index), NumValues(_NumValues) {
+SeparateArg::SeparateArg(const Option *Opt, unsigned Index, unsigned _NumValues,
+                         const Arg *BaseArg)
+  : Arg(SeparateClass, Opt, Index, BaseArg), NumValues(_NumValues) {
 }
 
 void SeparateArg::render(const ArgList &Args, ArgStringList &Output) const {
@@ -172,8 +172,9 @@
   return Args.getArgString(getIndex() + 1 + N);
 }
 
-JoinedAndSeparateArg::JoinedAndSeparateArg(const Option *Opt, unsigned Index)
-  : Arg(JoinedAndSeparateClass, Opt, Index) {
+JoinedAndSeparateArg::JoinedAndSeparateArg(const Option *Opt, unsigned Index, 
+                                           const Arg *BaseArg)
+  : Arg(JoinedAndSeparateClass, Opt, Index, BaseArg) {
 }
 
 void JoinedAndSeparateArg::render(const ArgList &Args, 

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

==============================================================================
--- cfe/trunk/lib/Driver/ArgList.cpp (original)
+++ cfe/trunk/lib/Driver/ArgList.cpp Sun Mar 29 17:29:05 2009
@@ -196,23 +196,24 @@
   return BaseArgs.MakeArgString(Str);
 }
 
-Arg *DerivedArgList::MakeFlagArg(const Option *Opt) const {
-  return new FlagArg(Opt, BaseArgs.MakeIndex(Opt->getName()));
+Arg *DerivedArgList::MakeFlagArg(const Arg *BaseArg, const Option *Opt) const {
+  return new FlagArg(Opt, BaseArgs.MakeIndex(Opt->getName()), BaseArg);
 }
 
-Arg *DerivedArgList::MakePositionalArg(const Option *Opt, 
+Arg *DerivedArgList::MakePositionalArg(const Arg *BaseArg, const Option *Opt, 
                                        const char *Value) const {
-  return new PositionalArg(Opt, BaseArgs.MakeIndex(Value));
+  return new PositionalArg(Opt, BaseArgs.MakeIndex(Value), BaseArg);
 }
 
-Arg *DerivedArgList::MakeSeparateArg(const Option *Opt, 
+Arg *DerivedArgList::MakeSeparateArg(const Arg *BaseArg, const Option *Opt, 
                                      const char *Value) const {
-  return new SeparateArg(Opt, BaseArgs.MakeIndex(Opt->getName(), Value), 1);
+  return new SeparateArg(Opt, BaseArgs.MakeIndex(Opt->getName(), Value), 1, 
+                         BaseArg);
 }
 
-Arg *DerivedArgList::MakeJoinedArg(const Option *Opt, 
+Arg *DerivedArgList::MakeJoinedArg(const Arg *BaseArg, const Option *Opt, 
                                    const char *Value) const {
   std::string Joined(Opt->getName());
   Joined += Value;
-  return new JoinedArg(Opt, BaseArgs.MakeIndex(Joined.c_str()));
+  return new JoinedArg(Opt, BaseArgs.MakeIndex(Joined.c_str()), BaseArg);
 }

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

==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Sun Mar 29 17:29:05 2009
@@ -142,7 +142,7 @@
 
   if (!Args.hasArg(options::OPT_mmacosx_version_min_EQ, false)) {
     const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
-    DAL->append(DAL->MakeJoinedArg(O, MacosxVersionMin.c_str()));
+    DAL->append(DAL->MakeJoinedArg(0, O, MacosxVersionMin.c_str()));
   }
   
   for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
@@ -173,6 +173,7 @@
         continue;
       }
 
+      XarchArg->setBaseArg(A);
       A = XarchArg;
     } 
 
@@ -188,64 +189,65 @@
     case options::OPT_mkernel:
     case options::OPT_fapple_kext:
       DAL->append(A);
-      DAL->append(DAL->MakeFlagArg(Opts.getOption(options::OPT_static)));
-      DAL->append(DAL->MakeFlagArg(Opts.getOption(options::OPT_static)));
+      DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
+      DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
       break;
       
     case options::OPT_dependency_file:
-      DAL->append(DAL->MakeSeparateArg(Opts.getOption(options::OPT_MF),
+      DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
                                        A->getValue(Args)));
       break;
 
     case options::OPT_gfull:
-      DAL->append(DAL->MakeFlagArg(Opts.getOption(options::OPT_g_Flag)));
-      DAL->append(DAL->MakeFlagArg(
+      DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
+      DAL->append(DAL->MakeFlagArg(A,
              Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
       break;
 
     case options::OPT_gused:
-      DAL->append(DAL->MakeFlagArg(Opts.getOption(options::OPT_g_Flag)));
-      DAL->append(DAL->MakeFlagArg(
+      DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
+      DAL->append(DAL->MakeFlagArg(A,
              Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
       break;
 
     case options::OPT_fterminated_vtables:
     case options::OPT_findirect_virtual_calls:
-      DAL->append(DAL->MakeFlagArg(Opts.getOption(options::OPT_fapple_kext)));
-      DAL->append(DAL->MakeFlagArg(Opts.getOption(options::OPT_static)));
+      DAL->append(DAL->MakeFlagArg(A,
+                                   Opts.getOption(options::OPT_fapple_kext)));
+      DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
       break;
 
     case options::OPT_shared:
-      DAL->append(DAL->MakeFlagArg(Opts.getOption(options::OPT_dynamiclib)));
+      DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
       break;
 
     case options::OPT_fconstant_cfstrings:
-      DAL->append(DAL->MakeFlagArg(
+      DAL->append(DAL->MakeFlagArg(A,
                              Opts.getOption(options::OPT_mconstant_cfstrings)));
       break;
 
     case options::OPT_fno_constant_cfstrings:
-      DAL->append(DAL->MakeFlagArg(
+      DAL->append(DAL->MakeFlagArg(A,
                           Opts.getOption(options::OPT_mno_constant_cfstrings)));
       break;
 
     case options::OPT_Wnonportable_cfstrings:
-      DAL->append(DAL->MakeFlagArg(
+      DAL->append(DAL->MakeFlagArg(A,
                      Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
       break;
 
     case options::OPT_Wno_nonportable_cfstrings:
-      DAL->append(DAL->MakeFlagArg(
+      DAL->append(DAL->MakeFlagArg(A,
                   Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
       break;
 
     case options::OPT_fpascal_strings:
-      DAL->append(DAL->MakeFlagArg(
+      DAL->append(DAL->MakeFlagArg(A,
                                  Opts.getOption(options::OPT_mpascal_strings)));
       break;
 
     case options::OPT_fno_pascal_strings:
-      DAL->append(DAL->MakeFlagArg(
+      DAL->append(DAL->MakeFlagArg(A,
                               Opts.getOption(options::OPT_mno_pascal_strings)));
       break;
     }
@@ -256,10 +258,10 @@
   // look it up.
   if (getArchName() == "x86_64")
     if (!Args.hasArg(options::OPT_m64, false))
-      DAL->append(DAL->MakeFlagArg(Opts.getOption(options::OPT_m64)));
+      DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
 
   if (!Args.hasArg(options::OPT_mtune_EQ, false))
-    DAL->append(DAL->MakeJoinedArg(Opts.getOption(options::OPT_mtune_EQ),
+    DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
                                     "core2"));
 
   return DAL;





More information about the cfe-commits mailing list