[PATCH] D153699: [clang] Fix pretty-printing for variables declared in a for-loop condition
vaithak created this revision. Herald added a project: All. vaithak requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D153699 Files: clang/lib/AST/StmtPrinter.cpp clang/test/PCH/for-loop-init-ternary-operator-statement.cpp clang/test/SemaCXX/ast-print.cpp Index: clang/test/SemaCXX/ast-print.cpp === --- clang/test/SemaCXX/ast-print.cpp +++ clang/test/SemaCXX/ast-print.cpp @@ -21,12 +21,14 @@ // CHECK: if (int a = 1) // CHECK: while (int a = 1) // CHECK: switch (int a = 1) +// CHECK: for (; int a = 1;) void test2() { if (int a = 1) { } while (int a = 1) { } switch (int a = 1) { } +for(; int a = 1; ) { } } // CHECK: new (1) int; Index: clang/test/PCH/for-loop-init-ternary-operator-statement.cpp === --- clang/test/PCH/for-loop-init-ternary-operator-statement.cpp +++ clang/test/PCH/for-loop-init-ternary-operator-statement.cpp @@ -2,7 +2,7 @@ // RUN: %clang_cc1 -x ast -ast-print %t | FileCheck %s int f() { - // CHECK: for (int i = 0; x; i++) { + // CHECK: for (int i = 0; int x = i < 2 ? 1 : 0; i++) { for (int i = 0; int x = i < 2 ? 1 : 0; i++) { return x; } Index: clang/lib/AST/StmtPrinter.cpp === --- clang/lib/AST/StmtPrinter.cpp +++ clang/lib/AST/StmtPrinter.cpp @@ -400,7 +400,9 @@ PrintInitStmt(Node->getInit(), 5); else OS << (Node->getCond() ? "; " : ";"); - if (Node->getCond()) + if (const DeclStmt *DS = Node->getConditionVariableDeclStmt()) +PrintRawDeclStmt(DS); + else if (Node->getCond()) PrintExpr(Node->getCond()); OS << ";"; if (Node->getInc()) { Index: clang/test/SemaCXX/ast-print.cpp === --- clang/test/SemaCXX/ast-print.cpp +++ clang/test/SemaCXX/ast-print.cpp @@ -21,12 +21,14 @@ // CHECK: if (int a = 1) // CHECK: while (int a = 1) // CHECK: switch (int a = 1) +// CHECK: for (; int a = 1;) void test2() { if (int a = 1) { } while (int a = 1) { } switch (int a = 1) { } +for(; int a = 1; ) { } } // CHECK: new (1) int; Index: clang/test/PCH/for-loop-init-ternary-operator-statement.cpp === --- clang/test/PCH/for-loop-init-ternary-operator-statement.cpp +++ clang/test/PCH/for-loop-init-ternary-operator-statement.cpp @@ -2,7 +2,7 @@ // RUN: %clang_cc1 -x ast -ast-print %t | FileCheck %s int f() { - // CHECK: for (int i = 0; x; i++) { + // CHECK: for (int i = 0; int x = i < 2 ? 1 : 0; i++) { for (int i = 0; int x = i < 2 ? 1 : 0; i++) { return x; } Index: clang/lib/AST/StmtPrinter.cpp === --- clang/lib/AST/StmtPrinter.cpp +++ clang/lib/AST/StmtPrinter.cpp @@ -400,7 +400,9 @@ PrintInitStmt(Node->getInit(), 5); else OS << (Node->getCond() ? "; " : ";"); - if (Node->getCond()) + if (const DeclStmt *DS = Node->getConditionVariableDeclStmt()) +PrintRawDeclStmt(DS); + else if (Node->getCond()) PrintExpr(Node->getCond()); OS << ";"; if (Node->getInc()) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D153699: [clang] Fix pretty-printing for variables declared in a for-loop condition
vaithak updated this revision to Diff 534223. vaithak added a comment. rebased on the latest changes Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D153699/new/ https://reviews.llvm.org/D153699 Files: clang/lib/AST/StmtPrinter.cpp clang/test/PCH/for-loop-init-ternary-operator-statement.cpp clang/test/SemaCXX/ast-print.cpp Index: clang/test/SemaCXX/ast-print.cpp === --- clang/test/SemaCXX/ast-print.cpp +++ clang/test/SemaCXX/ast-print.cpp @@ -21,12 +21,14 @@ // CHECK: if (int a = 1) // CHECK: while (int a = 1) // CHECK: switch (int a = 1) +// CHECK: for (; int a = 1;) void test2() { if (int a = 1) { } while (int a = 1) { } switch (int a = 1) { } +for(; int a = 1; ) { } } // CHECK: new (1) int; Index: clang/test/PCH/for-loop-init-ternary-operator-statement.cpp === --- clang/test/PCH/for-loop-init-ternary-operator-statement.cpp +++ clang/test/PCH/for-loop-init-ternary-operator-statement.cpp @@ -2,7 +2,7 @@ // RUN: %clang_cc1 -x ast -ast-print %t | FileCheck %s int f() { - // CHECK: for (int i = 0; x; i++) { + // CHECK: for (int i = 0; int x = i < 2 ? 1 : 0; i++) { for (int i = 0; int x = i < 2 ? 1 : 0; i++) { return x; } Index: clang/lib/AST/StmtPrinter.cpp === --- clang/lib/AST/StmtPrinter.cpp +++ clang/lib/AST/StmtPrinter.cpp @@ -400,7 +400,9 @@ PrintInitStmt(Node->getInit(), 5); else OS << (Node->getCond() ? "; " : ";"); - if (Node->getCond()) + if (const DeclStmt *DS = Node->getConditionVariableDeclStmt()) +PrintRawDeclStmt(DS); + else if (Node->getCond()) PrintExpr(Node->getCond()); OS << ";"; if (Node->getInc()) { Index: clang/test/SemaCXX/ast-print.cpp === --- clang/test/SemaCXX/ast-print.cpp +++ clang/test/SemaCXX/ast-print.cpp @@ -21,12 +21,14 @@ // CHECK: if (int a = 1) // CHECK: while (int a = 1) // CHECK: switch (int a = 1) +// CHECK: for (; int a = 1;) void test2() { if (int a = 1) { } while (int a = 1) { } switch (int a = 1) { } +for(; int a = 1; ) { } } // CHECK: new (1) int; Index: clang/test/PCH/for-loop-init-ternary-operator-statement.cpp === --- clang/test/PCH/for-loop-init-ternary-operator-statement.cpp +++ clang/test/PCH/for-loop-init-ternary-operator-statement.cpp @@ -2,7 +2,7 @@ // RUN: %clang_cc1 -x ast -ast-print %t | FileCheck %s int f() { - // CHECK: for (int i = 0; x; i++) { + // CHECK: for (int i = 0; int x = i < 2 ? 1 : 0; i++) { for (int i = 0; int x = i < 2 ? 1 : 0; i++) { return x; } Index: clang/lib/AST/StmtPrinter.cpp === --- clang/lib/AST/StmtPrinter.cpp +++ clang/lib/AST/StmtPrinter.cpp @@ -400,7 +400,9 @@ PrintInitStmt(Node->getInit(), 5); else OS << (Node->getCond() ? "; " : ";"); - if (Node->getCond()) + if (const DeclStmt *DS = Node->getConditionVariableDeclStmt()) +PrintRawDeclStmt(DS); + else if (Node->getCond()) PrintExpr(Node->getCond()); OS << ";"; if (Node->getInc()) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D153699: [clang] Fix pretty-printing for variables declared in a for-loop condition
vaithak added a comment. Please commit this change for me as I don't have commit access. Thanks 👍 My details: "Vaibhav Thakkar" Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D153699/new/ https://reviews.llvm.org/D153699 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits