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

codegen: add support for abstract classes #80

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions internal/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ func (g *generator) createGenClass(typeDef *winmd.TypeDef) (*genClass, error) {
ImplInterfaces: implInterfaces,
ExclusiveInterfaces: exclusiveGenInterfaces,
HasEmptyConstructor: hasEmptyConstructor,
IsAbstract: typeDef.Flags.Abstract(),
}, nil
}

Expand Down Expand Up @@ -1155,6 +1156,12 @@ func (g *generator) Signature(typeDef *winmd.TypeDef) (string, error) {

return fmt.Sprintf(`delegate({%s})`, guid), nil
case typeDef.IsRuntimeClass():
// Static only classes carry the abstract flag.
// These cannot be instantiated so no signature needed.
if typeDef.Flags.Abstract() {
return "", nil
}

// runtime_class_signature => "rc(" runtime_class_name ";" default_interface ")"

// Runtime classes must specify the DefaultAttribute on exactly one of their InterfaceImpl rows.
Expand Down
1 change: 1 addition & 0 deletions internal/codegen/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type genClass struct {
ImplInterfaces []*genInterface
ExclusiveInterfaces []*genInterface
HasEmptyConstructor bool
IsAbstract bool
}

func (g *genClass) GetRequiredImports() []*genImport {
Expand Down
2 changes: 2 additions & 0 deletions internal/codegen/templates/class.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{if not .IsAbstract}}
const Signature{{.Name}} string = "{{.Signature}}"

type {{.Name}} struct {
Expand All @@ -13,6 +14,7 @@ func New{{.Name}}() (*{{.Name}}, error) {
return (*{{.Name}})(unsafe.Pointer(inspectable)), nil
}
{{end}}
{{end}}

{{$owner := .Name}}
{{range .ImplInterfaces}}
Expand Down
Loading