remember and pretty-print cast types

llvm-svn: 39191
This commit is contained in:
Chris Lattner 2006-11-20 04:34:45 +00:00
parent f0a40e7ef4
commit 0d8b1a1eff
8 changed files with 27 additions and 11 deletions

View File

@ -109,6 +109,8 @@ Decl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, Decl *PrevDecl) {
assert(D.getIdentifier() && "Wrong callback for declspec withotu declarator");
TypeRef T = GetTypeForDeclarator(D, S);
if (T.isNull()) return 0;
return new TypedefDecl(D.getIdentifier(), T, PrevDecl);
}

View File

@ -304,8 +304,8 @@ Action::ExprResult Sema::
ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
SourceLocation LParenLoc, TypeTy *Ty,
SourceLocation RParenLoc) {
// Error parsing type, ignore.
if (Ty == 0) return 0;
// If error parsing type, ignore.
if (Ty == 0) return true;
return new SizeOfAlignOfTypeExpr(isSizeof, TypeRef::getFromOpaquePtr(Ty));
}
@ -351,7 +351,9 @@ ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
Action::ExprResult Sema::
ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
SourceLocation RParenLoc, ExprTy *Op) {
return new CastExpr((Type*)Ty, (Expr*)Op);
// If error parsing type, ignore.
if (Ty == 0) return true;
return new CastExpr(TypeRef::getFromOpaquePtr(Ty), (Expr*)Op);
}

View File

@ -92,6 +92,9 @@ static TypeRef ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) {
/// instances.
TypeRef Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
TypeRef T = ConvertDeclSpecToType(D.getDeclSpec(), Context);
// If there was an error parsing declspecs, return a null type pointer.
if (T.isNull()) return T;
// Apply const/volatile/restrict qualifiers to T.
T = T.getQualifiedType(D.getDeclSpec().TypeQualifiers);

View File

@ -289,9 +289,9 @@ void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
}
void StmtPrinter::VisitCastExpr(CastExpr *Node) {
OS << "(";
// TODO PRINT TYPE
OS << "<type>";
OS << ")";
std::string TypeStr;
Node->getDestType().getAsString(TypeStr);
OS << TypeStr << ")";
PrintExpr(Node->getSubExpr());
}
void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {

View File

@ -109,6 +109,8 @@ Decl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, Decl *PrevDecl) {
assert(D.getIdentifier() && "Wrong callback for declspec withotu declarator");
TypeRef T = GetTypeForDeclarator(D, S);
if (T.isNull()) return 0;
return new TypedefDecl(D.getIdentifier(), T, PrevDecl);
}

View File

@ -304,8 +304,8 @@ Action::ExprResult Sema::
ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
SourceLocation LParenLoc, TypeTy *Ty,
SourceLocation RParenLoc) {
// Error parsing type, ignore.
if (Ty == 0) return 0;
// If error parsing type, ignore.
if (Ty == 0) return true;
return new SizeOfAlignOfTypeExpr(isSizeof, TypeRef::getFromOpaquePtr(Ty));
}
@ -351,7 +351,9 @@ ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
Action::ExprResult Sema::
ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
SourceLocation RParenLoc, ExprTy *Op) {
return new CastExpr((Type*)Ty, (Expr*)Op);
// If error parsing type, ignore.
if (Ty == 0) return true;
return new CastExpr(TypeRef::getFromOpaquePtr(Ty), (Expr*)Op);
}

View File

@ -92,6 +92,9 @@ static TypeRef ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) {
/// instances.
TypeRef Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
TypeRef T = ConvertDeclSpecToType(D.getDeclSpec(), Context);
// If there was an error parsing declspecs, return a null type pointer.
if (T.isNull()) return T;
// Apply const/volatile/restrict qualifiers to T.
T = T.getQualifiedType(D.getDeclSpec().TypeQualifiers);

View File

@ -215,10 +215,12 @@ public:
/// CastExpr - [C99 6.5.4] Cast Operators.
///
class CastExpr : public Expr {
Type *Ty;
TypeRef Ty;
Expr *Op;
public:
CastExpr(Type *ty, Expr *op) : Ty(ty), Op(op) {}
CastExpr(TypeRef ty, Expr *op) : Ty(ty), Op(op) {}
TypeRef getDestType() const { return Ty; }
Expr *getSubExpr() { return Op; }
virtual void visit(StmtVisitor &Visitor);