[PATCH] D157350: [clang][ExtractAPI] Add support for C++ variable templates

2023-08-15 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 550485.
evelez7 added a comment.

Get rid of unnecessary function for checking if global var


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157350/new/

https://reviews.llvm.org/D157350

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/global_var_template.cpp
  clang/test/ExtractAPI/global_var_template_partial_spec.cpp
  clang/test/ExtractAPI/global_var_template_spec.cpp

Index: clang/test/ExtractAPI/global_var_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/global_var_template_spec.cpp
@@ -0,0 +1,207 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template T Foo = T(3.14);
+
+template<> int Foo;
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@Foo"
+  },
+  "kind": {
+"displayName": "Global Variable Template",
+"identifier": "c++.var"
+  },
+  "location": {
+"position": {
+  "character": 24,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": ">;"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@Foo>#I"

[PATCH] D158027: [clang][ExtractAPI] Visit method templates with better scheme

2023-08-15 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Visit and serialize method templates and template specializations. Introduces a 
new scheme of visiting child Decls via VisitCXXMethodDecl which will be 
followed in future patches for Fields and non-template methods.

Depends on D157579 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158027

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/method_template.cpp
  clang/test/ExtractAPI/method_template_spec.cpp

Index: clang/test/ExtractAPI/method_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/method_template_spec.cpp
@@ -0,0 +1,371 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {
+  template void Bar(T Fizz);
+
+  template<> void Bar(int Fizz);
+};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@FT@>1#TBar#t0.0#v#",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@F@Bar<#I>#I#",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "private",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "

[PATCH] D158027: [clang][ExtractAPI] Visit method templates with better scheme

2023-08-15 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 550500.
evelez7 added a comment.

Fix arbitrary include changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158027/new/

https://reviews.llvm.org/D158027

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/method_template.cpp
  clang/test/ExtractAPI/method_template_spec.cpp

Index: clang/test/ExtractAPI/method_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/method_template_spec.cpp
@@ -0,0 +1,371 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {
+  template void Bar(T Fizz);
+
+  template<> void Bar(int Fizz);
+};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@FT@>1#TBar#t0.0#v#",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@F@Bar<#I>#I#",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "private",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "Fizz"
+},
+{
+  "kind": "text",
+  "spelling": ");"
+}
+  ],
+  "functionSignature": {
+"parameters": [
+  {
+"declarationFragments": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifie

[PATCH] D158029: [clang][ExtractAPI] Add support for C++ member templates

2023-08-15 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a reviewer: dang.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Visit and serialize C++ fields by checking if a var template's context is a 
CXXRecordDecl in VisitVarTemplateDecl.

Depends on D158027 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158029

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/field_template.cpp

Index: clang/test/ExtractAPI/field_template.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/field_template.cpp
@@ -0,0 +1,206 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {
+  template static T Bar;
+};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@Bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "private",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "static"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo@Bar"
+  },
+  "kind": {
+"displayName": "Template Property",
+"identifier": "c++.property"
+  },
+  "location": {
+"position": {
+  "character": 33,
+  "line": 2
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "n

[PATCH] D158031: [clang][ExtractAPI] Refactor C++ method and field visitation

2023-08-15 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Refactor visitation for C++ record children by following the Visitor's CRTP.
Expand VisitCXXField, VisitCXXMethod for non-templates and introduce 
VisitCXXConstructor, VisitCXXDestructor.
Handle relationships by finding the parent's Record via USR from DeclContext.

Depends on D158029 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158031

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/constructor_destructor.cpp
  clang/test/ExtractAPI/methods.cpp

Index: clang/test/ExtractAPI/methods.cpp
===
--- clang/test/ExtractAPI/methods.cpp
+++ clang/test/ExtractAPI/methods.cpp
@@ -64,13 +64,13 @@
 },
 {
   "kind": "memberOf",
-  "source": "c:@S@Foo@F@getFoo#S",
+  "source": "c:@S@Foo@F@getBar#1",
   "target": "c:@S@Foo",
   "targetFallback": "Foo"
 },
 {
   "kind": "memberOf",
-  "source": "c:@S@Foo@F@getBar#1",
+  "source": "c:@S@Foo@F@getFoo#S",
   "target": "c:@S@Foo",
   "targetFallback": "Foo"
 }
@@ -310,11 +310,11 @@
   ]
 },
 {
-  "accessLevel": "public",
+  "accessLevel": "protected",
   "declarationFragments": [
 {
   "kind": "keyword",
-  "spelling": "static"
+  "spelling": "constexpr"
 },
 {
   "kind": "text",
@@ -322,8 +322,8 @@
 },
 {
   "kind": "typeIdentifier",
-  "preciseIdentifier": "c:d",
-  "spelling": "double"
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
 },
 {
   "kind": "text",
@@ -331,34 +331,42 @@
 },
 {
   "kind": "identifier",
-  "spelling": "getFoo"
+  "spelling": "getBar"
 },
 {
   "kind": "text",
-  "spelling": "();"
+  "spelling": "() "
+},
+{
+  "kind": "keyword",
+  "spelling": "const"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "functionSignature": {
 "returns": [
   {
 "kind": "typeIdentifier",
-"preciseIdentifier": "c:d",
-"spelling": "double"
+"preciseIdentifier": "c:I",
+"spelling": "int"
   }
 ]
   },
   "identifier": {
 "interfaceLanguage": "c++",
-"precise": "c:@S@Foo@F@getFoo#S"
+"precise": "c:@S@Foo@F@getBar#1"
   },
   "kind": {
-"displayName": "Static Method",
-"identifier": "c++.type.method"
+"displayName": "Instance Method",
+"identifier": "c++.method"
   },
   "location": {
 "position": {
   "character": 17,
-  "line": 7
+  "line": 10
 },
 "uri": "file://INPUT_DIR/input.h"
   },
@@ -366,28 +374,28 @@
 "navigator": [
   {
 "kind": "identifier",
-"spelling": "getFoo"
+"spelling": "getBar"
   }
 ],
 "subHeading": [
   {
 "kind": "identifier",
-"spelling": "getFoo"
+"spelling": "getBar"
   }
 ],
-"title": "getFoo"
+"title": "getBar"
   },
   "pathComponents": [
 "Foo",
-"getFoo"
+"getBar"
   ]
 },
 {
-  "accessLevel": "protected",
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
-  "spelling": "constexpr"
+  "spelling": "static"
 },
 {
   "kind": "text",
@@ -395,8 +403,8 @@
 },
 {
   "kind": "typeIdentifier",
-  "preciseIdentifier": "c:I",
-  "spelling": "int"
+  "preciseIdentifier": "c:d",
+  "spelling": "double"
 },
 {
   "kind": "text",
@@ -404,42 +412,34 @@
 },
 {
   "kind": "identifier",
-  "spelling": "getBar"
-},
-{
-  "kind": "text",
-  "spelling": "() "
-},
-{
-  "kind": "keyword",
-  "spelling": "const"
+  "spelling": "getFoo"
 },
 {
   "kind": "text",
-  "spelling": ";"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
 "returns": [
   {
 

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-16 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 550937.
evelez7 marked 5 inline comments as done.
evelez7 added a comment.

Address review feedback

- Handle inheriting from a template parameter.
- Add a new test to check inheriting from a template parameter.
- Move base class gathering to a new private method for code reuse.
- Move Template class to API.h and convert getTemplate functions to 
constructors.
- Rename all instances of Spec to Specialization.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157076/new/

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_param_inheritance.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,206 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generat

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-16 Thread Erick Velez via Phabricator via cfe-commits
evelez7 added a comment.

We didn't handle inheriting from a template parameter, but now we do by 
serializing the relationship. The parameter does not produce a target USR so it 
falls back to its name.




Comment at: clang/include/clang/ExtractAPI/DeclarationFragments.h:191
 
+class Template {
+  struct TemplateParameter {

dang wrote:
> This is really a model type and should live either in it's own file or in 
> API.h
Moved to API.h



Comment at: clang/lib/ExtractAPI/DeclarationFragments.cpp:754
+  Fragments.append(TemplateParam->getTypeConstraint()
+   ->getNamedConcept()
+   ->getName()

dang wrote:
> is this clang-format formatted?
Yes.



Comment at: clang/lib/ExtractAPI/DeclarationFragments.cpp:784
+dyn_cast(TemplateParameters[i]);
+if (TypeParameter.compare("type-parameter-" +
+  std::to_string(Parameter->getDepth()) + "-" +

dang wrote:
> Kinda sad we have to do this. I guess there is no easy way to change the AST 
> to support this?
I've just realized that we could just take the the template parameter and 
insert it arbitrarily but it could easily be the incorrect partial 
specialization. We'd still need to determine which argument corresponds to the 
template param.

One optimization is to check if there is only one new param in a partial 
specialization so that a var template's type is automatically known if it is 
the new template param, i.e. template T x

The unfortunate reality is that template parameters are actual Decls 
(TemplateTypeParmDecl, which do hold the generic's correct name), and 
TemplateArguments are not. Calling TemplateArgument.getAsDecl() or 
getAsTemplate always result in assertion errors (when the arg is a template 
param) since there are no analogous structures. There'd have to be a 
TemplateTypeArgDecl.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157076/new/

https://reviews.llvm.org/D157076

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157350: [clang][ExtractAPI] Add support for C++ variable templates

2023-08-16 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 550944.
evelez7 added a comment.

Update all instances of Spec to Specialization


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157350/new/

https://reviews.llvm.org/D157350

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/global_var_template.cpp
  clang/test/ExtractAPI/global_var_template_partial_spec.cpp
  clang/test/ExtractAPI/global_var_template_spec.cpp

Index: clang/test/ExtractAPI/global_var_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/global_var_template_spec.cpp
@@ -0,0 +1,207 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template T Foo = T(3.14);
+
+template<> int Foo;
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@Foo"
+  },
+  "kind": {
+"displayName": "Global Variable Template",
+"identifier": "c++.var"
+  },
+  "location": {
+"position": {
+  "character": 24,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": ">;"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@Foo>#I"
+  },
+ 

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-16 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 550945.
evelez7 added a comment.

Also rename traverseSpec* in SerializerBase.h


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157076/new/

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_param_inheritance.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,206 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo {};
+
+template<> class Foo {};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": 

[PATCH] D157579: [clang][ExtractAPI] Add support for C++ global function templates

2023-08-16 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 550948.
evelez7 added a comment.

Update instances of Spec to Specialization


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157579/new/

https://reviews.llvm.org/D157579

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/global_func_template.cpp
  clang/test/ExtractAPI/global_func_template_spec.cpp

Index: clang/test/ExtractAPI/global_func_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/global_func_template_spec.cpp
@@ -0,0 +1,299 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template void Foo(T Bar);
+
+template<> void Foo(int Bar);
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ");"
+}
+  ],
+  "functionSignature": {
+"parameters": [
+  {
+"declarationFragments": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:t0.0",
+"spelling": "T"
+  },
+  {
+"kind": "text",
+"spelling": " "
+  },
+  {
+"kind": "internalParam",
+"spelling": "Bar"
+  }
+],
+"name": "Bar"
+  }
+],
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:v",
+"spelling": "void"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@FT@>1#TFoo#t0.0#v#"
+  },
+  "kind": {
+"displayName": "Function Template",
+"identifier": "c++.func"
+  },
+  "location": {
+"position": {
+  "character": 27,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters"

[PATCH] D157350: [clang][ExtractAPI] Add support for C++ variable templates

2023-08-16 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 550950.
evelez7 added a comment.

Forgot Spec instance in SerializerBase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157350/new/

https://reviews.llvm.org/D157350

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/global_var_template.cpp
  clang/test/ExtractAPI/global_var_template_partial_spec.cpp
  clang/test/ExtractAPI/global_var_template_spec.cpp

Index: clang/test/ExtractAPI/global_var_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/global_var_template_spec.cpp
@@ -0,0 +1,207 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template T Foo = T(3.14);
+
+template<> int Foo;
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@Foo"
+  },
+  "kind": {
+"displayName": "Global Variable Template",
+"identifier": "c++.var"
+  },
+  "location": {
+"position": {
+  "character": 24,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": ">;"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@Foo>#I"
+  },
+  "ki

[PATCH] D158027: [clang][ExtractAPI] Visit method templates with better scheme

2023-08-16 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 550953.
evelez7 added a comment.

Update Spec naming


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158027/new/

https://reviews.llvm.org/D158027

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/method_template.cpp
  clang/test/ExtractAPI/method_template_spec.cpp

Index: clang/test/ExtractAPI/method_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/method_template_spec.cpp
@@ -0,0 +1,371 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {
+  template void Bar(T Fizz);
+
+  template<> void Bar(int Fizz);
+};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@FT@>1#TBar#t0.0#v#",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@F@Bar<#I>#I#",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "private",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "Fizz"
+},
+{
+  "kind": "text",
+  "spelling": ");"
+}
+  ],
+  "functionSignature": {
+"parameters": [
+  {
+"declarationFragments": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:t0.0

[PATCH] D158029: [clang][ExtractAPI] Add support for C++ member templates

2023-08-16 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 550958.
evelez7 added a comment.

Update to use the new Template class constructor instead of old getFragments.

Also better functional style for appending.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158029/new/

https://reviews.llvm.org/D158029

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/field_template.cpp

Index: clang/test/ExtractAPI/field_template.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/field_template.cpp
@@ -0,0 +1,206 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {
+  template static T Bar;
+};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@Bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "private",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "static"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo@Bar"
+  },
+  "kind": {
+"displayName": "Template Property",
+"identifier": "c++.property"
+  },
+  "location": {
+"position": {
+  "character": 33,
+  "line": 2
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"sub

[PATCH] D158031: [clang][ExtractAPI] Refactor C++ method and field visitation

2023-08-17 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 551212.
evelez7 added a comment.

Fix passing Decl's template, introduced from parent updates


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158031/new/

https://reviews.llvm.org/D158031

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/constructor_destructor.cpp
  clang/test/ExtractAPI/methods.cpp

Index: clang/test/ExtractAPI/methods.cpp
===
--- clang/test/ExtractAPI/methods.cpp
+++ clang/test/ExtractAPI/methods.cpp
@@ -64,13 +64,13 @@
 },
 {
   "kind": "memberOf",
-  "source": "c:@S@Foo@F@getFoo#S",
+  "source": "c:@S@Foo@F@getBar#1",
   "target": "c:@S@Foo",
   "targetFallback": "Foo"
 },
 {
   "kind": "memberOf",
-  "source": "c:@S@Foo@F@getBar#1",
+  "source": "c:@S@Foo@F@getFoo#S",
   "target": "c:@S@Foo",
   "targetFallback": "Foo"
 }
@@ -310,11 +310,11 @@
   ]
 },
 {
-  "accessLevel": "public",
+  "accessLevel": "protected",
   "declarationFragments": [
 {
   "kind": "keyword",
-  "spelling": "static"
+  "spelling": "constexpr"
 },
 {
   "kind": "text",
@@ -322,8 +322,8 @@
 },
 {
   "kind": "typeIdentifier",
-  "preciseIdentifier": "c:d",
-  "spelling": "double"
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
 },
 {
   "kind": "text",
@@ -331,34 +331,42 @@
 },
 {
   "kind": "identifier",
-  "spelling": "getFoo"
+  "spelling": "getBar"
 },
 {
   "kind": "text",
-  "spelling": "();"
+  "spelling": "() "
+},
+{
+  "kind": "keyword",
+  "spelling": "const"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "functionSignature": {
 "returns": [
   {
 "kind": "typeIdentifier",
-"preciseIdentifier": "c:d",
-"spelling": "double"
+"preciseIdentifier": "c:I",
+"spelling": "int"
   }
 ]
   },
   "identifier": {
 "interfaceLanguage": "c++",
-"precise": "c:@S@Foo@F@getFoo#S"
+"precise": "c:@S@Foo@F@getBar#1"
   },
   "kind": {
-"displayName": "Static Method",
-"identifier": "c++.type.method"
+"displayName": "Instance Method",
+"identifier": "c++.method"
   },
   "location": {
 "position": {
   "character": 17,
-  "line": 7
+  "line": 10
 },
 "uri": "file://INPUT_DIR/input.h"
   },
@@ -366,28 +374,28 @@
 "navigator": [
   {
 "kind": "identifier",
-"spelling": "getFoo"
+"spelling": "getBar"
   }
 ],
 "subHeading": [
   {
 "kind": "identifier",
-"spelling": "getFoo"
+"spelling": "getBar"
   }
 ],
-"title": "getFoo"
+"title": "getBar"
   },
   "pathComponents": [
 "Foo",
-"getFoo"
+"getBar"
   ]
 },
 {
-  "accessLevel": "protected",
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
-  "spelling": "constexpr"
+  "spelling": "static"
 },
 {
   "kind": "text",
@@ -395,8 +403,8 @@
 },
 {
   "kind": "typeIdentifier",
-  "preciseIdentifier": "c:I",
-  "spelling": "int"
+  "preciseIdentifier": "c:d",
+  "spelling": "double"
 },
 {
   "kind": "text",
@@ -404,42 +412,34 @@
 },
 {
   "kind": "identifier",
-  "spelling": "getBar"
-},
-{
-  "kind": "text",
-  "spelling": "() "
-},
-{
-  "kind": "keyword",
-  "spelling": "const"
+  "spelling": "getFoo"
 },
 {
   "kind": "text",
-  "spelling": ";"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
 "returns": [
   {
 "kind": "typeIdentifier",
-"preciseIdentifier": "c:I",
-"spelling": "int"
+"preciseIdentifier": "c:d",
+"spelling": "double"
   }
 ]
   },
   "identifier": {
 "interfaceLanguage": "c++",
-"precise": "c:@S@Foo@F@getBar#1"
+"precise": "c:@S@Foo@F@getFoo#S"
   },
   

[PATCH] D158239: [clang][ExtractAPI] Add support for namespaces

2023-08-17 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Serialize namespaces, nested namespaces, and class relationships inside them.

Depends on D157076 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158239

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/namespace.cpp
  clang/test/ExtractAPI/nested_namespaces.cpp

Index: clang/test/ExtractAPI/nested_namespaces.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/nested_namespaces.cpp
@@ -0,0 +1,164 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+namespace Foo {
+  namespace Bar { }
+}
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@N@Foo@N@Bar",
+  "target": "c:@N@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "namespace"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@N@Foo"
+  },
+  "kind": {
+"displayName": "Namespace",
+"identifier": "c++.namespace"
+  },
+  "location": {
+"position": {
+  "character": 11,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "namespace"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@N@Foo@N@Bar"
+  },
+  "kind": {
+"displayName": "Namespace",
+"identifier": "c++.namespace"
+  },
+  "location": {
+"position": {
+  "character": 13,
+  "line": 2
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"title": "Bar"
+  },
+  "pathComponents": [
+"Foo",
+"Bar"
+  ]
+}
+  ]
+}
Index: clang/test/ExtractAPI/namespace.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/namespace.cpp
@@ -0,0 +1,164 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// 

[PATCH] D158239: [clang][ExtractAPI] Add support for namespaces

2023-08-17 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 551340.
evelez7 added a comment.

Remove unnecessary line break.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158239/new/

https://reviews.llvm.org/D158239

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/namespace.cpp
  clang/test/ExtractAPI/nested_namespaces.cpp

Index: clang/test/ExtractAPI/nested_namespaces.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/nested_namespaces.cpp
@@ -0,0 +1,164 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+namespace Foo {
+  namespace Bar { }
+}
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@N@Foo@N@Bar",
+  "target": "c:@N@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "namespace"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@N@Foo"
+  },
+  "kind": {
+"displayName": "Namespace",
+"identifier": "c++.namespace"
+  },
+  "location": {
+"position": {
+  "character": 11,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "namespace"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@N@Foo@N@Bar"
+  },
+  "kind": {
+"displayName": "Namespace",
+"identifier": "c++.namespace"
+  },
+  "location": {
+"position": {
+  "character": 13,
+  "line": 2
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"title": "Bar"
+  },
+  "pathComponents": [
+"Foo",
+"Bar"
+  ]
+}
+  ]
+}
Index: clang/test/ExtractAPI/namespace.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/namespace.cpp
@@ -0,0 +1,164 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x

[PATCH] D158239: [clang][ExtractAPI] Add support for namespaces

2023-08-17 Thread Erick Velez via Phabricator via cfe-commits
evelez7 added a comment.

Note that this doesn't handle anonymous namespaces. Similar problems arise with 
anonymous classes/structs, being worked on.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158239/new/

https://reviews.llvm.org/D158239

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158239: [clang][ExtractAPI] Add support for namespaces

2023-08-18 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 551526.
evelez7 added a comment.

Revert extraneous formatting in API.h


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158239/new/

https://reviews.llvm.org/D158239

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/namespace.cpp
  clang/test/ExtractAPI/nested_namespaces.cpp

Index: clang/test/ExtractAPI/nested_namespaces.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/nested_namespaces.cpp
@@ -0,0 +1,164 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+namespace Foo {
+  namespace Bar { }
+}
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@N@Foo@N@Bar",
+  "target": "c:@N@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "namespace"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@N@Foo"
+  },
+  "kind": {
+"displayName": "Namespace",
+"identifier": "c++.namespace"
+  },
+  "location": {
+"position": {
+  "character": 11,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "namespace"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@N@Foo@N@Bar"
+  },
+  "kind": {
+"displayName": "Namespace",
+"identifier": "c++.namespace"
+  },
+  "location": {
+"position": {
+  "character": 13,
+  "line": 2
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"title": "Bar"
+  },
+  "pathComponents": [
+"Foo",
+"Bar"
+  ]
+}
+  ]
+}
Index: clang/test/ExtractAPI/namespace.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/namespace.cpp
@@ -0,0 +1,164 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RU

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-18 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 551591.
evelez7 added a comment.

Fix formatting for introduced declarations in DeclarationFragments.h


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157076/new/

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_param_inheritance.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,206 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo {};
+
+template<> class Foo {};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-18 Thread Erick Velez via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7ba37f4e46a5: [clang][ExtractAPI] Add support for C++ class 
templates and concepts (authored by evelez7).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157076/new/

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_param_inheritance.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,206 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo {}

[PATCH] D157350: [clang][ExtractAPI] Add support for C++ variable templates

2023-08-18 Thread Erick Velez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8d8c8981cac0: [clang][ExtractAPI] Add support for C++ 
variable templates (authored by evelez7).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157350/new/

https://reviews.llvm.org/D157350

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/global_var_template.cpp
  clang/test/ExtractAPI/global_var_template_partial_spec.cpp
  clang/test/ExtractAPI/global_var_template_spec.cpp

Index: clang/test/ExtractAPI/global_var_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/global_var_template_spec.cpp
@@ -0,0 +1,207 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template T Foo = T(3.14);
+
+template<> int Foo;
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@Foo"
+  },
+  "kind": {
+"displayName": "Global Variable Template",
+"identifier": "c++.var"
+  },
+  "location": {
+"position": {
+  "character": 24,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": ">;"
+}
+  ],
+  "identifier": {
+"i

[PATCH] D157579: [clang][ExtractAPI] Add support for C++ global function templates

2023-08-18 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 551642.
evelez7 added a comment.

Formatting changes, keep GlobalFunction has templates together and revert 
extraneous formatting


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157579/new/

https://reviews.llvm.org/D157579

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/global_func_template.cpp
  clang/test/ExtractAPI/global_func_template_spec.cpp

Index: clang/test/ExtractAPI/global_func_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/global_func_template_spec.cpp
@@ -0,0 +1,299 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template void Foo(T Bar);
+
+template<> void Foo(int Bar);
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ");"
+}
+  ],
+  "functionSignature": {
+"parameters": [
+  {
+"declarationFragments": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:t0.0",
+"spelling": "T"
+  },
+  {
+"kind": "text",
+"spelling": " "
+  },
+  {
+"kind": "internalParam",
+"spelling": "Bar"
+  }
+],
+"name": "Bar"
+  }
+],
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:v",
+"spelling": "void"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@FT@>1#TFoo#t0.0#v#"
+  },
+  "kind": {
+"displayName": "Function Template",
+"identifier": "c++.func"
+  },
+  "location": {
+"position": {
+  "character": 27,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  

[PATCH] D157579: [clang][ExtractAPI] Add support for C++ global function templates

2023-08-18 Thread Erick Velez via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG80b787e80329: [clang][ExtractAPI] Add support for C++ global 
function templates (authored by evelez7).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157579/new/

https://reviews.llvm.org/D157579

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/global_func_template.cpp
  clang/test/ExtractAPI/global_func_template_spec.cpp

Index: clang/test/ExtractAPI/global_func_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/global_func_template_spec.cpp
@@ -0,0 +1,299 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template void Foo(T Bar);
+
+template<> void Foo(int Bar);
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ");"
+}
+  ],
+  "functionSignature": {
+"parameters": [
+  {
+"declarationFragments": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:t0.0",
+"spelling": "T"
+  },
+  {
+"kind": "text",
+"spelling": " "
+  },
+  {
+"kind": "internalParam",
+"spelling": "Bar"
+  }
+],
+"name": "Bar"
+  }
+],
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:v",
+"spelling": "void"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@FT@>1#TFoo#t0.0#v#"
+  },
+  "kind": {
+"displayName": "Function Template",
+"identifier": "c++.func"
+  },
+  "location": {
+"position": {
+  "character": 27,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+   

[PATCH] D158027: [clang][ExtractAPI] Visit method templates with better scheme

2023-08-21 Thread Erick Velez via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd8e9c5d9cab5: [clang][ExtractAPI] Visit method templates 
with better scheme (authored by evelez7).

Changed prior to commit:
  https://reviews.llvm.org/D158027?vs=550953&id=552042#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158027/new/

https://reviews.llvm.org/D158027

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/method_template.cpp
  clang/test/ExtractAPI/method_template_spec.cpp

Index: clang/test/ExtractAPI/method_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/method_template_spec.cpp
@@ -0,0 +1,371 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {
+  template void Bar(T Fizz);
+
+  template<> void Bar(int Fizz);
+};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@FT@>1#TBar#t0.0#v#",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@F@Bar<#I>#I#",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "private",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "Fizz"
+},
+{
+  "kind": "text",
+  "spellin

[PATCH] D158029: [clang][ExtractAPI] Add support for C++ member templates

2023-08-21 Thread Erick Velez via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG634b2fd2cac2: [clang][ExtractAPI] Add support for C++ member 
templates (authored by evelez7).

Changed prior to commit:
  https://reviews.llvm.org/D158029?vs=550958&id=552070#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158029/new/

https://reviews.llvm.org/D158029

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/field_template.cpp

Index: clang/test/ExtractAPI/field_template.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/field_template.cpp
@@ -0,0 +1,206 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {
+  template static T Bar;
+};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@Bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "private",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "static"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo@Bar"
+  },
+  "kind": {
+"displayName": "Template Property",
+"identifier": "c++.property"
+  },
+  "location": {
+"position": {
+  "character": 33,
+  "line": 2
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+   

[PATCH] D158031: [clang][ExtractAPI] Refactor C++ method and field visitation

2023-08-21 Thread Erick Velez via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3bb485530869: [clang][ExtractAPI] Refactor C++ method and 
field visitation (authored by evelez7).

Changed prior to commit:
  https://reviews.llvm.org/D158031?vs=551212&id=552076#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158031/new/

https://reviews.llvm.org/D158031

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/constructor_destructor.cpp
  clang/test/ExtractAPI/methods.cpp

Index: clang/test/ExtractAPI/methods.cpp
===
--- clang/test/ExtractAPI/methods.cpp
+++ clang/test/ExtractAPI/methods.cpp
@@ -64,13 +64,13 @@
 },
 {
   "kind": "memberOf",
-  "source": "c:@S@Foo@F@getFoo#S",
+  "source": "c:@S@Foo@F@getBar#1",
   "target": "c:@S@Foo",
   "targetFallback": "Foo"
 },
 {
   "kind": "memberOf",
-  "source": "c:@S@Foo@F@getBar#1",
+  "source": "c:@S@Foo@F@getFoo#S",
   "target": "c:@S@Foo",
   "targetFallback": "Foo"
 }
@@ -310,11 +310,11 @@
   ]
 },
 {
-  "accessLevel": "public",
+  "accessLevel": "protected",
   "declarationFragments": [
 {
   "kind": "keyword",
-  "spelling": "static"
+  "spelling": "constexpr"
 },
 {
   "kind": "text",
@@ -322,8 +322,8 @@
 },
 {
   "kind": "typeIdentifier",
-  "preciseIdentifier": "c:d",
-  "spelling": "double"
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
 },
 {
   "kind": "text",
@@ -331,34 +331,42 @@
 },
 {
   "kind": "identifier",
-  "spelling": "getFoo"
+  "spelling": "getBar"
 },
 {
   "kind": "text",
-  "spelling": "();"
+  "spelling": "() "
+},
+{
+  "kind": "keyword",
+  "spelling": "const"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "functionSignature": {
 "returns": [
   {
 "kind": "typeIdentifier",
-"preciseIdentifier": "c:d",
-"spelling": "double"
+"preciseIdentifier": "c:I",
+"spelling": "int"
   }
 ]
   },
   "identifier": {
 "interfaceLanguage": "c++",
-"precise": "c:@S@Foo@F@getFoo#S"
+"precise": "c:@S@Foo@F@getBar#1"
   },
   "kind": {
-"displayName": "Static Method",
-"identifier": "c++.type.method"
+"displayName": "Instance Method",
+"identifier": "c++.method"
   },
   "location": {
 "position": {
   "character": 17,
-  "line": 7
+  "line": 10
 },
 "uri": "file://INPUT_DIR/input.h"
   },
@@ -366,28 +374,28 @@
 "navigator": [
   {
 "kind": "identifier",
-"spelling": "getFoo"
+"spelling": "getBar"
   }
 ],
 "subHeading": [
   {
 "kind": "identifier",
-"spelling": "getFoo"
+"spelling": "getBar"
   }
 ],
-"title": "getFoo"
+"title": "getBar"
   },
   "pathComponents": [
 "Foo",
-"getFoo"
+"getBar"
   ]
 },
 {
-  "accessLevel": "protected",
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
-  "spelling": "constexpr"
+  "spelling": "static"
 },
 {
   "kind": "text",
@@ -395,8 +403,8 @@
 },
 {
   "kind": "typeIdentifier",
-  "preciseIdentifier": "c:I",
-  "spelling": "int"
+  "preciseIdentifier": "c:d",
+  "spelling": "double"
 },
 {
   "kind": "text",
@@ -404,42 +412,34 @@
 },
 {
   "kind": "identifier",
-  "spelling": "getBar"
-},
-{
-  "kind": "text",
-  "spelling": "() "
-},
-{
-  "kind": "keyword",
-  "spelling": "const"
+  "spelling": "getFoo"
 },
 {
   "kind": "text",
-  "spelling": ";"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
 "returns": [
   {
 "kind": "typeIdentifier",
-"preciseIdentifier": "c:I",
-"spelling": "int"
+"preciseIdentifier": "c:d",
+"spelling": 

[PATCH] D158031: [clang][ExtractAPI] Refactor C++ method and field visitation

2023-08-21 Thread Erick Velez via Phabricator via cfe-commits
evelez7 added a comment.

In D158031#4603363 , @dang wrote:

> Did this change not affect ordering of the symbols in the generated JSON? 
> Looks pretty good to me otherwise!

It only changed method ordering due to them not being grouped together, so 
instance methods always appear before static methods now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158031/new/

https://reviews.llvm.org/D158031

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158239: [clang][ExtractAPI] Add support for namespaces

2023-08-21 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 552155.
evelez7 marked an inline comment as done.
evelez7 added a comment.

Move DetermineParentDecl to determineParentRecord in APIVisitor as a private 
method.

Easier to just let it fetch the record for us and return nullptr if the parent 
is the translation unit.
Also we don't have to cast the Decls to their most derived form for the USR.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158239/new/

https://reviews.llvm.org/D158239

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/namespace.cpp
  clang/test/ExtractAPI/nested_namespaces.cpp

Index: clang/test/ExtractAPI/nested_namespaces.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/nested_namespaces.cpp
@@ -0,0 +1,164 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+namespace Foo {
+  namespace Bar { }
+}
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@N@Foo@N@Bar",
+  "target": "c:@N@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "namespace"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@N@Foo"
+  },
+  "kind": {
+"displayName": "Namespace",
+"identifier": "c++.namespace"
+  },
+  "location": {
+"position": {
+  "character": 11,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "namespace"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@N@Foo@N@Bar"
+  },
+  "kind": {
+"displayName": "Namespace",
+"identifier": "c++.namespace"
+  },
+  "location": {
+"position": {
+  "character": 13,
+  "line": 2
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"title": "Bar"
+  },
+  "pathComponents": [
+"Foo",
+"Bar"
+  ]
+}
+  ]
+}
Index: clang/test/ExtractAPI/namespace.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/namesp

[PATCH] D158474: [clang][ExtractAPI] Fix bool spelling coming from the macro definition.

2023-08-21 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

getFragmentsForType resulted in a bool typeIdentifier fragment to be spelled 
"_Bool".
This fixes the spelling to be "bool" and checks it in C and C++.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158474

Files:
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/bool.c
  clang/test/ExtractAPI/bool.cpp

Index: clang/test/ExtractAPI/bool.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/bool.cpp
@@ -0,0 +1,203 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+bool Foo;
+
+bool IsFoo(bool Bar);
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:b",
+  "spelling": "bool"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@Foo"
+  },
+  "kind": {
+"displayName": "Global Variable",
+"identifier": "c++.var"
+  },
+  "location": {
+"position": {
+  "character": 6,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:b",
+  "spelling": "bool"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "IsFoo"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:b",
+  "spelling": "bool"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ");"
+}
+  ],
+  "functionSignature": {
+"parameters": [
+  {
+"declarationFragments": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:b",
+"spelling": "bool"
+  },
+  {
+"kind": "text",
+"spelling": " "
+  },
+  {
+"kind": "internalParam",
+"spelling": "Bar"
+  }
+],
+"name": "Bar"
+  }
+],
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:b",
+"spelling": "bool"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@F@IsFoo#b#"
+  },
+  "kind": {
+"displayName": "Function",
+"identifier": "c++.func"
+  },
+  "location": {
+"position": {
+  "character": 6,
+  "line": 3
+},
+"

[PATCH] D158239: [clang][ExtractAPI] Add support for namespaces

2023-08-22 Thread Erick Velez via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG08f034f952fa: [clang][ExtractAPI] Add support for namespaces 
(authored by evelez7).

Changed prior to commit:
  https://reviews.llvm.org/D158239?vs=552155&id=552414#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158239/new/

https://reviews.llvm.org/D158239

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/namespace.cpp
  clang/test/ExtractAPI/nested_namespaces.cpp

Index: clang/test/ExtractAPI/nested_namespaces.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/nested_namespaces.cpp
@@ -0,0 +1,164 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+namespace Foo {
+  namespace Bar { }
+}
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@N@Foo@N@Bar",
+  "target": "c:@N@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "namespace"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@N@Foo"
+  },
+  "kind": {
+"displayName": "Namespace",
+"identifier": "c++.namespace"
+  },
+  "location": {
+"position": {
+  "character": 11,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "namespace"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@N@Foo@N@Bar"
+  },
+  "kind": {
+"displayName": "Namespace",
+"identifier": "c++.namespace"
+  },
+  "location": {
+"position": {
+  "character": 13,
+  "line": 2
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"title": "Bar"
+  },
+  "pathComponents": [
+"Foo",
+"Bar"
+  ]
+}
+  ]
+}
Index: clang/test/ExtractAPI/namespace.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/namespace.cpp
@@ -0,0 +1,164 @@
+// RUN: rm -rf %t
+// RUN: split-file 

[PATCH] D158474: [clang][ExtractAPI] Fix bool spelling coming from the macro definition.

2023-08-22 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 552504.
evelez7 added a comment.

Use clang instead of clang_cc1 like other C tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158474/new/

https://reviews.llvm.org/D158474

Files:
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/bool.c
  clang/test/ExtractAPI/bool.cpp

Index: clang/test/ExtractAPI/bool.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/bool.cpp
@@ -0,0 +1,203 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+bool Foo;
+
+bool IsFoo(bool Bar);
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:b",
+  "spelling": "bool"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@Foo"
+  },
+  "kind": {
+"displayName": "Global Variable",
+"identifier": "c++.var"
+  },
+  "location": {
+"position": {
+  "character": 6,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:b",
+  "spelling": "bool"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "IsFoo"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:b",
+  "spelling": "bool"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ");"
+}
+  ],
+  "functionSignature": {
+"parameters": [
+  {
+"declarationFragments": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:b",
+"spelling": "bool"
+  },
+  {
+"kind": "text",
+"spelling": " "
+  },
+  {
+"kind": "internalParam",
+"spelling": "Bar"
+  }
+],
+"name": "Bar"
+  }
+],
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:b",
+"spelling": "bool"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@F@IsFoo#b#"
+  },
+  "kind": {
+"displayName": "Function",
+"identifier": "c++.func"
+  },
+  "location": {
+"position": {
+  "character": 6,
+  "line": 3
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "IsFoo"
+  }
+],
+"sub

[PATCH] D158474: [clang][ExtractAPI] Fix bool spelling coming from the macro definition.

2023-08-22 Thread Erick Velez via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe81744563a53: [clang][ExtractAPI] Fix bool spelling coming 
from the macro definition. (authored by evelez7).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158474/new/

https://reviews.llvm.org/D158474

Files:
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/bool.c
  clang/test/ExtractAPI/bool.cpp

Index: clang/test/ExtractAPI/bool.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/bool.cpp
@@ -0,0 +1,203 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+bool Foo;
+
+bool IsFoo(bool Bar);
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:b",
+  "spelling": "bool"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@Foo"
+  },
+  "kind": {
+"displayName": "Global Variable",
+"identifier": "c++.var"
+  },
+  "location": {
+"position": {
+  "character": 6,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:b",
+  "spelling": "bool"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "IsFoo"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:b",
+  "spelling": "bool"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ");"
+}
+  ],
+  "functionSignature": {
+"parameters": [
+  {
+"declarationFragments": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:b",
+"spelling": "bool"
+  },
+  {
+"kind": "text",
+"spelling": " "
+  },
+  {
+"kind": "internalParam",
+"spelling": "Bar"
+  }
+],
+"name": "Bar"
+  }
+],
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:b",
+"spelling": "bool"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@F@IsFoo#b#"
+  },
+  "kind": {
+"displayName": "Function",
+"identifier": "c++.func"
+  },
+  "location": {
+"position": {
+  "character": 6,
+  "line": 3
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+   

[PATCH] D154038: [clang][ExtractAPI] Add semicolons to vars and fields and to test reference JSON

2023-07-31 Thread Erick Velez via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG422bcd10c48b: [clang][ExtractAPI] Add semicolons to vars and 
fields and to test reference JSON (authored by evelez7).

Changed prior to commit:
  https://reviews.llvm.org/D154038?vs=536245&id=545925#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154038/new/

https://reviews.llvm.org/D154038

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/anonymous_record_no_typedef.c
  clang/test/ExtractAPI/global_record.c
  clang/test/ExtractAPI/global_record_multifile.c
  clang/test/ExtractAPI/known_files_only.c
  clang/test/ExtractAPI/language.c
  clang/test/ExtractAPI/objc_interface.m
  clang/test/ExtractAPI/relative_include.m
  clang/test/ExtractAPI/struct.c
  clang/test/ExtractAPI/typedef_struct_enum.c
  clang/test/ExtractAPI/underscored.c

Index: clang/test/ExtractAPI/underscored.c
===
--- clang/test/ExtractAPI/underscored.c
+++ clang/test/ExtractAPI/underscored.c
@@ -85,6 +85,10 @@
 {
   "kind": "identifier",
   "spelling": "exposed_global"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -190,6 +194,10 @@
 {
   "kind": "identifier",
   "spelling": "a"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/typedef_struct_enum.c
===
--- clang/test/ExtractAPI/typedef_struct_enum.c
+++ clang/test/ExtractAPI/typedef_struct_enum.c
@@ -328,6 +328,10 @@
 {
   "kind": "identifier",
   "spelling": "bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/struct.c
===
--- clang/test/ExtractAPI/struct.c
+++ clang/test/ExtractAPI/struct.c
@@ -161,6 +161,10 @@
 {
   "kind": "identifier",
   "spelling": "Red"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -213,6 +217,10 @@
 {
   "kind": "identifier",
   "spelling": "Green"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -265,6 +273,10 @@
 {
   "kind": "identifier",
   "spelling": "Blue"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -317,6 +329,10 @@
 {
   "kind": "identifier",
   "spelling": "Alpha"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "docComment": {
Index: clang/test/ExtractAPI/relative_include.m
===
--- clang/test/ExtractAPI/relative_include.m
+++ clang/test/ExtractAPI/relative_include.m
@@ -102,6 +102,10 @@
 {
   "kind": "identifier",
   "spelling": "MyInt"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -153,6 +157,10 @@
 {
   "kind": "identifier",
   "spelling": "MyChar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/objc_interface.m
===
--- clang/test/ExtractAPI/objc_interface.m
+++ clang/test/ExtractAPI/objc_interface.m
@@ -579,6 +579,10 @@
 {
   "kind": "identifier",
   "spelling": "Ivar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/language.c
===
--- clang/test/ExtractAPI/language.c
+++ clang/test/ExtractAPI/language.c
@@ -70,6 +70,10 @@
 {
   "kind": "identifier",
   "spelling": "c"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -150,6 +154,10 @@
 {
   "kind": "identifier",
   "spelling": "objc"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/known_files_only.c
===
--- clang/test/ExtractAPI/known_files_only.c
+++ clang/test/ExtractAPI/known_files_only.c
@@ -66,6 +66,10 @@
 {
   "kind": "ident

[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-08-01 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 546317.
evelez7 marked 4 inline comments as done.
evelez7 added a comment.

Address review feedback, add tests, and small refactors.

- Add tests for destructors, constructors, and conversion methods.
- Remove redundant check-nots in existing tests.
- Properly record destructor names.
- Add explicit qualifier to conversions.
- Remove unused code from getFragmentsForSpecialCXXMethod.
- Use appendSpace isntead of literals in keyword fragments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class.cpp
  clang/test/ExtractAPI/constructor_destructor.cpp
  clang/test/ExtractAPI/conversions.cpp
  clang/test/ExtractAPI/function_noexcepts.cpp
  clang/test/ExtractAPI/methods.cpp
  clang/test/ExtractAPI/multiple_inheritance.cpp
  clang/test/ExtractAPI/simple_inheritance.cpp

Index: clang/test/ExtractAPI/simple_inheritance.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/simple_inheritance.cpp
@@ -0,0 +1,162 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang++ -extract-api -target arm64-apple-macosx -x c++-header \
+// RUN: %t/input.h -o %t/output.json -Xclang -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {};
+
+class Bar : public Foo {};
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "inheritsFrom",
+  "source": "c:@S@Bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Bar"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 3
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+

[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-08-01 Thread Erick Velez via Phabricator via cfe-commits
evelez7 added inline comments.



Comment at: clang/include/clang/ExtractAPI/API.h:770
+template <>
+struct has_function_signature : public std::true_type {};
+

dang wrote:
> Does `CXXInstanceMethodRecord` need one of these as well?
`CXXInstanceMethodRecord` inherits from `CXXMethodRecord` which holds the 
signature for all methods.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-08-01 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 546323.
evelez7 added a comment.

Add test for overloaded operator.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class.cpp
  clang/test/ExtractAPI/constructor_destructor.cpp
  clang/test/ExtractAPI/conversions.cpp
  clang/test/ExtractAPI/function_noexcepts.cpp
  clang/test/ExtractAPI/methods.cpp
  clang/test/ExtractAPI/multiple_inheritance.cpp
  clang/test/ExtractAPI/operator_overload.cpp
  clang/test/ExtractAPI/simple_inheritance.cpp

Index: clang/test/ExtractAPI/simple_inheritance.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/simple_inheritance.cpp
@@ -0,0 +1,162 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang++ -extract-api -target arm64-apple-macosx -x c++-header \
+// RUN: %t/input.h -o %t/output.json -Xclang -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {};
+
+class Bar : public Foo {};
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "inheritsFrom",
+  "source": "c:@S@Bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Bar"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 3
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"title": "Bar"
+  },
+  "pathComponents": [
+"Bar"
+  ]
+}
+  ]
+}
Index: clang/test/ExtractAPI/operator_overload.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/operator_overload.cpp
@@ -0,0 +1,210 @@
+// RUN: rm -rf %t
+//

[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-08-02 Thread Erick Velez via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8b76b44e46ac: [clang][ExtractAPI] Add support for C++ 
classes (authored by evelez7).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class.cpp
  clang/test/ExtractAPI/constructor_destructor.cpp
  clang/test/ExtractAPI/conversions.cpp
  clang/test/ExtractAPI/function_noexcepts.cpp
  clang/test/ExtractAPI/methods.cpp
  clang/test/ExtractAPI/multiple_inheritance.cpp
  clang/test/ExtractAPI/operator_overload.cpp
  clang/test/ExtractAPI/simple_inheritance.cpp

Index: clang/test/ExtractAPI/simple_inheritance.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/simple_inheritance.cpp
@@ -0,0 +1,162 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang++ -extract-api -target arm64-apple-macosx -x c++-header \
+// RUN: %t/input.h -o %t/output.json -Xclang -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {};
+
+class Bar : public Foo {};
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "inheritsFrom",
+  "source": "c:@S@Bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Bar"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 3
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"title": "Bar"
+  },
+  "pathComponents": [
+"Bar"
+  ]
+}
+  ]
+}
Index: clang/test/ExtractAPI/operator_overload.cpp
==

[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-08-02 Thread Erick Velez via Phabricator via cfe-commits
evelez7 added a comment.

In D153557#4554980 , @haowei wrote:

> Hi, we are seeing a test error on `Clang :: 
> ExtractAPI/constructor_destructor.cpp` after this patch was landed. Error 
> message:

Hi! Sorry about that, I see you've made some changes. Do you still need me to 
revert this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-08-02 Thread Erick Velez via Phabricator via cfe-commits
evelez7 added a comment.

@haowei Thank you for letting me know! That patch does seem to fix it, 
unfortunately it didn't fail on my end. Thanks again.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-08-02 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 546635.
evelez7 added a comment.

Reintroduce fix from f4de606ef271 
 and use 
clang frontend for C++ tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class.cpp
  clang/test/ExtractAPI/constructor_destructor.cpp
  clang/test/ExtractAPI/conversions.cpp
  clang/test/ExtractAPI/function_noexcepts.cpp
  clang/test/ExtractAPI/methods.cpp
  clang/test/ExtractAPI/multiple_inheritance.cpp
  clang/test/ExtractAPI/operator_overload.cpp
  clang/test/ExtractAPI/simple_inheritance.cpp

Index: clang/test/ExtractAPI/simple_inheritance.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/simple_inheritance.cpp
@@ -0,0 +1,162 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {};
+
+class Bar : public Foo {};
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "inheritsFrom",
+  "source": "c:@S@Bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Bar"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 3
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"title": "Bar"
+  },
+  "pathComponents": [
+"Bar"
+  ]
+}
+  ]
+}
Index: clang/test/ExtractAPI/operator_overload.cpp

[PATCH] D157007: [clang][ExtractAPI] Add support for C++ classes with fix

2023-08-03 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a subscriber: ChuanqiXu.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Reintroduce D153557  with fix for 
use-after-free from f4de606ef271 
 and minor 
changes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157007

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class.cpp
  clang/test/ExtractAPI/constructor_destructor.cpp
  clang/test/ExtractAPI/conversions.cpp
  clang/test/ExtractAPI/function_noexcepts.cpp
  clang/test/ExtractAPI/methods.cpp
  clang/test/ExtractAPI/multiple_inheritance.cpp
  clang/test/ExtractAPI/operator_overload.cpp
  clang/test/ExtractAPI/simple_inheritance.cpp

Index: clang/test/ExtractAPI/simple_inheritance.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/simple_inheritance.cpp
@@ -0,0 +1,162 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {};
+
+class Bar : public Foo {};
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "inheritsFrom",
+  "source": "c:@S@Bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Bar"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 3
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"title": "Bar"
+

[PATCH] D157007: [clang][ExtractAPI] Add support for C++ classes with fix

2023-08-03 Thread Erick Velez via Phabricator via cfe-commits
evelez7 added inline comments.



Comment at: clang/lib/ExtractAPI/DeclarationFragments.cpp:612
+  if (isa(Method)) {
+Name = Method->getNameAsString();
+if (dyn_cast(Method)->isExplicit())

Minor change is here. Since `Name` is now an `std::string`, a cast to 
`Method`'s DeclContext is no longer needed to bypass the simple identifier 
assertion from `getName` for StringRefs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157007/new/

https://reviews.llvm.org/D157007

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157075: [clang][ExtractAPI] Add support for C++ class templates and concepts Depends on D157007

2023-08-04 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add has_template template, DeclarationFragments, and serialization for class 
templates and concepts.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157075

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,205 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo {};
+
+template<> class Foo {};
+
+/// ex

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-04 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add has_template template, DeclarationFragmentBuilder functions, and tests for 
class templates, specializations/partial specs, and concepts.

Depends on D157007 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,205 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-04 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 547265.
evelez7 added a comment.

Format DeclarationFragments.h, try to address buildbot fail on clang-format


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157076/new/

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,205 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo {};
+
+template<> class Foo {};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "mi

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-04 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 547314.
evelez7 added a comment.

Add documentation to template argument name deduction, add missing method 
declarations to visitor base


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157076/new/

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,205 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo {};
+
+template<> class Foo {};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-04 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 547389.
evelez7 added a comment.

Abstract the name deduction for generic template args to its own function. It's 
very helpful in other cases.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157076/new/

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,206 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo {};
+
+template<> class Foo {};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-07 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 547971.
evelez7 added a comment.

Refactor template arg name deduction to get as string for 
FragmentKind::typeIdentifier


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157076/new/

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,206 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo {};
+
+template<> class Foo {};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0

[PATCH] D157350: [clang][ExtractAPI] Add support for C++ variable templates

2023-08-07 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Serialize global C++ variable templates and specializations.

Depends on D157076 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157350

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/global_var_template.cpp
  clang/test/ExtractAPI/global_var_template_partial_spec.cpp
  clang/test/ExtractAPI/global_var_template_spec.cpp

Index: clang/test/ExtractAPI/global_var_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/global_var_template_spec.cpp
@@ -0,0 +1,207 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template T Foo = T(3.14);
+
+template<> int Foo;
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@Foo"
+  },
+  "kind": {
+"displayName": "Global Variable Template",
+"identifier": "c++.var"
+  },
+  "location": {
+"position": {
+  "character": 24,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+   

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-07 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 548042.
evelez7 added a comment.

Add brackets for SerializerBase visit methods


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157076/new/

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,206 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo {};
+
+template<> class Foo {};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+  

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-09 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 548862.
evelez7 added a comment.

Fix template arg identification


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157076/new/

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,206 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo {};
+
+template<> class Foo {};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"gen

[PATCH] D157579: [clang][ExtractAPI] Add support for C++ global function templates

2023-08-09 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add records, serialization for global function templates and their 
specializations

Depends on D157350 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157579

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/global_func_template.cpp
  clang/test/ExtractAPI/global_func_template_spec.cpp

Index: clang/test/ExtractAPI/global_func_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/global_func_template_spec.cpp
@@ -0,0 +1,299 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template void Foo(T Bar);
+
+template<> void Foo(int Bar);
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ");"
+}
+  ],
+  "functionSignature": {
+"parameters": [
+  {
+"declarationFragments": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:t0.0",
+"spelling": "T"
+  },
+  {
+"kind": "text",
+"spelling": " "
+  },
+  {
+"kind": "internalParam",
+"spelling": "Bar"
+  }
+],
+"name": "Bar"
+  }
+],
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:v",
+"spelling": "void"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@FT@>1#TFoo#t0.0#v#"
+  },
+  "kind": {
+"displayName": "Function Template",
+"identifier": "c++.func"
+  },
+  "location": {
+"position": {
+  "character": 27,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "ide

[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-06-22 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a subscriber: ChuanqiXu.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add ExtractAPI support C++ classes, fields,  methods, and various qualifiers 
and specifiers


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -366,6 +366,38 @@
 Kind["identifier"] = AddLangPrefix("struct");
 Kind["displayName"] = "Structure";
 break;
+  case APIRecord::RK_CXXField:
+Kind["identifier"] = AddLangPrefix("property");
+Kind["displayName"] = "Instance Property";
+break;
+  case APIRecord::RK_Union:
+Kind["identifier"] = AddLangPrefix("union");
+Kind["displayName"] = "Union";
+break;
+  case APIRecord::RK_StaticField:
+Kind["identifier"] = AddLangPrefix("type.property");
+Kind["displayName"] = "Type Property";
+break;
+  case APIRecord::RK_CXXClass:
+Kind["identifier"] = AddLangPrefix("class");
+Kind["displayName"] = "Class";
+break;
+  case APIRecord::RK_CXXStaticMethod:
+Kind["identifier"] = AddLangPrefix("type.method");
+Kind["displayName"] = "Static Method";
+break;
+  case APIRecord::RK_CXXInstanceMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Instance Method";
+break;
+  case APIRecord::RK_CXXConstructorMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Constructor";
+break;
+  case APIRecord::RK_CXXDestructorMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Destructor";
+break;
   case APIRecord::RK_ObjCIvar:
 Kind["identifier"] = AddLangPrefix("ivar");
 Kind["displayName"] = "Instance Variable";
@@ -543,7 +575,6 @@
 
   return ParentContexts;
 }
-
 } // namespace
 
 /// Defines the format version emitted by SymbolGraphSerializer.
@@ -698,6 +729,28 @@
   serializeMembers(Record, Record.Fields);
 }
 
+void SymbolGraphSerializer::visitStaticFieldRecord(
+const StaticFieldRecord &Record) {
+  auto StaticField = serializeAPIRecord(Record);
+  if (!StaticField)
+return;
+  Symbols.emplace_back(std::move(*StaticField));
+  serializeRelationship(RelationshipKind::MemberOf, Record, Record.Context);
+}
+
+void SymbolGraphSerializer::visitCXXClassRecord(const CXXClassRecord &Record) {
+  auto Class = serializeAPIRecord(Record);
+  if (!Class)
+return;
+
+  Symbols.emplace_back(std::move(*Class));
+  serializeMembers(Record, Record.Fields);
+  serializeMembers(Record, Record.Methods);
+
+  for (const auto Base : Record.Bases)
+serializeRelationship(RelationshipKind::InheritsFrom, Record, Base);
+}
+
 void SymbolGraphSerializer::visitObjCContainerRecord(
 const ObjCContainerRecord &Record) {
   auto ObjCContainer = serializeAPIRecord(Record);
@@ -761,6 +814,12 @@
   case APIRecord::RK_Struct:
 visitStructRecord(*cast(Record));
 break;
+  case APIRecord::RK_StaticField:
+visitStaticFieldRecord(*cast(Record));
+break;
+  case APIRecord::RK_CXXClass:
+visitCXXClassRecord(*cast(Record));
+break;
   case APIRecord::RK_ObjCInterface:
 visitObjCContainerRecord(*cast(Record));
 break;
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -12,8 +12,10 @@
 //===--===//
 
 #include "clang/ExtractAPI/DeclarationFragments.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/ExtractAPI/TypedefUnderlyingTypeResolver.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Parse/Parser.h"
 #include "llvm/ADT/StringSwitch.h"
 
 using namespace clang::extractapi;
@@ -84,6 +86,43 @@
   .Default(DeclarationFragments::FragmentKind::None);
 }
 
+DeclarationFragments DeclarationFragments::getExceptionSpecificationString(
+ExceptionSpecificationType ExceptionSpec) {
+  DeclarationFragments Fragments;
+  switch (ExceptionSpec) {
+  case ExceptionSpecificationType::EST_BasicNoexcept:
+Fragments.append(" noexcept", DeclarationFragments::Fra

[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-06-22 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 533788.
evelez7 added a comment.

Add access control serialization


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -17,6 +17,7 @@
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Path.h"
@@ -38,6 +39,14 @@
 Paren[Key] = std::move(*Obj);
 }
 
+/// Helper function to inject a StringRef \p String into an object \p Paren at
+/// position \p Key
+void serializeString(Object &Paren, StringRef Key,
+ std::optional String) {
+  if (String)
+Paren[Key] = std::move(*String);
+}
+
 /// Helper function to inject a JSON array \p Array into object \p Paren at
 /// position \p Key.
 void serializeArray(Object &Paren, StringRef Key, std::optional Array) {
@@ -366,6 +375,38 @@
 Kind["identifier"] = AddLangPrefix("struct");
 Kind["displayName"] = "Structure";
 break;
+  case APIRecord::RK_CXXField:
+Kind["identifier"] = AddLangPrefix("property");
+Kind["displayName"] = "Instance Property";
+break;
+  case APIRecord::RK_Union:
+Kind["identifier"] = AddLangPrefix("union");
+Kind["displayName"] = "Union";
+break;
+  case APIRecord::RK_StaticField:
+Kind["identifier"] = AddLangPrefix("type.property");
+Kind["displayName"] = "Type Property";
+break;
+  case APIRecord::RK_CXXClass:
+Kind["identifier"] = AddLangPrefix("class");
+Kind["displayName"] = "Class";
+break;
+  case APIRecord::RK_CXXStaticMethod:
+Kind["identifier"] = AddLangPrefix("type.method");
+Kind["displayName"] = "Static Method";
+break;
+  case APIRecord::RK_CXXInstanceMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Instance Method";
+break;
+  case APIRecord::RK_CXXConstructorMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Constructor";
+break;
+  case APIRecord::RK_CXXDestructorMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Destructor";
+break;
   case APIRecord::RK_ObjCIvar:
 Kind["identifier"] = AddLangPrefix("ivar");
 Kind["displayName"] = "Instance Variable";
@@ -470,6 +511,31 @@
   Record, has_function_signature()));
 }
 
+template 
+std::optional serializeAccessMixinImpl(const RecordTy &Record,
+  std::true_type) {
+  const auto &AccessControl = Record.Access;
+  StringRef Access;
+  if (AccessControl.empty())
+return std::nullopt;
+  Access = AccessControl.getAccess();
+  return Access;
+}
+
+template 
+std::optional serializeAccessMixinImpl(const RecordTy &Record,
+  std::false_type) {
+  return std::nullopt;
+}
+
+template 
+void serializeAccessMixin(Object &Paren, const RecordTy &Record) {
+  auto accessLevel = serializeAccessMixinImpl(Record, has_access());
+  if (!accessLevel.has_value())
+accessLevel = "public";
+  serializeString(Paren, "accessLevel", accessLevel);
+}
+
 struct PathComponent {
   StringRef USR;
   StringRef Name;
@@ -543,7 +609,6 @@
 
   return ParentContexts;
 }
-
 } // namespace
 
 /// Defines the format version emitted by SymbolGraphSerializer.
@@ -602,9 +667,6 @@
   serializeObject(Obj, "docComment", serializeDocComment(Record.Comment));
   serializeArray(Obj, "declarationFragments",
  serializeDeclarationFragments(Record.Declaration));
-  // TODO: Once we keep track of symbol access information serialize it
-  // correctly here.
-  Obj["accessLevel"] = "public";
   SmallVector PathComponentsNames;
   // If this returns true it indicates that we couldn't find a symbol in the
   // hierarchy.
@@ -617,6 +679,7 @@
   serializeArray(Obj, "pathComponents", Array(PathComponentsNames));
 
   serializeFunctionSignatureMixin(Obj, Record);
+  serializeAccessMixin(Obj, Record);
 
   return Obj;
 }
@@ -698,6 +761,28 @@
   serializeMembers(Record, Record.Fields);
 }
 
+void SymbolGraphSerializer::visitStaticFieldRecord(
+const StaticFieldRecord 

[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-06-22 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 533799.
evelez7 added a comment.

Do not include return types for constructors/destructors


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -17,6 +17,7 @@
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Path.h"
@@ -38,6 +39,14 @@
 Paren[Key] = std::move(*Obj);
 }
 
+/// Helper function to inject a StringRef \p String into an object \p Paren at
+/// position \p Key
+void serializeString(Object &Paren, StringRef Key,
+ std::optional String) {
+  if (String)
+Paren[Key] = std::move(*String);
+}
+
 /// Helper function to inject a JSON array \p Array into object \p Paren at
 /// position \p Key.
 void serializeArray(Object &Paren, StringRef Key, std::optional Array) {
@@ -366,6 +375,38 @@
 Kind["identifier"] = AddLangPrefix("struct");
 Kind["displayName"] = "Structure";
 break;
+  case APIRecord::RK_CXXField:
+Kind["identifier"] = AddLangPrefix("property");
+Kind["displayName"] = "Instance Property";
+break;
+  case APIRecord::RK_Union:
+Kind["identifier"] = AddLangPrefix("union");
+Kind["displayName"] = "Union";
+break;
+  case APIRecord::RK_StaticField:
+Kind["identifier"] = AddLangPrefix("type.property");
+Kind["displayName"] = "Type Property";
+break;
+  case APIRecord::RK_CXXClass:
+Kind["identifier"] = AddLangPrefix("class");
+Kind["displayName"] = "Class";
+break;
+  case APIRecord::RK_CXXStaticMethod:
+Kind["identifier"] = AddLangPrefix("type.method");
+Kind["displayName"] = "Static Method";
+break;
+  case APIRecord::RK_CXXInstanceMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Instance Method";
+break;
+  case APIRecord::RK_CXXConstructorMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Constructor";
+break;
+  case APIRecord::RK_CXXDestructorMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Destructor";
+break;
   case APIRecord::RK_ObjCIvar:
 Kind["identifier"] = AddLangPrefix("ivar");
 Kind["displayName"] = "Instance Variable";
@@ -470,6 +511,31 @@
   Record, has_function_signature()));
 }
 
+template 
+std::optional serializeAccessMixinImpl(const RecordTy &Record,
+  std::true_type) {
+  const auto &AccessControl = Record.Access;
+  StringRef Access;
+  if (AccessControl.empty())
+return std::nullopt;
+  Access = AccessControl.getAccess();
+  return Access;
+}
+
+template 
+std::optional serializeAccessMixinImpl(const RecordTy &Record,
+  std::false_type) {
+  return std::nullopt;
+}
+
+template 
+void serializeAccessMixin(Object &Paren, const RecordTy &Record) {
+  auto accessLevel = serializeAccessMixinImpl(Record, has_access());
+  if (!accessLevel.has_value())
+accessLevel = "public";
+  serializeString(Paren, "accessLevel", accessLevel);
+}
+
 struct PathComponent {
   StringRef USR;
   StringRef Name;
@@ -543,7 +609,6 @@
 
   return ParentContexts;
 }
-
 } // namespace
 
 /// Defines the format version emitted by SymbolGraphSerializer.
@@ -602,9 +667,6 @@
   serializeObject(Obj, "docComment", serializeDocComment(Record.Comment));
   serializeArray(Obj, "declarationFragments",
  serializeDeclarationFragments(Record.Declaration));
-  // TODO: Once we keep track of symbol access information serialize it
-  // correctly here.
-  Obj["accessLevel"] = "public";
   SmallVector PathComponentsNames;
   // If this returns true it indicates that we couldn't find a symbol in the
   // hierarchy.
@@ -617,6 +679,7 @@
   serializeArray(Obj, "pathComponents", Array(PathComponentsNames));
 
   serializeFunctionSignatureMixin(Obj, Record);
+  serializeAccessMixin(Obj, Record);
 
   return Obj;
 }
@@ -698,6 +761,28 @@
   serializeMembers(Record, Record.Fields);
 }
 
+void SymbolGraphSerializer::visitStaticFieldRecord(
+

[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-06-23 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 534060.
evelez7 added a comment.

Fix duplicate visitation of CXXRecordDecls by overloading 
WalkUpFromCXXRecordDecl


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -17,6 +17,7 @@
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Path.h"
@@ -38,6 +39,14 @@
 Paren[Key] = std::move(*Obj);
 }
 
+/// Helper function to inject a StringRef \p String into an object \p Paren at
+/// position \p Key
+void serializeString(Object &Paren, StringRef Key,
+ std::optional String) {
+  if (String)
+Paren[Key] = std::move(*String);
+}
+
 /// Helper function to inject a JSON array \p Array into object \p Paren at
 /// position \p Key.
 void serializeArray(Object &Paren, StringRef Key, std::optional Array) {
@@ -366,6 +375,38 @@
 Kind["identifier"] = AddLangPrefix("struct");
 Kind["displayName"] = "Structure";
 break;
+  case APIRecord::RK_CXXField:
+Kind["identifier"] = AddLangPrefix("property");
+Kind["displayName"] = "Instance Property";
+break;
+  case APIRecord::RK_Union:
+Kind["identifier"] = AddLangPrefix("union");
+Kind["displayName"] = "Union";
+break;
+  case APIRecord::RK_StaticField:
+Kind["identifier"] = AddLangPrefix("type.property");
+Kind["displayName"] = "Type Property";
+break;
+  case APIRecord::RK_CXXClass:
+Kind["identifier"] = AddLangPrefix("class");
+Kind["displayName"] = "Class";
+break;
+  case APIRecord::RK_CXXStaticMethod:
+Kind["identifier"] = AddLangPrefix("type.method");
+Kind["displayName"] = "Static Method";
+break;
+  case APIRecord::RK_CXXInstanceMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Instance Method";
+break;
+  case APIRecord::RK_CXXConstructorMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Constructor";
+break;
+  case APIRecord::RK_CXXDestructorMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Destructor";
+break;
   case APIRecord::RK_ObjCIvar:
 Kind["identifier"] = AddLangPrefix("ivar");
 Kind["displayName"] = "Instance Variable";
@@ -470,6 +511,31 @@
   Record, has_function_signature()));
 }
 
+template 
+std::optional serializeAccessMixinImpl(const RecordTy &Record,
+  std::true_type) {
+  const auto &AccessControl = Record.Access;
+  StringRef Access;
+  if (AccessControl.empty())
+return std::nullopt;
+  Access = AccessControl.getAccess();
+  return Access;
+}
+
+template 
+std::optional serializeAccessMixinImpl(const RecordTy &Record,
+  std::false_type) {
+  return std::nullopt;
+}
+
+template 
+void serializeAccessMixin(Object &Paren, const RecordTy &Record) {
+  auto accessLevel = serializeAccessMixinImpl(Record, has_access());
+  if (!accessLevel.has_value())
+accessLevel = "public";
+  serializeString(Paren, "accessLevel", accessLevel);
+}
+
 struct PathComponent {
   StringRef USR;
   StringRef Name;
@@ -543,7 +609,6 @@
 
   return ParentContexts;
 }
-
 } // namespace
 
 /// Defines the format version emitted by SymbolGraphSerializer.
@@ -602,9 +667,6 @@
   serializeObject(Obj, "docComment", serializeDocComment(Record.Comment));
   serializeArray(Obj, "declarationFragments",
  serializeDeclarationFragments(Record.Declaration));
-  // TODO: Once we keep track of symbol access information serialize it
-  // correctly here.
-  Obj["accessLevel"] = "public";
   SmallVector PathComponentsNames;
   // If this returns true it indicates that we couldn't find a symbol in the
   // hierarchy.
@@ -617,6 +679,7 @@
   serializeArray(Obj, "pathComponents", Array(PathComponentsNames));
 
   serializeFunctionSignatureMixin(Obj, Record);
+  serializeAccessMixin(Obj, Record);
 
   return Obj;
 }
@@ -698,6 +761,28 @@
   serializeMembers(Record, Record.Fields);
 }
 
+void SymbolGraphSerializer::vis

[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-06-23 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 534141.
evelez7 added a comment.

Add conversion function and overloaded operator support


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -17,6 +17,7 @@
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Path.h"
@@ -38,6 +39,14 @@
 Paren[Key] = std::move(*Obj);
 }
 
+/// Helper function to inject a StringRef \p String into an object \p Paren at
+/// position \p Key
+void serializeString(Object &Paren, StringRef Key,
+ std::optional String) {
+  if (String)
+Paren[Key] = std::move(*String);
+}
+
 /// Helper function to inject a JSON array \p Array into object \p Paren at
 /// position \p Key.
 void serializeArray(Object &Paren, StringRef Key, std::optional Array) {
@@ -366,6 +375,38 @@
 Kind["identifier"] = AddLangPrefix("struct");
 Kind["displayName"] = "Structure";
 break;
+  case APIRecord::RK_CXXField:
+Kind["identifier"] = AddLangPrefix("property");
+Kind["displayName"] = "Instance Property";
+break;
+  case APIRecord::RK_Union:
+Kind["identifier"] = AddLangPrefix("union");
+Kind["displayName"] = "Union";
+break;
+  case APIRecord::RK_StaticField:
+Kind["identifier"] = AddLangPrefix("type.property");
+Kind["displayName"] = "Type Property";
+break;
+  case APIRecord::RK_CXXClass:
+Kind["identifier"] = AddLangPrefix("class");
+Kind["displayName"] = "Class";
+break;
+  case APIRecord::RK_CXXStaticMethod:
+Kind["identifier"] = AddLangPrefix("type.method");
+Kind["displayName"] = "Static Method";
+break;
+  case APIRecord::RK_CXXInstanceMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Instance Method";
+break;
+  case APIRecord::RK_CXXConstructorMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Constructor";
+break;
+  case APIRecord::RK_CXXDestructorMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Destructor";
+break;
   case APIRecord::RK_ObjCIvar:
 Kind["identifier"] = AddLangPrefix("ivar");
 Kind["displayName"] = "Instance Variable";
@@ -470,6 +511,31 @@
   Record, has_function_signature()));
 }
 
+template 
+std::optional serializeAccessMixinImpl(const RecordTy &Record,
+  std::true_type) {
+  const auto &AccessControl = Record.Access;
+  StringRef Access;
+  if (AccessControl.empty())
+return std::nullopt;
+  Access = AccessControl.getAccess();
+  return Access;
+}
+
+template 
+std::optional serializeAccessMixinImpl(const RecordTy &Record,
+  std::false_type) {
+  return std::nullopt;
+}
+
+template 
+void serializeAccessMixin(Object &Paren, const RecordTy &Record) {
+  auto accessLevel = serializeAccessMixinImpl(Record, has_access());
+  if (!accessLevel.has_value())
+accessLevel = "public";
+  serializeString(Paren, "accessLevel", accessLevel);
+}
+
 struct PathComponent {
   StringRef USR;
   StringRef Name;
@@ -543,7 +609,6 @@
 
   return ParentContexts;
 }
-
 } // namespace
 
 /// Defines the format version emitted by SymbolGraphSerializer.
@@ -602,9 +667,6 @@
   serializeObject(Obj, "docComment", serializeDocComment(Record.Comment));
   serializeArray(Obj, "declarationFragments",
  serializeDeclarationFragments(Record.Declaration));
-  // TODO: Once we keep track of symbol access information serialize it
-  // correctly here.
-  Obj["accessLevel"] = "public";
   SmallVector PathComponentsNames;
   // If this returns true it indicates that we couldn't find a symbol in the
   // hierarchy.
@@ -617,6 +679,7 @@
   serializeArray(Obj, "pathComponents", Array(PathComponentsNames));
 
   serializeFunctionSignatureMixin(Obj, Record);
+  serializeAccessMixin(Obj, Record);
 
   return Obj;
 }
@@ -698,6 +761,28 @@
   serializeMembers(Record, Record.Fields);
 }
 
+void SymbolGraphSerializer::visitStaticFieldRecord(
+c

[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-06-28 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 535559.
evelez7 marked 6 inline comments as done.
evelez7 added a comment.

Address some review feedback

Remove RK_Struct, RK_Union from CXXClassRecord::classof, use std::string for 
AccessControl, style and remove unused imports


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -38,6 +38,14 @@
 Paren[Key] = std::move(*Obj);
 }
 
+/// Helper function to inject a StringRef \p String into an object \p Paren at
+/// position \p Key
+void serializeString(Object &Paren, StringRef Key,
+ std::optional String) {
+  if (String)
+Paren[Key] = std::move(*String);
+}
+
 /// Helper function to inject a JSON array \p Array into object \p Paren at
 /// position \p Key.
 void serializeArray(Object &Paren, StringRef Key, std::optional Array) {
@@ -366,6 +374,38 @@
 Kind["identifier"] = AddLangPrefix("struct");
 Kind["displayName"] = "Structure";
 break;
+  case APIRecord::RK_CXXField:
+Kind["identifier"] = AddLangPrefix("property");
+Kind["displayName"] = "Instance Property";
+break;
+  case APIRecord::RK_Union:
+Kind["identifier"] = AddLangPrefix("union");
+Kind["displayName"] = "Union";
+break;
+  case APIRecord::RK_StaticField:
+Kind["identifier"] = AddLangPrefix("type.property");
+Kind["displayName"] = "Type Property";
+break;
+  case APIRecord::RK_CXXClass:
+Kind["identifier"] = AddLangPrefix("class");
+Kind["displayName"] = "Class";
+break;
+  case APIRecord::RK_CXXStaticMethod:
+Kind["identifier"] = AddLangPrefix("type.method");
+Kind["displayName"] = "Static Method";
+break;
+  case APIRecord::RK_CXXInstanceMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Instance Method";
+break;
+  case APIRecord::RK_CXXConstructorMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Constructor";
+break;
+  case APIRecord::RK_CXXDestructorMethod:
+Kind["identifier"] = AddLangPrefix("method");
+Kind["displayName"] = "Destructor";
+break;
   case APIRecord::RK_ObjCIvar:
 Kind["identifier"] = AddLangPrefix("ivar");
 Kind["displayName"] = "Instance Variable";
@@ -470,6 +510,31 @@
   Record, has_function_signature()));
 }
 
+template 
+std::optional serializeAccessMixinImpl(const RecordTy &Record,
+std::true_type) {
+  const auto &AccessControl = Record.Access;
+  std::string Access;
+  if (AccessControl.empty())
+return std::nullopt;
+  Access = AccessControl.getAccess();
+  return Access;
+}
+
+template 
+std::optional serializeAccessMixinImpl(const RecordTy &Record,
+std::false_type) {
+  return std::nullopt;
+}
+
+template 
+void serializeAccessMixin(Object &Paren, const RecordTy &Record) {
+  auto accessLevel = serializeAccessMixinImpl(Record, has_access());
+  if (!accessLevel.has_value())
+accessLevel = "public";
+  serializeString(Paren, "accessLevel", accessLevel);
+}
+
 struct PathComponent {
   StringRef USR;
   StringRef Name;
@@ -543,7 +608,6 @@
 
   return ParentContexts;
 }
-
 } // namespace
 
 /// Defines the format version emitted by SymbolGraphSerializer.
@@ -602,9 +666,6 @@
   serializeObject(Obj, "docComment", serializeDocComment(Record.Comment));
   serializeArray(Obj, "declarationFragments",
  serializeDeclarationFragments(Record.Declaration));
-  // TODO: Once we keep track of symbol access information serialize it
-  // correctly here.
-  Obj["accessLevel"] = "public";
   SmallVector PathComponentsNames;
   // If this returns true it indicates that we couldn't find a symbol in the
   // hierarchy.
@@ -617,6 +678,7 @@
   serializeArray(Obj, "pathComponents", Array(PathComponentsNames));
 
   serializeFunctionSignatureMixin(Obj, Record);
+  serializeAccessMixin(Obj, Record);
 
   return Obj;
 }
@@ -698,6 +760,28 @@
   serializeMembers(Record, Record.Fields);
 }
 
+void SymbolGraphSerializer::visitStaticFieldRecord(
+const StaticFieldRecord &Record) {
+  auto StaticField = serializeAPIRecord(Record);
+  if (!StaticField)
+return;
+  Symbols.emplac

[PATCH] D154038: [clang][ExtractAPI] Add semicolons to vars and fields and to test reference JSON

2023-06-28 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a reviewer: dang.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154038

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/anonymous_record_no_typedef.c
  clang/test/ExtractAPI/global_record.c
  clang/test/ExtractAPI/global_record_multifile.c
  clang/test/ExtractAPI/known_files_only.c
  clang/test/ExtractAPI/language.c
  clang/test/ExtractAPI/objc_interface.m
  clang/test/ExtractAPI/relative_include.m
  clang/test/ExtractAPI/struct.c
  clang/test/ExtractAPI/typedef_struct_enum.c
  clang/test/ExtractAPI/underscored.c

Index: clang/test/ExtractAPI/underscored.c
===
--- clang/test/ExtractAPI/underscored.c
+++ clang/test/ExtractAPI/underscored.c
@@ -85,6 +85,10 @@
 {
   "kind": "identifier",
   "spelling": "exposed_global"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -190,6 +194,10 @@
 {
   "kind": "identifier",
   "spelling": "a"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/typedef_struct_enum.c
===
--- clang/test/ExtractAPI/typedef_struct_enum.c
+++ clang/test/ExtractAPI/typedef_struct_enum.c
@@ -328,6 +328,10 @@
 {
   "kind": "identifier",
   "spelling": "bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/struct.c
===
--- clang/test/ExtractAPI/struct.c
+++ clang/test/ExtractAPI/struct.c
@@ -161,6 +161,10 @@
 {
   "kind": "identifier",
   "spelling": "Red"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -213,6 +217,10 @@
 {
   "kind": "identifier",
   "spelling": "Green"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -265,6 +273,10 @@
 {
   "kind": "identifier",
   "spelling": "Blue"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -317,6 +329,10 @@
 {
   "kind": "identifier",
   "spelling": "Alpha"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "docComment": {
Index: clang/test/ExtractAPI/relative_include.m
===
--- clang/test/ExtractAPI/relative_include.m
+++ clang/test/ExtractAPI/relative_include.m
@@ -102,6 +102,10 @@
 {
   "kind": "identifier",
   "spelling": "MyInt"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -153,6 +157,10 @@
 {
   "kind": "identifier",
   "spelling": "MyChar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/objc_interface.m
===
--- clang/test/ExtractAPI/objc_interface.m
+++ clang/test/ExtractAPI/objc_interface.m
@@ -579,6 +579,10 @@
 {
   "kind": "identifier",
   "spelling": "Ivar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/language.c
===
--- clang/test/ExtractAPI/language.c
+++ clang/test/ExtractAPI/language.c
@@ -70,6 +70,10 @@
 {
   "kind": "identifier",
   "spelling": "c"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -150,6 +154,10 @@
 {
   "kind": "identifier",
   "spelling": "objc"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/known_files_only.c
===
--- clang/test/ExtractAPI/known_files_only.c
+++ clang/test/ExtractAPI/known_files_only.c
@@ -66,6 +66,10 @@
 {
   "kind": "identifier",
   "spelling": "num"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/Extr

[PATCH] D154038: [clang][ExtractAPI] Add semicolons to vars and fields and to test reference JSON

2023-06-28 Thread Erick Velez via Phabricator via cfe-commits
evelez7 added a comment.

These updated tests pass locally for me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154038/new/

https://reviews.llvm.org/D154038

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-06-29 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 536071.
evelez7 added a comment.

Add C++ class tests, fix exception spec fragments

- Add tests for single and multiple inheritance, class methods, and functions 
with noexcept.
- Exception spec fragments had a space included in it, moved it to separate 
fragment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class.cpp
  clang/test/ExtractAPI/function_noexcepts.cpp
  clang/test/ExtractAPI/methods.cpp
  clang/test/ExtractAPI/multiple_inheritance.cpp
  clang/test/ExtractAPI/simple_inheritance.cpp

Index: clang/test/ExtractAPI/simple_inheritance.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/simple_inheritance.cpp
@@ -0,0 +1,165 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang++ -extract-api -target arm64-apple-macosx -x c++-header \
+// RUN: %t/input.h -o %t/output.json -Xclang -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+class Foo {};
+
+class Bar : public Foo {};
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "inheritsFrom",
+  "source": "c:@S@Bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Bar"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 3
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"title": "Bar"
+  },
+  "pathComponents": [
+"Bar"
+  ]
+}
+  ]
+}
Index: clang/test/ExtractAPI/multiple_inheritance.cpp
==

[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-06-29 Thread Erick Velez via Phabricator via cfe-commits
evelez7 added a comment.

There aren't any variables or fields in the tests currently, waiting on D154038 
 because of no semicolons in their fragments.




Comment at: clang/lib/ExtractAPI/API.cpp:19
 #include "clang/AST/RawCommentList.h"
+#include "clang/ExtractAPI/DeclarationFragments.h"
 #include "clang/Index/USRGeneration.h"

dang wrote:
> AccessControl should move into API.h so we don't need to pull in 
> DeclarationFragments.h
This include doesn't need to be here, clangd auto-included it. Using 
`FunctionSignature` would've explicitly included it in the first place. 
DeclarationFragments.h is already included in API.h.

I was following `FunctionSignature` as far as where to declare and define. 
Moving `AccessControl` would mean including API.h in DeclarationFragments.h to 
allow `DeclarationFragmentsBuilder::getAccessControl`.



Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:607
-  // correctly here.
-  Obj["accessLevel"] = "public";
   SmallVector PathComponentsNames;

dang wrote:
> We still need all symbols to have an "accessLevel" specifier. Maybe the 
> false_type overload of `serializeAccessMixin` could make "public" the default.
This is done on line 534. "public" is serialized if the returned optional is 
empty.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153557/new/

https://reviews.llvm.org/D153557

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154038: [clang][ExtractAPI] Add semicolons to vars and fields and to test reference JSON

2023-06-30 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 536245.
evelez7 marked an inline comment as done.
evelez7 added a comment.

Move semicolon line below After fragment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154038/new/

https://reviews.llvm.org/D154038

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/anonymous_record_no_typedef.c
  clang/test/ExtractAPI/global_record.c
  clang/test/ExtractAPI/global_record_multifile.c
  clang/test/ExtractAPI/known_files_only.c
  clang/test/ExtractAPI/language.c
  clang/test/ExtractAPI/objc_interface.m
  clang/test/ExtractAPI/relative_include.m
  clang/test/ExtractAPI/struct.c
  clang/test/ExtractAPI/typedef_struct_enum.c
  clang/test/ExtractAPI/underscored.c

Index: clang/test/ExtractAPI/underscored.c
===
--- clang/test/ExtractAPI/underscored.c
+++ clang/test/ExtractAPI/underscored.c
@@ -85,6 +85,10 @@
 {
   "kind": "identifier",
   "spelling": "exposed_global"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -190,6 +194,10 @@
 {
   "kind": "identifier",
   "spelling": "a"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/typedef_struct_enum.c
===
--- clang/test/ExtractAPI/typedef_struct_enum.c
+++ clang/test/ExtractAPI/typedef_struct_enum.c
@@ -328,6 +328,10 @@
 {
   "kind": "identifier",
   "spelling": "bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/struct.c
===
--- clang/test/ExtractAPI/struct.c
+++ clang/test/ExtractAPI/struct.c
@@ -161,6 +161,10 @@
 {
   "kind": "identifier",
   "spelling": "Red"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -213,6 +217,10 @@
 {
   "kind": "identifier",
   "spelling": "Green"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -265,6 +273,10 @@
 {
   "kind": "identifier",
   "spelling": "Blue"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -317,6 +329,10 @@
 {
   "kind": "identifier",
   "spelling": "Alpha"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "docComment": {
Index: clang/test/ExtractAPI/relative_include.m
===
--- clang/test/ExtractAPI/relative_include.m
+++ clang/test/ExtractAPI/relative_include.m
@@ -102,6 +102,10 @@
 {
   "kind": "identifier",
   "spelling": "MyInt"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -153,6 +157,10 @@
 {
   "kind": "identifier",
   "spelling": "MyChar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/objc_interface.m
===
--- clang/test/ExtractAPI/objc_interface.m
+++ clang/test/ExtractAPI/objc_interface.m
@@ -579,6 +579,10 @@
 {
   "kind": "identifier",
   "spelling": "Ivar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/language.c
===
--- clang/test/ExtractAPI/language.c
+++ clang/test/ExtractAPI/language.c
@@ -70,6 +70,10 @@
 {
   "kind": "identifier",
   "spelling": "c"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -150,6 +154,10 @@
 {
   "kind": "identifier",
   "spelling": "objc"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/known_files_only.c
===
--- clang/test/ExtractAPI/known_files_only.c
+++ clang/test/ExtractAPI/known_files_only.c
@@ -66,6 +66,10 @@
 {
   "kind": "identifier",
   "spelling": "num"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/global_rec

[PATCH] D151293: [clang][ExtractAPI] Refactor serializer to the CRTP

2023-05-23 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a reviewer: dang.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Refactor SerializerBase and SymbolGraphSerializer to use a visitor pattern 
described by the CRTP.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151293

Files:
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SerializerBase.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -38,14 +38,14 @@
 
 /// Helper function to inject a JSON object \p Obj into another object \p Paren
 /// at position \p Key.
-void serializeObject(Object &Paren, StringRef Key, std::optional Obj) {
+void visitObject(Object &Paren, StringRef Key, std::optional Obj) {
   if (Obj)
 Paren[Key] = std::move(*Obj);
 }
 
 /// Helper function to inject a JSON array \p Array into object \p Paren at
 /// position \p Key.
-void serializeArray(Object &Paren, StringRef Key, std::optional Array) {
+void visitArray(Object &Paren, StringRef Key, std::optional Array) {
   if (Array)
 Paren[Key] = std::move(*Array);
 }
@@ -66,7 +66,7 @@
 ///
 /// \returns \c std::nullopt if the version \p V is empty, or an \c Object
 /// containing the semantic version representation of \p V.
-std::optional serializeSemanticVersion(const VersionTuple &V) {
+std::optional visitSemanticVersion(const VersionTuple &V) {
   if (V.empty())
 return std::nullopt;
 
@@ -81,11 +81,11 @@
 ///
 /// The OS information in Symbol Graph contains the \c name of the OS, and an
 /// optional \c minimumVersion semantic version field.
-Object serializeOperatingSystem(const Triple &T) {
+Object visitOperatingSystem(const Triple &T) {
   Object OS;
   OS["name"] = T.getOSTypeName(T.getOS());
-  serializeObject(OS, "minimumVersion",
-  serializeSemanticVersion(T.getMinimumSupportedOSVersion()));
+  visitObject(OS, "minimumVersion",
+  visitSemanticVersion(T.getMinimumSupportedOSVersion()));
   return OS;
 }
 
@@ -93,16 +93,16 @@
 ///
 /// The platform object describes a target platform triple in corresponding
 /// three fields: \c architecture, \c vendor, and \c operatingSystem.
-Object serializePlatform(const Triple &T) {
+Object visitPlatform(const Triple &T) {
   Object Platform;
   Platform["architecture"] = T.getArchName();
   Platform["vendor"] = T.getVendorName();
-  Platform["operatingSystem"] = serializeOperatingSystem(T);
+  Platform["operatingSystem"] = visitOperatingSystem(T);
   return Platform;
 }
 
 /// Serialize a source position.
-Object serializeSourcePosition(const PresumedLoc &Loc) {
+Object visitSourcePosition(const PresumedLoc &Loc) {
   assert(Loc.isValid() && "invalid source position");
 
   Object SourcePosition;
@@ -117,10 +117,10 @@
 /// \param Loc The presumed location to serialize.
 /// \param IncludeFileURI If true, include the file path of \p Loc as a URI.
 /// Defaults to false.
-Object serializeSourceLocation(const PresumedLoc &Loc,
-   bool IncludeFileURI = false) {
+Object visitSourceLocation(const PresumedLoc &Loc,
+   bool IncludeFileURI = false) {
   Object SourceLocation;
-  serializeObject(SourceLocation, "position", serializeSourcePosition(Loc));
+  visitObject(SourceLocation, "position", visitSourcePosition(Loc));
 
   if (IncludeFileURI) {
 std::string FileURI = "file://";
@@ -133,11 +133,11 @@
 }
 
 /// Serialize a source range with begin and end locations.
-Object serializeSourceRange(const PresumedLoc &BeginLoc,
-const PresumedLoc &EndLoc) {
+Object visitSourceRange(const PresumedLoc &BeginLoc,
+const PresumedLoc &EndLoc) {
   Object SourceRange;
-  serializeObject(SourceRange, "start", serializeSourcePosition(BeginLoc));
-  serializeObject(SourceRange, "end", serializeSourcePosition(EndLoc));
+  visitObject(SourceRange, "start", visitSourcePosition(BeginLoc));
+  visitObject(SourceRange, "end", visitSourcePosition(EndLoc));
   return SourceRange;
 }
 
@@ -152,8 +152,7 @@
 ///
 /// \returns \c std::nullopt if the symbol has default availability attributes,
 /// or an \c Array containing the formatted availability information.
-std::optional
-serializeAvailability(const AvailabilitySet &Availabilities) {
+std::optional visitAvailability(const AvailabilitySet &Availabilities) {
   if (Availabilities.isDefault())
 return std::nullopt;
 
@@ -174,12 +173,12 @@
 

[PATCH] D151402: Address some review feedback

2023-05-24 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a reviewer: dang.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Delete unnecessary includes, revert SymbolGraphSerializer hidden
namespace function names, move IgnoresList, Options to SGS

Depends on D151293 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151402

Files:
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -14,16 +14,11 @@
 #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Version.h"
-#include "clang/ExtractAPI/API.h"
-#include "clang/ExtractAPI/APIIgnoresList.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
-#include "clang/ExtractAPI/Serialization/SerializerBase.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/JSON.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/VersionTuple.h"
 #include 
@@ -38,14 +33,14 @@
 
 /// Helper function to inject a JSON object \p Obj into another object \p Paren
 /// at position \p Key.
-void visitObject(Object &Paren, StringRef Key, std::optional Obj) {
+void serializeObject(Object &Paren, StringRef Key, std::optional Obj) {
   if (Obj)
 Paren[Key] = std::move(*Obj);
 }
 
 /// Helper function to inject a JSON array \p Array into object \p Paren at
 /// position \p Key.
-void visitArray(Object &Paren, StringRef Key, std::optional Array) {
+void serializeArray(Object &Paren, StringRef Key, std::optional Array) {
   if (Array)
 Paren[Key] = std::move(*Array);
 }
@@ -66,7 +61,7 @@
 ///
 /// \returns \c std::nullopt if the version \p V is empty, or an \c Object
 /// containing the semantic version representation of \p V.
-std::optional visitSemanticVersion(const VersionTuple &V) {
+std::optional serializeSemanticVersion(const VersionTuple &V) {
   if (V.empty())
 return std::nullopt;
 
@@ -81,11 +76,11 @@
 ///
 /// The OS information in Symbol Graph contains the \c name of the OS, and an
 /// optional \c minimumVersion semantic version field.
-Object visitOperatingSystem(const Triple &T) {
+Object serializeOperatingSystem(const Triple &T) {
   Object OS;
   OS["name"] = T.getOSTypeName(T.getOS());
-  visitObject(OS, "minimumVersion",
-  visitSemanticVersion(T.getMinimumSupportedOSVersion()));
+  serializeObject(OS, "minimumVersion",
+  serializeSemanticVersion(T.getMinimumSupportedOSVersion()));
   return OS;
 }
 
@@ -93,16 +88,16 @@
 ///
 /// The platform object describes a target platform triple in corresponding
 /// three fields: \c architecture, \c vendor, and \c operatingSystem.
-Object visitPlatform(const Triple &T) {
+Object serializePlatform(const Triple &T) {
   Object Platform;
   Platform["architecture"] = T.getArchName();
   Platform["vendor"] = T.getVendorName();
-  Platform["operatingSystem"] = visitOperatingSystem(T);
+  Platform["operatingSystem"] = serializeOperatingSystem(T);
   return Platform;
 }
 
 /// Serialize a source position.
-Object visitSourcePosition(const PresumedLoc &Loc) {
+Object serializeSourcePosition(const PresumedLoc &Loc) {
   assert(Loc.isValid() && "invalid source position");
 
   Object SourcePosition;
@@ -117,10 +112,10 @@
 /// \param Loc The presumed location to serialize.
 /// \param IncludeFileURI If true, include the file path of \p Loc as a URI.
 /// Defaults to false.
-Object visitSourceLocation(const PresumedLoc &Loc,
-   bool IncludeFileURI = false) {
+Object serializeSourceLocation(const PresumedLoc &Loc,
+   bool IncludeFileURI = false) {
   Object SourceLocation;
-  visitObject(SourceLocation, "position", visitSourcePosition(Loc));
+  serializeObject(SourceLocation, "position", serializeSourcePosition(Loc));
 
   if (IncludeFileURI) {
 std::string FileURI = "file://";
@@ -133,11 +128,11 @@
 }
 
 /// Serialize a source range with begin and end locations.
-Object visitSourceRange(const PresumedLoc &BeginLoc,
-const PresumedLoc &EndLoc) {
+Object serializeSourceRange(const PresumedLoc &BeginLoc,
+const PresumedLoc &EndLoc) {
   Object SourceRange;
-  visitObject(SourceRange, "start", visitSourcePosition(BeginLoc));
-  visitObject(SourceRang

[PATCH] D151293: [clang][ExtractAPI] Refactor serializer to the CRTP

2023-05-24 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 525431.
evelez7 marked 8 inline comments as done.
evelez7 added a comment.

Address some review feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151293/new/

https://reviews.llvm.org/D151293

Files:
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SerializerBase.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -38,14 +38,14 @@
 
 /// Helper function to inject a JSON object \p Obj into another object \p Paren
 /// at position \p Key.
-void serializeObject(Object &Paren, StringRef Key, std::optional Obj) {
+void visitObject(Object &Paren, StringRef Key, std::optional Obj) {
   if (Obj)
 Paren[Key] = std::move(*Obj);
 }
 
 /// Helper function to inject a JSON array \p Array into object \p Paren at
 /// position \p Key.
-void serializeArray(Object &Paren, StringRef Key, std::optional Array) {
+void visitArray(Object &Paren, StringRef Key, std::optional Array) {
   if (Array)
 Paren[Key] = std::move(*Array);
 }
@@ -66,7 +66,7 @@
 ///
 /// \returns \c std::nullopt if the version \p V is empty, or an \c Object
 /// containing the semantic version representation of \p V.
-std::optional serializeSemanticVersion(const VersionTuple &V) {
+std::optional visitSemanticVersion(const VersionTuple &V) {
   if (V.empty())
 return std::nullopt;
 
@@ -81,11 +81,11 @@
 ///
 /// The OS information in Symbol Graph contains the \c name of the OS, and an
 /// optional \c minimumVersion semantic version field.
-Object serializeOperatingSystem(const Triple &T) {
+Object visitOperatingSystem(const Triple &T) {
   Object OS;
   OS["name"] = T.getOSTypeName(T.getOS());
-  serializeObject(OS, "minimumVersion",
-  serializeSemanticVersion(T.getMinimumSupportedOSVersion()));
+  visitObject(OS, "minimumVersion",
+  visitSemanticVersion(T.getMinimumSupportedOSVersion()));
   return OS;
 }
 
@@ -93,16 +93,16 @@
 ///
 /// The platform object describes a target platform triple in corresponding
 /// three fields: \c architecture, \c vendor, and \c operatingSystem.
-Object serializePlatform(const Triple &T) {
+Object visitPlatform(const Triple &T) {
   Object Platform;
   Platform["architecture"] = T.getArchName();
   Platform["vendor"] = T.getVendorName();
-  Platform["operatingSystem"] = serializeOperatingSystem(T);
+  Platform["operatingSystem"] = visitOperatingSystem(T);
   return Platform;
 }
 
 /// Serialize a source position.
-Object serializeSourcePosition(const PresumedLoc &Loc) {
+Object visitSourcePosition(const PresumedLoc &Loc) {
   assert(Loc.isValid() && "invalid source position");
 
   Object SourcePosition;
@@ -117,10 +117,10 @@
 /// \param Loc The presumed location to serialize.
 /// \param IncludeFileURI If true, include the file path of \p Loc as a URI.
 /// Defaults to false.
-Object serializeSourceLocation(const PresumedLoc &Loc,
-   bool IncludeFileURI = false) {
+Object visitSourceLocation(const PresumedLoc &Loc,
+   bool IncludeFileURI = false) {
   Object SourceLocation;
-  serializeObject(SourceLocation, "position", serializeSourcePosition(Loc));
+  visitObject(SourceLocation, "position", visitSourcePosition(Loc));
 
   if (IncludeFileURI) {
 std::string FileURI = "file://";
@@ -133,11 +133,11 @@
 }
 
 /// Serialize a source range with begin and end locations.
-Object serializeSourceRange(const PresumedLoc &BeginLoc,
-const PresumedLoc &EndLoc) {
+Object visitSourceRange(const PresumedLoc &BeginLoc,
+const PresumedLoc &EndLoc) {
   Object SourceRange;
-  serializeObject(SourceRange, "start", serializeSourcePosition(BeginLoc));
-  serializeObject(SourceRange, "end", serializeSourcePosition(EndLoc));
+  visitObject(SourceRange, "start", visitSourcePosition(BeginLoc));
+  visitObject(SourceRange, "end", visitSourcePosition(EndLoc));
   return SourceRange;
 }
 
@@ -152,8 +152,7 @@
 ///
 /// \returns \c std::nullopt if the symbol has default availability attributes,
 /// or an \c Array containing the formatted availability information.
-std::optional
-serializeAvailability(const AvailabilitySet &Availabilities) {
+std::optional visitAvailability(const AvailabilitySet &Availabilities) {
   if (Availabilities.isDefault())
 return std::nullopt;
 
@@ -174,12 +173,12 @@
 if (AvailInfo.Unavailable)
   Availability["isUnconditionallyUnavailable"] = true;
 else {
-  serializeObject(Availabi

[PATCH] D151293: [clang][ExtractAPI] Refactor serializer to the CRTP

2023-05-25 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 525652.
evelez7 added a comment.

Really address review feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151293/new/

https://reviews.llvm.org/D151293

Files:
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SerializerBase.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -38,14 +38,14 @@
 
 /// Helper function to inject a JSON object \p Obj into another object \p Paren
 /// at position \p Key.
-void serializeObject(Object &Paren, StringRef Key, std::optional Obj) {
+void visitObject(Object &Paren, StringRef Key, std::optional Obj) {
   if (Obj)
 Paren[Key] = std::move(*Obj);
 }
 
 /// Helper function to inject a JSON array \p Array into object \p Paren at
 /// position \p Key.
-void serializeArray(Object &Paren, StringRef Key, std::optional Array) {
+void visitArray(Object &Paren, StringRef Key, std::optional Array) {
   if (Array)
 Paren[Key] = std::move(*Array);
 }
@@ -66,7 +66,7 @@
 ///
 /// \returns \c std::nullopt if the version \p V is empty, or an \c Object
 /// containing the semantic version representation of \p V.
-std::optional serializeSemanticVersion(const VersionTuple &V) {
+std::optional visitSemanticVersion(const VersionTuple &V) {
   if (V.empty())
 return std::nullopt;
 
@@ -81,11 +81,11 @@
 ///
 /// The OS information in Symbol Graph contains the \c name of the OS, and an
 /// optional \c minimumVersion semantic version field.
-Object serializeOperatingSystem(const Triple &T) {
+Object visitOperatingSystem(const Triple &T) {
   Object OS;
   OS["name"] = T.getOSTypeName(T.getOS());
-  serializeObject(OS, "minimumVersion",
-  serializeSemanticVersion(T.getMinimumSupportedOSVersion()));
+  visitObject(OS, "minimumVersion",
+  visitSemanticVersion(T.getMinimumSupportedOSVersion()));
   return OS;
 }
 
@@ -93,16 +93,16 @@
 ///
 /// The platform object describes a target platform triple in corresponding
 /// three fields: \c architecture, \c vendor, and \c operatingSystem.
-Object serializePlatform(const Triple &T) {
+Object visitPlatform(const Triple &T) {
   Object Platform;
   Platform["architecture"] = T.getArchName();
   Platform["vendor"] = T.getVendorName();
-  Platform["operatingSystem"] = serializeOperatingSystem(T);
+  Platform["operatingSystem"] = visitOperatingSystem(T);
   return Platform;
 }
 
 /// Serialize a source position.
-Object serializeSourcePosition(const PresumedLoc &Loc) {
+Object visitSourcePosition(const PresumedLoc &Loc) {
   assert(Loc.isValid() && "invalid source position");
 
   Object SourcePosition;
@@ -117,10 +117,10 @@
 /// \param Loc The presumed location to serialize.
 /// \param IncludeFileURI If true, include the file path of \p Loc as a URI.
 /// Defaults to false.
-Object serializeSourceLocation(const PresumedLoc &Loc,
-   bool IncludeFileURI = false) {
+Object visitSourceLocation(const PresumedLoc &Loc,
+   bool IncludeFileURI = false) {
   Object SourceLocation;
-  serializeObject(SourceLocation, "position", serializeSourcePosition(Loc));
+  visitObject(SourceLocation, "position", visitSourcePosition(Loc));
 
   if (IncludeFileURI) {
 std::string FileURI = "file://";
@@ -133,11 +133,11 @@
 }
 
 /// Serialize a source range with begin and end locations.
-Object serializeSourceRange(const PresumedLoc &BeginLoc,
-const PresumedLoc &EndLoc) {
+Object visitSourceRange(const PresumedLoc &BeginLoc,
+const PresumedLoc &EndLoc) {
   Object SourceRange;
-  serializeObject(SourceRange, "start", serializeSourcePosition(BeginLoc));
-  serializeObject(SourceRange, "end", serializeSourcePosition(EndLoc));
+  visitObject(SourceRange, "start", visitSourcePosition(BeginLoc));
+  visitObject(SourceRange, "end", visitSourcePosition(EndLoc));
   return SourceRange;
 }
 
@@ -152,8 +152,7 @@
 ///
 /// \returns \c std::nullopt if the symbol has default availability attributes,
 /// or an \c Array containing the formatted availability information.
-std::optional
-serializeAvailability(const AvailabilitySet &Availabilities) {
+std::optional visitAvailability(const AvailabilitySet &Availabilities) {
   if (Availabilities.isDefault())
 return std::nullopt;
 
@@ -174,12 +173,12 @@
 if (AvailInfo.Unavailable)
   Availability["isUnconditionallyUnavailable"] = true;
 else {
-  serializeObject(Availability, "introducedVersion",
-

[PATCH] D151477: [clang][ExtractAPI] Refactor serializer to the CRTP

2023-05-25 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added reviewers: dang, zixuw.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Refactor SerializerBase and SymbolGraphSerializer to use a visitor pattern 
described by the CRTP.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151477

Files:
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/Serialization/SerializerBase.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -14,16 +14,11 @@
 #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Version.h"
-#include "clang/ExtractAPI/API.h"
-#include "clang/ExtractAPI/APIIgnoresList.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
-#include "clang/ExtractAPI/Serialization/SerializerBase.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/JSON.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/VersionTuple.h"
 #include 
@@ -541,19 +536,16 @@
 Array generateParentContexts(const RecordTy &Record, const APISet &API,
  Language Lang) {
   Array ParentContexts;
-  generatePathComponents(Record, API,
- [Lang, &ParentContexts](const PathComponent &PC) {
-   ParentContexts.push_back(
-   serializeParentContext(PC, Lang));
- });
+  generatePathComponents(
+  Record, API, [Lang, &ParentContexts](const PathComponent &PC) {
+ParentContexts.push_back(serializeParentContext(PC, Lang));
+  });
 
   return ParentContexts;
 }
 
 } // namespace
 
-void SymbolGraphSerializer::anchor() {}
-
 /// Defines the format version emitted by SymbolGraphSerializer.
 const VersionTuple SymbolGraphSerializer::FormatVersion{0, 5, 3};
 
@@ -670,7 +662,7 @@
   Relationships.emplace_back(std::move(Relationship));
 }
 
-void SymbolGraphSerializer::serializeGlobalFunctionRecord(
+void SymbolGraphSerializer::visitGlobalFunctionRecord(
 const GlobalFunctionRecord &Record) {
   auto Obj = serializeAPIRecord(Record);
   if (!Obj)
@@ -679,7 +671,7 @@
   Symbols.emplace_back(std::move(*Obj));
 }
 
-void SymbolGraphSerializer::serializeGlobalVariableRecord(
+void SymbolGraphSerializer::visitGlobalVariableRecord(
 const GlobalVariableRecord &Record) {
   auto Obj = serializeAPIRecord(Record);
   if (!Obj)
@@ -688,7 +680,7 @@
   Symbols.emplace_back(std::move(*Obj));
 }
 
-void SymbolGraphSerializer::serializeEnumRecord(const EnumRecord &Record) {
+void SymbolGraphSerializer::visitEnumRecord(const EnumRecord &Record) {
   auto Enum = serializeAPIRecord(Record);
   if (!Enum)
 return;
@@ -697,7 +689,7 @@
   serializeMembers(Record, Record.Constants);
 }
 
-void SymbolGraphSerializer::serializeStructRecord(const StructRecord &Record) {
+void SymbolGraphSerializer::visitStructRecord(const StructRecord &Record) {
   auto Struct = serializeAPIRecord(Record);
   if (!Struct)
 return;
@@ -706,7 +698,7 @@
   serializeMembers(Record, Record.Fields);
 }
 
-void SymbolGraphSerializer::serializeObjCContainerRecord(
+void SymbolGraphSerializer::visitObjCContainerRecord(
 const ObjCContainerRecord &Record) {
   auto ObjCContainer = serializeAPIRecord(Record);
   if (!ObjCContainer)
@@ -743,7 +735,7 @@
   }
 }
 
-void SymbolGraphSerializer::serializeMacroDefinitionRecord(
+void SymbolGraphSerializer::visitMacroDefinitionRecord(
 const MacroDefinitionRecord &Record) {
   auto Macro = serializeAPIRecord(Record);
 
@@ -753,33 +745,33 @@
   Symbols.emplace_back(std::move(*Macro));
 }
 
-void SymbolGraphSerializer::serializeSingleRecord(const APIRecord *Record) {
+void SymbolGraphSerializer::visitSingleRecord(const APIRecord *Record) {
   switch (Record->getKind()) {
   case APIRecord::RK_Unknown:
 llvm_unreachable("Records should have a known kind!");
   case APIRecord::RK_GlobalFunction:
-serializeGlobalFunctionRecord(*cast(Record));
+visitGlobalFunctionRecord(*cast(Record));
 break;
   case APIRecord::RK_GlobalVariable:
-serializeGlobalVariableRecord(*cast(Record));
+visitGlobalVariableRecord(*cast(Record));
 break;
   case APIRecord::RK_Enum:
-serializeEnumRecord(*cast(Record));
+visitEnumRecord(*cast(Record));
 break;
   case APIRecord::RK_Struct:
-serializeStructRec

[PATCH] D151293: [clang][ExtractAPI] Refactor serializer to the CRTP

2023-05-25 Thread Erick Velez via Phabricator via cfe-commits
evelez7 abandoned this revision.
evelez7 added inline comments.



Comment at: clang/include/clang/ExtractAPI/Serialization/SerializerBase.h:28-31
+struct APISetVisitorOption {
   /// Do not include unnecessary whitespaces to save space.
   bool Compact;
 };

dang wrote:
> This is very specific to SymbolGraphSerializer or at last to JSON.
If there aren't any base visitor options, I'll just move this to 
`SymbolGraphSerializer` without any inheritance.



Comment at: clang/include/clang/ExtractAPI/Serialization/SerializerBase.h:84
+for (const auto &Protocol : API.getObjCProtocols())
+  getDerived()->visitObjCContainerRecord(*Protocol.second);
+  }

dang wrote:
> This should visit some sort Protocol Records specifically. Likewise for 
> interfaces.
Not sure I understand, these functions essentially replace the loops in the old 
`SymbolGraphSerializer::serialize` loops, which are now grouped as function 
calls in `APISetVisitor::traverseAPISet`. Should I add functions that take 
Protocols, Interfaces as parameters to visit them specifically?



Comment at: 
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h:129
   template 
-  void serializeMembers(const APIRecord &Record,
-const SmallVector> &Members);
+  void visitMembers(const APIRecord &Record,
+const SmallVector> &Members);

dang wrote:
> I think we shouldn't need to have this method. APISetVisitor should handle 
> calling the relevant visitMethods for the members.
I've been considering how to move it to `APISetVisitor`. Its current 
implementation doesn't seem like it would fit well with a generic base 
implementation. It would be overridden to call `visitRelationship` which relies 
on a `RelationshipKind` parameter. Since that's SymbolKit specific, I don't 
think we'd raise that to the base class.

If there was a base relationship struct that `RelationshipKind` inherited from, 
it might solve that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151293/new/

https://reviews.llvm.org/D151293

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151477: [clang][ExtractAPI] Refactor serializer to the CRTP

2023-05-26 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 526148.
evelez7 added a comment.

Address review feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151477/new/

https://reviews.llvm.org/D151477

Files:
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/Serialization/SerializerBase.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -14,16 +14,11 @@
 #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Version.h"
-#include "clang/ExtractAPI/API.h"
-#include "clang/ExtractAPI/APIIgnoresList.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
-#include "clang/ExtractAPI/Serialization/SerializerBase.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/JSON.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/VersionTuple.h"
 #include 
@@ -541,19 +536,16 @@
 Array generateParentContexts(const RecordTy &Record, const APISet &API,
  Language Lang) {
   Array ParentContexts;
-  generatePathComponents(Record, API,
- [Lang, &ParentContexts](const PathComponent &PC) {
-   ParentContexts.push_back(
-   serializeParentContext(PC, Lang));
- });
+  generatePathComponents(
+  Record, API, [Lang, &ParentContexts](const PathComponent &PC) {
+ParentContexts.push_back(serializeParentContext(PC, Lang));
+  });
 
   return ParentContexts;
 }
 
 } // namespace
 
-void SymbolGraphSerializer::anchor() {}
-
 /// Defines the format version emitted by SymbolGraphSerializer.
 const VersionTuple SymbolGraphSerializer::FormatVersion{0, 5, 3};
 
@@ -670,7 +662,7 @@
   Relationships.emplace_back(std::move(Relationship));
 }
 
-void SymbolGraphSerializer::serializeGlobalFunctionRecord(
+void SymbolGraphSerializer::visitGlobalFunctionRecord(
 const GlobalFunctionRecord &Record) {
   auto Obj = serializeAPIRecord(Record);
   if (!Obj)
@@ -679,7 +671,7 @@
   Symbols.emplace_back(std::move(*Obj));
 }
 
-void SymbolGraphSerializer::serializeGlobalVariableRecord(
+void SymbolGraphSerializer::visitGlobalVariableRecord(
 const GlobalVariableRecord &Record) {
   auto Obj = serializeAPIRecord(Record);
   if (!Obj)
@@ -688,7 +680,7 @@
   Symbols.emplace_back(std::move(*Obj));
 }
 
-void SymbolGraphSerializer::serializeEnumRecord(const EnumRecord &Record) {
+void SymbolGraphSerializer::visitEnumRecord(const EnumRecord &Record) {
   auto Enum = serializeAPIRecord(Record);
   if (!Enum)
 return;
@@ -697,7 +689,7 @@
   serializeMembers(Record, Record.Constants);
 }
 
-void SymbolGraphSerializer::serializeStructRecord(const StructRecord &Record) {
+void SymbolGraphSerializer::visitStructRecord(const StructRecord &Record) {
   auto Struct = serializeAPIRecord(Record);
   if (!Struct)
 return;
@@ -706,7 +698,7 @@
   serializeMembers(Record, Record.Fields);
 }
 
-void SymbolGraphSerializer::serializeObjCContainerRecord(
+void SymbolGraphSerializer::visitObjCContainerRecord(
 const ObjCContainerRecord &Record) {
   auto ObjCContainer = serializeAPIRecord(Record);
   if (!ObjCContainer)
@@ -743,7 +735,7 @@
   }
 }
 
-void SymbolGraphSerializer::serializeMacroDefinitionRecord(
+void SymbolGraphSerializer::visitMacroDefinitionRecord(
 const MacroDefinitionRecord &Record) {
   auto Macro = serializeAPIRecord(Record);
 
@@ -758,28 +750,28 @@
   case APIRecord::RK_Unknown:
 llvm_unreachable("Records should have a known kind!");
   case APIRecord::RK_GlobalFunction:
-serializeGlobalFunctionRecord(*cast(Record));
+visitGlobalFunctionRecord(*cast(Record));
 break;
   case APIRecord::RK_GlobalVariable:
-serializeGlobalVariableRecord(*cast(Record));
+visitGlobalVariableRecord(*cast(Record));
 break;
   case APIRecord::RK_Enum:
-serializeEnumRecord(*cast(Record));
+visitEnumRecord(*cast(Record));
 break;
   case APIRecord::RK_Struct:
-serializeStructRecord(*cast(Record));
+visitStructRecord(*cast(Record));
 break;
   case APIRecord::RK_ObjCInterface:
-serializeObjCContainerRecord(*cast(Record));
+visitObjCContainerRecord(*cast(Record));
 break;
   case APIRecord::RK_ObjCProtocol:
-serializeObjCContainerRecord(*cast(Record));
+visitObjCContainerRecord(*cast(Record));
 break;
   case APIRecord::RK_MacroDefinition:
-serializeMacr