mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-03 19:41:24 -05:00
5ce93dad2e
This patch mostly merges parse.Package and types.Package, though it
can't quite go all the way. A types.Package doesn't have 'using'
declarations, while the parsed representation of a .noms file needs to
have that information. Hence, the parse package is moved to the 'pkg'
package, and pkg.Parsed is introduced. This type embeds types.Package
and adds the necessary additional information.
To make inroads on handling imports, I enhanced ParsePackage() (now
called ParseNomDL()) to actually process the 'alias' and 'import'
statements in the input and go replace namespaced type names in the
package with refs of imported packages. For example, the TypeRef for
'Bar' generated in the following package
alias Foo = import "sha1-ffffffff"
struct Bar {
f: Foo.RockinStruct
}
will actually return types.Ref{sha1-ffffffff} when you call PackageRef()
on it.
In addition, I've added a function to the new 'pkg' package,
which allows the caller to get the dependencies of a type package
from a chunk store.
Fixes issue #353, towards issue #294
382 lines
12 KiB
Go
382 lines
12 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_struct_with_unions_CachedRef = __testPackageInFile_struct_with_unions_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_struct_with_unions_Ref() types.Ref {
|
|
p := types.PackageDef{
|
|
NamedTypes: types.MapOfStringToTypeRefDef{
|
|
|
|
"StructWithUnions": __typeRefOfStructWithUnions(),
|
|
},
|
|
}.New()
|
|
return types.Ref{R: types.RegisterPackage(&p)}
|
|
}
|
|
|
|
// StructWithUnions
|
|
|
|
type StructWithUnions struct {
|
|
m types.Map
|
|
}
|
|
|
|
func NewStructWithUnions() StructWithUnions {
|
|
return StructWithUnions{types.NewMap(
|
|
types.NewString("$name"), types.NewString("StructWithUnions"),
|
|
types.NewString("$type"), types.MakeTypeRef("StructWithUnions", __testPackageInFile_struct_with_unions_CachedRef),
|
|
types.NewString("a"), New__unionOfBOfFloat64AndCOfString().NomsValue(),
|
|
types.NewString("d"), New__unionOfEOfFloat64AndFOfString().NomsValue(),
|
|
)}
|
|
}
|
|
|
|
type StructWithUnionsDef struct {
|
|
A __unionOfBOfFloat64AndCOfStringDef
|
|
D __unionOfEOfFloat64AndFOfStringDef
|
|
}
|
|
|
|
func (def StructWithUnionsDef) New() StructWithUnions {
|
|
return StructWithUnions{
|
|
types.NewMap(
|
|
types.NewString("$name"), types.NewString("StructWithUnions"),
|
|
types.NewString("$type"), types.MakeTypeRef("StructWithUnions", __testPackageInFile_struct_with_unions_CachedRef),
|
|
types.NewString("a"), def.A.New().NomsValue(),
|
|
types.NewString("d"), def.D.New().NomsValue(),
|
|
)}
|
|
}
|
|
|
|
func (s StructWithUnions) Def() (d StructWithUnionsDef) {
|
|
d.A = __unionOfBOfFloat64AndCOfStringFromVal(s.m.Get(types.NewString("a"))).Def()
|
|
d.D = __unionOfEOfFloat64AndFOfStringFromVal(s.m.Get(types.NewString("d"))).Def()
|
|
return
|
|
}
|
|
|
|
// Creates and returns a Noms Value that describes StructWithUnions.
|
|
func __typeRefOfStructWithUnions() types.TypeRef {
|
|
return types.MakeStructTypeRef("StructWithUnions",
|
|
[]types.Field{
|
|
types.Field{"a", types.MakeStructTypeRef("", []types.Field{}, types.Choices{types.Field{"b", types.MakePrimitiveTypeRef(types.Float64Kind), false},
|
|
types.Field{"c", types.MakePrimitiveTypeRef(types.StringKind), false}}), false},
|
|
types.Field{"d", types.MakeStructTypeRef("", []types.Field{}, types.Choices{types.Field{"e", types.MakePrimitiveTypeRef(types.Float64Kind), false},
|
|
types.Field{"f", types.MakePrimitiveTypeRef(types.StringKind), false}}), false},
|
|
},
|
|
types.Choices{},
|
|
)
|
|
}
|
|
|
|
func StructWithUnionsFromVal(val types.Value) StructWithUnions {
|
|
// TODO: Validate here
|
|
return StructWithUnions{val.(types.Map)}
|
|
}
|
|
|
|
func (s StructWithUnions) NomsValue() types.Value {
|
|
return s.m
|
|
}
|
|
|
|
func (s StructWithUnions) Equals(other StructWithUnions) bool {
|
|
return s.m.Equals(other.m)
|
|
}
|
|
|
|
func (s StructWithUnions) Ref() ref.Ref {
|
|
return s.m.Ref()
|
|
}
|
|
|
|
func (s StructWithUnions) Type() types.TypeRef {
|
|
return s.m.Get(types.NewString("$type")).(types.TypeRef)
|
|
}
|
|
|
|
func (s StructWithUnions) A() __unionOfBOfFloat64AndCOfString {
|
|
return __unionOfBOfFloat64AndCOfStringFromVal(s.m.Get(types.NewString("a")))
|
|
}
|
|
|
|
func (s StructWithUnions) SetA(val __unionOfBOfFloat64AndCOfString) StructWithUnions {
|
|
return StructWithUnions{s.m.Set(types.NewString("a"), val.NomsValue())}
|
|
}
|
|
|
|
func (s StructWithUnions) D() __unionOfEOfFloat64AndFOfString {
|
|
return __unionOfEOfFloat64AndFOfStringFromVal(s.m.Get(types.NewString("d")))
|
|
}
|
|
|
|
func (s StructWithUnions) SetD(val __unionOfEOfFloat64AndFOfString) StructWithUnions {
|
|
return StructWithUnions{s.m.Set(types.NewString("d"), val.NomsValue())}
|
|
}
|
|
|
|
// __unionOfBOfFloat64AndCOfString
|
|
|
|
type __unionOfBOfFloat64AndCOfString struct {
|
|
m types.Map
|
|
}
|
|
|
|
func New__unionOfBOfFloat64AndCOfString() __unionOfBOfFloat64AndCOfString {
|
|
return __unionOfBOfFloat64AndCOfString{types.NewMap(
|
|
types.NewString("$name"), types.NewString("__unionOfBOfFloat64AndCOfString"),
|
|
types.NewString("$type"), types.MakeTypeRef("__unionOfBOfFloat64AndCOfString", __testPackageInFile_struct_with_unions_CachedRef),
|
|
types.NewString("$unionIndex"), types.UInt32(0),
|
|
types.NewString("$unionValue"), types.Float64(0),
|
|
)}
|
|
}
|
|
|
|
type __unionOfBOfFloat64AndCOfStringDef struct {
|
|
__unionIndex uint32
|
|
__unionValue interface{}
|
|
}
|
|
|
|
func (def __unionOfBOfFloat64AndCOfStringDef) New() __unionOfBOfFloat64AndCOfString {
|
|
return __unionOfBOfFloat64AndCOfString{
|
|
types.NewMap(
|
|
types.NewString("$name"), types.NewString("__unionOfBOfFloat64AndCOfString"),
|
|
types.NewString("$type"), types.MakeTypeRef("__unionOfBOfFloat64AndCOfString", __testPackageInFile_struct_with_unions_CachedRef),
|
|
types.NewString("$unionIndex"), types.UInt32(def.__unionIndex),
|
|
types.NewString("$unionValue"), def.__unionDefToValue(),
|
|
)}
|
|
}
|
|
|
|
func (s __unionOfBOfFloat64AndCOfString) Def() (d __unionOfBOfFloat64AndCOfStringDef) {
|
|
d.__unionIndex = uint32(s.m.Get(types.NewString("$unionIndex")).(types.UInt32))
|
|
d.__unionValue = s.__unionValueToDef()
|
|
return
|
|
}
|
|
|
|
func (def __unionOfBOfFloat64AndCOfStringDef) __unionDefToValue() types.Value {
|
|
switch def.__unionIndex {
|
|
case 0:
|
|
return types.Float64(def.__unionValue.(float64))
|
|
case 1:
|
|
return types.NewString(def.__unionValue.(string))
|
|
}
|
|
panic("unreachable")
|
|
}
|
|
|
|
func (s __unionOfBOfFloat64AndCOfString) __unionValueToDef() interface{} {
|
|
switch uint32(s.m.Get(types.NewString("$unionIndex")).(types.UInt32)) {
|
|
case 0:
|
|
return float64(s.m.Get(types.NewString("$unionValue")).(types.Float64))
|
|
case 1:
|
|
return s.m.Get(types.NewString("$unionValue")).(types.String).String()
|
|
}
|
|
panic("unreachable")
|
|
}
|
|
|
|
// Creates and returns a Noms Value that describes __unionOfBOfFloat64AndCOfString.
|
|
func __typeRefOf__unionOfBOfFloat64AndCOfString() types.TypeRef {
|
|
return types.MakeStructTypeRef("__unionOfBOfFloat64AndCOfString",
|
|
[]types.Field{},
|
|
types.Choices{
|
|
types.Field{"b", types.MakePrimitiveTypeRef(types.Float64Kind), false},
|
|
types.Field{"c", types.MakePrimitiveTypeRef(types.StringKind), false},
|
|
},
|
|
)
|
|
}
|
|
|
|
func __unionOfBOfFloat64AndCOfStringFromVal(val types.Value) __unionOfBOfFloat64AndCOfString {
|
|
// TODO: Validate here
|
|
return __unionOfBOfFloat64AndCOfString{val.(types.Map)}
|
|
}
|
|
|
|
func (s __unionOfBOfFloat64AndCOfString) NomsValue() types.Value {
|
|
return s.m
|
|
}
|
|
|
|
func (s __unionOfBOfFloat64AndCOfString) Equals(other __unionOfBOfFloat64AndCOfString) bool {
|
|
return s.m.Equals(other.m)
|
|
}
|
|
|
|
func (s __unionOfBOfFloat64AndCOfString) Ref() ref.Ref {
|
|
return s.m.Ref()
|
|
}
|
|
|
|
func (s __unionOfBOfFloat64AndCOfString) Type() types.TypeRef {
|
|
return s.m.Get(types.NewString("$type")).(types.TypeRef)
|
|
}
|
|
|
|
func (s __unionOfBOfFloat64AndCOfString) B() (val float64, ok bool) {
|
|
if s.m.Get(types.NewString("$unionIndex")).(types.UInt32) != 0 {
|
|
return
|
|
}
|
|
return float64(s.m.Get(types.NewString("$unionValue")).(types.Float64)), true
|
|
}
|
|
|
|
func (s __unionOfBOfFloat64AndCOfString) SetB(val float64) __unionOfBOfFloat64AndCOfString {
|
|
return __unionOfBOfFloat64AndCOfString{s.m.Set(types.NewString("$unionIndex"), types.UInt32(0)).Set(types.NewString("$unionValue"), types.Float64(val))}
|
|
}
|
|
|
|
func (def __unionOfBOfFloat64AndCOfStringDef) B() (val float64, ok bool) {
|
|
if def.__unionIndex != 0 {
|
|
return
|
|
}
|
|
return def.__unionValue.(float64), true
|
|
}
|
|
|
|
func (def __unionOfBOfFloat64AndCOfStringDef) SetB(val float64) __unionOfBOfFloat64AndCOfStringDef {
|
|
def.__unionIndex = 0
|
|
def.__unionValue = val
|
|
return def
|
|
}
|
|
|
|
func (s __unionOfBOfFloat64AndCOfString) C() (val string, ok bool) {
|
|
if s.m.Get(types.NewString("$unionIndex")).(types.UInt32) != 1 {
|
|
return
|
|
}
|
|
return s.m.Get(types.NewString("$unionValue")).(types.String).String(), true
|
|
}
|
|
|
|
func (s __unionOfBOfFloat64AndCOfString) SetC(val string) __unionOfBOfFloat64AndCOfString {
|
|
return __unionOfBOfFloat64AndCOfString{s.m.Set(types.NewString("$unionIndex"), types.UInt32(1)).Set(types.NewString("$unionValue"), types.NewString(val))}
|
|
}
|
|
|
|
func (def __unionOfBOfFloat64AndCOfStringDef) C() (val string, ok bool) {
|
|
if def.__unionIndex != 1 {
|
|
return
|
|
}
|
|
return def.__unionValue.(string), true
|
|
}
|
|
|
|
func (def __unionOfBOfFloat64AndCOfStringDef) SetC(val string) __unionOfBOfFloat64AndCOfStringDef {
|
|
def.__unionIndex = 1
|
|
def.__unionValue = val
|
|
return def
|
|
}
|
|
|
|
// __unionOfEOfFloat64AndFOfString
|
|
|
|
type __unionOfEOfFloat64AndFOfString struct {
|
|
m types.Map
|
|
}
|
|
|
|
func New__unionOfEOfFloat64AndFOfString() __unionOfEOfFloat64AndFOfString {
|
|
return __unionOfEOfFloat64AndFOfString{types.NewMap(
|
|
types.NewString("$name"), types.NewString("__unionOfEOfFloat64AndFOfString"),
|
|
types.NewString("$type"), types.MakeTypeRef("__unionOfEOfFloat64AndFOfString", __testPackageInFile_struct_with_unions_CachedRef),
|
|
types.NewString("$unionIndex"), types.UInt32(0),
|
|
types.NewString("$unionValue"), types.Float64(0),
|
|
)}
|
|
}
|
|
|
|
type __unionOfEOfFloat64AndFOfStringDef struct {
|
|
__unionIndex uint32
|
|
__unionValue interface{}
|
|
}
|
|
|
|
func (def __unionOfEOfFloat64AndFOfStringDef) New() __unionOfEOfFloat64AndFOfString {
|
|
return __unionOfEOfFloat64AndFOfString{
|
|
types.NewMap(
|
|
types.NewString("$name"), types.NewString("__unionOfEOfFloat64AndFOfString"),
|
|
types.NewString("$type"), types.MakeTypeRef("__unionOfEOfFloat64AndFOfString", __testPackageInFile_struct_with_unions_CachedRef),
|
|
types.NewString("$unionIndex"), types.UInt32(def.__unionIndex),
|
|
types.NewString("$unionValue"), def.__unionDefToValue(),
|
|
)}
|
|
}
|
|
|
|
func (s __unionOfEOfFloat64AndFOfString) Def() (d __unionOfEOfFloat64AndFOfStringDef) {
|
|
d.__unionIndex = uint32(s.m.Get(types.NewString("$unionIndex")).(types.UInt32))
|
|
d.__unionValue = s.__unionValueToDef()
|
|
return
|
|
}
|
|
|
|
func (def __unionOfEOfFloat64AndFOfStringDef) __unionDefToValue() types.Value {
|
|
switch def.__unionIndex {
|
|
case 0:
|
|
return types.Float64(def.__unionValue.(float64))
|
|
case 1:
|
|
return types.NewString(def.__unionValue.(string))
|
|
}
|
|
panic("unreachable")
|
|
}
|
|
|
|
func (s __unionOfEOfFloat64AndFOfString) __unionValueToDef() interface{} {
|
|
switch uint32(s.m.Get(types.NewString("$unionIndex")).(types.UInt32)) {
|
|
case 0:
|
|
return float64(s.m.Get(types.NewString("$unionValue")).(types.Float64))
|
|
case 1:
|
|
return s.m.Get(types.NewString("$unionValue")).(types.String).String()
|
|
}
|
|
panic("unreachable")
|
|
}
|
|
|
|
// Creates and returns a Noms Value that describes __unionOfEOfFloat64AndFOfString.
|
|
func __typeRefOf__unionOfEOfFloat64AndFOfString() types.TypeRef {
|
|
return types.MakeStructTypeRef("__unionOfEOfFloat64AndFOfString",
|
|
[]types.Field{},
|
|
types.Choices{
|
|
types.Field{"e", types.MakePrimitiveTypeRef(types.Float64Kind), false},
|
|
types.Field{"f", types.MakePrimitiveTypeRef(types.StringKind), false},
|
|
},
|
|
)
|
|
}
|
|
|
|
func __unionOfEOfFloat64AndFOfStringFromVal(val types.Value) __unionOfEOfFloat64AndFOfString {
|
|
// TODO: Validate here
|
|
return __unionOfEOfFloat64AndFOfString{val.(types.Map)}
|
|
}
|
|
|
|
func (s __unionOfEOfFloat64AndFOfString) NomsValue() types.Value {
|
|
return s.m
|
|
}
|
|
|
|
func (s __unionOfEOfFloat64AndFOfString) Equals(other __unionOfEOfFloat64AndFOfString) bool {
|
|
return s.m.Equals(other.m)
|
|
}
|
|
|
|
func (s __unionOfEOfFloat64AndFOfString) Ref() ref.Ref {
|
|
return s.m.Ref()
|
|
}
|
|
|
|
func (s __unionOfEOfFloat64AndFOfString) Type() types.TypeRef {
|
|
return s.m.Get(types.NewString("$type")).(types.TypeRef)
|
|
}
|
|
|
|
func (s __unionOfEOfFloat64AndFOfString) E() (val float64, ok bool) {
|
|
if s.m.Get(types.NewString("$unionIndex")).(types.UInt32) != 0 {
|
|
return
|
|
}
|
|
return float64(s.m.Get(types.NewString("$unionValue")).(types.Float64)), true
|
|
}
|
|
|
|
func (s __unionOfEOfFloat64AndFOfString) SetE(val float64) __unionOfEOfFloat64AndFOfString {
|
|
return __unionOfEOfFloat64AndFOfString{s.m.Set(types.NewString("$unionIndex"), types.UInt32(0)).Set(types.NewString("$unionValue"), types.Float64(val))}
|
|
}
|
|
|
|
func (def __unionOfEOfFloat64AndFOfStringDef) E() (val float64, ok bool) {
|
|
if def.__unionIndex != 0 {
|
|
return
|
|
}
|
|
return def.__unionValue.(float64), true
|
|
}
|
|
|
|
func (def __unionOfEOfFloat64AndFOfStringDef) SetE(val float64) __unionOfEOfFloat64AndFOfStringDef {
|
|
def.__unionIndex = 0
|
|
def.__unionValue = val
|
|
return def
|
|
}
|
|
|
|
func (s __unionOfEOfFloat64AndFOfString) F() (val string, ok bool) {
|
|
if s.m.Get(types.NewString("$unionIndex")).(types.UInt32) != 1 {
|
|
return
|
|
}
|
|
return s.m.Get(types.NewString("$unionValue")).(types.String).String(), true
|
|
}
|
|
|
|
func (s __unionOfEOfFloat64AndFOfString) SetF(val string) __unionOfEOfFloat64AndFOfString {
|
|
return __unionOfEOfFloat64AndFOfString{s.m.Set(types.NewString("$unionIndex"), types.UInt32(1)).Set(types.NewString("$unionValue"), types.NewString(val))}
|
|
}
|
|
|
|
func (def __unionOfEOfFloat64AndFOfStringDef) F() (val string, ok bool) {
|
|
if def.__unionIndex != 1 {
|
|
return
|
|
}
|
|
return def.__unionValue.(string), true
|
|
}
|
|
|
|
func (def __unionOfEOfFloat64AndFOfStringDef) SetF(val string) __unionOfEOfFloat64AndFOfStringDef {
|
|
def.__unionIndex = 1
|
|
def.__unionValue = val
|
|
return def
|
|
}
|