<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61207>61207</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Python bindings - Parsing Objective-C protocols/generics
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
devm18426
</td>
</tr>
</table>
<pre>
I'm experiencing some strange behavior while parsing the following Objective-C code:
```python
code = """@class NSObject, SomeProtocol;
@interface OtherClass : NSObject {
id* testVar;
id*<SomeProtocol> objWithSomeMethod;
NSObject*<SomeProtocol> objWithSomeMethod2;
NSObject<SomeProtocol> objWithSomeMethod3;
}
@end"""
translation_unit = i.parse("test.h", unsaved_files=(("test.h", code),), args=("-x", "objective-c"))
# Access instance variable declarations
instance_cursors = list(list(translation_unit.cursor.get_children())[3].get_children())
testvar_cursor, objwithsomemethod_cursor, objwithsomemethod2_cursor, objwithsomemethod3_cursor = instance_cursors
print(f"testVar: {testvar_cursor.kind=} {testvar_cursor.objc_type_encoding=} {testvar_cursor.type.kind=} {testvar_cursor.displayname=}")
print(f"objWithSomeMethod: {objwithsomemethod_cursor.kind=} {objwithsomemethod_cursor.objc_type_encoding=} {objwithsomemethod_cursor.type.kind=} {objwithsomemethod_cursor.displayname=}")
print(f"objWithSomeMethod2: {objwithsomemethod2_cursor.kind=} {objwithsomemethod2_cursor.objc_type_encoding=} {objwithsomemethod2_cursor.type.kind=} {objwithsomemethod2_cursor.displayname=}")
print(f"objWithSomeMethod3: {objwithsomemethod3_cursor.kind=} {objwithsomemethod3_cursor.objc_type_encoding=} {objwithsomemethod3_cursor.type.kind=} {objwithsomemethod3_cursor.displayname=}")
```
Result:
```
testVar: testvar_cursor.kind=CursorKind.OBJC_IVAR_DECL testvar_cursor.objc_type_encoding='^@' testvar_cursor.type.kind=TypeKind.POINTER testvar_cursor.displayname='test'
objWithSomeMethod: objwithsomemethod_cursor.kind=CursorKind.OBJC_IVAR_DECL objwithsomemethod_cursor.objc_type_encoding='^@' objwithsomemethod_cursor.type.kind=TypeKind.POINTER objwithsomemethod_cursor.displayname=''
objWithSomeMethod2: objwithsomemethod2_cursor.kind=CursorKind.OBJC_IVAR_DECL objwithsomemethod2_cursor.objc_type_encoding='@' objwithsomemethod2_cursor.type.kind=TypeKind.OBJCOBJECTPOINTER objwithsomemethod2_cursor.displayname=''
objWithSomeMethod3: objwithsomemethod3_cursor.kind=CursorKind.OBJC_IVAR_DECL objwithsomemethod3_cursor.objc_type_encoding='{NSObject=}' objwithsomemethod3_cursor.type.kind=TypeKind.OBJCINTERFACE objwithsomemethod3_cursor.displayname='objWithSomeMethod3'
```
It would appear that the cursor `displayname` (and `spelling`) properties are empty when the cursor type is `POINTER` or `OBJCOBJECTPOINTER` and the type contains Objective-C protocol information. The regular protocol-less pointer `testVar` seems to work fine.
Additionally, I see no way to access the protocol modifier on the type declaration of the variables (the angle brackets `<SomeProtocol>`). The variable types are reported as simple pointers without any protocol information that I can identify.
I've also included `objWithSomeMethod3` which is not a pointer (`OBJCINTERFACE`) but has a protocol defined. The `displayname` works fine however protocol info is likewise unavailable.
Is this behavior intended or am I missing something?
Thanks.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysl99v4j4SwP8a8zIqSh0g8MADhVbq3t222q32HpGTDMStY0e2A8t_fxqH30267d5XQiAyPz8zHhgL5-RaI07Z8I4NFz1R-8LYaY6b8nY84KNeavLd9JHxpAT8XaGVqDOp1-BMieC8FXqNkGIhNtJY2BZSIVTCOtLxBcLKKGW29O0pfcXMyw3ezCEzObJ4xqIFiw7vo6h5VTtfGH0uIm1g8QIY5_vXIMqUcA6-_2zcMj6Hn6bEZ2u8yYxi8d2F80EktUe7EhnCky_QzoM5i2dHF8CSvQ0AgMwZn4FH538Je_R2lLB4fhnuHkz6-l_pC3r8H_SFyU9Wpyw_Zcgv4h2NP2EZn7iTxREddX6q3FlVqHtO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