Introduce UnresolvedKind, so TypeRefKind isn't overloaded.

We'd wound up in a spot where serialization code used 'TypeRefKind' to
mean one of two very different things...either an actual value that
describes some Noms type, or a reference to a type definition that
lives somewhere else. To get rid of this ambiguity, we introduce
'UnresolvedKind' to take over the latter meaning. Now, TypeRefKind
means _only_ a value that describes a type. If you want to point off
to a type definition elsewhere in the type package, or in another
type package, use UnresolvedKind.
This commit is contained in:
Chris Masone
2015-10-16 14:35:18 -07:00
parent e9f5b1e2b5
commit 9b225dce9b
24 changed files with 638 additions and 471 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ func TestDatasetCommitTracker(t *testing.T) {
assert.False(ds2.Head().Value().Equals(ds1Commit))
assert.False(ds1.Head().Value().Equals(ds2Commit))
assert.Equal("sha1-f2e1dc4fa579e0bc58ad90dddc9b94e8b36b2740", ms.Root().String())
assert.Equal("sha1-caf368ddcfc4c841dace8b1fe8c7a1cf3d94f890", ms.Root().String())
}
func newDS(id string, ms *chunks.MemoryStore) Dataset {
+30 -15
View File
@@ -99,7 +99,6 @@ func generate(packageName, in, out, depsDir string, pkgDS dataset.Dataset) datas
// Generate code for all p's deps first.
deps := generateDepCode(depsDir, p.New(), pkgDS.Store())
generateAndEmit(getBareFileName(in), out, importPaths(depsDir, deps), deps, p)
// Since we're just building up a set of refs to all the packages in pkgDS, simply retrying is the logical response to commit failure.
@@ -486,18 +485,22 @@ func (gen *codeGen) writeEnum(t types.TypeRef, ordinal int) {
func (gen *codeGen) canUseDef(t types.TypeRef) bool {
cache := map[string]bool{}
var rec func(t types.TypeRef) bool
rec = func(t types.TypeRef) bool {
rt := gen.Resolve(t)
var rec func(t types.TypeRef, p types.Package) bool
rec = func(t types.TypeRef, p types.Package) bool {
if t.HasPackageRef() {
p = gen.deps[t.PackageRef()]
d.Chk.NotNil(p)
}
rt := resolveInPackage(t, &p)
switch rt.Kind() {
case types.ListKind:
return rec(rt.Desc.(types.CompoundDesc).ElemTypes[0])
return rec(rt.Desc.(types.CompoundDesc).ElemTypes[0], p)
case types.SetKind:
elemType := rt.Desc.(types.CompoundDesc).ElemTypes[0]
return !gen.containsNonComparable(elemType) && rec(elemType)
return !gen.containsNonComparable(elemType) && rec(elemType, p)
case types.MapKind:
elemTypes := rt.Desc.(types.CompoundDesc).ElemTypes
return !gen.containsNonComparable(elemTypes[0]) && rec(elemTypes[0]) && rec(elemTypes[1])
return !gen.containsNonComparable(elemTypes[0]) && rec(elemTypes[0], p) && rec(elemTypes[1], p)
case types.StructKind:
userName := gen.generator.UserName(t)
if b, ok := cache[userName]; ok {
@@ -505,7 +508,7 @@ func (gen *codeGen) canUseDef(t types.TypeRef) bool {
}
cache[userName] = true
for _, f := range rt.Desc.(types.StructDesc).Fields {
if f.T.Equals(t) || !rec(f.T) {
if f.T.Equals(t) || !rec(f.T, p) {
cache[userName] = false
return false
}
@@ -516,7 +519,8 @@ func (gen *codeGen) canUseDef(t types.TypeRef) bool {
}
}
return rec(t)
// TODO: pkg.Parsed.New() gets called too often. Figure out whether we generally want a Package or a PackageDef and modify pkg.Parsed accordingly. BUG 420
return rec(t, gen.pkg.New())
}
// We use a go map as the def for Set and Map. These cannot have a key that is a
@@ -524,9 +528,13 @@ func (gen *codeGen) canUseDef(t types.TypeRef) bool {
func (gen *codeGen) containsNonComparable(t types.TypeRef) bool {
cache := map[string]bool{}
var rec func(t types.TypeRef) bool
rec = func(t types.TypeRef) bool {
t = gen.Resolve(t)
var rec func(t types.TypeRef, p types.Package) bool
rec = func(t types.TypeRef, p types.Package) bool {
if t.HasPackageRef() {
p = gen.deps[t.PackageRef()]
d.Chk.NotNil(p)
}
t = resolveInPackage(t, &p)
switch t.Desc.Kind() {
case types.ListKind, types.MapKind, types.SetKind:
return true
@@ -540,7 +548,7 @@ func (gen *codeGen) containsNonComparable(t types.TypeRef) bool {
// get handled higher up in the call chain.
cache[userName] = false
for _, f := range t.Desc.(types.StructDesc).Fields {
if rec(f.T) {
if rec(f.T, p) {
cache[userName] = true
return true
}
@@ -550,6 +558,13 @@ func (gen *codeGen) containsNonComparable(t types.TypeRef) bool {
return false
}
}
return rec(t)
// TODO: pkg.Parsed.New() gets called too often. Figure out whether we generally want a Package or a PackageDef and modify pkg.Parsed accordingly. BUG 420
return rec(t, gen.pkg.New())
}
func resolveInPackage(t types.TypeRef, p *types.Package) types.TypeRef {
if !t.IsUnresolved() {
return t
}
return p.Types().Get(uint64(t.Ordinal()))
}
+3
View File
@@ -22,6 +22,7 @@ import (
"github.com/attic-labs/noms/dataset"
"github.com/attic-labs/noms/nomdl/codegen/code"
"github.com/attic-labs/noms/nomdl/pkg"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -166,11 +167,13 @@ func TestImportedTypes(t *testing.T) {
types.MakeEnumTypeRef("E1", "a", "b"),
types.MakeStructTypeRef("S1", []types.Field{
types.Field{"f", types.MakePrimitiveTypeRef(types.BoolKind), false},
types.Field{"e", types.MakeTypeRef(ref.Ref{}, 0), false},
}, types.Choices{})},
}.New()
importedRef := types.WriteValue(imported.NomsValue(), ds)
pkgDS, ok := pkgDS.Commit(types.NewSetOfRefOfPackage().Insert(types.NewRefOfPackage(importedRef)).NomsValue())
assert.True(ok)
good := fmt.Sprintf(`
alias Other = import "%s"
@@ -0,0 +1,200 @@
// This file was generated by nomdl/codegen.
package sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b
import (
"github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
var __sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9bPackageInFile_sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_CachedRef = __sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9bPackageInFile_sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_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 __sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9bPackageInFile_sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_Ref() ref.Ref {
p := types.PackageDef{
Types: types.ListOfTypeRefDef{
types.MakeStructTypeRef("D",
[]types.Field{
types.Field{"structField", types.MakeTypeRef(ref.Parse("sha1-a28289724b3c6c83ea7d1a7ac67e050b058099bb"), 0), false},
types.Field{"enumField", types.MakeTypeRef(ref.Parse("sha1-a28289724b3c6c83ea7d1a7ac67e050b058099bb"), 1), false},
},
types.Choices{},
),
types.MakeStructTypeRef("DUser",
[]types.Field{
types.Field{"Dfield", types.MakeTypeRef(ref.Ref{}, 0), false},
},
types.Choices{},
),
},
}.New()
return types.RegisterPackage(&p)
}
// D
type D struct {
m types.Map
}
func NewD() D {
return D{types.NewMap(
types.NewString("$type"), types.MakeTypeRef(__sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9bPackageInFile_sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_CachedRef, 0),
types.NewString("structField"), sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.NewS().NomsValue(),
types.NewString("enumField"), types.UInt32(0),
)}
}
type DDef struct {
StructField sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.SDef
EnumField sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.E
}
func (def DDef) New() D {
return D{
types.NewMap(
types.NewString("$type"), types.MakeTypeRef(__sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9bPackageInFile_sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_CachedRef, 0),
types.NewString("structField"), def.StructField.New().NomsValue(),
types.NewString("enumField"), types.UInt32(def.EnumField),
)}
}
func (s D) Def() (d DDef) {
d.StructField = sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.SFromVal(s.m.Get(types.NewString("structField"))).Def()
d.EnumField = sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
return
}
var __typeRefForD = types.MakeTypeRef(__sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9bPackageInFile_sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_CachedRef, 0)
func (m D) TypeRef() types.TypeRef {
return __typeRefForD
}
func init() {
types.RegisterFromValFunction(__typeRefForD, func(v types.Value) types.NomsValue {
return DFromVal(v)
})
}
func DFromVal(val types.Value) D {
// TODO: Validate here
return D{val.(types.Map)}
}
func (s D) NomsValue() types.Value {
return s.m
}
func (s D) Equals(other types.Value) bool {
if other, ok := other.(D); ok {
return s.m.Equals(other.m)
}
return false
}
func (s D) Ref() ref.Ref {
return s.m.Ref()
}
func (s D) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.m.Chunks()...)
return
}
func (s D) StructField() sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.S {
return sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.SFromVal(s.m.Get(types.NewString("structField")))
}
func (s D) SetStructField(val sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.S) D {
return D{s.m.Set(types.NewString("structField"), val.NomsValue())}
}
func (s D) EnumField() sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.E {
return sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
}
func (s D) SetEnumField(val sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.E) D {
return D{s.m.Set(types.NewString("enumField"), types.UInt32(val))}
}
// DUser
type DUser struct {
m types.Map
}
func NewDUser() DUser {
return DUser{types.NewMap(
types.NewString("$type"), types.MakeTypeRef(__sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9bPackageInFile_sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_CachedRef, 1),
types.NewString("Dfield"), NewD().NomsValue(),
)}
}
type DUserDef struct {
Dfield DDef
}
func (def DUserDef) New() DUser {
return DUser{
types.NewMap(
types.NewString("$type"), types.MakeTypeRef(__sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9bPackageInFile_sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_CachedRef, 1),
types.NewString("Dfield"), def.Dfield.New().NomsValue(),
)}
}
func (s DUser) Def() (d DUserDef) {
d.Dfield = DFromVal(s.m.Get(types.NewString("Dfield"))).Def()
return
}
var __typeRefForDUser = types.MakeTypeRef(__sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9bPackageInFile_sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_CachedRef, 1)
func (m DUser) TypeRef() types.TypeRef {
return __typeRefForDUser
}
func init() {
types.RegisterFromValFunction(__typeRefForDUser, func(v types.Value) types.NomsValue {
return DUserFromVal(v)
})
}
func DUserFromVal(val types.Value) DUser {
// TODO: Validate here
return DUser{val.(types.Map)}
}
func (s DUser) NomsValue() types.Value {
return s.m
}
func (s DUser) Equals(other types.Value) bool {
if other, ok := other.(DUser); ok {
return s.m.Equals(other.m)
}
return false
}
func (s DUser) Ref() ref.Ref {
return s.m.Ref()
}
func (s DUser) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.m.Chunks()...)
return
}
func (s DUser) Dfield() D {
return DFromVal(s.m.Get(types.NewString("Dfield")))
}
func (s DUser) SetDfield(val D) DUser {
return DUser{s.m.Set(types.NewString("Dfield"), val.NomsValue())}
}
@@ -1,18 +1,18 @@
// This file was generated by nomdl/codegen.
package sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9
package sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb
import (
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
var __sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9PackageInFile_sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9_CachedRef = __sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9PackageInFile_sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9_Ref()
var __sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bbPackageInFile_sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb_CachedRef = __sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bbPackageInFile_sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb_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 __sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9PackageInFile_sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9_Ref() ref.Ref {
func __sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bbPackageInFile_sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb_Ref() ref.Ref {
p := types.PackageDef{
Types: types.ListOfTypeRefDef{
@@ -37,7 +37,7 @@ type S struct {
func NewS() S {
return S{types.NewMap(
types.NewString("$type"), types.MakeTypeRef(__sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9PackageInFile_sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9_CachedRef, 0),
types.NewString("$type"), types.MakeTypeRef(__sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bbPackageInFile_sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb_CachedRef, 0),
types.NewString("s"), types.NewString(""),
types.NewString("b"), types.Bool(false),
)}
@@ -51,7 +51,7 @@ type SDef struct {
func (def SDef) New() S {
return S{
types.NewMap(
types.NewString("$type"), types.MakeTypeRef(__sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9PackageInFile_sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9_CachedRef, 0),
types.NewString("$type"), types.MakeTypeRef(__sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bbPackageInFile_sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb_CachedRef, 0),
types.NewString("s"), types.NewString(def.S),
types.NewString("b"), types.Bool(def.B),
)}
@@ -63,7 +63,7 @@ func (s S) Def() (d SDef) {
return
}
var __typeRefForS = types.MakeTypeRef(__sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9PackageInFile_sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9_CachedRef, 0)
var __typeRefForS = types.MakeTypeRef(__sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bbPackageInFile_sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb_CachedRef, 0)
func (m S) TypeRef() types.TypeRef {
return __typeRefForS
@@ -1,118 +0,0 @@
// This file was generated by nomdl/codegen.
package sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5
import (
"github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
var __sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5PackageInFile_sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_CachedRef = __sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5PackageInFile_sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_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 __sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5PackageInFile_sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_Ref() ref.Ref {
p := types.PackageDef{
Types: types.ListOfTypeRefDef{
types.MakeStructTypeRef("D",
[]types.Field{
types.Field{"structField", types.MakeTypeRef(ref.Parse("sha1-98b6b6ab264682e37158e48a36684fa1f32afdc9"), 0), false},
types.Field{"enumField", types.MakeTypeRef(ref.Parse("sha1-98b6b6ab264682e37158e48a36684fa1f32afdc9"), 1), false},
},
types.Choices{},
),
},
}.New()
return types.RegisterPackage(&p)
}
// D
type D struct {
m types.Map
}
func NewD() D {
return D{types.NewMap(
types.NewString("$type"), types.MakeTypeRef(__sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5PackageInFile_sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_CachedRef, 0),
types.NewString("structField"), sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.NewS().NomsValue(),
types.NewString("enumField"), types.UInt32(0),
)}
}
type DDef struct {
StructField sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.SDef
EnumField sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.E
}
func (def DDef) New() D {
return D{
types.NewMap(
types.NewString("$type"), types.MakeTypeRef(__sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5PackageInFile_sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_CachedRef, 0),
types.NewString("structField"), def.StructField.New().NomsValue(),
types.NewString("enumField"), types.UInt32(def.EnumField),
)}
}
func (s D) Def() (d DDef) {
d.StructField = sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.SFromVal(s.m.Get(types.NewString("structField"))).Def()
d.EnumField = sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
return
}
var __typeRefForD = types.MakeTypeRef(__sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5PackageInFile_sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_CachedRef, 0)
func (m D) TypeRef() types.TypeRef {
return __typeRefForD
}
func init() {
types.RegisterFromValFunction(__typeRefForD, func(v types.Value) types.NomsValue {
return DFromVal(v)
})
}
func DFromVal(val types.Value) D {
// TODO: Validate here
return D{val.(types.Map)}
}
func (s D) NomsValue() types.Value {
return s.m
}
func (s D) Equals(other types.Value) bool {
if other, ok := other.(D); ok {
return s.m.Equals(other.m)
}
return false
}
func (s D) Ref() ref.Ref {
return s.m.Ref()
}
func (s D) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.m.Chunks()...)
return
}
func (s D) StructField() sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.S {
return sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.SFromVal(s.m.Get(types.NewString("structField")))
}
func (s D) SetStructField(val sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.S) D {
return D{s.m.Set(types.NewString("structField"), val.NomsValue())}
}
func (s D) EnumField() sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.E {
return sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
}
func (s D) SetEnumField(val sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.E) D {
return D{s.m.Set(types.NewString("enumField"), types.UInt32(val))}
}
+2 -2
View File
@@ -41,8 +41,8 @@ func TestTypeRef(t *testing.T) {
def := StructDef{"hi", true}
st := def.New()
typ := st.TypeRef()
assert.Equal("", typ.Name())
assert.Equal(types.TypeRefKind, typ.Kind())
assert.EqualValues(0, typ.Ordinal())
assert.Equal(types.UnresolvedKind, typ.Kind())
}
func TestStructChunks(t *testing.T) {
+59 -59
View File
@@ -3,7 +3,7 @@
package test
import (
"github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5"
"github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -20,7 +20,7 @@ func __testPackageInFile_struct_with_imports_Ref() ref.Ref {
types.MakeEnumTypeRef("E", "E1", "Ignored"),
types.MakeStructTypeRef("ImportUser",
[]types.Field{
types.Field{"importedStruct", types.MakeTypeRef(ref.Parse("sha1-d64765d6f185e4e5f7d9e67d1fc4e084b38229f5"), 0), false},
types.Field{"importedStruct", types.MakeTypeRef(ref.Parse("sha1-62ceff17aeabec0b252f8acfd18b3758b6e63e9b"), 0), false},
types.Field{"enum", types.MakeTypeRef(ref.Ref{}, 0), false},
},
types.Choices{},
@@ -48,13 +48,13 @@ type ImportUser struct {
func NewImportUser() ImportUser {
return ImportUser{types.NewMap(
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_with_imports_CachedRef, 1),
types.NewString("importedStruct"), sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.NewD().NomsValue(),
types.NewString("importedStruct"), sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.NewD().NomsValue(),
types.NewString("enum"), types.UInt32(0),
)}
}
type ImportUserDef struct {
ImportedStruct sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.DDef
ImportedStruct sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.DDef
Enum E
}
@@ -68,7 +68,7 @@ func (def ImportUserDef) New() ImportUser {
}
func (s ImportUser) Def() (d ImportUserDef) {
d.ImportedStruct = sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.DFromVal(s.m.Get(types.NewString("importedStruct"))).Def()
d.ImportedStruct = sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.DFromVal(s.m.Get(types.NewString("importedStruct"))).Def()
d.Enum = E(s.m.Get(types.NewString("enum")).(types.UInt32))
return
}
@@ -111,11 +111,11 @@ func (s ImportUser) Chunks() (futures []types.Future) {
return
}
func (s ImportUser) ImportedStruct() sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.D {
return sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.DFromVal(s.m.Get(types.NewString("importedStruct")))
func (s ImportUser) ImportedStruct() sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.D {
return sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.DFromVal(s.m.Get(types.NewString("importedStruct")))
}
func (s ImportUser) SetImportedStruct(val sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.D) ImportUser {
func (s ImportUser) SetImportedStruct(val sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.D) ImportUser {
return ImportUser{s.m.Set(types.NewString("importedStruct"), val.NomsValue())}
}
@@ -127,111 +127,111 @@ func (s ImportUser) SetEnum(val E) ImportUser {
return ImportUser{s.m.Set(types.NewString("enum"), types.UInt32(val))}
}
// ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D
// ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D
type ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D struct {
type ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D struct {
l types.List
}
func NewListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D() ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D {
return ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D{types.NewList()}
func NewListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D() ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D {
return ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D{types.NewList()}
}
type ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_DDef []sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.DDef
type ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_DDef []sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.DDef
func (def ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_DDef) New() ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D {
func (def ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_DDef) New() ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = d.New().NomsValue()
}
return ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D{types.NewList(l...)}
return ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D{types.NewList(l...)}
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Def() ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_DDef {
d := make([]sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.DDef, l.Len())
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Def() ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_DDef {
d := make([]sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.DDef, l.Len())
for i := uint64(0); i < l.Len(); i++ {
d[i] = sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.DFromVal(l.l.Get(i)).Def()
d[i] = sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.DFromVal(l.l.Get(i)).Def()
}
return d
}
func ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_DFromVal(val types.Value) ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D {
func ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_DFromVal(val types.Value) ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D {
// TODO: Validate here
return ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D{val.(types.List)}
return ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D{val.(types.List)}
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) NomsValue() types.Value {
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) NomsValue() types.Value {
return l.l
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Equals(other types.Value) bool {
if other, ok := other.(ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D); ok {
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Equals(other types.Value) bool {
if other, ok := other.(ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Ref() ref.Ref {
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Chunks() (futures []types.Future) {
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Chunks() (futures []types.Future) {
futures = append(futures, l.TypeRef().Chunks()...)
futures = append(futures, l.l.Chunks()...)
return
}
// A Noms Value that describes ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D.
var __typeRefForListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D types.TypeRef
// A Noms Value that describes ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D.
var __typeRefForListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D types.TypeRef
func (m ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) TypeRef() types.TypeRef {
return __typeRefForListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D
func (m ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) TypeRef() types.TypeRef {
return __typeRefForListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D
}
func init() {
__typeRefForListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(ref.Parse("sha1-d64765d6f185e4e5f7d9e67d1fc4e084b38229f5"), 0))
types.RegisterFromValFunction(__typeRefForListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D, func(v types.Value) types.NomsValue {
return ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_DFromVal(v)
__typeRefForListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(ref.Parse("sha1-62ceff17aeabec0b252f8acfd18b3758b6e63e9b"), 0))
types.RegisterFromValFunction(__typeRefForListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D, func(v types.Value) types.NomsValue {
return ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_DFromVal(v)
})
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Len() uint64 {
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Len() uint64 {
return l.l.Len()
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Empty() bool {
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Empty() bool {
return l.Len() == uint64(0)
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Get(i uint64) sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.D {
return sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.DFromVal(l.l.Get(i))
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Get(i uint64) sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.D {
return sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.DFromVal(l.l.Get(i))
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Slice(idx uint64, end uint64) ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D {
return ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D{l.l.Slice(idx, end)}
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Slice(idx uint64, end uint64) ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D {
return ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D{l.l.Slice(idx, end)}
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Set(i uint64, val sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.D) ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D {
return ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D{l.l.Set(i, val.NomsValue())}
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Set(i uint64, val sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.D) ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D {
return ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D{l.l.Set(i, val.NomsValue())}
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Append(v ...sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.D) ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D {
return ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D{l.l.Append(l.fromElemSlice(v)...)}
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Append(v ...sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.D) ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D {
return ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D{l.l.Append(l.fromElemSlice(v)...)}
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Insert(idx uint64, v ...sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.D) ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D {
return ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D{l.l.Insert(idx, l.fromElemSlice(v)...)}
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Insert(idx uint64, v ...sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.D) ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D {
return ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D{l.l.Insert(idx, l.fromElemSlice(v)...)}
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Remove(idx uint64, end uint64) ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D {
return ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D{l.l.Remove(idx, end)}
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Remove(idx uint64, end uint64) ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D {
return ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D{l.l.Remove(idx, end)}
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) RemoveAt(idx uint64) ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D {
return ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D{(l.l.RemoveAt(idx))}
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) RemoveAt(idx uint64) ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D {
return ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D{(l.l.RemoveAt(idx))}
}
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) fromElemSlice(p []sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.D) []types.Value {
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) fromElemSlice(p []sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.D) []types.Value {
r := make([]types.Value, len(p))
for i, v := range p {
r[i] = v.NomsValue()
@@ -239,27 +239,27 @@ func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) fromElemSlice(p [
return r
}
type ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_DIterCallback func(v sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.D, i uint64) (stop bool)
type ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_DIterCallback func(v sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.D, i uint64) (stop bool)
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Iter(cb ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_DIterCallback) {
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Iter(cb ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_DIterCallback) {
l.l.Iter(func(v types.Value, i uint64) bool {
return cb(sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.DFromVal(v), i)
return cb(sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.DFromVal(v), i)
})
}
type ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_DIterAllCallback func(v sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.D, i uint64)
type ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_DIterAllCallback func(v sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.D, i uint64)
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) IterAll(cb ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_DIterAllCallback) {
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) IterAll(cb ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_DIterAllCallback) {
l.l.IterAll(func(v types.Value, i uint64) {
cb(sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.DFromVal(v), i)
cb(sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.DFromVal(v), i)
})
}
type ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_DFilterCallback func(v sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.D, i uint64) (keep bool)
type ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_DFilterCallback func(v sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.D, i uint64) (keep bool)
func (l ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D) Filter(cb ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_DFilterCallback) ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D {
nl := NewListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_D()
l.IterAll(func(v sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5.D, i uint64) {
func (l ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D) Filter(cb ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_DFilterCallback) ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D {
nl := NewListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_D()
l.IterAll(func(v sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b.D, i uint64) {
if cb(v, i) {
nl = nl.Append(v)
}
@@ -4,8 +4,8 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
leaf "github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9"
dep "github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5"
dep "github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b"
leaf "github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb"
)
func TestWithImportsDef(t *testing.T) {
@@ -38,7 +38,7 @@ func TestWithImportsDef(t *testing.T) {
func TestListOfImportsDef(t *testing.T) {
assert := assert.New(t)
lDef := ListOfsha1_d64765d6f185e4e5f7d9e67d1fc4e084b38229f5_DDef{
lDef := ListOfsha1_62ceff17aeabec0b252f8acfd18b3758b6e63e9b_DDef{
dep.DDef{EnumField: leaf.E3},
dep.DDef{EnumField: leaf.E2},
dep.DDef{EnumField: leaf.E1},
+96 -14
View File
@@ -3,7 +3,7 @@
package test
import (
"github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9"
"github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -19,8 +19,14 @@ func __testPackageInFile_dep_Ref() ref.Ref {
types.MakeStructTypeRef("D",
[]types.Field{
types.Field{"structField", types.MakeTypeRef(ref.Parse("sha1-98b6b6ab264682e37158e48a36684fa1f32afdc9"), 0), false},
types.Field{"enumField", types.MakeTypeRef(ref.Parse("sha1-98b6b6ab264682e37158e48a36684fa1f32afdc9"), 1), false},
types.Field{"structField", types.MakeTypeRef(ref.Parse("sha1-a28289724b3c6c83ea7d1a7ac67e050b058099bb"), 0), false},
types.Field{"enumField", types.MakeTypeRef(ref.Parse("sha1-a28289724b3c6c83ea7d1a7ac67e050b058099bb"), 1), false},
},
types.Choices{},
),
types.MakeStructTypeRef("DUser",
[]types.Field{
types.Field{"Dfield", types.MakeTypeRef(ref.Ref{}, 0), false},
},
types.Choices{},
),
@@ -38,14 +44,14 @@ type D struct {
func NewD() D {
return D{types.NewMap(
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_dep_CachedRef, 0),
types.NewString("structField"), sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.NewS().NomsValue(),
types.NewString("structField"), sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.NewS().NomsValue(),
types.NewString("enumField"), types.UInt32(0),
)}
}
type DDef struct {
StructField sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.SDef
EnumField sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.E
StructField sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.SDef
EnumField sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.E
}
func (def DDef) New() D {
@@ -58,8 +64,8 @@ func (def DDef) New() D {
}
func (s D) Def() (d DDef) {
d.StructField = sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.SFromVal(s.m.Get(types.NewString("structField"))).Def()
d.EnumField = sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
d.StructField = sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.SFromVal(s.m.Get(types.NewString("structField"))).Def()
d.EnumField = sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
return
}
@@ -101,18 +107,94 @@ func (s D) Chunks() (futures []types.Future) {
return
}
func (s D) StructField() sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.S {
return sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.SFromVal(s.m.Get(types.NewString("structField")))
func (s D) StructField() sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.S {
return sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.SFromVal(s.m.Get(types.NewString("structField")))
}
func (s D) SetStructField(val sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.S) D {
func (s D) SetStructField(val sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.S) D {
return D{s.m.Set(types.NewString("structField"), val.NomsValue())}
}
func (s D) EnumField() sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.E {
return sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
func (s D) EnumField() sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.E {
return sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
}
func (s D) SetEnumField(val sha1_98b6b6ab264682e37158e48a36684fa1f32afdc9.E) D {
func (s D) SetEnumField(val sha1_a28289724b3c6c83ea7d1a7ac67e050b058099bb.E) D {
return D{s.m.Set(types.NewString("enumField"), types.UInt32(val))}
}
// DUser
type DUser struct {
m types.Map
}
func NewDUser() DUser {
return DUser{types.NewMap(
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_dep_CachedRef, 1),
types.NewString("Dfield"), NewD().NomsValue(),
)}
}
type DUserDef struct {
Dfield DDef
}
func (def DUserDef) New() DUser {
return DUser{
types.NewMap(
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_dep_CachedRef, 1),
types.NewString("Dfield"), def.Dfield.New().NomsValue(),
)}
}
func (s DUser) Def() (d DUserDef) {
d.Dfield = DFromVal(s.m.Get(types.NewString("Dfield"))).Def()
return
}
var __typeRefForDUser = types.MakeTypeRef(__testPackageInFile_dep_CachedRef, 1)
func (m DUser) TypeRef() types.TypeRef {
return __typeRefForDUser
}
func init() {
types.RegisterFromValFunction(__typeRefForDUser, func(v types.Value) types.NomsValue {
return DUserFromVal(v)
})
}
func DUserFromVal(val types.Value) DUser {
// TODO: Validate here
return DUser{val.(types.Map)}
}
func (s DUser) NomsValue() types.Value {
return s.m
}
func (s DUser) Equals(other types.Value) bool {
if other, ok := other.(DUser); ok {
return s.m.Equals(other.m)
}
return false
}
func (s DUser) Ref() ref.Ref {
return s.m.Ref()
}
func (s DUser) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.m.Chunks()...)
return
}
func (s DUser) Dfield() D {
return DFromVal(s.m.Get(types.NewString("Dfield")))
}
func (s DUser) SetDfield(val D) DUser {
return DUser{s.m.Set(types.NewString("Dfield"), val.NomsValue())}
}
+5 -1
View File
@@ -1,6 +1,10 @@
alias leaf = import "sha1-98b6b6ab264682e37158e48a36684fa1f32afdc9"
alias leaf = import "sha1-a28289724b3c6c83ea7d1a7ac67e050b058099bb"
struct D {
structField: leaf.S
enumField: leaf.E
}
struct DUser {
Dfield: D
}
+1 -1
View File
@@ -143,7 +143,7 @@ Type <- t:(PrimitiveType / CompoundType / Union / NamespaceIdent) {
case types.Choices:
return types.MakeStructTypeRef("", nil, t), nil
case namespaceIdent:
return types.MakeExternalTypeRef(t.Namespace, t.ID), nil
return types.MakeUnresolvedTypeRef(t.Namespace, t.ID), nil
default:
return nil, fmt.Errorf("%v is %T, not something that satisfies TypeRef", t, t)
}
+146 -146
View File
@@ -564,218 +564,218 @@ var g = &grammar{
},
{
name: "CompoundType",
pos: position{line: 152, col: 1, offset: 3790},
pos: position{line: 152, col: 1, offset: 3792},
expr: &choiceExpr{
pos: position{line: 152, col: 17, offset: 3806},
pos: position{line: 152, col: 17, offset: 3808},
alternatives: []interface{}{
&actionExpr{
pos: position{line: 152, col: 17, offset: 3806},
pos: position{line: 152, col: 17, offset: 3808},
run: (*parser).callonCompoundType2,
expr: &seqExpr{
pos: position{line: 152, col: 17, offset: 3806},
pos: position{line: 152, col: 17, offset: 3808},
exprs: []interface{}{
&litMatcher{
pos: position{line: 152, col: 17, offset: 3806},
pos: position{line: 152, col: 17, offset: 3808},
val: "List",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 152, col: 24, offset: 3813},
pos: position{line: 152, col: 24, offset: 3815},
name: "_",
},
&litMatcher{
pos: position{line: 152, col: 26, offset: 3815},
pos: position{line: 152, col: 26, offset: 3817},
val: "(",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 152, col: 30, offset: 3819},
pos: position{line: 152, col: 30, offset: 3821},
name: "_",
},
&labeledExpr{
pos: position{line: 152, col: 32, offset: 3821},
pos: position{line: 152, col: 32, offset: 3823},
label: "t",
expr: &ruleRefExpr{
pos: position{line: 152, col: 34, offset: 3823},
pos: position{line: 152, col: 34, offset: 3825},
name: "Type",
},
},
&ruleRefExpr{
pos: position{line: 152, col: 39, offset: 3828},
pos: position{line: 152, col: 39, offset: 3830},
name: "_",
},
&litMatcher{
pos: position{line: 152, col: 41, offset: 3830},
pos: position{line: 152, col: 41, offset: 3832},
val: ")",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 152, col: 45, offset: 3834},
pos: position{line: 152, col: 45, offset: 3836},
name: "_",
},
},
},
},
&actionExpr{
pos: position{line: 154, col: 5, offset: 3920},
pos: position{line: 154, col: 5, offset: 3922},
run: (*parser).callonCompoundType13,
expr: &seqExpr{
pos: position{line: 154, col: 5, offset: 3920},
pos: position{line: 154, col: 5, offset: 3922},
exprs: []interface{}{
&litMatcher{
pos: position{line: 154, col: 5, offset: 3920},
pos: position{line: 154, col: 5, offset: 3922},
val: "Map",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 154, col: 11, offset: 3926},
pos: position{line: 154, col: 11, offset: 3928},
name: "_",
},
&litMatcher{
pos: position{line: 154, col: 13, offset: 3928},
pos: position{line: 154, col: 13, offset: 3930},
val: "(",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 154, col: 17, offset: 3932},
pos: position{line: 154, col: 17, offset: 3934},
name: "_",
},
&labeledExpr{
pos: position{line: 154, col: 19, offset: 3934},
pos: position{line: 154, col: 19, offset: 3936},
label: "k",
expr: &ruleRefExpr{
pos: position{line: 154, col: 21, offset: 3936},
pos: position{line: 154, col: 21, offset: 3938},
name: "Type",
},
},
&ruleRefExpr{
pos: position{line: 154, col: 26, offset: 3941},
pos: position{line: 154, col: 26, offset: 3943},
name: "_",
},
&litMatcher{
pos: position{line: 154, col: 28, offset: 3943},
pos: position{line: 154, col: 28, offset: 3945},
val: ",",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 154, col: 32, offset: 3947},
pos: position{line: 154, col: 32, offset: 3949},
name: "_",
},
&labeledExpr{
pos: position{line: 154, col: 34, offset: 3949},
pos: position{line: 154, col: 34, offset: 3951},
label: "v",
expr: &ruleRefExpr{
pos: position{line: 154, col: 36, offset: 3951},
pos: position{line: 154, col: 36, offset: 3953},
name: "Type",
},
},
&ruleRefExpr{
pos: position{line: 154, col: 41, offset: 3956},
pos: position{line: 154, col: 41, offset: 3958},
name: "_",
},
&litMatcher{
pos: position{line: 154, col: 43, offset: 3958},
pos: position{line: 154, col: 43, offset: 3960},
val: ")",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 154, col: 47, offset: 3962},
pos: position{line: 154, col: 47, offset: 3964},
name: "_",
},
},
},
},
&actionExpr{
pos: position{line: 156, col: 5, offset: 4066},
pos: position{line: 156, col: 5, offset: 4068},
run: (*parser).callonCompoundType29,
expr: &seqExpr{
pos: position{line: 156, col: 5, offset: 4066},
pos: position{line: 156, col: 5, offset: 4068},
exprs: []interface{}{
&litMatcher{
pos: position{line: 156, col: 5, offset: 4066},
pos: position{line: 156, col: 5, offset: 4068},
val: "Set",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 156, col: 11, offset: 4072},
pos: position{line: 156, col: 11, offset: 4074},
name: "_",
},
&litMatcher{
pos: position{line: 156, col: 13, offset: 4074},
pos: position{line: 156, col: 13, offset: 4076},
val: "(",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 156, col: 17, offset: 4078},
pos: position{line: 156, col: 17, offset: 4080},
name: "_",
},
&labeledExpr{
pos: position{line: 156, col: 19, offset: 4080},
pos: position{line: 156, col: 19, offset: 4082},
label: "t",
expr: &ruleRefExpr{
pos: position{line: 156, col: 21, offset: 4082},
pos: position{line: 156, col: 21, offset: 4084},
name: "Type",
},
},
&ruleRefExpr{
pos: position{line: 156, col: 26, offset: 4087},
pos: position{line: 156, col: 26, offset: 4089},
name: "_",
},
&litMatcher{
pos: position{line: 156, col: 28, offset: 4089},
pos: position{line: 156, col: 28, offset: 4091},
val: ")",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 156, col: 32, offset: 4093},
pos: position{line: 156, col: 32, offset: 4095},
name: "_",
},
},
},
},
&actionExpr{
pos: position{line: 158, col: 5, offset: 4178},
pos: position{line: 158, col: 5, offset: 4180},
run: (*parser).callonCompoundType40,
expr: &seqExpr{
pos: position{line: 158, col: 5, offset: 4178},
pos: position{line: 158, col: 5, offset: 4180},
exprs: []interface{}{
&litMatcher{
pos: position{line: 158, col: 5, offset: 4178},
pos: position{line: 158, col: 5, offset: 4180},
val: "Ref",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 158, col: 11, offset: 4184},
pos: position{line: 158, col: 11, offset: 4186},
name: "_",
},
&litMatcher{
pos: position{line: 158, col: 13, offset: 4186},
pos: position{line: 158, col: 13, offset: 4188},
val: "(",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 158, col: 17, offset: 4190},
pos: position{line: 158, col: 17, offset: 4192},
name: "_",
},
&labeledExpr{
pos: position{line: 158, col: 19, offset: 4192},
pos: position{line: 158, col: 19, offset: 4194},
label: "t",
expr: &ruleRefExpr{
pos: position{line: 158, col: 21, offset: 4194},
pos: position{line: 158, col: 21, offset: 4196},
name: "Type",
},
},
&ruleRefExpr{
pos: position{line: 158, col: 26, offset: 4199},
pos: position{line: 158, col: 26, offset: 4201},
name: "_",
},
&litMatcher{
pos: position{line: 158, col: 28, offset: 4201},
pos: position{line: 158, col: 28, offset: 4203},
val: ")",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 158, col: 32, offset: 4205},
pos: position{line: 158, col: 32, offset: 4207},
name: "_",
},
},
@@ -786,88 +786,88 @@ var g = &grammar{
},
{
name: "PrimitiveType",
pos: position{line: 162, col: 1, offset: 4289},
pos: position{line: 162, col: 1, offset: 4291},
expr: &actionExpr{
pos: position{line: 162, col: 18, offset: 4306},
pos: position{line: 162, col: 18, offset: 4308},
run: (*parser).callonPrimitiveType1,
expr: &labeledExpr{
pos: position{line: 162, col: 18, offset: 4306},
pos: position{line: 162, col: 18, offset: 4308},
label: "p",
expr: &choiceExpr{
pos: position{line: 162, col: 21, offset: 4309},
pos: position{line: 162, col: 21, offset: 4311},
alternatives: []interface{}{
&litMatcher{
pos: position{line: 162, col: 21, offset: 4309},
pos: position{line: 162, col: 21, offset: 4311},
val: "UInt64",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 32, offset: 4320},
pos: position{line: 162, col: 32, offset: 4322},
val: "UInt32",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 43, offset: 4331},
pos: position{line: 162, col: 43, offset: 4333},
val: "UInt16",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 54, offset: 4342},
pos: position{line: 162, col: 54, offset: 4344},
val: "UInt8",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 64, offset: 4352},
pos: position{line: 162, col: 64, offset: 4354},
val: "Int64",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 74, offset: 4362},
pos: position{line: 162, col: 74, offset: 4364},
val: "Int32",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 84, offset: 4372},
pos: position{line: 162, col: 84, offset: 4374},
val: "Int16",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 94, offset: 4382},
pos: position{line: 162, col: 94, offset: 4384},
val: "Int8",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 103, offset: 4391},
pos: position{line: 162, col: 103, offset: 4393},
val: "Float64",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 115, offset: 4403},
pos: position{line: 162, col: 115, offset: 4405},
val: "Float32",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 127, offset: 4415},
pos: position{line: 162, col: 127, offset: 4417},
val: "Bool",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 136, offset: 4424},
pos: position{line: 162, col: 136, offset: 4426},
val: "String",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 147, offset: 4435},
pos: position{line: 162, col: 147, offset: 4437},
val: "Blob",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 156, offset: 4444},
pos: position{line: 162, col: 156, offset: 4446},
val: "Value",
ignoreCase: false,
},
&litMatcher{
pos: position{line: 162, col: 166, offset: 4454},
pos: position{line: 162, col: 166, offset: 4456},
val: "TypeRef",
ignoreCase: false,
},
@@ -878,28 +878,28 @@ var g = &grammar{
},
{
name: "QuotedString",
pos: position{line: 166, col: 1, offset: 4539},
pos: position{line: 166, col: 1, offset: 4541},
expr: &actionExpr{
pos: position{line: 166, col: 17, offset: 4555},
pos: position{line: 166, col: 17, offset: 4557},
run: (*parser).callonQuotedString1,
expr: &seqExpr{
pos: position{line: 166, col: 17, offset: 4555},
pos: position{line: 166, col: 17, offset: 4557},
exprs: []interface{}{
&litMatcher{
pos: position{line: 166, col: 17, offset: 4555},
pos: position{line: 166, col: 17, offset: 4557},
val: "\"",
ignoreCase: false,
},
&labeledExpr{
pos: position{line: 166, col: 21, offset: 4559},
pos: position{line: 166, col: 21, offset: 4561},
label: "n",
expr: &ruleRefExpr{
pos: position{line: 166, col: 23, offset: 4561},
pos: position{line: 166, col: 23, offset: 4563},
name: "String",
},
},
&litMatcher{
pos: position{line: 166, col: 30, offset: 4568},
pos: position{line: 166, col: 30, offset: 4570},
val: "\"",
ignoreCase: false,
},
@@ -909,42 +909,42 @@ var g = &grammar{
},
{
name: "String",
pos: position{line: 170, col: 1, offset: 4601},
pos: position{line: 170, col: 1, offset: 4603},
expr: &actionExpr{
pos: position{line: 170, col: 11, offset: 4611},
pos: position{line: 170, col: 11, offset: 4613},
run: (*parser).callonString1,
expr: &choiceExpr{
pos: position{line: 170, col: 12, offset: 4612},
pos: position{line: 170, col: 12, offset: 4614},
alternatives: []interface{}{
&seqExpr{
pos: position{line: 170, col: 12, offset: 4612},
pos: position{line: 170, col: 12, offset: 4614},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 170, col: 12, offset: 4612},
pos: position{line: 170, col: 12, offset: 4614},
name: "StringPiece",
},
&litMatcher{
pos: position{line: 170, col: 24, offset: 4624},
pos: position{line: 170, col: 24, offset: 4626},
val: "\\\"",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 170, col: 29, offset: 4629},
pos: position{line: 170, col: 29, offset: 4631},
name: "StringPiece",
},
&litMatcher{
pos: position{line: 170, col: 41, offset: 4641},
pos: position{line: 170, col: 41, offset: 4643},
val: "\\\"",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 170, col: 46, offset: 4646},
pos: position{line: 170, col: 46, offset: 4648},
name: "StringPiece",
},
},
},
&ruleRefExpr{
pos: position{line: 170, col: 60, offset: 4660},
pos: position{line: 170, col: 60, offset: 4662},
name: "StringPiece",
},
},
@@ -953,24 +953,24 @@ var g = &grammar{
},
{
name: "StringPiece",
pos: position{line: 174, col: 1, offset: 4706},
pos: position{line: 174, col: 1, offset: 4708},
expr: &zeroOrMoreExpr{
pos: position{line: 174, col: 16, offset: 4721},
pos: position{line: 174, col: 16, offset: 4723},
expr: &choiceExpr{
pos: position{line: 174, col: 17, offset: 4722},
pos: position{line: 174, col: 17, offset: 4724},
alternatives: []interface{}{
&seqExpr{
pos: position{line: 174, col: 17, offset: 4722},
pos: position{line: 174, col: 17, offset: 4724},
exprs: []interface{}{
&litMatcher{
pos: position{line: 174, col: 17, offset: 4722},
pos: position{line: 174, col: 17, offset: 4724},
val: "\\",
ignoreCase: false,
},
&notExpr{
pos: position{line: 174, col: 21, offset: 4726},
pos: position{line: 174, col: 21, offset: 4728},
expr: &litMatcher{
pos: position{line: 174, col: 22, offset: 4727},
pos: position{line: 174, col: 22, offset: 4729},
val: "\"",
ignoreCase: false,
},
@@ -978,7 +978,7 @@ var g = &grammar{
},
},
&charClassMatcher{
pos: position{line: 174, col: 28, offset: 4733},
pos: position{line: 174, col: 28, offset: 4735},
val: "[^\"\\\\]",
chars: []rune{'"', '\\'},
ignoreCase: false,
@@ -990,27 +990,27 @@ var g = &grammar{
},
{
name: "NamespaceIdent",
pos: position{line: 176, col: 1, offset: 4743},
pos: position{line: 176, col: 1, offset: 4745},
expr: &actionExpr{
pos: position{line: 176, col: 19, offset: 4761},
pos: position{line: 176, col: 19, offset: 4763},
run: (*parser).callonNamespaceIdent1,
expr: &seqExpr{
pos: position{line: 176, col: 19, offset: 4761},
pos: position{line: 176, col: 19, offset: 4763},
exprs: []interface{}{
&labeledExpr{
pos: position{line: 176, col: 19, offset: 4761},
pos: position{line: 176, col: 19, offset: 4763},
label: "n",
expr: &zeroOrMoreExpr{
pos: position{line: 176, col: 21, offset: 4763},
pos: position{line: 176, col: 21, offset: 4765},
expr: &seqExpr{
pos: position{line: 176, col: 22, offset: 4764},
pos: position{line: 176, col: 22, offset: 4766},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 176, col: 22, offset: 4764},
pos: position{line: 176, col: 22, offset: 4766},
name: "Ident",
},
&litMatcher{
pos: position{line: 176, col: 28, offset: 4770},
pos: position{line: 176, col: 28, offset: 4772},
val: ".",
ignoreCase: false,
},
@@ -1019,10 +1019,10 @@ var g = &grammar{
},
},
&labeledExpr{
pos: position{line: 176, col: 34, offset: 4776},
pos: position{line: 176, col: 34, offset: 4778},
label: "id",
expr: &ruleRefExpr{
pos: position{line: 176, col: 37, offset: 4779},
pos: position{line: 176, col: 37, offset: 4781},
name: "Ident",
},
},
@@ -1032,15 +1032,15 @@ var g = &grammar{
},
{
name: "Ident",
pos: position{line: 185, col: 1, offset: 4977},
pos: position{line: 185, col: 1, offset: 4979},
expr: &actionExpr{
pos: position{line: 185, col: 10, offset: 4986},
pos: position{line: 185, col: 10, offset: 4988},
run: (*parser).callonIdent1,
expr: &seqExpr{
pos: position{line: 185, col: 10, offset: 4986},
pos: position{line: 185, col: 10, offset: 4988},
exprs: []interface{}{
&charClassMatcher{
pos: position{line: 185, col: 10, offset: 4986},
pos: position{line: 185, col: 10, offset: 4988},
val: "[\\pL_]",
chars: []rune{'_'},
classes: []*unicode.RangeTable{rangeTable("L")},
@@ -1048,9 +1048,9 @@ var g = &grammar{
inverted: false,
},
&zeroOrMoreExpr{
pos: position{line: 185, col: 17, offset: 4993},
pos: position{line: 185, col: 17, offset: 4995},
expr: &charClassMatcher{
pos: position{line: 185, col: 17, offset: 4993},
pos: position{line: 185, col: 17, offset: 4995},
val: "[\\pL\\pN_]",
chars: []rune{'_'},
classes: []*unicode.RangeTable{rangeTable("L"), rangeTable("N")},
@@ -1065,28 +1065,28 @@ var g = &grammar{
{
name: "_",
displayName: "\"optional whitespace\"",
pos: position{line: 189, col: 1, offset: 5037},
pos: position{line: 189, col: 1, offset: 5039},
expr: &actionExpr{
pos: position{line: 189, col: 28, offset: 5064},
pos: position{line: 189, col: 28, offset: 5066},
run: (*parser).callon_1,
expr: &seqExpr{
pos: position{line: 189, col: 28, offset: 5064},
pos: position{line: 189, col: 28, offset: 5066},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 189, col: 28, offset: 5064},
pos: position{line: 189, col: 28, offset: 5066},
name: "WS",
},
&zeroOrMoreExpr{
pos: position{line: 189, col: 31, offset: 5067},
pos: position{line: 189, col: 31, offset: 5069},
expr: &seqExpr{
pos: position{line: 189, col: 32, offset: 5068},
pos: position{line: 189, col: 32, offset: 5070},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 189, col: 32, offset: 5068},
pos: position{line: 189, col: 32, offset: 5070},
name: "Comment",
},
&ruleRefExpr{
pos: position{line: 189, col: 40, offset: 5076},
pos: position{line: 189, col: 40, offset: 5078},
name: "WS",
},
},
@@ -1098,11 +1098,11 @@ var g = &grammar{
},
{
name: "WS",
pos: position{line: 193, col: 1, offset: 5103},
pos: position{line: 193, col: 1, offset: 5105},
expr: &zeroOrMoreExpr{
pos: position{line: 193, col: 7, offset: 5109},
pos: position{line: 193, col: 7, offset: 5111},
expr: &charClassMatcher{
pos: position{line: 193, col: 7, offset: 5109},
pos: position{line: 193, col: 7, offset: 5111},
val: "[\\r\\n\\t\\pZ]",
chars: []rune{'\r', '\n', '\t'},
classes: []*unicode.RangeTable{rangeTable("Z")},
@@ -1113,22 +1113,22 @@ var g = &grammar{
},
{
name: "Comment",
pos: position{line: 195, col: 1, offset: 5123},
pos: position{line: 195, col: 1, offset: 5125},
expr: &choiceExpr{
pos: position{line: 195, col: 12, offset: 5134},
pos: position{line: 195, col: 12, offset: 5136},
alternatives: []interface{}{
&seqExpr{
pos: position{line: 195, col: 12, offset: 5134},
pos: position{line: 195, col: 12, offset: 5136},
exprs: []interface{}{
&litMatcher{
pos: position{line: 195, col: 12, offset: 5134},
pos: position{line: 195, col: 12, offset: 5136},
val: "//",
ignoreCase: false,
},
&zeroOrMoreExpr{
pos: position{line: 195, col: 17, offset: 5139},
pos: position{line: 195, col: 17, offset: 5141},
expr: &charClassMatcher{
pos: position{line: 195, col: 17, offset: 5139},
pos: position{line: 195, col: 17, offset: 5141},
val: "[^\\n]",
chars: []rune{'\n'},
ignoreCase: false,
@@ -1138,7 +1138,7 @@ var g = &grammar{
},
},
&ruleRefExpr{
pos: position{line: 195, col: 26, offset: 5148},
pos: position{line: 195, col: 26, offset: 5150},
name: "MultilineComment",
},
},
@@ -1146,32 +1146,32 @@ var g = &grammar{
},
{
name: "MultilineComment",
pos: position{line: 197, col: 1, offset: 5166},
pos: position{line: 197, col: 1, offset: 5168},
expr: &seqExpr{
pos: position{line: 197, col: 21, offset: 5186},
pos: position{line: 197, col: 21, offset: 5188},
exprs: []interface{}{
&litMatcher{
pos: position{line: 197, col: 21, offset: 5186},
pos: position{line: 197, col: 21, offset: 5188},
val: "/*",
ignoreCase: false,
},
&zeroOrMoreExpr{
pos: position{line: 197, col: 26, offset: 5191},
pos: position{line: 197, col: 26, offset: 5193},
expr: &choiceExpr{
pos: position{line: 197, col: 27, offset: 5192},
pos: position{line: 197, col: 27, offset: 5194},
alternatives: []interface{}{
&seqExpr{
pos: position{line: 197, col: 27, offset: 5192},
pos: position{line: 197, col: 27, offset: 5194},
exprs: []interface{}{
&litMatcher{
pos: position{line: 197, col: 27, offset: 5192},
pos: position{line: 197, col: 27, offset: 5194},
val: "*",
ignoreCase: false,
},
&notExpr{
pos: position{line: 197, col: 31, offset: 5196},
pos: position{line: 197, col: 31, offset: 5198},
expr: &litMatcher{
pos: position{line: 197, col: 32, offset: 5197},
pos: position{line: 197, col: 32, offset: 5199},
val: "/",
ignoreCase: false,
},
@@ -1179,7 +1179,7 @@ var g = &grammar{
},
},
&charClassMatcher{
pos: position{line: 197, col: 38, offset: 5203},
pos: position{line: 197, col: 38, offset: 5205},
val: "[^*]",
chars: []rune{'*'},
ignoreCase: false,
@@ -1189,7 +1189,7 @@ var g = &grammar{
},
},
&litMatcher{
pos: position{line: 197, col: 45, offset: 5210},
pos: position{line: 197, col: 45, offset: 5212},
val: "*/",
ignoreCase: false,
},
@@ -1198,18 +1198,18 @@ var g = &grammar{
},
{
name: "EOF",
pos: position{line: 199, col: 1, offset: 5216},
pos: position{line: 199, col: 1, offset: 5218},
expr: &seqExpr{
pos: position{line: 199, col: 8, offset: 5223},
pos: position{line: 199, col: 8, offset: 5225},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 199, col: 8, offset: 5223},
pos: position{line: 199, col: 8, offset: 5225},
name: "_",
},
&notExpr{
pos: position{line: 199, col: 10, offset: 5225},
pos: position{line: 199, col: 10, offset: 5227},
expr: &anyMatcher{
line: 199, col: 11, offset: 5226,
line: 199, col: 11, offset: 5228,
},
},
},
@@ -1396,7 +1396,7 @@ func (c *current) onType1(t interface{}) (interface{}, error) {
case types.Choices:
return types.MakeStructTypeRef("", nil, t), nil
case namespaceIdent:
return types.MakeExternalTypeRef(t.Namespace, t.ID), nil
return types.MakeUnresolvedTypeRef(t.Namespace, t.ID), nil
default:
return nil, fmt.Errorf("%v is %T, not something that satisfies TypeRef", t, t)
}
+5 -5
View File
@@ -40,7 +40,7 @@ func (suite *ImportTestSuite) SetupTest() {
suite.nestedRef = types.WriteValue(suite.nested.NomsValue(), suite.cs)
fs := types.MakeStructTypeRef("ForeignStruct", []types.Field{
types.Field{"b", types.MakePrimitiveTypeRef(types.BoolKind), false},
types.Field{"b", types.MakeTypeRef(ref.Ref{}, 1), false},
types.Field{"n", types.MakeTypeRef(suite.nestedRef, 0), false},
},
types.Choices{})
@@ -66,28 +66,28 @@ func (suite *ImportTestSuite) TestGetDeps() {
func (suite *ImportTestSuite) TestResolveNamespace() {
deps := GetDeps(types.SetOfRefOfPackageDef{suite.importRef: true}, suite.cs)
t := resolveNamespace(types.MakeExternalTypeRef("Other", "ForeignEnum"), map[string]ref.Ref{"Other": suite.importRef}, deps)
t := resolveNamespace(types.MakeUnresolvedTypeRef("Other", "ForeignEnum"), map[string]ref.Ref{"Other": suite.importRef}, deps)
suite.EqualValues(types.MakeTypeRef(suite.importRef, 1), t)
}
func (suite *ImportTestSuite) TestUnknownAlias() {
deps := GetDeps(types.SetOfRefOfPackageDef{suite.importRef: true}, suite.cs)
suite.Panics(func() {
resolveNamespace(types.MakeExternalTypeRef("Bother", "ForeignEnum"), map[string]ref.Ref{"Other": suite.importRef}, deps)
resolveNamespace(types.MakeUnresolvedTypeRef("Bother", "ForeignEnum"), map[string]ref.Ref{"Other": suite.importRef}, deps)
})
}
func (suite *ImportTestSuite) TestUnknownImportedType() {
deps := GetDeps(types.SetOfRefOfPackageDef{suite.importRef: true}, suite.cs)
suite.Panics(func() {
resolveNamespace(types.MakeExternalTypeRef("Other", "NotThere"), map[string]ref.Ref{"Other": suite.importRef}, deps)
resolveNamespace(types.MakeUnresolvedTypeRef("Other", "NotThere"), map[string]ref.Ref{"Other": suite.importRef}, deps)
})
}
func (suite *ImportTestSuite) TestDetectFreeVariable() {
ls := types.MakeStructTypeRef("Local", []types.Field{
types.Field{"b", types.MakePrimitiveTypeRef(types.BoolKind), false},
types.Field{"n", types.MakeExternalTypeRef("", "OtherLocal"), false},
types.Field{"n", types.MakeUnresolvedTypeRef("", "OtherLocal"), false},
},
types.Choices{})
suite.Panics(func() {
+7 -7
View File
@@ -55,10 +55,10 @@ using List(Noms.Commit)
suite.Equal(types.MapKind, pkg.UsingDeclarations[0].Desc.Kind())
suite.True(types.MakePrimitiveTypeRef(types.StringKind).Equals(pkg.UsingDeclarations[0].Desc.(types.CompoundDesc).ElemTypes[0]))
suite.True(types.MakeExternalTypeRef("", "Simple").Equals(pkg.UsingDeclarations[0].Desc.(types.CompoundDesc).ElemTypes[1]))
suite.True(types.MakeUnresolvedTypeRef("", "Simple").Equals(pkg.UsingDeclarations[0].Desc.(types.CompoundDesc).ElemTypes[1]))
suite.Equal(types.ListKind, pkg.UsingDeclarations[1].Desc.Kind())
suite.EqualValues([]types.TypeRef{types.MakeExternalTypeRef("Noms", "Commit")},
suite.EqualValues([]types.TypeRef{types.MakeUnresolvedTypeRef("Noms", "Commit")},
pkg.UsingDeclarations[1].Desc.(types.CompoundDesc).ElemTypes)
}
@@ -211,15 +211,15 @@ func (suite *ParsedResultTestSuite) SetupTest() {
suite.mapOfNamedTypeField = testField{
"mapOfStructToOther",
types.MakeCompoundTypeRef("", types.MapKind,
types.MakeExternalTypeRef("", "Struct"),
types.MakeExternalTypeRef("Elsewhere", "Other"),
types.MakeUnresolvedTypeRef("", "Struct"),
types.MakeUnresolvedTypeRef("Elsewhere", "Other"),
),
false}
suite.namedTypeField = testField{"otherStruct", types.MakeExternalTypeRef("", "Other"), false}
suite.namespacedTypeField = testField{"namespacedStruct", types.MakeExternalTypeRef("Elsewhere", "Other"), false}
suite.namedTypeField = testField{"otherStruct", types.MakeUnresolvedTypeRef("", "Other"), false}
suite.namespacedTypeField = testField{"namespacedStruct", types.MakeUnresolvedTypeRef("Elsewhere", "Other"), false}
suite.union = types.Choices{
types.Field{"a", types.MakePrimitiveTypeRef(types.Int32Kind), false},
types.Field{"n", types.MakeExternalTypeRef("NN", "Other"), false},
types.Field{"n", types.MakeUnresolvedTypeRef("NN", "Other"), false},
types.Field{"c", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
}
}
+9 -15
View File
@@ -44,10 +44,6 @@ func (r *jsonArrayReader) read() interface{} {
return v
}
func (r *jsonArrayReader) peek() interface{} {
return r.a[r.i]
}
func (r *jsonArrayReader) atEnd() bool {
return r.i >= len(r.a)
}
@@ -84,12 +80,8 @@ func (r *jsonArrayReader) readTypeRefAsTag() TypeRef {
valueType := r.readTypeRefAsTag()
return MakeCompoundTypeRef("", kind, keyType, valueType)
case TypeRefKind:
// TypeRefKind can mean that we have a TypeRef primitive or a TypeRef pointing to a TypeRef in a Package. Do a lookahead.
i := r.peek()
if _, ok := i.(float64); ok {
return MakePrimitiveTypeRef(TypeRefKind)
}
return MakePrimitiveTypeRef(TypeRefKind)
case UnresolvedKind:
pkgRef := r.readRef()
ordinal := int16(r.read().(float64))
return MakeTypeRef(pkgRef, ordinal)
@@ -208,15 +200,18 @@ func (r *jsonArrayReader) readValueWithoutTag(t TypeRef, pkg *Package) NomsValue
panic("not allowed")
case TypeRefKind:
return r.readTypeRefKindToValue(t, pkg)
case UnresolvedKind:
return r.readUnresolvedKindToValue(t, pkg)
}
panic("not reachable")
}
func (r *jsonArrayReader) readTypeRefKindToValue(t TypeRef, pkg *Package) NomsValue {
if _, ok := t.Desc.(PrimitiveDesc); ok {
return valueAsNomsValue{r.readTypeRefAsValue(pkg), t}
}
d.Chk.IsType(PrimitiveDesc(0), t.Desc)
return valueAsNomsValue{r.readTypeRefAsValue(pkg), t}
}
func (r *jsonArrayReader) readUnresolvedKindToValue(t TypeRef, pkg *Package) NomsValue {
d.Chk.True(t.IsUnresolved())
pkgRef := t.PackageRef()
ordinal := t.Ordinal()
@@ -275,8 +270,7 @@ func (r *jsonArrayReader) readTypeRefAsValue(pkg *Package) TypeRef {
choices = append(choices, Field{Name: fieldName, T: fieldType, Optional: optional})
}
return MakeStructTypeRef(name, fields, choices)
case TypeRefKind:
case UnresolvedKind:
pkgRef := r.readRef()
ordinal := int16(r.read().(float64))
return MakeTypeRef(pkgRef, ordinal)
+15 -24
View File
@@ -50,7 +50,7 @@ func TestReadTypeRefAsTag(t *testing.T) {
test(MakeCompoundTypeRef("", ListKind, MakePrimitiveTypeRef(BoolKind)), "[%d, %d, true, false]", ListKind, BoolKind)
pkgRef := ref.Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d")
test(MakeTypeRef(pkgRef, 42), `[%d, "%s", 42]`, TypeRefKind, pkgRef.String())
test(MakeTypeRef(pkgRef, 42), `[%d, "%s", 42]`, UnresolvedKind, pkgRef.String())
test(MakePrimitiveTypeRef(TypeRefKind), `[%d, %d, "%s", 12]`, TypeRefKind, TypeRefKind, pkgRef.String())
}
@@ -212,8 +212,7 @@ func TestReadStruct(t *testing.T) {
pkg := NewPackage().SetTypes(NewListOfTypeRef().Append(tref))
pkgRef := RegisterPackage(&pkg)
// TODO: Should use ordinal of type and not name
a := parseJson(`[%d, "%s", 0, 42, "hi", true]`, TypeRefKind, pkgRef.String())
a := parseJson(`[%d, "%s", 0, 42, "hi", true]`, UnresolvedKind, pkgRef.String())
r := newJsonArrayReader(a, cs)
structTr := MakeTypeRef(pkgRef, 0)
@@ -242,7 +241,7 @@ func TestReadStructUnion(t *testing.T) {
pkg := NewPackage().SetTypes(NewListOfTypeRef().Append(tref))
pkgRef := RegisterPackage(&pkg)
a := parseJson(`[%d, "%s", 0, 42, 1, "hi"]`, TypeRefKind, pkgRef.String())
a := parseJson(`[%d, "%s", 0, 42, 1, "hi"]`, UnresolvedKind, pkgRef.String())
r := newJsonArrayReader(a, cs)
structTr := MakeTypeRef(pkgRef, 0)
@@ -272,8 +271,7 @@ func TestReadStructOptional(t *testing.T) {
pkg := NewPackage().SetTypes(NewListOfTypeRef().Append(tref))
pkgRef := RegisterPackage(&pkg)
// TODO: Should use ordinal of type and not name
a := parseJson(`[%d, "%s", 0, 42, false, true, false]`, TypeRefKind, pkgRef.String())
a := parseJson(`[%d, "%s", 0, 42, false, true, false]`, UnresolvedKind, pkgRef.String())
r := newJsonArrayReader(a, cs)
structTr := MakeTypeRef(pkgRef, 0)
@@ -307,8 +305,7 @@ func TestReadStructWithList(t *testing.T) {
pkg := NewPackage().SetTypes(NewListOfTypeRef().Append(tref))
pkgRef := RegisterPackage(&pkg)
// TODO: Should use ordinal of type and not name
a := parseJson(`[%d, "%s", 0, true, [0, 1, 2], "hi"]`, TypeRefKind, pkgRef.String())
a := parseJson(`[%d, "%s", 0, true, [0, 1, 2], "hi"]`, UnresolvedKind, pkgRef.String())
r := newJsonArrayReader(a, cs)
structTr := MakeTypeRef(pkgRef, 0)
@@ -347,8 +344,7 @@ func TestReadStructWithValue(t *testing.T) {
pkg := NewPackage().SetTypes(NewListOfTypeRef().Append(tref))
pkgRef := RegisterPackage(&pkg)
// TODO: Should use ordinal of type and not name
a := parseJson(`[%d, "%s", 0, true, %d, 42, "hi"]`, TypeRefKind, pkgRef.String(), UInt8Kind)
a := parseJson(`[%d, "%s", 0, true, %d, 42, "hi"]`, UnresolvedKind, pkgRef.String(), UInt8Kind)
r := newJsonArrayReader(a, cs)
structTr := MakeTypeRef(pkgRef, 0)
@@ -382,8 +378,7 @@ func TestReadValueStruct(t *testing.T) {
pkg := NewPackage().SetTypes(NewListOfTypeRef().Append(tref))
pkgRef := RegisterPackage(&pkg)
// TODO: Should use ordinal of type and not name
a := parseJson(`[%d, %d, "%s", 0, 42, "hi", true]`, ValueKind, TypeRefKind, pkgRef.String())
a := parseJson(`[%d, %d, "%s", 0, 42, "hi", true]`, ValueKind, UnresolvedKind, pkgRef.String())
r := newJsonArrayReader(a, cs)
structTr := MakeTypeRef(pkgRef, 0)
@@ -407,8 +402,7 @@ func TestReadEnum(t *testing.T) {
pkg := NewPackage().SetTypes(NewListOfTypeRef().Append(tref))
pkgRef := RegisterPackage(&pkg)
// TODO: Should use ordinal of type and not name
a := parseJson(`[%d, "%s", 0, 1]`, TypeRefKind, pkgRef.String())
a := parseJson(`[%d, "%s", 0, 1]`, UnresolvedKind, pkgRef.String())
r := newJsonArrayReader(a, cs)
v := r.readTopLevelValue().NomsValue()
@@ -423,8 +417,7 @@ func TestReadValueEnum(t *testing.T) {
pkg := NewPackage().SetTypes(NewListOfTypeRef().Append(tref))
pkgRef := RegisterPackage(&pkg)
// TODO: Should use ordinal of type and not name
a := parseJson(`[%d, %d, "%s", 0, 1]`, ValueKind, TypeRefKind, pkgRef.String())
a := parseJson(`[%d, %d, "%s", 0, 1]`, ValueKind, UnresolvedKind, pkgRef.String())
r := newJsonArrayReader(a, cs)
v := r.readTopLevelValue().NomsValue()
@@ -490,8 +483,7 @@ func TestReadStructWithEnum(t *testing.T) {
pkg := NewPackage().SetTypes(NewListOfTypeRef().Append(structTref, enumTref))
pkgRef := RegisterPackage(&pkg)
// TODO: Should use ordinal of type and not name
a := parseJson(`[%d, "%s", 0, 42, 1, true]`, TypeRefKind, pkgRef.String())
a := parseJson(`[%d, "%s", 0, 42, 1, true]`, UnresolvedKind, pkgRef.String())
r := newJsonArrayReader(a, cs)
structTr := MakeTypeRef(pkgRef, 0)
@@ -521,8 +513,7 @@ func TestReadStructWithBlob(t *testing.T) {
pkg := NewPackage().SetTypes(NewListOfTypeRef().Append(tref))
pkgRef := RegisterPackage(&pkg)
// TODO: Should use ordinal of type and not name
a := parseJson(`[%d, "%s", 0, "AAE="]`, TypeRefKind, pkgRef.String())
a := parseJson(`[%d, "%s", 0, "AAE="]`, UnresolvedKind, pkgRef.String())
r := newJsonArrayReader(a, cs)
structTr := MakeTypeRef(pkgRef, 0)
@@ -571,13 +562,13 @@ func TestReadTypeRefValue(t *testing.T) {
`[%d, %d, "S", [], ["x", %d, false, "v", %d, false]]`, TypeRefKind, StructKind, Int16Kind, ValueKind)
pkgRef := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567")
test(MakeTypeRef(pkgRef, 123), `[%d, %d, "%s", 123]`, TypeRefKind, TypeRefKind, pkgRef.String())
test(MakeTypeRef(pkgRef, 123), `[%d, %d, "%s", 123]`, TypeRefKind, UnresolvedKind, pkgRef.String())
test(MakeStructTypeRef("S", []Field{
Field{"e", MakeTypeRef(pkgRef, 123), false},
Field{"x", MakePrimitiveTypeRef(Int64Kind), false},
}, Choices{}),
`[%d, %d, "S", ["e", %d, "%s", 123, false, "x", %d, false], []]`, TypeRefKind, StructKind, TypeRefKind, pkgRef.String(), Int64Kind)
`[%d, %d, "S", ["e", %d, "%s", 123, false, "x", %d, false], []]`, TypeRefKind, StructKind, UnresolvedKind, pkgRef.String(), Int64Kind)
}
func TestReadPackage(t *testing.T) {
@@ -600,11 +591,11 @@ func TestReadPackage(t *testing.T) {
// }
a := []interface{}{
float64(TypeRefKind), __typesPackageInFile_package_CachedRef.String(), float64(0),
float64(UnresolvedKind), __typesPackageInFile_package_CachedRef.String(), float64(0),
[]interface{}{}, // Dependencies
[]interface{}{ // Types
float64(StructKind), "EnumStruct", []interface{}{
"hand", float64(TypeRefKind), "sha1-0000000000000000000000000000000000000000", float64(1), false,
"hand", float64(UnresolvedKind), "sha1-0000000000000000000000000000000000000000", float64(1), false,
}, []interface{}{},
float64(EnumKind), "Handedness", []interface{}{"right", "left", "switch"},
},
+24 -30
View File
@@ -57,13 +57,11 @@ func (w *jsonArrayWriter) writeTypeRefAsTag(t TypeRef) {
for _, elemType := range t.Desc.(CompoundDesc).ElemTypes {
w.writeTypeRefAsTag(elemType)
}
case TypeRefKind:
if t.IsUnresolved() {
pkgRef := t.PackageRef()
d.Chk.NotEqual(ref.Ref{}, pkgRef)
w.writeRef(pkgRef)
w.write(t.Ordinal())
}
case UnresolvedKind:
pkgRef := t.PackageRef()
d.Chk.NotEqual(ref.Ref{}, pkgRef)
w.writeRef(pkgRef)
w.write(t.Ordinal())
}
}
@@ -106,10 +104,12 @@ func (w *jsonArrayWriter) writeValue(v Value, tr TypeRef, pkg *Package) {
case StringKind:
w.write(v.(String).String())
case TypeRefKind:
w.writeTypeRefKindValue(v, tr, pkg)
case UnresolvedKind:
if tr.HasPackageRef() {
pkg = LookupPackage(tr.PackageRef())
}
w.writeTypeRefKindValue(v, tr, pkg)
w.writeUnresolvedKindValue(v, tr, pkg)
case ValueKind:
w.writeTypeRefAsTag(v.TypeRef())
w.writeValue(v, v.TypeRef(), pkg)
@@ -151,36 +151,30 @@ func (w *jsonArrayWriter) writeTypeRefAsValue(v TypeRef) {
choiceWriter.write(choice.Optional)
}
w.write(choiceWriter.toArray())
case TypeRefKind:
if v.IsUnresolved() {
w.writeRef(v.PackageRef())
w.write(v.Ordinal())
}
case UnresolvedKind:
w.writeRef(v.PackageRef())
w.write(v.Ordinal())
default:
d.Chk.True(IsPrimitiveKind(k), v.Describe())
}
}
// writeTypeRefKindValue writes either a struct, enum or a TypeRef value
func (w *jsonArrayWriter) writeTypeRefKindValue(v Value, tr TypeRef, pkg *Package) {
if t, ok := v.(TypeRef); ok {
w.writeTypeRefAsValue(t)
} else { // Enum or Struct
pkgRef := tr.PackageRef()
if pkgRef != (ref.Ref{}) {
pkg = LookupPackage(pkgRef)
}
d.Chk.IsType(TypeRef{}, v)
w.writeTypeRefAsValue(v.(TypeRef))
}
typeDef := pkg.Types().Get(uint64(tr.Ordinal()))
k := typeDef.Kind()
if k == EnumKind {
w.write(uint32(v.(UInt32)))
} else {
d.Chk.Equal(StructKind, k)
w.writeStruct(v.(Map), typeDef, pkg)
}
// writeUnresolvedKindValue writes either a struct or an enum
func (w *jsonArrayWriter) writeUnresolvedKindValue(v Value, tr TypeRef, pkg *Package) {
typeDef := pkg.Types().Get(uint64(tr.Ordinal()))
switch typeDef.Kind() {
default:
d.Chk.Fail("An Unresolved TypeRef can only reference a StructKind or Enum Kind.", "Actually referenced: %+v", typeDef)
case EnumKind:
w.write(uint32(v.(UInt32)))
case StructKind:
w.writeStruct(v.(Map), typeDef, pkg)
}
}
+18 -18
View File
@@ -125,7 +125,7 @@ func TestWriteEmptyStruct(t *testing.T) {
w := newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{TypeRefKind, pkgRef.String(), int16(0)}, *w)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0)}, *w)
}
func TestWriteStruct(t *testing.T) {
@@ -142,7 +142,7 @@ func TestWriteStruct(t *testing.T) {
w := newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{TypeRefKind, pkgRef.String(), int16(0), int8(42), true}, *w)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), int8(42), true}, *w)
}
func TestWriteStructOptionalField(t *testing.T) {
@@ -159,13 +159,13 @@ func TestWriteStructOptionalField(t *testing.T) {
w := newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{TypeRefKind, pkgRef.String(), int16(0), true, int8(42), true}, *w)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), true, int8(42), true}, *w)
v = NewMap(NewString("b"), Bool(true))
w = newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{TypeRefKind, pkgRef.String(), int16(0), false, true}, *w)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), false, true}, *w)
}
func TestWriteStructWithUnion(t *testing.T) {
@@ -184,13 +184,13 @@ func TestWriteStructWithUnion(t *testing.T) {
w := newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{TypeRefKind, pkgRef.String(), int16(0), int8(42), uint32(1), "hi"}, *w)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), int8(42), uint32(1), "hi"}, *w)
v = NewMap(NewString("x"), Int8(42), NewString("$unionIndex"), UInt32(0), NewString("$unionValue"), Bool(true))
w = newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{TypeRefKind, pkgRef.String(), int16(0), int8(42), uint32(0), true}, *w)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), int8(42), uint32(0), true}, *w)
}
func TestWriteStructWithList(t *testing.T) {
@@ -206,12 +206,12 @@ func TestWriteStructWithList(t *testing.T) {
w := newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{TypeRefKind, pkgRef.String(), int16(0), []interface{}{"a", "b"}}, *w)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), []interface{}{"a", "b"}}, *w)
v = NewMap(NewString("l"), NewList())
w = newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{TypeRefKind, pkgRef.String(), int16(0), []interface{}{}}, *w)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), []interface{}{}}, *w)
}
func TestWriteStructWithStruct(t *testing.T) {
@@ -230,7 +230,7 @@ func TestWriteStructWithStruct(t *testing.T) {
w := newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{TypeRefKind, pkgRef.String(), int16(1), int32(42)}, *w)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(1), int32(42)}, *w)
}
func TestWriteStructWithBlob(t *testing.T) {
@@ -247,7 +247,7 @@ func TestWriteStructWithBlob(t *testing.T) {
w := newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{TypeRefKind, pkgRef.String(), int16(0), "AAE="}, *w)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), "AAE="}, *w)
}
func TestWriteEnum(t *testing.T) {
@@ -261,7 +261,7 @@ func TestWriteEnum(t *testing.T) {
w := newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{TypeRefKind, pkgRef.String(), int16(0), uint32(1)}, *w)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), uint32(1)}, *w)
}
func TestWriteListOfEnum(t *testing.T) {
@@ -276,7 +276,7 @@ func TestWriteListOfEnum(t *testing.T) {
w := newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{ListKind, TypeRefKind, pkgRef.String(), int16(0), []interface{}{uint32(0), uint32(1), uint32(2)}}, *w)
assert.EqualValues([]interface{}{ListKind, UnresolvedKind, pkgRef.String(), int16(0), []interface{}{uint32(0), uint32(1), uint32(2)}}, *w)
}
func TestWriteListOfValue(t *testing.T) {
@@ -335,7 +335,7 @@ func TestWriteListOfValueWithStruct(t *testing.T) {
w := newJsonArrayWriter()
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
assert.EqualValues([]interface{}{ListKind, ValueKind, []interface{}{TypeRefKind, pkgRef.String(), int16(0), int32(42)}}, *w)
assert.EqualValues([]interface{}{ListKind, ValueKind, []interface{}{UnresolvedKind, pkgRef.String(), int16(0), int32(42)}}, *w)
}
func TestWriteListOfValueWithTypeRefs(t *testing.T) {
@@ -361,7 +361,7 @@ func TestWriteListOfValueWithTypeRefs(t *testing.T) {
BoolKind, true,
TypeRefKind, Int32Kind,
TypeRefKind, TypeRefKind,
TypeRefKind, TypeRefKind, pkgRef.String(), int16(0),
TypeRefKind, UnresolvedKind, pkgRef.String(), int16(0),
}}, *w)
}
@@ -408,10 +408,10 @@ func TestWriteTypeRefValue(t *testing.T) {
}))
pkgRef := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567")
test([]interface{}{TypeRefKind, TypeRefKind, pkgRef.String(), int16(123)},
test([]interface{}{TypeRefKind, UnresolvedKind, pkgRef.String(), int16(123)},
MakeTypeRef(pkgRef, 123))
test([]interface{}{TypeRefKind, StructKind, "S", []interface{}{"e", TypeRefKind, pkgRef.String(), int16(123), false, "x", Int64Kind, false}, []interface{}{}},
test([]interface{}{TypeRefKind, StructKind, "S", []interface{}{"e", UnresolvedKind, pkgRef.String(), int16(123), false, "x", Int64Kind, false}, []interface{}{}},
MakeStructTypeRef("S", []Field{
Field{"e", MakeTypeRef(pkgRef, 123), false},
Field{"x", MakePrimitiveTypeRef(Int64Kind), false},
@@ -451,11 +451,11 @@ func TestWritePackage(t *testing.T) {
// }
exp := []interface{}{
TypeRefKind, __typesPackageInFile_package_CachedRef.String(), int16(0),
UnresolvedKind, __typesPackageInFile_package_CachedRef.String(), int16(0),
[]interface{}{}, // Dependencies
[]interface{}{
StructKind, "EnumStruct", []interface{}{
"hand", TypeRefKind, "sha1-0000000000000000000000000000000000000000", int16(1), false,
"hand", UnresolvedKind, "sha1-0000000000000000000000000000000000000000", int16(1), false,
}, []interface{}{},
EnumKind, "Handedness", []interface{}{"right", "left", "switch"},
},
+2
View File
@@ -26,8 +26,10 @@ const (
EnumKind
StructKind
TypeRefKind
UnresolvedKind
)
// IsPrimitiveKind returns true if k represents a Noms primitive type, which excludes collections (List, Map, Set), Refs, Enums, Structs and Unresolved type references.
func IsPrimitiveKind(k NomsKind) bool {
switch k {
case BoolKind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, Float32Kind, Float64Kind, UInt8Kind, UInt16Kind, UInt32Kind, UInt64Kind, StringKind, BlobKind, ValueKind, TypeRefKind:
+1 -1
View File
@@ -14,7 +14,7 @@ func TestType(t *testing.T) {
typ := st.TypeRef()
ordinal := int16(0)
assert.Equal(ordinal, typ.Ordinal())
assert.Equal(TypeRefKind, typ.Kind())
assert.Equal(UnresolvedKind, typ.Kind())
assert.Equal(__typesPackageInFile_package_CachedRef, typ.PackageRef())
typ = LookupPackage(__typesPackageInFile_package_CachedRef).Types().Get(0)
+2 -2
View File
@@ -70,7 +70,7 @@ func fromEncodeable(i interface{}, cs chunks.ChunkSource) Future {
kind := NomsKind(i.Kind)
desc := typeDescFromInterface(kind, i.Desc, cs)
if desc, ok := desc.(UnresolvedDesc); ok {
d.Chk.Equal(TypeRefKind, kind)
d.Chk.Equal(UnresolvedKind, kind)
return futureFromValue(MakeTypeRef(desc.pkgRef, desc.ordinal))
}
return futureFromValue(buildType(i.Name, desc))
@@ -132,7 +132,7 @@ func typeDescFromInterface(kind NomsKind, i interface{}, cs chunks.ChunkSource)
case StructKind:
items := i.(enc.Map)
return StructDescFromMap(mapFromFutures(futuresFromIterable(items, cs), cs))
case TypeRefKind:
case UnresolvedKind:
items := i.([]interface{})
pkgRef := items[0].(ref.Ref)
ordinal := items[1].(int16)
+1 -1
View File
@@ -89,7 +89,7 @@ type UnresolvedDesc struct {
}
func (u UnresolvedDesc) Kind() NomsKind {
return TypeRefKind
return UnresolvedKind
}
func (u UnresolvedDesc) Equals(other TypeDesc) bool {
+2 -2
View File
@@ -145,7 +145,7 @@ func MakeTypeRef(pkgRef ref.Ref, ordinal int16) TypeRef {
return TypeRef{Desc: UnresolvedDesc{pkgRef, ordinal}, ref: &ref.Ref{}}
}
func MakeExternalTypeRef(namespace, n string) TypeRef {
func MakeUnresolvedTypeRef(namespace, n string) TypeRef {
return TypeRef{name: name{namespace, n}, Desc: UnresolvedDesc{ordinal: -1}, ref: &ref.Ref{}}
}
@@ -154,7 +154,7 @@ func buildType(n string, desc TypeDesc) TypeRef {
return TypeRef{name: name{name: n}, Desc: desc, ref: &ref.Ref{}}
}
switch desc.Kind() {
case ListKind, RefKind, SetKind, MapKind, EnumKind, StructKind:
case ListKind, RefKind, SetKind, MapKind, EnumKind, StructKind, UnresolvedKind:
return TypeRef{name: name{name: n}, Desc: desc, ref: &ref.Ref{}}
default:
d.Exp.Fail("Unrecognized Kind:", "%v", desc.Kind())