VD->getType().getAsStringInternal(Name);
OS << Name;
- // FIXME: Initializer for vardecl
+ // If this is a vardecl with an initializer, emit it.
+ if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
+ if (V->getInit()) {
+ OS << " = ";
+ PrintExpr(V->getInit());
+ }
+ }
} else {
// FIXME: "struct x;"
assert(0 && "Unexpected decl");
}
Sema::DeclTy *
-Sema::ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
+Sema::ParseDeclarator(Scope *S, Declarator &D, ExprTy *init,
DeclTy *lastDeclarator) {
Decl *LastDeclarator = (Decl*)lastDeclarator;
+ Expr *Init = static_cast<Expr*>(init);
IdentifierInfo *II = D.getIdentifier();
// See if this is a redefinition of a variable in the same scope.
Decl *New;
if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) {
+ assert(Init == 0 && "Can't have initializer for a typedef!");
TypedefDecl *NewTD = ParseTypedefDecl(S, D, LastDeclarator);
if (!NewTD) return 0;
}
}
} else if (D.isFunctionDeclarator()) {
+ assert(Init == 0 && "Can't have an initializer for a functiondecl!");
QualType R = GetTypeForDeclarator(D, S);
if (R.isNull()) return 0; // FIXME: "auto func();" passes through...
NewVD = MergeVarDecl(NewVD, PrevDecl);
if (NewVD == 0) return 0;
}
+
+ NewVD->setInit(Init);
New = NewVD;
}
};
StorageClass getStorageClass() const { return SClass; }
+ const Expr *getInit() const { return Init; }
+ Expr *getInit() { return Init; }
+ void setInit(Expr *I) { Init = I; }
+
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) {
return D->getKind() >= BlockVariable && D->getKind() <= ParmVariable;
: ValueDecl(DK, L, Id, T, PrevDecl) { SClass = SC; }
private:
StorageClass SClass;
- // TODO: Initializer.
+ Expr *Init;
};
/// BlockVarDecl - Represent a local variable declaration.