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/Sema.cpp b/lib/Sema/Sema.cpp
index c6a862b..bb5316a 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -42,6 +42,7 @@
void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
TUScope = S;
+ CurContext = Context.getTranslationUnitDecl();
if (!PP.getLangOptions().ObjC1) return;
TypedefType *t;
@@ -93,14 +94,16 @@
// FIXME: Move this initialization up to Sema::ActOnTranslationUnitScope()
// and make sure the decls get inserted into TUScope!
if (PP.getLangOptions().ObjC1) {
+ TranslationUnitDecl *TUDecl = Context.getTranslationUnitDecl();
+
// Synthesize "typedef struct objc_class *Class;"
RecordDecl *ClassTag = RecordDecl::Create(Context, Decl::Struct,
- NULL,
+ TUDecl,
SourceLocation(),
&IT.get("objc_class"), 0);
QualType ClassT = Context.getPointerType(Context.getTagDeclType(ClassTag));
TypedefDecl *ClassTypedef =
- TypedefDecl::Create(Context, NULL, SourceLocation(),
+ TypedefDecl::Create(Context, TUDecl, SourceLocation(),
&Context.Idents.get("Class"), ClassT, 0);
Context.setObjCClassType(ClassTypedef);
@@ -113,14 +116,14 @@
// Synthesize "typedef struct objc_object { Class isa; } *id;"
RecordDecl *ObjectTag =
- RecordDecl::Create(Context, Decl::Struct, NULL,
+ RecordDecl::Create(Context, Decl::Struct, TUDecl,
SourceLocation(),
&IT.get("objc_object"), 0);
FieldDecl *IsaDecl = FieldDecl::Create(Context, SourceLocation(), 0,
Context.getObjCClassType());
ObjectTag->defineBody(&IsaDecl, 1);
QualType ObjT = Context.getPointerType(Context.getTagDeclType(ObjectTag));
- TypedefDecl *IdTypedef = TypedefDecl::Create(Context, NULL,
+ TypedefDecl *IdTypedef = TypedefDecl::Create(Context, TUDecl,
SourceLocation(),
&Context.Idents.get("id"),
ObjT, 0);