From 5ca17df62617797189947106b601c85e2fa9cc7c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 19 Nov 2006 23:32:49 +0000 Subject: [PATCH] decls should all have types llvm-svn: 39187 --- clang/AST/SemaDecl.cpp | 9 ++++----- clang/Sema/SemaDecl.cpp | 9 ++++----- clang/include/clang/AST/Decl.h | 30 ++++++++++++++++-------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/clang/AST/SemaDecl.cpp b/clang/AST/SemaDecl.cpp index 68429eae691a..22c69c9388ad 100644 --- a/clang/AST/SemaDecl.cpp +++ b/clang/AST/SemaDecl.cpp @@ -60,8 +60,6 @@ Sema::DeclTy *Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) { Action::DeclTy * Sema::ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init, DeclTy *LastInGroup) { - TypeRef DeclaratorType = GetTypeForDeclarator(D, S); - IdentifierInfo *II = D.getIdentifier(); Decl *PrevDecl = 0; @@ -75,9 +73,9 @@ Sema::ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init, if (D.getDeclSpec().StorageClassSpec == DeclSpec::SCS_typedef) { New = ParseTypedefDecl(S, D, PrevDecl); } else if (D.isFunctionDeclarator()) - New = new FunctionDecl(II, PrevDecl); + New = new FunctionDecl(II, GetTypeForDeclarator(D, S), PrevDecl); else - New = new VarDecl(II, PrevDecl); + New = new VarDecl(II, GetTypeForDeclarator(D, S), PrevDecl); if (!New) return 0; @@ -111,6 +109,7 @@ Sema::ParseFunctionDefinition(Scope *S, Declarator &D, StmtTy *Body) { Decl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, Decl *PrevDecl) { assert(D.getIdentifier() && "Wrong callback for declspec withotu declarator"); - return new TypedefDecl(D.getIdentifier(), PrevDecl); + TypeRef T = GetTypeForDeclarator(D, S); + return new TypedefDecl(D.getIdentifier(), T, PrevDecl); } diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp index 68429eae691a..22c69c9388ad 100644 --- a/clang/Sema/SemaDecl.cpp +++ b/clang/Sema/SemaDecl.cpp @@ -60,8 +60,6 @@ Sema::DeclTy *Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) { Action::DeclTy * Sema::ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init, DeclTy *LastInGroup) { - TypeRef DeclaratorType = GetTypeForDeclarator(D, S); - IdentifierInfo *II = D.getIdentifier(); Decl *PrevDecl = 0; @@ -75,9 +73,9 @@ Sema::ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init, if (D.getDeclSpec().StorageClassSpec == DeclSpec::SCS_typedef) { New = ParseTypedefDecl(S, D, PrevDecl); } else if (D.isFunctionDeclarator()) - New = new FunctionDecl(II, PrevDecl); + New = new FunctionDecl(II, GetTypeForDeclarator(D, S), PrevDecl); else - New = new VarDecl(II, PrevDecl); + New = new VarDecl(II, GetTypeForDeclarator(D, S), PrevDecl); if (!New) return 0; @@ -111,6 +109,7 @@ Sema::ParseFunctionDefinition(Scope *S, Declarator &D, StmtTy *Body) { Decl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, Decl *PrevDecl) { assert(D.getIdentifier() && "Wrong callback for declspec withotu declarator"); - return new TypedefDecl(D.getIdentifier(), PrevDecl); + TypeRef T = GetTypeForDeclarator(D, S); + return new TypedefDecl(D.getIdentifier(), T, PrevDecl); } diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 1fcfb15ff98a..153ca7d2933a 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -15,6 +15,7 @@ #define LLVM_CLANG_AST_DECL_H #include "clang/Basic/SourceLocation.h" +#include "clang/AST/Type.h" namespace llvm { namespace clang { @@ -31,28 +32,29 @@ public: Typedef, Function, Variable }; private: + /// DeclKind - This indicates which class this is. + Kind DeclKind; + /// Identifier - The identifier for this declaration (e.g. the name for the /// variable, the tag for a struct). IdentifierInfo *Identifier; /// Type. - - /// DeclKind - This indicates which class this is. - Kind DeclKind; + TypeRef DeclType; /// Scope stack info when parsing, otherwise decl list when scope is popped. /// Decl *Next; public: - Decl(IdentifierInfo *Id, Kind DK, Decl *next) - : Identifier(Id), DeclKind(DK), Next(next) {} + Decl(Kind DK, IdentifierInfo *Id, TypeRef T, Decl *next) + : DeclKind(DK), Identifier(Id), DeclType(T), Next(next) {} virtual ~Decl(); const IdentifierInfo *getIdentifier() const { return Identifier; } + TypeRef getType() const { return DeclType; } Kind getKind() const { return DeclKind; } - Decl *getNext() const { return Next; } // Implement isa/cast/dyncast/etc. @@ -63,8 +65,8 @@ public: /// Objective-C classes. class TypeDecl : public Decl { public: - TypeDecl(IdentifierInfo *Id, Kind DK, Decl *Next) - : Decl(Id, DK, Next) {} + TypeDecl(Kind DK, IdentifierInfo *Id, TypeRef T, Decl *Next) + : Decl(DK, Id, T, Next) {} // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return D->getKind() == Typedef; } @@ -74,8 +76,8 @@ public: class TypedefDecl : public TypeDecl { public: // FIXME: Remove Declarator argument. - TypedefDecl(IdentifierInfo *Id, Decl *Next) - : TypeDecl(Id, Typedef, Next) {} + TypedefDecl(IdentifierInfo *Id, TypeRef T, Decl *Next) + : TypeDecl(Typedef, Id, T, Next) {} // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return D->getKind() == Typedef; } @@ -88,8 +90,8 @@ class FunctionDecl : public Decl { // Args etc. Stmt *Body; // Null if a prototype. public: - FunctionDecl(IdentifierInfo *Id, Decl *Next) - : Decl(Id, Function, Next), Body(0) {} + FunctionDecl(IdentifierInfo *Id, TypeRef T, Decl *Next) + : Decl(Function, Id, T, Next), Body(0) {} Stmt *getBody() const { return Body; } void setBody(Stmt *B) { Body = B; } @@ -105,8 +107,8 @@ public: class VarDecl : public Decl { // Initializer. public: - VarDecl(IdentifierInfo *Id, Decl *Next) - : Decl(Id, Variable, Next) {} + VarDecl(IdentifierInfo *Id, TypeRef T, Decl *Next) + : Decl(Variable, Id, T, Next) {} // Implement isa/cast/dyncast/etc.