forked from OSchip/llvm-project
switch the VarDecl allocation model to go through ASTContext.
llvm-svn: 48396
This commit is contained in:
parent
2c7f144ab7
commit
4b08ca8f2e
|
@ -205,6 +205,28 @@ void Decl::addDeclKind(Kind k) {
|
|||
// 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,
|
||||
|
|
|
@ -1744,9 +1744,9 @@ Stmt *RewriteTest::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) {
|
|||
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()),
|
||||
|
|
|
@ -777,13 +777,13 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
|
|||
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
|
||||
|
@ -793,9 +793,11 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
|
|||
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(),
|
||||
|
@ -1014,8 +1016,8 @@ Sema::ActOnParamDeclarator(struct DeclaratorChunk::ParamInfo &PI,
|
|||
} 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();
|
||||
|
|
|
@ -823,8 +823,9 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration(
|
|||
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);
|
||||
|
|
|
@ -294,6 +294,17 @@ public:
|
|||
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; }
|
||||
|
@ -322,17 +333,7 @@ public:
|
|||
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);
|
||||
|
@ -349,11 +350,13 @@ protected:
|
|||
|
||||
/// 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; }
|
||||
|
@ -370,10 +373,13 @@ protected:
|
|||
/// 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; }
|
||||
|
@ -388,11 +394,19 @@ protected:
|
|||
|
||||
/// 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);
|
||||
|
@ -404,12 +418,6 @@ public:
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue