[cfe-commits] r63060 - in /cfe/trunk: clang.xcodeproj/project.pbxproj include/clang/Lex/Preprocessor.h lib/Sema/SemaExpr.cpp

Chris Lattner sabre at nondot.org
Mon Jan 26 14:36:52 PST 2009


Author: lattner
Date: Mon Jan 26 16:36:52 2009
New Revision: 63060

URL: http://llvm.org/viewvc/llvm-project?rev=63060&view=rev
Log:
rename getSpelledCharacterAt to getSpellingOfSingleCharacterNumericConstant,
optimize it to use the LiteralData when possible.

Modified:
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=63060&r1=63059&r2=63060&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Mon Jan 26 16:36:52 2009
@@ -382,7 +382,7 @@
 		35A057E10EAE2D950069249F /* SVals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SVals.cpp; path = lib/Analysis/SVals.cpp; sourceTree = "<group>"; };
 		35A057E60EAE2DDD0069249F /* CacheTokens.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CacheTokens.cpp; path = Driver/CacheTokens.cpp; sourceTree = "<group>"; };
 		35A2B8610CF8FFA300E6C317 /* SemaUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = SemaUtil.h; path = lib/Sema/SemaUtil.h; sourceTree = "<group>"; tabWidth = 2; };
-		35A3E7000DD3874400757F74 /* CGDebugInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGDebugInfo.cpp; path = lib/CodeGen/CGDebugInfo.cpp; sourceTree = "<group>"; tabWidth = 2; };
+		35A3E7000DD3874400757F74 /* CGDebugInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGDebugInfo.cpp; path = lib/CodeGen/CGDebugInfo.cpp; sourceTree = "<group>"; tabWidth = 2; wrapsLines = 1; };
 		35A3E7010DD3874400757F74 /* CGDebugInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = CGDebugInfo.h; path = lib/CodeGen/CGDebugInfo.h; sourceTree = "<group>"; tabWidth = 2; };
 		35A8FCF60D9B4ADD001C2F97 /* ProgramPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProgramPoint.h; path = clang/Analysis/ProgramPoint.h; sourceTree = "<group>"; };
 		35A8FCF70D9B4ADD001C2F97 /* PathDiagnostic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PathDiagnostic.h; path = clang/Analysis/PathDiagnostic.h; sourceTree = "<group>"; };

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=63060&r1=63059&r2=63060&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Mon Jan 26 16:36:52 2009
@@ -451,16 +451,26 @@
   /// if an internal buffer is returned.
   unsigned getSpelling(const Token &Tok, const char *&Buffer) const;
   
-  /// getSpelledCharacterAt - Return a pointer to the start of the specified
-  /// location in the appropriate MemoryBuffer.
-  char getSpelledCharacterAt(SourceLocation SL) const {
+  /// getSpellingOfSingleCharacterNumericConstant - Tok is a numeric constant
+  /// with length 1, return the character.
+  char getSpellingOfSingleCharacterNumericConstant(const Token &Tok) const {
+    assert(Tok.is(tok::numeric_constant) &&
+           Tok.getLength() == 1 && "Called on unsupported token");
+    assert(!Tok.needsCleaning() && "Token can't need cleaning with length 1");
+
+    // If the token is carrying a literal data pointer, just use it.
+    if (const char *D = Tok.getLiteralData())
+      return *D;
+    
     if (PTH) {
       const char *Data;
-      if (PTH->getSpelling(SL, Data))
+      if (PTH->getSpelling(Tok.getLocation(), Data))
         return *Data;
     }
 
-    return *SourceMgr.getCharacterData(SL);
+    // Otherwise, fall back on getCharacterData, which is slower, but always
+    // works.
+    return *SourceMgr.getCharacterData(Tok.getLocation());
   }
   
   /// CreateString - Plop the specified string into a scratch buffer and set the

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=63060&r1=63059&r2=63060&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jan 26 16:36:52 2009
@@ -869,7 +869,7 @@
   // Fast path for a single digit (which is quite common).  A single digit
   // cannot have a trigraph, escaped newline, radix prefix, or type suffix.
   if (Tok.getLength() == 1) {
-    const char Val = PP.getSpelledCharacterAt(Tok.getLocation());
+    const char Val = PP.getSpellingOfSingleCharacterNumericConstant(Tok);
     unsigned IntSize = Context.Target.getIntWidth();
     return Owned(new (Context) IntegerLiteral(llvm::APInt(IntSize, Val-'0'),
                     Context.IntTy, Tok.getLocation()));





More information about the cfe-commits mailing list