diff --git a/clang/include/clang/AST/TextNodeDumper.h b/clang/include/clang/AST/TextNodeDumper.h --- a/clang/include/clang/AST/TextNodeDumper.h +++ b/clang/include/clang/AST/TextNodeDumper.h @@ -203,6 +203,7 @@ void dumpAccessSpecifier(AccessSpecifier AS); void dumpCleanupObject(const ExprWithCleanups::CleanupObject &C); void dumpTemplateSpecializationKind(TemplateSpecializationKind TSK); + void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS); void dumpDeclRef(const Decl *D, StringRef Label = {}); @@ -255,6 +256,7 @@ void VisitCastExpr(const CastExpr *Node); void VisitImplicitCastExpr(const ImplicitCastExpr *Node); void VisitDeclRefExpr(const DeclRefExpr *Node); + void VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *Node); void VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *Node); void VisitPredefinedExpr(const PredefinedExpr *Node); void VisitCharacterLiteral(const CharacterLiteral *Node); diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp --- a/clang/lib/AST/TextNodeDumper.cpp +++ b/clang/lib/AST/TextNodeDumper.cpp @@ -754,6 +754,46 @@ } } +void clang::TextNodeDumper::dumpNestedNameSpecifier(const NestedNameSpecifier *NNS) { + if (!NNS) + return; + + AddChild([=] { + OS << "NestedNameSpecifier"; + + switch (NNS->getKind()) { + case NestedNameSpecifier::Identifier: + OS << " Identifier"; + OS << " '" << NNS->getAsIdentifier()->getName() << "'"; + break; + case NestedNameSpecifier::Namespace: + OS << " Namespace"; + dumpBareDeclRef(NNS->getAsNamespace()); + break; + case NestedNameSpecifier::NamespaceAlias: + OS << " NamespaceAlias"; + dumpBareDeclRef(NNS->getAsNamespaceAlias()); + break; + case NestedNameSpecifier::TypeSpec: + OS << " TypeSpec"; + dumpType(QualType(NNS->getAsType(), 0)); + break; + case NestedNameSpecifier::TypeSpecWithTemplate: + OS << " TypeSpecWithTemplate"; + dumpType(QualType(NNS->getAsType(), 0)); + break; + case NestedNameSpecifier::Global: + OS << " Global"; + break; + case NestedNameSpecifier::Super: + OS << " Super"; + break; + } + + dumpNestedNameSpecifier(NNS->getPrefix()); + }); +} + void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef Label) { if (!D) return; @@ -1065,6 +1105,7 @@ void TextNodeDumper::VisitDeclRefExpr(const DeclRefExpr *Node) { OS << " "; dumpBareDeclRef(Node->getDecl()); + dumpNestedNameSpecifier(Node->getQualifier()); if (Node->getDecl() != Node->getFoundDecl()) { OS << " ("; dumpBareDeclRef(Node->getFoundDecl()); @@ -1080,6 +1121,12 @@ OS << " immediate-escalating"; } +void clang::TextNodeDumper::VisitDependentScopeDeclRefExpr( + const DependentScopeDeclRefExpr *Node) { + + dumpNestedNameSpecifier(Node->getQualifier()); +} + void TextNodeDumper::VisitUnresolvedLookupExpr( const UnresolvedLookupExpr *Node) { OS << " ("; @@ -1174,6 +1221,7 @@ void TextNodeDumper::VisitMemberExpr(const MemberExpr *Node) { OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl(); dumpPointer(Node->getMemberDecl()); + dumpNestedNameSpecifier(Node->getQualifier()); switch (Node->isNonOdrUse()) { case NOUR_None: break; case NOUR_Unevaluated: OS << " non_odr_use_unevaluated"; break; @@ -1867,6 +1915,7 @@ } void TextNodeDumper::VisitVarDecl(const VarDecl *D) { + dumpNestedNameSpecifier(D->getQualifier()); dumpName(D); dumpType(D->getType()); dumpTemplateSpecializationKind(D->getTemplateSpecializationKind()); @@ -2061,6 +2110,8 @@ if (const auto *CTSD = dyn_cast(D)) dumpTemplateSpecializationKind(CTSD->getSpecializationKind()); + dumpNestedNameSpecifier(D->getQualifier()); + if (!D->isCompleteDefinition()) return; @@ -2260,6 +2311,7 @@ if (D->getQualifier()) D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy()); OS << D->getDeclName(); + dumpNestedNameSpecifier(D->getQualifier()); } void TextNodeDumper::VisitUsingEnumDecl(const UsingEnumDecl *D) { diff --git a/clang/test/AST/ast-dump-decl.cpp b/clang/test/AST/ast-dump-decl.cpp --- a/clang/test/AST/ast-dump-decl.cpp +++ b/clang/test/AST/ast-dump-decl.cpp @@ -614,24 +614,27 @@ // CHECK-NEXT: |-TemplateTypeParmDecl 0x{{.+}} col:25 referenced typename depth 0 index 0 T // CHECK-NEXT: |-VarDecl 0x{{.+}} col:43 TestVarTemplate 'const T' static // CHECK-NEXT: |-VarTemplateSpecializationDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} col:14 referenced TestVarTemplate 'const int':'const int' implicit_instantiation cinit + // CHECK-NEXT: | |-NestedNameSpecifier TypeSpec 'testCanonicalTemplate::S' // CHECK-NEXT: | |-TemplateArgument type 'int' // CHECK-NEXT: | | `-BuiltinType 0x{{.+}} 'int' // CHECK-NEXT: | `-InitListExpr 0x{{.+}} 'int':'int' - // CHECK-NEXT: `-VarTemplateSpecializationDecl 0x{{.+}} col:43 referenced TestVarTemplate 'const int':'const int' implicit_instantiation static + // CHECK-NEXT: `-VarTemplateSpecializationDecl 0x{{.+}} col:43 referenced TestVarTemplate 'const int':'const int' implicit_instantiation static // CHECK-NEXT: `-TemplateArgument type 'int' - // CHECK: VarTemplateSpecializationDecl 0x{{.+}} <{{.+}}:[[@LINE-21]]:28, col:43> col:43 referenced TestVarTemplate 'const int':'const int' implicit_instantiation static + // CHECK: VarTemplateSpecializationDecl 0x{{.+}} <{{.+}}:[[@LINE-22]]:28, col:43> col:43 referenced TestVarTemplate 'const int':'const int' implicit_instantiation static // CHECK-NEXT:`-TemplateArgument type 'int' // CHECK-NEXT: `-BuiltinType 0x{{.+}} 'int' - // CHECK: VarTemplateDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} <{{.+}}:[[@LINE-23]]:3, line:[[@LINE-22]]:34> col:14 TestVarTemplate - // CHECK-NEXT: |-TemplateTypeParmDecl 0x{{.+}} col:21 referenced typename depth 0 index 0 T - // CHECK-NEXT: |-VarDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} col:14 TestVarTemplate 'const T' cinit + // CHECK: VarTemplateDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} <{{.+}}:[[@LINE-24]]:3, line:[[@LINE-23]]:34> col:14 TestVarTemplate + // CHECK-NEXT: |-TemplateTypeParmDecl 0x{{.+}} col:21 referenced typename depth 0 index 0 T + // CHECK-NEXT: |-VarDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} col:14 TestVarTemplate 'const T' cinit + // CHECK-NEXT: | |-NestedNameSpecifier TypeSpec 'testCanonicalTemplate::S' // CHECK-NEXT: | `-InitListExpr 0x{{.+}} 'void' // CHECK-NEXT: |-VarTemplateSpecialization 0x{{.+}} 'TestVarTemplate' 'const int':'const int' // CHECK-NEXT: `-VarTemplateSpecialization 0x{{.+}} 'TestVarTemplate' 'const int':'const int' - // CHECK: VarTemplateSpecializationDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} <{{.+}}:[[@LINE-29]]:3, col:34> col:14 referenced TestVarTemplate 'const int':'const int' implicit_instantiation cinit + // CHECK: VarTemplateSpecializationDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} <{{.+}}:[[@LINE-31]]:3, col:34> col:14 referenced TestVarTemplate 'const int':'const int' implicit_instantiation cinit + // CHECK-NEXT: |-NestedNameSpecifier TypeSpec 'testCanonicalTemplate::S' // CHECK-NEXT: |-TemplateArgument type 'int' // CHECK-NEXT: | `-BuiltinType 0x{{.+}} 'int' // CHECK-NEXT: `-InitListExpr 0x{{.+}} 'int':'int' @@ -737,6 +740,7 @@ } // CHECK: NamespaceDecl{{.*}} TestUsingDecl // CHECK-NEXT: UsingDecl{{.*}} testUsingDecl::i +// CHECK-NEXT: | `-NestedNameSpecifier NamespaceNamespace 0x{{.*}} 'testUsingDecl // CHECK-NEXT: UsingShadowDecl{{.*}} Var{{.*}} 'i' 'int' namespace testUnresolvedUsing { diff --git a/clang/test/AST/ast-dump-expr.cpp b/clang/test/AST/ast-dump-expr.cpp --- a/clang/test/AST/ast-dump-expr.cpp +++ b/clang/test/AST/ast-dump-expr.cpp @@ -224,6 +224,8 @@ p->::S::~S(); // CHECK: CXXMemberCallExpr 0x{{[^ ]*}} 'void' // CHECK-NEXT: MemberExpr 0x{{[^ ]*}} '' ->~S 0x{{[^ ]*}} + // CHECK-NEXT: NestedNameSpecifier TypeSpec 'S' + // CHECK-NEXT: NestedNameSpecifier Global // CHECK-NEXT: ImplicitCastExpr // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} 'S *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'S *' @@ -231,6 +233,7 @@ r->template U::~U(); // CHECK: CXXMemberCallExpr 0x{{[^ ]*}} 'void' // CHECK-NEXT: MemberExpr 0x{{[^ ]*}} '' ->~U 0x{{[^ ]*}} + // CHECK-NEXT: NestedNameSpecifier TypeSpecWithTemplate 'U':'U' // CHECK-NEXT: ImplicitCastExpr // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} 'U *' lvalue ParmVar 0x{{[^ ]*}} 'r' 'U *' diff --git a/clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp b/clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp --- a/clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp +++ b/clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp @@ -114,10 +114,12 @@ // CHECK-NEXT: | | |-CallExpr [[ADDR_47:0x[a-z0-9]*]] 'int' // CHECK-NEXT: | | | `-ImplicitCastExpr [[ADDR_48:0x[a-z0-9]*]] 'int (*)({{.*}})' // CHECK-NEXT: | | | `-DeclRefExpr [[ADDR_49:0x[a-z0-9]*]] 'int ({{.*}})' {{.*}}Function [[ADDR_1]] 'foo' 'int ({{.*}})' +// CHECK-NEXT: | | | `-NestedNameSpecifier NamespaceNamespace [[ADDR_0]] 'A' // CHECK-NEXT: | | `-PseudoObjectExpr [[ADDR_50:0x[a-z0-9]*]] 'int' // CHECK-NEXT: | | |-CallExpr [[ADDR_51:0x[a-z0-9]*]] 'int' // CHECK-NEXT: | | | `-ImplicitCastExpr [[ADDR_52:0x[a-z0-9]*]] 'int (*)({{.*}})' // CHECK-NEXT: | | | `-DeclRefExpr [[ADDR_53:0x[a-z0-9]*]] 'int ({{.*}})' {{.*}}Function [[ADDR_6]] 'bar' 'int ({{.*}})' +// CHECK-NEXT: | | | `-NestedNameSpecifier NamespaceNamespace [[ADDR_31]] 'B' // CHECK-NEXT: | | `-CallExpr [[ADDR_54:0x[a-z0-9]*]] 'int' // CHECK-NEXT: | | `-ImplicitCastExpr [[ADDR_55:0x[a-z0-9]*]] 'int (*)({{.*}})' // CHECK-NEXT: | | `-DeclRefExpr [[ADDR_11]] 'int ({{.*}})' Function [[ADDR_12]] 'bar[implementation={vendor(llvm)}]' 'int ({{.*}})' @@ -125,6 +127,7 @@ // CHECK-NEXT: | |-CallExpr [[ADDR_57:0x[a-z0-9]*]] 'int' // CHECK-NEXT: | | `-ImplicitCastExpr [[ADDR_58:0x[a-z0-9]*]] 'int (*)({{.*}})' // CHECK-NEXT: | | `-DeclRefExpr [[ADDR_59:0x[a-z0-9]*]] 'int ({{.*}})' {{.*}}Function [[ADDR_14]] 'baz' 'int ({{.*}})' +// CHECK-NEXT: | | `-NestedNameSpecifier NamespaceNamespace [[ADDR_13]] 'C' // CHECK-NEXT: | `-CallExpr [[ADDR_60:0x[a-z0-9]*]] 'int' // CHECK-NEXT: | `-ImplicitCastExpr [[ADDR_61:0x[a-z0-9]*]] 'int (*)({{.*}})' // CHECK-NEXT: | `-DeclRefExpr [[ADDR_19]] 'int ({{.*}})' Function [[ADDR_20]] 'baz[implementation={vendor(llvm)}]' 'int ({{.*}})' diff --git a/clang/test/AST/ast-dump-using.cpp b/clang/test/AST/ast-dump-using.cpp --- a/clang/test/AST/ast-dump-using.cpp +++ b/clang/test/AST/ast-dump-using.cpp @@ -6,6 +6,7 @@ namespace b { using a::S; // CHECK: UsingDecl {{.*}} a::S +// CHECK-NEXT: | `-NestedNameSpecifier NamespaceNamespace {{.*}} 'a' // CHECK-NEXT: UsingShadowDecl {{.*}} implicit CXXRecord {{.*}} 'S' // CHECK-NEXT: `-RecordType {{.*}} 'a::S' typedef S f; // to dump the introduced type