[cfe-commits] r39191 - in /cfe/cfe/trunk: AST/SemaDecl.cpp AST/SemaExpr.cpp AST/SemaType.cpp AST/StmtPrinter.cpp Sema/SemaDecl.cpp Sema/SemaExpr.cpp Sema/SemaType.cpp include/clang/AST/Expr.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:40:52 PDT 2007
Author: sabre
Date: Wed Jul 11 11:40:52 2007
New Revision: 39191
URL: http://llvm.org/viewvc/llvm-project?rev=39191&view=rev
Log:
remember and pretty-print cast types
Modified:
cfe/cfe/trunk/AST/SemaDecl.cpp
cfe/cfe/trunk/AST/SemaExpr.cpp
cfe/cfe/trunk/AST/SemaType.cpp
cfe/cfe/trunk/AST/StmtPrinter.cpp
cfe/cfe/trunk/Sema/SemaDecl.cpp
cfe/cfe/trunk/Sema/SemaExpr.cpp
cfe/cfe/trunk/Sema/SemaType.cpp
cfe/cfe/trunk/include/clang/AST/Expr.h
Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39191&r1=39190&r2=39191&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:40:52 2007
@@ -109,6 +109,8 @@
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);
}
Modified: cfe/cfe/trunk/AST/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaExpr.cpp?rev=39191&r1=39190&r2=39191&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/AST/SemaExpr.cpp Wed Jul 11 11:40:52 2007
@@ -304,8 +304,8 @@
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 @@
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);
}
Modified: cfe/cfe/trunk/AST/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaType.cpp?rev=39191&r1=39190&r2=39191&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaType.cpp (original)
+++ cfe/cfe/trunk/AST/SemaType.cpp Wed Jul 11 11:40:52 2007
@@ -92,6 +92,9 @@
/// 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);
Modified: cfe/cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/StmtPrinter.cpp?rev=39191&r1=39190&r2=39191&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/cfe/trunk/AST/StmtPrinter.cpp Wed Jul 11 11:40:52 2007
@@ -289,9 +289,9 @@
}
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) {
Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39191&r1=39190&r2=39191&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:40:52 2007
@@ -109,6 +109,8 @@
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);
}
Modified: cfe/cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaExpr.cpp?rev=39191&r1=39190&r2=39191&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:40:52 2007
@@ -304,8 +304,8 @@
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 @@
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);
}
Modified: cfe/cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaType.cpp?rev=39191&r1=39190&r2=39191&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaType.cpp Wed Jul 11 11:40:52 2007
@@ -92,6 +92,9 @@
/// 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);
Modified: cfe/cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Expr.h?rev=39191&r1=39190&r2=39191&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:40:52 2007
@@ -215,10 +215,12 @@
/// 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);
More information about the cfe-commits
mailing list