Skip to content

Add C-Style casts support#26

Merged
simonrozsival merged 5 commits into
simonrozsival:binding-source-generatorfrom
jkurdek:cstyle-casts
Apr 30, 2024
Merged

Add C-Style casts support#26
simonrozsival merged 5 commits into
simonrozsival:binding-source-generatorfrom
jkurdek:cstyle-casts

Conversation

@jkurdek
Copy link
Copy Markdown
Collaborator

@jkurdek jkurdek commented Apr 24, 2024

No description provided.

Copy link
Copy Markdown
Owner

@simonrozsival simonrozsival left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. Thanks for moving the models to a separate file.


if (foundCast && part is MemberAccess memberAccess)
{
array[i] = new ConditionalAccess(memberAccess);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct to keep the foundCast set to true? Shouldn't we "reset" it after the first member access"? Also when there is a ConditionalAccess, shouldn't that reset the flag too?

Comment on lines +62 to +64
new ConditionalAccess(new MemberAccess("X")),
new ConditionalAccess(new MemberAccess("Y")),
new ConditionalAccess(new MemberAccess("Z")),
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the correct transformation would be turning just the first MemberAccess into a conditional one. Or am I missing something?

return TransformExplicitCastsToAsCasts(source);
}

private static CodeWriterBinding TransformExplicitCastsToAsCasts(CodeWriterBinding source) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we want to move this code to a separate class. I see value in being able to test this separately, but it seems too complicated for this use case. If we were planning on adding more transforms, it might be great way to do this, but I don't think we'll add more. I would personally implement a similar loop in AppendHandlersArray to correctly insert ? and test this using integration tests. What do you think?

@simonrozsival simonrozsival merged commit a573668 into simonrozsival:binding-source-generator Apr 30, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators May 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants