[cfe-commits] r41330 - in /cfe/trunk: Lex/IdentifierTable.cpp Parse/ParseObjc.cpp include/clang/Lex/Token.h

Steve Naroff snaroff at apple.com
Thu Aug 23 11:16:40 PDT 2007


Author: snaroff
Date: Thu Aug 23 13:16:40 2007
New Revision: 41330

URL: http://llvm.org/viewvc/llvm-project?rev=41330&view=rev
Log:

Add helper functions Token::isObjCAtKeyword() and Token::getObjCKeywordID().

Convert all clients to the new cleaner, more robust API.


Modified:
    cfe/trunk/Lex/IdentifierTable.cpp
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/include/clang/Lex/Token.h

Modified: cfe/trunk/Lex/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/IdentifierTable.cpp?rev=41330&r1=41329&r2=41330&view=diff

==============================================================================
--- cfe/trunk/Lex/IdentifierTable.cpp (original)
+++ cfe/trunk/Lex/IdentifierTable.cpp Thu Aug 23 13:16:40 2007
@@ -18,6 +18,22 @@
 using namespace clang;
 
 //===----------------------------------------------------------------------===//
+// Token Implementation
+//===----------------------------------------------------------------------===//
+
+/// isObjCAtKeyword - Return true if we have an ObjC keyword identifier. 
+bool Token::isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const {
+  return getKind() == tok::identifier && 
+         getIdentifierInfo()->getObjCKeywordID() == objcKey;
+}
+
+/// getObjCKeywordID - Return the ObjC keyword kind.
+tok::ObjCKeywordKind Token::getObjCKeywordID() const {
+  IdentifierInfo *specId = getIdentifierInfo();
+  return specId ? specId->getObjCKeywordID() : tok::objc_not_keyword;
+}
+
+//===----------------------------------------------------------------------===//
 // IdentifierInfo Implementation
 //===----------------------------------------------------------------------===//
 

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=41330&r1=41329&r2=41330&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Thu Aug 23 13:16:40 2007
@@ -29,8 +29,7 @@
 Parser::DeclTy *Parser::ParseObjCAtDirectives() {
   SourceLocation AtLoc = ConsumeToken(); // the "@"
   
-  IdentifierInfo *II = Tok.getIdentifierInfo();
-  switch (II ? II->getObjCKeywordID() : tok::objc_not_keyword) {
+  switch (Tok.getObjCKeywordID()) {
     case tok::objc_class:
       return ParseObjCAtClassDeclaration(AtLoc);
     case tok::objc_interface:
@@ -111,8 +110,7 @@
 ///
 Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
   SourceLocation atLoc, AttributeList *attrList) {
-  assert((Tok.getKind() == tok::identifier &&
-          Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_interface) &&
+  assert(Tok.isObjCAtKeyword(tok::objc_interface) &&
          "ParseObjCAtInterfaceDeclaration(): Expected @interface");
   ConsumeToken(); // the "interface" identifier
   
@@ -151,8 +149,7 @@
     ParseObjCInterfaceDeclList(0/*FIXME*/);
 
     // The @ sign was already consumed by ParseObjCInterfaceDeclList().
-    if (Tok.getKind() == tok::identifier &&
-        Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_end) {
+    if (Tok.isObjCAtKeyword(tok::objc_end)) {
       ConsumeToken(); // the "end" identifier
       return 0;
     }
@@ -189,8 +186,7 @@
   ParseObjCInterfaceDeclList(0/*FIXME*/);
 
   // The @ sign was already consumed by ParseObjCInterfaceDeclList().
-  if (Tok.getKind() == tok::identifier &&
-      Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_end) {
+  if (Tok.isObjCAtKeyword(tok::objc_end)) {
     ConsumeToken(); // the "end" identifier
     return 0;
   }
@@ -214,7 +210,7 @@
   while (1) {
     if (Tok.getKind() == tok::at) {
       SourceLocation AtLoc = ConsumeToken(); // the "@"
-      tok::ObjCKeywordKind ocKind = Tok.getIdentifierInfo()->getObjCKeywordID();
+      tok::ObjCKeywordKind ocKind = Tok.getObjCKeywordID();
       
       if (ocKind == tok::objc_end) { // terminate list
         return;
@@ -488,13 +484,12 @@
     tok::ObjCKeywordKind visibility = tok::objc_private;
     if (Tok.getKind() == tok::at) { // parse objc-visibility-spec
       ConsumeToken(); // eat the @ sign
-      IdentifierInfo *specId = Tok.getIdentifierInfo();
-      switch (specId->getObjCKeywordID()) {
+      switch (Tok.getObjCKeywordID()) {
       case tok::objc_private:
       case tok::objc_public:
       case tok::objc_protected:
       case tok::objc_package:
-        visibility = specId->getObjCKeywordID();
+        visibility = Tok.getObjCKeywordID();
         ConsumeToken();
         continue; 
       default:
@@ -538,8 +533,7 @@
 ///   semicolon in the first alternative if objc-protocol-refs are omitted.
 
 Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {
-  assert((Tok.getKind() == tok::identifier &&
-          Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_protocol) &&
+  assert(Tok.isObjCAtKeyword(tok::objc_protocol) &&
          "ParseObjCAtProtocolDeclaration(): Expected @protocol");
   ConsumeToken(); // the "protocol" identifier
   
@@ -586,8 +580,7 @@
   ParseObjCInterfaceDeclList(0/*FIXME*/);
 
   // The @ sign was already consumed by ParseObjCInterfaceDeclList().
-  if (Tok.getKind() == tok::identifier &&
-      Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_end) {
+  if (Tok.isObjCAtKeyword(tok::objc_end)) {
     ConsumeToken(); // the "end" identifier
     return 0;
   }
@@ -663,8 +656,7 @@
 ///    objc-encode-expression:
 ///      @encode ( type-name )
 Parser::ExprResult Parser::ParseObjCEncodeExpression() {
-  assert(Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_encode && 
-         "Not an @encode expression!");
+  assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!");
   
   SourceLocation EncLoc = ConsumeToken();
   

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

==============================================================================
--- cfe/trunk/include/clang/Lex/Token.h (original)
+++ cfe/trunk/include/clang/Lex/Token.h Thu Aug 23 13:16:40 2007
@@ -105,7 +105,13 @@
   /// isExpandDisabled - Return true if this identifier token should never
   /// be expanded in the future, due to C99 6.10.3.4p2.
   bool isExpandDisabled() const { return Flags & DisableExpand; }
-    
+  
+  /// isObjCAtKeyword - Return true if we have an ObjC keyword identifier. 
+  bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const;
+  
+  /// getObjCKeywordID - Return the ObjC keyword kind.
+  tok::ObjCKeywordKind getObjCKeywordID() const;
+  
   /// needsCleaning - Return true if this token has trigraphs or escaped
   /// newlines in it.
   ///





More information about the cfe-commits mailing list