Skip to content

Conversation

@zandercodes
Copy link

This code adds the interface inheritance functions to be created.

Copilot AI review requested due to automatic review settings October 28, 2025 00:32
Copy link

Copilot AI left a 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 Inheritance configuration 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.

@zandercodes zandercodes marked this pull request as draft October 28, 2025 09:57
@zandercodes
Copy link
Author

I forgot to update the README.md. I'll do that later.

@zandercodes zandercodes force-pushed the feature-add-inheritance branch from 501169e to 71375b3 Compare October 28, 2025 10:46
@zandercodes zandercodes marked this pull request as ready for review October 28, 2025 10:47
@zandercodes zandercodes marked this pull request as draft October 28, 2025 12:59
@zandercodes zandercodes force-pushed the feature-add-inheritance branch 2 times, most recently from 7dab0ad to 07a34cc Compare October 29, 2025 17:39
@zandercodes zandercodes requested a review from Copilot October 30, 2025 07:57
Copy link

Copilot AI left a 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.

@zandercodes zandercodes force-pushed the feature-add-inheritance branch from 07a34cc to 52856f4 Compare October 30, 2025 08:15
@zandercodes zandercodes requested a review from Copilot October 30, 2025 08:16
Copy link

Copilot AI left a 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.

@jagobagascon
Copy link
Contributor

@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.

@zandercodes zandercodes force-pushed the feature-add-inheritance branch from 2677b90 to 5c72684 Compare November 1, 2025 23:27
@zandercodes
Copy link
Author

zandercodes commented Nov 1, 2025

@jagobagascon
I should be done now.
I tested this with my application and everything is working so far.
As far as the code is concerned, only the inheritance of the class and its functions were added during generation.
Then I made some adjustments to codegen.go, which made the code a little clearer.
I would say you can now perform a review. I am satisfied so far.

@zandercodes zandercodes marked this pull request as ready for review November 1, 2025 23:34
@zandercodes zandercodes marked this pull request as draft November 3, 2025 16:35
@zandercodes
Copy link
Author

I still need to fix the “sanity check” issue.

Copy link
Contributor

@jagobagascon jagobagascon left a 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
@zandercodes zandercodes force-pushed the feature-add-inheritance branch from 5c72684 to 8b29c91 Compare November 4, 2025 14:33
@zandercodes zandercodes changed the title feat: add support for interface inheritance in code generation feat: implement interface inheritance support in code generator Nov 4, 2025
@zandercodes zandercodes marked this pull request as ready for review November 4, 2025 14:47
@zandercodes
Copy link
Author

@jagobagascon Status?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants