]> granicus.if.org Git - clang/commitdiff
Change Parser & Sema to use interned "super" for comparions.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 14 Aug 2008 22:04:54 +0000 (22:04 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 14 Aug 2008 22:04:54 +0000 (22:04 +0000)
 - Added as private members for each because it is not clear where to
   put the common definition. Perhaps the IdentifierInfos all of these
   "pseudo-keywords" should be collected into one place (this would
   KnownFunctionIDs and Objective-C property IDs, for example).

Remove Token::isNamedIdentifier.
 - There isn't a good reason to use strcmp when we have interned
   strings, and there isn't a good reason to encourage clients to do
   so.

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

include/clang/Lex/Token.h
include/clang/Parse/Parser.h
lib/Lex/Lexer.cpp
lib/Parse/Parser.cpp
lib/Sema/Sema.cpp
lib/Sema/Sema.h
lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprObjC.cpp

index d5bfd9cdf59ca79a352ad532ec4ab210a61fe567..474d4048d154785efbb0b8b290d695368a09c67e 100644 (file)
@@ -85,10 +85,6 @@ public:
     IdentInfo = II;
   }
   
-  /// isNamedIdentifier - Return true if this token is a ppidentifier with the
-  /// specified name.  For example, tok.isNamedIdentifier("this").
-  bool isNamedIdentifier(const char *Name) const;
-  
   /// setFlag - Set the specified flag.
   void setFlag(TokenFlags Flag) {
     Flags |= Flag;
index cd63b9951c817408e1ad560ce0b22565a63df86e..83ec0a7a8c2c545a187fc565feedb6bf32fef781 100644 (file)
@@ -51,6 +51,11 @@ class Parser {
   enum { ScopeCacheSize = 16 };
   unsigned NumCachedScopes;
   Scope *ScopeCache[ScopeCacheSize];
+
+  /// Ident_super - IdentifierInfo for "super", to support fast
+  /// comparison.
+  IdentifierInfo *Ident_super;
+
 public:
   Parser(Preprocessor &PP, Action &Actions);
   ~Parser();
@@ -434,7 +439,7 @@ private:
     if (Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope))
       return true;
     
-    return Tok.isNamedIdentifier("super");
+    return Tok.getIdentifierInfo() == Ident_super;
   }
   
   ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
index 4fbbe3cc46449da7e6bc64696081fa56a6a4de8e..8bce589f177f1e7fb2b6e5fd58dad603a7d8f197 100644 (file)
@@ -51,12 +51,6 @@ tok::ObjCKeywordKind Token::getObjCKeywordID() const {
   return specId ? specId->getObjCKeywordID() : tok::objc_not_keyword;
 }
 
-/// isNamedIdentifier - Return true if this token is a ppidentifier with the
-/// specified name.  For example, tok.isNamedIdentifier("this").
-bool Token::isNamedIdentifier(const char *Name) const {
-  return IdentInfo && !strcmp(IdentInfo->getName(), Name);
-}
-
 
 //===----------------------------------------------------------------------===//
 // Lexer Class Implementation
index 7bd8b7b893a83a459a482e5686bd5444c120a3b2..a5e73cce32695d996e231e65873e212833d389fc 100644 (file)
@@ -267,6 +267,8 @@ void Parser::Initialize() {
                                   &PP.getIdentifierTable().get("nonatomic");
     ObjCForCollectionInKW = &PP.getIdentifierTable().get("in");
   }
+
+  Ident_super = &PP.getIdentifierTable().get("super");
 }
 
 /// ParseTopLevelDecl - Parse one top-level declaration, return whatever the
index 46c9e994ce15110c9b7812450a25a59fa5166429..c8d83bd4a50d89e49559b015d012eb923b39773e 100644 (file)
@@ -103,6 +103,8 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer)
   KnownFunctionIDs[id_vsprintf]  = &IT.get("vsprintf");
   KnownFunctionIDs[id_vprintf]   = &IT.get("vprintf");
 
+  SuperID = &IT.get("super");
+
   TUScope = 0;
   if (getLangOptions().CPlusPlus)
     FieldCollector.reset(new CXXFieldCollector());
index d6dcaf2b9ae6cbf1ee4caeb20be28b4d6daf7657..98f98aa353600e6953b76c50889f6a7273b22630 100644 (file)
@@ -137,7 +137,10 @@ public:
   /// kinds of checking (e.g. checking format string errors in printf calls).
   /// This list is populated upon the creation of a Sema object.    
   IdentifierInfo* KnownFunctionIDs[ id_num_known_functions ];
-  
+
+  /// SuperID - Identifier for "super" used for Objective-C checking.
+  IdentifierInfo* SuperID;
+
   /// Translation Unit Scope - useful to Objective-C actions that need
   /// to lookup file scope declarations in the "ordinary" C decl namespace.
   /// For example, user-defined classes, built-in "id" type, etc.
index 2e99b3dfe81299f1a8a9e405860f5eec7094f9e0..58a126be6c165ae91f4cdf37d1f8964460b01a2a 100644 (file)
@@ -328,7 +328,7 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
       }
     }
     // Needed to implement property "super.method" notation.
-    if (SD == 0 && !strcmp(II.getName(), "super")) {
+    if (SD == 0 && &II == SuperID) {
       QualType T = Context.getPointerType(Context.getObjCInterfaceType(
                      getCurMethodDecl()->getClassInterface()));
       return new PredefinedExpr(Loc, T, PredefinedExpr::ObjCSuper);
index 75546ea903b05c686c0d42243a6935303d63ac82..7c2f45b6db4465a64085d7e5cf00faf9d5fdadf3 100644 (file)
@@ -150,7 +150,7 @@ Sema::ExprResult Sema::ActOnClassMessage(
   ObjCInterfaceDecl* ClassDecl = 0;
   bool isSuper = false;
   
-  if (!strcmp(receiverName->getName(), "super") && getCurMethodDecl()) {
+  if (receiverName == SuperID && getCurMethodDecl()) {
     isSuper = true;
     ClassDecl = getCurMethodDecl()->getClassInterface()->getSuperClass();
     if (!ClassDecl)