aaron.ballman created this revision. The AST dump functionality does not currently make use of a printing policy, so when dumping C++ code, you will see `_Bool`, `struct Foo` and other C-isms in the output. This patch adds a `PrintingPolicy` object to the AST dumper to get slightly improved output for the various language modes, and corrects the impacted test cases.
https://reviews.llvm.org/D40448 Files: include/clang/AST/Type.h lib/AST/ASTDumper.cpp lib/AST/TypePrinter.cpp lib/StaticAnalyzer/Checkers/PaddingChecker.cpp test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-examples.cpp test/Frontend/float16.cpp test/Misc/ast-dump-attr.cpp test/Misc/ast-dump-decl.cpp test/Misc/ast-dump-invalid.cpp test/OpenMP/dump.cpp test/Parser/objc-default-ctor-init.mm test/SemaCXX/compound-literal.cpp test/SemaCXX/sourceranges.cpp test/SemaCXX/warn-redundant-move.cpp test/SemaObjCXX/block-cleanup.mm test/SemaTemplate/default-expr-arguments-2.cpp test/SemaTemplate/default-expr-arguments-3.cpp
Index: test/SemaTemplate/default-expr-arguments-3.cpp =================================================================== --- test/SemaTemplate/default-expr-arguments-3.cpp +++ test/SemaTemplate/default-expr-arguments-3.cpp @@ -1,11 +1,11 @@ // RUN: %clang_cc1 -std=c++14 -verify -ast-dump %s | FileCheck %s // expected-no-diagnostics -// CHECK: FunctionDecl {{.*}} used func 'void (void)' +// CHECK: FunctionDecl {{.*}} used func 'void ()' // CHECK-NEXT: TemplateArgument type 'int' -// CHECK: LambdaExpr {{.*}} 'class (lambda at -// CHECK: ParmVarDecl {{.*}} used f 'enum foo' cinit -// CHECK-NEXT: DeclRefExpr {{.*}} 'enum foo' EnumConstant {{.*}} 'a' 'enum foo' +// CHECK: LambdaExpr {{.*}} '(lambda at +// CHECK: ParmVarDecl {{.*}} used f 'foo' cinit +// CHECK-NEXT: DeclRefExpr {{.*}} 'foo' EnumConstant {{.*}} 'a' 'foo' namespace PR28795 { template<typename T> @@ -22,9 +22,9 @@ // CHECK: ClassTemplateSpecializationDecl {{.*}} struct class2 definition // CHECK: TemplateArgument type 'int' -// CHECK: LambdaExpr {{.*}} 'class (lambda at -// CHECK: ParmVarDecl {{.*}} used f 'enum foo' cinit -// CHECK-NEXT: DeclRefExpr {{.*}} 'enum foo' EnumConstant {{.*}} 'a' 'enum foo' +// CHECK: LambdaExpr {{.*}} '(lambda at +// CHECK: ParmVarDecl {{.*}} used f 'foo' cinit +// CHECK-NEXT: DeclRefExpr {{.*}} 'foo' EnumConstant {{.*}} 'a' 'foo' // Template struct case: template <class T> struct class2 { @@ -38,11 +38,11 @@ // CHECK: FunctionTemplateDecl {{.*}} f1 // CHECK-NEXT: TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T -// CHECK-NEXT: FunctionDecl {{.*}} f1 'void (void)' -// CHECK: FunctionDecl {{.*}} f1 'void (void)' +// CHECK-NEXT: FunctionDecl {{.*}} f1 'void ()' +// CHECK: FunctionDecl {{.*}} f1 'void ()' // CHECK-NEXT: TemplateArgument type 'int' -// CHECK: ParmVarDecl {{.*}} n 'enum foo' cinit -// CHECK-NEXT: DeclRefExpr {{.*}} 'enum foo' EnumConstant {{.*}} 'a' 'enum foo' +// CHECK: ParmVarDecl {{.*}} n 'foo' cinit +// CHECK-NEXT: DeclRefExpr {{.*}} 'foo' EnumConstant {{.*}} 'a' 'foo' template<typename T> void f1() { Index: test/SemaTemplate/default-expr-arguments-2.cpp =================================================================== --- test/SemaTemplate/default-expr-arguments-2.cpp +++ test/SemaTemplate/default-expr-arguments-2.cpp @@ -9,8 +9,8 @@ public: enum { kSomeConst = 128 }; bar(int x = kSomeConst) {} }; - - // CHECK: FunctionDecl{{.*}}f 'void (void)' + + // CHECK: FunctionDecl{{.*}}f 'void ()' void f() { // CHECK: VarDecl{{.*}}tmp 'bar<int>' // CHECK: CXXDefaultArgExpr{{.*}}'int' Index: test/SemaObjCXX/block-cleanup.mm =================================================================== --- test/SemaObjCXX/block-cleanup.mm +++ test/SemaObjCXX/block-cleanup.mm @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -triple x86_64-apple-macosx10.11.0 -std=gnu++11 -o /dev/null -x objective-c++ -fblocks -ast-dump %s 2>&1 | FileCheck %s -// CHECK: -FunctionDecl {{.*}} test 'id (void)' +// CHECK: -FunctionDecl {{.*}} test 'id ()' // CHECK-NEXT: -CompoundStmt // CHECK-NEXT: -ReturnStmt // CHECK-NEXT: -ExprWithCleanups Index: test/SemaCXX/warn-redundant-move.cpp =================================================================== --- test/SemaCXX/warn-redundant-move.cpp +++ test/SemaCXX/warn-redundant-move.cpp @@ -75,7 +75,7 @@ return d; // Verify the implicit move from the AST dump // CHECK-AST: ReturnStmt{{.*}}line:[[@LINE-2]] - // CHECK-AST-NEXT: CXXConstructExpr{{.*}}struct D{{.*}}void (struct D &&) + // CHECK-AST-NEXT: CXXConstructExpr{{.*}}D{{.*}}void (D &&) // CHECK-AST-NEXT: ImplicitCastExpr // CHECK-AST-NEXT: DeclRefExpr{{.*}}ParmVar{{.*}}'d' Index: test/SemaCXX/sourceranges.cpp =================================================================== --- test/SemaCXX/sourceranges.cpp +++ test/SemaCXX/sourceranges.cpp @@ -46,7 +46,7 @@ void construct() { using namespace foo; A a = A(12); - // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'class foo::A' 'void (int){{( __attribute__\(\(thiscall\)\))?}}' + // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'foo::A' 'void (int){{( __attribute__\(\(thiscall\)\))?}}' D d = D(12); - // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'struct D' 'void (int){{( __attribute__\(\(thiscall\)\))?}}' + // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'D' 'void (int){{( __attribute__\(\(thiscall\)\))?}}' } Index: test/SemaCXX/compound-literal.cpp =================================================================== --- test/SemaCXX/compound-literal.cpp +++ test/SemaCXX/compound-literal.cpp @@ -36,31 +36,31 @@ void test() { (void)(POD){1, 2}; - // CHECK-NOT: CXXBindTemporaryExpr {{.*}} 'struct brace_initializers::POD' - // CHECK: CompoundLiteralExpr {{.*}} 'struct brace_initializers::POD' - // CHECK-NEXT: InitListExpr {{.*}} 'struct brace_initializers::POD' + // CHECK-NOT: CXXBindTemporaryExpr {{.*}} 'brace_initializers::POD' + // CHECK: CompoundLiteralExpr {{.*}} 'brace_initializers::POD' + // CHECK-NEXT: InitListExpr {{.*}} 'brace_initializers::POD' // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}} // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}} (void)(HasDtor){1, 2}; - // CHECK: CXXBindTemporaryExpr {{.*}} 'struct brace_initializers::HasDtor' - // CHECK-NEXT: CompoundLiteralExpr {{.*}} 'struct brace_initializers::HasDtor' - // CHECK-NEXT: InitListExpr {{.*}} 'struct brace_initializers::HasDtor' + // CHECK: CXXBindTemporaryExpr {{.*}} 'brace_initializers::HasDtor' + // CHECK-NEXT: CompoundLiteralExpr {{.*}} 'brace_initializers::HasDtor' + // CHECK-NEXT: InitListExpr {{.*}} 'brace_initializers::HasDtor' // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}} // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}} #if __cplusplus >= 201103L (void)(HasCtor){1, 2}; - // CHECK-CXX11-NOT: CXXBindTemporaryExpr {{.*}} 'struct brace_initializers::HasCtor' - // CHECK-CXX11: CompoundLiteralExpr {{.*}} 'struct brace_initializers::HasCtor' - // CHECK-CXX11-NEXT: CXXTemporaryObjectExpr {{.*}} 'struct brace_initializers::HasCtor' + // CHECK-CXX11-NOT: CXXBindTemporaryExpr {{.*}} 'brace_initializers::HasCtor' + // CHECK-CXX11: CompoundLiteralExpr {{.*}} 'brace_initializers::HasCtor' + // CHECK-CXX11-NEXT: CXXTemporaryObjectExpr {{.*}} 'brace_initializers::HasCtor' // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 1{{$}} // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 2{{$}} (void)(HasCtorDtor){1, 2}; - // CHECK-CXX11: CXXBindTemporaryExpr {{.*}} 'struct brace_initializers::HasCtorDtor' - // CHECK-CXX11-NEXT: CompoundLiteralExpr {{.*}} 'struct brace_initializers::HasCtorDtor' - // CHECK-CXX11-NEXT: CXXTemporaryObjectExpr {{.*}} 'struct brace_initializers::HasCtorDtor' + // CHECK-CXX11: CXXBindTemporaryExpr {{.*}} 'brace_initializers::HasCtorDtor' + // CHECK-CXX11-NEXT: CompoundLiteralExpr {{.*}} 'brace_initializers::HasCtorDtor' + // CHECK-CXX11-NEXT: CXXTemporaryObjectExpr {{.*}} 'brace_initializers::HasCtorDtor' // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 1{{$}} // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 2{{$}} #endif Index: test/Parser/objc-default-ctor-init.mm =================================================================== --- test/Parser/objc-default-ctor-init.mm +++ test/Parser/objc-default-ctor-init.mm @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -std=c++11 -ast-dump %s | FileCheck %s // CHECK: CXXCtorInitializer Field {{.*}} 'ptr' 'void *' -// CHECK: CXXCtorInitializer Field {{.*}} 'q' 'struct Q' +// CHECK: CXXCtorInitializer Field {{.*}} 'q' 'Q' @interface NSObject @end Index: test/OpenMP/dump.cpp =================================================================== --- test/OpenMP/dump.cpp +++ test/OpenMP/dump.cpp @@ -48,7 +48,7 @@ // CHECK-NEXT: | | `-DeclRefExpr {{.+}} <col:48> 'int' lvalue OMPCapturedExpr {{.+}} 'a' 'int &' // CHECK-NEXT: | |-OMPSharedClause {{.+}} <col:51, col:61> // CHECK-NEXT: | | `-MemberExpr {{.+}} <col:58> 'int' lvalue ->b -// CHECK-NEXT: | | `-CXXThisExpr {{.+}} <col:58> 'struct S *' this +// CHECK-NEXT: | | `-CXXThisExpr {{.+}} <col:58> 'S *' this // CHECK-NEXT: | |-OMPScheduleClause {{.+}} <col:61, col:79> // CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} <col:78> 'int' <LValueToRValue> // CHECK-NEXT: | | `-DeclRefExpr {{.+}} <col:78> 'int' lvalue OMPCapturedExpr {{.+}} '.capture_expr.' 'int' @@ -62,7 +62,7 @@ #pragma omp declare simd inbranch void foo(); -// CHECK: `-FunctionDecl {{.+}} <line:63:1, col:10> col:6 foo 'void (void)' +// CHECK: `-FunctionDecl {{.+}} <line:63:1, col:10> col:6 foo 'void ()' // CHECK-NEXT: |-OMPDeclareSimdDeclAttr {{.+}} <line:62:9, col:34> Implicit BS_Inbranch // CHECK: `-OMPDeclareSimdDeclAttr {{.+}} <line:61:9, col:25> Implicit BS_Undefined Index: test/Misc/ast-dump-invalid.cpp =================================================================== --- test/Misc/ast-dump-invalid.cpp +++ test/Misc/ast-dump-invalid.cpp @@ -35,7 +35,7 @@ // CHECK-NEXT: `-IfStmt {{.*}} <line:25:3, line:28:12> // CHECK-NEXT: |-<<<NULL>>> // CHECK-NEXT: |-<<<NULL>>> -// CHECK-NEXT: |-OpaqueValueExpr {{.*}} <<invalid sloc>> '_Bool' +// CHECK-NEXT: |-OpaqueValueExpr {{.*}} <<invalid sloc>> 'bool' // CHECK-NEXT: |-ReturnStmt {{.*}} <line:26:5, col:12> // CHECK-NEXT: | `-IntegerLiteral {{.*}} <col:12> 'int' 4 // CHECK-NEXT: `-ReturnStmt {{.*}} <line:28:5, col:12> Index: test/Misc/ast-dump-decl.cpp =================================================================== --- test/Misc/ast-dump-decl.cpp +++ test/Misc/ast-dump-decl.cpp @@ -20,7 +20,7 @@ return TestVarDeclNRVO; } } -// CHECK: VarDecl{{.*}} TestVarDeclNRVO 'class testVarDeclNRVO::A' nrvo +// CHECK: VarDecl{{.*}} TestVarDeclNRVO 'testVarDeclNRVO::A' nrvo void testParmVarDeclInit(int TestParmVarDeclInit = 0); // CHECK: ParmVarDecl{{.*}} TestParmVarDeclInit 'int' @@ -97,8 +97,8 @@ // CHECK-NEXT: CopyAssignment non_trivial has_const_param // CHECK-NEXT: MoveAssignment exists simple non_trivial // CHECK-NEXT: Destructor simple irrelevant trivial -// CHECK-NEXT: virtual private 'class testCXXRecordDecl::A' -// CHECK-NEXT: public 'class testCXXRecordDecl::B' +// CHECK-NEXT: virtual private 'testCXXRecordDecl::A' +// CHECK-NEXT: public 'testCXXRecordDecl::B' // CHECK-NEXT: CXXRecordDecl{{.*}} class TestCXXRecordDecl // CHECK-NEXT: FieldDecl @@ -118,10 +118,10 @@ void TestCXXMethodDeclThrow() throw(); void TestCXXMethodDeclThrowType() throw(int); }; -// CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclPure 'void (void)' virtual pure -// CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclDelete 'void (void)' delete -// CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclThrow 'void (void) throw()' -// CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclThrowType 'void (void) throw(int)' +// CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclPure 'void ()' virtual pure +// CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclDelete 'void ()' delete +// CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclThrow 'void () throw()' +// CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclThrowType 'void () throw(int)' namespace testCXXConstructorDecl { class A { }; @@ -147,7 +147,7 @@ class TestCXXDestructorDecl { ~TestCXXDestructorDecl() { } }; -// CHECK: CXXDestructorDecl{{.*}} ~TestCXXDestructorDecl 'void (void) noexcept' +// CHECK: CXXDestructorDecl{{.*}} ~TestCXXDestructorDecl 'void () noexcept' // CHECK-NEXT: CompoundStmt // Test that the range of a defaulted members is computed correctly. @@ -177,7 +177,7 @@ class TestCXXConversionDecl { operator int() { return 0; } }; -// CHECK: CXXConversionDecl{{.*}} operator int 'int (void)' +// CHECK: CXXConversionDecl{{.*}} operator int 'int ()' // CHECK-NEXT: CompoundStmt namespace TestStaticAssertDecl { @@ -499,7 +499,7 @@ // CHECK: CXXRecord{{.*}} TestFriendDecl // CHECK-NEXT: FriendDecl // CHECK-NEXT: FunctionDecl{{.*}} foo -// CHECK-NEXT: FriendDecl{{.*}} 'class A':'class A' +// CHECK-NEXT: FriendDecl{{.*}} 'class A':'A' // CHECK-NEXT: FriendDecl{{.*}} 'T' namespace TestFileScopeAsmDecl { @@ -516,11 +516,11 @@ }; } // CHECK: NamespaceDecl [[TestFriendDecl2:0x.*]] <{{.*}}> {{.*}} TestFriendDecl2 -// CHECK: |-FunctionDecl [[TestFriendDecl2_f:0x.*]] <{{.*}}> {{.*}} f 'void (void)' +// CHECK: |-FunctionDecl [[TestFriendDecl2_f:0x.*]] <{{.*}}> {{.*}} f 'void ()' // CHECK: `-CXXRecordDecl {{.*}} struct S // CHECK: |-CXXRecordDecl {{.*}} struct S // CHECK: `-FriendDecl -// CHECK: `-FunctionDecl {{.*}} parent [[TestFriendDecl2]] prev [[TestFriendDecl2_f]] <{{.*}}> {{.*}} f 'void (void)' +// CHECK: `-FunctionDecl {{.*}} parent [[TestFriendDecl2]] prev [[TestFriendDecl2_f]] <{{.*}}> {{.*}} f 'void ()' namespace Comment { extern int Test; Index: test/Misc/ast-dump-attr.cpp =================================================================== --- test/Misc/ast-dump-attr.cpp +++ test/Misc/ast-dump-attr.cpp @@ -123,7 +123,7 @@ void func() { auto Test = []() __attribute__((no_thread_safety_analysis)) {}; - // CHECK: CXXMethodDecl{{.*}}operator() 'void (void) const' + // CHECK: CXXMethodDecl{{.*}}operator() 'void () const' // CHECK: NoThreadSafetyAnalysisAttr // Because GNU's noreturn applies to the function type, and this lambda does @@ -131,7 +131,7 @@ // conversion should both be noreturn, but the method should not contain a // NoReturnAttr because the attribute applied to the type. auto Test2 = []() __attribute__((noreturn)) { while(1); }; - // CHECK: CXXMethodDecl{{.*}}operator() 'void (void) __attribute__((noreturn)) const' + // CHECK: CXXMethodDecl{{.*}}operator() 'void () __attribute__((noreturn)) const' // CHECK-NOT: NoReturnAttr // CHECK: CXXConversionDecl{{.*}}operator void (*)() __attribute__((noreturn)) } Index: test/Frontend/float16.cpp =================================================================== --- test/Frontend/float16.cpp +++ test/Frontend/float16.cpp @@ -132,7 +132,7 @@ //CHECK-NEXT: | | `-BinaryOperator {{.*}} '_Float16' '+' //CHECK-NEXT: | | |-ImplicitCastExpr {{.*}} '_Float16' <LValueToRValue> //CHECK-NEXT: | | | `-MemberExpr {{.*}} '_Float16' lvalue ->f1c 0x{{.*}} -//CHECK-NEXT: | | | `-CXXThisExpr {{.*}} 'class C1 *' this +//CHECK-NEXT: | | | `-CXXThisExpr {{.*}} 'C1 *' this //CHECK-NEXT: | | `-ImplicitCastExpr {{.*}} '_Float16' <LValueToRValue> //CHECK-NEXT: | | `-DeclRefExpr {{.*}} '_Float16' lvalue ParmVar 0x{{.*}} 'arg' '_Float16' //CHECK-NEXT: | |-CXXMethodDecl {{.*}} used func2c '_Float16 (_Float16)' static @@ -208,14 +208,14 @@ //CHECK-NEXT: | `-FloatingLiteral {{.*}} 'double' 1.000977e+00 C1 c1(f1l); -//CHECK: | `-VarDecl{{.*}} used c1 'class C1' callinit -//CHECK-NEXT: | `-CXXConstructExpr {{.*}} 'class C1' 'void (_Float16) +//CHECK: | `-VarDecl{{.*}} used c1 'C1' callinit +//CHECK-NEXT: | `-CXXConstructExpr {{.*}} 'C1' 'void (_Float16) //CHECK-NEXT: | `-ImplicitCastExpr {{.*}} '_Float16' <LValueToRValue> //CHECK-NEXT: | `-DeclRefExpr {{.*}} '_Float16' lvalue Var 0x{{.*}} 'f1l' '_Float16' S1<_Float16> s1 = { 132.f16 }; -//CHECK: | `-VarDecl {{.*}} used s1 'S1<_Float16>':'struct S1<_Float16>' cinit -//CHECK-NEXT: | `-InitListExpr {{.*}} 'S1<_Float16>':'struct S1<_Float16>' +//CHECK: | `-VarDecl {{.*}} used s1 'S1<_Float16>':'S1<_Float16>' cinit +//CHECK-NEXT: | `-InitListExpr {{.*}} 'S1<_Float16>':'S1<_Float16>' //CHECK-NEXT: | `-FloatingLiteral {{.*}} '_Float16' 1.320000e+02 _Float16 f4l = func1n(f1l) + func1f(f2l) + c1.func1c(f3l) + c1.func2c(f1l) + @@ -240,13 +240,13 @@ //CHECK-NEXT: | | | | | | | `-DeclRefExpr {{.*}} '_Float16' lvalue Var {{.*}} 'f2l' '_Float16' //CHECK-NEXT: | | | | | | `-CXXMemberCallExpr {{.*}} '_Float16' //CHECK-NEXT: | | | | | | |-MemberExpr {{.*}} '<bound member function type>' .func1c {{.*}} -//CHECK-NEXT: | | | | | | | `-DeclRefExpr {{.*}} 'class C1' lvalue Var {{.*}} 'c1' 'class C1' +//CHECK-NEXT: | | | | | | | `-DeclRefExpr {{.*}} 'C1' lvalue Var {{.*}} 'c1' 'C1' //CHECK-NEXT: | | | | | | `-ImplicitCastExpr {{.*}} '_Float16' <LValueToRValue> //CHECK-NEXT: | | | | | | `-DeclRefExpr {{.*}} '_Float16' lvalue Var {{.*}} 'f3l' '_Float16' //CHECK-NEXT: | | | | | `-CallExpr {{.*}} '_Float16' //CHECK-NEXT: | | | | | |-ImplicitCastExpr {{.*}} '_Float16 (*)(_Float16)' <FunctionToPointerDecay> //CHECK-NEXT: | | | | | | `-MemberExpr {{.*}} '_Float16 (_Float16)' lvalue .func2c {{.*}} -//CHECK-NEXT: | | | | | | `-DeclRefExpr {{.*}} 'class C1' lvalue Var {{.*}} 'c1' 'class C1' +//CHECK-NEXT: | | | | | | `-DeclRefExpr {{.*}} 'C1' lvalue Var {{.*}} 'c1' 'C1' //CHECK-NEXT: | | | | | `-ImplicitCastExpr {{.*}} '_Float16' <LValueToRValue> //CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} '_Float16' lvalue Var {{.*}} 'f1l' '_Float16' //CHECK-NEXT: | | | | `-CallExpr {{.*}} '_Float16':'_Float16' @@ -256,7 +256,7 @@ //CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} '_Float16' lvalue Var {{.*}} 'f1l' '_Float16' //CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} '_Float16' <LValueToRValue> //CHECK-NEXT: | | | `-MemberExpr {{.*}} '_Float16' lvalue .mem2 {{.*}} -//CHECK-NEXT: | | | `-DeclRefExpr {{.*}} 'S1<_Float16>':'struct S1<_Float16>' lvalue Var {{.*}} 's1' 'S1<_Float16>':'struct S1<_Float16>' +//CHECK-NEXT: | | | `-DeclRefExpr {{.*}} 'S1<_Float16>':'S1<_Float16>' lvalue Var {{.*}} 's1' 'S1<_Float16>':'S1<_Float16>' //CHECK-NEXT: | | `-ImplicitCastExpr {{.*}} '_Float16' <LValueToRValue> //CHECK-NEXT: | | `-DeclRefExpr {{.*}} '_Float16' lvalue Var {{.*}} 'f1n' '_Float16' //CHECK-NEXT: | `-ImplicitCastExpr {{.*}} '_Float16' <LValueToRValue> Index: test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-examples.cpp =================================================================== --- test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-examples.cpp +++ test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-examples.cpp @@ -16,13 +16,13 @@ // CHECK-LABEL: example1 void example1() { - // CHECK: VarDecl{{.*}}ra 'struct A &' - // CHECK: ImplicitCastExpr{{.*}}'struct A' lvalue <DerivedToBase (A)> + // CHECK: VarDecl{{.*}}ra 'A &' + // CHECK: ImplicitCastExpr{{.*}}'A' lvalue <DerivedToBase (A)> A &ra = b; - // CHECK: VarDecl{{.*}}rca 'const struct A &' - // CHECK: ImplicitCastExpr{{.*}}'const struct A' lvalue <DerivedToBase (A)> + // CHECK: VarDecl{{.*}}rca 'const A &' + // CHECK: ImplicitCastExpr{{.*}}'const A' lvalue <DerivedToBase (A)> // CHECK-NOT: MaterializeTemporaryExpr - // CHECK: ImplicitCastExpr{{.*}}'const struct B' lvalue <NoOp> + // CHECK: ImplicitCastExpr{{.*}}'const B' lvalue <NoOp> const A& rca = b; } @@ -34,17 +34,17 @@ // CHECK-LABEL: example2 void example2() { - // CHECK: VarDecl{{.*}}rca 'const struct A &' - // CHECK: ImplicitCastExpr{{.*}}'const struct A' lvalue <DerivedToBase (A)> - // CHECK: MaterializeTemporaryExpr{{.*}}'const struct B' - // CHECK: ImplicitCastExpr{{.*}}'const struct B' <NoOp> + // CHECK: VarDecl{{.*}}rca 'const A &' + // CHECK: ImplicitCastExpr{{.*}}'const A' lvalue <DerivedToBase (A)> + // CHECK: MaterializeTemporaryExpr{{.*}}'const B' + // CHECK: ImplicitCastExpr{{.*}}'const B' <NoOp> // CHECK: CallExpr{{.*}}B - const A &rca = f(); - // CHECK: VarDecl{{.*}}r 'const struct A &' - // CHECK: ImplicitCastExpr{{.*}}'const struct A' lvalue <DerivedToBase (A)> - // CHECK: MaterializeTemporaryExpr{{.*}}'const struct B' - // CHECK: ImplicitCastExpr{{.*}}'const struct B' <NoOp> - // CHECK: CXXMemberCallExpr{{.*}}'struct B' + const A &rca = f(); + // CHECK: VarDecl{{.*}}r 'const A &' + // CHECK: ImplicitCastExpr{{.*}}'const A' lvalue <DerivedToBase (A)> + // CHECK: MaterializeTemporaryExpr{{.*}}'const B' + // CHECK: ImplicitCastExpr{{.*}}'const B' <NoOp> + // CHECK: CXXMemberCallExpr{{.*}}'B' const A& r = x; } @@ -52,5 +52,5 @@ void example3() { // CHECK: VarDecl{{.*}}rcd2 'const double &' // CHECK: ImplicitCastExpr{{.*}} <IntegralToFloating> - const double& rcd2 = 2; + const double& rcd2 = 2; } Index: lib/StaticAnalyzer/Checkers/PaddingChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/PaddingChecker.cpp +++ lib/StaticAnalyzer/Checkers/PaddingChecker.cpp @@ -293,7 +293,9 @@ SmallString<100> Buf; llvm::raw_svector_ostream Os(Buf); Os << "Excessive padding in '"; - Os << QualType::getAsString(RD->getTypeForDecl(), Qualifiers()) << "'"; + Os << QualType::getAsString(RD->getTypeForDecl(), Qualifiers(), + LangOptions()) + << "'"; if (auto *TSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) { // TODO: make this show up better in the console output and in Index: lib/AST/TypePrinter.cpp =================================================================== --- lib/AST/TypePrinter.cpp +++ lib/AST/TypePrinter.cpp @@ -1746,6 +1746,10 @@ OS << ' '; } +std::string QualType::getAsString() const { + return getAsString(split(), LangOptions()); +} + std::string QualType::getAsString(const PrintingPolicy &Policy) const { std::string S; getAsStringInternal(S, Policy); @@ -1752,10 +1756,10 @@ return S; } -std::string QualType::getAsString(const Type *ty, Qualifiers qs) { +std::string QualType::getAsString(const Type *ty, Qualifiers qs, + const PrintingPolicy &Policy) { std::string buffer; - LangOptions options; - getAsStringInternal(ty, qs, buffer, PrintingPolicy(options)); + getAsStringInternal(ty, qs, buffer, Policy); return buffer; } Index: lib/AST/ASTDumper.cpp =================================================================== --- lib/AST/ASTDumper.cpp +++ lib/AST/ASTDumper.cpp @@ -99,6 +99,9 @@ const CommandTraits *Traits; const SourceManager *SM; + /// The policy to use for printing; can be defaulted. + PrintingPolicy PrintPolicy; + /// Pending[i] is an action to dump an entity at level i. llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending; @@ -207,12 +210,20 @@ public: ASTDumper(raw_ostream &OS, const CommandTraits *Traits, const SourceManager *SM) - : OS(OS), Traits(Traits), SM(SM), - ShowColors(SM && SM->getDiagnostics().getShowColors()) { } - + : ASTDumper(OS, Traits, SM, + SM && SM->getDiagnostics().getShowColors()) {} ASTDumper(raw_ostream &OS, const CommandTraits *Traits, const SourceManager *SM, bool ShowColors) - : OS(OS), Traits(Traits), SM(SM), ShowColors(ShowColors) {} + : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {} + //ASTDumper(raw_ostream &OS, const CommandTraits *Traits, + // const SourceManager *SM, const PrintingPolicy &PrintPolicy) + // : ASTDumper(OS, Traits, SM, SM && SM->getDiagnostics().getShowColors(), + // PrintPolicy) {} + ASTDumper(raw_ostream &OS, const CommandTraits *Traits, + const SourceManager *SM, bool ShowColors, + const PrintingPolicy &PrintPolicy) + : OS(OS), Traits(Traits), SM(SM), ShowColors(ShowColors), + PrintPolicy(PrintPolicy) {} void setDeserialize(bool D) { Deserialize = D; } @@ -646,13 +657,13 @@ ColorScope Color(*this, TypeColor); SplitQualType T_split = T.split(); - OS << "'" << QualType::getAsString(T_split) << "'"; + OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'"; if (Desugar && !T.isNull()) { // If the type is sugared, also dump a (shallow) desugared type. SplitQualType D_split = T.getSplitDesugaredType(); if (T_split != D_split) - OS << ":'" << QualType::getAsString(D_split) << "'"; + OS << ":'" << QualType::getAsString(D_split, PrintPolicy) << "'"; } } @@ -1187,12 +1198,12 @@ if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) { if (MD->size_overridden_methods() != 0) { - auto dumpOverride = - [=](const CXXMethodDecl *D) { - SplitQualType T_split = D->getType().split(); - OS << D << " " << D->getParent()->getName() << "::" - << D->getNameAsString() << " '" << QualType::getAsString(T_split) << "'"; - }; + auto dumpOverride = [=](const CXXMethodDecl *D) { + SplitQualType T_split = D->getType().split(); + OS << D << " " << D->getParent()->getName() + << "::" << D->getNameAsString() << " '" + << QualType::getAsString(T_split, PrintPolicy) << "'"; + }; dumpChild([=] { auto FirstOverrideItr = MD->begin_overridden_methods(); @@ -2683,15 +2694,18 @@ LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); } LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const { - ASTDumper P(OS, &getASTContext().getCommentCommandTraits(), - &getASTContext().getSourceManager()); + const ASTContext &Ctx = getASTContext(); + ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(), + false, Ctx.getPrintingPolicy()); P.setDeserialize(Deserialize); P.dumpDecl(this); } LLVM_DUMP_METHOD void Decl::dumpColor() const { - ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(), - &getASTContext().getSourceManager(), /*ShowColors*/true); + const ASTContext &Ctx = getASTContext(); + ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(), + &Ctx.getSourceManager(), /*ShowColors*/ true, + Ctx.getPrintingPolicy()); P.dumpDecl(this); } @@ -2706,7 +2720,8 @@ while (!DC->isTranslationUnit()) DC = DC->getParent(); ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext(); - ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager()); + ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(), + false, Ctx.getPrintingPolicy()); P.setDeserialize(Deserialize); P.dumpLookups(this, DumpDecls); } Index: include/clang/AST/Type.h =================================================================== --- include/clang/AST/Type.h +++ include/clang/AST/Type.h @@ -980,16 +980,14 @@ return LHS.Value != RHS.Value; } - std::string getAsString() const { - return getAsString(split()); + static std::string getAsString(SplitQualType split, + const PrintingPolicy &Policy) { + return getAsString(split.Ty, split.Quals, Policy); } + static std::string getAsString(const Type *ty, Qualifiers qs, + const PrintingPolicy &Policy); - static std::string getAsString(SplitQualType split) { - return getAsString(split.Ty, split.Quals); - } - - static std::string getAsString(const Type *ty, Qualifiers qs); - + std::string getAsString() const; std::string getAsString(const PrintingPolicy &Policy) const; void print(raw_ostream &OS, const PrintingPolicy &Policy,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits