[cfe-commits] r54794 - in /cfe/trunk: 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
Daniel Dunbar
daniel at zuster.org
Thu Aug 14 15:04:55 PDT 2008
Author: ddunbar
Date: Thu Aug 14 17:04:54 2008
New Revision: 54794
URL: http://llvm.org/viewvc/llvm-project?rev=54794&view=rev
Log:
Change Parser & Sema to use interned "super" for comparions.
- 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.
Modified:
cfe/trunk/include/clang/Lex/Token.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
Modified: cfe/trunk/include/clang/Lex/Token.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Token.h?rev=54794&r1=54793&r2=54794&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Token.h (original)
+++ cfe/trunk/include/clang/Lex/Token.h Thu Aug 14 17:04:54 2008
@@ -85,10 +85,6 @@
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;
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=54794&r1=54793&r2=54794&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Aug 14 17:04:54 2008
@@ -51,6 +51,11 @@
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 @@
if (Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope))
return true;
- return Tok.isNamedIdentifier("super");
+ return Tok.getIdentifierInfo() == Ident_super;
}
ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=54794&r1=54793&r2=54794&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Thu Aug 14 17:04:54 2008
@@ -51,12 +51,6 @@
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
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=54794&r1=54793&r2=54794&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Thu Aug 14 17:04:54 2008
@@ -267,6 +267,8 @@
&PP.getIdentifierTable().get("nonatomic");
ObjCForCollectionInKW = &PP.getIdentifierTable().get("in");
}
+
+ Ident_super = &PP.getIdentifierTable().get("super");
}
/// ParseTopLevelDecl - Parse one top-level declaration, return whatever the
Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=54794&r1=54793&r2=54794&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Thu Aug 14 17:04:54 2008
@@ -103,6 +103,8 @@
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());
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=54794&r1=54793&r2=54794&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Aug 14 17:04:54 2008
@@ -137,7 +137,10 @@
/// 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.
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=54794&r1=54793&r2=54794&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Aug 14 17:04:54 2008
@@ -328,7 +328,7 @@
}
}
// 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);
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=54794&r1=54793&r2=54794&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu Aug 14 17:04:54 2008
@@ -150,7 +150,7 @@
ObjCInterfaceDecl* ClassDecl = 0;
bool isSuper = false;
- if (!strcmp(receiverName->getName(), "super") && getCurMethodDecl()) {
+ if (receiverName == SuperID && getCurMethodDecl()) {
isSuper = true;
ClassDecl = getCurMethodDecl()->getClassInterface()->getSuperClass();
if (!ClassDecl)
More information about the cfe-commits
mailing list