NomDL Codegen: Do not create a Def if non comparable

Due to limitations in Go we cannot create a Def for a Map or Set that
has a key that is a Map, Set or a List. This is because the key if a Go
map needs to be a comparable and maps and slices are not comparable.
This commit is contained in:
Erik Arvidsson
2015-09-21 15:34:02 -04:00
parent b037fa9a11
commit 2769353a55
16 changed files with 339 additions and 218 deletions
+52 -16
View File
@@ -133,7 +133,7 @@ func (gen *codeGen) readTemplates() *template.Template {
// in the templates.
func (gen *codeGen) defType(t parse.TypeRef) string {
t = gen.lookup(t)
t = gen.resolve(t)
k := t.Desc.Kind()
switch k {
case parse.BlobKind:
@@ -153,7 +153,7 @@ func (gen *codeGen) defType(t parse.TypeRef) string {
}
func (gen *codeGen) userType(t parse.TypeRef) string {
t = gen.lookup(t)
t = gen.resolve(t)
k := t.Desc.Kind()
switch k {
case parse.BlobKind:
@@ -169,7 +169,7 @@ func (gen *codeGen) userType(t parse.TypeRef) string {
}
func (gen *codeGen) defToValue(val string, t parse.TypeRef) string {
t = gen.lookup(t)
t = gen.resolve(t)
switch t.Desc.Kind() {
case parse.BlobKind, parse.ValueKind:
return val // Blob & Value type has no Def
@@ -186,7 +186,7 @@ func (gen *codeGen) defToValue(val string, t parse.TypeRef) string {
}
func (gen *codeGen) valueToDef(val string, t parse.TypeRef) string {
t = gen.lookup(t)
t = gen.resolve(t)
switch t.Desc.Kind() {
case parse.BlobKind:
return gen.valueToUser(val, t)
@@ -239,7 +239,7 @@ func primitiveKindToString(k parse.NomsKind) string {
}
func (gen *codeGen) nativeToValue(val string, t parse.TypeRef) string {
t = gen.lookup(t)
t = gen.resolve(t)
k := t.Desc.Kind()
switch k {
case parse.BoolKind, parse.Float32Kind, parse.Float64Kind, parse.Int16Kind, parse.Int32Kind, parse.Int64Kind, parse.Int8Kind, parse.UInt16Kind, parse.UInt32Kind, parse.UInt64Kind, parse.UInt8Kind:
@@ -267,7 +267,7 @@ func (gen *codeGen) valueToNative(val string, t parse.TypeRef) string {
}
func (gen *codeGen) userToValue(val string, t parse.TypeRef) string {
t = gen.lookup(t)
t = gen.resolve(t)
k := t.Desc.Kind()
switch k {
case parse.BlobKind, parse.ValueKind:
@@ -281,7 +281,7 @@ func (gen *codeGen) userToValue(val string, t parse.TypeRef) string {
}
func (gen *codeGen) valueToUser(val string, t parse.TypeRef) string {
t = gen.lookup(t)
t = gen.resolve(t)
k := t.Desc.Kind()
switch k {
case parse.BlobKind:
@@ -297,7 +297,7 @@ func (gen *codeGen) valueToUser(val string, t parse.TypeRef) string {
}
func (gen *codeGen) userZero(t parse.TypeRef) string {
t = gen.lookup(t)
t = gen.resolve(t)
k := t.Desc.Kind()
switch k {
case parse.BlobKind:
@@ -322,7 +322,7 @@ func (gen *codeGen) userZero(t parse.TypeRef) string {
}
func (gen *codeGen) valueZero(t parse.TypeRef) string {
t = gen.lookup(t)
t = gen.resolve(t)
k := t.Desc.Kind()
switch k {
case parse.BlobKind:
@@ -353,7 +353,7 @@ func (gen *codeGen) valueZero(t parse.TypeRef) string {
}
func (gen *codeGen) userName(t parse.TypeRef) string {
t = gen.lookup(t)
t = gen.resolve(t)
k := t.Desc.Kind()
switch k {
case parse.BlobKind, parse.BoolKind, parse.Float32Kind, parse.Float64Kind, parse.Int16Kind, parse.Int32Kind, parse.Int64Kind, parse.Int8Kind, parse.StringKind, parse.UInt16Kind, parse.UInt32Kind, parse.UInt64Kind, parse.UInt8Kind, parse.ValueKind:
@@ -387,7 +387,7 @@ func (gen *codeGen) userName(t parse.TypeRef) string {
panic("unreachable")
}
func (gen *codeGen) lookup(t parse.TypeRef) parse.TypeRef {
func (gen *codeGen) resolve(t parse.TypeRef) parse.TypeRef {
if !t.IsUnresolved() {
return t
}
@@ -418,7 +418,7 @@ func (gen *codeGen) WritePackage(packageName string) {
}
func (gen *codeGen) write(t parse.TypeRef) {
t = gen.lookup(t)
t = gen.resolve(t)
if gen.written[gen.userName(t)] {
return
}
@@ -457,12 +457,14 @@ func (gen *codeGen) writeStruct(t parse.TypeRef) {
Choices []parse.Field
HasUnion bool
UnionZeroType parse.TypeRef
CanUseDef bool
}{
gen.userName(t),
desc.Fields,
nil,
desc.Union != nil,
parse.TypeRef{Desc: parse.PrimitiveDesc(parse.UInt32Kind)},
gen.canUseDef(t),
}
if data.HasUnion {
data.Choices = desc.Union.Choices
@@ -482,11 +484,13 @@ func (gen *codeGen) writeStruct(t parse.TypeRef) {
func (gen *codeGen) writeList(t parse.TypeRef) {
elemTypes := t.Desc.(parse.CompoundDesc).ElemTypes
data := struct {
Name string
ElemType parse.TypeRef
Name string
ElemType parse.TypeRef
CanUseDef bool
}{
gen.userName(t),
elemTypes[0],
gen.canUseDef(t),
}
gen.writeTemplate("list.tmpl", t, data)
gen.write(elemTypes[0])
@@ -498,10 +502,12 @@ func (gen *codeGen) writeMap(t parse.TypeRef) {
Name string
KeyType parse.TypeRef
ValueType parse.TypeRef
CanUseDef bool
}{
gen.userName(t),
elemTypes[0],
elemTypes[1],
gen.canUseDef(t),
}
gen.writeTemplate("map.tmpl", t, data)
gen.write(elemTypes[0])
@@ -524,11 +530,13 @@ func (gen *codeGen) writeRef(t parse.TypeRef) {
func (gen *codeGen) writeSet(t parse.TypeRef) {
elemTypes := t.Desc.(parse.CompoundDesc).ElemTypes
data := struct {
Name string
ElemType parse.TypeRef
Name string
ElemType parse.TypeRef
CanUseDef bool
}{
gen.userName(t),
elemTypes[0],
gen.canUseDef(t),
}
gen.writeTemplate("set.tmpl", t, data)
gen.write(elemTypes[0])
@@ -544,3 +552,31 @@ func (gen *codeGen) writeEnum(t parse.TypeRef) {
}
gen.writeTemplate("enum.tmpl", t, data)
}
// We use a go map as the def for Set and Map. These cannot have a key that is a
// Set, Map or a List because slices and maps are not comparable in go.
func (gen *codeGen) canUseDef(t parse.TypeRef) bool {
return gen.canUseDefRec(t, false)
}
func (gen *codeGen) canUseDefRec(t parse.TypeRef, deep bool) bool {
t = gen.resolve(t)
switch t.Desc.Kind() {
case parse.ListKind:
return !deep && gen.canUseDefRec(t.Desc.(parse.CompoundDesc).ElemTypes[0], deep)
case parse.SetKind:
return !deep && gen.canUseDefRec(t.Desc.(parse.CompoundDesc).ElemTypes[0], true)
case parse.MapKind:
elemTypes := t.Desc.(parse.CompoundDesc).ElemTypes
return !deep && gen.canUseDefRec(elemTypes[0], true) && gen.canUseDefRec(elemTypes[1], false)
case parse.StructKind:
for _, f := range t.Desc.(parse.StructDesc).Fields {
if !gen.canUseDefRec(f.T, deep) {
return false
}
}
return true
default:
return true
}
}
+71
View File
@@ -2,9 +2,11 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/golang.org/x/tools/imports"
@@ -46,3 +48,72 @@ func TestGeneratedFiles(t *testing.T) {
assertOutput(n, "test/"+file[:len(file)-5]+".go", t)
}
}
func TestCanUseDef(t *testing.T) {
assert := assert.New(t)
assertCanUseDef := func(s string, using, named bool) {
pkg := parse.ParsePackage("", bytes.NewBufferString(s))
gen := NewCodeGen(nil, pkg)
for _, t := range pkg.UsingDeclarations {
assert.Equal(using, gen.canUseDef(t), s)
}
for _, t := range pkg.NamedTypes {
assert.Equal(named, gen.canUseDef(t), s)
}
}
good := `
using List(Int8)
using Set(Int8)
using Map(Int8, Int8)
using Map(Int8, Set(Int8))
using Map(Int8, Map(Int8, Int8))
struct Simple {
x: Int8
}
using Set(Simple)
using Map(Simple, Int8)
using Map(Simple, Simple)
`
assertCanUseDef(good, true, true)
bad := `
struct WithList {
x: List(Int8)
}
using Set(WithList)
using Map(WithList, Int8)
struct WithSet {
x: Set(Int8)
}
using Set(WithSet)
using Map(WithSet, Int8)
struct WithMap {
x: Map(Int8, Int8)
}
using Set(WithMap)
using Map(WithMap, Int8)
`
assertCanUseDef(bad, false, true)
bad = `
Set(Set(Int8))
Set(Map(Int, Int8))
Set(List(Int8))
Map(Set(Int8), Int8)
Map(Map(Int8, Int8), Int8)
Map(List(Int8), Int8)
`
for _, line := range strings.Split(bad, "\n") {
if strings.TrimSpace(line) == "" {
continue
}
assertCanUseDef(fmt.Sprintf("using %s", line), false, false)
assertCanUseDef(fmt.Sprintf("struct S { x: %s }", line), false, false)
}
}
+18 -15
View File
@@ -4,32 +4,35 @@ type {{.Name}} struct {
l types.List
}
type {{.Name}}Def []{{defType .ElemType}}
func New{{.Name}}() {{.Name}} {
return {{.Name}}{types.NewList()}
}
func (def {{.Name}}Def) New() {{.Name}} {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = {{defToValue "d" .ElemType }}
{{if .CanUseDef}}
type {{.Name}}Def []{{defType .ElemType}}
func (def {{.Name}}Def) New() {{.Name}} {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = {{defToValue "d" .ElemType }}
}
return {{.Name}}{types.NewList(l...)}
}
return {{.Name}}{types.NewList(l...)}
}
func (self {{.Name}}) Def() {{.Name}}Def {
l := make([]{{defType .ElemType}}, self.Len())
for i := uint64(0); i < self.Len(); i++ {
l[i] = {{valueToDef "self.l.Get(i)" .ElemType }}
}
return l
}
{{end}}
func {{.Name}}FromVal(val types.Value) {{.Name}} {
// TODO: Validate here
return {{.Name}}{val.(types.List)}
}
func (self {{.Name}}) Def() {{.Name}}Def {
l := make([]{{defType .ElemType}}, self.Len())
for i := uint64(0); i < self.Len(); i++ {
l[i] = {{valueToDef "self.l.Get(i)" .ElemType }}
}
return l
}
func (self {{.Name}}) NomsValue() types.Value {
return self.l
+19 -16
View File
@@ -4,28 +4,31 @@ type {{.Name}} struct {
m types.Map
}
type {{.Name}}Def map[{{defType .KeyType}}]{{defType .ValueType}}
func New{{.Name}}() {{.Name}} {
return {{.Name}}{types.NewMap()}
}
func (def {{.Name}}Def) New() {{.Name}} {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, {{defToValue "k" .KeyType}}, {{defToValue "v" .ValueType}})
}
return {{.Name}}{types.NewMap(kv...)}
}
{{if .CanUseDef}}
type {{.Name}}Def map[{{defType .KeyType}}]{{defType .ValueType}}
func (self {{.Name}}) Def() {{.Name}}Def {
def := make(map[{{defType .KeyType}}]{{defType .ValueType}})
self.m.Iter(func(k, v types.Value) bool {
def[{{valueToDef "k" .KeyType}}] = {{valueToDef "v" .ValueType}}
return false
})
return def
}
func (def {{.Name}}Def) New() {{.Name}} {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, {{defToValue "k" .KeyType}}, {{defToValue "v" .ValueType}})
}
return {{.Name}}{types.NewMap(kv...)}
}
func (self {{.Name}}) Def() {{.Name}}Def {
def := make(map[{{defType .KeyType}}]{{defType .ValueType}})
self.m.Iter(func(k, v types.Value) bool {
def[{{valueToDef "k" .KeyType}}] = {{valueToDef "v" .ValueType}}
return false
})
return def
}
{{end}}
func {{.Name}}FromVal(p types.Value) {{.Name}} {
// TODO: Validate here
+21 -19
View File
@@ -4,30 +4,32 @@ type {{.Name}} struct {
s types.Set
}
type {{.Name}}Def map[{{defType .ElemType}}]bool
func New{{.Name}}() {{.Name}} {
return {{.Name}}{types.NewSet()}
}
func (def {{.Name}}Def) New() {{.Name}} {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = {{defToValue "d" .ElemType}}
i++
}
return {{.Name}}{types.NewSet(l...)}
}
{{if .CanUseDef}}
type {{.Name}}Def map[{{defType .ElemType}}]bool
func (s {{.Name}}) Def() {{.Name}}Def {
def := make(map[{{defType .ElemType}}]bool, s.Len())
s.s.Iter(func(v types.Value) bool {
def[{{valueToDef "v" .ElemType}}] = true
return false
})
return def
}
func (def {{.Name}}Def) New() {{.Name}} {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = {{defToValue "d" .ElemType}}
i++
}
return {{.Name}}{types.NewSet(l...)}
}
func (s {{.Name}}) Def() {{.Name}}Def {
def := make(map[{{defType .ElemType}}]bool, s.Len())
s.s.Iter(func(v types.Value) bool {
def[{{valueToDef "v" .ElemType}}] = true
return false
})
return def
}
{{end}}
func {{.Name}}FromVal(p types.Value) {{.Name}} {
return {{.Name}}{p.(types.Set)}
+62 -56
View File
@@ -1,11 +1,5 @@
// {{.Name}}
type {{.Name}}Def struct {
{{range .Fields}}{{title .Name}} {{defType .T}}
{{end}}{{if .HasUnion}}__unionIndex uint32
__unionValue interface{}
{{end}}}
type {{.Name}} struct {
m types.Map
}
@@ -19,41 +13,50 @@ func New{{.Name}}() {{.Name}} {
)}
}
func (def {{.Name}}Def) New() {{.Name}} {
return {{.Name}}{
types.NewMap(
types.NewString("$name"), types.NewString("{{.Name}}"),
{{range .Fields}}types.NewString("{{title .Name}}"), {{defToValue (print "def." (title .Name)) .T}},
{{end}}{{if .HasUnion}}types.NewString("$unionIndex"), types.UInt32(def.__unionIndex),
types.NewString("$unionValue"), def.__unionDefToValue(),
{{end}}
)}
}
{{if .CanUseDef}}
type {{.Name}}Def struct {
{{range .Fields}}{{title .Name}} {{defType .T}}
{{end}}{{if .HasUnion}}__unionIndex uint32
__unionValue interface{}
{{end}}}
func (self {{.Name}}) Def() {{.Name}}Def {
return {{.Name}}Def{
{{range .Fields}}{{valueToDef (printf `self.m.Get(types.NewString("%s"))` (title .Name)) .T}},
{{end}}{{if .HasUnion}}uint32(self.m.Get(types.NewString("$unionIndex")).(types.UInt32)),
self.__unionValueToDef(),{{end}}
func (def {{.Name}}Def) New() {{.Name}} {
return {{.Name}}{
types.NewMap(
types.NewString("$name"), types.NewString("{{.Name}}"),
{{range .Fields}}types.NewString("{{title .Name}}"), {{defToValue (print "def." (title .Name)) .T}},
{{end}}{{if .HasUnion}}types.NewString("$unionIndex"), types.UInt32(def.__unionIndex),
types.NewString("$unionValue"), def.__unionDefToValue(),
{{end}}
)}
}
}
{{if .HasUnion}}
func (def {{.Name}}Def) __unionDefToValue() types.Value {
switch def.__unionIndex {
{{range $index, $field := .Choices}}case {{$index}}:
return {{defToValue (printf "def.__unionValue.(%s)" (defType .T)) .T}}
{{end}}}
panic("unreachable")
}
func (self {{.Name}}) Def() {{.Name}}Def {
return {{.Name}}Def{
{{range .Fields}}{{valueToDef (printf `self.m.Get(types.NewString("%s"))` (title .Name)) .T}},
{{end}}{{if .HasUnion}}uint32(self.m.Get(types.NewString("$unionIndex")).(types.UInt32)),
self.__unionValueToDef(),{{end}}
}
}
func (self {{.Name}}) __unionValueToDef() interface{} {
switch uint32(self.m.Get(types.NewString("$unionIndex")).(types.UInt32)) {
{{range $index, $field := .Choices}}case {{$index}}:
return {{valueToDef `self.m.Get(types.NewString("$unionValue"))` .T}}
{{end}}}
panic("unreachable")
}
{{if .HasUnion}}
func (def {{.Name}}Def) __unionDefToValue() types.Value {
switch def.__unionIndex {
{{range $index, $field := .Choices}}case {{$index}}:
return {{defToValue (printf "def.__unionValue.(%s)" (defType .T)) .T}}
{{end}}}
panic("unreachable")
}
func (self {{.Name}}) __unionValueToDef() interface{} {
switch uint32(self.m.Get(types.NewString("$unionIndex")).(types.UInt32)) {
{{range $index, $field := .Choices}}case {{$index}}:
return {{valueToDef `self.m.Get(types.NewString("$unionValue"))` .T}}
{{end}}}
panic("unreachable")
}
{{end}}
{{end}}
func {{.Name}}FromVal(val types.Value) {{.Name}} {
@@ -84,28 +87,31 @@ func (self {{$name}}) Set{{title .Name}}(val {{userType .T}}) {{$name}} {
}
{{end}}
{{$canUseDef := .CanUseDef}}
{{range $index, $field := .Choices}}
func (self {{$name}}) {{title .Name}}() (val {{userType .T}}, ok bool) {
if self.m.Get(types.NewString("$unionIndex")).(types.UInt32) != {{$index}} {
return
func (self {{$name}}) {{title .Name}}() (val {{userType .T}}, ok bool) {
if self.m.Get(types.NewString("$unionIndex")).(types.UInt32) != {{$index}} {
return
}
return {{valueToUser `self.m.Get(types.NewString("$unionValue"))` .T}}, true
}
return {{valueToUser `self.m.Get(types.NewString("$unionValue"))` .T}}, true
}
func (self {{$name}}) Set{{title .Name}}(val {{userType .T}}) {{$name}} {
return {{$name}}{self.m.Set(types.NewString("$unionIndex"), types.UInt32({{$index}})).Set(types.NewString("$unionValue"), {{userToValue "val" .T}})}
}
func (def {{$name}}Def) {{title .Name}}() (val {{defType .T}}, ok bool) {
if def.__unionIndex != {{$index}} {
return
func (self {{$name}}) Set{{title .Name}}(val {{userType .T}}) {{$name}} {
return {{$name}}{self.m.Set(types.NewString("$unionIndex"), types.UInt32({{$index}})).Set(types.NewString("$unionValue"), {{userToValue "val" .T}})}
}
return def.__unionValue.({{defType .T}}), true
}
func (def {{$name}}Def) Set{{title .Name}}(val {{defType .T}}) {{$name}}Def {
def.__unionIndex = {{$index}}
def.__unionValue = val
return def
}
{{if $canUseDef}}
func (def {{$name}}Def) {{title .Name}}() (val {{defType .T}}, ok bool) {
if def.__unionIndex != {{$index}} {
return
}
return def.__unionValue.({{defType .T}}), true
}
func (def {{$name}}Def) Set{{title .Name}}(val {{defType .T}}) {{$name}}Def {
def.__unionIndex = {{$index}}
def.__unionValue = val
return def
}
{{end}}
{{end}}
+4 -4
View File
@@ -9,10 +9,6 @@ import (
// EnumStruct
type EnumStructDef struct {
Hand Handedness
}
type EnumStruct struct {
m types.Map
}
@@ -24,6 +20,10 @@ func NewEnumStruct() EnumStruct {
)}
}
type EnumStructDef struct {
Hand Handedness
}
func (def EnumStructDef) New() EnumStruct {
return EnumStruct{
types.NewMap(
+7 -7
View File
@@ -13,12 +13,12 @@ type ListOfInt64 struct {
l types.List
}
type ListOfInt64Def []int64
func NewListOfInt64() ListOfInt64 {
return ListOfInt64{types.NewList()}
}
type ListOfInt64Def []int64
func (def ListOfInt64Def) New() ListOfInt64 {
l := make([]types.Value, len(def))
for i, d := range def {
@@ -27,11 +27,6 @@ func (def ListOfInt64Def) New() ListOfInt64 {
return ListOfInt64{types.NewList(l...)}
}
func ListOfInt64FromVal(val types.Value) ListOfInt64 {
// TODO: Validate here
return ListOfInt64{val.(types.List)}
}
func (self ListOfInt64) Def() ListOfInt64Def {
l := make([]int64, self.Len())
for i := uint64(0); i < self.Len(); i++ {
@@ -40,6 +35,11 @@ func (self ListOfInt64) Def() ListOfInt64Def {
return l
}
func ListOfInt64FromVal(val types.Value) ListOfInt64 {
// TODO: Validate here
return ListOfInt64{val.(types.List)}
}
func (self ListOfInt64) NomsValue() types.Value {
return self.l
}
+4 -4
View File
@@ -13,12 +13,12 @@ type MapOfBoolToString struct {
m types.Map
}
type MapOfBoolToStringDef map[bool]string
func NewMapOfBoolToString() MapOfBoolToString {
return MapOfBoolToString{types.NewMap()}
}
type MapOfBoolToStringDef map[bool]string
func (def MapOfBoolToStringDef) New() MapOfBoolToString {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
@@ -113,12 +113,12 @@ type MapOfStringToValue struct {
m types.Map
}
type MapOfStringToValueDef map[string]types.Value
func NewMapOfStringToValue() MapOfStringToValue {
return MapOfStringToValue{types.NewMap()}
}
type MapOfStringToValueDef map[string]types.Value
func (def MapOfStringToValueDef) New() MapOfStringToValue {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
+20 -20
View File
@@ -49,12 +49,12 @@ type ListOfString struct {
l types.List
}
type ListOfStringDef []string
func NewListOfString() ListOfString {
return ListOfString{types.NewList()}
}
type ListOfStringDef []string
func (def ListOfStringDef) New() ListOfString {
l := make([]types.Value, len(def))
for i, d := range def {
@@ -63,11 +63,6 @@ func (def ListOfStringDef) New() ListOfString {
return ListOfString{types.NewList(l...)}
}
func ListOfStringFromVal(val types.Value) ListOfString {
// TODO: Validate here
return ListOfString{val.(types.List)}
}
func (self ListOfString) Def() ListOfStringDef {
l := make([]string, self.Len())
for i := uint64(0); i < self.Len(); i++ {
@@ -76,6 +71,11 @@ func (self ListOfString) Def() ListOfStringDef {
return l
}
func ListOfStringFromVal(val types.Value) ListOfString {
// TODO: Validate here
return ListOfString{val.(types.List)}
}
func (self ListOfString) NomsValue() types.Value {
return self.l
}
@@ -166,12 +166,12 @@ type ListOfRefOfFloat32 struct {
l types.List
}
type ListOfRefOfFloat32Def []ref.Ref
func NewListOfRefOfFloat32() ListOfRefOfFloat32 {
return ListOfRefOfFloat32{types.NewList()}
}
type ListOfRefOfFloat32Def []ref.Ref
func (def ListOfRefOfFloat32Def) New() ListOfRefOfFloat32 {
l := make([]types.Value, len(def))
for i, d := range def {
@@ -180,11 +180,6 @@ func (def ListOfRefOfFloat32Def) New() ListOfRefOfFloat32 {
return ListOfRefOfFloat32{types.NewList(l...)}
}
func ListOfRefOfFloat32FromVal(val types.Value) ListOfRefOfFloat32 {
// TODO: Validate here
return ListOfRefOfFloat32{val.(types.List)}
}
func (self ListOfRefOfFloat32) Def() ListOfRefOfFloat32Def {
l := make([]ref.Ref, self.Len())
for i := uint64(0); i < self.Len(); i++ {
@@ -193,6 +188,11 @@ func (self ListOfRefOfFloat32) Def() ListOfRefOfFloat32Def {
return l
}
func ListOfRefOfFloat32FromVal(val types.Value) ListOfRefOfFloat32 {
// TODO: Validate here
return ListOfRefOfFloat32{val.(types.List)}
}
func (self ListOfRefOfFloat32) NomsValue() types.Value {
return self.l
}
@@ -314,10 +314,6 @@ func (r RefOfFloat32) SetValue(val float32, cs chunks.ChunkSink) RefOfFloat32 {
// StructWithRef
type StructWithRefDef struct {
R ref.Ref
}
type StructWithRef struct {
m types.Map
}
@@ -329,6 +325,10 @@ func NewStructWithRef() StructWithRef {
)}
}
type StructWithRefDef struct {
R ref.Ref
}
func (def StructWithRefDef) New() StructWithRef {
return StructWithRef{
types.NewMap(
@@ -409,12 +409,12 @@ type SetOfFloat32 struct {
s types.Set
}
type SetOfFloat32Def map[float32]bool
func NewSetOfFloat32() SetOfFloat32 {
return SetOfFloat32{types.NewSet()}
}
type SetOfFloat32Def map[float32]bool
func (def SetOfFloat32Def) New() SetOfFloat32 {
l := make([]types.Value, len(def))
i := 0
+2 -2
View File
@@ -13,12 +13,12 @@ type SetOfBool struct {
s types.Set
}
type SetOfBoolDef map[bool]bool
func NewSetOfBool() SetOfBool {
return SetOfBool{types.NewSet()}
}
type SetOfBoolDef map[bool]bool
func (def SetOfBoolDef) New() SetOfBool {
l := make([]types.Value, len(def))
i := 0
+5 -5
View File
@@ -9,11 +9,6 @@ import (
// Struct
type StructDef struct {
S string
B bool
}
type Struct struct {
m types.Map
}
@@ -26,6 +21,11 @@ func NewStruct() Struct {
)}
}
type StructDef struct {
S string
B bool
}
func (def StructDef) New() Struct {
return Struct{
types.NewMap(
+17 -17
View File
@@ -9,23 +9,6 @@ import (
// StructPrimitives
type StructPrimitivesDef struct {
Uint64 uint64
Uint32 uint32
Uint16 uint16
Uint8 uint8
Int64 int64
Int32 int32
Int16 int16
Int8 int8
Float64 float64
Float32 float32
Bool bool
String string
Blob types.Blob
Value types.Value
}
type StructPrimitives struct {
m types.Map
}
@@ -50,6 +33,23 @@ func NewStructPrimitives() StructPrimitives {
)}
}
type StructPrimitivesDef struct {
Uint64 uint64
Uint32 uint32
Uint16 uint16
Uint8 uint8
Int64 int64
Int32 int32
Int16 int16
Int8 int8
Float64 float64
Float32 float32
Bool bool
String string
Blob types.Blob
Value types.Value
}
func (def StructPrimitivesDef) New() StructPrimitives {
return StructPrimitives{
types.NewMap(
+14 -14
View File
@@ -9,13 +9,6 @@ import (
// StructWithList
type StructWithListDef struct {
L ListOfUInt8Def
B bool
S string
I int64
}
type StructWithList struct {
m types.Map
}
@@ -30,6 +23,13 @@ func NewStructWithList() StructWithList {
)}
}
type StructWithListDef struct {
L ListOfUInt8Def
B bool
S string
I int64
}
func (def StructWithListDef) New() StructWithList {
return StructWithList{
types.NewMap(
@@ -105,12 +105,12 @@ type ListOfUInt8 struct {
l types.List
}
type ListOfUInt8Def []uint8
func NewListOfUInt8() ListOfUInt8 {
return ListOfUInt8{types.NewList()}
}
type ListOfUInt8Def []uint8
func (def ListOfUInt8Def) New() ListOfUInt8 {
l := make([]types.Value, len(def))
for i, d := range def {
@@ -119,11 +119,6 @@ func (def ListOfUInt8Def) New() ListOfUInt8 {
return ListOfUInt8{types.NewList(l...)}
}
func ListOfUInt8FromVal(val types.Value) ListOfUInt8 {
// TODO: Validate here
return ListOfUInt8{val.(types.List)}
}
func (self ListOfUInt8) Def() ListOfUInt8Def {
l := make([]uint8, self.Len())
for i := uint64(0); i < self.Len(); i++ {
@@ -132,6 +127,11 @@ func (self ListOfUInt8) Def() ListOfUInt8Def {
return l
}
func ListOfUInt8FromVal(val types.Value) ListOfUInt8 {
// TODO: Validate here
return ListOfUInt8{val.(types.List)}
}
func (self ListOfUInt8) NomsValue() types.Value {
return self.l
}
@@ -9,12 +9,6 @@ import (
// StructWithUnionField
type StructWithUnionFieldDef struct {
A float32
__unionIndex uint32
__unionValue interface{}
}
type StructWithUnionField struct {
m types.Map
}
@@ -28,6 +22,12 @@ func NewStructWithUnionField() StructWithUnionField {
)}
}
type StructWithUnionFieldDef struct {
A float32
__unionIndex uint32
__unionValue interface{}
}
func (def StructWithUnionFieldDef) New() StructWithUnionField {
return StructWithUnionField{
types.NewMap(
@@ -229,12 +229,12 @@ type SetOfUInt8 struct {
s types.Set
}
type SetOfUInt8Def map[uint8]bool
func NewSetOfUInt8() SetOfUInt8 {
return SetOfUInt8{types.NewSet()}
}
type SetOfUInt8Def map[uint8]bool
func (def SetOfUInt8Def) New() SetOfUInt8 {
l := make([]types.Value, len(def))
i := 0
+15 -15
View File
@@ -9,11 +9,6 @@ import (
// StructWithUnions
type StructWithUnionsDef struct {
A __unionOfBOfFloat64AndCOfStringDef
D __unionOfEOfFloat64AndFOfStringDef
}
type StructWithUnions struct {
m types.Map
}
@@ -26,6 +21,11 @@ func NewStructWithUnions() StructWithUnions {
)}
}
type StructWithUnionsDef struct {
A __unionOfBOfFloat64AndCOfStringDef
D __unionOfEOfFloat64AndFOfStringDef
}
func (def StructWithUnionsDef) New() StructWithUnions {
return StructWithUnions{
types.NewMap(
@@ -77,11 +77,6 @@ func (self StructWithUnions) SetD(val __unionOfEOfFloat64AndFOfString) StructWit
// __unionOfBOfFloat64AndCOfString
type __unionOfBOfFloat64AndCOfStringDef struct {
__unionIndex uint32
__unionValue interface{}
}
type __unionOfBOfFloat64AndCOfString struct {
m types.Map
}
@@ -94,6 +89,11 @@ func New__unionOfBOfFloat64AndCOfString() __unionOfBOfFloat64AndCOfString {
)}
}
type __unionOfBOfFloat64AndCOfStringDef struct {
__unionIndex uint32
__unionValue interface{}
}
func (def __unionOfBOfFloat64AndCOfStringDef) New() __unionOfBOfFloat64AndCOfString {
return __unionOfBOfFloat64AndCOfString{
types.NewMap(
@@ -197,11 +197,6 @@ func (def __unionOfBOfFloat64AndCOfStringDef) SetC(val string) __unionOfBOfFloat
// __unionOfEOfFloat64AndFOfString
type __unionOfEOfFloat64AndFOfStringDef struct {
__unionIndex uint32
__unionValue interface{}
}
type __unionOfEOfFloat64AndFOfString struct {
m types.Map
}
@@ -214,6 +209,11 @@ func New__unionOfEOfFloat64AndFOfString() __unionOfEOfFloat64AndFOfString {
)}
}
type __unionOfEOfFloat64AndFOfStringDef struct {
__unionIndex uint32
__unionValue interface{}
}
func (def __unionOfEOfFloat64AndFOfStringDef) New() __unionOfEOfFloat64AndFOfString {
return __unionOfEOfFloat64AndFOfString{
types.NewMap(