Files
dolt/nomdl/codegen/test/enum_struct.go
Chris Masone 30422eaa33 Fix a few issues with switching from NamedTypes -> Types and re-run go generate
grammar.peg didn't get updated along with grammar.peg.go in arv's last patch,
so that needed to be fixed. Also, pkg.Parsed had its own field named Types, which
shadowed the one it got by embedded types.Package. This only came into play when
generating code for packages pulled out of a dataset. Since arv had to manually
patch up all generated code in his last patch, he never hit this issue and I
missed it in review.

Now, go generate passes once more. Yay
2015-10-14 14:31:06 -07:00

118 lines
2.7 KiB
Go

// This file was generated by nomdl/codegen.
package test
import (
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
var __testPackageInFile_enum_struct_CachedRef = __testPackageInFile_enum_struct_Ref()
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func __testPackageInFile_enum_struct_Ref() ref.Ref {
p := types.PackageDef{
Types: types.ListOfTypeRefDef{
types.MakeEnumTypeRef("Handedness", "right", "left", "switch"),
types.MakeStructTypeRef("EnumStruct",
[]types.Field{
types.Field{"hand", types.MakeTypeRef("Handedness", ref.Ref{}), false},
},
types.Choices{},
),
},
}.New()
return types.RegisterPackage(&p)
}
// Handedness
type Handedness uint32
const (
Right Handedness = iota
Left
Switch
)
// EnumStruct
type EnumStruct struct {
m types.Map
}
func NewEnumStruct() EnumStruct {
return EnumStruct{types.NewMap(
types.NewString("$name"), types.NewString("EnumStruct"),
types.NewString("$type"), types.MakeTypeRef("EnumStruct", __testPackageInFile_enum_struct_CachedRef),
types.NewString("hand"), types.UInt32(0),
)}
}
type EnumStructDef struct {
Hand Handedness
}
func (def EnumStructDef) New() EnumStruct {
return EnumStruct{
types.NewMap(
types.NewString("$name"), types.NewString("EnumStruct"),
types.NewString("$type"), types.MakeTypeRef("EnumStruct", __testPackageInFile_enum_struct_CachedRef),
types.NewString("hand"), types.UInt32(def.Hand),
)}
}
func (s EnumStruct) Def() (d EnumStructDef) {
d.Hand = Handedness(s.m.Get(types.NewString("hand")).(types.UInt32))
return
}
var __typeRefForEnumStruct = types.MakeTypeRef("EnumStruct", __testPackageInFile_enum_struct_CachedRef)
func (m EnumStruct) TypeRef() types.TypeRef {
return __typeRefForEnumStruct
}
func init() {
types.RegisterFromValFunction(__typeRefForEnumStruct, func(v types.Value) types.NomsValue {
return EnumStructFromVal(v)
})
}
func EnumStructFromVal(val types.Value) EnumStruct {
// TODO: Validate here
return EnumStruct{val.(types.Map)}
}
func (s EnumStruct) NomsValue() types.Value {
return s.m
}
func (s EnumStruct) Equals(other types.Value) bool {
if other, ok := other.(EnumStruct); ok {
return s.m.Equals(other.m)
}
return false
}
func (s EnumStruct) Ref() ref.Ref {
return s.m.Ref()
}
func (s EnumStruct) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.m.Chunks()...)
return
}
func (s EnumStruct) Hand() Handedness {
return Handedness(s.m.Get(types.NewString("hand")).(types.UInt32))
}
func (s EnumStruct) SetHand(val Handedness) EnumStruct {
return EnumStruct{s.m.Set(types.NewString("hand"), types.UInt32(val))}
}