Nick Sumner <[email protected]> writes: > Revised patch attached.
LGTM. Do you need me to commit this for you? > Nick > > > On Wed, May 27, 2015 at 8:18 PM, Justin Bogner <[email protected]> wrote: >> Nick Sumner <[email protected]> writes: >>> Hi all, >>> >>> The attached patch allows StmtPrinter to print old style field >>> designators in initializers. Given the code: >>> struct A { int b; int c; }; >>> struct A a = {b: 3, .c = 4}; >>> >>> The initializer is presently printed as: >>> struct A a = {b: = 3, .c = 4}; >>> >>> The combination of ':' and '=' is invalid. >>> >>> With the patch, the initializer is printed as: >>> struct A a = {b: 3, .c = 4}; >> >> Looks pretty good. Could you convert the test to one that runs as part >> of make check? You can probably add something to test/Sema/ast-print.c, >> or at least use that test as an example. >> >>> Best, >>> Nick >>> >>> Index: lib/AST/StmtPrinter.cpp >>> =================================================================== >>> --- lib/AST/StmtPrinter.cpp (revision 238263) >>> +++ lib/AST/StmtPrinter.cpp (working copy) >>> @@ -1395,13 +1395,16 @@ >>> } >>> >>> void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) { >>> + bool needsEquals = true; >>> for (DesignatedInitExpr::designators_iterator D = >>> Node->designators_begin(), >>> DEnd = Node->designators_end(); >>> D != DEnd; ++D) { >>> if (D->isFieldDesignator()) { >>> if (D->getDotLoc().isInvalid()) { >>> - if (IdentifierInfo *II = D->getFieldName()) >>> + if (IdentifierInfo *II = D->getFieldName()) { >>> OS << II->getName() << ":"; >>> + needsEquals = false; >>> + } >>> } else { >>> OS << "." << D->getFieldName()->getName(); >>> } >>> @@ -1418,7 +1421,10 @@ >>> } >>> } >>> >>> - OS << " = "; >>> + if (needsEquals) >>> + OS << " = "; >>> + else >>> + OS << " "; >>> PrintExpr(Node->getInit()); >>> } >>> >>> >>> >>> struct A { int b; int c; }; >>> struct A a = {b: 3, .c = 4}; >>> >>> struct D { struct A d[10]; struct A e[10]; }; >>> struct D d = { .d[5].c = 3, e: { [5].c = 4 } }; >>> // e:[5].c is invalid syntax >>> >>> _______________________________________________ >>> cfe-commits mailing list >>> [email protected] >>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > > Index: lib/AST/StmtPrinter.cpp > =================================================================== > --- lib/AST/StmtPrinter.cpp (revision 238393) > +++ lib/AST/StmtPrinter.cpp (working copy) > @@ -1395,13 +1395,16 @@ > } > > void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) { > + bool NeedsEquals = true; > for (DesignatedInitExpr::designators_iterator D = > Node->designators_begin(), > DEnd = Node->designators_end(); > D != DEnd; ++D) { > if (D->isFieldDesignator()) { > if (D->getDotLoc().isInvalid()) { > - if (IdentifierInfo *II = D->getFieldName()) > + if (IdentifierInfo *II = D->getFieldName()) { > OS << II->getName() << ":"; > + NeedsEquals = false; > + } > } else { > OS << "." << D->getFieldName()->getName(); > } > @@ -1418,7 +1421,10 @@ > } > } > > - OS << " = "; > + if (NeedsEquals) > + OS << " = "; > + else > + OS << " "; > PrintExpr(Node->getInit()); > } > > Index: test/Sema/ast-print.c > =================================================================== > --- test/Sema/ast-print.c (revision 238393) > +++ test/Sema/ast-print.c (working copy) > @@ -45,3 +45,12 @@ > > // CHECK: struct __attribute__((visibility("default"))) S; > struct __attribute__((visibility("default"))) S; > + > +struct pair_t { > + int a; > + int b; > +}; > + > +// CHECK: struct pair_t p = {a: 3, .b = 4}; > +struct pair_t p = {a: 3, .b = 4}; > + _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
