[cfe-commits] r39181 - in /cfe/cfe/trunk: AST/Sema.h AST/SemaExpr.cpp AST/SemaType.cpp AST/StmtPrinter.cpp Sema/Sema.h Sema/SemaExpr.cpp Sema/SemaType.cpp include/clang/AST/Expr.h include/clang/AST/Type.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:40:41 PDT 2007
Author: sabre
Date: Wed Jul 11 11:40:40 2007
New Revision: 39181
URL: http://llvm.org/viewvc/llvm-project?rev=39181&view=rev
Log:
Parse and remember types enough that we can pretty print:
void foo(int X) {
X = __alignof(int);
X = sizeof(const int** restrict ** volatile*);
}
as:
x = __alignof(int)
x = sizeof(int const **restrict **volatile *)
Modified:
cfe/cfe/trunk/AST/Sema.h
cfe/cfe/trunk/AST/SemaExpr.cpp
cfe/cfe/trunk/AST/SemaType.cpp
cfe/cfe/trunk/AST/StmtPrinter.cpp
cfe/cfe/trunk/Sema/Sema.h
cfe/cfe/trunk/Sema/SemaExpr.cpp
cfe/cfe/trunk/Sema/SemaType.cpp
cfe/cfe/trunk/include/clang/AST/Expr.h
cfe/cfe/trunk/include/clang/AST/Type.h
Modified: cfe/cfe/trunk/AST/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.h?rev=39181&r1=39180&r2=39181&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Sema.h (original)
+++ cfe/cfe/trunk/AST/Sema.h Wed Jul 11 11:40:40 2007
@@ -48,6 +48,7 @@
//
TypeRef GetTypeForDeclarator(Declarator &D, Scope *S);
+ virtual TypeResult ParseTypeName(Scope *S, Declarator &D);
//===--------------------------------------------------------------------===//
// Symbol table / Decl tracking callbacks: SemaDecl.cpp.
Modified: cfe/cfe/trunk/AST/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaExpr.cpp?rev=39181&r1=39180&r2=39181&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/AST/SemaExpr.cpp Wed Jul 11 11:40:40 2007
@@ -304,7 +304,9 @@
ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
SourceLocation LParenLoc, TypeTy *Ty,
SourceLocation RParenLoc) {
- return new SizeOfAlignOfTypeExpr(isSizeof, (Type*)Ty);
+ // Error parsing type, ignore.
+ if (Ty == 0) return 0;
+ return new SizeOfAlignOfTypeExpr(isSizeof, TypeRef::getFromOpaquePtr(Ty));
}
Modified: cfe/cfe/trunk/AST/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaType.cpp?rev=39181&r1=39180&r2=39181&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaType.cpp (original)
+++ cfe/cfe/trunk/AST/SemaType.cpp Wed Jul 11 11:40:40 2007
@@ -119,3 +119,11 @@
return T;
}
+
+Sema::TypeResult Sema::ParseTypeName(Scope *S, Declarator &D) {
+ // FIXME: Validate Declarator.
+
+ TypeRef T = GetTypeForDeclarator(D, S);
+
+ return T.getAsOpaquePtr();
+}
Modified: cfe/cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/StmtPrinter.cpp?rev=39181&r1=39180&r2=39181&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/cfe/trunk/AST/StmtPrinter.cpp Wed Jul 11 11:40:40 2007
@@ -257,9 +257,11 @@
}
void StmtPrinter::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
- OS << (Node->isSizeOf() ? "sizeof(" : "alignof(");
- // FIXME: print type.
- OS << "ty)";
+ OS << (Node->isSizeOf() ? "sizeof(" : "__alignof(");
+
+ std::string TypeStr;
+ Node->getArgumentType()->getAsString(TypeStr);
+ OS << TypeStr << ")";
}
void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
PrintExpr(Node->getBase());
Modified: cfe/cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.h?rev=39181&r1=39180&r2=39181&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/Sema.h (original)
+++ cfe/cfe/trunk/Sema/Sema.h Wed Jul 11 11:40:40 2007
@@ -48,6 +48,7 @@
//
TypeRef GetTypeForDeclarator(Declarator &D, Scope *S);
+ virtual TypeResult ParseTypeName(Scope *S, Declarator &D);
//===--------------------------------------------------------------------===//
// Symbol table / Decl tracking callbacks: SemaDecl.cpp.
Modified: cfe/cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaExpr.cpp?rev=39181&r1=39180&r2=39181&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:40:40 2007
@@ -304,7 +304,9 @@
ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
SourceLocation LParenLoc, TypeTy *Ty,
SourceLocation RParenLoc) {
- return new SizeOfAlignOfTypeExpr(isSizeof, (Type*)Ty);
+ // Error parsing type, ignore.
+ if (Ty == 0) return 0;
+ return new SizeOfAlignOfTypeExpr(isSizeof, TypeRef::getFromOpaquePtr(Ty));
}
Modified: cfe/cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaType.cpp?rev=39181&r1=39180&r2=39181&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaType.cpp Wed Jul 11 11:40:40 2007
@@ -119,3 +119,11 @@
return T;
}
+
+Sema::TypeResult Sema::ParseTypeName(Scope *S, Declarator &D) {
+ // FIXME: Validate Declarator.
+
+ TypeRef T = GetTypeForDeclarator(D, S);
+
+ return T.getAsOpaquePtr();
+}
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=39181&r1=39180&r2=39181&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:40:40 2007
@@ -15,12 +15,12 @@
#define LLVM_CLANG_AST_EXPR_H
#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
namespace llvm {
namespace clang {
class IdentifierInfo;
class Decl;
- class Type;
/// Expr - This represents one expression. Note that Expr's are subclasses of
/// Stmt. This allows an expression to be transparently used any place a Stmt
@@ -135,12 +135,13 @@
/// *types*. sizeof(expr) is handled by UnaryOperator.
class SizeOfAlignOfTypeExpr : public Expr {
bool isSizeof; // true if sizeof, false if alignof.
- Type *Ty;
+ TypeRef Ty;
public:
- SizeOfAlignOfTypeExpr(bool issizeof, Type *ty) : isSizeof(issizeof), Ty(ty) {
+ SizeOfAlignOfTypeExpr(bool issizeof, TypeRef ty) : isSizeof(issizeof), Ty(ty){
}
bool isSizeOf() const { return isSizeof; }
+ TypeRef getArgumentType() const { return Ty; }
virtual void visit(StmtVisitor &Visitor);
};
Modified: cfe/cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Type.h?rev=39181&r1=39180&r2=39181&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Type.h Wed Jul 11 11:40:40 2007
@@ -53,6 +53,12 @@
assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?");
ThePtr |= Quals;
}
+
+ static TypeRef getFromOpaquePtr(void *Ptr) {
+ TypeRef T;
+ T.ThePtr = reinterpret_cast<uintptr_t>(Ptr);
+ return T;
+ }
unsigned getQualifiers() const {
return ThePtr & CVRFlags;
@@ -61,6 +67,10 @@
return reinterpret_cast<Type*>(ThePtr & ~CVRFlags);
}
+ void *getAsOpaquePtr() const {
+ return reinterpret_cast<void*>(ThePtr);
+ }
+
Type &operator*() const {
return *getTypePtr();
}
More information about the cfe-commits
mailing list