Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance Variable Names Not Available For Objective-C Pointer Types (with Protocols/Generics) #45

Open
devm18426 opened this issue Mar 5, 2023 · 1 comment
Labels
question Further information is requested

Comments

@devm18426
Copy link

I'm experiencing some strange behavior while parsing the following Objective-C code:

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.

@sighingnow
Copy link
Owner

I'm not familiar of Objective-C but I think it should be posted to LLVM discussion forums. This repo only provides pre-compiled Python packages to help the installation process and has nothing to do with the behavior of clang parser itself.

@sighingnow sighingnow added the question Further information is requested label Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants