decls should all have types

llvm-svn: 39187
This commit is contained in:
Chris Lattner 2006-11-19 23:32:49 +00:00
parent 591a675b1c
commit 5ca17df626
3 changed files with 24 additions and 24 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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.