Skip to content

Commit 676cfff

Browse files
committed
generate: Generate Ref aliases for structs
1 parent e6a27d6 commit 676cfff

File tree

7 files changed

+157
-26
lines changed

7 files changed

+157
-26
lines changed

generate/codegen/modulewriter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (m *ModuleWriter) WriteStructs() {
124124

125125
// if Ref type, allias to unsafe.Pointer
126126
if strings.HasSuffix(s.Name, "Ref") {
127-
cw.WriteLineF("type %s = unsafe.Pointer", s.GoName)
127+
cw.WriteLineF("type %s unsafe.Pointer", s.GoName)
128128
continue
129129
}
130130
}
@@ -168,7 +168,7 @@ func (m *ModuleWriter) WriteFunctions() {
168168
cw.WriteLine(fmt.Sprintf("// %s [Full Topic]", fa.Description))
169169
cw.WriteLine(fmt.Sprintf("//\n// [Full Topic]: %s", fa.DocURL))
170170
}
171-
cw.WriteLineF("func %s(%s) %s {}", fa.Type.GoName(&m.Module, true), fa.GoArgs(&m.Module), fa.GoReturn(&m.Module))
171+
cw.WriteLineF("// func %s(%s) %s {}", fa.Type.GoName(&m.Module, true), fa.GoArgs(&m.Module), fa.GoReturn(&m.Module))
172172
}
173173
}
174174

generate/generator.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ func (db *Generator) Generate(platform string, version int, rootDir string, fram
113113
}
114114
mw.Functions = append(mw.Functions, fn)
115115
case "Struct":
116-
if s.Name != "CGImageRef" {
117-
continue
118-
}
119116
fn := db.ToStruct(framework, s)
120117
if fn == nil {
121118
continue

generate/struct.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import (
44
"log"
55

66
"github.com/progrium/macdriver/generate/codegen"
7+
"github.com/progrium/macdriver/generate/modules"
78
"github.com/progrium/macdriver/generate/typing"
89
)
910

1011
func (db *Generator) ToStruct(fw string, sym Symbol) *codegen.Struct {
11-
// these structs have known declparse failures
1212
knownIssues := map[string]bool{}
1313
if knownIssues[sym.Name] {
1414
_, err := sym.Parse()
@@ -22,7 +22,7 @@ func (db *Generator) ToStruct(fw string, sym Symbol) *codegen.Struct {
2222
}
2323
s := &codegen.Struct{
2424
Name: sym.Name,
25-
GoName: sym.Name,
25+
GoName: modules.TrimPrefix(sym.Name),
2626
Description: sym.Description,
2727
DocURL: sym.DocURL(),
2828
Type: styp,

macos/coregraphics/coregraphics_custom.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

macos/coregraphics/coregraphics_structs.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package coregraphics
33
// #import <CoreGraphics/CGGeometry.h>
44
import "C"
55
import (
6-
"unsafe"
7-
86
"github.com/progrium/macdriver/objc"
97
)
108

@@ -14,8 +12,6 @@ import (
1412
type PathElement struct{}
1513
type ScreenUpdateMoveDelta struct{}
1614

17-
type DisplayStreamUpdateRef unsafe.Pointer
18-
1915
type AffineTransform struct {
2016
A Float
2117
B Float

macos/coregraphics/functions.gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ package coregraphics
55
// Returns an image containing the contents of the specified display. [Full Topic]
66
//
77
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/1455691-cgdisplaycreateimage?language=objc
8-
func DisplayCreateImage(displayID DirectDisplayID) ImageRef {}
8+
// func DisplayCreateImage(displayID DirectDisplayID) ImageRef {}

macos/coregraphics/structs.gen.go

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,158 @@ import (
66
"unsafe"
77
)
88

9+
// A structure that holds a version and two callback functions for drawing a custom pattern. [Full Topic]
10+
//
11+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgpatterncallbacks?language=objc
12+
// A structure that contains pointers to callback functions that manage the copying of data for a data consumer. [Full Topic]
13+
//
14+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgdataconsumercallbacks?language=objc
15+
// A reference to frame update’s metadata. [Full Topic]
16+
//
17+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgdisplaystreamupdateref?language=objc
18+
type DisplayStreamUpdateRef unsafe.Pointer
19+
20+
// A profile that specifies how to interpret a color value for display. [Full Topic]
21+
//
22+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgcolorspaceref?language=objc
23+
type ColorSpaceRef unsafe.Pointer
24+
25+
// An abstraction for data-reading tasks that eliminates the need to manage a raw memory buffer. [Full Topic]
26+
//
27+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgdataproviderref?language=objc
28+
type DataProviderRef unsafe.Pointer
29+
30+
// An opaque data type used to convert PostScript data to PDF data. [Full Topic]
31+
//
32+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgpsconverterref?language=objc
33+
type PSConverterRef unsafe.Pointer
34+
35+
// A document that contains PDF (Portable Document Format) drawing information. [Full Topic]
36+
//
37+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgpdfdocumentref?language=objc
38+
type PDFDocumentRef unsafe.Pointer
39+
40+
// A general facility for defining and using callback functions. [Full Topic]
41+
//
42+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgfunctionref?language=objc
43+
type FunctionRef unsafe.Pointer
44+
45+
// An object that describes how to convert between color spaces for use by other system services. [Full Topic]
46+
//
47+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgcolorconversioninforef?language=objc
48+
type ColorConversionInfoRef unsafe.Pointer
49+
50+
// A structure that contains a point in a two-dimensional coordinate system. [Full Topic]
51+
//
52+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgpoint?language=objc
53+
// A Quartz 2D drawing environment. [Full Topic]
54+
//
55+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgcontextref?language=objc
56+
type ContextRef unsafe.Pointer
57+
58+
// Defines an opaque type that represents a low-level hardware event. [Full Topic]
59+
//
60+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgeventref?language=objc
61+
type EventRef unsafe.Pointer
62+
63+
// A mutable graphics path: a mathematical description of shapes or lines to be drawn in a graphics context. [Full Topic]
64+
//
65+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgmutablepathref?language=objc
66+
type MutablePathRef unsafe.Pointer
67+
68+
// A definition for a smooth transition between colors for drawing radial and axial gradient fills. [Full Topic]
69+
//
70+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cggradientref?language=objc
71+
type GradientRef unsafe.Pointer
72+
73+
// Defines a structure containing pointers to client-defined callback functions that manage the sending of data for a sequential-access data provider. [Full Topic]
74+
//
75+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgdataprovidersequentialcallbacks?language=objc
76+
// A set of character glyphs and layout information for drawing text. [Full Topic]
77+
//
78+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgfontref?language=objc
79+
type FontRef unsafe.Pointer
80+
81+
// A structure that contains width and height values. [Full Topic]
82+
//
83+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgsize?language=objc
84+
// A reference to a display stream object. [Full Topic]
85+
//
86+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgdisplaystreamref?language=objc
87+
type DisplayStreamRef unsafe.Pointer
88+
89+
// A set of components that define a color, with a color space specifying how to interpret them. [Full Topic]
90+
//
91+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgcolorref?language=objc
92+
type ColorRef unsafe.Pointer
93+
94+
// A definition for a smooth transition between colors, controlled by a custom function you provide, for drawing radial and axial gradient fills. [Full Topic]
95+
//
96+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgshadingref?language=objc
97+
type ShadingRef unsafe.Pointer
98+
999
// A bitmap image or image mask. [Full Topic]
10100
//
11101
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgimageref?language=objc
12-
type CGImageRef = unsafe.Pointer
102+
type ImageRef unsafe.Pointer
103+
104+
// An abstraction for data-writing tasks that eliminates the need to manage a raw memory buffer. [Full Topic]
105+
//
106+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgdataconsumerref?language=objc
107+
type DataConsumerRef unsafe.Pointer
108+
109+
// [Full Topic]
110+
//
111+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgcolordataformat?language=objc
112+
// A 2D pattern to be used for drawing graphics paths. [Full Topic]
113+
//
114+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgpatternref?language=objc
115+
type PatternRef unsafe.Pointer
116+
117+
// The distance, in pixel units, that an onscreen region moves. [Full Topic]
118+
//
119+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgscreenupdatemovedelta?language=objc
120+
// Defines pointers to client-defined callback functions that manage the sending of data for a direct-access data provider. [Full Topic]
121+
//
122+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgdataproviderdirectcallbacks?language=objc
123+
// A reference to a display mode object. [Full Topic]
124+
//
125+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgdisplaymoderef?language=objc
126+
type DisplayModeRef unsafe.Pointer
127+
128+
// A type that represents a page in a PDF document. [Full Topic]
129+
//
130+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgpdfpageref?language=objc
131+
type PDFPageRef unsafe.Pointer
132+
133+
// A structure that contains a two-dimensional vector. [Full Topic]
134+
//
135+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgvector?language=objc
136+
// An offscreen context for reusing content drawn with Core Graphics. [Full Topic]
137+
//
138+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cglayerref?language=objc
139+
type LayerRef unsafe.Pointer
140+
141+
// Defines an opaque type that represents the source of a Quartz event. [Full Topic]
142+
//
143+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgeventsourceref?language=objc
144+
type EventSourceRef unsafe.Pointer
145+
146+
// A structure that contains the location and dimensions of a rectangle. [Full Topic]
147+
//
148+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgrect?language=objc
149+
// A structure that contains callbacks needed by a CGFunctionRef object. [Full Topic]
150+
//
151+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgfunctioncallbacks?language=objc
152+
// A data structure that provides information about a path element. [Full Topic]
153+
//
154+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgpathelement?language=objc
155+
// [Full Topic]
156+
//
157+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgdevicecolor?language=objc
158+
// Defines the structure used to report information about event taps. [Full Topic]
159+
//
160+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgeventtapinformation?language=objc
161+
// A structure for holding the callbacks provided when you create a PostScript converter object. [Full Topic]
162+
//
163+
// [Full Topic]: https://developer.apple.com/documentation/coregraphics/cgpsconvertercallbacks?language=objc

0 commit comments

Comments
 (0)