Skip to content

Commit

Permalink
Rewrite generator ext suffix into ext prefix
Browse files Browse the repository at this point in the history
To better align with webgpu-native#212
  • Loading branch information
eliemichel committed Dec 10, 2024
1 parent 11eddf5 commit 8428961
Show file tree
Hide file tree
Showing 5 changed files with 446 additions and 463 deletions.
92 changes: 52 additions & 40 deletions gen/cheader.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
{{- if .Constants}}
{{- range .Constants}}
{{- MComment .Doc 0}}
#define WGPU_{{.Name | ConstantCase}}{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}} ({{.Value | CValue}})
#define WGPU_{{if $.ExtPrefix}}{{$.ExtPrefix | ConstantCase}}_{{end}}{{.Name | ConstantCase}} ({{.Value | CValue}})
{{- end}}
{{ end}}

Expand Down Expand Up @@ -145,7 +145,7 @@ typedef struct WGPUStringView {
{{ end}}
{{- range .Typedefs}}
{{- MComment .Doc 0}}
typedef {{CType .Type "" ""}} WGPU{{.Name | PascalCase}}{{$.ExtSuffix}};
typedef {{CType .Type "" ""}} WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}};
{{ end}}

/** @} */
Expand All @@ -161,7 +161,7 @@ typedef {{CType .Type "" ""}} WGPU{{.Name | PascalCase}}{{$.ExtSuffix}};
{{- range .Objects}}
{{- if not .IsStruct}}
{{- MComment .Doc 0}}
typedef struct WGPU{{.Name | PascalCase}}{{$.ExtSuffix}}Impl* WGPU{{.Name | PascalCase}}{{$.ExtSuffix}} WGPU_OBJECT_ATTRIBUTE;
typedef struct WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}Impl* WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}} WGPU_OBJECT_ATTRIBUTE;
{{- end}}
{{- end}}
{{ end}}
Expand All @@ -171,14 +171,14 @@ typedef struct WGPU{{.Name | PascalCase}}{{$.ExtSuffix}}Impl* WGPU{{.Name | Pasc
{{- if .Structs}}
// Structure forward declarations
{{- range .Structs}}
struct WGPU{{.Name | PascalCase}}{{$.ExtSuffix}};
struct WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}};
{{- end}}
{{ end}}

{{- if .Callbacks}}
// Callback info structure forward declarations
{{- range .Callbacks}}
struct WGPU{{.Name | PascalCase}}CallbackInfo{{$.ExtSuffix}};
struct WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}CallbackInfo;
{{- end}}
{{ end}}

Expand All @@ -193,20 +193,20 @@ struct WGPU{{.Name | PascalCase}}CallbackInfo{{$.ExtSuffix}};
{{- if .Extended}}
{{- range $entryIndex, $_ := .Entries}}
{{- if .}}
_wgpu_EXTEND_ENUM(WGPU{{$enum.Name | PascalCase}}, WGPU{{$enum.Name | PascalCase}}_{{.Name | PascalCase}}{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}}, {{EnumValue $.EnumPrefix $enum $entryIndex}});
_wgpu_EXTEND_ENUM(WGPU{{$enum.Name | PascalCase}}, WGPU{{$enum.Name | PascalCase}}_{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}, {{EnumValue $.EnumPrefix $enum $entryIndex}});
{{- end}}
{{- end}}
{{- else}}
{{- MComment .Doc 0}}
typedef enum WGPU{{.Name | PascalCase}}{{$.ExtSuffix}} {
typedef enum WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}} {
{{- range $entryIndex, $_ := .Entries}}
{{- if .}}
{{- MCommentEnum .Doc 4 $.EnumPrefix $enum $entryIndex }}
WGPU{{$enum.Name | PascalCase}}_{{.Name | PascalCase}}{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}} = {{EnumValue $.EnumPrefix $enum $entryIndex}},
WGPU{{$.ExtPrefix | PascalCase}}{{$enum.Name | PascalCase}}_{{.Name | PascalCase}} = {{EnumValue $.EnumPrefix $enum $entryIndex}},
{{- end}}
{{- end}}
WGPU{{$enum.Name | PascalCase}}_Force32{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}} = 0x7FFFFFFF
} WGPU{{$enum.Name | PascalCase}}{{$.ExtSuffix}} WGPU_ENUM_ATTRIBUTE;
WGPU{{$.ExtPrefix | PascalCase}}{{$enum.Name | PascalCase}}_Force32 = 0x7FFFFFFF
} WGPU{{$.ExtPrefix | PascalCase}}{{$enum.Name | PascalCase}} WGPU_ENUM_ATTRIBUTE;
{{- end}}
{{ end}}

Expand All @@ -221,10 +221,10 @@ typedef enum WGPU{{.Name | PascalCase}}{{$.ExtSuffix}} {

{{- range $bitflag := .Bitflags}}
{{- MComment .Doc 0}}
typedef WGPUFlags WGPU{{.Name | PascalCase}}{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}};
typedef WGPUFlags WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}};
{{- range $entryIndex, $_ := .Entries}}
{{- MCommentBitflag .Doc 4 $bitflag $entryIndex }}
static const WGPU{{$bitflag.Name | PascalCase}} WGPU{{$bitflag.Name | PascalCase}}_{{.Name | PascalCase}}{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}} = {{BitflagValue $bitflag $entryIndex}};
static const WGPU{{$.ExtPrefix | PascalCase}}{{$bitflag.Name | PascalCase}} WGPU{{$.ExtPrefix | PascalCase}}{{$bitflag.Name | PascalCase}}_{{.Name | PascalCase}} = {{BitflagValue $bitflag $entryIndex}};
{{- end}}
{{ end}}

Expand All @@ -243,7 +243,7 @@ typedef void (*WGPUProc)(void) WGPU_FUNCTION_ATTRIBUTE;

{{- range .Callbacks}}
{{- MCommentCallback . 0}}
typedef void (*WGPU{{.Name | PascalCase}}Callback{{$.ExtSuffix}})({{CallbackArgs .}}) WGPU_FUNCTION_ATTRIBUTE;
typedef void (*WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}Callback)({{CallbackArgs .}}) WGPU_FUNCTION_ATTRIBUTE;
{{- end}}

/** @} */
Expand Down Expand Up @@ -285,20 +285,20 @@ typedef struct WGPUChainedStructOut {

{{- range .Callbacks}}
{{- MComment .Doc 0}}
typedef struct WGPU{{.Name | PascalCase}}CallbackInfo{{$.ExtSuffix}} {
typedef struct WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}CallbackInfo {
WGPUChainedStruct const * nextInChain;
{{- if eq .Style "callback_mode" }}
WGPUCallbackMode mode;
{{- end}}
WGPU{{.Name | PascalCase}}Callback{{$.ExtSuffix}} callback;
WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}Callback callback;
WGPU_NULLABLE void* userdata1;
WGPU_NULLABLE void* userdata2;
} WGPU{{.Name | PascalCase}}CallbackInfo{{$.ExtSuffix}} WGPU_STRUCTURE_ATTRIBUTE;
} WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}CallbackInfo WGPU_STRUCTURE_ATTRIBUTE;

/**
* Initializer for @ref WGPU{{.Name | PascalCase}}CallbackInfo{{$.ExtSuffix}}.
* Initializer for @ref WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}CallbackInfo.
*/
#define WGPU_{{.Name | ConstantCase}}_CALLBACK_INFO{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}}_INIT _wgpu_MAKE_INIT_STRUCT(WGPU{{.Name | PascalCase}}CallbackInfo{{$.ExtSuffix}}, { \
#define WGPU_{{if $.ExtPrefix}}{{$.ExtPrefix | ConstantCase}}_{{end}}{{.Name | ConstantCase}}_CALLBACK_INFO_INIT _wgpu_MAKE_INIT_STRUCT(WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}CallbackInfo, { \
/*.nextInChain=*/NULL _wgpu_COMMA \
{{- if eq .Style "callback_mode" }}
/*.mode=*/WGPUCallbackMode_WaitAnyOnly _wgpu_COMMA \
Expand All @@ -314,7 +314,7 @@ typedef struct WGPU{{.Name | PascalCase}}CallbackInfo{{$.ExtSuffix}} {
{{- "\n"}}
{{- range $struct := .Structs}}
{{- MCommentStruct . 0}}
typedef struct WGPU{{.Name | PascalCase}}{{$.ExtSuffix}} {
typedef struct WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}} {
{{- if eq .Type "base_in" }}
WGPUChainedStruct const * nextInChain;
{{- else if eq .Type "base_out" }}
Expand Down Expand Up @@ -343,23 +343,23 @@ typedef struct WGPU{{.Name | PascalCase}}{{$.ExtSuffix}} {
{{ StructMember $struct $memberIndex}}
{{- end}}
{{- end}}
} WGPU{{.Name | PascalCase}}{{$.ExtSuffix}} WGPU_STRUCTURE_ATTRIBUTE;
} WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}} WGPU_STRUCTURE_ATTRIBUTE;

/**
* Initializer for @ref WGPU{{.Name | PascalCase}}{{$.ExtSuffix}}.
* Initializer for @ref WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}.
*/
#define WGPU_{{.Name | ConstantCase}}{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}}_INIT _wgpu_MAKE_INIT_STRUCT(WGPU{{.Name | PascalCase}}{{$.ExtSuffix}}, { \
#define WGPU_{{if $.ExtPrefix}}{{$.ExtPrefix | ConstantCase}}_{{end}}{{.Name | ConstantCase}}_INIT _wgpu_MAKE_INIT_STRUCT(WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}, { \
{{- if eq .Type "base_in" "base_out" "base_in_or_out" }}
/*.nextInChain=*/NULL _wgpu_COMMA \
{{- else if eq .Type "extension_in" }}
/*.chain=*/_wgpu_MAKE_INIT_STRUCT(WGPUChainedStruct, { \
/*.next=*/NULL _wgpu_COMMA \
/*.sType=*/WGPUSType_{{.Name | PascalCase}}{{$.ExtSuffix}} _wgpu_COMMA \
/*.sType=*/WGPUSType_{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}} _wgpu_COMMA \
}) _wgpu_COMMA \
{{- else if eq .Type "extension_out" "extension_in_or_out" }}
/*.chain=*/_wgpu_MAKE_INIT_STRUCT(WGPUChainedStructOut, { \
/*.next=*/NULL _wgpu_COMMA \
/*.sType=*/WGPUSType_{{.Name | PascalCase}}{{$.ExtSuffix}} _wgpu_COMMA \
/*.sType=*/WGPUSType_{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}} _wgpu_COMMA \
}) _wgpu_COMMA \
{{- end }}
{{- range $memberIndex, $_ := .Members}}
Expand All @@ -378,10 +378,10 @@ extern "C" {

{{- range .Functions}}
/**
* Proc pointer type for @ref wgpu{{.Name | PascalCase}}{{$.ExtSuffix}}:
* > @copydoc wgpu{{.Name | PascalCase}}{{$.ExtSuffix}}
* Proc pointer type for @ref wgpu{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}:
* > @copydoc wgpu{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}
*/
typedef {{FunctionReturns .}} (*WGPUProc{{.Name | PascalCase}}{{$.ExtSuffix}})({{FunctionArgs . nil}}) WGPU_FUNCTION_ATTRIBUTE;
typedef {{FunctionReturns .}} (*WGPUProc{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}})({{FunctionArgs . nil}}) WGPU_FUNCTION_ATTRIBUTE;
{{- end}}
{{- if eq .Name "webgpu"}}
/**
Expand All @@ -394,23 +394,31 @@ typedef WGPUProc (*WGPUProcGetProcAddress)(WGPUStringView procName) WGPU_FUNCTIO
{{- range $object := .Objects}}
// Procs of {{$object.Name | PascalCase}}
{{- range $object.Methods}}
{{- if $object.Extended}}
/**
* Proc pointer type for @ref wgpu{{$object.Name | PascalCase}}{{.Name | PascalCase}}{{$.ExtSuffix}}:
* > @copydoc wgpu{{$object.Name | PascalCase}}{{.Name | PascalCase}}{{$.ExtSuffix}}
* Proc pointer type for @ref wgpu{{$object.Name | PascalCase}}{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}:
* > @copydoc wgpu{{$object.Name | PascalCase}}{{.Name | PascalCase}}
*/
typedef {{FunctionReturns .}} (*WGPUProc{{$object.Name | PascalCase}}{{.Name | PascalCase}}{{$.ExtSuffix}})({{FunctionArgs . $object}}) WGPU_FUNCTION_ATTRIBUTE;
typedef {{FunctionReturns .}} (*WGPUProc{{$object.Name | PascalCase}}{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}})({{FunctionArgs . $object}}) WGPU_FUNCTION_ATTRIBUTE;
{{- else}}
/**
* Proc pointer type for @ref wgpu{{$.ExtPrefix | PascalCase}}{{$object.Name | PascalCase}}{{.Name | PascalCase}}:
* > @copydoc wgpu{{$.ExtPrefix | PascalCase}}{{$object.Name | PascalCase}}{{.Name | PascalCase}}
*/
typedef {{FunctionReturns .}} (*WGPUProc{{$.ExtPrefix | PascalCase}}{{$object.Name | PascalCase}}{{.Name | PascalCase}})({{FunctionArgs . $object}}) WGPU_FUNCTION_ATTRIBUTE;
{{- end}}
{{- end}}
{{- if not (or .IsStruct .Extended)}}
/**
* Proc pointer type for @ref wgpu{{$object.Name | PascalCase}}AddRef{{$.ExtSuffix}}.
* > @copydoc wgpu{{$object.Name | PascalCase}}AddRef{{$.ExtSuffix}}
* Proc pointer type for @ref wgpu{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}AddRef.
* > @copydoc wgpu{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}AddRef
*/
typedef void (*WGPUProc{{.Name | PascalCase}}AddRef{{$.ExtSuffix}})(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE;
typedef void (*WGPUProc{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}AddRef)(WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}} {{$.ExtPrefix | PascalCase}}{{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE;
/**
* Proc pointer type for @ref wgpu{{$object.Name | PascalCase}}Release{{$.ExtSuffix}}.
* > @copydoc wgpu{{$object.Name | PascalCase}}Release{{$.ExtSuffix}}
* Proc pointer type for @ref wgpu{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}Release.
* > @copydoc wgpu{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}Release}
*/
typedef void (*WGPUProc{{.Name | PascalCase}}Release{{$.ExtSuffix}})(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE;
typedef void (*WGPUProc{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}Release)(WGPU{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}} {{$.ExtPrefix | PascalCase}}{{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE;
{{- end}}
{{ end}}{{"\n" -}}

Expand All @@ -427,7 +435,7 @@ typedef void (*WGPUProc{{.Name | PascalCase}}Release{{$.ExtSuffix}})(WGPU{{.Name

{{- range .Functions}}
{{- MCommentFunction . 0}}
WGPU_EXPORT {{FunctionReturns .}} wgpu{{.Name | PascalCase}}{{$.ExtSuffix}}({{FunctionArgs . nil}}) WGPU_FUNCTION_ATTRIBUTE;
WGPU_EXPORT {{FunctionReturns .}} wgpu{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}({{FunctionArgs . nil}}) WGPU_FUNCTION_ATTRIBUTE;
{{- end}}
{{- if eq .Name "webgpu"}}
/**
Expand Down Expand Up @@ -456,11 +464,15 @@ WGPU_EXPORT WGPUProc wgpuGetProcAddress(WGPUStringView procName) WGPU_FUNCTION_A
*/
{{- range $object.Methods}}
{{- MCommentFunction . 0}}
WGPU_EXPORT {{FunctionReturns .}} wgpu{{$object.Name | PascalCase}}{{.Name | PascalCase}}{{$.ExtSuffix}}({{FunctionArgs . $object}}) WGPU_FUNCTION_ATTRIBUTE;
{{- if $object.Extended}}
WGPU_EXPORT {{FunctionReturns .}} wgpu{{$object.Name | PascalCase}}{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}({{FunctionArgs . $object}}) WGPU_FUNCTION_ATTRIBUTE;
{{- else}}
WGPU_EXPORT {{FunctionReturns .}} wgpu{{$.ExtPrefix | PascalCase}}{{$object.Name | PascalCase}}{{.Name | PascalCase}}({{FunctionArgs . $object}}) WGPU_FUNCTION_ATTRIBUTE;
{{- end}}
{{- end}}
{{- if not (or .IsStruct .Extended)}}
WGPU_EXPORT void wgpu{{.Name | PascalCase}}AddRef{{$.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;
WGPU_EXPORT void wgpu{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}AddRef(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE;
WGPU_EXPORT void wgpu{{$.ExtPrefix | PascalCase}}{{.Name | PascalCase}}Release(WGPU{{.Name | PascalCase}} {{.Name | CamelCase}}) WGPU_FUNCTION_ATTRIBUTE;
{{- end}}
/** @} */

Expand Down
53 changes: 27 additions & 26 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

type Generator struct {
ExtSuffix string
ExtPrefix string
HeaderName string
*Yml
}
Expand Down Expand Up @@ -294,24 +294,24 @@ func (g *Generator) CType(typ string, pointerType PointerType, suffix string) st
func (g *Generator) FunctionArgs(f Function, o *Object) string {
sb := &strings.Builder{}
if o != nil {
typeSuffix := g.TypeSuffixForNamespace(o.Namespace)
typePrefix := g.TypePrefixForNamespace(o.Namespace)
if len(f.Args) > 0 {
fmt.Fprintf(sb, "WGPU%s%s %s, ", PascalCase(o.Name), typeSuffix, CamelCase(o.Name))
fmt.Fprintf(sb, "WGPU%s %s, ", PascalCase(typePrefix + o.Name), CamelCase(o.Name))
} else {
fmt.Fprintf(sb, "WGPU%s%s %s", PascalCase(o.Name), typeSuffix, CamelCase(o.Name))
fmt.Fprintf(sb, "WGPU%s %s", PascalCase(typePrefix + o.Name), CamelCase(o.Name))
}
}
for i, arg := range f.Args {
if arg.Optional {
sb.WriteString("WGPU_NULLABLE ")
}
typeSuffix := g.TypeSuffixForNamespace(arg.Namespace)
typePrefix := g.TypePrefixForNamespace(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", g.CType(matches[1], arg.Pointer, typeSuffix), CamelCase(arg.Name))
fmt.Fprintf(sb, "%s %s", g.CType(typePrefix + matches[1], arg.Pointer, ""), CamelCase(arg.Name))
} else {
fmt.Fprintf(sb, "%s %s", g.CType(arg.Type, arg.Pointer, typeSuffix), CamelCase(arg.Name))
fmt.Fprintf(sb, "%s %s", g.CType(typePrefix + arg.Type, arg.Pointer, ""), CamelCase(arg.Name))
}
if i != len(f.Args)-1 {
sb.WriteString(", ")
Expand All @@ -329,17 +329,17 @@ func (g *Generator) CallbackArgs(f Callback) string {
if arg.Optional {
sb.WriteString("WGPU_NULLABLE ")
}
typeSuffix := g.TypeSuffixForNamespace(arg.Namespace)
typePrefix := g.TypePrefixForNamespace(arg.Namespace)
var structPrefix string
if strings.HasPrefix(arg.Type, "struct.") {
structPrefix = "struct "
}
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, g.CType(matches[1], arg.Pointer, typeSuffix), CamelCase(arg.Name))
fmt.Fprintf(sb, "%s%s %s, ", structPrefix, g.CType(typePrefix + matches[1], arg.Pointer, ""), CamelCase(arg.Name))
} else {
fmt.Fprintf(sb, "%s%s %s, ", structPrefix, g.CType(arg.Type, arg.Pointer, typeSuffix), CamelCase(arg.Name))
fmt.Fprintf(sb, "%s%s %s, ", structPrefix, g.CType(typePrefix + arg.Type, arg.Pointer, ""), CamelCase(arg.Name))
}
}
sb.WriteString("WGPU_NULLABLE void* userdata1, WGPU_NULLABLE void* userdata2")
Expand Down Expand Up @@ -411,9 +411,10 @@ func (g *Generator) BitflagValue(b Bitflag, entryIndex int) (string, error) {
}
}
// construct comment
entryComment += PascalCase(v)
if g.ExtSuffix != "" {
entryComment += "_" + g.ExtSuffix
if g.ExtPrefix != "" {
entryComment += PascalCase(g.ExtPrefix + "_" + v)
} else {
entryComment += PascalCase(v)
}
if valueIndex != len(entry.ValueCombination)-1 {
entryComment += " | "
Expand All @@ -431,20 +432,20 @@ func (g *Generator) BitflagValue(b Bitflag, entryIndex int) (string, error) {
return entryValue, nil
}

func (g *Generator) TypeSuffixForNamespace(namespace string) string {
func (g *Generator) TypePrefixForNamespace(namespace string) string {
switch namespace {
case "":
return ConstantCase(g.ExtSuffix)
return g.ExtPrefix + "_"
case "webgpu":
return ""
default:
return ConstantCase(namespace)
return namespace + "_"
}
}

func (g *Generator) StructMember(s Struct, memberIndex int) (string, error) {
member := s.Members[memberIndex]
typeSuffix := g.TypeSuffixForNamespace(member.Namespace)
typePrefix := g.TypePrefixForNamespace(member.Namespace)

matches := arrayTypeRegexp.FindStringSubmatch(member.Type)
if len(matches) == 2 {
Expand All @@ -456,9 +457,9 @@ func (g *Generator) StructMember(s Struct, memberIndex int) (string, error) {
sb.WriteString("WGPU_NULLABLE ")
}
if strings.HasPrefix(member.Type, "callback.") {
fmt.Fprintf(sb, "%s %s;", g.CType(member.Type, "", "Info"), CamelCase(member.Name))
fmt.Fprintf(sb, "%s %s;", g.CType(typePrefix + member.Type, "", "Info"), CamelCase(member.Name))
} else {
fmt.Fprintf(sb, "%s %s;", g.CType(member.Type, member.Pointer, typeSuffix), CamelCase(member.Name))
fmt.Fprintf(sb, "%s %s;", g.CType(typePrefix + member.Type, member.Pointer, ""), CamelCase(member.Name))
}
return sb.String(), nil
}
Expand All @@ -476,7 +477,7 @@ func (g *Generator) StructMemberArrayCount(s Struct, memberIndex int) (string, e

func (g *Generator) StructMemberArrayData(s Struct, memberIndex int) (string, error) {
member := s.Members[memberIndex]
typeSuffix := g.TypeSuffixForNamespace(member.Namespace)
typePrefix := g.TypePrefixForNamespace(member.Namespace)

matches := arrayTypeRegexp.FindStringSubmatch(member.Type)
if len(matches) != 2 {
Expand All @@ -487,7 +488,7 @@ func (g *Generator) StructMemberArrayData(s Struct, memberIndex int) (string, er
if member.Optional {
sb.WriteString("WGPU_NULLABLE ")
}
fmt.Fprintf(sb, "%s %s;", g.CType(matches[1], member.Pointer, typeSuffix), CamelCase(member.Name))
fmt.Fprintf(sb, "%s %s;", g.CType(typePrefix + matches[1], member.Pointer, ""), CamelCase(member.Name))
return sb.String(), nil
}

Expand Down Expand Up @@ -596,11 +597,11 @@ func (g *Generator) DefaultValue(member ParameterType, isDocString bool) string
return literal("NULL")
} else {
typ := strings.TrimPrefix(member.Type, "struct.")
return ref("WGPU_" + ConstantCase(typ) + g.ConstantExtSuffix() + "_INIT")
return ref("WGPU_" + g.ConstantExtPrefix() + ConstantCase(typ) + "_INIT")
}
case strings.HasPrefix(member.Type, "callback."):
typ := strings.TrimPrefix(member.Type, "callback.")
return ref("WGPU_" + ConstantCase(typ) + "_CALLBACK_INFO" + g.ConstantExtSuffix() + "_INIT")
return ref("WGPU_" + g.ConstantExtPrefix() + ConstantCase(typ) + "_CALLBACK_INFO" + "_INIT")
case strings.HasPrefix(member.Type, "object."):
return literal("NULL")
case strings.HasPrefix(member.Type, "array<"):
Expand All @@ -614,9 +615,9 @@ func (g *Generator) DefaultValue(member ParameterType, isDocString bool) string
}
}

func (g *Generator) ConstantExtSuffix() string {
if g.ExtSuffix != "" {
return "_" + ConstantCase(g.ExtSuffix)
func (g *Generator) ConstantExtPrefix() string {
if g.ExtPrefix != "" {
return ConstantCase(g.ExtPrefix) + "_"
} else {
return ""
}
Expand Down
Loading

0 comments on commit 8428961

Please sign in to comment.