Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/test/ast-no-range.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# CHECK-NEXT: "arcana": "{{TranslationUnitDecl.*}}"
# CHECK-NEXT: "children": [
# CHECK-NEXT: {
# CHECK: "arcana": "VarDecl {{.*}} x 'int'",
# CHECK: "arcana": "VarDecl {{.*}} x 'int' external-linkage",
# CHECK-NEXT: "children": [
# CHECK-NEXT: {
# CHECK-NEXT: "arcana": "QualType {{.*}} 'int' ",
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/test/ast.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# CHECK: "id": 1,
# CHECK-NEXT: "jsonrpc": "2.0",
# CHECK-NEXT: "result": {
# CHECK-NEXT: "arcana": "VarDecl {{.*}} x 'int'",
# CHECK-NEXT: "arcana": "VarDecl {{.*}} x 'int' external-linkage",
# CHECK-NEXT: "children": [
# CHECK-NEXT: {
# CHECK-NEXT: "arcana": "QualType {{.*}} 'int' ",
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/unittests/DumpASTTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ TEST(DumpASTTests, Arcana) {
auto Node = dumpAST(DynTypedNode::create(findDecl(AST, "x")), AST.getTokens(),
AST.getASTContext());
EXPECT_THAT(Node.arcana, testing::StartsWith("VarDecl "));
EXPECT_THAT(Node.arcana, testing::EndsWith(" 'int'"));
EXPECT_THAT(Node.arcana, testing::EndsWith(" 'int' external-linkage"));
ASSERT_THAT(Node.children, SizeIs(1)) << "Expected one child typeloc";
EXPECT_THAT(Node.children.front().arcana, testing::StartsWith("QualType "));
}
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/AST/TextNodeDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class TextNodeDumper
void dumpType(QualType T);
void dumpBareDeclRef(const Decl *D);
void dumpName(const NamedDecl *ND);
void dumpFormalLinkage(const NamedDecl *ND);
void dumpAccessSpecifier(AccessSpecifier AS);
void dumpCleanupObject(const ExprWithCleanups::CleanupObject &C);
void dumpTemplateSpecializationKind(TemplateSpecializationKind TSK);
Expand Down
54 changes: 54 additions & 0 deletions clang/lib/AST/TextNodeDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,29 @@ static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
OS << ')';
}

void TextNodeDumper::dumpFormalLinkage(const NamedDecl *ND) {
switch (ND->getFormalLinkage()) {
case Linkage::None:
// A lot of declarations have no linkage, so we only dump linkage if there
// is one.
break;
case Linkage::Internal:
OS << " internal-linkage";
break;
case Linkage::External:
OS << " external-linkage";
break;
case Linkage::Module:
OS << " module-linkage";
break;
case Linkage::Invalid:
llvm_unreachable("Linkage hasn't been computed!");
case Linkage::UniqueExternal:
case Linkage::VisibleNone:
llvm_unreachable("Not a formal linkage!");
}
}

void TextNodeDumper::VisitLoopControlStmt(const LoopControlStmt *Node) {
if (!Node->hasLabelTarget())
return;
Expand Down Expand Up @@ -2295,6 +2318,11 @@ void TextNodeDumper::VisitTypedefDecl(const TypedefDecl *D) {
dumpType(D->getUnderlyingType());
if (D->isModulePrivate())
OS << " __module_private__";

const TagDecl *TD = D->getUnderlyingType()->getAsTagDecl();
if (TD && TD->getTypedefNameForAnonDecl()) {
Comment thread
Endilll marked this conversation as resolved.
dumpFormalLinkage(D);
}
}

void TextNodeDumper::VisitEnumDecl(const EnumDecl *D) {
Expand All @@ -2314,6 +2342,8 @@ void TextNodeDumper::VisitEnumDecl(const EnumDecl *D) {
OS << " instantiated_from";
dumpPointer(Instance);
}

dumpFormalLinkage(D);
}

void TextNodeDumper::VisitRecordDecl(const RecordDecl *D) {
Expand All @@ -2323,6 +2353,10 @@ void TextNodeDumper::VisitRecordDecl(const RecordDecl *D) {
OS << " __module_private__";
if (D->isCompleteDefinition())
OS << " definition";

if (!D->isImplicit() && !D->getDescribedTemplate()) {
dumpFormalLinkage(D);
}
}

void TextNodeDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Expand Down Expand Up @@ -2420,6 +2454,10 @@ void TextNodeDumper::VisitFunctionDecl(const FunctionDecl *D) {
OS << " instantiated_from";
dumpPointer(Instance);
}

if (!isa<CXXDeductionGuideDecl>(D) && !D->getDescribedTemplate()) {
dumpFormalLinkage(D);
}
}

void TextNodeDumper::VisitCXXDeductionGuideDecl(
Expand Down Expand Up @@ -2520,6 +2558,10 @@ void TextNodeDumper::VisitVarDecl(const VarDecl *D) {
AddChild("value", [=] { Visit(*Value, E->getType()); });
}
}

if (!D->getDescribedVarTemplate()) {
dumpFormalLinkage(D);
}
}

void TextNodeDumper::VisitBindingDecl(const BindingDecl *D) {
Expand Down Expand Up @@ -2633,6 +2675,8 @@ void TextNodeDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
OS << " nested";
if (!D->isFirstDecl())
dumpDeclRef(D->getFirstDecl(), "original");

dumpFormalLinkage(D);
}

void TextNodeDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Expand All @@ -2648,11 +2692,17 @@ void TextNodeDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
void TextNodeDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
dumpName(D);
dumpType(D->getUnderlyingType());

const TagDecl *TD = D->getUnderlyingType()->getAsTagDecl();
if (TD && TD->getTypedefNameForAnonDecl()) {
dumpFormalLinkage(D);
}
}

void TextNodeDumper::VisitTypeAliasTemplateDecl(
const TypeAliasTemplateDecl *D) {
dumpName(D);
dumpFormalLinkage(D);
}

void TextNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Expand Down Expand Up @@ -2813,14 +2863,17 @@ void TextNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {

void TextNodeDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
dumpName(D);
dumpFormalLinkage(D);
}

void TextNodeDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
dumpName(D);
dumpFormalLinkage(D);
}

void TextNodeDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
dumpName(D);
dumpFormalLinkage(D);
}

void TextNodeDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
Expand Down Expand Up @@ -3118,6 +3171,7 @@ void TextNodeDumper::VisitBlockDecl(const BlockDecl *D) {

void TextNodeDumper::VisitConceptDecl(const ConceptDecl *D) {
dumpName(D);
dumpFormalLinkage(D);
}

void TextNodeDumper::VisitCompoundStmt(const CompoundStmt *S) {
Expand Down
4 changes: 2 additions & 2 deletions clang/test/AST/ast-dump-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct Invalid {
//CHECK: {{^}}[[Blue]]| |-[[RESET]][[Blue]]HTMLEndTagComment[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:13[[RESET]], [[Yellow]]col:16[[RESET]]> Name="a"{{$}}
//CHECK: {{^}}[[Blue]]| |-[[RESET]][[Blue]]TextComment[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:5:4[[RESET]]> Text=" "{{$}}
//CHECK: {{^}}[[Blue]]| `-[[RESET]][[Blue]]HTMLStartTagComment[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:5[[RESET]], [[Yellow]]col:8[[RESET]]> Name="br" SelfClosing{{$}}
//CHECK: {{^}}[[Blue]]|-[[RESET]][[GREEN]]FunctionDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:9:1[[RESET]], [[Yellow]]line:16:1[[RESET]]> [[Yellow]]line:9:6[[RESET]][[CYAN]] TestAttributedStmt[[RESET]] [[Green]]'void ()'[[RESET]]{{$}}
//CHECK: {{^}}[[Blue]]|-[[RESET]][[GREEN]]FunctionDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:9:1[[RESET]], [[Yellow]]line:16:1[[RESET]]> [[Yellow]]line:9:6[[RESET]][[CYAN]] TestAttributedStmt[[RESET]] [[Green]]'void ()'[[RESET]] external-linkage{{$}}
//CHECK: {{^}}[[Blue]]| |-[[RESET]][[MAGENTA:.\[0;1;35m]]CompoundStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:27[[RESET]], [[Yellow]]line:16:1[[RESET]]>{{$}}
//CHECK: {{^}}[[Blue]]| | `-[[RESET]][[MAGENTA]]SwitchStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:10:3[[RESET]], [[Yellow]]line:15:3[[RESET]]>{{$}}
//CHECK: {{^}}[[Blue]]| | |-[[RESET]][[MAGENTA]]IntegerLiteral[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:10:11[[RESET]]> [[Green]]'int'[[RESET]][[Cyan:.\[0;36m]][[RESET]][[Cyan]][[RESET]][[CYAN]] 1[[RESET]]{{$}}
Expand All @@ -63,7 +63,7 @@ struct Invalid {
//CHECK: {{^}}[[Blue]]| `-[[RESET]][[Blue]]FullComment[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:8:4[[RESET]], [[Yellow]]col:11[[RESET]]>{{$}}
//CHECK: {{^}}[[Blue]]| `-[[RESET]][[Blue]]ParagraphComment[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:4[[RESET]], [[Yellow]]col:11[[RESET]]>{{$}}
//CHECK: {{^}}[[Blue]]| `-[[RESET]][[Blue]]TextComment[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:4[[RESET]], [[Yellow]]col:11[[RESET]]> Text=" Comment"{{$}}
//CHECK: {{^}}[[Blue]]|-[[RESET]][[GREEN]]CXXRecordDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:18:1[[RESET]], [[Yellow]]line:25:1[[RESET]]> [[Yellow]]line:18:33[[RESET]] class[[CYAN]] Mutex[[RESET]] definition{{$}}
//CHECK: {{^}}[[Blue]]|-[[RESET]][[GREEN]]CXXRecordDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:18:1[[RESET]], [[Yellow]]line:25:1[[RESET]]> [[Yellow]]line:18:33[[RESET]] class[[CYAN]] Mutex[[RESET]] definition external-linkage{{$}}
//CHECK: {{^}}[[Blue]]| |-[[RESET]][[BLUE]]CapabilityAttr[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:22[[RESET]]> capability "mutex"{{$}}
//CHECK: {{^}}[[Blue]]| |-[[RESET]][[GREEN]]CXXRecordDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:1[[RESET]], [[Yellow]]col:33[[RESET]]> [[Yellow]]col:33[[RESET]] implicit class[[CYAN]] Mutex[[RESET]]{{$}}
//CHECK: {{^}}[[Blue]]| |-[[RESET]][[GREEN]]FieldDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:20:3[[RESET]], [[Yellow]]col:7[[RESET]]> [[Yellow]]col:7[[RESET]][[CYAN]] var1[[RESET]] [[Green]]'int'[[RESET]]{{$}}
Expand Down
6 changes: 3 additions & 3 deletions clang/test/AST/ast-dump-constant-expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ struct Test {
};

// CHECK:Dumping Test:
// CHECK-NEXT:CXXRecordDecl {{.*}} <{{.*}}ast-dump-constant-expr.cpp:43:1, line:57:1> line:43:8 struct Test definition
// CHECK:|-CXXMethodDecl {{.*}} <line:44:3, line:54:3> line:44:8 test 'void ()' implicit-inline
// CHECK-NEXT:CXXRecordDecl {{.*}} <{{.*}}ast-dump-constant-expr.cpp:43:1, line:57:1> line:43:8 struct Test definition external-linkage
// CHECK:|-CXXMethodDecl {{.*}} <line:44:3, line:54:3> line:44:8 test 'void ()' implicit-inline external-linkage
// CHECK-NEXT:| `-CompoundStmt {{.*}} <col:15, line:54:3>
// CHECK-NEXT:| |-CStyleCastExpr {{.*}} <line:45:5, col:20> 'void' <ToVoid>
// CHECK-NEXT:| | `-ConstantExpr {{.*}} <col:11, col:20> 'int'
Expand Down Expand Up @@ -90,4 +90,4 @@ struct Test {
// CHECK-NEXT:| `-CallExpr {{.*}} <col:11, col:23> '__int128'
// CHECK-NEXT:| `-ImplicitCastExpr {{.*}} <col:11> '__int128 (*)()' <FunctionToPointerDecay>
// CHECK-NEXT:| `-DeclRefExpr {{.*}} <col:11> '__int128 ()' lvalue Function {{.*}} 'test_Int128' '__int128 ()'
// CHECK-NEXT:`-CXXMethodDecl {{.*}} <line:56:3, col:38> col:18 consteval consteval_method 'void ()' implicit-inline
// CHECK-NEXT:`-CXXMethodDecl {{.*}} <line:56:3, col:38> col:18 consteval consteval_method 'void ()' implicit-inline external-linkage
4 changes: 2 additions & 2 deletions clang/test/AST/ast-dump-ctad-alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ Out2<double>::AInner t(1.0);
// CHECK-NEXT: | | `-TypeTraitExpr {{.*}} 'bool' __is_deducible
// CHECK-NEXT: | | |-DeducedTemplateSpecializationType {{.*}} 'Out2<double>::AInner' dependent
// CHECK-NEXT: | | | `-name: 'Out2<double>::AInner'
// CHECK-NEXT: | | | `-TypeAliasTemplateDecl {{.+}} AInner{{$}}
// CHECK-NEXT: | | | `-TypeAliasTemplateDecl {{.+}} AInner external-linkage{{$}}
// CHECK-NEXT: | | `-TemplateSpecializationType {{.*}} 'Inner<Y>' dependent
// CHECK-NEXT: | | |-name: 'Inner':'Out<int>::Inner' qualified
// CHECK-NEXT: | | | `-ClassTemplateDecl {{.+}} Inner{{$}}
// CHECK-NEXT: | | | `-ClassTemplateDecl {{.+}} Inner external-linkage{{$}}
// CHECK-NEXT: | | `-TemplateArgument type 'Y'
// CHECK-NEXT: | | `-SubstTemplateTypeParmType {{.*}} 'Y'
// CHECK-NEXT: | | |-FunctionTemplate {{.*}} '<deduction guide for Inner>'
Expand Down
2 changes: 1 addition & 1 deletion clang/test/AST/ast-dump-decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ extern int TestVarDeclSC;
// CHECK: VarDecl{{.*}} TestVarDeclSC 'int' extern

__thread int TestVarDeclThread;
// CHECK: VarDecl{{.*}} TestVarDeclThread 'int' tls{{$}}
// CHECK: VarDecl{{.*}} TestVarDeclThread 'int' tls external-linkage{{$}}

__module_private__ int TestVarDeclPrivate;
// CHECK-MODULE: VarDecl{{.*}} TestVarDeclPrivate 'int' __module_private__
Expand Down
Loading