Skip to content

Commit 3b3fd84

Browse files
object extensions
1 parent fcb3096 commit 3b3fd84

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

gen/cheader.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ typedef WGPUProc (*WGPUProcGetProcAddress)(WGPUDevice device, char const * procN
187187
{{- MComment .Doc 0}}
188188
typedef {{FunctionReturns .}} (*WGPUProc{{$object.Name | PascalCase}}{{.Name | PascalCase}})({{FunctionArgs . $object}}) WGPU_FUNCTION_ATTRIBUTE;
189189
{{- end}}
190-
{{- if not .IsStruct}}
190+
{{- if not (or .IsStruct .Extended)}}
191191
typedef void (*WGPUProc{{.Name | PascalCase}}Reference)(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE;
192192
typedef void (*WGPUProc{{.Name | PascalCase}}Release)(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE;
193193
{{- end}}
@@ -211,7 +211,7 @@ WGPU_EXPORT WGPUProc wgpuGetProcAddress(WGPUDevice device, char const * procName
211211
{{- MComment .Doc 0}}
212212
WGPU_EXPORT {{FunctionReturns .}} wgpu{{$object.Name | PascalCase}}{{.Name | PascalCase}}({{FunctionArgs . $object}}) WGPU_FUNCTION_ATTRIBUTE;
213213
{{- end}}
214-
{{- if not .IsStruct}}
214+
{{- if not (or .IsStruct .Extended)}}
215215
WGPU_EXPORT void wgpu{{.Name | PascalCase}}Reference(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE;
216216
WGPU_EXPORT void wgpu{{.Name | PascalCase}}Release(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE;
217217
{{- end}}

gen/validator.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func mergeAndValidateDuplicates(yamlPaths []string) (errs error) {
8282
}
8383
for _, bf := range data.Bitflags {
8484
if prevBf, ok := bitflags[bf.Name]; ok {
85+
if !bf.Extended {
86+
errs = errors.Join(errs, fmt.Errorf("merge: bitflags.%s in %s is being extended but isn't marked as one", bf.Name, yamlPath))
87+
}
8588
for _, entry := range bf.Entries {
8689
if slices.ContainsFunc(prevBf.Entries, func(e BitflagEntry) bool { return e.Name == entry.Name }) {
8790
errs = errors.Join(errs, fmt.Errorf("merge: bitflags.%s.%s in %s was already found previously while parsing, duplicates are not allowed", bf.Name, entry.Name, yamlPath))
@@ -113,6 +116,9 @@ func mergeAndValidateDuplicates(yamlPaths []string) (errs error) {
113116
}
114117
for _, o := range data.Objects {
115118
if prevObj, ok := objects[o.Name]; ok {
119+
if !o.Extended {
120+
errs = errors.Join(errs, fmt.Errorf("merge: objects.%s in %s is being extended but isn't marked as one", o.Name, yamlPath))
121+
}
116122
for _, method := range o.Methods {
117123
if slices.ContainsFunc(prevObj.Methods, func(f Function) bool { return f.Name == method.Name }) {
118124
errs = errors.Join(errs, fmt.Errorf("merge: objects.%s.%s in %s was already found previously while parsing, duplicates are not allowed", o.Name, method.Name, yamlPath))

gen/yml.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ type EnumEntry struct {
3939
}
4040

4141
type Bitflag struct {
42-
Name string `yaml:"name"`
43-
Doc string `yaml:"doc"`
44-
Entries []BitflagEntry `yaml:"entries"`
42+
Name string `yaml:"name"`
43+
Doc string `yaml:"doc"`
44+
Entries []BitflagEntry `yaml:"entries"`
45+
Extended bool `yaml:"extended"`
4546
}
4647
type BitflagEntry struct {
4748
Name string `yaml:"name"`
@@ -93,9 +94,10 @@ const (
9394
)
9495

9596
type Object struct {
96-
Name string `yaml:"name"`
97-
Doc string `yaml:"doc"`
98-
Methods []Function `yaml:"methods"`
97+
Name string `yaml:"name"`
98+
Doc string `yaml:"doc"`
99+
Methods []Function `yaml:"methods"`
100+
Extended bool `yaml:"extended"`
99101

100102
IsStruct bool `yaml:"-"`
101103
}

schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@
242242
"doc": {
243243
"type": "string"
244244
},
245+
"extended": {
246+
"type": "boolean",
247+
"description": "Optional property, an indicator that this bitflag is an extension of an already present bitflag"
248+
},
245249
"entries": {
246250
"type": "array",
247251
"items": {
@@ -352,6 +356,10 @@
352356
"doc": {
353357
"type": "string"
354358
},
359+
"extended": {
360+
"type": "boolean",
361+
"description": "Optional property, an indicator that this object is an extension of an already present object"
362+
},
355363
"methods": {
356364
"type": "array",
357365
"items": {

0 commit comments

Comments
 (0)