[cfe-commits] r82344 - in /cfe/trunk: include/clang/Frontend/CommandLineSourceLoc.h tools/clang-cc/clang-cc.cpp

Chris Lattner sabre at nondot.org
Sat Sep 19 17:39:15 PDT 2009


Author: lattner
Date: Sat Sep 19 19:39:15 2009
New Revision: 82344

URL: http://llvm.org/viewvc/llvm-project?rev=82344&view=rev
Log:
switch command line 'parse' methods to use StringRef for efficiency, which
is also required for an llvm-side change.

Modified:
    cfe/trunk/include/clang/Frontend/CommandLineSourceLoc.h
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Frontend/CommandLineSourceLoc.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CommandLineSourceLoc.h?rev=82344&r1=82343&r2=82344&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/CommandLineSourceLoc.h (original)
+++ cfe/trunk/include/clang/Frontend/CommandLineSourceLoc.h Sat Sep 19 19:39:15 2009
@@ -37,39 +37,38 @@
     class parser<clang::ParsedSourceLocation>
       : public basic_parser<clang::ParsedSourceLocation> {
     public:
-      bool parse(Option &O, const char *ArgName,
-                 const std::string &ArgValue,
+      bool parse(Option &O, StringRef ArgName, StringRef ArgValue,
                  clang::ParsedSourceLocation &Val);
     };
 
     bool
     parser<clang::ParsedSourceLocation>::
-    parse(Option &O, const char *ArgName, const std::string &ArgValue,
+    parse(Option &O, StringRef ArgName, StringRef ArgValue,
           clang::ParsedSourceLocation &Val) {
       using namespace clang;
 
       const char *ExpectedFormat
         = "source location must be of the form filename:line:column";
-      std::string::size_type SecondColon = ArgValue.rfind(':');
+      StringRef::size_type SecondColon = ArgValue.rfind(':');
       if (SecondColon == std::string::npos) {
         std::fprintf(stderr, "%s\n", ExpectedFormat);
         return true;
       }
-      char *EndPtr;
-      long Column
-        = std::strtol(ArgValue.c_str() + SecondColon + 1, &EndPtr, 10);
-      if (EndPtr != ArgValue.c_str() + ArgValue.size()) {
+
+      unsigned Column;
+      if (ArgValue.substr(SecondColon + 1).getAsInteger(10, Column)) {
         std::fprintf(stderr, "%s\n", ExpectedFormat);
         return true;
       }
+      ArgValue = ArgValue.substr(0, SecondColon);
 
-      std::string::size_type FirstColon = ArgValue.rfind(':', SecondColon-1);
+      StringRef::size_type FirstColon = ArgValue.rfind(':');
       if (FirstColon == std::string::npos) {
         std::fprintf(stderr, "%s\n", ExpectedFormat);
         return true;
       }
-      long Line = std::strtol(ArgValue.c_str() + FirstColon + 1, &EndPtr, 10);
-      if (EndPtr != ArgValue.c_str() + SecondColon) {
+      unsigned Line;
+      if (ArgValue.substr(FirstColon + 1).getAsInteger(10, Line)) {
         std::fprintf(stderr, "%s\n", ExpectedFormat);
         return true;
       }

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=82344&r1=82343&r2=82344&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Sat Sep 19 19:39:15 2009
@@ -667,8 +667,8 @@
 
 // It might be nice to add bounds to the CommandLine library directly.
 struct OptLevelParser : public llvm::cl::parser<unsigned> {
-  bool parse(llvm::cl::Option &O, const char *ArgName,
-             const std::string &Arg, unsigned &Val) {
+  bool parse(llvm::cl::Option &O, llvm::StringRef ArgName,
+             llvm::StringRef Arg, unsigned &Val) {
     if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val))
       return true;
     if (Val > 3)





More information about the cfe-commits mailing list