From b8a4920d6288905c18f5d54d297edc0d7cdb5e79 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sat, 12 Apr 2008 00:47:19 +0000 Subject: [PATCH] Added PushOnScopeChains method to Sema, that adds a decl to both the IdResolver and the Scope. llvm-svn: 49567 --- clang/lib/Sema/Sema.cpp | 15 +++++---------- clang/lib/Sema/Sema.h | 3 +++ clang/lib/Sema/SemaDecl.cpp | 36 ++++++++++++++++-------------------- 3 files changed, 24 insertions(+), 30 deletions(-) diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 92858726b483..c6a862b2b1e2 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -48,31 +48,26 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { // Add the built-in ObjC types. t = cast(Context.getObjCIdType().getTypePtr()); - IdResolver.AddDecl(t->getDecl(), S); - TUScope->AddDecl(t->getDecl()); + PushOnScopeChains(t->getDecl(), TUScope); t = cast(Context.getObjCClassType().getTypePtr()); - IdResolver.AddDecl(t->getDecl(), S); - TUScope->AddDecl(t->getDecl()); + PushOnScopeChains(t->getDecl(), TUScope); ObjCInterfaceType *it = cast(Context.getObjCProtoType()); ObjCInterfaceDecl *IDecl = it->getDecl(); - IdResolver.AddDecl(IDecl, S); - TUScope->AddDecl(IDecl); + PushOnScopeChains(IDecl, TUScope); // Synthesize "typedef struct objc_selector *SEL;" RecordDecl *SelTag = RecordDecl::Create(Context, Decl::Struct, CurContext, SourceLocation(), &Context.Idents.get("objc_selector"), 0); - IdResolver.AddDecl(SelTag, S); - TUScope->AddDecl(SelTag); + PushOnScopeChains(SelTag, TUScope); QualType SelT = Context.getPointerType(Context.getTagDeclType(SelTag)); TypedefDecl *SelTypedef = TypedefDecl::Create(Context, CurContext, SourceLocation(), &Context.Idents.get("SEL"), SelT, 0); - IdResolver.AddDecl(SelTypedef, S); - TUScope->AddDecl(SelTypedef); + PushOnScopeChains(SelTypedef, TUScope); Context.setObjCSelType(SelTypedef); } diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index cf22f6808873..226ffa233d48 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/lib/Sema/Sema.h @@ -261,6 +261,9 @@ private: void PushDeclContext(DeclContext *CD); void PopDeclContext(); + /// Add this decl to the scope shadowed decl chains. + void PushOnScopeChains(NamedDecl *D, Scope *S); + /// Subroutines of ActOnDeclarator(). TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, ScopedDecl *LastDecl); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 169a5f77fb15..7a86a8e7d3d2 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -51,6 +51,12 @@ void Sema::PopDeclContext() { CurContext = CurContext->getParent(); } +/// Add this decl to the scope shadowed decl chains. +void Sema::PushOnScopeChains(NamedDecl *D, Scope *S) { + IdResolver.AddDecl(D, S); + S->AddDecl(D); +} + void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) { if (S->decl_empty()) return; assert((S->getFlags() & Scope::DeclScope) &&"Scope shouldn't contain decls!"); @@ -429,10 +435,8 @@ Sema::CreateImplicitParameter(Scope *S, IdentifierInfo *Id, SourceLocation IdLoc, QualType Type) { ParmVarDecl *New = ParmVarDecl::Create(Context, CurContext, IdLoc, Id, Type, VarDecl::None, 0, 0); - if (Id) { - IdResolver.AddDecl(New, S); - S->AddDecl(New); - } + if (Id) + PushOnScopeChains(New, S); return New; } @@ -896,10 +900,8 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) { } // If this has an identifier, add it to the scope stack. - if (II) { - IdResolver.AddDecl(New, S); - S->AddDecl(New); - } + if (II) + PushOnScopeChains(New, S); // If any semantic error occurred, mark the decl as invalid. if (D.getInvalidType() || InvalidDecl) New->setInvalidDecl(); @@ -1117,10 +1119,8 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { if (D.getInvalidType()) New->setInvalidDecl(); - if (II) { - IdResolver.AddDecl(New, S); - S->AddDecl(New); - } + if (II) + PushOnScopeChains(New, S); HandleDeclAttributes(New, D.getAttributes(), 0); return New; @@ -1184,10 +1184,8 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) { for (unsigned p = 0, NumParams = FD->getNumParams(); p < NumParams; ++p) { ParmVarDecl *Param = FD->getParamDecl(p); // If this has an identifier, add it to the scope stack. - if (Param->getIdentifier()) { - IdResolver.AddDecl(Param, FnBodyScope); - FnBodyScope->AddDecl(Param); - } + if (Param->getIdentifier()) + PushOnScopeChains(Param, FnBodyScope); } return FD; @@ -1378,8 +1376,7 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK, S = S->getParent(); // Add it to the decl chain. - IdResolver.AddDecl(New, S); - S->AddDecl(New); + PushOnScopeChains(New, S); } HandleDeclAttributes(New, Attr, 0); @@ -1718,8 +1715,7 @@ Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl, LastEnumConst); // Register this decl in the current scope stack. - IdResolver.AddDecl(New, S); - S->AddDecl(New); + PushOnScopeChains(New, S); return New; }