2021-12-02 00:48:25 +03:00
|
|
|
// Code below generated from scalar_gen.go.tmpl
|
|
|
|
package scalar
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-01-14 03:58:42 +03:00
|
|
|
"math/big"
|
2021-12-02 00:48:25 +03:00
|
|
|
|
|
|
|
"github.com/wader/fq/pkg/bitio"
|
|
|
|
)
|
|
|
|
|
|
|
|
{{- range $name, $t := $.types }}
|
|
|
|
// Type {{$name}}
|
|
|
|
|
|
|
|
// Actual{{$name}} asserts actual value is a {{$name}} and returns it
|
|
|
|
func (s S) Actual{{$name}}() {{$t.go_type}} {
|
|
|
|
v, ok := s.Actual.({{$t.go_type}})
|
|
|
|
if !ok {
|
|
|
|
panic(fmt.Sprintf("failed to type assert s.Actual %v as {{$t.go_type}}", s.Actual))
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2022-05-07 13:46:34 +03:00
|
|
|
// Actual{{$name}}Fn map actual {{$name}} using f
|
|
|
|
type Actual{{$name}}Fn func(a {{$t.go_type}}) {{$t.go_type}}
|
|
|
|
|
|
|
|
func (fn Actual{{$name}}Fn) MapScalar(s S) (S, error) {
|
|
|
|
s.Actual = fn(s.Actual{{$name}}())
|
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
|
2021-12-02 00:48:25 +03:00
|
|
|
// Sym{{$name}} asserts symbolic value is a {{$name}} and returns it
|
|
|
|
func (s S) Sym{{$name}}() {{$t.go_type}} {
|
|
|
|
v, ok := s.Sym.({{$t.go_type}})
|
|
|
|
if !ok {
|
|
|
|
panic(fmt.Sprintf("failed to type assert s.Sym %v as {{$t.go_type}}", s.Sym))
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
2022-05-07 13:46:34 +03:00
|
|
|
|
|
|
|
// Sym{{$name}}Fn map sym {{$name}} using f
|
|
|
|
type Sym{{$name}}Fn func(a {{$t.go_type}}) {{$t.go_type}}
|
|
|
|
|
|
|
|
func (f Sym{{$name}}Fn) MapScalar(s S) (S, error) {
|
|
|
|
s.Sym = f(s.Sym{{$name}}())
|
|
|
|
return s, nil
|
|
|
|
}
|
2021-12-02 00:48:25 +03:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{- range $from_name, $from := $.types }}
|
|
|
|
{{- if ne $from.map_from false}}
|
|
|
|
// Map {{$from_name}} -> Scalar
|
|
|
|
type {{$from_name}}ToScalar map[{{$from.go_type}}]S
|
|
|
|
func (m {{$from_name}}ToScalar) MapScalar(s S) (S, error) {
|
|
|
|
a := s.Actual{{$from_name}}()
|
|
|
|
if ns, ok := m[a]; ok {
|
|
|
|
ns.Actual = a
|
|
|
|
s = ns
|
|
|
|
}
|
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
|
2022-05-07 13:46:34 +03:00
|
|
|
// Map {{$from_name}} -> Description
|
2022-04-07 19:25:23 +03:00
|
|
|
type {{$from_name}}ToDescription map[{{$from.go_type}}]string
|
|
|
|
func (m {{$from_name}}ToDescription) MapScalar(s S) (S, error) {
|
|
|
|
a := s.Actual{{$from_name}}()
|
|
|
|
if d, ok := m[a]; ok {
|
|
|
|
s.Description = d
|
|
|
|
}
|
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
|
2021-12-02 00:48:25 +03:00
|
|
|
{{- range $to_name, $to := $.types }}
|
|
|
|
{{- if ne $to.map_to false}}
|
2022-04-07 19:25:23 +03:00
|
|
|
// Map {{$from_name}} -> Sym {{$to_name}}
|
2021-12-02 00:48:25 +03:00
|
|
|
type {{$from_name}}ToSym{{$to_name}} map[{{$from.go_type}}]{{$to.go_type}}
|
|
|
|
func (m {{$from_name}}ToSym{{$to_name}}) MapScalar(s S) (S, error) {
|
|
|
|
if t, ok := m[s.Actual{{$from_name}}()]; ok {
|
|
|
|
s.Sym = t
|
|
|
|
}
|
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
{{- end}}
|
|
|
|
{{- end}}
|
|
|
|
{{- end}}
|
|
|
|
{{- end}}
|
|
|
|
|