go-macho icon indicating copy to clipboard operation
go-macho copied to clipboard

fix: method argument name collision

Open t0rr3sp3dr0 opened this issue 1 year ago • 2 comments

Sometimes, the generated argument name for methods collide with reserved words. This patch simplifies the name of method arguments to prevent these collisions.

  • Before:
@interface AMSBagUnderlyingDataPersistence

- (id)underlyingDataFor:(id)for error:(id *)_error;
  • After:
@interface AMSBagUnderlyingDataPersistence

- (id)underlyingDataFor:(id)arg0 error:(id *)arg1;

t0rr3sp3dr0 avatar May 17 '24 07:05 t0rr3sp3dr0

That's the way I used to have it, but much preferred the auto completion with best guess names.

It might be impossible to achieve but would it be possible to check generated names vs keyword list then prepend arg if it is a keyword?

blacktop avatar May 17 '24 08:05 blacktop

I'm willing to concede if there are too many edge cases etc

blacktop avatar May 17 '24 08:05 blacktop

I think is not hard to create a table of reversed words and prepend something to the identifier. The only possible problem that comes to my mind is if we have a typedef’d name that collides with the argument name. But not 100% sure that is a problem, maybe the compiler allows it.

t0rr3sp3dr0 avatar May 17 '24 17:05 t0rr3sp3dr0

Ideally, I would like to implement this: https://github.com/apple/swift/blob/main/docs/CToSwiftNameTranslation.md#objective-c-methods

It explains with a lot of detail how Swift picks argument names for Objective-C methods.

But it would require an amount of time that I don’t think it’s worth spending right now.

t0rr3sp3dr0 avatar May 17 '24 17:05 t0rr3sp3dr0

Done, added a list of C and C++ reserved words. If an argument name matches a keyword, an underscore is prepended to the identifier.

It seems there are no true reserved words in Objective-C, clang was able to compile methods with arguments named BOOL, Class, SEL, and id.

t0rr3sp3dr0 avatar May 17 '24 23:05 t0rr3sp3dr0

Ideally, I would like to implement this: https://github.com/apple/swift/blob/main/docs/CToSwiftNameTranslation.md#objective-c-methods

It explains with a lot of detail how Swift picks argument names for Objective-C methods.

But it would require an amount of time that I don’t think it’s worth spending right now.

This would be great and what my lazy implementation was trying to mimic

blacktop avatar May 18 '24 08:05 blacktop