[cfe-commits] r66106 - in /cfe/trunk/lib/Driver: Arg.cpp OptTable.cpp Option.cpp

Daniel Dunbar daniel at zuster.org
Wed Mar 4 15:22:02 PST 2009


Author: ddunbar
Date: Wed Mar  4 17:22:02 2009
New Revision: 66106

URL: http://llvm.org/viewvc/llvm-project?rev=66106&view=rev
Log:
Driver: Implement Option::accept methods.

Modified:
    cfe/trunk/lib/Driver/Arg.cpp
    cfe/trunk/lib/Driver/OptTable.cpp
    cfe/trunk/lib/Driver/Option.cpp

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

==============================================================================
--- cfe/trunk/lib/Driver/Arg.cpp (original)
+++ cfe/trunk/lib/Driver/Arg.cpp Wed Mar  4 17:22:02 2009
@@ -41,8 +41,8 @@
 
   llvm::errs() << " Index:" << Index;
 
-  if (const CommaJoinedArg *CJA = dyn_cast<CommaJoinedArg>(this))
-    llvm::errs() << " NumValues:" << CJA->getNumValues();
+  if (isa<CommaJoinedArg>(this) || isa<SeparateArg>(this))
+    llvm::errs() << " NumValues:" << getNumValues();
 
   llvm::errs() << ">\n";
 

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

==============================================================================
--- cfe/trunk/lib/Driver/OptTable.cpp (original)
+++ cfe/trunk/lib/Driver/OptTable.cpp Wed Mar  4 17:22:02 2009
@@ -126,7 +126,7 @@
   if (Str[0] != '-')
     return new PositionalArg(getOption(InputOpt), Index++);
 
-  for (unsigned j = UnknownOpt + 1; j < getNumOptions(); ++j) {
+  for (unsigned j = UnknownOpt + 1; j < LastOption; ++j) {
     const char *OptName = getOptionName((options::ID) j);
     
     // Arguments are only accepted by options which prefix them.

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

==============================================================================
--- cfe/trunk/lib/Driver/Option.cpp (original)
+++ cfe/trunk/lib/Driver/Option.cpp Wed Mar  4 17:22:02 2009
@@ -8,8 +8,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Driver/Option.h"
+
+#include "clang/Driver/Arg.h"
+#include "clang/Driver/ArgList.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cassert>
+#include <algorithm>
 using namespace clang;
 using namespace clang::driver;
 
@@ -65,6 +69,8 @@
     llvm::errs() << " NumArgs:" << MOA->getNumArgs();
 
   llvm::errs() << ">\n";
+
+  llvm::errs().flush(); // FIXME
 }
 
 bool Option::matches(const Option *Opt) const {
@@ -116,8 +122,12 @@
 }
 
 Arg *FlagOption::accept(const ArgList &Args, unsigned &Index) const {
-  assert(0 && "FIXME");
-  return 0;
+  // Matches iff this is an exact match.  
+  // FIXME: Avoid strlen.
+  if (strlen(getName()) != strlen(Args.getArgString(Index)))
+    return 0;
+
+  return new PositionalArg(this, Index++);
 }
 
 JoinedOption::JoinedOption(options::ID ID, const char *Name, 
@@ -126,8 +136,8 @@
 }
 
 Arg *JoinedOption::accept(const ArgList &Args, unsigned &Index) const {
-  assert(0 && "FIXME");
-  return 0;
+  // Always matches.
+  return new JoinedArg(this, Index++);
 }
 
 CommaJoinedOption::CommaJoinedOption(options::ID ID, const char *Name, 
@@ -137,8 +147,20 @@
 }
 
 Arg *CommaJoinedOption::accept(const ArgList &Args, unsigned &Index) const {
-  assert(0 && "FIXME");
-  return 0;
+  // Always matches. We count the commas now so we can answer
+  // getNumValues easily.
+  
+  // Get the suffix string.
+  // FIXME: Avoid strlen, and move to helper method?
+  const char *Suffix = Args.getArgString(Index) + strlen(getName());
+  const char *SuffixEnd = Suffix + strlen(Suffix);
+  
+  // Degenerate case, exact match has no values.
+  if (Suffix == SuffixEnd)
+    return new CommaJoinedArg(this, Index++, 0);
+
+  return new CommaJoinedArg(this, Index++, 
+                            std::count(Suffix, SuffixEnd, ',') + 1);
 }
 
 SeparateOption::SeparateOption(options::ID ID, const char *Name, 
@@ -147,8 +169,14 @@
 }
 
 Arg *SeparateOption::accept(const ArgList &Args, unsigned &Index) const {
-  assert(0 && "FIXME");
-  return 0;
+  // Matches iff this is an exact match.  
+  // FIXME: Avoid strlen.
+  if (strlen(getName()) != strlen(Args.getArgString(Index)))
+    return 0;
+
+  // FIXME: Missing argument error.
+  Index += 2;
+  return new SeparateArg(this, Index - 2, 1);
 }
 
 MultiArgOption::MultiArgOption(options::ID ID, const char *Name, 
@@ -158,8 +186,14 @@
 }
 
 Arg *MultiArgOption::accept(const ArgList &Args, unsigned &Index) const {
-  assert(0 && "FIXME");
-  return 0;
+  // Matches iff this is an exact match.  
+  // FIXME: Avoid strlen.
+  if (strlen(getName()) != strlen(Args.getArgString(Index)))
+    return 0;
+
+  // FIXME: Missing argument error.
+  Index += 1 + NumArgs;
+  return new SeparateArg(this, Index - 1 - NumArgs, NumArgs);
 }
 
 JoinedOrSeparateOption::JoinedOrSeparateOption(options::ID ID, const char *Name,
@@ -169,8 +203,15 @@
 }
 
 Arg *JoinedOrSeparateOption::accept(const ArgList &Args, unsigned &Index) const {
-  assert(0 && "FIXME");
-  return 0;
+  // If this is not an exact match, it is a joined arg.
+  // FIXME: Avoid strlen.
+  if (strlen(getName()) != strlen(Args.getArgString(Index)))
+    return new JoinedArg(this, Index++);
+
+  // Otherwise it must be separate.
+  // FIXME: Missing argument error.
+  Index += 2;
+  return new SeparateArg(this, Index - 2, 1);  
 }
 
 JoinedAndSeparateOption::JoinedAndSeparateOption(options::ID ID,
@@ -181,7 +222,10 @@
 }
 
 Arg *JoinedAndSeparateOption::accept(const ArgList &Args, unsigned &Index) const {
-  assert(0 && "FIXME");
-  return 0;
+  // Always matches.
+
+  // FIXME: Missing argument error.
+  Index += 2;
+  return new JoinedAndSeparateArg(this, Index - 2);
 }
 





More information about the cfe-commits mailing list