From 34870da70fa42b0391b79627ebd0cfc6eb22213b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 29 Aug 2007 22:54:08 +0000 Subject: [PATCH] cleanup context-sensitive objc keyword recognition. Patch by Fariborz Jahanian. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41583 91177308-0d34-0410-b5e6-96231b3b80d8 --- Parse/ParseObjc.cpp | 8 +++----- Parse/Parser.cpp | 11 +++++++++++ include/clang/Parse/Parser.h | 6 ++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index 4b3c600794..7c0f84257e 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -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; } diff --git a/Parse/Parser.cpp b/Parse/Parser.cpp index d034dc26bc..581d585a82 100644 --- a/Parse/Parser.cpp +++ b/Parse/Parser.cpp @@ -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 diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 9f419526fb..ab6f84fb31 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -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(); -- 2.40.0