[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-07-25 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 543982.
Ruturaj4 added a comment.



1. Updating D152770 : [clang][ExtractAPI] Add 
support for Objective-C categories #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Thanks for your comments and sorry for delay. I have changed the design and 
moved everything in SymbolGraphSerializer.cpp.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152770

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/objc_module_category.m
  clang/test/ExtractAPI/objc_various_categories.m

Index: clang/test/ExtractAPI/objc_various_categories.m
===
--- clang/test/ExtractAPI/objc_various_categories.m
+++ clang/test/ExtractAPI/objc_various_categories.m
@@ -25,13 +25,17 @@
 @end
 
 @interface MyClass2 (MyCategory2)
-- (int) SomeMethod;
+- (int) SomeMethod2;
 @end
 
-@interface NSString (Category)
+@interface NSString (Category1)
 -(void) StringMethod;
 @end
 
+@interface NSString (Category2)
+-(void) StringMethod2;
+@end
+
 //--- myclass_1.h
 @interface MyClass1
 @end
@@ -74,27 +78,39 @@
 },
 {
   "kind": "memberOf",
-  "source": "c:objc(cs)MyClass2(im)SomeMethod",
+  "source": "c:objc(cy)MyClass2@MyCategory2",
+  "target": "c:objc(cs)MyClass2",
+  "targetFallback": "MyClass2"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyClass2(im)SomeMethod2",
   "target": "c:objc(cy)MyClass2@MyCategory2",
   "targetFallback": "MyCategory2"
 },
 {
   "kind": "memberOf",
-  "source": "c:objc(cs)NSString(im)StringMethod",
-  "target": "c:objc(cy)NSString@Category",
-  "targetFallback": "Category"
+  "source": "c:objc(cy)NSString@Category1",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
 },
 {
   "kind": "memberOf",
-  "source": "c:objc(cy)MyClass2@MyCategory2",
-  "target": "c:objc(cs)MyClass2",
-  "targetFallback": "MyClass2"
+  "source": "c:objc(cs)NSString(im)StringMethod",
+  "target": "c:objc(cy)NSString@Category1",
+  "targetFallback": "Category1"
 },
 {
   "kind": "memberOf",
-  "source": "c:objc(cy)NSString@Category",
+  "source": "c:objc(cy)NSString@Category2",
   "target": "c:objc(cs)NSString",
   "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod2",
+  "target": "c:objc(cy)NSString@Category2",
+  "targetFallback": "Category2"
 }
   ],
   "symbols": [
@@ -221,6 +237,17 @@
 "SomeMethod"
   ]
 },
+{
+  "accessLevel": "public",
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyClass2"
+  },
+  "kind": {
+"displayName": "Module Extension",
+"identifier": "objective-c.module.extension"
+  }
+},
 {
   "accessLevel": "public",
   "declarationFragments": [
@@ -252,7 +279,7 @@
   ],
   "identifier": {
 "interfaceLanguage": "objective-c",
-"precise": "c:objc(cy)MyClass2@MyCategory2"
+"precise": "c:objc(cs)MyClass2"
   },
   "kind": {
 "displayName": "Class Extension",
@@ -302,7 +329,7 @@
 },
 {
   "kind": "identifier",
-  "spelling": "SomeMethod"
+  "spelling": "SomeMethod2"
 },
 {
   "kind": "text",
@@ -320,7 +347,7 @@
   },
   "identifier": {
 "interfaceLanguage": "objective-c",
-"precise": "c:objc(cs)MyClass2(im)SomeMethod"
+"precise": "c:objc(cs)MyClass2(im)SomeMethod2"
   },
   "kind": {
 "displayName": "Instance Method",
@@ -337,7 +364,7 @@
 "navigator": [
   {
 "kind": "identifier",
-"spelling": "SomeMethod"
+"spelling": "SomeMethod2"
   }
 ],
 "subHeading": [
@@ -347,16 +374,27 @@
   },
   {
 "kind": "identifier",
-"spelling": "SomeMethod"
+"spelling": "SomeMethod2"
   }
 ],
-"title": "SomeMethod"
+"title": "SomeMethod2"
   },
   "pathComponents": [
-"MyClass2",
-"SomeMethod"
+"MyCategory2",
+"SomeMethod2"
   ]
 },
+{
+  "accessLevel": "public",
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"

[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-08-15 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 550303.
Ruturaj4 marked an inline comment as done.
Ruturaj4 added a comment.

- [clang][ExtractAPI] Add support for Objective-C categories

1. Updating D152770 : [clang][ExtractAPI] Add 
support for Objective-C categories #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Update test to remove MyClass2.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152770

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/objc_module_category.m
  clang/test/ExtractAPI/objc_various_categories.m

Index: clang/test/ExtractAPI/objc_various_categories.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_various_categories.m
@@ -0,0 +1,507 @@
+// 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 -x objective-c-header \
+// RUN: -target arm64-apple-macosx \
+// RUN: %t/myclass_1.h \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// 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
+#import "myclass_1.h"
+#import "Foundation.h"
+
+@interface MyClass1 (MyCategory1)
+- (int) SomeMethod;
+@end
+
+@interface NSString (Category1)
+-(void) StringMethod;
+@end
+
+@interface NSString (Category2)
+-(void) StringMethod2;
+@end
+
+//--- myclass_1.h
+@interface MyClass1
+@end
+
+//--- Foundation.h
+@interface NSString
+@end
+
+//--- 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:objc(cs)MyClass1(im)SomeMethod",
+  "target": "c:objc(cs)MyClass1",
+  "targetFallback": "MyClass1"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)NSString@Category1",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod",
+  "target": "c:objc(cy)NSString@Category1",
+  "targetFallback": "Category1"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)NSString@Category2",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod2",
+  "target": "c:objc(cy)NSString@Category2",
+  "targetFallback": "Category2"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyClass1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyClass1"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/myclass_1.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "MyClass1"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyClass1"
+  }
+],
+"title": "MyClass1"
+  },
+  "pathComponents": [
+"MyClass1"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "text",
+  "spelling": "- ("
+},
+{
+  "kind": "typ

[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-08-15 Thread R4444 via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG184931853924: [clang][ExtractAPI] Add support for 
Objective-C categories (authored by Ruturaj4).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152770

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/objc_module_category.m
  clang/test/ExtractAPI/objc_various_categories.m

Index: clang/test/ExtractAPI/objc_various_categories.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_various_categories.m
@@ -0,0 +1,507 @@
+// 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 -x objective-c-header \
+// RUN: -target arm64-apple-macosx \
+// RUN: %t/myclass_1.h \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// 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
+#import "myclass_1.h"
+#import "Foundation.h"
+
+@interface MyClass1 (MyCategory1)
+- (int) SomeMethod;
+@end
+
+@interface NSString (Category1)
+-(void) StringMethod;
+@end
+
+@interface NSString (Category2)
+-(void) StringMethod2;
+@end
+
+//--- myclass_1.h
+@interface MyClass1
+@end
+
+//--- Foundation.h
+@interface NSString
+@end
+
+//--- 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:objc(cs)MyClass1(im)SomeMethod",
+  "target": "c:objc(cs)MyClass1",
+  "targetFallback": "MyClass1"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)NSString@Category1",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod",
+  "target": "c:objc(cy)NSString@Category1",
+  "targetFallback": "Category1"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)NSString@Category2",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod2",
+  "target": "c:objc(cy)NSString@Category2",
+  "targetFallback": "Category2"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyClass1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyClass1"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/myclass_1.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "MyClass1"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyClass1"
+  }
+],
+"title": "MyClass1"
+  },
+  "pathComponents": [
+"MyClass1"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "text",
+  "spelling": "- ("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": ") "
+},
+{
+  "kind": "identifier",
+  "spelling": "SomeMethod"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+

[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-08-01 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 546074.
Ruturaj4 added a comment.

- [clang][ExtractAPI] Add support for Objective-C categories
- [clang][ExtractAPI] Add support for Objective-C categories

1. Updating D152770 : [clang][ExtractAPI] Add 
support for Objective-C categories #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Upload the correct patch and update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152770

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/objc_module_category.m
  clang/test/ExtractAPI/objc_various_categories.m

Index: clang/test/ExtractAPI/objc_various_categories.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_various_categories.m
@@ -0,0 +1,671 @@
+// 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 -x objective-c-header \
+// RUN: -target arm64-apple-macosx \
+// RUN: %t/myclass_1.h \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// 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
+#import 
+#import "myclass_1.h"
+#import "myclass_2.h"
+
+@interface MyClass1 (MyCategory1)
+- (int) SomeMethod;
+@end
+
+@interface MyClass2 (MyCategory2)
+- (int) SomeMethod2;
+@end
+
+@interface NSString (Category1)
+-(void) StringMethod;
+@end
+
+@interface NSString (Category2)
+-(void) StringMethod2;
+@end
+
+//--- myclass_1.h
+@interface MyClass1
+@end
+
+//--- myclass_2.h
+@interface MyClass2
+@end
+
+//--- 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:objc(cs)MyClass1(im)SomeMethod",
+  "target": "c:objc(cs)MyClass1",
+  "targetFallback": "MyClass1"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cy)MyClass2@MyCategory2",
+  "target": "c:objc(cs)MyClass2",
+  "targetFallback": "MyClass2"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyClass2(im)SomeMethod2",
+  "target": "c:objc(cy)MyClass2@MyCategory2",
+  "targetFallback": "MyCategory2"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cy)NSString@Category1",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod",
+  "target": "c:objc(cy)NSString@Category1",
+  "targetFallback": "Category1"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cy)NSString@Category2",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod2",
+  "target": "c:objc(cy)NSString@Category2",
+  "targetFallback": "Category2"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyClass1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyClass1"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/myclass_1.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "MyClass1"
+  

[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-08-02 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 546682.
Ruturaj4 marked 4 inline comments as done.
Ruturaj4 added a comment.



1. Updating D152770 : [clang][ExtractAPI] Add 
support for Objective-C categories #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Made all the changes according to comments.

1. Removed check on line #219 to include unique USR for categories.
2. Explained how multiple categories to the same type are supported.
3. Added new relationship "extensionTo".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152770

Files:
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/objc_module_category.m
  clang/test/ExtractAPI/objc_various_categories.m

Index: clang/test/ExtractAPI/objc_various_categories.m
===
--- clang/test/ExtractAPI/objc_various_categories.m
+++ clang/test/ExtractAPI/objc_various_categories.m
@@ -77,7 +77,7 @@
   "targetFallback": "MyClass1"
 },
 {
-  "kind": "memberOf",
+  "kind": "extensionTo",
   "source": "c:objc(cy)MyClass2@MyCategory2",
   "target": "c:objc(cs)MyClass2",
   "targetFallback": "MyClass2"
@@ -89,7 +89,7 @@
   "targetFallback": "MyCategory2"
 },
 {
-  "kind": "memberOf",
+  "kind": "extensionTo",
   "source": "c:objc(cy)NSString@Category1",
   "target": "c:objc(cs)NSString",
   "targetFallback": "NSString"
@@ -101,7 +101,7 @@
   "targetFallback": "Category1"
 },
 {
-  "kind": "memberOf",
+  "kind": "extensionTo",
   "source": "c:objc(cy)NSString@Category2",
   "target": "c:objc(cs)NSString",
   "targetFallback": "NSString"
@@ -241,7 +241,7 @@
   "accessLevel": "public",
   "identifier": {
 "interfaceLanguage": "objective-c",
-"precise": "c:objc(cs)MyClass2"
+"precise": "c:objc(cy)MyClass2@MyCategory2"
   },
   "kind": {
 "displayName": "Module Extension",
@@ -279,7 +279,7 @@
   ],
   "identifier": {
 "interfaceLanguage": "objective-c",
-"precise": "c:objc(cs)MyClass2"
+"precise": "c:objc(cy)MyClass2@MyCategory2"
   },
   "kind": {
 "displayName": "Class Extension",
@@ -388,7 +388,7 @@
   "accessLevel": "public",
   "identifier": {
 "interfaceLanguage": "objective-c",
-"precise": "c:objc(cs)NSString"
+"precise": "c:objc(cy)NSString@Category1"
   },
   "kind": {
 "displayName": "Module Extension",
@@ -426,7 +426,7 @@
   ],
   "identifier": {
 "interfaceLanguage": "objective-c",
-"precise": "c:objc(cs)NSString"
+"precise": "c:objc(cy)NSString@Category1"
   },
   "kind": {
 "displayName": "Class Extension",
@@ -562,7 +562,7 @@
   ],
   "identifier": {
 "interfaceLanguage": "objective-c",
-"precise": "c:objc(cs)NSString"
+"precise": "c:objc(cy)NSString@Category2"
   },
   "kind": {
 "displayName": "Class Extension",
Index: clang/test/ExtractAPI/objc_module_category.m
===
--- clang/test/ExtractAPI/objc_module_category.m
+++ clang/test/ExtractAPI/objc_module_category.m
@@ -53,7 +53,7 @@
   },
   "relationships": [
 {
-  "kind": "memberOf",
+  "kind": "extensionTo",
   "source": "c:objc(cy)NSString@Category1",
   "target": "c:objc(cs)NSString",
   "targetFallback": "NSString"
@@ -65,7 +65,7 @@
   "targetFallback": "Category1"
 },
 {
-  "kind": "memberOf",
+  "kind": "extensionTo",
   "source": "c:objc(cy)NSString@Category2",
   "target": "c:objc(cs)NSString",
   "targetFallback": "NSString"
@@ -82,7 +82,7 @@
   "accessLevel": "public",
   "identifier": {
 "interfaceLanguage": "objective-c",
-"precise": "c:objc(cs)NSString"
+"precise": "c:objc(cy)NSString@Category1"
   },
   "kind": {
 "displayName": "Module Extension",
@@ -137,7 +137,7 @@
   },
   "identifier": {
 "interfaceLanguage": "objective-c",
-"precise": "c:objc(cs)NSString"
+"precise": "c:objc(cy)NSString@Category1"
   },
   "kind": {
 "displayName": "Class Extension",
@@ -290,7 +290,7 @@
   },
   "identifier": {
 "interfaceLanguage": "objective-c",
-"precise": "c:objc(cs)NSString"
+"precise": "c:objc(cy)NSString@Category2"
   },
   "kind": {
 "displayName": "Class Extension",
Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
=

[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-08-02 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 added inline comments.



Comment at: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h:488
+  bool IsFromExternalModule = true;
+  for (const auto &Interface : API.getObjCInterfaces()) {
+if (InterfaceDecl->getName() == Interface.second.get()->Name) {

dang wrote:
> I think this is fine for now but there must be a better way of doing this 
> that doesn't involve traversing the whole APISet
I looked at different api methods, but still not able to figure it out. I will 
do it once this gets approved. In a following patch.



Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:219
   Object Identifier;
-  Identifier["precise"] = Record.USR;
+  if (auto *CategoryRecord =
+  dyn_cast_or_null(&Record))

dang wrote:
> I don't think this is right. My expectation is that category records that 
> need to get emitted would still have their own unique USR.
Thanks. I removed the check.



Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:759
+  // Check if the current Category Record has been visited before, if not add.
+  if (!(visitedCategories.contains(Record.Interface.Name) > 0)) {
+visitedCategories.insert(Record.Interface.Name);

dang wrote:
> What happens when there are multiple categories to the same type though?
Yes! I added this check keeping that in mind. If the parent symbol of the 
category is not added before then it pushes it to serialize (but skips if 
already present). Otherwise, just adds the category.

For e.g. in example test - objc_various_categories.m, there are two categories 
extending the same type:

```
@interface NSString (Category1)
-(void) StringMethod;
@end

@interface NSString (Category2)
-(void) StringMethod2;
@end
```

In this case, it adds the symbol for NSString (parent of categories `Category1` 
and `Category2`). I fixed the comments to make that clear.



Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:775
+  Relationship["targetFallback"] = Record.Interface.Name;
+  Relationship["kind"] = getRelationshipString(RelationshipKind::MemberOf);
+  Relationships.emplace_back(std::move(Relationship));

dang wrote:
> I would expect this to be a new relationship kind that reads as "extensionTo"
Thanks, that makes sense. I fixed it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152770

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


[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-08-02 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 546683.
Ruturaj4 added a comment.



1. Updating D152770 : [clang][ExtractAPI] Add 
support for Objective-C categories #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Upload the correct patch and update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152770

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/objc_module_category.m
  clang/test/ExtractAPI/objc_various_categories.m

Index: clang/test/ExtractAPI/objc_various_categories.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_various_categories.m
@@ -0,0 +1,671 @@
+// 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 -x objective-c-header \
+// RUN: -target arm64-apple-macosx \
+// RUN: %t/myclass_1.h \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// 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
+#import 
+#import "myclass_1.h"
+#import "myclass_2.h"
+
+@interface MyClass1 (MyCategory1)
+- (int) SomeMethod;
+@end
+
+@interface MyClass2 (MyCategory2)
+- (int) SomeMethod2;
+@end
+
+@interface NSString (Category1)
+-(void) StringMethod;
+@end
+
+@interface NSString (Category2)
+-(void) StringMethod2;
+@end
+
+//--- myclass_1.h
+@interface MyClass1
+@end
+
+//--- myclass_2.h
+@interface MyClass2
+@end
+
+//--- 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:objc(cs)MyClass1(im)SomeMethod",
+  "target": "c:objc(cs)MyClass1",
+  "targetFallback": "MyClass1"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)MyClass2@MyCategory2",
+  "target": "c:objc(cs)MyClass2",
+  "targetFallback": "MyClass2"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyClass2(im)SomeMethod2",
+  "target": "c:objc(cy)MyClass2@MyCategory2",
+  "targetFallback": "MyCategory2"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)NSString@Category1",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod",
+  "target": "c:objc(cy)NSString@Category1",
+  "targetFallback": "Category1"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)NSString@Category2",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod2",
+  "target": "c:objc(cy)NSString@Category2",
+  "targetFallback": "Category2"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyClass1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyClass1"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/myclass_1.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "MyClass1"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spe

[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-08-09 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 548825.
Ruturaj4 added a comment.

- [clang][ExtractAPI] Add support for Objective-C categories
- [clang][ExtractAPI] Add support for Objective-C categories
- [clang][ExtractAPI] Add support for Objective-C categories
- [clang][ExtractAPI] Add support for Objective-C categories

1. Updating D152770 : [clang][ExtractAPI] Add 
support for Objective-C categories #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Fix test cases, and simulate the library interface.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152770

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/objc_module_category.m
  clang/test/ExtractAPI/objc_various_categories.m

Index: clang/test/ExtractAPI/objc_various_categories.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_various_categories.m
@@ -0,0 +1,675 @@
+// 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 -x objective-c-header \
+// RUN: -target arm64-apple-macosx \
+// RUN: %t/myclass_1.h \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// 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
+#import "myclass_1.h"
+#import "myclass_2.h"
+#import "Foundation.h"
+
+@interface MyClass1 (MyCategory1)
+- (int) SomeMethod;
+@end
+
+@interface MyClass2 (MyCategory2)
+- (int) SomeMethod2;
+@end
+
+@interface NSString (Category1)
+-(void) StringMethod;
+@end
+
+@interface NSString (Category2)
+-(void) StringMethod2;
+@end
+
+//--- myclass_1.h
+@interface MyClass1
+@end
+
+//--- myclass_2.h
+@interface MyClass2
+@end
+
+//--- Foundation.h
+@interface NSString
+@end
+
+//--- 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:objc(cs)MyClass1(im)SomeMethod",
+  "target": "c:objc(cs)MyClass1",
+  "targetFallback": "MyClass1"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)MyClass2@MyCategory2",
+  "target": "c:objc(cs)MyClass2",
+  "targetFallback": "MyClass2"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyClass2(im)SomeMethod2",
+  "target": "c:objc(cy)MyClass2@MyCategory2",
+  "targetFallback": "MyCategory2"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)NSString@Category1",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod",
+  "target": "c:objc(cy)NSString@Category1",
+  "targetFallback": "Category1"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)NSString@Category2",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod2",
+  "target": "c:objc(cy)NSString@Category2",
+  "targetFallback": "Category2"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyClass1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyClass1"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+ 

[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-07-04 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 created this revision.
Herald added a reviewer: ributzka.
Herald added a project: All.
Ruturaj4 added a reviewer: dang.
Ruturaj4 edited the summary of this revision.
Ruturaj4 edited the summary of this revision.
Ruturaj4 updated this revision to Diff 537064.
Ruturaj4 added a comment.
Ruturaj4 edited the summary of this revision.
Ruturaj4 published this revision for review.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.



1. Updating D152770 : [clang][ExtractAPI] Add 
support for Objective-C categories #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Introducing support for Objective-C Categories for ExtractAPI. The suuport for 
Objective-C Categories is currently lacking
in terms of categories that extend a type defined in current module and 
categories that extend types that belong to external
modules such as NSString. Thus the objective of this patch is two fold, to fix 
former and the later.

This is achieved by introducing two new symbols ->

objective-c.module.extension.
objective-c.class.extension.
Note that the extension represents objective-c "category" (orienting well with 
Swift's Extension, which in spite that fact
that is different, however "broadly" serves similar purpose). The original idea 
is inspired by Max's @theMomax initial
post - 
https://forums.swift.org/t/symbol-graph-adaptions-for-documenting-extensions-to-external-types-in-docc/56684,
and Daniel's helpful comments and feedback. The implementation nonetheless is 
different serving purpose for this project.


Introducing support for Objective-C Categories for ExtractAPI. The suuport for 
Objective-C Categories is currently lacking
in terms of categories that extend a type defined in current module and 
categories that extend types that belong to external
modules such as `NSString`. Thus the objective of this patch is two fold, to 
fix former and the later.

This is achieved by introducing two new symbols ->

1. `objective-c.module.extension`.
2. `objective-c.class.extension`.

Note that the extension represents objective-c "category" (orienting well with 
Swift's Extension, which in spite that fact
that is different, however "broadly" serves similar purpose). The original idea 
is inspired by Max's `@theMomax` initial
post - 
https://forums.swift.org/t/symbol-graph-adaptions-for-documenting-extensions-to-external-types-in-docc/56684,
and Daniel's helpful comments and feedback. The implementation nonetheless is 
different serving purpose for this project.

The following diagram well represents the purpose ->
F28127510: llvm_categories.png 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152770

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/objc_module_category.m
  clang/test/ExtractAPI/objc_various_categories.m

Index: clang/test/ExtractAPI/objc_various_categories.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_various_categories.m
@@ -0,0 +1,519 @@
+// 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 -x objective-c-header \
+// RUN: -target arm64-apple-macosx \
+// RUN: %t/myclass_1.h \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// 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
+#import 
+#import "myclass_1.h"
+#import "myclass_2.h"
+
+@interface MyClass1 (MyCategory1)
+- (int) SomeMethod;
+@end
+
+@interface MyClass2 (MyCategory2)
+- (int) SomeMethod;
+@end
+
+@interface NSString (Category)
+-(void) StringMethod;
+@end
+
+//--- myclass_1.h
+@interface MyClass1
+@end
+
+//--- myclass_2.h
+@interface MyClass2
+@end
+
+//--- 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": "a

[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

2023-03-19 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 created this revision.
Ruturaj4 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
Ruturaj4 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

enums and structs declared inside typedefs have incorrect declaration 
fragments, where the typedef keyword and other syntax is missing.

For the following struct:

typedef struct Test {

  int hello;

} Test;
The produced declaration is:

"declarationFragments": [

  {
"kind": "keyword",
"spelling": "struct"
  },
  {
"kind": "text",
"spelling": " "
  },
  {
"kind": "identifier",
"spelling": "Test"
  }

],
instead the declaration fragments should represent the following

typedef struct Test {

  …

} Test;

This patch removes the condition in SymbolGraphSerializer.cpp file and 
completes declaration fragments


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146385

Files:
  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
@@ -801,11 +801,7 @@
 const TypedefRecord &Record) {
   // Typedefs of anonymous types have their entries unified with the underlying
   // type.
-  bool ShouldDrop = Record.UnderlyingType.Name.empty();
-  // enums declared with `NS_OPTION` have a named enum and a named typedef, 
with
-  // the same name
-  ShouldDrop |= (Record.UnderlyingType.Name == Record.Name);
-  if (ShouldDrop)
+  if (Record.UnderlyingType.Name.empty())
 return;
 
   auto Typedef = serializeAPIRecord(Record);


Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -801,11 +801,7 @@
 const TypedefRecord &Record) {
   // Typedefs of anonymous types have their entries unified with the underlying
   // type.
-  bool ShouldDrop = Record.UnderlyingType.Name.empty();
-  // enums declared with `NS_OPTION` have a named enum and a named typedef, with
-  // the same name
-  ShouldDrop |= (Record.UnderlyingType.Name == Record.Name);
-  if (ShouldDrop)
+  if (Record.UnderlyingType.Name.empty())
 return;
 
   auto Typedef = serializeAPIRecord(Record);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

2023-03-23 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 507958.
Ruturaj4 added a comment.



1. Updating D146385 : [clang][ExtractAPI] 
Complete declaration fragments for TagDecl types defined in a typedef #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Updated previous diff with requested changes and added new test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146385

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

Index: clang/test/ExtractAPI/typedef_struct_enum.c
===
--- /dev/null
+++ clang/test/ExtractAPI/typedef_struct_enum.c
@@ -0,0 +1,230 @@
+// 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 \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// 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
+typedef struct Test {
+} Test;
+
+typedef enum Test2 {
+  simple
+} Test2;
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:@E@Test2@simple",
+  "target": "c:@E@Test2",
+  "targetFallback": "Test2"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "keyword",
+  "spelling": "enum"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Test2"
+},
+{
+  "kind": "text",
+  "spelling": ": "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@E@Test2"
+  },
+  "kind": {
+"displayName": "Enumeration",
+"identifier": "c.enum"
+  },
+  "location": {
+"position": {
+  "character": 14,
+  "line": 4
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Test2"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Test2"
+  }
+],
+"title": "Test2"
+  },
+  "pathComponents": [
+"Test2"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "identifier",
+  "spelling": "simple"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@E@Test2@simple"
+  },
+  "kind": {
+"displayName": "Enumeration Case",
+"identifier": "c.enum.case"
+  },
+  "location": {
+"position": {
+  "character": 3,
+  "line": 5
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "simple"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "simple"
+  }
+],
+"title": "simple"
+  },
+  "pathComponents": [
+"Test2",
+"simple"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "keyword",
+  "spelling": "struct"
+

[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

2023-03-25 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 508375.
Ruturaj4 added a comment.



1. Updating D146385 : [clang][ExtractAPI] 
Complete declaration fragments for TagDecl types defined in a typedef #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Made all updates as you requested, though I didn't need to generate fragments 
for the underlying Decl. I added an example as you have recommended.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146385

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

Index: clang/test/ExtractAPI/typedef_struct_enum.c
===
--- clang/test/ExtractAPI/typedef_struct_enum.c
+++ clang/test/ExtractAPI/typedef_struct_enum.c
@@ -21,6 +21,12 @@
   simple
 } Test2;
 
+struct Foo;
+typedef struct Foo TypedefedFoo;
+struct Foo {
+int bar;
+};
+
 //--- reference.output.json.in
 {
   "metadata": {
@@ -36,6 +42,11 @@
 "platform": {
   "architecture": "arm64",
   "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
 "name": "macosx"
   },
   "vendor": "apple"
@@ -47,6 +58,12 @@
   "source": "c:@E@Test2@simple",
   "target": "c:@E@Test2",
   "targetFallback": "Test2"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@FI@bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
 }
   ],
   "symbols": [
@@ -82,6 +99,14 @@
   "preciseIdentifier": "c:i",
   "spelling": "unsigned int"
 },
+{
+  "kind": "text",
+  "spelling": " { ... } "
+},
+{
+  "kind": "identifier",
+  "spelling": "Test2"
+},
 {
   "kind": "text",
   "spelling": ";"
@@ -187,6 +212,14 @@
   "kind": "identifier",
   "spelling": "Test"
 },
+{
+  "kind": "text",
+  "spelling": " { ... } "
+},
+{
+  "kind": "identifier",
+  "spelling": "Test"
+},
 {
   "kind": "text",
   "spelling": ";"
@@ -225,6 +258,184 @@
   "pathComponents": [
 "Test"
   ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "struct"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Structure",
+"identifier": "c.struct"
+  },
+  "location": {
+"position": {
+  "character": 8,
+  "line": 10
+},
+"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:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "bar"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Foo@FI@bar"
+  },
+  "kind": {
+"displayName": "Instance Property",
+"identifier": "c.property"
+  },
+  "location": {
+"position": {
+  "character": 9,
+  "line": 11
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "bar"
+  }
+],
+"title": "bar"
+  },
+  "pathComponents": [
+"Foo",
+"bar"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+

[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

2023-03-25 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 marked 2 inline comments as done.
Ruturaj4 added inline comments.



Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:347
+if (TagTy->getDecl()->isStruct()) {
+  for (const auto &Struct : API.getStructs()) {
+if (Decl->getName() == Struct.second.get()->Name) {

dang wrote:
> What happens if the visitation hasn't already encountered the definition of 
> the struct? We wouldn't find it in the the APISet and this doesn't work. The 
> approach I would suggest here is to generate the fragments for the underlying 
> Decl directly. For example what happens for the following code:
> 
> ```c
> struct Foo;
> typedef struct Foo TypedefedFoo;
> struct Foo {
> int bar;
> };
> ```
Actually added an example for this. Our code works fine. Please take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146385

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


[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

2023-03-28 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 509004.
Ruturaj4 added a comment.



1. Updating D146385 : [clang][ExtractAPI] 
Complete declaration fragments for TagDecl types defined in a typedef #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Update main to avoid build failures.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146385

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

Index: clang/test/ExtractAPI/typedef_struct_enum.c
===
--- clang/test/ExtractAPI/typedef_struct_enum.c
+++ clang/test/ExtractAPI/typedef_struct_enum.c
@@ -21,6 +21,12 @@
   simple
 } Test2;
 
+struct Foo;
+typedef struct Foo TypedefedFoo;
+struct Foo {
+int bar;
+};
+
 //--- reference.output.json.in
 {
   "metadata": {
@@ -36,6 +42,11 @@
 "platform": {
   "architecture": "arm64",
   "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
 "name": "macosx"
   },
   "vendor": "apple"
@@ -47,6 +58,12 @@
   "source": "c:@E@Test2@simple",
   "target": "c:@E@Test2",
   "targetFallback": "Test2"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@FI@bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
 }
   ],
   "symbols": [
@@ -82,6 +99,14 @@
   "preciseIdentifier": "c:i",
   "spelling": "unsigned int"
 },
+{
+  "kind": "text",
+  "spelling": " { ... } "
+},
+{
+  "kind": "identifier",
+  "spelling": "Test2"
+},
 {
   "kind": "text",
   "spelling": ";"
@@ -187,6 +212,14 @@
   "kind": "identifier",
   "spelling": "Test"
 },
+{
+  "kind": "text",
+  "spelling": " { ... } "
+},
+{
+  "kind": "identifier",
+  "spelling": "Test"
+},
 {
   "kind": "text",
   "spelling": ";"
@@ -225,6 +258,184 @@
   "pathComponents": [
 "Test"
   ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "struct"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Structure",
+"identifier": "c.struct"
+  },
+  "location": {
+"position": {
+  "character": 8,
+  "line": 10
+},
+"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:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "bar"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Foo@FI@bar"
+  },
+  "kind": {
+"displayName": "Instance Property",
+"identifier": "c.property"
+  },
+  "location": {
+"position": {
+  "character": 9,
+  "line": 11
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "bar"
+  }
+],
+"title": "bar"
+  },
+  "pathComponents": [
+"Foo",
+"bar"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "keyword"

[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

2023-03-29 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 509472.
Ruturaj4 added a comment.



1. Updating D146385 : [clang][ExtractAPI] 
Complete declaration fragments for TagDecl types defined in a typedef #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

declare modifyRecord function "static"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146385

Files:
  clang/lib/ExtractAPI/ExtractAPIVisitor.cpp


Index: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
+++ clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
@@ -49,7 +49,7 @@
 }
 
 template 
-void modifyRecord(const T &Records, const llvm::StringRef &name) {
+static void modifyRecord(const T &Records, const llvm::StringRef &name) {
   for (const auto &Record : Records) {
 if (name == Record.second.get()->Name) {
   Record.second.get()->Declaration.removeLast();


Index: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
+++ clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
@@ -49,7 +49,7 @@
 }
 
 template 
-void modifyRecord(const T &Records, const llvm::StringRef &name) {
+static void modifyRecord(const T &Records, const llvm::StringRef &name) {
   for (const auto &Record : Records) {
 if (name == Record.second.get()->Name) {
   Record.second.get()->Declaration.removeLast();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

2023-03-29 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 marked an inline comment as done.
Ruturaj4 added inline comments.



Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:56
+  Record.second.get()->Declaration.removeLast();
+  Record.second.get()
+  ->Declaration

dang wrote:
> I think this warrants adding methods to declaration fragments to streamline 
> this sort of operation (merging fragments at arbitrary offsets. This should 
> probably be done as a follow up patch.
Ok I will add this in a subsequent patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146385

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


[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

2023-03-29 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 509473.
Ruturaj4 added a comment.



1. Updating D146385 : [clang][ExtractAPI] 
Complete declaration fragments for TagDecl types defined in a typedef #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

rebase and update patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146385

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

Index: clang/test/ExtractAPI/typedef_struct_enum.c
===
--- /dev/null
+++ clang/test/ExtractAPI/typedef_struct_enum.c
@@ -0,0 +1,441 @@
+// 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 \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// 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
+typedef struct Test {
+} Test;
+
+typedef enum Test2 {
+  simple
+} Test2;
+
+struct Foo;
+typedef struct Foo TypedefedFoo;
+struct Foo {
+int bar;
+};
+
+//--- 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:@E@Test2@simple",
+  "target": "c:@E@Test2",
+  "targetFallback": "Test2"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@FI@bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "keyword",
+  "spelling": "enum"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Test2"
+},
+{
+  "kind": "text",
+  "spelling": ": "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": " { ... } "
+},
+{
+  "kind": "identifier",
+  "spelling": "Test2"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@E@Test2"
+  },
+  "kind": {
+"displayName": "Enumeration",
+"identifier": "c.enum"
+  },
+  "location": {
+"position": {
+  "character": 14,
+  "line": 4
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Test2"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Test2"
+  }
+],
+"title": "Test2"
+  },
+  "pathComponents": [
+"Test2"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "identifier",
+  "spelling": "simple"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@E@Test2@simple"
+  },
+  "kind": {
+"displayName": "Enumeration Case",
+"identifier": "c.enum.case"
+  },
+  "location": {
+"position": {
+  "character": 3,
+  "line": 5
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "simple"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "simple

[PATCH] D151048: [clang][ExtractAPI] Modify declaration fragment methods to add a new fragment at an arbitrary offset.

2023-05-21 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 created this revision.
Ruturaj4 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
Ruturaj4 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The current implementation doesn't support merging declaration fragments at 
arbitrary offsets. This patch adds that support
by modifying declaration fragment methods.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151048

Files:
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h


Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -110,15 +110,16 @@
 static void modifyRecords(const T &Records, const StringRef &Name) {
   for (const auto &Record : Records) {
 if (Name == Record.second.get()->Name) {
-  Record.second.get()->Declaration.removeLast();
   Record.second.get()
   ->Declaration
-  .appendFront(" ", DeclarationFragments::FragmentKind::Text)
-  .appendFront("typedef", DeclarationFragments::FragmentKind::Keyword,
-   "", nullptr)
-  .append(" { ... } ", DeclarationFragments::FragmentKind::Text)
-  .append(Name, DeclarationFragments::FragmentKind::Identifier)
-  .append(";", DeclarationFragments::FragmentKind::Text);
+  .insertAtIndex(0, "typedef",
+ DeclarationFragments::FragmentKind::Keyword, "",
+ nullptr)
+  .insertAtIndex(1, " ", DeclarationFragments::FragmentKind::Text)
+  .insertAtIndex(-1, " { ... } ",
+ DeclarationFragments::FragmentKind::Text)
+  .insertAtIndex(-1, Name,
+ DeclarationFragments::FragmentKind::Identifier);
   break;
 }
   }
Index: clang/include/clang/ExtractAPI/DeclarationFragments.h
===
--- clang/include/clang/ExtractAPI/DeclarationFragments.h
+++ clang/include/clang/ExtractAPI/DeclarationFragments.h
@@ -99,25 +99,37 @@
 
   const std::vector &getFragments() const { return Fragments; }
 
-  // Add a new Fragment to the beginning of the Fragments.
-  DeclarationFragments &appendFront(StringRef Spelling, FragmentKind Kind,
-StringRef PreciseIdentifier = "",
-const Decl *Declaration = nullptr) {
-Fragments.emplace(Fragments.begin(), Spelling, Kind, PreciseIdentifier,
-  Declaration);
+  size_t calculateOffset(intmax_t Index) const {
+if (Index >= 0) {
+  size_t offset = static_cast(Index);
+  if (offset > Fragments.size()) {
+offset = Fragments.size();
+  }
+  return offset;
+}
+return Fragments.size() + static_cast(Index);
+  }
+
+  // Add a new Fragment at an arbitrary offset.
+  DeclarationFragments &insertAtIndex(intmax_t Index, StringRef Spelling,
+  FragmentKind Kind,
+  StringRef PreciseIdentifier = "",
+  const Decl *Declaration = nullptr) {
+Fragments.insert(
+Fragments.begin() + calculateOffset(Index),
+std::move(Fragment(Spelling, Kind, PreciseIdentifier, Declaration)));
 return *this;
   }
 
-  DeclarationFragments &appendFront(DeclarationFragments &&Other) {
-Fragments.insert(Fragments.begin(),
+  DeclarationFragments &insertAtIndex(intmax_t Index,
+  DeclarationFragments &&Other) {
+Fragments.insert(Fragments.begin() + calculateOffset(Index),
  std::make_move_iterator(Other.Fragments.begin()),
  std::make_move_iterator(Other.Fragments.end()));
 Other.Fragments.clear();
 return *this;
   }
 
-  void removeLast() { Fragments.pop_back(); }
-
   /// Append a new Fragment to the end of the Fragments.
   ///
   /// \returns a reference to the DeclarationFragments object itself after


Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -110,15 +110,16 @@
 static void modifyRecords(const T &Records, const StringRef &Name) {
   for (const auto &Record : Records) {
 if (Name == Record.second.get()->Name) {
-  Record.second.get()->Declaration.removeLast();
   Record.second.get()
   ->Declaration
-  .appendFront(" ", DeclarationFragments::FragmentKind::Text)
-  .appendFront("typedef", DeclarationFragments::FragmentKind::Keyword,
-   "", nullptr)
-  .append(" { ... } ", DeclarationFragments::FragmentKind:

[PATCH] D151048: [clang][ExtractAPI] Modify declaration fragment methods to add a new fragment at an arbitrary offset.

2023-05-27 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 marked 3 inline comments as done.
Ruturaj4 added a comment.

Daniel, I made all the changes as you desired, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151048

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


[PATCH] D151048: [clang][ExtractAPI] Modify declaration fragment methods to add a new fragment at an arbitrary offset.

2023-05-27 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 526296.
Ruturaj4 added a comment.



1. Updating D151048 : [clang][ExtractAPI] 
Modify declaration fragment methods to add a new fragment at an arbitrary 
offset. #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

I made all the suggested changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151048

Files:
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h


Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -110,16 +110,16 @@
 static void modifyRecords(const T &Records, const StringRef &Name) {
   for (const auto &Record : Records) {
 if (Name == Record.second.get()->Name) {
-  Record.second.get()
-  ->Declaration
-  .insertAtIndex(0, "typedef",
- DeclarationFragments::FragmentKind::Keyword, "",
- nullptr)
-  .insertAtIndex(1, " ", DeclarationFragments::FragmentKind::Text)
-  .insertAtIndex(-1, " { ... } ",
- DeclarationFragments::FragmentKind::Text)
-  .insertAtIndex(-1, Name,
- DeclarationFragments::FragmentKind::Identifier);
+  auto &DeclFragment = Record.second->Declaration;
+  DeclFragment.insert(DeclFragment.begin(), " ",
+  DeclarationFragments::FragmentKind::Text);
+  DeclFragment.insert(DeclFragment.begin(), "typedef",
+  DeclarationFragments::FragmentKind::Keyword, "",
+  nullptr);
+  DeclFragment.insert(--DeclFragment.end(), " { ... } ",
+  DeclarationFragments::FragmentKind::Text);
+  DeclFragment.insert(--DeclFragment.end(), Name,
+  DeclarationFragments::FragmentKind::Identifier);
   break;
 }
   }
Index: clang/include/clang/ExtractAPI/DeclarationFragments.h
===
--- clang/include/clang/ExtractAPI/DeclarationFragments.h
+++ clang/include/clang/ExtractAPI/DeclarationFragments.h
@@ -97,34 +97,32 @@
   Declaration(Declaration) {}
   };
 
+  using FragmentIterator = std::vector::iterator;
+  using ConstFragmentIterator = std::vector::const_iterator;
+
   const std::vector &getFragments() const { return Fragments; }
 
-  size_t calculateOffset(intmax_t Index) const {
-if (Index >= 0) {
-  size_t offset = static_cast(Index);
-  if (offset > Fragments.size()) {
-offset = Fragments.size();
-  }
-  return offset;
-}
-return Fragments.size() + static_cast(Index);
-  }
+  FragmentIterator begin() { return Fragments.begin(); }
+
+  FragmentIterator end() { return Fragments.end(); }
+
+  ConstFragmentIterator cbegin() const { return Fragments.cbegin(); }
+
+  ConstFragmentIterator cend() const { return Fragments.cend(); }
 
   // Add a new Fragment at an arbitrary offset.
-  DeclarationFragments &insertAtIndex(intmax_t Index, StringRef Spelling,
-  FragmentKind Kind,
-  StringRef PreciseIdentifier = "",
-  const Decl *Declaration = nullptr) {
-Fragments.insert(
-Fragments.begin() + calculateOffset(Index),
-std::move(Fragment(Spelling, Kind, PreciseIdentifier, Declaration)));
+  DeclarationFragments &insert(FragmentIterator It, StringRef Spelling,
+   FragmentKind Kind,
+   StringRef PreciseIdentifier = "",
+   const Decl *Declaration = nullptr) {
+Fragments.insert(It, std::move(Fragment(Spelling, Kind, PreciseIdentifier,
+Declaration)));
 return *this;
   }
 
-  DeclarationFragments &insertAtIndex(intmax_t Index,
-  DeclarationFragments &&Other) {
-Fragments.insert(Fragments.begin() + calculateOffset(Index),
- std::make_move_iterator(Other.Fragments.begin()),
+  DeclarationFragments &insert(FragmentIterator It,
+   DeclarationFragments &&Other) {
+Fragments.insert(It, std::make_move_iterator(Other.Fragments.begin()),
  std::make_move_iterator(Other.Fragments.end()));
 Other.Fragments.clear();
 return *this;


Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===
--- clang/include/clang/ExtractAPI/ExtractAPIVisit

[PATCH] D151048: [clang][ExtractAPI] Modify declaration fragment methods to add a new fragment at an arbitrary offset.

2023-05-30 Thread R4444 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 rG135ce2f820d8: [clang][ExtractAPI] Modify declaration 
fragment methods to add a new fragment… (authored by Ruturaj4).

Changed prior to commit:
  https://reviews.llvm.org/D151048?vs=526296&id=526816#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151048

Files:
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h


Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -110,15 +110,16 @@
 static void modifyRecords(const T &Records, const StringRef &Name) {
   for (const auto &Record : Records) {
 if (Name == Record.second.get()->Name) {
-  Record.second.get()->Declaration.removeLast();
   Record.second.get()
   ->Declaration
-  .appendFront(" ", DeclarationFragments::FragmentKind::Text)
-  .appendFront("typedef", DeclarationFragments::FragmentKind::Keyword,
-   "", nullptr)
-  .append(" { ... } ", DeclarationFragments::FragmentKind::Text)
-  .append(Name, DeclarationFragments::FragmentKind::Identifier)
-  .append(";", DeclarationFragments::FragmentKind::Text);
+  .insertAtIndex(0, "typedef",
+ DeclarationFragments::FragmentKind::Keyword, "",
+ nullptr)
+  .insertAtIndex(1, " ", DeclarationFragments::FragmentKind::Text)
+  .insertAtIndex(-1, " { ... } ",
+ DeclarationFragments::FragmentKind::Text)
+  .insertAtIndex(-1, Name,
+ DeclarationFragments::FragmentKind::Identifier);
   break;
 }
   }
Index: clang/include/clang/ExtractAPI/DeclarationFragments.h
===
--- clang/include/clang/ExtractAPI/DeclarationFragments.h
+++ clang/include/clang/ExtractAPI/DeclarationFragments.h
@@ -99,25 +99,37 @@
 
   const std::vector &getFragments() const { return Fragments; }
 
-  // Add a new Fragment to the beginning of the Fragments.
-  DeclarationFragments &appendFront(StringRef Spelling, FragmentKind Kind,
-StringRef PreciseIdentifier = "",
-const Decl *Declaration = nullptr) {
-Fragments.emplace(Fragments.begin(), Spelling, Kind, PreciseIdentifier,
-  Declaration);
+  size_t calculateOffset(intmax_t Index) const {
+if (Index >= 0) {
+  size_t offset = static_cast(Index);
+  if (offset > Fragments.size()) {
+offset = Fragments.size();
+  }
+  return offset;
+}
+return Fragments.size() + static_cast(Index);
+  }
+
+  // Add a new Fragment at an arbitrary offset.
+  DeclarationFragments &insertAtIndex(intmax_t Index, StringRef Spelling,
+  FragmentKind Kind,
+  StringRef PreciseIdentifier = "",
+  const Decl *Declaration = nullptr) {
+Fragments.insert(
+Fragments.begin() + calculateOffset(Index),
+std::move(Fragment(Spelling, Kind, PreciseIdentifier, Declaration)));
 return *this;
   }
 
-  DeclarationFragments &appendFront(DeclarationFragments &&Other) {
-Fragments.insert(Fragments.begin(),
+  DeclarationFragments &insertAtIndex(intmax_t Index,
+  DeclarationFragments &&Other) {
+Fragments.insert(Fragments.begin() + calculateOffset(Index),
  std::make_move_iterator(Other.Fragments.begin()),
  std::make_move_iterator(Other.Fragments.end()));
 Other.Fragments.clear();
 return *this;
   }
 
-  void removeLast() { Fragments.pop_back(); }
-
   /// Append a new Fragment to the end of the Fragments.
   ///
   /// \returns a reference to the DeclarationFragments object itself after


Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -110,15 +110,16 @@
 static void modifyRecords(const T &Records, const StringRef &Name) {
   for (const auto &Record : Records) {
 if (Name == Record.second.get()->Name) {
-  Record.second.get()->Declaration.removeLast();
   Record.second.get()
   ->Declaration
-  .appendFront(" ", DeclarationFragments::FragmentKind::Text)
-  .appendFront("typedef", DeclarationFragments::FragmentKind::Keyword,
-   "", nullptr)
-  .append(" { ... } ", DeclarationFragments::Fragment