aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2007-09-29 00:54:24 +0000
committerFariborz Jahanian <fjahanian@apple.com>2007-09-29 00:54:24 +0000
commit9d048ff59ffb5d41e57297c6509c11920052cf67 (patch)
tree1668110a59f546c4a33fff0a159e9b0857b8b1fb
parent5b6b72f53ad164497cf62484b60cdbb4361f1978 (diff)
Removed use of hash table for class decls and do a name look up directly.
There is still an issue if doing ScopedLookup is an overkill and we can just access the decl using the identifier. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42463 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Parse/ParseDecl.cpp3
-rw-r--r--Parse/ParseObjc.cpp9
-rw-r--r--Sema/Sema.h13
-rw-r--r--Sema/SemaDecl.cpp45
-rw-r--r--clang.xcodeproj/project.pbxproj1
-rw-r--r--include/clang/AST/ASTContext.h7
-rw-r--r--include/clang/Parse/Action.h8
7 files changed, 49 insertions, 37 deletions
diff --git a/Parse/ParseDecl.cpp b/Parse/ParseDecl.cpp
index 7fbab64d11..db568df26e 100644
--- a/Parse/ParseDecl.cpp
+++ b/Parse/ParseDecl.cpp
@@ -757,7 +757,8 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
MatchRHSPunctuation(tok::r_brace, LBraceLoc);
- Actions.ActOnFields(RecordLoc,TagDecl,&FieldDecls[0],FieldDecls.size());
+ Actions.ActOnFields(CurScope,
+ RecordLoc,TagDecl,&FieldDecls[0],FieldDecls.size());
AttributeList *AttrList = 0;
// If attributes exist after struct contents, parse them.
diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp
index be0e026157..e367834f70 100644
--- a/Parse/ParseObjc.cpp
+++ b/Parse/ParseObjc.cpp
@@ -154,7 +154,7 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
if (attrList) // categories don't support attributes.
Diag(Tok, diag::err_objc_no_attributes_on_category);
- DeclTy *CategoryType = Actions.ObjcStartCatInterface(atLoc,
+ DeclTy *CategoryType = Actions.ObjcStartCatInterface(CurScope, atLoc,
nameId, nameLoc,
categoryId, categoryLoc,
&ProtocolRefs[0],
@@ -268,7 +268,8 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
}
}
/// Insert collected methods declarations into the @interface object.
- Actions.ObjcAddMethodsToClass(interfaceDecl,&allMethods[0],allMethods.size());
+ Actions.ObjcAddMethodsToClass(CurScope,
+ interfaceDecl,&allMethods[0],allMethods.size());
return;
}
@@ -801,7 +802,7 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl) {
}
}
if (AllIvarDecls.size()) { // Check for {} - no ivars in braces
- Actions.ActOnFields(LBraceLoc, interfaceDecl,
+ Actions.ActOnFields(CurScope, LBraceLoc, interfaceDecl,
&AllIvarDecls[0], AllIvarDecls.size(),
&AllVisibilities[0]);
}
@@ -968,7 +969,7 @@ Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) {
// @implementation not to have been parsed to completion and ObjcImpDecl
// could be 0.
/// Insert collected methods declarations into the @interface object.
- Actions.ObjcAddMethodsToClass(ObjcImpDecl,
+ Actions.ObjcAddMethodsToClass(CurScope, ObjcImpDecl,
&AllImplMethods[0],AllImplMethods.size());
ObjcImpDecl = 0;
AllImplMethods.clear();
diff --git a/Sema/Sema.h b/Sema/Sema.h
index d9a1cc4fe2..2c753f3aa5 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -46,6 +46,7 @@ namespace clang {
class SwitchStmt;
class OCUVectorType;
class TypedefDecl;
+ class ObjcInterfaceDecl;
/// Sema - This implements semantic analysis and AST building for C.
class Sema : public Action {
@@ -121,7 +122,7 @@ public:
bool Diag(SourceLocation Loc, unsigned DiagID,
const std::string &Msg1, const std::string &Msg2,
SourceRange R1, SourceRange R2);
-
+
virtual void DeleteExpr(ExprTy *E);
virtual void DeleteStmt(StmtTy *S);
@@ -157,7 +158,8 @@ private:
Declarator &D, ExprTy *BitfieldWidth);
// This is used for both record definitions and ObjC interface declarations.
- virtual void ActOnFields(SourceLocation RecLoc, DeclTy *TagDecl,
+ virtual void ActOnFields(Scope* S,
+ SourceLocation RecLoc, DeclTy *TagDecl,
DeclTy **Fields, unsigned NumFields,
tok::ObjCKeywordKind *visibility = 0);
virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
@@ -181,6 +183,8 @@ private:
Scope *FnBodyScope);
ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
SourceLocation IdLoc, Scope *S);
+ ObjcInterfaceDecl *getObjCInterfaceDecl(Scope *S,
+ IdentifierInfo *Id, SourceLocation IdLoc);
ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S);
ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
Scope *S);
@@ -364,7 +368,8 @@ public:
IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
- virtual DeclTy *ObjcStartCatInterface(SourceLocation AtInterfaceLoc,
+ virtual DeclTy *ObjcStartCatInterface(Scope* S,
+ SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
@@ -384,7 +389,7 @@ public:
IdentifierInfo **IdentList,
unsigned NumElts);
- virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl,
+ virtual void ObjcAddMethodsToClass(Scope* S, DeclTy *ClassDecl,
DeclTy **allMethods, unsigned allNum);
virtual void ActOnImpleIvarVsClassIvars(DeclTy *ClassDecl,
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 28682cc0e5..2b0e1452f6 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -78,6 +78,18 @@ void Sema::PopScope(SourceLocation Loc, Scope *S) {
}
}
+/// ObjcInterfaceDecl - Look up a for a class declaration in the scope.
+/// return 0 if one not found.
+ObjcInterfaceDecl *Sema::getObjCInterfaceDecl(Scope *S,
+ IdentifierInfo *Id,
+ SourceLocation IdLoc) {
+ ScopedDecl *IdDecl = LookupScopedDecl(Id, Decl::IDNS_Ordinary,
+ IdLoc, S);
+ if (IdDecl && !isa<ObjcInterfaceDecl>(IdDecl))
+ IdDecl = 0;
+ return cast_or_null<ObjcInterfaceDecl>(static_cast<Decl*>(IdDecl));
+}
+
/// LookupScopedDecl - Look up the inner-most declaration in the specified
/// namespace.
ScopedDecl *Sema::LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
@@ -880,8 +892,7 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(Scope* S,
Diag(PrevDecl->getLocation(), diag::err_previous_definition);
}
- ObjcInterfaceDecl* IDecl = Context.getObjCInterfaceDecl(ClassName);
-
+ ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(S, ClassName, ClassLoc);
if (IDecl) {
// Class already seen. Is it a forward declaration?
if (!IDecl->getIsForwardDecl())
@@ -912,7 +923,7 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(Scope* S,
}
else {
// Check that super class is previously defined
- SuperClassEntry = Context.getObjCInterfaceDecl(SuperName);
+ SuperClassEntry = getObjCInterfaceDecl(S, SuperName, SuperLoc);
if (!SuperClassEntry || SuperClassEntry->getIsForwardDecl()) {
Diag(AtInterfaceLoc, diag::err_undef_superclass, SuperName->getName(),
@@ -932,9 +943,6 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(Scope* S,
IDecl->setIntfRefProtocols((int)i, RefPDecl);
}
-
- Context.setObjCInterfaceDecl(ClassName, IDecl);
-
return IDecl;
}
@@ -1003,12 +1011,13 @@ Sema::ObjcForwardProtocolDeclaration(Scope *S, SourceLocation AtProtocolLoc,
return FDecl;
}
-Sema::DeclTy *Sema::ObjcStartCatInterface(SourceLocation AtInterfaceLoc,
+Sema::DeclTy *Sema::ObjcStartCatInterface(Scope* S,
+ SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
ObjcCategoryDecl *CDecl;
- ObjcInterfaceDecl* IDecl = Context.getObjCInterfaceDecl(ClassName);
+ ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(S, ClassName, ClassLoc);
CDecl = new ObjcCategoryDecl(AtInterfaceLoc, NumProtoRefs, ClassName);
if (IDecl) {
assert (ClassName->getFETokenInfo<ScopedDecl>() && "Missing @interface decl");
@@ -1071,7 +1080,7 @@ Sema::DeclTy *Sema::ObjcStartClassImplementation(Scope *S,
}
else {
// Is there an interface declaration of this class; if not, warn!
- IDecl = Context.getObjCInterfaceDecl(ClassName);
+ IDecl = getObjCInterfaceDecl(S, ClassName, ClassLoc);
if (!IDecl)
Diag(ClassLoc, diag::warn_undef_interface, ClassName->getName());
}
@@ -1089,7 +1098,7 @@ Sema::DeclTy *Sema::ObjcStartClassImplementation(Scope *S,
Diag(PrevDecl->getLocation(), diag::err_previous_definition);
}
else {
- SDecl = Context.getObjCInterfaceDecl(SuperClassname);
+ SDecl = getObjCInterfaceDecl(S, SuperClassname, SuperClassLoc);
if (!SDecl)
Diag(SuperClassLoc, diag::err_undef_superclass,
SuperClassname->getName(), ClassName->getName());
@@ -1256,13 +1265,12 @@ Sema::ObjcClassDeclaration(Scope *S, SourceLocation AtClassLoc,
for (unsigned i = 0; i != NumElts; ++i) {
ObjcInterfaceDecl *IDecl;
- IDecl = Context.getObjCInterfaceDecl(IdentList[i]);
+ IDecl = getObjCInterfaceDecl(S, IdentList[i], AtClassLoc);
if (!IDecl) {// Already seen?
IDecl = new ObjcInterfaceDecl(SourceLocation(), 0, IdentList[i], true);
// Chain & install the interface decl into the identifier.
IDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
IdentList[i]->setFETokenInfo(IDecl);
- Context.setObjCInterfaceDecl(IdentList[i], IDecl);
}
// Remember that this needs to be removed when the scope is popped.
S->AddDecl(IdentList[i]);
@@ -1452,7 +1460,8 @@ static void ObjcSetIvarVisibility(ObjcIvarDecl *OIvar,
}
}
-void Sema::ActOnFields(SourceLocation RecLoc, DeclTy *RecDecl,
+void Sema::ActOnFields(Scope* S,
+ SourceLocation RecLoc, DeclTy *RecDecl,
DeclTy **Fields, unsigned NumFields,
tok::ObjCKeywordKind *visibility) {
Decl *EnclosingDecl = static_cast<Decl*>(RecDecl);
@@ -1589,8 +1598,8 @@ void Sema::ActOnFields(SourceLocation RecLoc, DeclTy *RecDecl,
cast<ObjcImplementationDecl>(static_cast<Decl*>(RecDecl));
assert(IMPDecl && "ActOnFields - missing ObjcImplementationDecl");
IMPDecl->ObjcAddInstanceVariablesToClassImpl(ClsFields, RecFields.size());
- ObjcInterfaceDecl* IDecl =
- Context.getObjCInterfaceDecl(IMPDecl->getIdentifier());
+ ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(S,
+ IMPDecl->getIdentifier(), RecLoc);
if (IDecl)
ActOnImpleIvarVsClassIvars(static_cast<DeclTy*>(IDecl),
reinterpret_cast<DeclTy**>(&RecFields[0]), RecFields.size());
@@ -1598,7 +1607,7 @@ void Sema::ActOnFields(SourceLocation RecLoc, DeclTy *RecDecl,
}
}
-void Sema::ObjcAddMethodsToClass(DeclTy *ClassDecl,
+void Sema::ObjcAddMethodsToClass(Scope* S, DeclTy *ClassDecl,
DeclTy **allMethods, unsigned allNum) {
// FIXME: Fix this when we can handle methods declared in protocols.
// See Parser::ParseObjCAtProtocolDeclaration
@@ -1639,8 +1648,8 @@ void Sema::ObjcAddMethodsToClass(DeclTy *ClassDecl,
static_cast<Decl*>(ClassDecl));
ImplClass->ObjcAddImplMethods(&insMethods[0], insMethods.size(),
&clsMethods[0], clsMethods.size());
- ObjcInterfaceDecl* IDecl =
- Context.getObjCInterfaceDecl(ImplClass->getIdentifier());
+ ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(S,
+ ImplClass->getIdentifier(), SourceLocation());
if (IDecl)
ImplMethodsVsClassMethods(this, ImplClass, IDecl);
}
diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj
index 04dad73923..fca0464b47 100644
--- a/clang.xcodeproj/project.pbxproj
+++ b/clang.xcodeproj/project.pbxproj
@@ -733,6 +733,7 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
+ compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index 86051eaa3c..59b1387eda 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -39,7 +39,6 @@ class ASTContext {
llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos;
llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos;
llvm::DenseMap<const RecordDecl*, const RecordLayout*> RecordLayoutInfo;
- llvm::DenseMap<const IdentifierInfo*, ObjcInterfaceDecl*> ClassNameInfo;
llvm::DenseMap<const IdentifierInfo*, ObjcProtocolDecl*> ProtocolNameInfo;
llvm::SmallVector<ObjcImplementationDecl*, 8> ImplementationClassInfo;
RecordDecl *CFConstantStringTypeDecl;
@@ -166,12 +165,6 @@ public:
/// position information.
const RecordLayout &getRecordLayout(const RecordDecl *D, SourceLocation L);
- ObjcInterfaceDecl* getObjCInterfaceDecl(const IdentifierInfo* ClassName)
- { return ClassNameInfo[ClassName]; }
- void setObjCInterfaceDecl(const IdentifierInfo* ClassName,
- ObjcInterfaceDecl* InterfaceDecl)
- { ClassNameInfo[ClassName] = InterfaceDecl; }
-
ObjcProtocolDecl* getObjCProtocolDecl(const IdentifierInfo* ProtocolName)
{ return ProtocolNameInfo[ProtocolName]; }
void setObjCProtocolDecl(const IdentifierInfo* ProtocolName,
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h
index 9ef27de47d..34561f7a2e 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -174,7 +174,8 @@ public:
Declarator &D, ExprTy *BitfieldWidth) {
return 0;
}
- virtual void ActOnFields(SourceLocation RecLoc, DeclTy *TagDecl,
+ virtual void ActOnFields(Scope* S,
+ SourceLocation RecLoc, DeclTy *TagDecl,
DeclTy **Fields, unsigned NumFields,
tok::ObjCKeywordKind *visibility = 0) {}
virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
@@ -443,7 +444,7 @@ public:
AttributeList *AttrList) {
return 0;
}
- virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl,
+ virtual void ObjcAddMethodsToClass(Scope* S, DeclTy *ClassDecl,
DeclTy **allMethods, unsigned allNum) {
return;
}
@@ -457,7 +458,8 @@ public:
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
return 0;
}
- virtual DeclTy *ObjcStartCatInterface(SourceLocation AtInterfaceLoc,
+ virtual DeclTy *ObjcStartCatInterface(Scope* S,
+ SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {