[cfe-commits] [PATCH][Review Request] - AST Print Problem with Constructor Initializer(version2)
Ted Kremenek
kremenek at apple.com
Tue Sep 7 15:23:07 PDT 2010
Hi Jim,
This looks good to me. I have one nit below.
On Sep 3, 2010, at 11:34 AM, Jim Goodnow II wrote:
> Didn't quite get it right the first time, but there is still a problem with arguments not being printed. Will look into it.
>
> - jim
>
> Index: lib/AST/DeclPrinter.cpp
> ===================================================================
> --- lib/AST/DeclPrinter.cpp (revision 112954)
> +++ lib/AST/DeclPrinter.cpp (working copy)
> @@ -518,12 +518,13 @@
> T = Parm->getOriginalType();
> T.getAsStringInternal(Name, Policy);
> Out << Name;
> - if (D->getInit()) {
> + Expr *Init = D->getInit();
> + if (Init) {
Since 'Init' is only used within the body of the conditional, I typically prefer:
if (Expr *Init = D->getInit())
instead of:
Expr *Init = D->getInit();
if (Init) {
The former restricts the scope of the 'Init' to where it is intended, making it impossible to use afterwards.
> if (D->hasCXXDirectInitializer())
> Out << "(";
> - else
> + else if (!dyn_cast<CXXConstructExpr>(Init))
> Out << " = ";
> - D->getInit()->printPretty(Out, Context, 0, Policy, Indentation);
> + Init->printPretty(Out, Context, 0, Policy, Indentation);
> if (D->hasCXXDirectInitializer())
> Out << ")";
> }<DeclPrinter.patch>_______________________________________________
I've gone ahead and applied this patch (with my suggested change) in r113296.
Cheers,
Ted
More information about the cfe-commits
mailing list