Added PushOnScopeChains method to Sema, that adds a decl to both the IdResolver and the Scope.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49567 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 169a5f7..7a86a8e 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -51,6 +51,12 @@
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 @@
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 @@
}
// 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 @@
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 @@
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 @@
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 @@
LastEnumConst);
// Register this decl in the current scope stack.
- IdResolver.AddDecl(New, S);
- S->AddDecl(New);
+ PushOnScopeChains(New, S);
return New;
}