[cfe-commits] r39003 - in /cfe/cfe/trunk: Lex/IdentifierTable.cpp Lex/Preprocessor.cpp include/clang/Basic/TokenKinds.def include/clang/Basic/TokenKinds.h include/clang/Lex/IdentifierTable.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:26:43 PDT 2007


Author: sabre
Date: Wed Jul 11 11:26:43 2007
New Revision: 39003

URL: http://llvm.org/viewvc/llvm-project?rev=39003&view=rev
Log:
Make the identifier table track objc keywords

Modified:
    cfe/cfe/trunk/Lex/IdentifierTable.cpp
    cfe/cfe/trunk/Lex/Preprocessor.cpp
    cfe/cfe/trunk/include/clang/Basic/TokenKinds.def
    cfe/cfe/trunk/include/clang/Basic/TokenKinds.h
    cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h

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

==============================================================================
--- cfe/cfe/trunk/Lex/IdentifierTable.cpp (original)
+++ cfe/cfe/trunk/Lex/IdentifierTable.cpp Wed Jul 11 11:26:43 2007
@@ -208,6 +208,7 @@
   Identifier->TokInfo.Macro = 0;
   Identifier->TokInfo.TokenID = tok::identifier;
   Identifier->TokInfo.PPID = tok::pp_not_keyword;
+  Identifier->TokInfo.ObjCID = tok::objc_not_keyword;
   Identifier->TokInfo.IsExtension = false;
   Identifier->TokInfo.IsPoisoned = false;
   Identifier->TokInfo.IsOtherTargetMacro = false;

Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=39003&r1=39002&r2=39003&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:26:43 2007
@@ -109,6 +109,14 @@
   PP.getIdentifierInfo(Name, Name+NameLen)->setPPKeywordID(PPID);
 }
 
+/// AddObjCKeyword - Register an Objective-C @keyword like "class" "selector" or 
+/// "property".
+static void AddObjCKeyword(tok::ObjCKeywordKind ObjCID, 
+                           const char *Name, unsigned NameLen,
+                           Preprocessor &PP) {
+  PP.getIdentifierInfo(Name, Name+NameLen)->setObjCKeywordID(ObjCID);
+}
+
 /// AddKeywords - Add all keywords to the symbol table.
 ///
 void Preprocessor::AddKeywords() {
@@ -135,6 +143,12 @@
   AddKeyword(NAME, tok::kw_ ## TOK, 0, 0, 0);
 #define PPKEYWORD(NAME) \
   AddPPKeyword(tok::pp_##NAME, #NAME, strlen(#NAME), *this);
+#define OBJC1_AT_KEYWORD(NAME) \
+  if (Features.ObjC1)          \
+    AddObjCKeyword(tok::objc_##NAME, #NAME, strlen(#NAME), *this);
+#define OBJC2_AT_KEYWORD(NAME) \
+  if (Features.ObjC2)          \
+    AddObjCKeyword(tok::objc_##NAME, #NAME, strlen(#NAME), *this);
 #include "clang/Basic/TokenKinds.def"
 }
 

Modified: cfe/cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=39003&r1=39002&r2=39003&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/TokenKinds.def Wed Jul 11 11:26:43 2007
@@ -26,6 +26,12 @@
 #ifndef PPKEYWORD
 #define PPKEYWORD(X)
 #endif
+#ifndef OBJC1_AT_KEYWORD
+#define OBJC1_AT_KEYWORD(X)
+#endif
+#ifndef OBJC2_AT_KEYWORD
+#define OBJC2_AT_KEYWORD(X)
+#endif
 
 //===----------------------------------------------------------------------===//
 // Preprocessor keywords.
@@ -294,6 +300,41 @@
 ALIAS("__volatile"   , volatile   )
 ALIAS("__volatile__" , volatile   )
 
+
+//===----------------------------------------------------------------------===//
+// Objective-C @-preceeded keywords.
+//===----------------------------------------------------------------------===//
+
+// These have meaning after an '@' in Objective-C mode. These define enums in
+// the tok::objc_* namespace.
+
+OBJC1_AT_KEYWORD(not_keyword)
+OBJC1_AT_KEYWORD(class)
+OBJC1_AT_KEYWORD(compatibility_alias)
+OBJC1_AT_KEYWORD(defs)
+OBJC1_AT_KEYWORD(encode)
+OBJC1_AT_KEYWORD(end)
+OBJC1_AT_KEYWORD(implementation)
+OBJC1_AT_KEYWORD(interface)
+OBJC1_AT_KEYWORD(private)
+OBJC1_AT_KEYWORD(protected)
+OBJC1_AT_KEYWORD(protocol)
+OBJC1_AT_KEYWORD(public)
+OBJC1_AT_KEYWORD(selector)
+OBJC1_AT_KEYWORD(throw)
+OBJC1_AT_KEYWORD(try)
+OBJC1_AT_KEYWORD(catch)
+OBJC1_AT_KEYWORD(finally)
+OBJC1_AT_KEYWORD(synchronized)
+
+// I'm guessing this is an objc2 keyword, what are the others?
+OBJC2_AT_KEYWORD(property)
+
+// TODO: What to do about context-sensitive keywords like:
+//       bycopy/byref/in/inout/oneway/out?
+
+#undef OBJC2_AT_KEYWORD
+#undef OBJC1_AT_KEYWORD
 #undef PPKEYWORD
 #undef ALIAS
 #undef KEYWORD

Modified: cfe/cfe/trunk/include/clang/Basic/TokenKinds.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/TokenKinds.h?rev=39003&r1=39002&r2=39003&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/TokenKinds.h (original)
+++ cfe/cfe/trunk/include/clang/Basic/TokenKinds.h Wed Jul 11 11:26:43 2007
@@ -27,12 +27,23 @@
   NUM_TOKENS
 };
 
+/// PPKeywordKind - This provides a namespace for preprocessor keywords which
+/// start with a '#' at the beginning of the line.
 enum PPKeywordKind {
 #define PPKEYWORD(X) pp_##X, 
 #include "clang/Basic/TokenKinds.def"
   NUM_PP_KEYWORDS
 };
 
+/// ObjCKeywordKind - This provides a namespace for Objective-C keywords which
+/// start with an '@'.
+enum ObjCKeywordKind {
+#define OBJC1_AT_KEYWORD(X) objc_##X,
+#define OBJC2_AT_KEYWORD(X) objc_##X,
+#include "clang/Basic/TokenKinds.def"
+  NUM_OBJC_KEYWORDS
+};
+
 const char *getTokenName(enum TokenKind Kind);
 
 }  // end namespace tok

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

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h Wed Jul 11 11:26:43 2007
@@ -29,14 +29,15 @@
 /// variable or function name).  The preprocessor keeps this information in a
 /// set, and all tok::identifier tokens have a pointer to one of these.  
 class IdentifierInfo {
-  unsigned NameLen;            // String that is the identifier.
-  MacroInfo *Macro;            // Set if this identifier is #define'd.
-  tok::TokenKind TokenID  : 8; // Front-end token ID or tok::identifier.
-  tok::PPKeywordKind PPID : 5; // ID for preprocessor command like 'ifdef'.
-  bool IsExtension        : 1; // True if identifier is a lang extension.
-  bool IsPoisoned         : 1; // True if identifier is poisoned.
-  bool IsOtherTargetMacro : 1; // True if ident is a macro on another target.
-  void *FETokenInfo;           // Managed by the language front-end.
+  unsigned NameLen;                // String that is the identifier.
+  MacroInfo *Macro;                // Set if this identifier is #define'd.
+  tok::TokenKind TokenID      : 8; // Front-end token ID or tok::identifier.
+  tok::PPKeywordKind PPID     : 5; // ID for preprocessor command like 'ifdef'.
+  tok::ObjCKeywordKind ObjCID : 5; // ID for preprocessor command like 'ifdef'.
+  bool IsExtension            : 1; // True if identifier is a lang extension.
+  bool IsPoisoned             : 1; // True if identifier is poisoned.
+  bool IsOtherTargetMacro     : 1; // True if ident is macro on another target.
+  void *FETokenInfo;               // Managed by the language front-end.
   friend class IdentifierTable;
 public:
   /// getName - Return the actual string for this identifier.  The length of
@@ -65,9 +66,17 @@
   tok::TokenKind getTokenID() const { return TokenID; }
   void setTokenID(tok::TokenKind ID) { TokenID = ID; }
   
+  /// getPPKeywordID - Return the preprocessor keyword ID for this identifier.
+  /// For example, define will return tok::pp_define.
   tok::PPKeywordKind getPPKeywordID() const { return PPID; }
   void setPPKeywordID(tok::PPKeywordKind ID) { PPID = ID; }
   
+  /// getObjCKeywordID - Return the Objective-C keyword ID for the this
+  /// identifier.  For example, 'class' will return tok::objc_class if ObjC is
+  /// enabled.
+  tok::ObjCKeywordKind getObjCKeywordID() const { return ObjCID; }
+  void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCID = ID; }
+  
   /// get/setExtension - Initialize information about whether or not this
   /// language token is an extension.  This controls extension warnings, and is
   /// only valid if a custom token ID is set.





More information about the cfe-commits mailing list