Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regenerate against QEMU 7.1.0 #191

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/qmp-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
qapischema "github.com/digitalocean/go-qemu/qapi-schema"
)

const specURL = `https://raw.githubusercontent.com/qemu/qemu/stable-2.11/qapi-schema.json`
const specURL = `https://gitlab.com/qemu-project/qemu/-/raw/v7.1.0/qapi/qapi-schema.json`

var (
inputSpec = flag.String("input", specURL, "Input spec")
Expand Down
14 changes: 7 additions & 7 deletions internal/qmp-gen/templates/alternate
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ supporting flat unions as implementations of an alternate.
//
// Can be one of:
{{- range $suffix, $type := .Options }}
// - {{ $basename }}{{ $suffix.Go }}
// - {{ $basename }}Variant{{ $suffix.Go }}
{{- end }}
type {{ $basename }} interface {
is{{ $basename }}()
}

{{- range $suffix, $type := .Options }}
{{ $subname := printf "%s%s" $basename $suffix.Go }}
{{ $subname := printf "%sVariant%s" $basename $suffix.Go }}

{{- if $type.NullType }}
// {{ $subname }} is a JSON null type, so it must
Expand All @@ -37,7 +37,7 @@ type {{ $basename }} interface {
{{- if eq (typeOf (index API $type)) "flatunion" }}
{{ $u := index API $type }}
{{- range $suffix, $type := $u.Options }}
func ({{ $u.Name.Go }}{{ $suffix.Go }}) is{{ $basename }}() {}
func ({{ $u.Name.Go }}Variant{{ $suffix.Go }}) is{{ $basename }}() {}
{{- end }}
{{- else }}
func ({{ $subname }}) is{{ $basename }}() {}
Expand All @@ -57,14 +57,14 @@ func decode{{ $basename }}(bs json.RawMessage) ({{ $basename }}, error) {
var {{ $suffix }} *int
if err := json.Unmarshal([]byte(bs), &{{ $suffix }}); err == nil {
if {{ $suffix }} == nil {
return {{ printf "%s%s" $basename $suffix.Go }}{}, nil
return {{ printf "%sVariant%s" $basename $suffix.Go }}{}, nil
}
}
{{- end }}
{{- end }}
{{- range $suffix, $type := .Options }}
{{- if $type.SimpleType }}
var {{ $suffix }} {{ printf "%s%s" $basename $suffix.Go }}
var {{ $suffix }} {{ printf "%sVariant%s" $basename $suffix.Go }}
if err := json.Unmarshal([]byte(bs), &{{ $suffix }}); err == nil {
return {{ $suffix }}, nil
}
Expand All @@ -78,13 +78,13 @@ func decode{{ $basename }}(bs json.RawMessage) ({{ $basename }}, error) {
if {{ $suffix }}, err := decode{{ $type.Go }}([]byte(bs)); err == nil {
switch impl := {{ $suffix }}.(type) {
{{- range $suffix, $type := $subtype.Options }}
case {{ $subtype.Name.Go }}{{ $suffix.Go }}:
case {{ $subtype.Name.Go }}Variant{{ $suffix.Go }}:
return impl, nil
{{- end }}
}
}
{{- else }}
var {{ $suffix }} {{ printf "%s%s" $basename $suffix.Go }}
var {{ $suffix }} {{ printf "%sVariant%s" $basename $suffix.Go }}
if err := json.Unmarshal([]byte(bs), &{{ $suffix }}); err == nil {
return {{ $suffix }}, nil
}
Expand Down
7 changes: 4 additions & 3 deletions internal/qmp-gen/templates/flatunion
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
//
// Can be one of:
{{- range $suffix, $type := $u.Options }}
// - {{ $basename }}{{ $suffix.Go }}
// - {{ $basename }}Variant{{ $suffix.Go }}
{{- end }}
type {{ $basename }} interface {
is{{ $basename }}()
}

{{- range $suffix, $type := $u.Options }}
{{ $subname := printf "%s%s" $basename $suffix.Go }}
{{ $subname := printf "%sVariant%s" $basename $suffix.Go }}
{{ $subtype := (index API $type) }}

// {{ $subname }} is an implementation of {{ $basename }}.
Expand Down Expand Up @@ -58,8 +58,9 @@ func decode{{ $basename }}(bs json.RawMessage) ({{ $basename }}, error) {
}
switch v.{{ $discriminatorField.Name.Go }} {
{{- range $suffix, $type := $u.Options }}
{{- $subname := printf "%sVariant%s" $basename $suffix.Go}}
case {{ $discriminatorField.Type.Go }}{{ $suffix.Go }}:
var ret {{ $basename }}{{ $suffix.Go }}
var ret {{ $subname }}
err := json.Unmarshal([]byte(bs), &ret)
return ret, err
{{- end }}
Expand Down
7 changes: 4 additions & 3 deletions internal/qmp-gen/templates/simpleunion
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ redefinition, but still tack on all the marshaling logic.
//
// Can be one of:
{{- range $suffix, $type := .Options }}
// - {{ $basename }}{{ $suffix.Go }}
// - {{ $basename }}Variant{{ $suffix.Go }}
{{- end }}
type {{ $basename }} interface {
is{{ $basename }}()
}

{{- range $suffix, $type := .Options }}
{{ $subname := printf "%s%s" $basename $suffix.Go }}
{{ $subname := printf "%sVariant%s" $basename $suffix.Go }}
{{- if ne $subname $type.Go }}
// {{ $subname }} is an implementation of {{ $basename }}.
type {{ $subname }} {{ $type.Go }}
Expand Down Expand Up @@ -55,8 +55,9 @@ func decode{{ $basename }}(bs json.RawMessage) ({{ $basename }}, error) {
}
switch v.T {
{{- range $suffix, $type := .Options }}
{{- $subname := printf "%sVariant%s" $basename $suffix.Go}}
case "{{ $suffix }}":
var ret {{ $basename }}{{ $suffix.Go }}
var ret {{ $subname }}
if err := json.Unmarshal([]byte(v.V), &ret); err != nil {
return nil, err
}
Expand Down
7 changes: 0 additions & 7 deletions internal/qmp-gen/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,6 @@ func (n name) NullType() bool {
}

func (n name) InterfaceType(api map[name]interface{}) bool {
if n.SimpleType() {
return false
}
switch api[n].(type) {
case simpleUnion, flatUnion, alternate:
return true
}
return false
}

Expand Down
Loading