// getCFConstantStringType - Return the type used for constant CFStrings.
QualType ASTContext::getCFConstantStringType() {
if (!CFConstantStringTypeDecl) {
- CFConstantStringTypeDecl = new RecordDecl(Decl::Struct, SourceLocation(),
- &Idents.get("NSConstantString"),
- 0);
+ CFConstantStringTypeDecl =
+ RecordDecl::Create(Decl::Struct, SourceLocation(),
+ &Idents.get("NSConstantString"), 0, *this);
QualType FieldTypes[4];
// const int *isa;
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
+#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
#include "clang/Basic/IdentifierTable.h"
#include "llvm/ADT/DenseMap.h"
}
}
+//===----------------------------------------------------------------------===//
+// Decl Allocation/Deallocation Method Implementations
+//===----------------------------------------------------------------------===//
+
+EnumConstantDecl *EnumConstantDecl::Create(SourceLocation L, IdentifierInfo *Id,
+ QualType T, Expr *E,
+ const llvm::APSInt &V,
+ ScopedDecl *PrevDecl, ASTContext &C){
+ void *Mem = C.getAllocator().Allocate<EnumConstantDecl>();
+ return new (Mem) EnumConstantDecl(L, Id, T, E, V, PrevDecl);
+}
+
+TypedefDecl *TypedefDecl::Create(SourceLocation L, IdentifierInfo *Id,
+ QualType T, ScopedDecl *PD, ASTContext &C) {
+ void *Mem = C.getAllocator().Allocate<TypedefDecl>();
+ return new (Mem) TypedefDecl(L, Id, T, PD);
+}
+
+EnumDecl *EnumDecl::Create(SourceLocation L, IdentifierInfo *Id,
+ ScopedDecl *PrevDecl, ASTContext &C) {
+ void *Mem = C.getAllocator().Allocate<EnumDecl>();
+ return new (Mem) EnumDecl(L, Id, PrevDecl);
+}
+
+RecordDecl *RecordDecl::Create(Kind DK, SourceLocation L, IdentifierInfo *Id,
+ ScopedDecl *PrevDecl, ASTContext &C) {
+ void *Mem = C.getAllocator().Allocate<RecordDecl>();
+ return new (Mem) RecordDecl(DK, L, Id, PrevDecl);
+}
+
+
//===----------------------------------------------------------------------===//
// Decl Implementation
//===----------------------------------------------------------------------===//
return 0;
}
-
//===----------------------------------------------------------------------===//
// Objective-C Decl Implementation
//===----------------------------------------------------------------------===//
std::string RecName = clsDeclared->getIdentifier()->getName();
RecName += "_IMPL";
IdentifierInfo *II = &Context->Idents.get(RecName.c_str());
- RecordDecl *RD = new RecordDecl(Decl::Struct, SourceLocation(), II, 0);
+ RecordDecl *RD = RecordDecl::Create(Decl::Struct, SourceLocation(), II, 0, *Context);
assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl");
QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
CastExpr *castExpr = new CastExpr(castT, IV->getBase(), SourceLocation());
void RewriteTest::SynthMsgSendSuperFunctionDecl() {
IdentifierInfo *msgSendIdent = &Context->Idents.get("objc_msgSendSuper");
llvm::SmallVector<QualType, 16> ArgTys;
- RecordDecl *RD = new RecordDecl(Decl::Struct, SourceLocation(),
- &Context->Idents.get("objc_super"), 0);
+ RecordDecl *RD = RecordDecl::Create(Decl::Struct, SourceLocation(),
+ &Context->Idents.get("objc_super"), 0,
+ *Context);
QualType argT = Context->getPointerType(Context->getTagDeclType(RD));
assert(!argT.isNull() && "Can't build 'struct objc_super *' type");
ArgTys.push_back(argT);
IdentifierInfo *msgSendIdent =
&Context->Idents.get("objc_msgSendSuper_stret");
llvm::SmallVector<QualType, 16> ArgTys;
- RecordDecl *RD = new RecordDecl(Decl::Struct, SourceLocation(),
- &Context->Idents.get("objc_super"), 0);
+ RecordDecl *RD = RecordDecl::Create(Decl::Struct, SourceLocation(),
+ &Context->Idents.get("objc_super"), 0,
+ *Context);
QualType argT = Context->getPointerType(Context->getTagDeclType(RD));
assert(!argT.isNull() && "Can't build 'struct objc_super *' type");
ArgTys.push_back(argT);
ObjCInterfaceDecl *RewriteTest::isSuperReceiver(Expr *recExpr) {
// check if we are sending a message to 'super'
- if (CurMethodDecl && CurMethodDecl->isInstance()) {
- if (CastExpr *CE = dyn_cast<CastExpr>(recExpr)) {
- if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr())) {
- if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
- if (!strcmp(PVD->getName(), "self")) {
- // is this id<P1..> type?
- if (CE->getType()->isObjCQualifiedIdType())
- return 0;
- if (const PointerType *PT = CE->getType()->getAsPointerType()) {
- if (ObjCInterfaceType *IT =
- dyn_cast<ObjCInterfaceType>(PT->getPointeeType())) {
- if (IT->getDecl() ==
- CurMethodDecl->getClassInterface()->getSuperClass())
- return IT->getDecl();
- }
- }
- }
- }
- }
- }
- }
- return 0;
+ if (!CurMethodDecl || !CurMethodDecl->isInstance()) return 0;
+
+ CastExpr *CE = dyn_cast<CastExpr>(recExpr);
+ if (!CE) return 0;
+
+ DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr());
+ if (!DRE) return 0;
+
+ ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl());
+ if (!PVD) return 0;
+
+ if (strcmp(PVD->getName(), "self") != 0)
+ return 0;
+
+ // is this id<P1..> type?
+ if (CE->getType()->isObjCQualifiedIdType())
+ return 0;
+ const PointerType *PT = CE->getType()->getAsPointerType();
+ if (!PT) return 0;
+
+ ObjCInterfaceType *IT = dyn_cast<ObjCInterfaceType>(PT->getPointeeType());
+ if (!IT) return 0;
+
+ if (IT->getDecl() != CurMethodDecl->getClassInterface()->getSuperClass())
+ return 0;
+
+ return IT->getDecl();
}
// struct objc_super { struct objc_object *receiver; struct objc_class *super; };
QualType RewriteTest::getSuperStructType() {
if (!SuperStructDecl) {
- SuperStructDecl = new RecordDecl(Decl::Struct, SourceLocation(),
- &Context->Idents.get("objc_super"), 0);
+ SuperStructDecl = RecordDecl::Create(Decl::Struct, SourceLocation(),
+ &Context->Idents.get("objc_super"), 0,
+ *Context);
QualType FieldTypes[2];
// struct objc_object *receiver;
QualType RewriteTest::getConstantStringStructType() {
if (!ConstantStringDecl) {
- ConstantStringDecl = new RecordDecl(Decl::Struct, SourceLocation(),
- &Context->Idents.get("__NSConstantStringImpl"), 0);
+ ConstantStringDecl = RecordDecl::Create(Decl::Struct, SourceLocation(),
+ &Context->Idents.get("__NSConstantStringImpl"), 0,
+ *Context);
QualType FieldTypes[4];
// struct objc_object *receiver;
TUScope->AddDecl(IDecl);
// Synthesize "typedef struct objc_selector *SEL;"
- RecordDecl *SelTag = new RecordDecl(Decl::Struct, SourceLocation(),
- &Context.Idents.get("objc_selector"), 0);
+ RecordDecl *SelTag = RecordDecl::Create(Decl::Struct, SourceLocation(),
+ &Context.Idents.get("objc_selector"),
+ 0, Context);
SelTag->getIdentifier()->setFETokenInfo(SelTag);
TUScope->AddDecl(SelTag);
QualType SelT = Context.getPointerType(Context.getTagDeclType(SelTag));
- TypedefDecl *SelTypedef = new TypedefDecl(SourceLocation(),
- &Context.Idents.get("SEL"),
- SelT, 0);
+ TypedefDecl *SelTypedef = TypedefDecl::Create(SourceLocation(),
+ &Context.Idents.get("SEL"),
+ SelT, 0, Context);
SelTypedef->getIdentifier()->setFETokenInfo(SelTypedef);
TUScope->AddDecl(SelTypedef);
Context.setObjCSelType(SelTypedef);
// and make sure the decls get inserted into TUScope!
if (PP.getLangOptions().ObjC1) {
// Synthesize "typedef struct objc_class *Class;"
- RecordDecl *ClassTag = new RecordDecl(Decl::Struct, SourceLocation(),
- &IT.get("objc_class"), 0);
+ RecordDecl *ClassTag = RecordDecl::Create(Decl::Struct, SourceLocation(),
+ &IT.get("objc_class"), 0,Context);
QualType ClassT = Context.getPointerType(Context.getTagDeclType(ClassTag));
- TypedefDecl *ClassTypedef = new TypedefDecl(SourceLocation(),
- &Context.Idents.get("Class"),
- ClassT, 0);
+ TypedefDecl *ClassTypedef =
+ TypedefDecl::Create(SourceLocation(), &Context.Idents.get("Class"),
+ ClassT, 0, Context);
Context.setObjCClassType(ClassTypedef);
// Synthesize "@class Protocol;
Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl));
// Synthesize "typedef struct objc_object { Class isa; } *id;"
- RecordDecl *ObjectTag = new RecordDecl(Decl::Struct, SourceLocation(),
- &IT.get("objc_object"), 0);
+ RecordDecl *ObjectTag =
+ RecordDecl::Create(Decl::Struct, SourceLocation(), &IT.get("objc_object"),
+ 0, Context);
FieldDecl *IsaDecl = new FieldDecl(SourceLocation(), 0,
Context.getObjCClassType());
ObjectTag->defineBody(&IsaDecl, 1);
QualType ObjT = Context.getPointerType(Context.getTagDeclType(ObjectTag));
- TypedefDecl *IdTypedef = new TypedefDecl(SourceLocation(),
- &Context.Idents.get("id"),
- ObjT, 0);
+ TypedefDecl *IdTypedef = TypedefDecl::Create(SourceLocation(),
+ &Context.Idents.get("id"),
+ ObjT, 0, Context);
Context.setObjCIdType(IdTypedef);
}
TUScope = 0;
assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
// Scope manipulation handled by caller.
- TypedefDecl *NewTD = new TypedefDecl(D.getIdentifierLoc(), D.getIdentifier(),
- T, LastDeclarator);
+ TypedefDecl *NewTD = TypedefDecl::Create(D.getIdentifierLoc(),
+ D.getIdentifier(),
+ T, LastDeclarator, Context);
if (D.getInvalidType())
NewTD->setInvalidDecl();
return NewTD;
case Decl::Enum:
// FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
// enum X { A, B, C } D; D should chain to X.
- New = new EnumDecl(Loc, Name, 0);
+ New = EnumDecl::Create(Loc, Name, 0, Context);
// If this is an undefined enum, warn.
if (TK != TK_Definition) Diag(Loc, diag::ext_forward_ref_enum);
break;
case Decl::Class:
// FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
// struct X { int A; } D; D should chain to X.
- New = new RecordDecl(Kind, Loc, Name, 0);
+ New = RecordDecl::Create(Kind, Loc, Name, 0, Context);
break;
}
}
}
- EnumConstantDecl *New = new EnumConstantDecl(IdLoc, Id, EltTy, Val, EnumVal,
- LastEnumConst);
+ EnumConstantDecl *New =
+ EnumConstantDecl::Create(IdLoc, Id, EltTy, Val, EnumVal, LastEnumConst,
+ Context);
// Register this decl in the current scope stack.
New->setNext(Id->getFETokenInfo<ScopedDecl>());
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/Bitcode/SerializationFwd.h"
+#include "llvm/Support/Allocator.h"
#include <vector>
namespace clang {
RecordDecl *CFConstantStringTypeDecl;
SourceManager &SourceMgr;
+ llvm::MallocAllocator Allocator;
public:
TargetInfo &Target;
IdentifierTable &Idents;
SelectorTable &Selectors;
SourceManager& getSourceManager() { return SourceMgr; }
-
+ llvm::MallocAllocator &getAllocator() { return Allocator; }
+
FullSourceLoc getFullLoc(SourceLocation Loc) const {
return FullSourceLoc(Loc,SourceMgr);
}
}
}
// global temp stats (until we have a per-module visitor)
- static void addDeclKind(const Kind k);
- static bool CollectingStats(bool enable=false);
+ static void addDeclKind(Kind k);
+ static bool CollectingStats(bool Enable = false);
static void PrintStats();
// Implement isa/cast/dyncast/etc.
class EnumConstantDecl : public ValueDecl {
Expr *Init; // an integer constant expression
llvm::APSInt Val; // The value.
-public:
+protected:
EnumConstantDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E,
const llvm::APSInt &V, ScopedDecl *PrevDecl)
: ValueDecl(EnumConstant, L, Id, T, PrevDecl), Init(E), Val(V) {}
+ ~EnumConstantDecl() {}
+public:
+ static EnumConstantDecl *Create(SourceLocation L, IdentifierInfo *Id,
+ QualType T, Expr *E, const llvm::APSInt &V,
+ ScopedDecl *PrevDecl, ASTContext &C);
+
const Expr *getInitExpr() const { return Init; }
Expr *getInitExpr() { return Init; }
const llvm::APSInt &getInitVal() const { return Val; }
class TypedefDecl : public TypeDecl {
/// UnderlyingType - This is the type the typedef is set to.
QualType UnderlyingType;
-public:
TypedefDecl(SourceLocation L, IdentifierInfo *Id, QualType T, ScopedDecl *PD)
: TypeDecl(Typedef, L, Id, PD), UnderlyingType(T) {}
+ ~TypedefDecl() {}
+public:
+
+ static TypedefDecl *Create(SourceLocation L, IdentifierInfo *Id, QualType T,
+ ScopedDecl *PD, ASTContext &C);
QualType getUnderlyingType() const { return UnderlyingType; }
void setUnderlyingType(QualType newType) { UnderlyingType = newType; }
/// to for code generation purposes. Note that the enumerator constants may
/// have a different type than this does.
QualType IntegerType;
-public:
+
EnumDecl(SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
: TagDecl(Enum, L, Id, PrevDecl) {
- ElementList = 0;
- IntegerType = QualType();
- }
+ ElementList = 0;
+ IntegerType = QualType();
+ }
+ ~EnumDecl() {}
+public:
+ static EnumDecl *Create(SourceLocation L, IdentifierInfo *Id,
+ ScopedDecl *PrevDecl, ASTContext &C);
/// defineElements - When created, EnumDecl correspond to a forward declared
/// enum. This method is used to mark the decl as being defined, with the
/// Members/NumMembers - This is a new[]'d array of pointers to Decls.
FieldDecl **Members; // Null if not defined.
int NumMembers; // -1 if not defined.
-public:
- RecordDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl*PrevDecl)
- : TagDecl(DK, L, Id, PrevDecl) {
+
+ RecordDecl(Kind DK, SourceLocation L, IdentifierInfo *Id,
+ ScopedDecl *PrevDecl) : TagDecl(DK, L, Id, PrevDecl) {
HasFlexibleArrayMember = false;
assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
Members = 0;
NumMembers = -1;
}
+ ~RecordDecl() {}
+public:
+
+ static RecordDecl *Create(Kind DK, SourceLocation L, IdentifierInfo *Id,
+ ScopedDecl *PrevDecl, ASTContext &C);
+
bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; }