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
This commit is contained in:
Fariborz Jahanian 2007-09-29 00:54:24 +00:00
Родитель 5b6b72f53a
Коммит 9d048ff59f
7 изменённых файлов: 49 добавлений и 37 удалений

Просмотреть файл

@ -757,7 +757,8 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
MatchRHSPunctuation(tok::r_brace, LBraceLoc); 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; AttributeList *AttrList = 0;
// If attributes exist after struct contents, parse them. // If attributes exist after struct contents, parse them.

Просмотреть файл

@ -154,7 +154,7 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
if (attrList) // categories don't support attributes. if (attrList) // categories don't support attributes.
Diag(Tok, diag::err_objc_no_attributes_on_category); Diag(Tok, diag::err_objc_no_attributes_on_category);
DeclTy *CategoryType = Actions.ObjcStartCatInterface(atLoc, DeclTy *CategoryType = Actions.ObjcStartCatInterface(CurScope, atLoc,
nameId, nameLoc, nameId, nameLoc,
categoryId, categoryLoc, categoryId, categoryLoc,
&ProtocolRefs[0], &ProtocolRefs[0],
@ -268,7 +268,8 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
} }
} }
/// Insert collected methods declarations into the @interface object. /// Insert collected methods declarations into the @interface object.
Actions.ObjcAddMethodsToClass(interfaceDecl,&allMethods[0],allMethods.size()); Actions.ObjcAddMethodsToClass(CurScope,
interfaceDecl,&allMethods[0],allMethods.size());
return; return;
} }
@ -801,7 +802,7 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl) {
} }
} }
if (AllIvarDecls.size()) { // Check for {} - no ivars in braces if (AllIvarDecls.size()) { // Check for {} - no ivars in braces
Actions.ActOnFields(LBraceLoc, interfaceDecl, Actions.ActOnFields(CurScope, LBraceLoc, interfaceDecl,
&AllIvarDecls[0], AllIvarDecls.size(), &AllIvarDecls[0], AllIvarDecls.size(),
&AllVisibilities[0]); &AllVisibilities[0]);
} }
@ -968,7 +969,7 @@ Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) {
// @implementation not to have been parsed to completion and ObjcImpDecl // @implementation not to have been parsed to completion and ObjcImpDecl
// could be 0. // could be 0.
/// Insert collected methods declarations into the @interface object. /// Insert collected methods declarations into the @interface object.
Actions.ObjcAddMethodsToClass(ObjcImpDecl, Actions.ObjcAddMethodsToClass(CurScope, ObjcImpDecl,
&AllImplMethods[0],AllImplMethods.size()); &AllImplMethods[0],AllImplMethods.size());
ObjcImpDecl = 0; ObjcImpDecl = 0;
AllImplMethods.clear(); AllImplMethods.clear();

Просмотреть файл

@ -46,6 +46,7 @@ namespace clang {
class SwitchStmt; class SwitchStmt;
class OCUVectorType; class OCUVectorType;
class TypedefDecl; class TypedefDecl;
class ObjcInterfaceDecl;
/// Sema - This implements semantic analysis and AST building for C. /// Sema - This implements semantic analysis and AST building for C.
class Sema : public Action { class Sema : public Action {
@ -121,7 +122,7 @@ public:
bool Diag(SourceLocation Loc, unsigned DiagID, bool Diag(SourceLocation Loc, unsigned DiagID,
const std::string &Msg1, const std::string &Msg2, const std::string &Msg1, const std::string &Msg2,
SourceRange R1, SourceRange R2); SourceRange R1, SourceRange R2);
virtual void DeleteExpr(ExprTy *E); virtual void DeleteExpr(ExprTy *E);
virtual void DeleteStmt(StmtTy *S); virtual void DeleteStmt(StmtTy *S);
@ -157,7 +158,8 @@ private:
Declarator &D, ExprTy *BitfieldWidth); Declarator &D, ExprTy *BitfieldWidth);
// This is used for both record definitions and ObjC interface declarations. // 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, DeclTy **Fields, unsigned NumFields,
tok::ObjCKeywordKind *visibility = 0); tok::ObjCKeywordKind *visibility = 0);
virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl, virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
@ -181,6 +183,8 @@ private:
Scope *FnBodyScope); Scope *FnBodyScope);
ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
SourceLocation IdLoc, Scope *S); SourceLocation IdLoc, Scope *S);
ObjcInterfaceDecl *getObjCInterfaceDecl(Scope *S,
IdentifierInfo *Id, SourceLocation IdLoc);
ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S); ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S);
ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
Scope *S); Scope *S);
@ -364,7 +368,8 @@ public:
IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs); IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
virtual DeclTy *ObjcStartCatInterface(SourceLocation AtInterfaceLoc, virtual DeclTy *ObjcStartCatInterface(Scope* S,
SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CategoryName, SourceLocation CategoryLoc, IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs); IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
@ -384,7 +389,7 @@ public:
IdentifierInfo **IdentList, IdentifierInfo **IdentList,
unsigned NumElts); unsigned NumElts);
virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl, virtual void ObjcAddMethodsToClass(Scope* S, DeclTy *ClassDecl,
DeclTy **allMethods, unsigned allNum); DeclTy **allMethods, unsigned allNum);
virtual void ActOnImpleIvarVsClassIvars(DeclTy *ClassDecl, virtual void ActOnImpleIvarVsClassIvars(DeclTy *ClassDecl,

Просмотреть файл

@ -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 /// LookupScopedDecl - Look up the inner-most declaration in the specified
/// namespace. /// namespace.
ScopedDecl *Sema::LookupScopedDecl(IdentifierInfo *II, unsigned NSI, ScopedDecl *Sema::LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
@ -880,8 +892,7 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(Scope* S,
Diag(PrevDecl->getLocation(), diag::err_previous_definition); Diag(PrevDecl->getLocation(), diag::err_previous_definition);
} }
ObjcInterfaceDecl* IDecl = Context.getObjCInterfaceDecl(ClassName); ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(S, ClassName, ClassLoc);
if (IDecl) { if (IDecl) {
// Class already seen. Is it a forward declaration? // Class already seen. Is it a forward declaration?
if (!IDecl->getIsForwardDecl()) if (!IDecl->getIsForwardDecl())
@ -912,7 +923,7 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(Scope* S,
} }
else { else {
// Check that super class is previously defined // Check that super class is previously defined
SuperClassEntry = Context.getObjCInterfaceDecl(SuperName); SuperClassEntry = getObjCInterfaceDecl(S, SuperName, SuperLoc);
if (!SuperClassEntry || SuperClassEntry->getIsForwardDecl()) { if (!SuperClassEntry || SuperClassEntry->getIsForwardDecl()) {
Diag(AtInterfaceLoc, diag::err_undef_superclass, SuperName->getName(), Diag(AtInterfaceLoc, diag::err_undef_superclass, SuperName->getName(),
@ -932,9 +943,6 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(Scope* S,
IDecl->setIntfRefProtocols((int)i, RefPDecl); IDecl->setIntfRefProtocols((int)i, RefPDecl);
} }
Context.setObjCInterfaceDecl(ClassName, IDecl);
return IDecl; return IDecl;
} }
@ -1003,12 +1011,13 @@ Sema::ObjcForwardProtocolDeclaration(Scope *S, SourceLocation AtProtocolLoc,
return FDecl; return FDecl;
} }
Sema::DeclTy *Sema::ObjcStartCatInterface(SourceLocation AtInterfaceLoc, Sema::DeclTy *Sema::ObjcStartCatInterface(Scope* S,
SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CategoryName, SourceLocation CategoryLoc, IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) { IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
ObjcCategoryDecl *CDecl; ObjcCategoryDecl *CDecl;
ObjcInterfaceDecl* IDecl = Context.getObjCInterfaceDecl(ClassName); ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(S, ClassName, ClassLoc);
CDecl = new ObjcCategoryDecl(AtInterfaceLoc, NumProtoRefs, ClassName); CDecl = new ObjcCategoryDecl(AtInterfaceLoc, NumProtoRefs, ClassName);
if (IDecl) { if (IDecl) {
assert (ClassName->getFETokenInfo<ScopedDecl>() && "Missing @interface decl"); assert (ClassName->getFETokenInfo<ScopedDecl>() && "Missing @interface decl");
@ -1071,7 +1080,7 @@ Sema::DeclTy *Sema::ObjcStartClassImplementation(Scope *S,
} }
else { else {
// Is there an interface declaration of this class; if not, warn! // Is there an interface declaration of this class; if not, warn!
IDecl = Context.getObjCInterfaceDecl(ClassName); IDecl = getObjCInterfaceDecl(S, ClassName, ClassLoc);
if (!IDecl) if (!IDecl)
Diag(ClassLoc, diag::warn_undef_interface, ClassName->getName()); 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); Diag(PrevDecl->getLocation(), diag::err_previous_definition);
} }
else { else {
SDecl = Context.getObjCInterfaceDecl(SuperClassname); SDecl = getObjCInterfaceDecl(S, SuperClassname, SuperClassLoc);
if (!SDecl) if (!SDecl)
Diag(SuperClassLoc, diag::err_undef_superclass, Diag(SuperClassLoc, diag::err_undef_superclass,
SuperClassname->getName(), ClassName->getName()); SuperClassname->getName(), ClassName->getName());
@ -1256,13 +1265,12 @@ Sema::ObjcClassDeclaration(Scope *S, SourceLocation AtClassLoc,
for (unsigned i = 0; i != NumElts; ++i) { for (unsigned i = 0; i != NumElts; ++i) {
ObjcInterfaceDecl *IDecl; ObjcInterfaceDecl *IDecl;
IDecl = Context.getObjCInterfaceDecl(IdentList[i]); IDecl = getObjCInterfaceDecl(S, IdentList[i], AtClassLoc);
if (!IDecl) {// Already seen? if (!IDecl) {// Already seen?
IDecl = new ObjcInterfaceDecl(SourceLocation(), 0, IdentList[i], true); IDecl = new ObjcInterfaceDecl(SourceLocation(), 0, IdentList[i], true);
// Chain & install the interface decl into the identifier. // Chain & install the interface decl into the identifier.
IDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>()); IDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
IdentList[i]->setFETokenInfo(IDecl); IdentList[i]->setFETokenInfo(IDecl);
Context.setObjCInterfaceDecl(IdentList[i], IDecl);
} }
// Remember that this needs to be removed when the scope is popped. // Remember that this needs to be removed when the scope is popped.
S->AddDecl(IdentList[i]); 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, DeclTy **Fields, unsigned NumFields,
tok::ObjCKeywordKind *visibility) { tok::ObjCKeywordKind *visibility) {
Decl *EnclosingDecl = static_cast<Decl*>(RecDecl); Decl *EnclosingDecl = static_cast<Decl*>(RecDecl);
@ -1589,8 +1598,8 @@ void Sema::ActOnFields(SourceLocation RecLoc, DeclTy *RecDecl,
cast<ObjcImplementationDecl>(static_cast<Decl*>(RecDecl)); cast<ObjcImplementationDecl>(static_cast<Decl*>(RecDecl));
assert(IMPDecl && "ActOnFields - missing ObjcImplementationDecl"); assert(IMPDecl && "ActOnFields - missing ObjcImplementationDecl");
IMPDecl->ObjcAddInstanceVariablesToClassImpl(ClsFields, RecFields.size()); IMPDecl->ObjcAddInstanceVariablesToClassImpl(ClsFields, RecFields.size());
ObjcInterfaceDecl* IDecl = ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(S,
Context.getObjCInterfaceDecl(IMPDecl->getIdentifier()); IMPDecl->getIdentifier(), RecLoc);
if (IDecl) if (IDecl)
ActOnImpleIvarVsClassIvars(static_cast<DeclTy*>(IDecl), ActOnImpleIvarVsClassIvars(static_cast<DeclTy*>(IDecl),
reinterpret_cast<DeclTy**>(&RecFields[0]), RecFields.size()); 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) { DeclTy **allMethods, unsigned allNum) {
// FIXME: Fix this when we can handle methods declared in protocols. // FIXME: Fix this when we can handle methods declared in protocols.
// See Parser::ParseObjCAtProtocolDeclaration // See Parser::ParseObjCAtProtocolDeclaration
@ -1639,8 +1648,8 @@ void Sema::ObjcAddMethodsToClass(DeclTy *ClassDecl,
static_cast<Decl*>(ClassDecl)); static_cast<Decl*>(ClassDecl));
ImplClass->ObjcAddImplMethods(&insMethods[0], insMethods.size(), ImplClass->ObjcAddImplMethods(&insMethods[0], insMethods.size(),
&clsMethods[0], clsMethods.size()); &clsMethods[0], clsMethods.size());
ObjcInterfaceDecl* IDecl = ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(S,
Context.getObjCInterfaceDecl(ImplClass->getIdentifier()); ImplClass->getIdentifier(), SourceLocation());
if (IDecl) if (IDecl)
ImplMethodsVsClassMethods(this, ImplClass, IDecl); ImplMethodsVsClassMethods(this, ImplClass, IDecl);
} }

Просмотреть файл

@ -733,6 +733,7 @@
08FB7793FE84155DC02AAC07 /* Project object */ = { 08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject; isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */; buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1; hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */; mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = ""; projectDirPath = "";

Просмотреть файл

@ -39,7 +39,6 @@ class ASTContext {
llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos; llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos;
llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos; llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos;
llvm::DenseMap<const RecordDecl*, const RecordLayout*> RecordLayoutInfo; llvm::DenseMap<const RecordDecl*, const RecordLayout*> RecordLayoutInfo;
llvm::DenseMap<const IdentifierInfo*, ObjcInterfaceDecl*> ClassNameInfo;
llvm::DenseMap<const IdentifierInfo*, ObjcProtocolDecl*> ProtocolNameInfo; llvm::DenseMap<const IdentifierInfo*, ObjcProtocolDecl*> ProtocolNameInfo;
llvm::SmallVector<ObjcImplementationDecl*, 8> ImplementationClassInfo; llvm::SmallVector<ObjcImplementationDecl*, 8> ImplementationClassInfo;
RecordDecl *CFConstantStringTypeDecl; RecordDecl *CFConstantStringTypeDecl;
@ -166,12 +165,6 @@ public:
/// position information. /// position information.
const RecordLayout &getRecordLayout(const RecordDecl *D, SourceLocation L); 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) ObjcProtocolDecl* getObjCProtocolDecl(const IdentifierInfo* ProtocolName)
{ return ProtocolNameInfo[ProtocolName]; } { return ProtocolNameInfo[ProtocolName]; }
void setObjCProtocolDecl(const IdentifierInfo* ProtocolName, void setObjCProtocolDecl(const IdentifierInfo* ProtocolName,

Просмотреть файл

@ -174,7 +174,8 @@ public:
Declarator &D, ExprTy *BitfieldWidth) { Declarator &D, ExprTy *BitfieldWidth) {
return 0; return 0;
} }
virtual void ActOnFields(SourceLocation RecLoc, DeclTy *TagDecl, virtual void ActOnFields(Scope* S,
SourceLocation RecLoc, DeclTy *TagDecl,
DeclTy **Fields, unsigned NumFields, DeclTy **Fields, unsigned NumFields,
tok::ObjCKeywordKind *visibility = 0) {} tok::ObjCKeywordKind *visibility = 0) {}
virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl, virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
@ -443,7 +444,7 @@ public:
AttributeList *AttrList) { AttributeList *AttrList) {
return 0; return 0;
} }
virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl, virtual void ObjcAddMethodsToClass(Scope* S, DeclTy *ClassDecl,
DeclTy **allMethods, unsigned allNum) { DeclTy **allMethods, unsigned allNum) {
return; return;
} }
@ -457,7 +458,8 @@ public:
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) { IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
return 0; return 0;
} }
virtual DeclTy *ObjcStartCatInterface(SourceLocation AtInterfaceLoc, virtual DeclTy *ObjcStartCatInterface(Scope* S,
SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CategoryName, SourceLocation CategoryLoc, IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) { IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {