-
-
Notifications
You must be signed in to change notification settings - Fork 656
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
[cpp] Gencpp Rework Mk II #11819
Open
Aidan63
wants to merge
75
commits into
HaxeFoundation:development
Choose a base branch
from
Aidan63:gencpp_rework_mkii
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[cpp] Gencpp Rework Mk II #11819
+2,511
−2,158
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a follow up to my previous cpp generator rework and is what I was aiming for in the first place.
Class and interface generation (as well as native and managed variants) was contained in one big function with a sprawling set of if statements to generate code based on those 4 types. Incorrect branches being taken has been the root of several bugs and the code in general is very unweildy and hard to extend.
When module level functions came out I had a go at extending the generator to output these as namespace level functions / variables but gave up as adding an extra variant was too much to deal with.
So now the cpp generate splits types into one of 5 categories, native class, managed class, native interface, managed interface. or enums. There are now dedicated generator functions for the header and implementation code of these 5 types which is mostly stitching together calls to shared functions with very little branching involved.
The fields for the class and interface types are also split up to make the generators work easier.
tclass_field
s are divided up into variables (physical), properties (non physical), functions, and dynamic functions. This means that areas such as generating mark and visit functions only need to iterate over the variables which makes the code much easier to follow. Previously it was iterating over all fields and needing to filter out dynamic functions, non physical fields, etc.This division works really well and there is no case where parts of the generator needs to then further filter the lists which is quite satisfying. When these fields get split up we also handle various hxcpp implementation details. E.g. dynamic functions will put a variable into othe variable list, abstract functions will place a no-op function into the function list, and variables with default functions will place a dynamic function into the dynamic function list. These means a lot of the edge cases which were handled multiple times in various places in the generator are now handled once at retyping which, again, simplifies the generators code.
Some stuff such as class Ids and interface slots are now assigned during retyping which means the context is now more immutable.
There was more I was thinking of doing such as the retyped classes containg tcpp expressions and types but this has been going on for quite a while now and I think its good enough. I've manually ran the hxcpp test suite and it all passes and I've ran some of the tests with the generational GC and that still works.