diff --git a/clang/include/clang/AST/JSONNodeDumper.h b/clang/include/clang/AST/JSONNodeDumper.h --- a/clang/include/clang/AST/JSONNodeDumper.h +++ b/clang/include/clang/AST/JSONNodeDumper.h @@ -208,6 +208,8 @@ void Visit(const concepts::Requirement *R); void Visit(const APValue &Value, QualType Ty); + void VisitAliasAttr(const AliasAttr *AA); + void VisitTypedefType(const TypedefType *TT); void VisitUsingType(const UsingType *TT); void VisitFunctionType(const FunctionType *T); diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp --- a/clang/lib/AST/JSONNodeDumper.cpp +++ b/clang/lib/AST/JSONNodeDumper.cpp @@ -530,6 +530,10 @@ return Ret; } +void JSONNodeDumper::VisitAliasAttr(const AliasAttr *AA) { + JOS.attribute("aliasee", AA->getAliasee()); +} + void JSONNodeDumper::VisitTypedefType(const TypedefType *TT) { JOS.attribute("decl", createBareDeclRef(TT->getDecl())); if (!TT->typeMatchesDecl()) diff --git a/clang/test/AST/ast-dump-attr-json.cpp b/clang/test/AST/ast-dump-attr-json.cpp new file mode 100644 --- /dev/null +++ b/clang/test/AST/ast-dump-attr-json.cpp @@ -0,0 +1,84 @@ +// RUN: %clang_cc1 -Wdocumentation -ast-dump=json %s | FileCheck %s + +int global_decl; +extern __attribute__((alias("global_decl"))) int global_alias; + +// NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py +// using --filters=VarDecl + + +// CHECK-NOT: {{^}}Dumping +// CHECK: "kind": "VarDecl", +// CHECK-NEXT: "loc": { +// CHECK-NEXT: "offset": 73, +// CHECK-NEXT: "file": "{{.*}}", +// CHECK-NEXT: "line": 3, +// CHECK-NEXT: "col": 5, +// CHECK-NEXT: "tokLen": 11 +// CHECK-NEXT: }, +// CHECK-NEXT: "range": { +// CHECK-NEXT: "begin": { +// CHECK-NEXT: "offset": 69, +// CHECK-NEXT: "col": 1, +// CHECK-NEXT: "tokLen": 3 +// CHECK-NEXT: }, +// CHECK-NEXT: "end": { +// CHECK-NEXT: "offset": 73, +// CHECK-NEXT: "col": 5, +// CHECK-NEXT: "tokLen": 11 +// CHECK-NEXT: } +// CHECK-NEXT: }, +// CHECK-NEXT: "name": "global_decl", +// CHECK-NEXT: "mangledName": "global_decl", +// CHECK-NEXT: "type": { +// CHECK-NEXT: "qualType": "int" +// CHECK-NEXT: } +// CHECK-NEXT: } + + +// CHECK-NOT: {{^}}Dumping +// CHECK: "kind": "VarDecl", +// CHECK-NEXT: "loc": { +// CHECK-NEXT: "offset": 135, +// CHECK-NEXT: "line": 4, +// CHECK-NEXT: "col": 50, +// CHECK-NEXT: "tokLen": 12 +// CHECK-NEXT: }, +// CHECK-NEXT: "range": { +// CHECK-NEXT: "begin": { +// CHECK-NEXT: "offset": 86, +// CHECK-NEXT: "col": 1, +// CHECK-NEXT: "tokLen": 6 +// CHECK-NEXT: }, +// CHECK-NEXT: "end": { +// CHECK-NEXT: "offset": 135, +// CHECK-NEXT: "col": 50, +// CHECK-NEXT: "tokLen": 12 +// CHECK-NEXT: } +// CHECK-NEXT: }, +// CHECK-NEXT: "name": "global_alias", +// CHECK-NEXT: "mangledName": "global_alias", +// CHECK-NEXT: "type": { +// CHECK-NEXT: "qualType": "int" +// CHECK-NEXT: }, +// CHECK-NEXT: "storageClass": "extern", +// CHECK-NEXT: "inner": [ +// CHECK-NEXT: { +// CHECK-NEXT: "id": "0x{{.*}}", +// CHECK-NEXT: "kind": "AliasAttr", +// CHECK-NEXT: "range": { +// CHECK-NEXT: "begin": { +// CHECK-NEXT: "offset": 108, +// CHECK-NEXT: "col": 23, +// CHECK-NEXT: "tokLen": 5 +// CHECK-NEXT: }, +// CHECK-NEXT: "end": { +// CHECK-NEXT: "offset": 127, +// CHECK-NEXT: "col": 42, +// CHECK-NEXT: "tokLen": 1 +// CHECK-NEXT: } +// CHECK-NEXT: }, +// CHECK-NEXT: "decl": "global_decl" +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: }