Skip to content

Commit

Permalink
Merge pull request #80 from saltosystems/feature/add-support-for-abst…
Browse files Browse the repository at this point in the history
…ract-classes

codegen: add support for abstract classes
  • Loading branch information
jagobagascon authored Oct 11, 2023
2 parents 2ab5b7d + 552f0fd commit 9071442
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
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

0 comments on commit 9071442

Please sign in to comment.