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

dotnet: how to represent getter/setters #939

Closed
williballenthin opened this issue Apr 4, 2022 · 13 comments
Closed

dotnet: how to represent getter/setters #939

williballenthin opened this issue Apr 4, 2022 · 13 comments
Labels
dotnet question Further information is requested
Milestone

Comments

@williballenthin
Copy link
Collaborator

dotnet may emit accessor/mutators (getter/setters) for some fields rather than direct field access. how do we recognize and emit these features?

@williballenthin williballenthin added question Further information is requested dotnet labels Apr 4, 2022
@williballenthin
Copy link
Collaborator Author

need concrete example

@williballenthin
Copy link
Collaborator Author

suspect that getter/setter is identified via method def flag

@williballenthin
Copy link
Collaborator Author

do we need a few feature for instance property access? do we reuse offset?

e.g.

- property: System.Net.FtpWebResponse.statusCode
- offset: System.Net.FtpWebResponse.statusCode

@mike-hunhoff
Copy link
Collaborator

Screen Shot 2022-04-07 at 10 43 09 AM

@mike-hunhoff
Copy link
Collaborator

for imported classes we may be able to identify getter/setter by signature type; specifically if the signature is of type Property.

Screen Shot 2022-04-07 at 10 58 02 AM

@williballenthin
Copy link
Collaborator Author

williballenthin commented Apr 7, 2022 via email

@mike-hunhoff
Copy link
Collaborator

example:

C#:

ftpRequest.KeepAlive = false;

IL:

IL_0000: callvirt  instance void [System]System.Net.FtpWebRequest::set_KeepAlive(bool)

@mike-hunhoff
Copy link
Collaborator

mike-hunhoff commented May 5, 2022

I like the idea of adding new property and field features. it may also be useful for users to specify whether a property/field is read/written.

detection should be fairly straightforward. non-public fields are accessed via properties, which we can identify using the .NET metadata. public fields, from my understanding, are accessed directly using CIL instructions stfld/stsfld, ldfld/ldflda/ldsfld/ldsflda.

I'm unsure how to represent read/writes to properties/fields if we decide to go that route.

(1) use / notation:

- property/get: System.Net.FtpWebRequest::KeepAlive

(2) use the get_ and set_ nomenclature seen in dnSpy:

- property: System.Net.FtpWebRequest::get_KeepAlive

(3) don't facilitate read/write access:

- property: System.Net.FtpWebRequest::KeepAlive

I lean towards 3 simply because I can't think of an example where it would be useful to specify read/write access.

@williballenthin
Copy link
Collaborator Author

do you think its important to differentiate properties from fields?

@mike-hunhoff
Copy link
Collaborator

No, I think it'd be fine to choose one feature term to represent both. If I were to choose one I'd prefer field or to reuse offset as you suggested.

@mr-tz
Copy link
Collaborator

mr-tz commented May 6, 2022

I think (3) is sufficient for now. I'm not a fan of the other syntax proposals.

@mr-tz
Copy link
Collaborator

mr-tz commented Aug 10, 2022

I've changed my mind and think differentiating between read and write would be useful.

1.

- property/get: System.Net.FtpWebRequest::KeepAlive
- property/set: System.Net.FtpWebRequest::KeepAlive

2.

- property/read: System.Net.FtpWebRequest::KeepAlive
- property/write: System.Net.FtpWebRequest::KeepAlive

3.

- property/r: System.Net.FtpWebRequest::KeepAlive
- property/w: System.Net.FtpWebRequest::KeepAlive

I'm in favor of 2. since it's clear and appears most versatile (across languages/formats).

@mike-hunhoff
Copy link
Collaborator

closed by #1168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants