]> granicus.if.org Git - clang/commitdiff
rename getSpelledCharacterAt to getSpellingOfSingleCharacterNumericConstant,
authorChris Lattner <sabre@nondot.org>
Mon, 26 Jan 2009 22:36:52 +0000 (22:36 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 26 Jan 2009 22:36:52 +0000 (22:36 +0000)
optimize it to use the LiteralData when possible.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63060 91177308-0d34-0410-b5e6-96231b3b80d8

clang.xcodeproj/project.pbxproj
include/clang/Lex/Preprocessor.h
lib/Sema/SemaExpr.cpp

index 05f26ae2d97d6113865ea3617db598c1d73a701d..042e0e3df88fa0e6b9486d8848394c863bed9820 100644 (file)
                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>"; };
index f6391d9781a25eb7c3006f52cceb1a0f4593d9ac..095c1db1de3c3213e6ec156ec0dec0617dc04304 100644 (file)
@@ -451,16 +451,26 @@ public:
   /// 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
index 9b91ec6ee5f496aa8aa94c366398c1081873d435..9e80946b43d2d61dbfc07e9caa19817e5d4251b5 100644 (file)
@@ -869,7 +869,7 @@ Action::OwningExprResult Sema::ActOnNumericConstant(const Token &Tok) {
   // 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()));