Skip to content

Commit 66531b8

Browse files
authored
More frameworks (#197)
* macos: decouple more minor deps from appkit * generate: fix possible extra : in setter name * generate: explicitly skip class methods on protocols since they dont work yet. added type to kernel * macos: add mps framework (w placeholder structs), plus structs to metal and coregraphics * generate: special case undocumented superclass MPSGraphObject as NSObject * generate: use any/latest minor version for major version of platform * macos: add mpsgraph framework * generate: avoid trying to convert UInt types to NS * generate: normalize strings so you can use package names against symbol module names * generate: use the framework being generated when symbol belongs to multiple including current framework * generate: add SInt8 and UInt8 as mapped to primitive types * macos: add coremidi framework * generate: resolve aliases when checking if enum type is string * macos: add vision framework * macos: fix subclass demo for ventura by calling init on the subclass instance * macos: add fileprovider framework * macos: add corevideo framework * macos: add coremedia framework * macos: add coremediaio framework * macos: add coreaudiotypes framework * macos: add quartz framework * macos: add contactsui framework * generate: make needsallocate for functions simpler and more accurate * macos: add mediaplayer framework * macos: add avfoundation framework * macos: add avkit framework * macos: add missing types and placeholder structs to coremedia and corevideo * macos: add coreaudio framework * macos: move wip frameworks with (mostly) circular dependency issues under _wip * Makefile: add test task * generate: add methods to stats * macos: skip protocol imports for coremediaio and fileprovider for now * generate: fix declparse to parse enums without { } * macos: add sysconfig framework
1 parent 0c305c5 commit 66531b8

File tree

971 files changed

+113540
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

971 files changed

+113540
-39
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ generate:
44
$(GOEXE) generate ./...
55
.PHONY: generate
66

7+
test:
8+
$(GOEXE) test ./...
9+
.PHONY: test
10+
711
clobber:
812
$(GOEXE) run ./generate/tools/clobbergen.go ./macos
913
.PHONY: clobber

generate/class.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func (db *Generator) ToClassGen(sym Symbol) *codegen.Class {
5151
}
5252
}
5353
if st.Interface.SuperName != "" {
54+
// MPSGraphObject not documented, but we should assume its at least similar to NSObject
55+
if st.Interface.SuperName == "MPSGraphObject" {
56+
st.Interface.SuperName = "NSObject"
57+
}
5458
if st.Interface.SuperName == "NSObject" {
5559
classGen.Super = &codegen.Class{
5660
Type: typing.Object,

generate/codegen/aliasinfo.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ type AliasInfo struct {
1515

1616
// IsString return if is a string type Enum
1717
func (e *AliasInfo) IsString() bool {
18-
_, ok := e.Type.(*typing.StringType)
18+
t := e.Type
19+
for {
20+
at, ok := t.(*typing.AliasType)
21+
if !ok {
22+
break
23+
}
24+
t = at.Type
25+
}
26+
_, ok := t.(*typing.StringType)
1927
return ok
2028
}
2129

generate/codegen/gen_method.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func (m *Method) needRelease() bool {
3636
case *typing.PrimitiveType, *typing.StringType:
3737
return false
3838
}
39-
return strings.HasPrefix(m.Name, "new") || !strings.HasPrefix(m.Name, "init") && strings.HasPrefix(m.Name, "Initial") ||
40-
strings.HasPrefix(m.Name, "copy") || strings.HasPrefix(m.Name, "mutableCopy")
39+
//!strings.HasPrefix(m.Name, "init") && strings.HasPrefix(m.Name, "Initial")
40+
return m.Name == "new" || m.Name == "copy" || m.Name == "mutableCopy"
4141
}
4242

4343
// Selector return full Objc function name

generate/codegen/gen_property.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package codegen
22

33
import (
4+
"strings"
5+
46
"github.com/progrium/macdriver/generate/typing"
57
"github.com/progrium/macdriver/internal/stringx"
68
)
@@ -49,11 +51,11 @@ func (p *Property) getter() *Method {
4951
func (p *Property) setter() *Method {
5052
name := "set" + stringx.Capitalize(p.Name)
5153
if p.SetterName != "" {
52-
name = p.SetterName
54+
name = strings.TrimSuffix(p.SetterName, ":")
5355
}
5456
goName := "set" + stringx.Capitalize(p.GoName)
5557
if p.SetterName != "" {
56-
goName = p.SetterName
58+
goName = strings.TrimSuffix(p.SetterName, ":")
5759
}
5860
return &Method{
5961
Name: name,

generate/codegen/gen_protocol.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ func (p *Protocol) writeProtocolInterface(w *CodeWriter) {
140140
}
141141
}
142142
for _, m := range p.allMethods() {
143+
// don't support class methods on protocols yet
144+
if m.ClassMethod {
145+
continue
146+
}
143147
if !m.Required {
144148
w.WriteLine("// optional")
145149
} else {
@@ -176,6 +180,10 @@ func (p *Protocol) writeDelegateStruct(w *CodeWriter) {
176180

177181
receiver := "di"
178182
for _, m := range p.allMethods() {
183+
// don't support class methods on protocols yet
184+
if m.ClassMethod {
185+
continue
186+
}
179187
if !m.Required {
180188
w.WriteLine(fmt.Sprintf("func (%s *%s) Has%s() bool {", receiver, implStructName, m.ProtocolGoFuncName()))
181189
w.WriteLine(fmt.Sprintf("\t return %s._%s != nil", receiver, m.ProtocolGoFuncName()))
@@ -235,6 +243,10 @@ func (p *Protocol) writeProtocolWrapperStruct(w *CodeWriter) {
235243
w.WriteLine("}")
236244

237245
for _, m := range p.allMethods() {
246+
// don't support class methods on protocols yet
247+
if m.ClassMethod {
248+
continue
249+
}
238250
w.WriteLine("")
239251
if !m.Required {
240252
receiver := strings.ToLower(typeName[0:1] + "_")

generate/codegen/modulewriter.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ func (m *ModuleWriter) WriteCode() {
3434
// get "cannot find protocol declaration" with protocol imports
3535
return
3636
}
37+
if m.Module.Package == "coremediaio" {
38+
// get "cannot find protocol declaration" with protocol imports
39+
return
40+
}
41+
if m.Module.Package == "fileprovider" {
42+
// get "cannot find protocol declaration" with protocol imports
43+
return
44+
}
3745
m.WriteProtocolsImportCode()
3846
}
3947

generate/declparse/declparse_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ var tests = []struct {
1515
},
1616
},
1717

18+
{
19+
ParseOnly: true,
20+
s: `typedef enum SCPreferencesNotification : uint32_t SCPreferencesNotification;`,
21+
n: &Statement{
22+
Enum: &EnumDecl{
23+
Name: "SCPreferencesNotification",
24+
Type: TypeInfo{
25+
Name: "uint32_t",
26+
},
27+
},
28+
Typedef: "SCPreferencesNotification",
29+
},
30+
},
31+
1832
{
1933
ParseOnly: true,
2034
// notice eNum is "enum"

generate/declparse/parser_enum.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ func parseEnum(p *Parser) (next stateFn, node Node, err error) {
3030
}
3131

3232
if err := p.expectToken(lexer.LCURLY); err != nil {
33-
return nil, nil, err
33+
p.tb.Unscan()
34+
return nil, decl, nil
3435
}
3536

3637
if err = p.expectToken(lexer.VARARG); err != nil {

generate/generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (db *Generator) ResolveTypeAlias(typeName string) (declparse.TypeInfo, bool
156156

157157
func (db *Generator) TypeFromSymbolName(name string) typing.Type {
158158
// hardcoded for now
159-
if db.Platform == "macos" && strings.HasPrefix(name, "UI") {
159+
if db.Platform == "macos" && strings.HasPrefix(name, "UI") && !strings.HasPrefix(name, "UInt") {
160160
name = "NS" + strings.TrimPrefix(name, "UI")
161161
}
162162
s := db.FindTypeSymbol(name)

0 commit comments

Comments
 (0)