ASTContext *Context;
SourceManager *SM;
+ TranslationUnitDecl *TUDecl;
unsigned MainFileID;
const char *MainFileStart, *MainFileEnd;
SourceLocation LastIncLoc;
void RewriteObjC::Initialize(ASTContext &context) {
Context = &context;
SM = &Context->getSourceManager();
+ TUDecl = Context->getTranslationUnitDecl();
MsgSendFunctionDecl = 0;
MsgSendSuperFunctionDecl = 0;
MsgSendStretFunctionDecl = 0;
std::string RecName = clsDeclared->getIdentifier()->getName();
RecName += "_IMPL";
IdentifierInfo *II = &Context->Idents.get(RecName.c_str());
- RecordDecl *RD = RecordDecl::Create(*Context, Decl::Struct, NULL,
+ RecordDecl *RD = RecordDecl::Create(*Context, Decl::Struct, TUDecl,
SourceLocation(), II, 0);
assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl");
QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
QualType getFuncType = Context->getFunctionType(Context->getObjCSelType(),
&ArgTys[0], ArgTys.size(),
false /*isVariadic*/);
- SelGetUidFunctionDecl = FunctionDecl::Create(*Context, NULL,
+ SelGetUidFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
SelGetUidIdent, getFuncType,
FunctionDecl::Extern, false, 0);
QualType getFuncType = Context->getFunctionType(Context->getObjCProtoType(),
&ArgTys[0], ArgTys.size(),
false /*isVariadic*/);
- GetProtocolFunctionDecl = FunctionDecl::Create(*Context, NULL,
+ GetProtocolFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
SelGetProtoIdent, getFuncType,
FunctionDecl::Extern, false, 0);
QualType msgSendType = Context->getFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(),
false);
- SuperContructorFunctionDecl = FunctionDecl::Create(*Context, NULL,
+ SuperContructorFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
msgSendIdent, msgSendType,
FunctionDecl::Extern, false, 0);
QualType msgSendType = Context->getFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(),
true /*isVariadic*/);
- MsgSendFunctionDecl = FunctionDecl::Create(*Context, NULL,
+ MsgSendFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
msgSendIdent, msgSendType,
FunctionDecl::Extern, false, 0);
void RewriteObjC::SynthMsgSendSuperFunctionDecl() {
IdentifierInfo *msgSendIdent = &Context->Idents.get("objc_msgSendSuper");
llvm::SmallVector<QualType, 16> ArgTys;
- RecordDecl *RD = RecordDecl::Create(*Context, Decl::Struct, NULL,
+ RecordDecl *RD = RecordDecl::Create(*Context, Decl::Struct, TUDecl,
SourceLocation(),
&Context->Idents.get("objc_super"), 0);
QualType argT = Context->getPointerType(Context->getTagDeclType(RD));
QualType msgSendType = Context->getFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(),
true /*isVariadic*/);
- MsgSendSuperFunctionDecl = FunctionDecl::Create(*Context, NULL,
+ MsgSendSuperFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
msgSendIdent, msgSendType,
FunctionDecl::Extern, false, 0);
QualType msgSendType = Context->getFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(),
true /*isVariadic*/);
- MsgSendStretFunctionDecl = FunctionDecl::Create(*Context, NULL,
+ MsgSendStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
msgSendIdent, msgSendType,
FunctionDecl::Extern, false, 0);
IdentifierInfo *msgSendIdent =
&Context->Idents.get("objc_msgSendSuper_stret");
llvm::SmallVector<QualType, 16> ArgTys;
- RecordDecl *RD = RecordDecl::Create(*Context, Decl::Struct, NULL,
+ RecordDecl *RD = RecordDecl::Create(*Context, Decl::Struct, TUDecl,
SourceLocation(),
&Context->Idents.get("objc_super"), 0);
QualType argT = Context->getPointerType(Context->getTagDeclType(RD));
QualType msgSendType = Context->getFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(),
true /*isVariadic*/);
- MsgSendSuperStretFunctionDecl = FunctionDecl::Create(*Context, NULL,
+ MsgSendSuperStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
msgSendIdent, msgSendType,
FunctionDecl::Extern, false, 0);
QualType msgSendType = Context->getFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(),
true /*isVariadic*/);
- MsgSendFpretFunctionDecl = FunctionDecl::Create(*Context, NULL,
+ MsgSendFpretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
msgSendIdent, msgSendType,
FunctionDecl::Extern, false, 0);
QualType getClassType = Context->getFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(),
false /*isVariadic*/);
- GetClassFunctionDecl = FunctionDecl::Create(*Context, NULL,
+ GetClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
getClassIdent, getClassType,
FunctionDecl::Extern, false, 0);
QualType getClassType = Context->getFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(),
false /*isVariadic*/);
- GetMetaClassFunctionDecl = FunctionDecl::Create(*Context, NULL,
+ GetMetaClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
getClassIdent, getClassType,
FunctionDecl::Extern, false, 0);
// The minus 2 removes the begin/end double quotes.
Preamble += utostr(prettyBuf.str().size()-2) + "};\n";
- VarDecl *NewVD = VarDecl::Create(*Context, NULL, SourceLocation(),
+ VarDecl *NewVD = VarDecl::Create(*Context, TUDecl, SourceLocation(),
&Context->Idents.get(S.c_str()), strType,
VarDecl::Static, NULL);
DeclRefExpr *DRE = new DeclRefExpr(NewVD, strType, SourceLocation());
// struct objc_super { struct objc_object *receiver; struct objc_class *super; };
QualType RewriteObjC::getSuperStructType() {
if (!SuperStructDecl) {
- SuperStructDecl = RecordDecl::Create(*Context, Decl::Struct, NULL,
+ SuperStructDecl = RecordDecl::Create(*Context, Decl::Struct, TUDecl,
SourceLocation(),
&Context->Idents.get("objc_super"), 0);
QualType FieldTypes[2];
QualType RewriteObjC::getConstantStringStructType() {
if (!ConstantStringDecl) {
- ConstantStringDecl = RecordDecl::Create(*Context, Decl::Struct, NULL,
+ ConstantStringDecl = RecordDecl::Create(*Context, Decl::Struct, TUDecl,
SourceLocation(),
&Context->Idents.get("__NSConstantStringImpl"), 0);
QualType FieldTypes[4];
}
}
+
void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
TUScope = S;
+ CurContext = Context.getTranslationUnitDecl();
if (!PP.getLangOptions().ObjC1) return;
TypedefType *t;
// 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);
// 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);