]> granicus.if.org Git - clang/commitdiff
cleanup context-sensitive objc keyword recognition. Patch by Fariborz Jahanian.
authorChris Lattner <sabre@nondot.org>
Wed, 29 Aug 2007 22:54:08 +0000 (22:54 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 29 Aug 2007 22:54:08 +0000 (22:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41583 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseObjc.cpp
Parse/Parser.cpp
include/clang/Parse/Parser.h

index 4b3c60079466086c35aaee361e5b9c63bf74369f..7c0f84257eb973a2fa4bcf9d55c59aa2f8013414 100644 (file)
@@ -303,13 +303,11 @@ IdentifierInfo *Parser::ParseObjCSelector() {
 ///   objc-type-qualifier: one of
 ///     in out inout bycopy byref oneway
 ///
-///   FIXME: remove the string compares...
 bool Parser::isObjCTypeQualifier() {
   if (Tok.getKind() == tok::identifier) {
-    const char *qual = Tok.getIdentifierInfo()->getName();
-    return (strcmp(qual, "in") == 0) || (strcmp(qual, "out") == 0) ||
-           (strcmp(qual, "inout") == 0) || (strcmp(qual, "oneway") == 0) ||
-           (strcmp(qual, "bycopy") == 0) || (strcmp(qual, "byref") == 0);
+    const IdentifierInfo *II = Tok.getIdentifierInfo();
+    for (unsigned i = 0; i < objc_NumQuals; ++i)
+      if (II == ObjcTypeQuals[i]) return true;
   }
   return false;
 }
index d034dc26bc205a420b6aefb8e83d63880aa4a311..581d585a82af4585649e0ab406cbf26662d98e2f 100644 (file)
@@ -247,6 +247,17 @@ void Parser::Initialize() {
   if (Tok.getKind() == tok::eof &&
       !getLang().CPlusPlus)  // Empty source file is an extension in C
     Diag(Tok, diag::ext_empty_source_file);
+  
+  // Initialization for Objective-C context sensitive keywords recognition.
+  // Referenced in Parser::isObjCTypeQualifier.
+  if (getLang().ObjC1) {
+    ObjcTypeQuals[objc_in] = &PP.getIdentifierTable().get("in");
+    ObjcTypeQuals[objc_out] = &PP.getIdentifierTable().get("out");
+    ObjcTypeQuals[objc_inout] = &PP.getIdentifierTable().get("inout");
+    ObjcTypeQuals[objc_oneway] = &PP.getIdentifierTable().get("oneway");
+    ObjcTypeQuals[objc_bycopy] = &PP.getIdentifierTable().get("bycopy");
+    ObjcTypeQuals[objc_byref] = &PP.getIdentifierTable().get("byref");
+  }
 }
 
 /// ParseTopLevelDecl - Parse one top-level declaration, return whatever the
index 9f419526fb0c5e9b6522e2cd8fc43a6ac2a5604c..ab6f84fb3139c2af56112ed690dc550844b7ffcd 100644 (file)
@@ -267,6 +267,12 @@ private:
   DeclTy *ParseObjCAtAliasDeclaration();
   
   IdentifierInfo *ParseObjCSelector();
+  // Definitions for Objective-c context sensitive keywords recognition.
+  enum ObjCTypeQual {
+    objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
+    objc_NumQuals
+  };
+  IdentifierInfo *ObjcTypeQuals[objc_NumQuals];
   bool isObjCTypeQualifier();
   void ParseObjCTypeName();
   void ParseObjCMethodRequirement();