mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-26 10:37:04 -06:00
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
114 lines
2.6 KiB
Go
114 lines
2.6 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() types.Ref {
|
|
p := types.PackageDef{
|
|
NamedTypes: types.MapOfStringToTypeRefDef{
|
|
|
|
"EnumStruct": __typeRefOfEnumStruct(),
|
|
"Handedness": __typeRefOfHandedness(),
|
|
},
|
|
}.New()
|
|
return types.Ref{R: types.RegisterPackage(&p)}
|
|
}
|
|
|
|
// 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.Int32(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.Int32(def.Hand),
|
|
)}
|
|
}
|
|
|
|
func (s EnumStruct) Def() (d EnumStructDef) {
|
|
d.Hand = Handedness(s.m.Get(types.NewString("hand")).(types.Int32))
|
|
return
|
|
}
|
|
|
|
// Creates and returns a Noms Value that describes EnumStruct.
|
|
func __typeRefOfEnumStruct() types.TypeRef {
|
|
return types.MakeStructTypeRef("EnumStruct",
|
|
[]types.Field{
|
|
types.Field{"hand", types.MakeTypeRef("Handedness", types.Ref{}), false},
|
|
},
|
|
types.Choices{},
|
|
)
|
|
}
|
|
|
|
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 EnumStruct) bool {
|
|
return s.m.Equals(other.m)
|
|
}
|
|
|
|
func (s EnumStruct) Ref() ref.Ref {
|
|
return s.m.Ref()
|
|
}
|
|
|
|
func (s EnumStruct) Type() types.TypeRef {
|
|
return s.m.Get(types.NewString("$type")).(types.TypeRef)
|
|
}
|
|
|
|
func (s EnumStruct) Hand() Handedness {
|
|
return Handedness(s.m.Get(types.NewString("hand")).(types.Int32))
|
|
}
|
|
|
|
func (s EnumStruct) SetHand(val Handedness) EnumStruct {
|
|
return EnumStruct{s.m.Set(types.NewString("hand"), types.Int32(val))}
|
|
}
|
|
|
|
// Handedness
|
|
|
|
type Handedness uint32
|
|
|
|
const (
|
|
Right Handedness = iota
|
|
Left
|
|
Switch
|
|
)
|
|
|
|
// Creates and returns a Noms Value that describes Handedness.
|
|
func __typeRefOfHandedness() types.TypeRef {
|
|
return types.MakeEnumTypeRef("Handedness", "right",
|
|
"left",
|
|
"switch",
|
|
)
|
|
}
|