Move Decl::NextDeclarator (w/ setters/getters) down to ScopedDecl/FieldDecl.

Decl is now svelte:-)

llvm-svn: 41935
This commit is contained in:
Steve Naroff 2007-09-13 23:52:58 +00:00
parent 9def2b15c1
commit a23cc79654
9 changed files with 68 additions and 55 deletions

View File

@ -225,7 +225,7 @@ void StmtDumper::DumpDeclarator(Decl *D) {
void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
DumpStmt(Node);
fprintf(F, "\n");
for (Decl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
for (ScopedDecl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
++IndentLevel;
Indent();
fprintf(F, "%p ", (void*)D);

View File

@ -144,7 +144,7 @@ void StmtPrinter::VisitNullStmt(NullStmt *Node) {
}
void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
for (Decl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
for (ScopedDecl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
Indent();
PrintRawDecl(D);
OS << ";\n";

View File

@ -41,8 +41,8 @@ public:
void VisitStmt(Stmt* S);
void VisitDeclRefExpr(DeclRefExpr* DR);
void VisitDeclStmt(DeclStmt* DS);
void Register(Decl* D);
void RegisterDeclChain(Decl* D);
void Register(ScopedDecl* D);
void RegisterDeclChain(ScopedDecl* D);
void RegisterUsedDecls();
};
@ -59,12 +59,12 @@ void RegisterDecls::VisitDeclStmt(DeclStmt* DS) {
RegisterDeclChain(DS->getDecl());
}
void RegisterDecls::RegisterDeclChain(Decl* D) {
void RegisterDecls::RegisterDeclChain(ScopedDecl* D) {
for (; D != NULL ; D = D->getNextDeclarator())
Register(D);
}
void RegisterDecls::Register(Decl* D) {
void RegisterDecls::Register(ScopedDecl* D) {
if (VarDecl* V = dyn_cast<VarDecl>(D)) {
LiveVariables::VPair& VP = L.getVarInfoMap()[V];
@ -240,7 +240,7 @@ void LivenessTFuncs::VisitDeclStmt(DeclStmt* DS) {
// be live before they are declared. Declarations, however, are not kills
// in the sense that the value is obliterated, so we do not register
// DeclStmts as a "kill site" for a variable.
for (Decl* D = DS->getDecl(); D != NULL ; D = D->getNextDeclarator())
for (ScopedDecl* D = DS->getDecl(); D != NULL ; D = D->getNextDeclarator())
KillVar(cast<VarDecl>(D));
}

View File

@ -318,7 +318,8 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
}
void CodeGenFunction::EmitDeclStmt(const DeclStmt &S) {
for (const Decl *Decl = S.getDecl(); Decl; Decl = Decl->getNextDeclarator())
for (const ScopedDecl *Decl = S.getDecl(); Decl;
Decl = Decl->getNextDeclarator())
EmitDecl(*Decl);
}

View File

@ -165,7 +165,7 @@ private:
DeclTy **Elements, unsigned NumElements);
private:
/// Subroutines of ParseDeclarator()...
TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, Decl *LastDeclarator);
TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, ScopedDecl *LastDecl);
TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *Old);
FunctionDecl *MergeFunctionDecl(FunctionDecl *New, ScopedDecl *Old);
VarDecl *MergeVarDecl(VarDecl *New, ScopedDecl *Old);

View File

@ -430,8 +430,8 @@ bool Sema::CheckInitializer(Expr *&Init, QualType &DeclType, bool isStatic) {
}
Sema::DeclTy *
Sema::ParseDeclarator(Scope *S, Declarator &D, DeclTy *lastDeclarator) {
Decl *LastDeclarator = (Decl*)lastDeclarator;
Sema::ParseDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
ScopedDecl *LastDeclarator = dyn_cast_or_null<ScopedDecl>((Decl *)lastDecl);
IdentifierInfo *II = D.getIdentifier();
// All of these full declarators require an identifier. If it doesn't have
@ -608,16 +608,17 @@ void Sema::AddInitializerToDecl(DeclTy *dcl, ExprTy *init) {
/// The declarators are chained together backwards, reverse the list.
Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
// Often we have single declarators, handle them quickly.
Decl *Group = static_cast<Decl*>(group);
if (Group == 0)
Decl *GroupDecl = static_cast<Decl*>(group);
if (GroupDecl == 0)
return 0;
Decl *NewGroup = 0;
ScopedDecl *Group = dyn_cast<ScopedDecl>(GroupDecl);
ScopedDecl *NewGroup = 0;
if (Group->getNextDeclarator() == 0)
NewGroup = Group;
else { // reverse the list.
while (Group) {
Decl *Next = Group->getNextDeclarator();
ScopedDecl *Next = Group->getNextDeclarator();
Group->setNextDeclarator(NewGroup);
NewGroup = Group;
Group = Next;
@ -625,7 +626,7 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
}
// Perform semantic analysis that depends on having fully processed both
// the declarator and initializer.
for (Decl *ID = NewGroup; ID; ID = ID->getNextDeclarator()) {
for (ScopedDecl *ID = NewGroup; ID; ID = ID->getNextDeclarator()) {
VarDecl *IDecl = dyn_cast<VarDecl>(ID);
if (!IDecl)
continue;
@ -846,7 +847,7 @@ Decl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D,
Decl *LastDeclarator) {
ScopedDecl *LastDeclarator) {
assert(D.getIdentifier() && "Wrong callback for declspec without declarator");
QualType T = GetTypeForDeclarator(D, S);

View File

@ -481,7 +481,7 @@ Sema::ParseForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
// C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
// identifiers for objects having storage class 'auto' or 'register'.
for (Decl *D = DS->getDecl(); D; D = D->getNextDeclarator()) {
for (ScopedDecl *D = DS->getDecl(); D; D = D->getNextDeclarator()) {
BlockVarDecl *BVD = dyn_cast<BlockVarDecl>(D);
if (BVD && !BVD->hasLocalStorage())
BVD = 0;

View File

@ -675,7 +675,6 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";

View File

@ -56,13 +56,8 @@ private:
/// InvalidDecl - This indicates a semantic error occurred.
int InvalidDecl : 1;
/// NextDeclarator - If this decl was part of a multi-declarator declaration,
/// such as "int X, Y, *Z;" this indicates Decl for the next declarator.
Decl *NextDeclarator;
protected:
Decl(Kind DK, Decl *NextDecl)
: DeclKind(DK), InvalidDecl(0), NextDeclarator(NextDecl) {
Decl(Kind DK) : DeclKind(DK), InvalidDecl(0) {
if (Decl::CollectingStats()) addDeclKind(DK);
}
virtual ~Decl();
@ -76,13 +71,6 @@ public:
void setInvalidDecl() { InvalidDecl = 1; }
int isInvalidDecl() const { return InvalidDecl; }
/// getNextDeclarator - If this decl was part of a multi-declarator
/// declaration, such as "int X, Y, *Z;" this returns the decl for the next
/// declarator. Otherwise it returns null.
Decl *getNextDeclarator() { return NextDeclarator; }
const Decl *getNextDeclarator() const { return NextDeclarator; }
void setNextDeclarator(Decl *N) { NextDeclarator = N; }
IdentifierNamespace getIdentifierNamespace() const {
switch (DeclKind) {
default: assert(0 && "Unknown decl kind!");
@ -119,14 +107,18 @@ class ScopedDecl : public Decl {
/// Loc - The location that this decl.
SourceLocation Loc;
/// NextDeclarator - If this decl was part of a multi-declarator declaration,
/// such as "int X, Y, *Z;" this indicates Decl for the next declarator.
ScopedDecl *NextDeclarator;
/// When this decl is in scope while parsing, the Next field contains a
/// pointer to the shadowed decl of the same name. When the scope is popped,
/// Decls are relinked onto a containing decl object.
///
ScopedDecl *Next;
protected:
ScopedDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, Decl *PrevDecl)
: Decl(DK, PrevDecl), Identifier(Id), Loc(L), Next(0) {}
ScopedDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
: Decl(DK), Identifier(Id), Loc(L), NextDeclarator(PrevDecl), Next(0) {}
public:
IdentifierInfo *getIdentifier() const { return Identifier; }
SourceLocation getLocation() const { return Loc; }
@ -136,6 +128,13 @@ public:
ScopedDecl *getNext() const { return Next; }
void setNext(ScopedDecl *N) { Next = N; }
/// getNextDeclarator - If this decl was part of a multi-declarator
/// declaration, such as "int X, Y, *Z;" this returns the decl for the next
/// declarator. Otherwise it returns null.
ScopedDecl *getNextDeclarator() { return NextDeclarator; }
const ScopedDecl *getNextDeclarator() const { return NextDeclarator; }
void setNextDeclarator(ScopedDecl *N) { NextDeclarator = N; }
// Implement isa/cast/dyncast/etc. - true for all ValueDecl's and TypeDecl's.
static bool classof(const Decl *D) {
return (D->getKind() >= Function && D->getKind() <= EnumConstant) ||
@ -151,7 +150,7 @@ class ValueDecl : public ScopedDecl {
QualType DeclType;
protected:
ValueDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
Decl *PrevDecl) : ScopedDecl(DK, L, Id, PrevDecl), DeclType(T) {}
ScopedDecl *PrevDecl) : ScopedDecl(DK, L, Id, PrevDecl), DeclType(T) {}
public:
QualType getType() const { return DeclType; }
void setType(QualType newType) { DeclType = newType; }
@ -211,7 +210,7 @@ public:
static bool classof(const VarDecl *D) { return true; }
protected:
VarDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
StorageClass SC, Decl *PrevDecl)
StorageClass SC, ScopedDecl *PrevDecl)
: ValueDecl(DK, L, Id, T, PrevDecl), Init(0) { SClass = SC; }
private:
StorageClass SClass;
@ -222,7 +221,7 @@ private:
class BlockVarDecl : public VarDecl {
public:
BlockVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
Decl *PrevDecl)
ScopedDecl *PrevDecl)
: VarDecl(BlockVariable, L, Id, T, S, PrevDecl) {}
// Implement isa/cast/dyncast/etc.
@ -237,7 +236,7 @@ public:
class FileVarDecl : public VarDecl {
public:
FileVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
Decl *PrevDecl)
ScopedDecl *PrevDecl)
: VarDecl(FileVariable, L, Id, T, S, PrevDecl) {}
// Implement isa/cast/dyncast/etc.
@ -249,7 +248,7 @@ public:
class ParmVarDecl : public VarDecl {
public:
ParmVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
Decl *PrevDecl)
ScopedDecl *PrevDecl)
: VarDecl(ParmVariable, L, Id, T, S, PrevDecl) {}
// Implement isa/cast/dyncast/etc.
@ -265,7 +264,8 @@ public:
None, Extern, Static
};
FunctionDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
StorageClass S = None, bool isInline = false, Decl *PrevDecl = 0)
StorageClass S = None, bool isInline = false,
ScopedDecl *PrevDecl = 0)
: ValueDecl(Function, L, Id, T, PrevDecl),
ParamInfo(0), Body(0), DeclChain(0), SClass(S), IsInline(isInline) {}
virtual ~FunctionDecl();
@ -324,19 +324,31 @@ class FieldDecl : public Decl {
/// Loc - The location that this decl.
SourceLocation Loc;
/// NextDeclarator - If this decl was part of a multi-declarator declaration,
/// such as "int X, Y, *Z;" this indicates Decl for the next declarator.
FieldDecl *NextDeclarator;
QualType DeclType;
public:
FieldDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Decl *PrevDecl)
: Decl(Field, PrevDecl), Identifier(Id), Loc(L), DeclType(T) {}
FieldDecl(SourceLocation L, IdentifierInfo *Id, QualType T, FieldDecl *PrevD)
: Decl(Field), Identifier(Id), Loc(L), NextDeclarator(PrevD),
DeclType(T) {}
FieldDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
Decl *PrevDecl) : Decl(DK, PrevDecl), Identifier(Id), Loc(L),
DeclType(T) {}
FieldDecl *PrevD) : Decl(DK), Identifier(Id), Loc(L),
NextDeclarator(PrevD), DeclType(T) {}
IdentifierInfo *getIdentifier() const { return Identifier; }
SourceLocation getLocation() const { return Loc; }
void setLocation(SourceLocation L) { Loc = L; }
const char *getName() const;
/// getNextDeclarator - If this decl was part of a multi-declarator
/// declaration, such as "int X, Y, *Z;" this returns the decl for the next
/// declarator. Otherwise it returns null.
FieldDecl *getNextDeclarator() { return NextDeclarator; }
const FieldDecl *getNextDeclarator() const { return NextDeclarator; }
void setNextDeclarator(FieldDecl *N) { NextDeclarator = N; }
QualType getType() const { return DeclType; }
QualType getCanonicalType() const { return DeclType.getCanonicalType(); }
@ -356,7 +368,7 @@ class EnumConstantDecl : public ValueDecl {
llvm::APSInt Val; // The value.
public:
EnumConstantDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E,
const llvm::APSInt &V, Decl *PrevDecl)
const llvm::APSInt &V, ScopedDecl *PrevDecl)
: ValueDecl(EnumConstant, L, Id, T, PrevDecl), Init(E), Val(V) {}
const Expr *getInitExpr() const { return Init; }
@ -383,7 +395,7 @@ class TypeDecl : public ScopedDecl {
Type *TypeForDecl;
friend class ASTContext;
protected:
TypeDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, Decl *PrevDecl)
TypeDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
: ScopedDecl(DK, L, Id, PrevDecl), TypeForDecl(0) {}
public:
// Implement isa/cast/dyncast/etc.
@ -398,8 +410,8 @@ class TypedefDecl : public TypeDecl {
/// UnderlyingType - This is the type the typedef is set to.
QualType UnderlyingType;
public:
TypedefDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Decl *PrevDecl)
: TypeDecl(Typedef, L, Id, PrevDecl), UnderlyingType(T) {}
TypedefDecl(SourceLocation L, IdentifierInfo *Id, QualType T, ScopedDecl *PD)
: TypeDecl(Typedef, L, Id, PD), UnderlyingType(T) {}
QualType getUnderlyingType() const { return UnderlyingType; }
void setUnderlyingType(QualType newType) { UnderlyingType = newType; }
@ -416,7 +428,7 @@ class TagDecl : public TypeDecl {
/// it is a declaration ("struct foo;").
bool IsDefinition : 1;
protected:
TagDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, Decl *PrevDecl)
TagDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
: TypeDecl(DK, L, Id, PrevDecl) {
IsDefinition = false;
}
@ -459,7 +471,7 @@ class EnumDecl : public TagDecl {
/// have a different type than this does.
QualType IntegerType;
public:
EnumDecl(SourceLocation L, IdentifierInfo *Id, Decl *PrevDecl)
EnumDecl(SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
: TagDecl(Enum, L, Id, PrevDecl) {
ElementList = 0;
}
@ -502,7 +514,7 @@ class RecordDecl : public TagDecl {
FieldDecl **Members; // Null if not defined.
int NumMembers; // -1 if not defined.
public:
RecordDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, Decl *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!");
@ -568,8 +580,8 @@ public:
class ObjcIvarDecl : public FieldDecl {
public:
ObjcIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Decl *PrevDecl)
: FieldDecl(ObjcIvar, L, Id, T, PrevDecl) {}
ObjcIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
FieldDecl *PrevDecl) : FieldDecl(ObjcIvar, L, Id, T, PrevDecl) {}
enum AccessControl {
None, Private, Protected, Public, Package
@ -614,7 +626,7 @@ public:
ParmVarDecl **paramInfo = 0, int numParams=-1,
AttributeList *M = 0, bool isInstance = true,
Decl *PrevDecl = 0)
: Decl(ObjcMethod, PrevDecl), MethodDeclType(T),
: Decl(ObjcMethod), MethodDeclType(T),
ParamInfo(paramInfo), NumMethodParams(numParams),
MethodAttrs(M), IsInstance(isInstance) {}