[cfe-commits] r48396 - in /cfe/trunk: AST/Decl.cpp Driver/RewriteTest.cpp Sema/SemaDecl.cpp Sema/SemaDeclObjC.cpp include/clang/AST/Decl.h
Chris Lattner
sabre at nondot.org
Sat Mar 15 14:10:17 PDT 2008
Author: lattner
Date: Sat Mar 15 16:10:16 2008
New Revision: 48396
URL: http://llvm.org/viewvc/llvm-project?rev=48396&view=rev
Log:
switch the VarDecl allocation model to go through ASTContext.
Modified:
cfe/trunk/AST/Decl.cpp
cfe/trunk/Driver/RewriteTest.cpp
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/Sema/SemaDeclObjC.cpp
cfe/trunk/include/clang/AST/Decl.h
Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=48396&r1=48395&r2=48396&view=diff
==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Sat Mar 15 16:10:16 2008
@@ -205,6 +205,28 @@
// 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,
Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=48396&r1=48395&r2=48396&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Sat Mar 15 16:10:16 2008
@@ -1744,9 +1744,9 @@
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()),
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=48396&r1=48395&r2=48396&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Sat Mar 15 16:10:16 2008
@@ -777,13 +777,13 @@
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 @@
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 @@
} 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();
Modified: cfe/trunk/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDeclObjC.cpp?rev=48396&r1=48395&r2=48396&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/Sema/SemaDeclObjC.cpp Sat Mar 15 16:10:16 2008
@@ -823,8 +823,9 @@
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);
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=48396&r1=48395&r2=48396&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sat Mar 15 16:10:16 2008
@@ -294,6 +294,17 @@
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 @@
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 @@
/// 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 @@
/// 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 @@
/// 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 @@
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;
More information about the cfe-commits
mailing list