Addition of TranslationUnitDecl to the AST:
-Added TranslationUnitDecl class to serve as top declaration context
-ASTContext gets a TUDecl member and a getTranslationUnitDecl() function
-All ScopedDecls get the TUDecl as DeclContext when declared at global scope
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49855 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 6d41fce..f0e4697 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -43,14 +43,18 @@
}
void Sema::PushDeclContext(DeclContext *CD) {
- assert(CD->getParent() == CurContext &&
+ assert( ( (CD->isFunctionOrMethod() && isa<TranslationUnitDecl>(CurContext))
+ || CD->getParent() == CurContext ) &&
"The next DeclContext should be directly contained in the current one.");
CurContext = CD;
}
void Sema::PopDeclContext() {
assert(CurContext && "DeclContext imbalance!");
- CurContext = CurContext->getParent();
+ // If CurContext is a ObjC method, getParent() will return NULL.
+ CurContext = CurContext->isFunctionOrMethod()
+ ? Context.getTranslationUnitDecl()
+ : CurContext->getParent();
}
/// Add this decl to the scope shadowed decl chains.