Skip to content

Commit

Permalink
Modify TypePrinter to differentiate between anonymous struct and unna…
Browse files Browse the repository at this point in the history
…med struct

Currently TypePrinter lumps anonymous classes and unnamed classes in one group "anonymous" this is not correct and can be confusing in some contexts.

Differential Revision: https://reviews.llvm.org/D96807
  • Loading branch information
shafik committed Feb 22, 2021
1 parent f0e6927 commit 50542d5
Show file tree
Hide file tree
Showing 63 changed files with 698 additions and 696 deletions.
8 changes: 4 additions & 4 deletions clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
Expand Up @@ -530,7 +530,7 @@ TEST(DocumentSymbols, Unnamed) {
WithDetail("int"), Children()))),
AllOf(WithName("UnnamedStruct"),
WithKind(SymbolKind::Variable),
WithDetail("struct (anonymous)"), Children())));
WithDetail("struct (unnamed)"), Children())));
}

TEST(DocumentSymbols, InHeaderFile) {
Expand Down Expand Up @@ -650,16 +650,16 @@ TEST(DocumentSymbols, Enums) {
EXPECT_THAT(
getSymbols(TU.build()),
ElementsAre(
AllOf(WithName("(anonymous enum)"), WithDetail("enum"),
Children(AllOf(WithName("Red"), WithDetail("(anonymous)")))),
AllOf(WithName("(anonymous enum)"), WithDetail("enum"),
Children(AllOf(WithName("Red"), WithDetail("(unnamed)")))),
AllOf(WithName("Color"), WithDetail("enum"),
Children(AllOf(WithName("Green"), WithDetail("Color")))),
AllOf(WithName("Color2"), WithDetail("enum"),
Children(AllOf(WithName("Yellow"), WithDetail("Color2")))),
AllOf(WithName("ns"),
Children(AllOf(WithName("(anonymous enum)"), WithDetail("enum"),
Children(AllOf(WithName("Black"),
WithDetail("(anonymous)"))))))));
WithDetail("(unnamed)"))))))));
}

TEST(DocumentSymbols, FromMacro) {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/unittests/HoverTests.cpp
Expand Up @@ -1449,7 +1449,7 @@ TEST(Hover, All) {
HI.NamespaceScope = "";
// FIXME: This should be `(anon enum)::`
HI.LocalScope = "";
HI.Type = "enum (anonymous)";
HI.Type = "enum (unnamed)";
HI.Definition = "ONE";
HI.Value = "0";
}},
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/AST/TypePrinter.cpp
Expand Up @@ -1304,8 +1304,10 @@ void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
if (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda()) {
OS << "lambda";
HasKindDecoration = true;
} else {
} else if ((isa<RecordDecl>(D) && cast<RecordDecl>(D)->isAnonymousStructOrUnion())) {
OS << "anonymous";
} else {
OS << "unnamed";
}

if (Policy.AnonymousTagLocations) {
Expand Down
14 changes: 7 additions & 7 deletions clang/test/AST/ast-dump-decl-json.c
Expand Up @@ -576,8 +576,8 @@ void testParmVarDecl(int TestParmVarDecl);
// CHECK-NEXT: },
// CHECK-NEXT: "name": "e",
// CHECK-NEXT: "type": {
// CHECK-NEXT: "desugaredQualType": "enum TestEnumDeclAnon::(anonymous at {{.*}}:31:3)",
// CHECK-NEXT: "qualType": "enum (anonymous enum at {{.*}}:31:3)"
// CHECK-NEXT: "desugaredQualType": "enum TestEnumDeclAnon::(unnamed at {{.*}}:31:3)",
// CHECK-NEXT: "qualType": "enum (unnamed enum at {{.*}}:31:3)"
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ]
Expand Down Expand Up @@ -764,8 +764,8 @@ void testParmVarDecl(int TestParmVarDecl);
// CHECK-NEXT: },
// CHECK-NEXT: "name": "testRecordDeclAnon1",
// CHECK-NEXT: "type": {
// CHECK-NEXT: "desugaredQualType": "struct TestRecordDeclAnon1::(anonymous at {{.*}}:46:3)",
// CHECK-NEXT: "qualType": "struct (anonymous struct at {{.*}}:46:3)"
// CHECK-NEXT: "desugaredQualType": "struct TestRecordDeclAnon1::(unnamed at {{.*}}:46:3)",
// CHECK-NEXT: "qualType": "struct (unnamed struct at {{.*}}:46:3)"
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ]
Expand Down Expand Up @@ -1133,7 +1133,7 @@ void testParmVarDecl(int TestParmVarDecl);
// CHECK-NEXT: "name": "TestFunctionDecl",
// CHECK-NEXT: "mangledName": "TestFunctionDecl",
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "int (int, enum (anonymous enum at {{.*}}:69:29))"
// CHECK-NEXT: "qualType": "int (int, enum (unnamed enum at {{.*}}:69:29))"
// CHECK-NEXT: },
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
Expand Down Expand Up @@ -1187,8 +1187,8 @@ void testParmVarDecl(int TestParmVarDecl);
// CHECK-NEXT: "name": "y",
// CHECK-NEXT: "mangledName": "y",
// CHECK-NEXT: "type": {
// CHECK-NEXT: "desugaredQualType": "enum (anonymous at {{.*}}:69:29)",
// CHECK-NEXT: "qualType": "enum (anonymous enum at {{.*}}:69:29)"
// CHECK-NEXT: "desugaredQualType": "enum (unnamed at {{.*}}:69:29)",
// CHECK-NEXT: "qualType": "enum (unnamed enum at {{.*}}:69:29)"
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: {
Expand Down
4 changes: 2 additions & 2 deletions clang/test/AST/ast-dump-enum-json.cpp
Expand Up @@ -79,7 +79,7 @@ enum class I : int {
// CHECK-NEXT: },
// CHECK-NEXT: "name": "One",
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "(anonymous enum at {{.*}}:3:1)"
// CHECK-NEXT: "qualType": "(unnamed enum at {{.*}}:3:1)"
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: {
Expand All @@ -105,7 +105,7 @@ enum class I : int {
// CHECK-NEXT: },
// CHECK-NEXT: "name": "Two",
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "(anonymous enum at {{.*}}:3:1)"
// CHECK-NEXT: "qualType": "(unnamed enum at {{.*}}:3:1)"
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ]
Expand Down
2 changes: 1 addition & 1 deletion clang/test/AST/ast-dump-openmp-cancel.c
Expand Up @@ -17,4 +17,4 @@ void test() {
// CHECK-NEXT: | `-OMPCancelDirective {{.*}} <line:6:1, col:28> openmp_standalone_directive
// CHECK-NEXT: |-ImplicitParamDecl {{.*}} <line:4:1> col:1 implicit .global_tid. 'const int *const restrict'
// CHECK-NEXT: |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: `-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-cancel.c:4:1) *const restrict'
// CHECK-NEXT: `-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-cancel.c:4:1) *const restrict'
2 changes: 1 addition & 1 deletion clang/test/AST/ast-dump-openmp-cancellation-point.c
Expand Up @@ -17,4 +17,4 @@ void test() {
// CHECK-NEXT: | `-OMPCancellationPointDirective {{.*}} <line:6:1, col:40> openmp_standalone_directive
// CHECK-NEXT: |-ImplicitParamDecl {{.*}} <line:4:1> col:1 implicit .global_tid. 'const int *const restrict'
// CHECK-NEXT: |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: `-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-cancellation-point.c:4:1) *const restrict'
// CHECK-NEXT: `-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-cancellation-point.c:4:1) *const restrict'
10 changes: 5 additions & 5 deletions clang/test/AST/ast-dump-openmp-distribute-parallel-for-simd.c
Expand Up @@ -59,7 +59,7 @@ void test_five(int x, int y, int z) {
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.lb. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.ub. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-distribute-parallel-for-simd.c:4:1) *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-distribute-parallel-for-simd.c:4:1) *const restrict'
// CHECK-NEXT: | | `-VarDecl {{.*}} <line:5:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue ParmVar {{.*}} 'x' 'int'
Expand Down Expand Up @@ -99,7 +99,7 @@ void test_five(int x, int y, int z) {
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.lb. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.ub. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-distribute-parallel-for-simd.c:10:1) *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-distribute-parallel-for-simd.c:10:1) *const restrict'
// CHECK-NEXT: | | |-VarDecl {{.*}} <line:11:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | `-VarDecl {{.*}} <line:12:10, col:18> col:14 used i 'int' cinit
Expand Down Expand Up @@ -146,7 +146,7 @@ void test_five(int x, int y, int z) {
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.lb. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.ub. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-distribute-parallel-for-simd.c:17:1) *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-distribute-parallel-for-simd.c:17:1) *const restrict'
// CHECK-NEXT: | | |-VarDecl {{.*}} <line:18:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | `-VarDecl {{.*}} <line:19:10, col:18> col:14 used i 'int' cinit
Expand Down Expand Up @@ -193,7 +193,7 @@ void test_five(int x, int y, int z) {
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.lb. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.ub. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-distribute-parallel-for-simd.c:24:1) *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-distribute-parallel-for-simd.c:24:1) *const restrict'
// CHECK-NEXT: | | |-VarDecl {{.*}} <line:25:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | `-VarDecl {{.*}} <line:26:10, col:18> col:14 used i 'int' cinit
Expand Down Expand Up @@ -253,7 +253,7 @@ void test_five(int x, int y, int z) {
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.lb. 'const unsigned long'
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.ub. 'const unsigned long'
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-distribute-parallel-for-simd.c:31:1) *const restrict'
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-distribute-parallel-for-simd.c:31:1) *const restrict'
// CHECK-NEXT: | |-VarDecl {{.*}} <line:32:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | |-VarDecl {{.*}} <line:33:10, col:18> col:14 used i 'int' cinit
Expand Down
10 changes: 5 additions & 5 deletions clang/test/AST/ast-dump-openmp-distribute-parallel-for.c
Expand Up @@ -59,7 +59,7 @@ void test_five(int x, int y, int z) {
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.lb. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.ub. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-distribute-parallel-for.c:4:1) *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-distribute-parallel-for.c:4:1) *const restrict'
// CHECK-NEXT: | | `-VarDecl {{.*}} <line:5:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | `-DeclRefExpr {{.*}} <col:3> 'int' lvalue ParmVar {{.*}} 'x' 'int'
Expand Down Expand Up @@ -99,7 +99,7 @@ void test_five(int x, int y, int z) {
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.lb. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.ub. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-distribute-parallel-for.c:10:1) *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-distribute-parallel-for.c:10:1) *const restrict'
// CHECK-NEXT: | | |-VarDecl {{.*}} <line:11:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | `-VarDecl {{.*}} <line:12:10, col:18> col:14 used i 'int' cinit
Expand Down Expand Up @@ -146,7 +146,7 @@ void test_five(int x, int y, int z) {
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.lb. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.ub. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-distribute-parallel-for.c:17:1) *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-distribute-parallel-for.c:17:1) *const restrict'
// CHECK-NEXT: | | |-VarDecl {{.*}} <line:18:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | `-VarDecl {{.*}} <line:19:10, col:18> col:14 used i 'int' cinit
Expand Down Expand Up @@ -193,7 +193,7 @@ void test_five(int x, int y, int z) {
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.lb. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.ub. 'const unsigned long'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-distribute-parallel-for.c:24:1) *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-distribute-parallel-for.c:24:1) *const restrict'
// CHECK-NEXT: | | |-VarDecl {{.*}} <line:25:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | `-VarDecl {{.*}} <line:26:10, col:18> col:14 used i 'int' cinit
Expand Down Expand Up @@ -253,7 +253,7 @@ void test_five(int x, int y, int z) {
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.lb. 'const unsigned long'
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit used .previous.ub. 'const unsigned long'
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-distribute-parallel-for.c:31:1) *const restrict'
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-distribute-parallel-for.c:31:1) *const restrict'
// CHECK-NEXT: | |-VarDecl {{.*}} <line:32:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | |-VarDecl {{.*}} <line:33:10, col:18> col:14 used i 'int' cinit
Expand Down

0 comments on commit 50542d5

Please sign in to comment.