[PATCH] D26452: Make output of -ast-print a valid C++ code.
This revision was automatically updated to reflect the committed changes. Closed by commit rL286439: Make output of -ast-print a valid C++ code. (authored by sepavloff). Changed prior to commit: https://reviews.llvm.org/D26452?vs=77354=77452#toc Repository: rL LLVM https://reviews.llvm.org/D26452 Files: cfe/trunk/lib/AST/DeclPrinter.cpp cfe/trunk/test/Analysis/cfg.cpp cfe/trunk/test/Coverage/ast-print-func.cpp cfe/trunk/test/Coverage/ast-print-temp-class.cpp cfe/trunk/test/Coverage/ast-print-temp-func.cpp cfe/trunk/test/Coverage/ast-printing.cpp cfe/trunk/test/Index/comment-cplus-decls.cpp cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp cfe/trunk/test/Misc/ast-dump-templates.cpp cfe/trunk/test/OpenMP/atomic_ast_print.cpp cfe/trunk/test/OpenMP/barrier_ast_print.cpp cfe/trunk/test/OpenMP/critical_ast_print.cpp cfe/trunk/test/OpenMP/declare_reduction_ast_print.cpp cfe/trunk/test/OpenMP/declare_simd_ast_print.cpp cfe/trunk/test/OpenMP/declare_target_ast_print.cpp cfe/trunk/test/OpenMP/distribute_ast_print.cpp cfe/trunk/test/OpenMP/distribute_dist_schedule_ast_print.cpp cfe/trunk/test/OpenMP/distribute_parallel_for_ast_print.cpp cfe/trunk/test/OpenMP/distribute_parallel_for_simd_ast_print.cpp cfe/trunk/test/OpenMP/distribute_simd_ast_print.cpp cfe/trunk/test/OpenMP/flush_ast_print.cpp cfe/trunk/test/OpenMP/for_ast_print.cpp cfe/trunk/test/OpenMP/for_simd_ast_print.cpp cfe/trunk/test/OpenMP/ordered_ast_print.cpp cfe/trunk/test/OpenMP/parallel_ast_print.cpp cfe/trunk/test/OpenMP/parallel_for_ast_print.cpp cfe/trunk/test/OpenMP/parallel_for_simd_ast_print.cpp cfe/trunk/test/OpenMP/parallel_sections_ast_print.cpp cfe/trunk/test/OpenMP/sections_ast_print.cpp cfe/trunk/test/OpenMP/simd_ast_print.cpp cfe/trunk/test/OpenMP/single_ast_print.cpp cfe/trunk/test/OpenMP/target_ast_print.cpp cfe/trunk/test/OpenMP/target_data_ast_print.cpp cfe/trunk/test/OpenMP/target_data_use_device_ptr_ast_print.cpp cfe/trunk/test/OpenMP/target_enter_data_ast_print.cpp cfe/trunk/test/OpenMP/target_exit_data_ast_print.cpp cfe/trunk/test/OpenMP/target_is_device_ptr_ast_print.cpp cfe/trunk/test/OpenMP/target_parallel_ast_print.cpp cfe/trunk/test/OpenMP/target_parallel_for_ast_print.cpp cfe/trunk/test/OpenMP/target_parallel_for_simd_ast_print.cpp cfe/trunk/test/OpenMP/target_simd_ast_print.cpp cfe/trunk/test/OpenMP/target_update_ast_print.cpp cfe/trunk/test/OpenMP/task_ast_print.cpp cfe/trunk/test/OpenMP/taskloop_ast_print.cpp cfe/trunk/test/OpenMP/taskloop_simd_ast_print.cpp cfe/trunk/test/OpenMP/taskwait_ast_print.cpp cfe/trunk/test/OpenMP/taskyield_ast_print.cpp cfe/trunk/test/OpenMP/teams_ast_print.cpp cfe/trunk/test/OpenMP/teams_distribute_ast_print.cpp cfe/trunk/test/OpenMP/teams_distribute_simd_ast_print.cpp cfe/trunk/test/OpenMP/threadprivate_ast_print.cpp cfe/trunk/test/SemaTemplate/temp_arg_enum_printing.cpp cfe/trunk/unittests/AST/ASTTypeTraitsTest.cpp cfe/trunk/unittests/AST/DeclPrinterTest.cpp Index: cfe/trunk/lib/AST/DeclPrinter.cpp === --- cfe/trunk/lib/AST/DeclPrinter.cpp +++ cfe/trunk/lib/AST/DeclPrinter.cpp @@ -78,6 +78,10 @@ void VisitTemplateDecl(const TemplateDecl *D); void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); void VisitClassTemplateDecl(ClassTemplateDecl *D); +void VisitClassTemplateSpecializationDecl( +ClassTemplateSpecializationDecl *D); +void VisitClassTemplatePartialSpecializationDecl( + ClassTemplatePartialSpecializationDecl *D); void VisitObjCMethodDecl(ObjCMethodDecl *D); void VisitObjCImplementationDecl(ObjCImplementationDecl *D); void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); @@ -95,8 +99,9 @@ void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); -void PrintTemplateParameters(const TemplateParameterList *Params, - const TemplateArgumentList *Args = nullptr); +void printTemplateParameters(const TemplateParameterList *Params); +void printTemplateArguments(const TemplateArgumentList , +const TemplateParameterList *Params = nullptr); void prettyPrintAttributes(Decl *D); void prettyPrintPragmas(Decl *D); void printDeclType(QualType T, StringRef DeclName, bool Pack = false); @@ -290,6 +295,13 @@ if (D->isImplicit()) continue; +// Don't print implicit specializations, as they are printed when visiting +// corresponding templates. +if (auto FD = dyn_cast(*D)) + if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation && + !isa(DC)) +continue; + // The next bits of code handles stuff like "struct {int x;} a,b"; we're // forced to merge the declarations because there's
[PATCH] D26452: Make output of -ast-print a valid C++ code.
rsmith accepted this revision. rsmith added a reviewer: rsmith. rsmith added a comment. This revision is now accepted and ready to land. I've not looked at all of the test changes in detail, but this looks fine to me. https://reviews.llvm.org/D26452 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26452: Make output of -ast-print a valid C++ code.
sepavloff created this revision. sepavloff added reviewers: ABataev, gribozavr, rtrieu. sepavloff added a subscriber: cfe-commits. Output generated by option -ast-print looks like C/C++ code, and it really is for plain C. For C++ the produced output was not valid C++ code, but the differences were small. With this change the output is fixed and can be compiled. Tests are changed so that output produced by -ast-print is compiled again with the same flags and both outputs are compared. Option -ast-print is extensively used in clang tests but it itself was tested poorly, existing tests only checked that compiler did not crash. There are unit tests in file DeclPrinterTest.cpp, but they test only terse output mode. The change affects many test files but the changes are mostly mechanical. Two main reasons why the test files require update are: - change in form of template specialization output, - template now is printed before its specializations. https://reviews.llvm.org/D26452 Files: lib/AST/DeclPrinter.cpp test/Analysis/cfg.cpp test/Coverage/ast-print-func.cpp test/Coverage/ast-print-temp-class.cpp test/Coverage/ast-print-temp-func.cpp test/Coverage/ast-printing.cpp test/Index/comment-cplus-decls.cpp test/Index/comment-to-html-xml-conversion.cpp test/Misc/ast-dump-templates.cpp test/OpenMP/atomic_ast_print.cpp test/OpenMP/barrier_ast_print.cpp test/OpenMP/critical_ast_print.cpp test/OpenMP/declare_reduction_ast_print.cpp test/OpenMP/declare_simd_ast_print.cpp test/OpenMP/declare_target_ast_print.cpp test/OpenMP/distribute_ast_print.cpp test/OpenMP/distribute_dist_schedule_ast_print.cpp test/OpenMP/distribute_parallel_for_ast_print.cpp test/OpenMP/distribute_parallel_for_simd_ast_print.cpp test/OpenMP/distribute_simd_ast_print.cpp test/OpenMP/flush_ast_print.cpp test/OpenMP/for_ast_print.cpp test/OpenMP/for_simd_ast_print.cpp test/OpenMP/ordered_ast_print.cpp test/OpenMP/parallel_ast_print.cpp test/OpenMP/parallel_for_ast_print.cpp test/OpenMP/parallel_for_simd_ast_print.cpp test/OpenMP/parallel_sections_ast_print.cpp test/OpenMP/sections_ast_print.cpp test/OpenMP/simd_ast_print.cpp test/OpenMP/single_ast_print.cpp test/OpenMP/target_ast_print.cpp test/OpenMP/target_data_ast_print.cpp test/OpenMP/target_data_use_device_ptr_ast_print.cpp test/OpenMP/target_enter_data_ast_print.cpp test/OpenMP/target_exit_data_ast_print.cpp test/OpenMP/target_is_device_ptr_ast_print.cpp test/OpenMP/target_parallel_ast_print.cpp test/OpenMP/target_parallel_for_ast_print.cpp test/OpenMP/target_parallel_for_simd_ast_print.cpp test/OpenMP/target_simd_ast_print.cpp test/OpenMP/target_update_ast_print.cpp test/OpenMP/task_ast_print.cpp test/OpenMP/taskloop_ast_print.cpp test/OpenMP/taskloop_simd_ast_print.cpp test/OpenMP/taskwait_ast_print.cpp test/OpenMP/taskyield_ast_print.cpp test/OpenMP/teams_ast_print.cpp test/OpenMP/teams_distribute_ast_print.cpp test/OpenMP/teams_distribute_simd_ast_print.cpp test/OpenMP/threadprivate_ast_print.cpp test/SemaTemplate/temp_arg_enum_printing.cpp unittests/AST/ASTTypeTraitsTest.cpp unittests/AST/DeclPrinterTest.cpp Index: unittests/AST/DeclPrinterTest.cpp === --- unittests/AST/DeclPrinterTest.cpp +++ unittests/AST/DeclPrinterTest.cpp @@ -254,178 +254,157 @@ ASSERT_TRUE(PrintedDeclCXX98Matches( "class A { int a; };", "A", -"class A {\n}")); -// Should be: with semicolon, with { ... } +"class A {}")); } TEST(DeclPrinter, TestCXXRecordDecl2) { ASSERT_TRUE(PrintedDeclCXX98Matches( "struct A { int a; };", "A", -"struct A {\n}")); -// Should be: with semicolon, with { ... } +"struct A {}")); } TEST(DeclPrinter, TestCXXRecordDecl3) { ASSERT_TRUE(PrintedDeclCXX98Matches( "union A { int a; };", "A", -"union A {\n}")); -// Should be: with semicolon, with { ... } +"union A {}")); } TEST(DeclPrinter, TestCXXRecordDecl4) { ASSERT_TRUE(PrintedDeclCXX98Matches( "class Z { int a; };" "class A : Z { int b; };", "A", -"class A : Z {\n}")); -// Should be: with semicolon, with { ... } +"class A : Z {}")); } TEST(DeclPrinter, TestCXXRecordDecl5) { ASSERT_TRUE(PrintedDeclCXX98Matches( "struct Z { int a; };" "struct A : Z { int b; };", "A", -"struct A : Z {\n}")); -// Should be: with semicolon, with { ... } +"struct A : Z {}")); } TEST(DeclPrinter, TestCXXRecordDecl6) { ASSERT_TRUE(PrintedDeclCXX98Matches( "class Z { int a; };" "class A : public Z { int b; };", "A", -"class A : public Z {\n}")); -// Should be: with semicolon, with { ... } +"class A : public Z {}")); } TEST(DeclPrinter, TestCXXRecordDecl7) { ASSERT_TRUE(PrintedDeclCXX98Matches( "class Z { int a; };" "class A : protected Z { int b; };", "A", -"class A : protected Z