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
108 lines
2.5 KiB
Go
108 lines
2.5 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_CachedRef = __testPackageInFile_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_struct_Ref() types.Ref {
|
|
p := types.PackageDef{
|
|
NamedTypes: types.MapOfStringToTypeRefDef{
|
|
|
|
"Struct": __typeRefOfStruct(),
|
|
},
|
|
}.New()
|
|
return types.Ref{R: types.RegisterPackage(&p)}
|
|
}
|
|
|
|
// Struct
|
|
|
|
type Struct struct {
|
|
m types.Map
|
|
}
|
|
|
|
func NewStruct() Struct {
|
|
return Struct{types.NewMap(
|
|
types.NewString("$name"), types.NewString("Struct"),
|
|
types.NewString("$type"), types.MakeTypeRef("Struct", __testPackageInFile_struct_CachedRef),
|
|
types.NewString("s"), types.NewString(""),
|
|
types.NewString("b"), types.Bool(false),
|
|
)}
|
|
}
|
|
|
|
type StructDef struct {
|
|
S string
|
|
B bool
|
|
}
|
|
|
|
func (def StructDef) New() Struct {
|
|
return Struct{
|
|
types.NewMap(
|
|
types.NewString("$name"), types.NewString("Struct"),
|
|
types.NewString("$type"), types.MakeTypeRef("Struct", __testPackageInFile_struct_CachedRef),
|
|
types.NewString("s"), types.NewString(def.S),
|
|
types.NewString("b"), types.Bool(def.B),
|
|
)}
|
|
}
|
|
|
|
func (s Struct) Def() (d StructDef) {
|
|
d.S = s.m.Get(types.NewString("s")).(types.String).String()
|
|
d.B = bool(s.m.Get(types.NewString("b")).(types.Bool))
|
|
return
|
|
}
|
|
|
|
// Creates and returns a Noms Value that describes Struct.
|
|
func __typeRefOfStruct() types.TypeRef {
|
|
return types.MakeStructTypeRef("Struct",
|
|
[]types.Field{
|
|
types.Field{"s", types.MakePrimitiveTypeRef(types.StringKind), false},
|
|
types.Field{"b", types.MakePrimitiveTypeRef(types.BoolKind), false},
|
|
},
|
|
types.Choices{},
|
|
)
|
|
}
|
|
|
|
func StructFromVal(val types.Value) Struct {
|
|
// TODO: Validate here
|
|
return Struct{val.(types.Map)}
|
|
}
|
|
|
|
func (s Struct) NomsValue() types.Value {
|
|
return s.m
|
|
}
|
|
|
|
func (s Struct) Equals(other Struct) bool {
|
|
return s.m.Equals(other.m)
|
|
}
|
|
|
|
func (s Struct) Ref() ref.Ref {
|
|
return s.m.Ref()
|
|
}
|
|
|
|
func (s Struct) Type() types.TypeRef {
|
|
return s.m.Get(types.NewString("$type")).(types.TypeRef)
|
|
}
|
|
|
|
func (s Struct) S() string {
|
|
return s.m.Get(types.NewString("s")).(types.String).String()
|
|
}
|
|
|
|
func (s Struct) SetS(val string) Struct {
|
|
return Struct{s.m.Set(types.NewString("s"), types.NewString(val))}
|
|
}
|
|
|
|
func (s Struct) B() bool {
|
|
return bool(s.m.Get(types.NewString("b")).(types.Bool))
|
|
}
|
|
|
|
func (s Struct) SetB(val bool) Struct {
|
|
return Struct{s.m.Set(types.NewString("b"), types.Bool(val))}
|
|
}
|