[cfe-commits] r41615 - in /cfe/trunk: AST/StmtPrinter.cpp Sema/SemaExpr.cpp include/clang/AST/StmtVisitor.h
Chris Lattner
sabre at nondot.org
Thu Aug 30 11:00:00 PDT 2007
Author: lattner
Date: Thu Aug 30 12:59:59 2007
New Revision: 41615
URL: http://llvm.org/viewvc/llvm-project?rev=41615&view=rev
Log:
implement pretty printing of offsetof
Modified:
cfe/trunk/AST/StmtPrinter.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/StmtVisitor.h
Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=41615&r1=41614&r2=41615&view=diff
==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Thu Aug 30 12:59:59 2007
@@ -64,6 +64,9 @@
return OS;
}
+ bool PrintOffsetOfDesignator(Expr *E);
+ void VisitUnaryOffsetOf(UnaryOperator *Node);
+
void VisitStmt(Stmt *Node);
#define STMT(N, CLASS, PARENT) \
void Visit##CLASS(CLASS *Node);
@@ -429,8 +432,33 @@
if (Node->isPostfix())
OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
+}
+
+bool StmtPrinter::PrintOffsetOfDesignator(Expr *E) {
+ if (isa<CompoundLiteralExpr>(E)) {
+ // Base case, print the type and comma.
+ OS << E->getType().getAsString() << ", ";
+ return true;
+ } else if (ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
+ PrintOffsetOfDesignator(ASE->getLHS());
+ OS << "[";
+ PrintExpr(ASE->getRHS());
+ OS << "]";
+ return false;
+ } else {
+ MemberExpr *ME = cast<MemberExpr>(E);
+ bool IsFirst = PrintOffsetOfDesignator(ME->getBase());
+ OS << (IsFirst ? "" : ".") << ME->getMemberDecl()->getName();
+ return false;
+ }
+}
+void StmtPrinter::VisitUnaryOffsetOf(UnaryOperator *Node) {
+ OS << "__builtin_offsetof(";
+ PrintOffsetOfDesignator(Node->getSubExpr());
+ OS << ")";
}
+
void StmtPrinter::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
OS << (Node->isSizeOf() ? "sizeof(" : "__alignof(");
OS << Node->getArgumentType().getAsString() << ")";
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=41615&r1=41614&r2=41615&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Thu Aug 30 12:59:59 2007
@@ -1748,6 +1748,8 @@
Res->getType().getAsString());
}
+ // FIXME: C++: Verify that operator[] isn't overloaded.
+
// C99 6.5.2.1p1
Expr *Idx = static_cast<Expr*>(OC.U.E);
if (!Idx->getType()->isIntegerType())
@@ -1772,6 +1774,10 @@
return Diag(BuiltinLoc, diag::err_typecheck_no_member,
OC.U.IdentInfo->getName(),
SourceRange(OC.LocStart, OC.LocEnd));
+
+ // FIXME: C++: Verify that MemberDecl isn't a static field.
+ // FIXME: Verify that MemberDecl isn't a bitfield.
+
Res = new MemberExpr(Res, false, MemberDecl, OC.LocEnd);
}
Modified: cfe/trunk/include/clang/AST/StmtVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtVisitor.h?rev=41615&r1=41614&r2=41615&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/StmtVisitor.h (original)
+++ cfe/trunk/include/clang/AST/StmtVisitor.h Thu Aug 30 12:59:59 2007
@@ -95,7 +95,7 @@
case UnaryOperator::Real: DISPATCH(UnaryReal, UnaryOperator);
case UnaryOperator::Imag: DISPATCH(UnaryImag, UnaryOperator);
case UnaryOperator::Extension: DISPATCH(UnaryExtension, UnaryOperator);
- case UnaryOperator::OffsetOf: DISPATCH(UnaryExtension, UnaryOperator);
+ case UnaryOperator::OffsetOf: DISPATCH(UnaryOffsetOf, UnaryOperator);
}
}
More information about the cfe-commits
mailing list