-
Notifications
You must be signed in to change notification settings - Fork 23
feat: implement interface inheritance support in code generator #104
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for interface inheritance in code generation, enabling the system to generate wrapper methods for functions inherited from base interfaces.
Key changes:
- Added an
Inheritanceconfiguration flag to enable/disable interface inheritance handling - Modified template logic to exclude inherited methods from VTables and generate QueryInterface-based wrappers instead
- Implemented recursive interface method collection to gather all inherited functions
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/codegen/templates/interface.tmpl | Filters out inherited methods from VTable structure generation |
| internal/codegen/templates/funcimpl.tmpl | Adds QueryInterface-based delegation for inherited methods |
| internal/codegen/config.go | Adds Inheritance configuration field |
| internal/codegen/codegen.go | Implements inheritance logic and getInheritedInterfaceMethods function |
| internal/cli/cli.go | Adds CLI flag for inheritance feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I forgot to update the README.md. I'll do that later. |
501169e to
71375b3
Compare
7dab0ad to
07a34cc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
07a34cc to
52856f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@zandercodes could you include the WinRT class/interface you want to generate in this PR? The value of this project lays in the generated code, and updating the generator without adding any code does not make much sense. And it would also be helpful for the review to have some code generated. |
2677b90 to
5c72684
Compare
|
@jagobagascon |
|
I still need to fix the “sanity check” issue. |
jagobagascon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that you are recursively calling to the GetImplementedInterfaces() which is causing problems with duplicated methods in your code.
For example the CharacteristicProperties property belongs to the iGattCharacteristic interface (see)
But since iGattCharacteristic2 also extends iGattCharacteristic you are getting that method twice.
This is the data returned by processImplementedInterfaces():
-> Generating class: GattCharacteristic
-> Implementing interface: IGattCharacteristic
-> Method: GetDescriptors
-> Method: get_CharacteristicProperties
-> Method: ...
...
-> Implementing interface: IGattCharacteristic2
-> Method: get_Service
-> Method: ...
-> Method: GetDescriptors inherited from: iGattCharacteristic
-> Method: get_CharacteristicProperties inherited from: iGattCharacteristic
...
The methods inherited by IGattCharacteristic2 should be ignored. They are already available via GattCharacteristic.
This is the code I would expect to be generated:
func (* GattCharacteristic) GetCharacteristicProperties() {
itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattCharacteristic))
...
}
func (* iGattCharacteristic2) GetCharacteristicProperties() {
itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattCharacteristic))
...
}
func (* iGattCharacteristic) GetCharacteristicProperties() {
syscall(...)
}
Add comprehensive WinRT interface inheritance handling: - Add processImplementedInterfaces() to resolve and process parent interface methods - Implement getInterfaceWrapperMethods() for generating delegation methods - Add removeDuplicateMethods() to prevent method conflicts in interface hierarchies - Fix WinRT classes not exposing methods from implemented interfaces Refactor and improve WinRT code generator: - Extract helper functions from createGenClass(): * processStaticAttributes() - handles StaticAttribute custom attributes * processActivatableAttributes() - processes ActivatableAttribute blobs * generateExclusiveInterfaces() - generates exclusive/private interfaces - Add isValidEnumInstanceField() and isValidEnumValueField() validators - Replace magic number 0x4000 with tdWindowsRuntime constant - Pre-allocate slices with proper capacity hints for better performance - Add comprehensive error wrapping with fmt.Errorf and %w - Add GoDoc comments to all major functions Add new WinRT code generation templates: - funcext.tmpl - generates inherited interface method wrappers via QueryInterface - paramforwarding.tmpl - handles parameter forwarding for delegated methods - Update class.tmpl, funcimpl.tmpl, interface.tmpl for inheritance support This enables proper COM-style interface inheritance in generated WinRT Go bindings while maintaining type safety and resource management. Breaking Changes: None - these are enhancements and bug fixes
5c72684 to
8b29c91
Compare
|
@jagobagascon Status? |
This code adds the interface inheritance functions to be created.