diff --git a/gen/cheader.tmpl b/gen/cheader.tmpl index c844f865..7e67feca 100644 --- a/gen/cheader.tmpl +++ b/gen/cheader.tmpl @@ -57,7 +57,7 @@ {{- if .Constants}} {{- range .Constants}} {{- MComment .Doc 0}} -#define WGPU_{{.Name | ConstantCase}} ({{.Value | CValue}}) +#define WGPU_{{.Name | ConstantCase}}{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}} ({{.Value | CValue}}) {{- end}} {{ end}} @@ -69,7 +69,7 @@ typedef uint32_t WGPUBool; {{- if .Objects}} {{- range .Objects}} {{- if not .IsStruct}} -typedef struct WGPU{{.Name | PascalCase}}Impl* WGPU{{.Name | PascalCase}} WGPU_OBJECT_ATTRIBUTE; +typedef struct WGPU{{.Name | PascalCase}}{{$.ExtSuffix}}Impl* WGPU{{.Name | PascalCase}}{{$.ExtSuffix}} WGPU_OBJECT_ATTRIBUTE; {{- end}} {{- end}} {{ end}} @@ -77,42 +77,42 @@ typedef struct WGPU{{.Name | PascalCase}}Impl* WGPU{{.Name | PascalCase}} WGPU_O {{- if .Structs}} // Structure forward declarations {{- range .Structs}} -struct WGPU{{.Name | PascalCase}}; +struct WGPU{{.Name | PascalCase}}{{$.ExtSuffix}}; {{- end}} {{ end}} {{- range $enum := .Enums}} {{- if .Extended}} {{- range $entryIndex, $_ := .Entries}} -__WGPU_EXTEND_ENUM(WGPU{{$enum.Name | PascalCase}}, WGPU{{$enum.Name | PascalCase}}_{{.Name | PascalCase}}, {{EnumValue $.EnumPrefix $enum $entryIndex}}); +__WGPU_EXTEND_ENUM(WGPU{{$enum.Name | PascalCase}}, WGPU{{$enum.Name | PascalCase}}_{{.Name | PascalCase}}{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}}, {{EnumValue $.EnumPrefix $enum $entryIndex}}); {{- end}} {{- else}} {{- MComment .Doc 0}} -typedef enum WGPU{{.Name | PascalCase}} { +typedef enum WGPU{{.Name | PascalCase}}{{$.ExtSuffix}} { {{- range $entryIndex, $_ := .Entries}} {{- MComment .Doc 4}} - WGPU{{$enum.Name | PascalCase}}_{{.Name | PascalCase}} = {{EnumValue $.EnumPrefix $enum $entryIndex}}, + WGPU{{$enum.Name | PascalCase}}_{{.Name | PascalCase}}{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}} = {{EnumValue $.EnumPrefix $enum $entryIndex}}, {{- end}} - WGPU{{$enum.Name | PascalCase}}_Force32 = 0x7FFFFFFF -} WGPU{{$enum.Name | PascalCase}} WGPU_ENUM_ATTRIBUTE; + WGPU{{$enum.Name | PascalCase}}_Force32{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}} = 0x7FFFFFFF +} WGPU{{$enum.Name | PascalCase}}{{$.ExtSuffix}} WGPU_ENUM_ATTRIBUTE; {{- end}} {{ end}} {{- range $bitflag := .Bitflags}} {{- if .Extended}} {{- range $entryIndex, $_ := .Entries}} -__WGPU_EXTEND_ENUM(WGPU{{$bitflag.Name | PascalCase}}, WGPU{{$bitflag.Name | PascalCase}}_{{.Name | PascalCase}}, {{BitflagValue $bitflag $entryIndex}}); +__WGPU_EXTEND_ENUM(WGPU{{$bitflag.Name | PascalCase}}, WGPU{{$bitflag.Name | PascalCase}}_{{.Name | PascalCase}}{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}}, {{BitflagValue $bitflag $entryIndex}}); {{- end}} {{- else}} {{- MComment .Doc 0}} -typedef enum WGPU{{.Name | PascalCase}} { +typedef enum WGPU{{.Name | PascalCase}}{{$.ExtSuffix}} { {{- range $entryIndex, $_ := .Entries}} {{- MComment .Doc 4}} - WGPU{{$bitflag.Name | PascalCase}}_{{.Name | PascalCase}} = {{BitflagValue $bitflag $entryIndex}}, + WGPU{{$bitflag.Name | PascalCase}}_{{.Name | PascalCase}}{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}} = {{BitflagValue $bitflag $entryIndex}}, {{- end}} - WGPU{{$bitflag.Name | PascalCase}}_Force32 = 0x7FFFFFFF -} WGPU{{$bitflag.Name | PascalCase}} WGPU_ENUM_ATTRIBUTE; -typedef WGPUFlags WGPU{{$bitflag.Name | PascalCase}}Flags WGPU_ENUM_ATTRIBUTE; + WGPU{{$bitflag.Name | PascalCase}}_Force32{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}} = 0x7FFFFFFF +} WGPU{{$bitflag.Name | PascalCase}}{{$.ExtSuffix}} WGPU_ENUM_ATTRIBUTE; +typedef WGPUFlags WGPU{{$bitflag.Name | PascalCase}}Flags{{$.ExtSuffix}} WGPU_ENUM_ATTRIBUTE; {{- end}} {{ end}} @@ -122,7 +122,7 @@ typedef void (*WGPUProc)(void) WGPU_FUNCTION_ATTRIBUTE; {{- range .FunctionTypes}} {{- MComment .Doc 0}} -typedef {{FunctionReturns .}} (*WGPU{{.Name | PascalCase}})({{FunctionArgs . nil}}) WGPU_FUNCTION_ATTRIBUTE; +typedef {{FunctionReturns .}} (*WGPU{{.Name | PascalCase}}{{$.ExtSuffix}})({{FunctionArgs . nil}}) WGPU_FUNCTION_ATTRIBUTE; {{- end}} {{- if .Objects}} @@ -130,7 +130,7 @@ typedef {{FunctionReturns .}} (*WGPU{{.Name | PascalCase}})({{FunctionArgs . nil {{- range $method := .Methods}} {{- if .ReturnsAsync}} {{- MComment .Doc 0}} -typedef void (*WGPU{{$object.Name | PascalCase}}{{$method.Name | PascalCase}}Callback)({{CallbackArgs .}}) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPU{{$object.Name | PascalCase}}{{$method.Name | PascalCase}}Callback{{$.ExtSuffix}})({{CallbackArgs .}}) WGPU_FUNCTION_ATTRIBUTE; {{- end}} {{- end}} {{- end}} @@ -148,9 +148,9 @@ typedef struct WGPUChainedStructOut { } WGPUChainedStructOut WGPU_STRUCTURE_ATTRIBUTE; {{ end}} -{{- range .Structs}} +{{- range $struct := .Structs}} {{- MComment .Doc 0}} -typedef struct WGPU{{.Name | PascalCase}} { +typedef struct WGPU{{.Name | PascalCase}}{{$.ExtSuffix}} { {{- if eq .Type "base_in" }} WGPUChainedStruct const * nextInChain; {{- else if eq .Type "base_out" }} @@ -160,17 +160,10 @@ typedef struct WGPU{{.Name | PascalCase}} { {{- else if eq .Type "extension_out"}} WGPUChainedStructOut chain; {{- end}} -{{- range .Members}} -{{- if IsArray .Type}} - size_t {{.Name | CamelCase | Singularize}}Count; -{{- MComment .Doc 4}} - {{ArrayType .Type .Pointer}} {{.Name | CamelCase}}; -{{- else}} -{{- MComment .Doc 4}} - {{if .Optional}}WGPU_NULLABLE {{end}}{{CType .Type .Pointer}} {{.Name | CamelCase}}; -{{- end}} +{{- range $memberIndex, $_ := .Members}} + {{ StructMember $struct $memberIndex}} {{- end}} -} WGPU{{.Name | PascalCase}} WGPU_STRUCTURE_ATTRIBUTE; +} WGPU{{.Name | PascalCase}}{{$.ExtSuffix}} WGPU_STRUCTURE_ATTRIBUTE; {{ end}}{{"\n" -}} #ifdef __cplusplus @@ -181,7 +174,7 @@ extern "C" { {{- range .Functions}} {{- MComment .Doc 0}} -typedef {{FunctionReturns .}} (*WGPUProc{{.Name | PascalCase}})({{FunctionArgs . nil}}) WGPU_FUNCTION_ATTRIBUTE; +typedef {{FunctionReturns .}} (*WGPUProc{{.Name | PascalCase}}{{$.ExtSuffix}})({{FunctionArgs . nil}}) WGPU_FUNCTION_ATTRIBUTE; {{- end}} {{- if eq .Name "webgpu"}} typedef WGPUProc (*WGPUProcGetProcAddress)(WGPUDevice device, char const * procName) WGPU_FUNCTION_ATTRIBUTE; @@ -191,11 +184,11 @@ typedef WGPUProc (*WGPUProcGetProcAddress)(WGPUDevice device, char const * procN // Procs of {{$object.Name | PascalCase}} {{- range $object.Methods}} {{- MComment .Doc 0}} -typedef {{FunctionReturns .}} (*WGPUProc{{$object.Name | PascalCase}}{{.Name | PascalCase}})({{FunctionArgs . $object}}) WGPU_FUNCTION_ATTRIBUTE; +typedef {{FunctionReturns .}} (*WGPUProc{{$object.Name | PascalCase}}{{.Name | PascalCase}}{{$.ExtSuffix}})({{FunctionArgs . $object}}) WGPU_FUNCTION_ATTRIBUTE; {{- end}} {{- if not (or .IsStruct .Extended)}} -typedef void (*WGPUProc{{.Name | PascalCase}}Reference)(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProc{{.Name | PascalCase}}Release)(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProc{{.Name | PascalCase}}Reference{{$.ExtSuffix}})(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProc{{.Name | PascalCase}}Release{{$.ExtSuffix}})(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE; {{- end}} {{ end}}{{"\n" -}} @@ -205,7 +198,7 @@ typedef void (*WGPUProc{{.Name | PascalCase}}Release)(WGPU{{.Name | PascalCase}} {{- range .Functions}} {{- MComment .Doc 0}} -WGPU_EXPORT {{FunctionReturns .}} wgpu{{.Name | PascalCase}}({{FunctionArgs . nil}}) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT {{FunctionReturns .}} wgpu{{.Name | PascalCase}}{{$.ExtSuffix}}({{FunctionArgs . nil}}) WGPU_FUNCTION_ATTRIBUTE; {{- end}} {{- if eq .Name "webgpu"}} WGPU_EXPORT WGPUProc wgpuGetProcAddress(WGPUDevice device, char const * procName) WGPU_FUNCTION_ATTRIBUTE; @@ -215,11 +208,11 @@ WGPU_EXPORT WGPUProc wgpuGetProcAddress(WGPUDevice device, char const * procName // Methods of {{$object.Name | PascalCase}} {{- range $object.Methods}} {{- MComment .Doc 0}} -WGPU_EXPORT {{FunctionReturns .}} wgpu{{$object.Name | PascalCase}}{{.Name | PascalCase}}({{FunctionArgs . $object}}) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT {{FunctionReturns .}} wgpu{{$object.Name | PascalCase}}{{.Name | PascalCase}}{{$.ExtSuffix}}({{FunctionArgs . $object}}) WGPU_FUNCTION_ATTRIBUTE; {{- end}} {{- if not (or .IsStruct .Extended)}} -WGPU_EXPORT void wgpu{{.Name | PascalCase}}Reference(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpu{{.Name | PascalCase}}Release(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpu{{.Name | PascalCase}}Reference{{$.ExtSuffix}}(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpu{{.Name | PascalCase}}Release{{$.ExtSuffix}}(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE; {{- end}} {{ end}}{{"\n" -}} diff --git a/gen/gen.go b/gen/gen.go index f9c63d26..95f5a6fa 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -11,11 +11,12 @@ import ( ) type Data struct { - Name string + Name string + ExtSuffix string *Yml } -func GenCHeader(data *Data, dst io.Writer) error { +func (d *Data) GenCHeader(dst io.Writer) error { t := template. New(""). Funcs(template.FuncMap{ @@ -26,17 +27,17 @@ func GenCHeader(data *Data, dst io.Writer) error { "ConstantCase": ConstantCase, "PascalCase": PascalCase, "CamelCase": CamelCase, - "CType": CType, - "CValue": CValue, - "EnumValue": EnumValue, - "BitflagValue": BitflagValue, + "CType": d.CType, + "CValue": d.CValue, + "EnumValue": d.EnumValue, + "BitflagValue": d.BitflagValue, "IsArray": func(typ string) bool { return arrayTypeRegexp.Match([]byte(typ)) }, "ArrayType": func(typ string, pointer PointerType) string { matches := arrayTypeRegexp.FindStringSubmatch(typ) if len(matches) == 2 { - return CType(matches[1], pointer) + return d.CType(matches[1], pointer, "") } return "" }, @@ -44,24 +45,25 @@ func GenCHeader(data *Data, dst io.Writer) error { "IsLast": func(i int, s any) bool { return i == reflect.ValueOf(s).Len()-1 }, "FunctionReturns": func(f Function) string { if f.Returns != nil { - return CType(f.Returns.Type, f.Returns.Pointer) + return d.CType(f.Returns.Type, f.Returns.Pointer, "") } return "void" }, - "FunctionArgs": FunctionArgs, - "CallbackArgs": CallbackArgs, + "FunctionArgs": d.FunctionArgs, + "CallbackArgs": d.CallbackArgs, + "StructMember": d.StructMember, }) t, err := t.Parse(tmpl) if err != nil { return fmt.Errorf("GenCHeader: failed to parse template: %w", err) } - if err := t.Execute(dst, data); err != nil { + if err := t.Execute(dst, d); err != nil { return fmt.Errorf("GenCHeader: failed to execute template: %w", err) } return nil } -func CValue(s string) (string, error) { +func (d *Data) CValue(s string) (string, error) { switch s { case "usize_max": return "SIZE_MAX", nil @@ -93,7 +95,7 @@ func CValue(s string) (string, error) { } } -func CType(typ string, pointerType PointerType) string { +func (d *Data) CType(typ string, pointerType PointerType, suffix string) string { appendModifiers := func(s string, pointerType PointerType) string { var sb strings.Builder sb.WriteString(s) @@ -132,44 +134,59 @@ func CType(typ string, pointerType PointerType) string { switch { case strings.HasPrefix(typ, "enum."): - ctype := "WGPU" + PascalCase(strings.TrimPrefix(typ, "enum.")) + ctype := "WGPU" + PascalCase(strings.TrimPrefix(typ, "enum.")) + suffix return appendModifiers(ctype, pointerType) case strings.HasPrefix(typ, "bitflag."): - ctype := "WGPU" + PascalCase(strings.TrimPrefix(typ, "bitflag.")) + "Flags" + ctype := "WGPU" + PascalCase(strings.TrimPrefix(typ, "bitflag.")) + "Flags" + suffix return appendModifiers(ctype, pointerType) case strings.HasPrefix(typ, "struct."): - ctype := "WGPU" + PascalCase(strings.TrimPrefix(typ, "struct.")) + ctype := "WGPU" + PascalCase(strings.TrimPrefix(typ, "struct.")) + suffix return appendModifiers(ctype, pointerType) case strings.HasPrefix(typ, "function_type."): - ctype := "WGPU" + PascalCase(strings.TrimPrefix(typ, "function_type.")) + ctype := "WGPU" + PascalCase(strings.TrimPrefix(typ, "function_type.")) + suffix return appendModifiers(ctype, pointerType) case strings.HasPrefix(typ, "object."): - ctype := "WGPU" + PascalCase(strings.TrimPrefix(typ, "object.")) + ctype := "WGPU" + PascalCase(strings.TrimPrefix(typ, "object.")) + suffix return appendModifiers(ctype, pointerType) default: return "" } } -func FunctionArgs(f Function, o *Object) string { +func (d *Data) FunctionArgs(f Function, o *Object) string { sb := &strings.Builder{} if o != nil { + var typeSuffix string + if o.Namespace == "" { + typeSuffix = ConstantCase(d.ExtSuffix) + } else if o.Namespace != "webgpu" { + typeSuffix = ConstantCase(o.Namespace) + } if len(f.Args) > 0 { - fmt.Fprintf(sb, "WGPU%s %s, ", PascalCase(o.Name), CamelCase(o.Name)) + fmt.Fprintf(sb, "WGPU%s%s %s, ", PascalCase(o.Name), typeSuffix, CamelCase(o.Name)) } else { - fmt.Fprintf(sb, "WGPU%s %s", PascalCase(o.Name), CamelCase(o.Name)) + fmt.Fprintf(sb, "WGPU%s%s %s", PascalCase(o.Name), typeSuffix, CamelCase(o.Name)) } } for i, arg := range f.Args { if arg.Optional { sb.WriteString("WGPU_NULLABLE ") } + if arg.Name == "instance_enumerate_adapters_result" { + fmt.Printf("%+v", arg) + } + var typeSuffix string + if arg.Namespace == "" { + typeSuffix = ConstantCase(d.ExtSuffix) + } else if arg.Namespace != "webgpu" { + typeSuffix = ConstantCase(arg.Namespace) + } matches := arrayTypeRegexp.FindStringSubmatch(arg.Type) if len(matches) == 2 { fmt.Fprintf(sb, "size_t %sCount, ", CamelCase(Singularize(arg.Name))) - fmt.Fprintf(sb, "%s %s", CType(matches[1], arg.Pointer), CamelCase(arg.Name)) + fmt.Fprintf(sb, "%s %s", d.CType(matches[1], arg.Pointer, typeSuffix), CamelCase(arg.Name)) } else { - fmt.Fprintf(sb, "%s %s", CType(arg.Type, arg.Pointer), CamelCase(arg.Name)) + fmt.Fprintf(sb, "%s %s", d.CType(arg.Type, arg.Pointer, typeSuffix), CamelCase(arg.Name)) } if i != len(f.Args)-1 { sb.WriteString(", ") @@ -187,12 +204,18 @@ func FunctionArgs(f Function, o *Object) string { return sb.String() } -func CallbackArgs(f Function) string { +func (d *Data) CallbackArgs(f Function) string { sb := &strings.Builder{} for _, arg := range f.ReturnsAsync { if arg.Optional { sb.WriteString("WGPU_NULLABLE ") } + var typeSuffix string + if arg.Namespace == "" { + typeSuffix = ConstantCase(d.ExtSuffix) + } else if arg.Namespace != "webgpu" { + typeSuffix = ConstantCase(arg.Namespace) + } var structPrefix string if strings.HasPrefix(arg.Type, "struct.") { structPrefix = "struct " @@ -200,16 +223,16 @@ func CallbackArgs(f Function) string { matches := arrayTypeRegexp.FindStringSubmatch(arg.Type) if len(matches) == 2 { fmt.Fprintf(sb, "size_t %sCount, ", CamelCase(Singularize(arg.Name))) - fmt.Fprintf(sb, "%s%s %s, ", structPrefix, CType(matches[1], arg.Pointer), CamelCase(arg.Name)) + fmt.Fprintf(sb, "%s%s %s, ", structPrefix, d.CType(matches[1], arg.Pointer, typeSuffix), CamelCase(arg.Name)) } else { - fmt.Fprintf(sb, "%s%s %s, ", structPrefix, CType(arg.Type, arg.Pointer), CamelCase(arg.Name)) + fmt.Fprintf(sb, "%s%s %s, ", structPrefix, d.CType(arg.Type, arg.Pointer, typeSuffix), CamelCase(arg.Name)) } } sb.WriteString("WGPU_NULLABLE void * userdata") return sb.String() } -func EnumValue(prefix string, e Enum, entryIndex int) (string, error) { +func (d *Data) EnumValue(prefix string, e Enum, entryIndex int) (string, error) { var entryValue uint16 entry := e.Entries[entryIndex] if entry.Value == "" { @@ -233,12 +256,15 @@ func EnumValue(prefix string, e Enum, entryIndex int) (string, error) { return fmt.Sprintf("%s%.4X", prefix, entryValue), nil } -func BitflagValue(b Bitflag, entryIndex int) (string, error) { +func (d *Data) BitflagValue(b Bitflag, entryIndex int) (string, error) { entry := b.Entries[entryIndex] var entryValue string if len(entry.ValueCombination) > 0 { for valueIndex, v := range entry.ValueCombination { entryValue += "WGPU" + PascalCase(b.Name) + "_" + PascalCase(v) + if d.ExtSuffix != "" { + entryValue += "_" + d.ExtSuffix + } if valueIndex != len(entry.ValueCombination)-1 { entryValue += " | " } @@ -266,3 +292,25 @@ func BitflagValue(b Bitflag, entryIndex int) (string, error) { } return entryValue, nil } + +func (d *Data) StructMember(s Struct, memberIndex int) (string, error) { + member := s.Members[memberIndex] + sb := &strings.Builder{} + if member.Optional { + sb.WriteString("WGPU_NULLABLE ") + } + var typeSuffix string + if member.Namespace == "" { + typeSuffix = ConstantCase(d.ExtSuffix) + } else if member.Namespace != "webgpu" { + typeSuffix = ConstantCase(member.Namespace) + } + matches := arrayTypeRegexp.FindStringSubmatch(member.Type) + if len(matches) == 2 { + fmt.Fprintf(sb, "size_t %sCount;\n", CamelCase(Singularize(member.Name))) + fmt.Fprintf(sb, " %s %s;", d.CType(matches[1], member.Pointer, typeSuffix), CamelCase(member.Name)) + } else { + fmt.Fprintf(sb, "%s %s;", d.CType(member.Type, member.Pointer, typeSuffix), CamelCase(member.Name)) + } + return sb.String(), nil +} diff --git a/gen/main.go b/gen/main.go index 543ec74a..f0c72136 100644 --- a/gen/main.go +++ b/gen/main.go @@ -19,12 +19,14 @@ var ( schemaPath string headerPaths StringListFlag yamlPaths StringListFlag + extSuffix bool ) func main() { flag.StringVar(&schemaPath, "schema", "", "path of the json schema") flag.Var(&yamlPaths, "yaml", "path of the yaml spec") flag.Var(&headerPaths, "header", "output path of the header") + flag.BoolVar(&extSuffix, "extsuffix", true, "append suffix to extension identifiers") flag.Parse() if schemaPath == "" || len(headerPaths) == 0 || len(yamlPaths) == 0 || len(headerPaths) != len(yamlPaths) { flag.Usage() @@ -67,10 +69,16 @@ func main() { panic("got invalid file name: " + fileName) } - var data Data - data.Yml = &yml - data.Name = fileNameSplit[0] - if err := GenCHeader(&data, dst); err != nil { + suffix := "" + if fileNameSplit[0] != "webgpu" && extSuffix { + suffix = strings.ToUpper(fileNameSplit[0]) + } + d := &Data{ + Yml: &yml, + Name: fileNameSplit[0], + ExtSuffix: suffix, + } + if err := d.GenCHeader(dst); err != nil { panic(err) } } diff --git a/gen/yml.go b/gen/yml.go index 2ac36146..0e577182 100644 --- a/gen/yml.go +++ b/gen/yml.go @@ -51,41 +51,6 @@ type BitflagEntry struct { ValueCombination []string `yaml:"value_combination"` } -type Function struct { - Name string `yaml:"name"` - Doc string `yaml:"doc"` - ReturnsAsync []FunctionArg `yaml:"returns_async"` - Returns *FunctionReturns `yaml:"returns"` - Args []FunctionArg `yaml:"args"` -} -type FunctionReturns struct { - Doc string `yaml:"doc"` - Type string `yaml:"type"` - Pointer PointerType `yaml:"pointer"` -} -type FunctionArg struct { - Name string `yaml:"name"` - Doc string `yaml:"doc"` - Type string `yaml:"type"` - Pointer PointerType `yaml:"pointer"` - Optional bool `yaml:"optional"` -} - -type Struct struct { - Name string `yaml:"name"` - Type string `yaml:"type"` - Doc string `yaml:"doc"` - FreeMembers bool `yaml:"free_members"` - Members []StructMember `yaml:"members"` -} -type StructMember struct { - Name string `yaml:"name"` - Type string `yaml:"type"` - Pointer PointerType `yaml:"pointer"` - Optional bool `yaml:"optional"` - Doc string `yaml:"doc"` -} - type PointerType string const ( @@ -93,11 +58,37 @@ const ( PointerTypeImmutable PointerType = "immutable" ) +type ParameterType struct { + Name string `yaml:"name"` + Doc string `yaml:"doc"` + Type string `yaml:"type"` + Pointer PointerType `yaml:"pointer"` + Optional bool `yaml:"optional"` + Namespace string `yaml:"namespace"` +} + +type Function struct { + Name string `yaml:"name"` + Doc string `yaml:"doc"` + ReturnsAsync []ParameterType `yaml:"returns_async"` + Returns *ParameterType `yaml:"returns"` + Args []ParameterType `yaml:"args"` +} + +type Struct struct { + Name string `yaml:"name"` + Type string `yaml:"type"` + Doc string `yaml:"doc"` + FreeMembers bool `yaml:"free_members"` + Members []ParameterType `yaml:"members"` +} + type Object struct { - Name string `yaml:"name"` - Doc string `yaml:"doc"` - Methods []Function `yaml:"methods"` - Extended bool `yaml:"extended"` + Name string `yaml:"name"` + Doc string `yaml:"doc"` + Methods []Function `yaml:"methods"` + Extended bool `yaml:"extended"` + Namespace string `yaml:"namespace"` IsStruct bool `yaml:"-"` } diff --git a/schema.json b/schema.json index 3af7526e..cac3d5b5 100644 --- a/schema.json +++ b/schema.json @@ -90,6 +90,11 @@ "optional": { "type": "boolean", "description": "Optional property, to indicate if a parameter is optional" + }, + "namespace": { + "type": "string", + "description": "Optional property, specifying the external namespace where this type is defined", + "pattern": "^[a-z]+$" } }, "required": [ @@ -360,6 +365,11 @@ "type": "boolean", "description": "Optional property, an indicator that this object is an extension of an already present object" }, + "namespace": { + "type": "string", + "description": "Optional property, specifying the external namespace where this object is defined", + "pattern": "^[a-z]+$" + }, "methods": { "type": "array", "items": {