[cfe-commits] r167736 - in /cfe/trunk: lib/AST/StmtPrinter.cpp test/Sema/ast-print.c

David Blaikie dblaikie at gmail.com
Mon Nov 12 11:12:12 PST 2012


Author: dblaikie
Date: Mon Nov 12 13:12:12 2012
New Revision: 167736

URL: http://llvm.org/viewvc/llvm-project?rev=167736&view=rev
Log:
Correct printing of nested anonymous type member accesses.

Patch by Florent Bruneau!

Modified:
    cfe/trunk/lib/AST/StmtPrinter.cpp
    cfe/trunk/test/Sema/ast-print.c

Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=167736&r1=167735&r2=167736&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Mon Nov 12 13:12:12 2012
@@ -910,10 +910,18 @@
 void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
   // FIXME: Suppress printing implicit bases (like "this")
   PrintExpr(Node->getBase());
+
+  MemberExpr *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
+  FieldDecl  *ParentDecl   = ParentMember ? dyn_cast<FieldDecl>(ParentMember->getMemberDecl()): NULL;
+
+  if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion()) {
+    OS << (Node->isArrow() ? "->" : ".");
+  }
+
   if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
     if (FD->isAnonymousStructOrUnion())
       return;
-  OS << (Node->isArrow() ? "->" : ".");
+
   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
     Qualifier->print(OS, Policy);
   if (Node->hasTemplateKeyword())

Modified: cfe/trunk/test/Sema/ast-print.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ast-print.c?rev=167736&r1=167735&r2=167736&view=diff
==============================================================================
--- cfe/trunk/test/Sema/ast-print.c (original)
+++ cfe/trunk/test/Sema/ast-print.c Mon Nov 12 13:12:12 2012
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -ast-print
+// RUN: %clang_cc1 %s -ast-print | FileCheck %s
 
 typedef void func_typedef();
 func_typedef xxx;
@@ -6,3 +6,15 @@
 typedef void func_t(int x);
 func_t a;
 
+struct blah {
+  struct {
+    struct {
+      int b;
+    };
+  };
+};
+
+int foo(const struct blah *b) {
+  // CHECK: return b->b;
+  return b->b;
+}





More information about the cfe-commits mailing list