diff --git a/clang/AST/SemaDecl.cpp b/clang/AST/SemaDecl.cpp index 5f53e47591fa..a90831df9ba9 100644 --- a/clang/AST/SemaDecl.cpp +++ b/clang/AST/SemaDecl.cpp @@ -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); } diff --git a/clang/AST/SemaExpr.cpp b/clang/AST/SemaExpr.cpp index 5ef5475ffe5e..9c5f36eeb202 100644 --- a/clang/AST/SemaExpr.cpp +++ b/clang/AST/SemaExpr.cpp @@ -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); } diff --git a/clang/AST/SemaType.cpp b/clang/AST/SemaType.cpp index a2e507c7af10..bba3ef5cb456 100644 --- a/clang/AST/SemaType.cpp +++ b/clang/AST/SemaType.cpp @@ -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); diff --git a/clang/AST/StmtPrinter.cpp b/clang/AST/StmtPrinter.cpp index e8fa8d811e87..8aa05bbe8a32 100644 --- a/clang/AST/StmtPrinter.cpp +++ b/clang/AST/StmtPrinter.cpp @@ -289,9 +289,9 @@ void StmtPrinter::VisitMemberExpr(MemberExpr *Node) { } void StmtPrinter::VisitCastExpr(CastExpr *Node) { OS << "("; - // TODO PRINT TYPE - OS << ""; - OS << ")"; + std::string TypeStr; + Node->getDestType().getAsString(TypeStr); + OS << TypeStr << ")"; PrintExpr(Node->getSubExpr()); } void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) { diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp index 5f53e47591fa..a90831df9ba9 100644 --- a/clang/Sema/SemaDecl.cpp +++ b/clang/Sema/SemaDecl.cpp @@ -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); } diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp index 5ef5475ffe5e..9c5f36eeb202 100644 --- a/clang/Sema/SemaExpr.cpp +++ b/clang/Sema/SemaExpr.cpp @@ -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); } diff --git a/clang/Sema/SemaType.cpp b/clang/Sema/SemaType.cpp index a2e507c7af10..bba3ef5cb456 100644 --- a/clang/Sema/SemaType.cpp +++ b/clang/Sema/SemaType.cpp @@ -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); diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index e442788a1681..27ffccf05f03 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -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);