// Decl Allocation/Deallocation Method Implementations
//===----------------------------------------------------------------------===//
+BlockVarDecl *BlockVarDecl::Create(SourceLocation L, IdentifierInfo *Id,
+ QualType T, StorageClass S,
+ ScopedDecl *PrevDecl, ASTContext &C) {
+ void *Mem = C.getAllocator().Allocate<BlockVarDecl>();
+ return new (Mem) BlockVarDecl(L, Id, T, S, PrevDecl);
+}
+
+
+FileVarDecl *FileVarDecl::Create(SourceLocation L, IdentifierInfo *Id,
+ QualType T, StorageClass S,
+ ScopedDecl *PrevDecl, ASTContext &C) {
+ void *Mem = C.getAllocator().Allocate<FileVarDecl>();
+ return new (Mem) FileVarDecl(L, Id, T, S, PrevDecl);
+}
+
+ParmVarDecl *ParmVarDecl::Create(SourceLocation L, IdentifierInfo *Id,
+ QualType T, StorageClass S,
+ ScopedDecl *PrevDecl, ASTContext &C) {
+ void *Mem = C.getAllocator().Allocate<ParmVarDecl>();
+ return new (Mem) ParmVarDecl(L, Id, T, S, PrevDecl);
+}
+
EnumConstantDecl *EnumConstantDecl::Create(SourceLocation L, IdentifierInfo *Id,
QualType T, Expr *E,
const llvm::APSInt &V,
InsertText(SourceLocation::getFileLoc(MainFileID, 0),
StrObjDecl.c_str(), StrObjDecl.size());
- FileVarDecl *NewVD = new FileVarDecl(SourceLocation(),
+ FileVarDecl *NewVD = FileVarDecl::Create(SourceLocation(),
&Context->Idents.get(S.c_str()), strType,
- VarDecl::Static, NULL);
+ VarDecl::Static, NULL, *Context);
DeclRefExpr *DRE = new DeclRefExpr(NewVD, strType, SourceLocation());
Expr *Unop = new UnaryOperator(DRE, UnaryOperator::AddrOf,
Context->getPointerType(DRE->getType()),
VarDecl *NewVD;
VarDecl::StorageClass SC;
switch (D.getDeclSpec().getStorageClassSpec()) {
- default: assert(0 && "Unknown storage class!");
- case DeclSpec::SCS_unspecified: SC = VarDecl::None; break;
- case DeclSpec::SCS_extern: SC = VarDecl::Extern; break;
- case DeclSpec::SCS_static: SC = VarDecl::Static; break;
- case DeclSpec::SCS_auto: SC = VarDecl::Auto; break;
- case DeclSpec::SCS_register: SC = VarDecl::Register; break;
- case DeclSpec::SCS_private_extern: SC = VarDecl::PrivateExtern; break;
+ default: assert(0 && "Unknown storage class!");
+ case DeclSpec::SCS_unspecified: SC = VarDecl::None; break;
+ case DeclSpec::SCS_extern: SC = VarDecl::Extern; break;
+ case DeclSpec::SCS_static: SC = VarDecl::Static; break;
+ case DeclSpec::SCS_auto: SC = VarDecl::Auto; break;
+ case DeclSpec::SCS_register: SC = VarDecl::Register; break;
+ case DeclSpec::SCS_private_extern: SC = VarDecl::PrivateExtern; break;
}
if (S->getParent() == 0) {
// C99 6.9p2: The storage-class specifiers auto and register shall not
R.getAsString());
InvalidDecl = true;
}
- NewVD = new FileVarDecl(D.getIdentifierLoc(), II, R, SC, LastDeclarator);
+ NewVD = FileVarDecl::Create(D.getIdentifierLoc(), II, R, SC,
+ LastDeclarator, Context);
} else {
- NewVD = new BlockVarDecl(D.getIdentifierLoc(), II, R, SC, LastDeclarator);
+ NewVD = BlockVarDecl::Create(D.getIdentifierLoc(), II, R, SC,
+ LastDeclarator, Context);
}
// Handle attributes prior to checking for duplicates in MergeVarDecl
HandleDeclAttributes(NewVD, D.getDeclSpec().getAttributes(),
} else if (parmDeclType->isFunctionType())
parmDeclType = Context.getPointerType(parmDeclType);
- ParmVarDecl *New = new ParmVarDecl(PI.IdentLoc, II, parmDeclType,
- VarDecl::None, 0);
+ ParmVarDecl *New = ParmVarDecl::Create(PI.IdentLoc, II, parmDeclType,
+ VarDecl::None, 0, Context);
if (PI.InvalidType)
New->setInvalidDecl();
argType = QualType::getFromOpaquePtr(ArgTypes[i]);
else
argType = Context.getObjCIdType();
- ParmVarDecl* Param = new ParmVarDecl(SourceLocation(/*FIXME*/), ArgNames[i],
- argType, VarDecl::None, 0);
+ ParmVarDecl* Param = ParmVarDecl::Create(SourceLocation(/*FIXME*/),
+ ArgNames[i], argType,
+ VarDecl::None, 0, Context);
Param->setObjCDeclQualifier(
CvtQTToAstBitMask(ArgQT[i].getObjCDeclQualifier()));
Params.push_back(Param);
enum StorageClass {
None, Auto, Register, Extern, Static, PrivateExtern
};
+private:
+ Expr *Init;
+ // FIXME: This can be packed into the bitfields in Decl.
+ unsigned SClass : 3;
+
+ friend class StmtIteratorBase;
+protected:
+ VarDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
+ StorageClass SC, ScopedDecl *PrevDecl)
+ : ValueDecl(DK, L, Id, T, PrevDecl), Init(0) { SClass = SC; }
+public:
StorageClass getStorageClass() const { return (StorageClass)SClass; }
const Expr *getInit() const { return Init; }
return D->getKind() >= VarFirst && D->getKind() <= VarLast;
}
static bool classof(const VarDecl *D) { return true; }
-protected:
- VarDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
- StorageClass SC, ScopedDecl *PrevDecl)
- : ValueDecl(DK, L, Id, T, PrevDecl), Init(0) { SClass = SC; }
-private:
- Expr *Init;
- // FIXME: This can be packed into the bitfields in Decl.
- unsigned SClass : 3;
-
- friend class StmtIteratorBase;
-
+
protected:
void EmitInRec(llvm::Serializer& S) const;
void ReadInRec(llvm::Deserializer& D);
/// BlockVarDecl - Represent a local variable declaration.
class BlockVarDecl : public VarDecl {
-public:
BlockVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
ScopedDecl *PrevDecl)
: VarDecl(BlockVar, L, Id, T, S, PrevDecl) {}
-
+public:
+ static BlockVarDecl *Create(SourceLocation L, IdentifierInfo *Id, QualType T,
+ StorageClass S, ScopedDecl *PrevDecl,
+ ASTContext &C);
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == BlockVar; }
static bool classof(const BlockVarDecl *D) { return true; }
/// definitions (C99 6.9.2p2) using our type system (without storing a
/// pointer to the decl's scope, which is transient).
class FileVarDecl : public VarDecl {
-public:
FileVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
ScopedDecl *PrevDecl)
: VarDecl(FileVar, L, Id, T, S, PrevDecl) {}
+public:
+ static FileVarDecl *Create(SourceLocation L, IdentifierInfo *Id, QualType T,
+ StorageClass S, ScopedDecl *PrevDecl,
+ ASTContext &C);
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == FileVar; }
/// ParmVarDecl - Represent a parameter to a function.
class ParmVarDecl : public VarDecl {
-public:
+ // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
+ /// FIXME: Also can be paced into the bitfields in Decl.
+ /// in, inout, etc.
+ unsigned objcDeclQualifier : 6;
+
ParmVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
ScopedDecl *PrevDecl)
: VarDecl(ParmVar, L, Id, T, S, PrevDecl),
objcDeclQualifier(OBJC_TQ_None) {}
+public:
+ static ParmVarDecl *Create(SourceLocation L, IdentifierInfo *Id, QualType T,
+ StorageClass S, ScopedDecl *PrevDecl,
+ ASTContext &C);
ObjCDeclQualifier getObjCDeclQualifier() const {
return ObjCDeclQualifier(objcDeclQualifier);
static bool classof(const Decl *D) { return D->getKind() == ParmVar; }
static bool classof(const ParmVarDecl *D) { return true; }
-private:
- // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
- /// FIXME: Also can be paced into the bitfields in Decl.
- /// in, inout, etc.
- unsigned objcDeclQualifier : 6;
-
protected:
/// EmitImpl - Serialize this ParmVarDecl. Called by Decl::Emit.
virtual void EmitImpl(llvm::Serializer& S) const;