[cfe-commits] r41934 - in /cfe/trunk: AST/Decl.cpp CodeGen/CGExpr.cpp CodeGen/CodeGenModule.cpp CodeGen/CodeGenModule.h Driver/ASTStreamers.cpp Sema/Sema.h Sema/SemaDecl.cpp Sema/SemaStmt.cpp include/clang/AST/Decl.h include/clang/AST/Expr.h include/clang/AST/Stmt.h
Steve Naroff
snaroff at apple.com
Thu Sep 13 14:41:19 PDT 2007
Author: snaroff
Date: Thu Sep 13 16:41:19 2007
New Revision: 41934
URL: http://llvm.org/viewvc/llvm-project?rev=41934&view=rev
Log:
Phase 2 of making the Decl class more lightweight...
Move Identifier/Loc instance variables (and associated getters/setters) down from Decl to ScopedDecl/FieldDecl.
Objc AST's can now inherit from Decl without getting instance variables and types that are C specific. For now, I am keeping NextDeclarator, since I believe it may be useful to ObjC. If not, it can be moved later.
Modified:
cfe/trunk/AST/Decl.cpp
cfe/trunk/CodeGen/CGExpr.cpp
cfe/trunk/CodeGen/CodeGenModule.cpp
cfe/trunk/CodeGen/CodeGenModule.h
cfe/trunk/Driver/ASTStreamers.cpp
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/Sema/SemaStmt.cpp
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h
Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=41934&r1=41933&r2=41934&view=diff
==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Thu Sep 13 16:41:19 2007
@@ -112,7 +112,13 @@
Decl::~Decl() {
}
-const char *Decl::getName() const {
+const char *FieldDecl::getName() const {
+ if (const IdentifierInfo *II = getIdentifier())
+ return II->getName();
+ return "";
+}
+
+const char *ScopedDecl::getName() const {
if (const IdentifierInfo *II = getIdentifier())
return II->getName();
return "";
Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=41934&r1=41933&r2=41934&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Thu Sep 13 16:41:19 2007
@@ -261,7 +261,7 @@
LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
- const Decl *D = E->getDecl();
+ const ValueDecl *D = E->getDecl();
if (isa<BlockVarDecl>(D) || isa<ParmVarDecl>(D)) {
llvm::Value *V = LocalDeclMap[D];
assert(V && "BlockVarDecl not entered in LocalDeclMap?");
Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=41934&r1=41933&r2=41934&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Thu Sep 13 16:41:19 2007
@@ -27,7 +27,7 @@
CodeGenModule::CodeGenModule(ASTContext &C, llvm::Module &M)
: Context(C), TheModule(M), Types(C, M), CFConstantStringClassRef(0) {}
-llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const Decl *D) {
+llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const ValueDecl *D) {
// See if it is already in the map.
llvm::Constant *&Entry = GlobalDeclMap[D];
if (Entry) return Entry;
Modified: cfe/trunk/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.h?rev=41934&r1=41933&r2=41934&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/CodeGen/CodeGenModule.h Thu Sep 13 16:41:19 2007
@@ -28,6 +28,7 @@
class ASTContext;
class FunctionDecl;
class Decl;
+ class ValueDecl;
class FileVarDecl;
namespace CodeGen {
@@ -53,7 +54,7 @@
llvm::Module &getModule() const { return TheModule; }
CodeGenTypes &getTypes() { return Types; }
- llvm::Constant *GetAddrOfGlobalDecl(const Decl *D);
+ llvm::Constant *GetAddrOfGlobalDecl(const ValueDecl *D);
/// getBuiltinLibFunction - Given a builtin id for a function like
/// "__builtin_fabsf", return a Function* for "fabsf".
Modified: cfe/trunk/Driver/ASTStreamers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTStreamers.cpp?rev=41934&r1=41933&r2=41934&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTStreamers.cpp (original)
+++ cfe/trunk/Driver/ASTStreamers.cpp Thu Sep 13 16:41:19 2007
@@ -124,8 +124,8 @@
PrintTypeDefDecl(TD);
} else if (ObjcInterfaceDecl *OID = dyn_cast<ObjcInterfaceDecl>(D)) {
PrintObjcInterfaceDecl(OID);
- } else {
- fprintf(stderr, "Read top-level variable decl: '%s'\n", D->getName());
+ } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
+ fprintf(stderr, "Read top-level variable decl: '%s'\n", SD->getName());
}
}
@@ -154,8 +154,8 @@
}
} else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
PrintTypeDefDecl(TD);
- } else {
- fprintf(stderr, "Read top-level variable decl: '%s'\n", D->getName());
+ } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
+ fprintf(stderr, "Read top-level variable decl: '%s'\n", SD->getName());
}
}
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=41934&r1=41933&r2=41934&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Thu Sep 13 16:41:19 2007
@@ -166,9 +166,9 @@
private:
/// Subroutines of ParseDeclarator()...
TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, Decl *LastDeclarator);
- TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
- FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old);
- VarDecl *MergeVarDecl(VarDecl *New, Decl *Old);
+ TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *Old);
+ FunctionDecl *MergeFunctionDecl(FunctionDecl *New, ScopedDecl *Old);
+ VarDecl *MergeVarDecl(VarDecl *New, ScopedDecl *Old);
/// AddTopLevelDecl - called after the decl has been fully processed.
/// Allows for bookkeeping and post-processing of each declaration.
void AddTopLevelDecl(Decl *current, Decl *last);
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=41934&r1=41933&r2=41934&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Thu Sep 13 16:41:19 2007
@@ -147,7 +147,7 @@
/// and scope as a previous declaration 'Old'. Figure out how to resolve this
/// situation, merging decls or emitting diagnostics as appropriate.
///
-TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) {
+TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *OldD) {
// Verify the old decl was also a typedef.
TypedefDecl *Old = dyn_cast<TypedefDecl>(OldD);
if (!Old) {
@@ -169,7 +169,7 @@
/// and scope as a previous declaration 'Old'. Figure out how to resolve this
/// situation, merging decls or emitting diagnostics as appropriate.
///
-FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) {
+FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, ScopedDecl *OldD) {
// Verify the old decl was also a function.
FunctionDecl *Old = dyn_cast<FunctionDecl>(OldD);
if (!Old) {
@@ -202,7 +202,7 @@
/// FIXME: Need to carefully consider tentative definition rules (C99 6.9.2p2).
/// For example, we incorrectly complain about i1, i4 from C99 6.9.2p4.
///
-VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
+VarDecl *Sema::MergeVarDecl(VarDecl *New, ScopedDecl *OldD) {
// Verify the old decl was also a variable.
VarDecl *Old = dyn_cast<VarDecl>(OldD);
if (!Old) {
@@ -571,7 +571,8 @@
VarDecl *VDecl = dyn_cast<VarDecl>(RealDecl);
if (!VDecl) {
- Diag(RealDecl->getLocation(), diag::err_illegal_initializer);
+ Diag(dyn_cast<ScopedDecl>(RealDecl)->getLocation(),
+ diag::err_illegal_initializer);
RealDecl->setInvalidDecl();
return;
}
@@ -1280,7 +1281,8 @@
// Verify that there isn't already something declared with this name in this
// scope.
- if (Decl *PrevDecl = LookupScopedDecl(Id, Decl::IDNS_Ordinary, IdLoc, S)) {
+ if (ScopedDecl *PrevDecl = LookupScopedDecl(Id, Decl::IDNS_Ordinary,
+ IdLoc, S)) {
if (S->isDeclScope(PrevDecl)) {
if (isa<EnumConstantDecl>(PrevDecl))
Diag(IdLoc, diag::err_redefinition_of_enumerator, Id->getName());
Modified: cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaStmt.cpp?rev=41934&r1=41933&r2=41934&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Thu Sep 13 16:41:19 2007
@@ -33,9 +33,11 @@
}
Sema::StmtResult Sema::ParseDeclStmt(DeclTy *decl) {
- if (decl)
- return new DeclStmt(static_cast<Decl *>(decl));
- else
+ if (decl) {
+ ScopedDecl *SD = dyn_cast<ScopedDecl>(static_cast<Decl *>(decl));
+ assert(SD && "Sema::ParseDeclStmt(): expected ScopedDecl");
+ return new DeclStmt(SD);
+ } else
return true; // error
}
@@ -57,7 +59,7 @@
/*empty*/;
if (i != NumElts) {
- Decl *D = cast<DeclStmt>(Elts[i])->getDecl();
+ ScopedDecl *D = cast<DeclStmt>(Elts[i])->getDecl();
Diag(D->getLocation(), diag::ext_mixed_decls_code);
}
}
@@ -484,7 +486,8 @@
if (BVD && !BVD->hasLocalStorage())
BVD = 0;
if (BVD == 0)
- Diag(D->getLocation(), diag::err_non_variable_decl_in_for);
+ Diag(dyn_cast<ScopedDecl>(D)->getLocation(),
+ diag::err_non_variable_decl_in_for);
// FIXME: mark decl erroneous!
}
}
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=41934&r1=41933&r2=41934&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Sep 13 16:41:19 2007
@@ -56,30 +56,18 @@
/// InvalidDecl - This indicates a semantic error occurred.
int InvalidDecl : 1;
- /// Loc - The location that this decl.
- SourceLocation Loc;
-
- /// Identifier - The identifier for this declaration (e.g. the name for the
- /// variable, the tag for a struct).
- IdentifierInfo *Identifier;
-
/// 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, SourceLocation L, IdentifierInfo *Id, Decl *NextDecl)
- : DeclKind(DK), InvalidDecl(0), Loc(L), Identifier(Id),
- NextDeclarator(NextDecl) {
+ Decl(Kind DK, Decl *NextDecl)
+ : DeclKind(DK), InvalidDecl(0), NextDeclarator(NextDecl) {
if (Decl::CollectingStats()) addDeclKind(DK);
}
virtual ~Decl();
public:
- IdentifierInfo *getIdentifier() const { return Identifier; }
- SourceLocation getLocation() const { return Loc; }
- void setLocation(SourceLocation L) { Loc = L; }
- const char *getName() const;
Kind getKind() const { return DeclKind; }
@@ -124,6 +112,13 @@
/// ScopedDecl - Represent lexically scoped names, used for all ValueDecl's
/// and TypeDecl's.
class ScopedDecl : public Decl {
+ /// Identifier - The identifier for this declaration (e.g. the name for the
+ /// variable, the tag for a struct).
+ IdentifierInfo *Identifier;
+
+ /// Loc - The location that this decl.
+ SourceLocation Loc;
+
/// 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.
@@ -131,8 +126,13 @@
ScopedDecl *Next;
protected:
ScopedDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, Decl *PrevDecl)
- : Decl(DK, L, Id, PrevDecl), Next(0) {}
+ : Decl(DK, PrevDecl), Identifier(Id), Loc(L), Next(0) {}
public:
+ IdentifierInfo *getIdentifier() const { return Identifier; }
+ SourceLocation getLocation() const { return Loc; }
+ void setLocation(SourceLocation L) { Loc = L; }
+ const char *getName() const;
+
ScopedDecl *getNext() const { return Next; }
void setNext(ScopedDecl *N) { Next = N; }
@@ -317,12 +317,25 @@
/// FieldDecl - An instance of this class is created by Sema::ParseField to
/// represent a member of a struct/union/class.
class FieldDecl : public Decl {
- QualType DeclType;
+ /// Identifier - The identifier for this declaration (e.g. the name for the
+ /// variable, the tag for a struct).
+ IdentifierInfo *Identifier;
+
+ /// Loc - The location that this decl.
+ SourceLocation Loc;
+
+ QualType DeclType;
public:
FieldDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Decl *PrevDecl)
- : Decl(Field, L, Id, PrevDecl), DeclType(T) {}
+ : Decl(Field, PrevDecl), Identifier(Id), Loc(L), DeclType(T) {}
FieldDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
- Decl *PrevDecl) : Decl(DK, L, Id, PrevDecl), DeclType(T) {}
+ Decl *PrevDecl) : Decl(DK, PrevDecl), Identifier(Id), Loc(L),
+ DeclType(T) {}
+
+ IdentifierInfo *getIdentifier() const { return Identifier; }
+ SourceLocation getLocation() const { return Loc; }
+ void setLocation(SourceLocation L) { Loc = L; }
+ const char *getName() const;
QualType getType() const { return DeclType; }
QualType getCanonicalType() const { return DeclType.getCanonicalType(); }
@@ -601,7 +614,7 @@
ParmVarDecl **paramInfo = 0, int numParams=-1,
AttributeList *M = 0, bool isInstance = true,
Decl *PrevDecl = 0)
- : Decl(ObjcMethod, L, Id, PrevDecl), MethodDeclType(T),
+ : Decl(ObjcMethod, PrevDecl), MethodDeclType(T),
ParamInfo(paramInfo), NumMethodParams(numParams),
MethodAttrs(M), IsInstance(isInstance) {}
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=41934&r1=41933&r2=41934&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu Sep 13 16:41:19 2007
@@ -116,14 +116,14 @@
/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
/// enum, etc.
class DeclRefExpr : public Expr {
- Decl *D; // a ValueDecl or EnumConstantDecl
+ ValueDecl *D;
SourceLocation Loc;
public:
- DeclRefExpr(Decl *d, QualType t, SourceLocation l) :
+ DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) :
Expr(DeclRefExprClass, t), D(d), Loc(l) {}
- Decl *getDecl() { return D; }
- const Decl *getDecl() const { return D; }
+ ValueDecl *getDecl() { return D; }
+ const ValueDecl *getDecl() const { return D; }
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=41934&r1=41933&r2=41934&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Thu Sep 13 16:41:19 2007
@@ -22,6 +22,7 @@
namespace clang {
class Expr;
class Decl;
+ class ScopedDecl;
class IdentifierInfo;
class SourceManager;
class SwitchStmt;
@@ -125,12 +126,12 @@
/// the first statement can be an expression or a declaration.
///
class DeclStmt : public Stmt {
- Decl *TheDecl;
+ ScopedDecl *TheDecl;
public:
- DeclStmt(Decl *D) : Stmt(DeclStmtClass), TheDecl(D) {}
+ DeclStmt(ScopedDecl *D) : Stmt(DeclStmtClass), TheDecl(D) {}
- const Decl *getDecl() const { return TheDecl; }
- Decl *getDecl() { return TheDecl; }
+ const ScopedDecl *getDecl() const { return TheDecl; }
+ ScopedDecl *getDecl() { return TheDecl; }
virtual SourceRange getSourceRange() const { return SourceRange(); }
More information about the cfe-commits
mailing list