Skip to content

Commit

Permalink
PURGE (part 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondburned committed Oct 16, 2024
1 parent 30a99fe commit ff5fdfa
Show file tree
Hide file tree
Showing 22 changed files with 173,867 additions and 272,651 deletions.
2 changes: 0 additions & 2 deletions gir/girgen/generators/callable/callable.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,6 @@ func (g *Generator) renderDynamicLinkedBlock() bool {
}

func (g *Generator) renderRuntimeLinkedBlock() bool {
return false // TODO

const (
secInputDecl = iota
secInputConv
Expand Down
125 changes: 0 additions & 125 deletions gir/girgen/generators/class-interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/diamondburned/gotk4/gir"
"github.com/diamondburned/gotk4/gir/girgen/file"
"github.com/diamondburned/gotk4/gir/girgen/gotmpl"
"github.com/diamondburned/gotk4/gir/girgen/strcases"
"github.com/diamondburned/gotk4/gir/girgen/types"

ifacegen "github.com/diamondburned/gotk4/gir/girgen/generators/iface"
Expand All @@ -13,38 +12,6 @@ import (
var classInterfaceTmpl = gotmpl.NewGoTemplate(`
{{ $wrapper := .Tree.WrapName false }}
{{ if .GLibTypeStruct }}
{{ if .IsClass }}
// {{ .StructName }}Overrides contains methods that are overridable.
type {{ .StructName }}Overrides struct {
{{ range .GLibTypeStruct.VirtualMethods -}}
{{ if $.IsInSameFile . -}}
{{- GoDoc .Go 1 TrailingNewLine -}}
{{- .Go.Name }} func{{ .Go.Tail }}
{{ end -}}
{{ end -}}
}
func default{{ .StructName }}Overrides(v *{{ .StructName }}) {{ .StructName }}Overrides{
return {{ .StructName }}Overrides{
{{ range .GLibTypeStruct.VirtualMethods -}}
{{ .Go.Name }}: v.{{ UnexportPascal .Go.Name }},
{{ end -}}
}
}
{{ else }}
// {{ .StructName }}Overrider contains methods that are overridable.
type {{ .StructName }}Overrider interface {
{{ range .GLibTypeStruct.VirtualMethods -}}
{{ if $.IsInSameFile . -}}
{{- GoDoc .Go 1 TrailingNewLine -}}
{{- .Go.Name }}{{ .Go.Tail }}
{{ end -}}
{{ end -}}
}
{{ end }}
{{ end }}
{{ GoDoc . 0 (OverrideSelfName .StructName) }}
{{ if not .IsClass -}}
//
Expand Down Expand Up @@ -111,72 +78,6 @@ var classInterfaceTmpl = gotmpl.NewGoTemplate(`
var _ {{ .InterfaceName }} = (*{{ .StructName }})(nil)
{{ end }}
{{ if .GLibTypeStruct }}
{{ if .IsClass }}
{{ Import . "unsafe" }}
func init() {
coreglib.RegisterClassInfo[*{{ .StructName }}, *{{ .GLibTypeStruct.Name }}, {{ .StructName }}Overrides](
GType{{ .StructName }},
init{{ .GLibTypeStruct.Name }},
{{ $wrapper }},
default{{ .StructName }}Overrides,
)
}
func init{{ .GLibTypeStruct.Name }}(gclass unsafe.Pointer, overrides {{ .StructName }}Overrides, classInitFunc func(*{{ .GLibTypeStruct.Name }})) {
{{- if .GLibTypeStruct.VirtualMethods }}
{{- if .IsRuntimeLinkMode }}
{{- ImportCore . "girepository" -}}
classt := girepository.MustFind({{ Quote .Root.Namespace.Name }}, {{ Quote .GLibTypeStruct.Record.Name }})
pclass := unsafe.Pointer(C.g_type_check_class_cast((*C.GTypeClass)(gclass), C.GType(GType{{ .StructName }})))
{{ range .GLibTypeStruct.VirtualMethods }}
if overrides.{{ .Go.Name }} != nil {
o := classt.StructFieldOffset({{ Quote .FieldName }})
*(*unsafe.Pointer)(unsafe.Add(unsafe.Pointer(pclass), o)) = unsafe.Pointer(C.{{ .C.Name }})
}
{{ end -}}
{{- else }}
pclass := (*C.{{ .GLibTypeStruct.CType }})(unsafe.Pointer(C.g_type_check_class_cast((*C.GTypeClass)(gclass), C.GType(GType{{ .StructName }}))))
{{ range .GLibTypeStruct.VirtualMethods }}
if overrides.{{ .Go.Name }} != nil {
pclass.{{ CGoField .FieldName }} = (*[0]byte)(C.{{ .C.Name }})
}
{{ end }}
{{ end -}}
{{ end -}}
if classInitFunc != nil {
{{- ImportCore . "gextras" -}}
class := (*{{ .GLibTypeStruct.Name }})(gextras.NewStructNative(gclass))
classInitFunc(class)
}
}
{{ else }}
func ifaceInit{{ .InterfaceName }}(gifacePtr, data C.gpointer) {
{{- Import . "unsafe" -}}
{{- if .GLibTypeStruct.VirtualMethods }}
{{- if .IsRuntimeLinkMode}}
iface := girepository.MustFind({{ Quote .Root.Namespace.Name }}, {{ Quote .GLibTypeStruct.Record.Name }})
{{- range .GLibTypeStruct.VirtualMethods}}
*(*unsafe.Pointer)(unsafe.Add(unsafe.Pointer(gifacePtr), iface.StructFieldOffset({{ Quote .FieldName }}))) = unsafe.Pointer(C.{{ .C.Name }})
{{- end }}
{{- else }}
iface := (*C.{{ .GLibTypeStruct.CType }})(unsafe.Pointer(gifacePtr))
{{- range .GLibTypeStruct.VirtualMethods }}
iface.{{ CGoField .FieldName }} = (*[0]byte)(C.{{ .C.Name }})
{{- end }}
{{- end }}
{{- end }}
}
{{ end }}
{{ end }}
func {{ $wrapper }}(obj *coreglib.Object) *{{ .StructName }} {
return {{ .Wrap "obj" }}
}
Expand Down Expand Up @@ -288,13 +189,6 @@ func generateInterfaceGenerator(gen FileGeneratorWriter, igen *ifacegen.Generato
parent.Resolved.ImportImpl(gen, writer.Header())
}

// These conditions should follow what's in the template.
if igen.GLibTypeStruct != nil {
if gen.LinkMode() == types.RuntimeLinkMode && len(igen.GLibTypeStruct.VirtualMethods) > 0 {
writer.Header().ImportCore("girepository")
}
}

data := ifacegenData{
Generator: igen,
ImplInterfaces: igen.ImplInterfaces(),
Expand Down Expand Up @@ -323,25 +217,6 @@ func generateInterfaceGenerator(gen FileGeneratorWriter, igen *ifacegen.Generato
})
}

for _, virtual := range igen.VirtualMethods {
// Unexport virtual method calls.
virtual.Name = strcases.UnexportPascal(virtual.Name)

writer.Header().ApplyFrom(&virtual.Header)
writer.Pen().WriteTmpl(methodInterfaceTmpl, gotmpl.M{
"Method": virtual,
"StructName": igen.StructName,
})
}

if igen.GLibTypeStruct != nil {
for _, virtual := range igen.GLibTypeStruct.VirtualMethods {
writer := FileWriterExportedFromType(gen, virtual)
writer.Header().ApplyFrom(virtual.C.Header)
writer.Pen().WriteTmpl(virtualExportedInterfaceTmpl, virtual)
}
}

for _, signal := range igen.Signals {
for _, result := range signal.Results {
// Apply type imports into the main file.
Expand Down
40 changes: 11 additions & 29 deletions gir/girgen/generators/iface/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,24 @@ func CanGenerate(gen types.FileGenerator, v interface{}) bool {
type Generator struct {
Root gir.TypeFindResult

Name string
CType string
GLibGetType string
GLibTypeStruct *TypeStruct
InfoAttrs *gir.InfoAttrs
InfoElements *gir.InfoElements
Name string
CType string
GLibGetType string
InfoAttrs *gir.InfoAttrs
InfoElements *gir.InfoElements

InterfaceName string
StructName string

VirtualMethods Methods
Methods Methods // for big interface
Constructors Methods
Signals []Signal
Methods Methods // for big interface
Constructors Methods
Signals []Signal

Tree types.Tree

// Abstract bool

methods []gir.Method
virtuals []gir.VirtualMethod
methods []gir.Method

header file.Header
gen types.FileGenerator
Expand Down Expand Up @@ -103,12 +100,10 @@ func (g *Generator) Reset() {

g.Tree.Reset()
g.Methods.reset(0)
g.VirtualMethods.reset(0)

*g = Generator{
Tree: g.Tree,
Methods: g.Methods,
VirtualMethods: g.VirtualMethods,
Tree: g.Tree,
Methods: g.Methods,

header: g.header,
cgen: g.cgen,
Expand Down Expand Up @@ -179,7 +174,6 @@ func (g *Generator) init(typ interface{}) bool {
g.InfoElements = &typ.InfoElements

g.methods = typ.Methods
g.virtuals = typ.VirtualMethods

if types.Filter(g.gen, typ.Name, typ.CType) {
g.Logln(logger.Debug, "class is filtered")
Expand All @@ -203,7 +197,6 @@ func (g *Generator) init(typ interface{}) bool {
g.InfoElements = &typ.InfoElements

g.methods = typ.Methods
g.virtuals = typ.VirtualMethods

if types.Filter(g.gen, typ.Name, typ.CType) {
g.Logln(logger.Debug, "interface is filtered")
Expand Down Expand Up @@ -302,16 +295,7 @@ func (g *Generator) Use(typ interface{}) bool {
}

g.Methods.setMethods(g, g.methods)
g.VirtualMethods.setVirtuals(g, g.virtuals)

g.renameGetters(g.Methods)
g.renameGetters(g.VirtualMethods)

if g.GLibTypeStruct != nil {
if !g.GLibTypeStruct.Init() {
g.GLibTypeStruct = nil
}
}

callbackGen := callback.NewGenerator(g.gen)
callbackGen.Parent = g.Root.Type
Expand Down Expand Up @@ -461,8 +445,6 @@ func (g *Generator) checkTypeStruct(girName string) {
g.Logln(logger.Skip, "type-struct skipped since disgused type record in runtime link mode")
return
}

g.GLibTypeStruct = newTypeStruct(g, result)
}

func (g *Generator) ImplInterfaces() []string {
Expand Down
Loading

0 comments on commit ff5fdfa

Please sign in to comment.