Skip to content

Commit f67cc42

Browse files
bitflag extensions
1 parent d7100dc commit f67cc42

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

gen/cheader.tmpl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct WGPU{{.Name | PascalCase}};
8484
{{- range $enum := .Enums}}
8585
{{- if .Extended}}
8686
{{- range $entryIndex, $_ := .Entries}}
87-
__WGPU_EXTEND_ENUM(WGPU{{ $enum.Name | PascalCase }}, WGPU{{ $enum.Name | PascalCase}}_{{.Name | PascalCase}}, {{EnumValue $.EnumPrefix $enum $entryIndex}});
87+
__WGPU_EXTEND_ENUM(WGPU{{$enum.Name | PascalCase}}, WGPU{{$enum.Name | PascalCase}}_{{.Name | PascalCase}}, {{EnumValue $.EnumPrefix $enum $entryIndex}});
8888
{{- end}}
8989
{{- else}}
9090
{{- MComment .Doc 0}}
@@ -99,15 +99,21 @@ typedef enum WGPU{{.Name | PascalCase}} {
9999
{{ end}}
100100

101101
{{- range $bitflag := .Bitflags}}
102-
{{- MComment .Doc 0}}
102+
{{- if .Extended}}
103+
{{- range $entryIndex, $_ := .Entries}}
104+
__WGPU_EXTEND_ENUM(WGPU{{$bitflag.Name | PascalCase}}, WGPU{{$bitflag.Name | PascalCase}}_{{.Name | PascalCase}}, {{BitflagValue $bitflag $entryIndex}});
105+
{{- end}}
106+
{{- else}}
107+
{{- MComment .Doc 0}}
103108
typedef enum WGPU{{.Name | PascalCase}} {
104-
{{- range $entryIndex, $_ := .Entries}}
105-
{{- MComment .Doc 4}}
109+
{{- range $entryIndex, $_ := .Entries}}
110+
{{- MComment .Doc 4}}
106111
WGPU{{$bitflag.Name | PascalCase}}_{{.Name | PascalCase}} = {{BitflagValue $bitflag $entryIndex}},
107-
{{- end}}
112+
{{- end}}
108113
WGPU{{$bitflag.Name | PascalCase}}_Force32 = 0x7FFFFFFF
109114
} WGPU{{$bitflag.Name | PascalCase}} WGPU_ENUM_ATTRIBUTE;
110115
typedef WGPUFlags WGPU{{$bitflag.Name | PascalCase}}Flags WGPU_ENUM_ATTRIBUTE;
116+
{{- end}}
111117
{{ end}}
112118

113119
{{- if eq .Name "webgpu"}}

gen/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ func SortAndTransform(yml *Yml) {
9898

9999
// Sort bitflags
100100
slices.SortStableFunc(yml.Bitflags, func(a, b Bitflag) int {
101+
// We want to generate extended bitflag declarations before the normal ones.
102+
if a.Extended && !b.Extended {
103+
return -1
104+
} else if !a.Extended && b.Extended {
105+
return 1
106+
}
101107
return strings.Compare(PascalCase(a.Name), PascalCase(b.Name))
102108
})
103109

gen/validator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ func mergeAndValidateDuplicates(yamlPaths []string) (errs error) {
8989
if slices.ContainsFunc(prevBf.Entries, func(e BitflagEntry) bool { return e.Name == entry.Name }) {
9090
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))
9191
}
92+
if entry.Value == "" && len(entry.ValueCombination) == 0 {
93+
errs = errors.Join(errs, fmt.Errorf("merge: bitflags.%s.%s in %s was extended but doesn't have a value or value_combination, extended bitflag entries must have an explicit value", bf.Name, entry.Name, yamlPath))
94+
}
9295
prevBf.Entries = append(prevBf.Entries, entry)
9396
}
9497
bitflags[bf.Name] = prevBf

0 commit comments

Comments
 (0)