Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/AST/StmtPrinter.cpp | ||
---|---|---|
2011 | what about having a Pre and Post print blocks, set to "(" and ")" or " = and ""` respectively? that way we could get rid of the second if block below. also i don't follow why blacklisting for parenlistexpr is needed here (i can see that it will end up printing double parens, but so is ParenExprs, and I think both of them shouldn't be showing up as initializer exprs of captured variables), could you elaborate with a comment and a test case? |
clang/lib/AST/StmtPrinter.cpp | ||
---|---|---|
2011 | I think you're right that skipping ParenListExpr is wrong here. I took this part of code from DeclPrinter. The ParenListExprs are skipped when printing variable declarations, but I think it is not applicable when printing lambda expression captures. Honestly, I didn't get about Pre and Post blocks. I know it is supported when printing types, but I could not find how to do this for expressions. |
clang/lib/AST/StmtPrinter.cpp | ||
---|---|---|
2011 | i meant something like below, (modulo naming): llvm::StringRef Pre; llvm::StringRef Post; if(Style == CallInit) { Pre = "("; Post = ")"; } else if (Style == CInit) Pre = " = "; OS << Pre; PrintExpr(Init): OS << Post; |
clang/lib/AST/StmtPrinter.cpp | ||
---|---|---|
2011 | Thank you for your suggestion - this makes code more clear. Regarding ParenListExpr exception - I investigated this case and found that this is necessary to prevent double braces when capturing variables of dependent unresolved types, e.g.: template <typename T> void foo(T var) { auto lambda = [m(var)] {}; } Here expression m(var) resolves in ParenListExpr which will print braces on its own. I added a couple of test cases to validate this behavior. |
do you have commit access? if not I am happy to land this for you.
After having some commits done on your behalf, you can apply for commit access as described in https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access
Thank you much for the review!
I do not have commit access. Could you please commit the changes on my behalf?
Ilya Golovenko <ilya.golovenko@huawei.com>
what about having a Pre and Post print blocks, set to "(" and ")" or " = and ""` respectively?
that way we could get rid of the second if block below.
also i don't follow why blacklisting for parenlistexpr is needed here (i can see that it will end up printing double parens, but so is ParenExprs, and I think both of them shouldn't be showing up as initializer exprs of captured variables), could you elaborate with a comment and a test case?