mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-23 02:40:49 -05:00
Make all usages of Type in Go use pointers (#1295)
This is in preparation of allowing back references which requires pointers to be able to compare that the structs are the same.
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func init() {
|
||||
p := types.NewPackage([]types.Type{
|
||||
p := types.NewPackage([]*types.Type{
|
||||
types.MakeStructType("Date",
|
||||
[]types.Field{
|
||||
types.Field{"MsSinceEpoch", types.MakePrimitiveType(types.Int64Kind), false},
|
||||
@@ -54,9 +54,9 @@ func (s Date) Def() (d DateDef) {
|
||||
return
|
||||
}
|
||||
|
||||
var __typeForDate types.Type
|
||||
var __typeForDate *types.Type
|
||||
|
||||
func (m Date) Type() types.Type {
|
||||
func (m Date) Type() *types.Type {
|
||||
return __typeForDate
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func init() {
|
||||
p := types.NewPackage([]types.Type{
|
||||
p := types.NewPackage([]*types.Type{
|
||||
types.MakeStructType("Geoposition",
|
||||
[]types.Field{
|
||||
types.Field{"Latitude", types.MakePrimitiveType(types.Float32Kind), false},
|
||||
@@ -67,9 +67,9 @@ func (s Geoposition) Def() (d GeopositionDef) {
|
||||
return
|
||||
}
|
||||
|
||||
var __typeForGeoposition types.Type
|
||||
var __typeForGeoposition *types.Type
|
||||
|
||||
func (m Geoposition) Type() types.Type {
|
||||
func (m Geoposition) Type() *types.Type {
|
||||
return __typeForGeoposition
|
||||
}
|
||||
|
||||
@@ -172,9 +172,9 @@ func (s Georectangle) Def() (d GeorectangleDef) {
|
||||
return
|
||||
}
|
||||
|
||||
var __typeForGeorectangle types.Type
|
||||
var __typeForGeorectangle *types.Type
|
||||
|
||||
func (m Georectangle) Type() types.Type {
|
||||
func (m Georectangle) Type() *types.Type {
|
||||
return __typeForGeorectangle
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func init() {
|
||||
p := types.NewPackage([]types.Type{
|
||||
p := types.NewPackage([]*types.Type{
|
||||
types.MakeStructType("RemotePhoto",
|
||||
[]types.Field{
|
||||
types.Field{"Id", types.MakePrimitiveType(types.StringKind), false},
|
||||
@@ -110,9 +110,9 @@ func (s RemotePhoto) Def() (d RemotePhotoDef) {
|
||||
return
|
||||
}
|
||||
|
||||
var __typeForRemotePhoto types.Type
|
||||
var __typeForRemotePhoto *types.Type
|
||||
|
||||
func (m RemotePhoto) Type() types.Type {
|
||||
func (m RemotePhoto) Type() *types.Type {
|
||||
return __typeForRemotePhoto
|
||||
}
|
||||
|
||||
@@ -305,9 +305,9 @@ func (s Face) Def() (d FaceDef) {
|
||||
return
|
||||
}
|
||||
|
||||
var __typeForFace types.Type
|
||||
var __typeForFace *types.Type
|
||||
|
||||
func (m Face) Type() types.Type {
|
||||
func (m Face) Type() *types.Type {
|
||||
return __typeForFace
|
||||
}
|
||||
|
||||
@@ -452,9 +452,9 @@ func (s Size) Def() (d SizeDef) {
|
||||
return
|
||||
}
|
||||
|
||||
var __typeForSize types.Type
|
||||
var __typeForSize *types.Type
|
||||
|
||||
func (m Size) Type() types.Type {
|
||||
func (m Size) Type() *types.Type {
|
||||
return __typeForSize
|
||||
}
|
||||
|
||||
@@ -569,9 +569,9 @@ func (m MapOfSizeToString) ChildValues() []types.Value {
|
||||
}
|
||||
|
||||
// A Noms Value that describes MapOfSizeToString.
|
||||
var __typeForMapOfSizeToString types.Type
|
||||
var __typeForMapOfSizeToString *types.Type
|
||||
|
||||
func (m MapOfSizeToString) Type() types.Type {
|
||||
func (m MapOfSizeToString) Type() *types.Type {
|
||||
return __typeForMapOfSizeToString
|
||||
}
|
||||
|
||||
@@ -704,9 +704,9 @@ func (s SetOfString) ChildValues() []types.Value {
|
||||
}
|
||||
|
||||
// A Noms Value that describes SetOfString.
|
||||
var __typeForSetOfString types.Type
|
||||
var __typeForSetOfString *types.Type
|
||||
|
||||
func (m SetOfString) Type() types.Type {
|
||||
func (m SetOfString) Type() *types.Type {
|
||||
return __typeForSetOfString
|
||||
}
|
||||
|
||||
@@ -849,9 +849,9 @@ func (s SetOfFace) ChildValues() []types.Value {
|
||||
}
|
||||
|
||||
// A Noms Value that describes SetOfFace.
|
||||
var __typeForSetOfFace types.Type
|
||||
var __typeForSetOfFace *types.Type
|
||||
|
||||
func (m SetOfFace) Type() types.Type {
|
||||
func (m SetOfFace) Type() *types.Type {
|
||||
return __typeForSetOfFace
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ func (s *testSuite) TestCSVExporter() {
|
||||
}
|
||||
|
||||
typeDef := types.MakeStructType(structName, f, []types.Field{})
|
||||
pkg := types.NewPackage([]types.Type{typeDef}, []ref.Ref{})
|
||||
pkg := types.NewPackage([]*types.Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := types.RegisterPackage(&pkg)
|
||||
typeRef := types.MakeType(pkgRef, 0)
|
||||
structFields := typeDef.Desc.(types.StructDesc).Fields
|
||||
|
||||
+3
-3
@@ -66,7 +66,7 @@ func ReportValidFieldTypes(r *csv.Reader, headers []string) []KindSlice {
|
||||
}
|
||||
|
||||
// MakeStructTypeFromHeaders creates a struct type from the headers using |kinds| as the type of each field. If |kinds| is empty, default to strings.
|
||||
func MakeStructTypeFromHeaders(headers []string, structName string, kinds KindSlice) (typeRef, typeDef types.Type) {
|
||||
func MakeStructTypeFromHeaders(headers []string, structName string, kinds KindSlice) (typeRef, typeDef *types.Type) {
|
||||
useStringType := len(kinds) == 0
|
||||
d.Chk.True(useStringType || len(headers) == len(kinds))
|
||||
fields := make([]types.Field, len(headers))
|
||||
@@ -83,7 +83,7 @@ func MakeStructTypeFromHeaders(headers []string, structName string, kinds KindSl
|
||||
}
|
||||
}
|
||||
typeDef = types.MakeStructType(structName, fields, []types.Field{})
|
||||
pkg := types.NewPackage([]types.Type{typeDef}, []ref.Ref{})
|
||||
pkg := types.NewPackage([]*types.Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := types.RegisterPackage(&pkg)
|
||||
typeRef = types.MakeType(pkgRef, 0)
|
||||
|
||||
@@ -93,7 +93,7 @@ func MakeStructTypeFromHeaders(headers []string, structName string, kinds KindSl
|
||||
// Read takes a CSV reader and reads it into a typed List of structs. Each row gets read into a struct named structName, described by headers. If the original data contained headers it is expected that the input reader has already read those and are pointing at the first data row.
|
||||
// If kinds is non-empty, it will be used to type the fields in the generated structs; otherwise, they will be left as string-fields.
|
||||
// In addition to the list, Read returns the typeRef for the structs in the list, and last the typeDef of the structs.
|
||||
func Read(r *csv.Reader, structName string, headers []string, kinds KindSlice, vrw types.ValueReadWriter) (l types.List, typeRef, typeDef types.Type) {
|
||||
func Read(r *csv.Reader, structName string, headers []string, kinds KindSlice, vrw types.ValueReadWriter) (l types.List, typeRef, typeDef *types.Type) {
|
||||
typeRef, typeDef = MakeStructTypeFromHeaders(headers, structName, kinds)
|
||||
valueChan := make(chan types.Value, 128) // TODO: Make this a function param?
|
||||
listType := types.MakeCompoundType(types.ListKind, typeRef)
|
||||
|
||||
+5
-5
@@ -11,7 +11,7 @@ import (
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func init() {
|
||||
p := types.NewPackage([]types.Type{
|
||||
p := types.NewPackage([]*types.Type{
|
||||
types.MakeStructType("Commit",
|
||||
[]types.Field{
|
||||
types.Field{"value", types.MakePrimitiveType(types.ValueKind), false},
|
||||
@@ -41,9 +41,9 @@ func NewCommit() Commit {
|
||||
}
|
||||
}
|
||||
|
||||
var __typeForCommit types.Type
|
||||
var __typeForCommit *types.Type
|
||||
|
||||
func (m Commit) Type() types.Type {
|
||||
func (m Commit) Type() *types.Type {
|
||||
return __typeForCommit
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ func (s Commit) SetParents(val types.Set) Commit {
|
||||
return s
|
||||
}
|
||||
|
||||
func typeForMapOfStringToRefOfCommit() types.Type {
|
||||
func typeForMapOfStringToRefOfCommit() *types.Type {
|
||||
return types.MakeMapType(types.StringType, types.MakeRefType(__typeForCommit))
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ func NewMapOfStringToRefOfCommit() types.Map {
|
||||
return types.NewTypedMap(typeForMapOfStringToRefOfCommit())
|
||||
}
|
||||
|
||||
func typeForSetOfRefOfCommit() types.Type {
|
||||
func typeForSetOfRefOfCommit() *types.Type {
|
||||
return types.MakeSetType(types.MakeRefType(__typeForCommit))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Package code provides Generator, which has methods for generating code snippets from a types.Type.
|
||||
// Package code provides Generator, which has methods for generating code snippets from a *types.Type.
|
||||
// Conceptually there are few type spaces here:
|
||||
//
|
||||
// - Def - MyStructDef, ListOfBoolDef; convenient Go types for working with data from a given Noms Value.
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
// Resolver provides a single method for resolving an unresolved types.Type.
|
||||
type Resolver interface {
|
||||
Resolve(t types.Type, pkg *types.Package) types.Type
|
||||
Resolve(t *types.Type, pkg *types.Package) *types.Type
|
||||
}
|
||||
|
||||
// Generator provides methods for generating code snippets from both resolved and unresolved types.Types. In the latter case, it uses R to resolve the types.Type before generating code.
|
||||
@@ -35,7 +35,7 @@ type Generator struct {
|
||||
}
|
||||
|
||||
// DefType returns a string containing the Go type that should be used as the 'Def' for the Noms type described by t.
|
||||
func (gen *Generator) DefType(t types.Type) string {
|
||||
func (gen *Generator) DefType(t *types.Type) string {
|
||||
rt := gen.R.Resolve(t, gen.Package)
|
||||
k := rt.Kind()
|
||||
switch k {
|
||||
@@ -58,7 +58,7 @@ func (gen *Generator) DefType(t types.Type) string {
|
||||
}
|
||||
|
||||
// UserType returns a string containing the Go type that should be used when the Noms type described by t needs to be returned by a generated getter or taken as a parameter to a generated setter.
|
||||
func (gen *Generator) UserType(t types.Type) string {
|
||||
func (gen *Generator) UserType(t *types.Type) string {
|
||||
rt := gen.R.Resolve(t, gen.Package)
|
||||
k := rt.Kind()
|
||||
switch k {
|
||||
@@ -79,7 +79,7 @@ func (gen *Generator) UserType(t types.Type) string {
|
||||
}
|
||||
|
||||
// UserTypeJS returns a string containing the JS type that should be used when the Noms type described by t needs to be returned by a generated getter or taken as a parameter to a generated setter.
|
||||
func (gen *Generator) UserTypeJS(t types.Type) string {
|
||||
func (gen *Generator) UserTypeJS(t *types.Type) string {
|
||||
rt := gen.R.Resolve(t, gen.Package)
|
||||
k := rt.Kind()
|
||||
switch k {
|
||||
@@ -116,7 +116,7 @@ func (gen *Generator) UserTypeJS(t types.Type) string {
|
||||
}
|
||||
|
||||
// DefToValue returns a string containing Go code to convert an instance of a Def type (named val) to a Noms types.Value of the type described by t.
|
||||
func (gen *Generator) DefToValue(val string, t types.Type) string {
|
||||
func (gen *Generator) DefToValue(val string, t *types.Type) string {
|
||||
rt := gen.R.Resolve(t, gen.Package)
|
||||
switch rt.Kind() {
|
||||
case types.BlobKind, types.PackageKind, types.ValueKind, types.TypeKind:
|
||||
@@ -132,7 +132,7 @@ func (gen *Generator) DefToValue(val string, t types.Type) string {
|
||||
}
|
||||
|
||||
// DefToUser returns a string containing Go code to convert an instance of a Def type (named val) to a User type described by t.
|
||||
func (gen *Generator) DefToUser(val string, t types.Type) string {
|
||||
func (gen *Generator) DefToUser(val string, t *types.Type) string {
|
||||
rt := gen.R.Resolve(t, gen.Package)
|
||||
switch rt.Kind() {
|
||||
case types.BlobKind, types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.PackageKind, types.StringKind, types.TypeKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind, types.ValueKind:
|
||||
@@ -144,7 +144,7 @@ func (gen *Generator) DefToUser(val string, t types.Type) string {
|
||||
}
|
||||
|
||||
// MayHaveChunks returns whether the type (t) may contain more chunks.
|
||||
func (gen *Generator) MayHaveChunks(t types.Type) bool {
|
||||
func (gen *Generator) MayHaveChunks(t *types.Type) bool {
|
||||
rt := gen.R.Resolve(t, gen.Package)
|
||||
switch rt.Kind() {
|
||||
case types.BlobKind, types.ListKind, types.MapKind, types.PackageKind, types.RefKind, types.SetKind, types.StructKind, types.TypeKind, types.ValueKind:
|
||||
@@ -156,7 +156,7 @@ func (gen *Generator) MayHaveChunks(t types.Type) bool {
|
||||
}
|
||||
|
||||
// ValueToDef returns a string containing Go code to convert an instance of a types.Value (val) into the Def type appropriate for t.
|
||||
func (gen *Generator) ValueToDef(val string, t types.Type) string {
|
||||
func (gen *Generator) ValueToDef(val string, t *types.Type) string {
|
||||
rt := gen.R.Resolve(t, gen.Package)
|
||||
switch rt.Kind() {
|
||||
case types.BlobKind, types.PackageKind, types.TypeKind:
|
||||
@@ -174,7 +174,7 @@ func (gen *Generator) ValueToDef(val string, t types.Type) string {
|
||||
}
|
||||
|
||||
// UserToDef returns a string containing Go code to convert an User value (val) into the Def type appropriate for t.
|
||||
func (gen *Generator) UserToDef(val string, t types.Type) string {
|
||||
func (gen *Generator) UserToDef(val string, t *types.Type) string {
|
||||
rt := gen.R.Resolve(t, gen.Package)
|
||||
switch rt.Kind() {
|
||||
case types.BlobKind, types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.PackageKind, types.StringKind, types.TypeKind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind, types.ValueKind:
|
||||
@@ -188,7 +188,7 @@ func (gen *Generator) UserToDef(val string, t types.Type) string {
|
||||
}
|
||||
|
||||
// NativeToValue returns a string containing Go code to convert an instance of a native type (named val) to a Noms types.Value of the type described by t.
|
||||
func (gen *Generator) NativeToValue(val string, t types.Type) string {
|
||||
func (gen *Generator) NativeToValue(val string, t *types.Type) string {
|
||||
t = gen.R.Resolve(t, gen.Package)
|
||||
k := t.Kind()
|
||||
switch k {
|
||||
@@ -201,7 +201,7 @@ func (gen *Generator) NativeToValue(val string, t types.Type) string {
|
||||
}
|
||||
|
||||
// ValueToNative returns a string containing Go code to convert an instance of a types.Value (val) into the native type appropriate for t.
|
||||
func (gen *Generator) ValueToNative(val string, t types.Type) string {
|
||||
func (gen *Generator) ValueToNative(val string, t *types.Type) string {
|
||||
k := t.Kind()
|
||||
switch k {
|
||||
case types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.Uint16Kind, types.Uint32Kind, types.Uint64Kind, types.Uint8Kind:
|
||||
@@ -214,7 +214,7 @@ func (gen *Generator) ValueToNative(val string, t types.Type) string {
|
||||
}
|
||||
|
||||
// UserToValue returns a string containing Go code to convert an instance of a User type (named val) to a Noms types.Value of the type described by t. For Go primitive types, this will use NativeToValue(). For other types, their UserType is a Noms types.Value (or a wrapper around one), so this is more-or-less a pass-through.
|
||||
func (gen *Generator) UserToValue(val string, t types.Type) string {
|
||||
func (gen *Generator) UserToValue(val string, t *types.Type) string {
|
||||
t = gen.R.Resolve(t, gen.Package)
|
||||
k := t.Kind()
|
||||
switch k {
|
||||
@@ -227,7 +227,7 @@ func (gen *Generator) UserToValue(val string, t types.Type) string {
|
||||
}
|
||||
|
||||
// ValueToUser returns a string containing Go code to convert an instance of a types.Value (val) into the User type appropriate for t. For Go primitives, this will use ValueToNative().
|
||||
func (gen *Generator) ValueToUser(val string, t types.Type) string {
|
||||
func (gen *Generator) ValueToUser(val string, t *types.Type) string {
|
||||
rt := gen.R.Resolve(t, gen.Package)
|
||||
k := rt.Kind()
|
||||
switch k {
|
||||
@@ -248,7 +248,7 @@ func (gen *Generator) ValueToUser(val string, t types.Type) string {
|
||||
}
|
||||
|
||||
// UserZero returns a string containing Go code to create an uninitialized instance of the User type appropriate for t.
|
||||
func (gen *Generator) UserZero(t types.Type) string {
|
||||
func (gen *Generator) UserZero(t *types.Type) string {
|
||||
rt := gen.R.Resolve(t, gen.Package)
|
||||
k := rt.Kind()
|
||||
switch k {
|
||||
@@ -276,7 +276,7 @@ func (gen *Generator) UserZero(t types.Type) string {
|
||||
}
|
||||
|
||||
// ValueZero returns a string containing Go code to create an uninitialized instance of the Noms types.Value appropriate for t.
|
||||
func (gen *Generator) ValueZero(t types.Type) string {
|
||||
func (gen *Generator) ValueZero(t *types.Type) string {
|
||||
rt := gen.R.Resolve(t, gen.Package)
|
||||
k := rt.Kind()
|
||||
switch k {
|
||||
@@ -304,7 +304,7 @@ func (gen *Generator) ValueZero(t types.Type) string {
|
||||
}
|
||||
|
||||
// UserName returns the name of the User type appropriate for t, taking into account Noms types imported from other packages.
|
||||
func (gen *Generator) UserName(t types.Type) string {
|
||||
func (gen *Generator) UserName(t *types.Type) string {
|
||||
rt := gen.R.Resolve(t, gen.Package)
|
||||
k := rt.Kind()
|
||||
switch k {
|
||||
@@ -337,12 +337,12 @@ func (gen *Generator) UserName(t types.Type) string {
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (gen Generator) importedUserNameJS(t types.Type) string {
|
||||
func (gen Generator) importedUserNameJS(t *types.Type) string {
|
||||
d.Chk.True(t.HasPackageRef())
|
||||
return fmt.Sprintf("%s.%s", gen.RefToAliasName(t.PackageRef()), gen.UserName(t))
|
||||
}
|
||||
|
||||
func (gen *Generator) refToID(t types.Type) string {
|
||||
func (gen *Generator) refToID(t *types.Type) string {
|
||||
if !t.IsUnresolved() || !t.HasPackageRef() {
|
||||
return gen.UserName(t)
|
||||
}
|
||||
@@ -363,8 +363,8 @@ func (gen *Generator) RefToAliasName(r ref.Ref) string {
|
||||
return fmt.Sprintf("_%s", gen.RefToJSIdentfierName(r))
|
||||
}
|
||||
|
||||
// ToTypesType returns a string containing Go code that instantiates a types.Type instance equivalent to t.
|
||||
func (gen *Generator) ToTypesType(t types.Type, inPackageDef bool) string {
|
||||
// ToTypesType returns a string containing Go code that instantiates a *types.Type instance equivalent to t.
|
||||
func (gen *Generator) ToTypesType(t *types.Type, inPackageDef bool) string {
|
||||
if t.IsUnresolved() {
|
||||
d.Chk.True(t.HasPackageRef())
|
||||
d.Chk.True(t.HasOrdinal(), "%s does not have an ordinal set", t.Name())
|
||||
@@ -413,7 +413,7 @@ func firstToLower(s string) string {
|
||||
}
|
||||
|
||||
// ToTypeValueJS returns a string containing JS code that instantiates a Type instance equivalent to t for JavaScript.
|
||||
func (gen *Generator) ToTypeValueJS(t types.Type, inPackageDef bool, indent int) string {
|
||||
func (gen *Generator) ToTypeValueJS(t *types.Type, inPackageDef bool, indent int) string {
|
||||
if t.IsUnresolved() {
|
||||
d.Chk.True(t.HasPackageRef())
|
||||
d.Chk.True(t.HasOrdinal(), "%s does not have an ordinal set", t.Name())
|
||||
|
||||
@@ -13,7 +13,7 @@ type testResolver struct {
|
||||
deps map[ref.Ref]types.Package
|
||||
}
|
||||
|
||||
func (res *testResolver) Resolve(t types.Type, pkg *types.Package) types.Type {
|
||||
func (res *testResolver) Resolve(t *types.Type, pkg *types.Package) *types.Type {
|
||||
if !t.IsUnresolved() {
|
||||
return t
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func (res *testResolver) Resolve(t types.Type, pkg *types.Package) types.Type {
|
||||
func TestUserName(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
imported := types.NewPackage([]types.Type{
|
||||
imported := types.NewPackage([]*types.Type{
|
||||
types.MakeStructType("S1", []types.Field{
|
||||
types.Field{"f", types.MakePrimitiveType(types.BoolKind), false},
|
||||
}, []types.Field{}),
|
||||
|
||||
+26
-26
@@ -185,13 +185,13 @@ type codeGen struct {
|
||||
pkg pkg.Parsed
|
||||
deps depsMap
|
||||
written map[string]bool
|
||||
toWrite []types.Type
|
||||
toWrite []*types.Type
|
||||
generator *code.Generator
|
||||
templates *template.Template
|
||||
}
|
||||
|
||||
func newCodeGen(w io.Writer, fileID string, written map[string]bool, deps depsMap, pkg pkg.Parsed) *codeGen {
|
||||
gen := &codeGen{w, pkg, deps, written, []types.Type{}, nil, nil}
|
||||
gen := &codeGen{w, pkg, deps, written, []*types.Type{}, nil, nil}
|
||||
gen.generator = &code.Generator{
|
||||
R: gen,
|
||||
AliasNames: pkg.AliasNames,
|
||||
@@ -229,7 +229,7 @@ func (gen *codeGen) readTemplates() *template.Template {
|
||||
}).ParseGlob(glob))
|
||||
}
|
||||
|
||||
func (gen *codeGen) Resolve(t types.Type, pkg *types.Package) types.Type {
|
||||
func (gen *codeGen) Resolve(t *types.Type, pkg *types.Package) *types.Type {
|
||||
if !t.IsUnresolved() {
|
||||
return t
|
||||
}
|
||||
@@ -253,7 +253,7 @@ func (gen *codeGen) WritePackage() {
|
||||
HasTypes bool
|
||||
Dependencies []ref.Ref
|
||||
Name string
|
||||
Types []types.Type
|
||||
Types []*types.Type
|
||||
}{
|
||||
gen.pkg.Package.Ref(),
|
||||
len(pkgTypes) > 0,
|
||||
@@ -310,7 +310,7 @@ func (gen *codeGen) WriteHeader() {
|
||||
HasTypes bool
|
||||
Dependencies []ref.Ref
|
||||
Name string
|
||||
Types []types.Type
|
||||
Types []*types.Type
|
||||
ImportedJS []string
|
||||
ImportedJSTypes []string
|
||||
AliasNames map[ref.Ref]string
|
||||
@@ -329,7 +329,7 @@ func (gen *codeGen) WriteHeader() {
|
||||
d.Exp.NoError(err)
|
||||
}
|
||||
|
||||
func (gen *codeGen) shouldBeWritten(t types.Type) bool {
|
||||
func (gen *codeGen) shouldBeWritten(t *types.Type) bool {
|
||||
if t.IsUnresolved() {
|
||||
return false
|
||||
}
|
||||
@@ -341,7 +341,7 @@ func (gen *codeGen) shouldBeWritten(t types.Type) bool {
|
||||
return !gen.written[gen.generator.UserName(t)]
|
||||
}
|
||||
|
||||
func (gen *codeGen) writeTopLevel(t types.Type, ordinal int) {
|
||||
func (gen *codeGen) writeTopLevel(t *types.Type, ordinal int) {
|
||||
switch t.Kind() {
|
||||
case types.StructKind:
|
||||
gen.writeStruct(t, ordinal)
|
||||
@@ -351,7 +351,7 @@ func (gen *codeGen) writeTopLevel(t types.Type, ordinal int) {
|
||||
}
|
||||
|
||||
// write generates the code for the given type.
|
||||
func (gen *codeGen) write(t types.Type) {
|
||||
func (gen *codeGen) write(t *types.Type) {
|
||||
if !gen.shouldBeWritten(t) {
|
||||
return
|
||||
}
|
||||
@@ -372,31 +372,31 @@ func (gen *codeGen) write(t types.Type) {
|
||||
}
|
||||
}
|
||||
|
||||
func (gen *codeGen) writeLater(t types.Type) {
|
||||
func (gen *codeGen) writeLater(t *types.Type) {
|
||||
if !gen.shouldBeWritten(t) {
|
||||
return
|
||||
}
|
||||
gen.toWrite = append(gen.toWrite, t)
|
||||
}
|
||||
|
||||
func (gen *codeGen) writeTemplate(tmpl string, t types.Type, data interface{}) {
|
||||
func (gen *codeGen) writeTemplate(tmpl string, t *types.Type, data interface{}) {
|
||||
err := gen.templates.ExecuteTemplate(gen.w, tmpl, data)
|
||||
d.Exp.NoError(err)
|
||||
gen.written[gen.generator.UserName(t)] = true
|
||||
}
|
||||
|
||||
func (gen *codeGen) writeStruct(t types.Type, ordinal int) {
|
||||
func (gen *codeGen) writeStruct(t *types.Type, ordinal int) {
|
||||
d.Chk.True(ordinal >= 0)
|
||||
desc := t.Desc.(types.StructDesc)
|
||||
data := struct {
|
||||
PackageRef ref.Ref
|
||||
Name string
|
||||
Type types.Type
|
||||
Type *types.Type
|
||||
Ordinal int
|
||||
Fields []types.Field
|
||||
Choices []types.Field
|
||||
HasUnion bool
|
||||
UnionZeroType types.Type
|
||||
UnionZeroType *types.Type
|
||||
}{
|
||||
gen.pkg.Package.Ref(),
|
||||
gen.generator.UserName(t),
|
||||
@@ -423,13 +423,13 @@ func (gen *codeGen) writeStruct(t types.Type, ordinal int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (gen *codeGen) writeList(t types.Type) {
|
||||
func (gen *codeGen) writeList(t *types.Type) {
|
||||
elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
|
||||
data := struct {
|
||||
PackageRef ref.Ref
|
||||
Name string
|
||||
Type types.Type
|
||||
ElemType types.Type
|
||||
Type *types.Type
|
||||
ElemType *types.Type
|
||||
}{
|
||||
gen.pkg.Package.Ref(),
|
||||
gen.generator.UserName(t),
|
||||
@@ -440,14 +440,14 @@ func (gen *codeGen) writeList(t types.Type) {
|
||||
gen.writeLater(elemTypes[0])
|
||||
}
|
||||
|
||||
func (gen *codeGen) writeMap(t types.Type) {
|
||||
func (gen *codeGen) writeMap(t *types.Type) {
|
||||
elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
|
||||
data := struct {
|
||||
PackageRef ref.Ref
|
||||
Name string
|
||||
Type types.Type
|
||||
KeyType types.Type
|
||||
ValueType types.Type
|
||||
Type *types.Type
|
||||
KeyType *types.Type
|
||||
ValueType *types.Type
|
||||
}{
|
||||
gen.pkg.Package.Ref(),
|
||||
gen.generator.UserName(t),
|
||||
@@ -460,13 +460,13 @@ func (gen *codeGen) writeMap(t types.Type) {
|
||||
gen.writeLater(elemTypes[1])
|
||||
}
|
||||
|
||||
func (gen *codeGen) writeRef(t types.Type) {
|
||||
func (gen *codeGen) writeRef(t *types.Type) {
|
||||
elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
|
||||
data := struct {
|
||||
PackageRef ref.Ref
|
||||
Name string
|
||||
Type types.Type
|
||||
ElemType types.Type
|
||||
Type *types.Type
|
||||
ElemType *types.Type
|
||||
}{
|
||||
gen.pkg.Package.Ref(),
|
||||
gen.generator.UserName(t),
|
||||
@@ -477,13 +477,13 @@ func (gen *codeGen) writeRef(t types.Type) {
|
||||
gen.writeLater(elemTypes[0])
|
||||
}
|
||||
|
||||
func (gen *codeGen) writeSet(t types.Type) {
|
||||
func (gen *codeGen) writeSet(t *types.Type) {
|
||||
elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
|
||||
data := struct {
|
||||
PackageRef ref.Ref
|
||||
Name string
|
||||
Type types.Type
|
||||
ElemType types.Type
|
||||
Type *types.Type
|
||||
ElemType *types.Type
|
||||
}{
|
||||
gen.pkg.Package.Ref(),
|
||||
gen.generator.UserName(t),
|
||||
|
||||
@@ -70,13 +70,13 @@ func TestSkipDuplicateTypes(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
leaf1 := types.NewPackage([]types.Type{
|
||||
leaf1 := types.NewPackage([]*types.Type{
|
||||
types.MakeStructType("S1", []types.Field{
|
||||
types.Field{"f", types.MakeCompoundType(types.ListKind, types.MakePrimitiveType(types.Uint16Kind)), false},
|
||||
types.Field{"e", types.MakeType(ref.Ref{}, 0), false},
|
||||
}, []types.Field{}),
|
||||
}, []ref.Ref{})
|
||||
leaf2 := types.NewPackage([]types.Type{
|
||||
leaf2 := types.NewPackage([]*types.Type{
|
||||
types.MakeStructType("S2", []types.Field{
|
||||
types.Field{"f", types.MakeCompoundType(types.ListKind, types.MakePrimitiveType(types.Uint16Kind)), false},
|
||||
}, []types.Field{}),
|
||||
|
||||
+10
-10
@@ -14,9 +14,9 @@ type namespaceIdent struct {
|
||||
|
||||
Package <- _ dd:Definition+ _ EOF {
|
||||
aliases := map[string]string{}
|
||||
usings := []types.Type{}
|
||||
usings := []*types.Type{}
|
||||
seenTypes := map[string]bool{}
|
||||
orderedTypes := []types.Type{}
|
||||
orderedTypes := []*types.Type{}
|
||||
for _, d := range dd.([]interface{}) {
|
||||
switch d := d.(type) {
|
||||
default:
|
||||
@@ -26,7 +26,7 @@ Package <- _ dd:Definition+ _ EOF {
|
||||
return nil, fmt.Errorf("Redefinition of " + d.Name)
|
||||
}
|
||||
aliases[d.Name] = d.Target
|
||||
case types.Type:
|
||||
case *types.Type:
|
||||
switch d.Kind() {
|
||||
default:
|
||||
return nil, fmt.Errorf("%v can't be defined at the top-level", d)
|
||||
@@ -109,16 +109,16 @@ Union <- `union` _ `{` _ u:UnionField+ _ `}` _ {
|
||||
}
|
||||
|
||||
Field <- i:Ident _ `:` _ o:(`optional` _)? t:Type _ {
|
||||
return types.Field{i.(string), t.(types.Type), o != nil}, nil
|
||||
return types.Field{i.(string), t.(*types.Type), o != nil}, nil
|
||||
}
|
||||
|
||||
UnionField <- i:Ident _ `:` _ t:Type _ {
|
||||
return types.Field{i.(string), t.(types.Type), false}, nil
|
||||
return types.Field{i.(string), t.(*types.Type), false}, nil
|
||||
}
|
||||
|
||||
Type <- t:(PrimitiveType / CompoundType / Union / NamespaceIdent) {
|
||||
switch t := t.(type) {
|
||||
case types.Type:
|
||||
case *types.Type:
|
||||
return t, nil
|
||||
case []types.Field:
|
||||
return types.MakeStructType("", nil, t), nil
|
||||
@@ -130,13 +130,13 @@ Type <- t:(PrimitiveType / CompoundType / Union / NamespaceIdent) {
|
||||
}
|
||||
|
||||
CompoundType <- `List` _ `<` _ t:Type _ `>` _ {
|
||||
return types.MakeCompoundType(types.ListKind, t.(types.Type)), nil
|
||||
return types.MakeCompoundType(types.ListKind, t.(*types.Type)), nil
|
||||
} / `Map` _ `<` _ k:Type _ `,` _ v:Type _ `>` _ {
|
||||
return types.MakeCompoundType(types.MapKind, k.(types.Type), v.(types.Type)), nil
|
||||
return types.MakeCompoundType(types.MapKind, k.(*types.Type), v.(*types.Type)), nil
|
||||
} / `Set` _ `<` _ t:Type _ `>` _ {
|
||||
return types.MakeCompoundType(types.SetKind, t.(types.Type)), nil
|
||||
return types.MakeCompoundType(types.SetKind, t.(*types.Type)), nil
|
||||
} / `Ref` _ `<` _ t:Type _ `>` _ {
|
||||
return types.MakeCompoundType(types.RefKind, t.(types.Type)), nil
|
||||
return types.MakeCompoundType(types.RefKind, t.(*types.Type)), nil
|
||||
}
|
||||
|
||||
PrimitiveType <- p:(`Uint64` / `Uint32` / `Uint16` / `Uint8` / `Int64` / `Int32` / `Int16` / `Int8` / `Float64` / `Float32` / `Bool` / `String` / `Blob` / `Value` / `Type`) {
|
||||
|
||||
+251
-251
File diff suppressed because it is too large
Load Diff
@@ -35,7 +35,7 @@ func (suite *ImportTestSuite) SetupTest() {
|
||||
types.Field{"b", types.MakePrimitiveType(types.BoolKind), false},
|
||||
types.Field{"i", types.MakePrimitiveType(types.Int8Kind), false},
|
||||
})
|
||||
suite.nested = types.NewPackage([]types.Type{ns}, []ref.Ref{})
|
||||
suite.nested = types.NewPackage([]*types.Type{ns}, []ref.Ref{})
|
||||
suite.nestedRef = suite.vrw.WriteValue(suite.nested).TargetRef()
|
||||
|
||||
fs := types.MakeStructType("ForeignStruct", []types.Field{
|
||||
@@ -43,7 +43,7 @@ func (suite *ImportTestSuite) SetupTest() {
|
||||
types.Field{"n", types.MakeType(suite.nestedRef, 0), false},
|
||||
},
|
||||
[]types.Field{})
|
||||
suite.imported = types.NewPackage([]types.Type{fs}, []ref.Ref{suite.nestedRef})
|
||||
suite.imported = types.NewPackage([]*types.Type{fs}, []ref.Ref{suite.nestedRef})
|
||||
suite.importRef = suite.vrw.WriteValue(suite.imported).TargetRef()
|
||||
}
|
||||
|
||||
@@ -73,13 +73,13 @@ func (suite *ImportTestSuite) TestDetectFreeVariable() {
|
||||
},
|
||||
[]types.Field{})
|
||||
suite.Panics(func() {
|
||||
inter := intermediate{Types: []types.Type{ls}}
|
||||
inter := intermediate{Types: []*types.Type{ls}}
|
||||
resolveLocalOrdinals(&inter)
|
||||
})
|
||||
}
|
||||
|
||||
func (suite *ImportTestSuite) TestImports() {
|
||||
find := func(n string, typ types.Type) types.Field {
|
||||
find := func(n string, typ *types.Type) types.Field {
|
||||
suite.Equal(types.StructKind, typ.Kind())
|
||||
for _, f := range typ.Desc.(types.StructDesc).Fields {
|
||||
if f.Name == n {
|
||||
@@ -89,7 +89,7 @@ func (suite *ImportTestSuite) TestImports() {
|
||||
suite.Fail("Could not find field", "%s not present", n)
|
||||
return types.Field{}
|
||||
}
|
||||
findChoice := func(n string, typ types.Type) types.Field {
|
||||
findChoice := func(n string, typ *types.Type) types.Field {
|
||||
suite.Equal(types.StructKind, typ.Kind())
|
||||
for _, f := range typ.Desc.(types.StructDesc).Union {
|
||||
if f.Name == n {
|
||||
|
||||
+13
-13
@@ -13,7 +13,7 @@ import (
|
||||
type Parsed struct {
|
||||
types.Package
|
||||
Name string
|
||||
UsingDeclarations []types.Type
|
||||
UsingDeclarations []*types.Type
|
||||
AliasNames map[ref.Ref]string
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func ParseNomDL(packageName string, r io.Reader, includePath string, vrw types.V
|
||||
|
||||
pkg := types.NewPackage(i.Types, deps)
|
||||
|
||||
usingDeclarations := make([]types.Type, len(i.UsingDeclarations))
|
||||
usingDeclarations := make([]*types.Type, len(i.UsingDeclarations))
|
||||
for idx, t := range i.UsingDeclarations {
|
||||
usingDeclarations[idx] = types.FixupType(t, &pkg)
|
||||
}
|
||||
@@ -51,8 +51,8 @@ func ParseNomDL(packageName string, r io.Reader, includePath string, vrw types.V
|
||||
type intermediate struct {
|
||||
Name string
|
||||
Aliases map[string]string
|
||||
UsingDeclarations []types.Type
|
||||
Types []types.Type
|
||||
UsingDeclarations []*types.Type
|
||||
Types []*types.Type
|
||||
}
|
||||
|
||||
func runParser(logname string, r io.Reader) intermediate {
|
||||
@@ -62,14 +62,14 @@ func runParser(logname string, r io.Reader) intermediate {
|
||||
}
|
||||
|
||||
func resolveLocalOrdinals(p *intermediate) {
|
||||
var rec func(t types.Type) types.Type
|
||||
var rec func(t *types.Type) *types.Type
|
||||
resolveFields := func(fields []types.Field) {
|
||||
for idx, f := range fields {
|
||||
f.T = rec(f.T)
|
||||
fields[idx] = f
|
||||
}
|
||||
}
|
||||
rec = func(t types.Type) types.Type {
|
||||
rec = func(t *types.Type) *types.Type {
|
||||
if t.IsUnresolved() {
|
||||
if t.Namespace() == "" && !t.HasOrdinal() {
|
||||
ordinal := indexOf(t, p.Types)
|
||||
@@ -101,7 +101,7 @@ func resolveLocalOrdinals(p *intermediate) {
|
||||
}
|
||||
}
|
||||
|
||||
func indexOf(t types.Type, ts []types.Type) int16 {
|
||||
func indexOf(t *types.Type, ts []*types.Type) int16 {
|
||||
for i, tt := range ts {
|
||||
if tt.Name() == t.Name() && tt.Namespace() == "" {
|
||||
return int16(i)
|
||||
@@ -111,7 +111,7 @@ func indexOf(t types.Type, ts []types.Type) int16 {
|
||||
}
|
||||
|
||||
func resolveNamespaces(p *intermediate, aliases map[string]ref.Ref, deps map[ref.Ref]types.Package) {
|
||||
var rec func(t types.Type) types.Type
|
||||
var rec func(t *types.Type) *types.Type
|
||||
resolveFields := func(fields []types.Field) {
|
||||
for idx, f := range fields {
|
||||
if f.T.IsUnresolved() {
|
||||
@@ -127,7 +127,7 @@ func resolveNamespaces(p *intermediate, aliases map[string]ref.Ref, deps map[ref
|
||||
fields[idx] = f
|
||||
}
|
||||
}
|
||||
rec = func(t types.Type) types.Type {
|
||||
rec = func(t *types.Type) *types.Type {
|
||||
if t.IsUnresolved() {
|
||||
if p.checkLocal(t) {
|
||||
return t
|
||||
@@ -162,7 +162,7 @@ func resolveNamespaces(p *intermediate, aliases map[string]ref.Ref, deps map[ref
|
||||
}
|
||||
}
|
||||
|
||||
func (i *intermediate) checkLocal(t types.Type) bool {
|
||||
func (i *intermediate) checkLocal(t *types.Type) bool {
|
||||
if t.Namespace() == "" {
|
||||
d.Chk.True(t.HasOrdinal(), "Invalid local reference")
|
||||
return true
|
||||
@@ -170,7 +170,7 @@ func (i *intermediate) checkLocal(t types.Type) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func resolveNamespace(t types.Type, aliases map[string]ref.Ref, deps map[ref.Ref]types.Package) types.Type {
|
||||
func resolveNamespace(t *types.Type, aliases map[string]ref.Ref, deps map[ref.Ref]types.Package) *types.Type {
|
||||
pkgRef, ok := aliases[t.Namespace()]
|
||||
d.Exp.True(ok, "Could not find import aliased to %s", t.Namespace())
|
||||
d.Chk.NotEqual("", t.Name())
|
||||
@@ -181,9 +181,9 @@ func resolveNamespace(t types.Type, aliases map[string]ref.Ref, deps map[ref.Ref
|
||||
}
|
||||
|
||||
// expandStruct takes a struct definition and expands the internal structs created for unions.
|
||||
func expandStruct(t types.Type, ordinal int) []types.Type {
|
||||
func expandStruct(t *types.Type, ordinal int) []*types.Type {
|
||||
d.Chk.Equal(types.StructKind, t.Kind())
|
||||
ts := []types.Type{t}
|
||||
ts := []*types.Type{t}
|
||||
ordinal++
|
||||
|
||||
doFields := func(fields []types.Field) []types.Field {
|
||||
|
||||
@@ -267,14 +267,14 @@ type testField struct {
|
||||
}
|
||||
|
||||
func (t testField) toField() types.Field {
|
||||
return types.Field{t.Name, t.D.(types.Type), t.Optional}
|
||||
return types.Field{t.Name, t.D.(*types.Type), t.Optional}
|
||||
}
|
||||
|
||||
type describable interface {
|
||||
Describe() string
|
||||
}
|
||||
|
||||
func (suite *ParsedResultTestSuite) findTypeByName(n string, ts []types.Type) types.Type {
|
||||
func (suite *ParsedResultTestSuite) findTypeByName(n string, ts []*types.Type) *types.Type {
|
||||
for _, t := range ts {
|
||||
if n == t.Name() {
|
||||
return t
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package types
|
||||
|
||||
import "github.com/attic-labs/noms/d"
|
||||
|
||||
func assertType(t Type, v ...Value) {
|
||||
func assertType(t *Type, v ...Value) {
|
||||
if t.Kind() != ValueKind {
|
||||
for _, v := range v {
|
||||
d.Chk.True(t.Equals(v.Type()), "Invalid type. Expected: %s, found: %s", t.Describe(), v.Type().Describe())
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ func (bl blobLeaf) ChildValues() []Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bl blobLeaf) Type() Type {
|
||||
func (bl blobLeaf) Type() *Type {
|
||||
return typeForBlob
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ func newCompoundBlob(tuples metaSequenceData, vr ValueReader) compoundBlob {
|
||||
return buildCompoundBlob(tuples, typeForBlob, vr).(compoundBlob)
|
||||
}
|
||||
|
||||
func buildCompoundBlob(tuples metaSequenceData, t Type, vr ValueReader) Value {
|
||||
func buildCompoundBlob(tuples metaSequenceData, t *Type, vr ValueReader) Value {
|
||||
d.Chk.True(t.Equals(typeForBlob))
|
||||
return compoundBlob{metaSequenceObject{tuples, typeForBlob}, tuples.uint64ValuesSum(), &ref.Ref{}, vr}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ type compoundList struct {
|
||||
vr ValueReader
|
||||
}
|
||||
|
||||
func buildCompoundList(tuples metaSequenceData, t Type, vr ValueReader) Value {
|
||||
func buildCompoundList(tuples metaSequenceData, t *Type, vr ValueReader) Value {
|
||||
cl := compoundList{metaSequenceObject{tuples, t}, tuples.uint64ValuesSum(), &ref.Ref{}, vr}
|
||||
return valueFromType(cl, t)
|
||||
}
|
||||
@@ -146,7 +146,7 @@ func (cl compoundList) MapP(concurrency int, mf MapFunc) []interface{} {
|
||||
return results
|
||||
}
|
||||
|
||||
func (cl compoundList) elemType() Type {
|
||||
func (cl compoundList) elemType() *Type {
|
||||
return cl.Type().Desc.(CompoundDesc).ElemTypes[0]
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ func newListLeafBoundaryChecker() boundaryChecker {
|
||||
|
||||
// If |sink| is not nil, chunks will be eagerly written as they're created. Otherwise they are
|
||||
// written when the root is written.
|
||||
func makeListLeafChunkFn(t Type, sink ValueWriter) makeChunkFn {
|
||||
func makeListLeafChunkFn(t *Type, sink ValueWriter) makeChunkFn {
|
||||
return func(items []sequenceItem) (sequenceItem, Value) {
|
||||
values := make([]Value, len(items))
|
||||
|
||||
|
||||
@@ -633,7 +633,7 @@ func TestCompoundListRefOfStructFirstNNumbers(t *testing.T) {
|
||||
structTypeDef := MakeStructType("num", []Field{
|
||||
Field{"n", MakePrimitiveType(Int64Kind), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{structTypeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{structTypeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
structType := MakeType(pkgRef, 0)
|
||||
refOfTypeStructType := MakeCompoundType(RefKind, structType)
|
||||
|
||||
@@ -17,7 +17,7 @@ type compoundMap struct {
|
||||
vr ValueReader
|
||||
}
|
||||
|
||||
func buildCompoundMap(tuples metaSequenceData, t Type, vr ValueReader) Value {
|
||||
func buildCompoundMap(tuples metaSequenceData, t *Type, vr ValueReader) Value {
|
||||
cm := compoundMap{metaSequenceObject{tuples, t}, tuples.numLeavesSum(), &ref.Ref{}, vr}
|
||||
return valueFromType(cm, t)
|
||||
}
|
||||
@@ -159,6 +159,6 @@ func (cm compoundMap) IterAll(cb mapIterAllCallback) {
|
||||
})
|
||||
}
|
||||
|
||||
func (cm compoundMap) elemTypes() []Type {
|
||||
func (cm compoundMap) elemTypes() []*Type {
|
||||
return cm.Type().Desc.(CompoundDesc).ElemTypes
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
type testMap struct {
|
||||
entries []mapEntry
|
||||
less testMapLessFn
|
||||
tr Type
|
||||
tr *Type
|
||||
knownBadKey Value
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func (tm testMap) toCompoundMap() compoundMap {
|
||||
|
||||
type testMapGenFn func(v Int64) Value
|
||||
|
||||
func newTestMap(length int, gen testMapGenFn, less testMapLessFn, tr Type) testMap {
|
||||
func newTestMap(length int, gen testMapGenFn, less testMapLessFn, tr *Type) testMap {
|
||||
s := rand.NewSource(4242)
|
||||
used := map[int64]bool{}
|
||||
|
||||
@@ -370,7 +370,7 @@ func TestCompoundMapRefOfStructFirstNNumbers(t *testing.T) {
|
||||
structTypeDef := MakeStructType("num", []Field{
|
||||
Field{"n", MakePrimitiveType(Int64Kind), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{structTypeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{structTypeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
structType := MakeType(pkgRef, 0)
|
||||
refOfTypeStructType := MakeRefType(structType)
|
||||
|
||||
@@ -18,7 +18,7 @@ type compoundSet struct {
|
||||
vr ValueReader
|
||||
}
|
||||
|
||||
func buildCompoundSet(tuples metaSequenceData, t Type, vr ValueReader) Value {
|
||||
func buildCompoundSet(tuples metaSequenceData, t *Type, vr ValueReader) Value {
|
||||
s := compoundSet{metaSequenceObject{tuples, t}, tuples.numLeavesSum(), &ref.Ref{}, vr}
|
||||
return valueFromType(s, t)
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func (cs compoundSet) IterAllP(concurrency int, f setIterAllCallback) {
|
||||
})
|
||||
}
|
||||
|
||||
func (cs compoundSet) elemType() Type {
|
||||
func (cs compoundSet) elemType() *Type {
|
||||
return cs.t.Desc.(CompoundDesc).ElemTypes[0]
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
type testSet struct {
|
||||
values []Value
|
||||
less testSetLessFn
|
||||
tr Type
|
||||
tr *Type
|
||||
}
|
||||
|
||||
type testSetLessFn func(x, y Value) bool
|
||||
@@ -42,7 +42,7 @@ func (ts testSet) toCompoundSet() compoundSet {
|
||||
|
||||
type testSetGenFn func(v Int64) Value
|
||||
|
||||
func newTestSet(length int, gen testSetGenFn, less testSetLessFn, tr Type) testSet {
|
||||
func newTestSet(length int, gen testSetGenFn, less testSetLessFn, tr *Type) testSet {
|
||||
s := rand.NewSource(4242)
|
||||
used := map[int64]bool{}
|
||||
|
||||
@@ -367,7 +367,7 @@ func TestCompoundSetRefOfStructFirstNNumbers(t *testing.T) {
|
||||
structTypeDef := MakeStructType("num", []Field{
|
||||
Field{"n", MakePrimitiveType(Int64Kind), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{structTypeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{structTypeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
structType := MakeType(pkgRef, 0)
|
||||
refOfTypeStructType := MakeCompoundType(RefKind, structType)
|
||||
|
||||
+16
-16
@@ -75,7 +75,7 @@ func (r *jsonArrayReader) readRef() ref.Ref {
|
||||
return ref.Parse(s)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readTypeAsTag() Type {
|
||||
func (r *jsonArrayReader) readTypeAsTag() *Type {
|
||||
kind := r.readKind()
|
||||
switch kind {
|
||||
case ListKind, SetKind, RefKind:
|
||||
@@ -101,7 +101,7 @@ func (r *jsonArrayReader) readTypeAsTag() Type {
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readBlob(t Type) Value {
|
||||
func (r *jsonArrayReader) readBlob(t *Type) Value {
|
||||
s := r.readString()
|
||||
decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(s))
|
||||
b, err := ioutil.ReadAll(decoder)
|
||||
@@ -109,7 +109,7 @@ func (r *jsonArrayReader) readBlob(t Type) Value {
|
||||
return newBlobLeaf(b)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readList(t Type, pkg *Package) Value {
|
||||
func (r *jsonArrayReader) readList(t *Type, pkg *Package) Value {
|
||||
desc := t.Desc.(CompoundDesc)
|
||||
data := []Value{}
|
||||
elemType := desc.ElemTypes[0]
|
||||
@@ -121,7 +121,7 @@ func (r *jsonArrayReader) readList(t Type, pkg *Package) Value {
|
||||
return valueFromType(newListLeaf(t, data...), t)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readSet(t Type, pkg *Package) Value {
|
||||
func (r *jsonArrayReader) readSet(t *Type, pkg *Package) Value {
|
||||
desc := t.Desc.(CompoundDesc)
|
||||
data := setData{}
|
||||
elemType := desc.ElemTypes[0]
|
||||
@@ -133,7 +133,7 @@ func (r *jsonArrayReader) readSet(t Type, pkg *Package) Value {
|
||||
return valueFromType(newSetLeaf(t, data...), t)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readMap(t Type, pkg *Package) Value {
|
||||
func (r *jsonArrayReader) readMap(t *Type, pkg *Package) Value {
|
||||
desc := t.Desc.(CompoundDesc)
|
||||
data := mapData{}
|
||||
keyType := desc.ElemTypes[0]
|
||||
@@ -148,7 +148,7 @@ func (r *jsonArrayReader) readMap(t Type, pkg *Package) Value {
|
||||
return valueFromType(newMapLeaf(t, data...), t)
|
||||
}
|
||||
|
||||
func indexTypeForMetaSequence(t Type) Type {
|
||||
func indexTypeForMetaSequence(t *Type) *Type {
|
||||
switch t.Kind() {
|
||||
default:
|
||||
panic(fmt.Sprintf("Unknown type used for metaSequence: %s", t.Describe()))
|
||||
@@ -163,7 +163,7 @@ func indexTypeForMetaSequence(t Type) Type {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) maybeReadMetaSequence(t Type, pkg *Package) (Value, bool) {
|
||||
func (r *jsonArrayReader) maybeReadMetaSequence(t *Type, pkg *Package) (Value, bool) {
|
||||
if !r.read().(bool) {
|
||||
return nil, false
|
||||
}
|
||||
@@ -181,9 +181,9 @@ func (r *jsonArrayReader) maybeReadMetaSequence(t Type, pkg *Package) (Value, bo
|
||||
return newMetaSequenceFromData(data, t, r.vr), true
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readPackage(t Type, pkg *Package) Value {
|
||||
func (r *jsonArrayReader) readPackage(t *Type, pkg *Package) Value {
|
||||
r2 := newJsonArrayReader(r.readArray(), r.vr)
|
||||
types := []Type{}
|
||||
types := []*Type{}
|
||||
for !r2.atEnd() {
|
||||
types = append(types, r2.readTypeAsValue(pkg))
|
||||
}
|
||||
@@ -197,7 +197,7 @@ func (r *jsonArrayReader) readPackage(t Type, pkg *Package) Value {
|
||||
return NewPackage(types, deps)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readRefValue(t Type) Value {
|
||||
func (r *jsonArrayReader) readRefValue(t *Type) Value {
|
||||
ref := r.readRef()
|
||||
return refFromType(ref, t)
|
||||
}
|
||||
@@ -207,7 +207,7 @@ func (r *jsonArrayReader) readTopLevelValue() Value {
|
||||
return r.readValueWithoutTag(t, nil)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readValueWithoutTag(t Type, pkg *Package) Value {
|
||||
func (r *jsonArrayReader) readValueWithoutTag(t *Type, pkg *Package) Value {
|
||||
switch t.Kind() {
|
||||
case BlobKind:
|
||||
if ms, ok := r.maybeReadMetaSequence(t, pkg); ok {
|
||||
@@ -278,12 +278,12 @@ func (r *jsonArrayReader) readValueWithoutTag(t Type, pkg *Package) Value {
|
||||
panic("not reachable")
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readTypeKindToValue(t Type, pkg *Package) Value {
|
||||
func (r *jsonArrayReader) readTypeKindToValue(t *Type, pkg *Package) Value {
|
||||
d.Chk.IsType(PrimitiveDesc(0), t.Desc)
|
||||
return r.readTypeAsValue(pkg)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readUnresolvedKindToValue(t Type, pkg *Package) Value {
|
||||
func (r *jsonArrayReader) readUnresolvedKindToValue(t *Type, pkg *Package) Value {
|
||||
// When we have a struct referencing another struct in the same package the package ref is empty. In that case we use the package that is passed into this function.
|
||||
d.Chk.True(t.IsUnresolved())
|
||||
pkgRef := t.PackageRef()
|
||||
@@ -305,12 +305,12 @@ func (r *jsonArrayReader) readUnresolvedKindToValue(t Type, pkg *Package) Value
|
||||
return r.readStruct(typeDef, t, pkg)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readTypeAsValue(pkg *Package) Type {
|
||||
func (r *jsonArrayReader) readTypeAsValue(pkg *Package) *Type {
|
||||
k := r.readKind()
|
||||
switch k {
|
||||
case ListKind, MapKind, RefKind, SetKind:
|
||||
r2 := newJsonArrayReader(r.readArray(), r.vr)
|
||||
elemTypes := []Type{}
|
||||
elemTypes := []*Type{}
|
||||
for !r2.atEnd() {
|
||||
t := r2.readTypeAsValue(pkg)
|
||||
elemTypes = append(elemTypes, t)
|
||||
@@ -353,7 +353,7 @@ func (r *jsonArrayReader) readTypeAsValue(pkg *Package) Type {
|
||||
return MakePrimitiveType(k)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readStruct(typeDef, typ Type, pkg *Package) Value {
|
||||
func (r *jsonArrayReader) readStruct(typeDef, typ *Type, pkg *Package) Value {
|
||||
// We've read `[StructKind, sha1, name` at this point
|
||||
values := []Value{}
|
||||
desc := typeDef.Desc.(StructDesc)
|
||||
|
||||
@@ -37,7 +37,7 @@ func parseJson(s string, vs ...interface{}) (v []interface{}) {
|
||||
func TestReadTypeAsTag(t *testing.T) {
|
||||
cs := NewTestValueStore()
|
||||
|
||||
test := func(expected Type, s string, vs ...interface{}) {
|
||||
test := func(expected *Type, s string, vs ...interface{}) {
|
||||
a := parseJson(s, vs...)
|
||||
r := newJsonArrayReader(a, cs)
|
||||
tr := r.readTypeAsTag()
|
||||
@@ -250,7 +250,7 @@ func TestReadStruct(t *testing.T) {
|
||||
Field{"s", MakePrimitiveType(StringKind), false},
|
||||
Field{"b", MakePrimitiveType(BoolKind), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typ}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typ}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
|
||||
a := parseJson(`[%d, "%s", "0", "42", "hi", true]`, UnresolvedKind, pkgRef.String())
|
||||
@@ -272,7 +272,7 @@ func TestReadStructUnion(t *testing.T) {
|
||||
Field{"b", MakePrimitiveType(BoolKind), false},
|
||||
Field{"s", MakePrimitiveType(StringKind), false},
|
||||
})
|
||||
pkg := NewPackage([]Type{typ}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typ}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
|
||||
a := parseJson(`[%d, "%s", "0", "42", "1", "hi"]`, UnresolvedKind, pkgRef.String())
|
||||
@@ -302,7 +302,7 @@ func TestReadStructOptional(t *testing.T) {
|
||||
Field{"s", MakePrimitiveType(StringKind), true},
|
||||
Field{"b", MakePrimitiveType(BoolKind), true},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typ}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typ}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
|
||||
a := parseJson(`[%d, "%s", "0", "42", false, true, false]`, UnresolvedKind, pkgRef.String())
|
||||
@@ -333,7 +333,7 @@ func TestReadStructWithList(t *testing.T) {
|
||||
Field{"l", MakeCompoundType(ListKind, MakePrimitiveType(Int32Kind)), false},
|
||||
Field{"s", MakePrimitiveType(StringKind), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typ}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typ}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
|
||||
a := parseJson(`[%d, "%s", "0", true, false, ["0", "1", "2"], "hi"]`, UnresolvedKind, pkgRef.String())
|
||||
@@ -362,7 +362,7 @@ func TestReadStructWithValue(t *testing.T) {
|
||||
Field{"v", MakePrimitiveType(ValueKind), false},
|
||||
Field{"s", MakePrimitiveType(StringKind), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typ}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typ}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
|
||||
a := parseJson(`[%d, "%s", "0", true, %d, "42", "hi"]`, UnresolvedKind, pkgRef.String(), Uint8Kind)
|
||||
@@ -389,7 +389,7 @@ func TestReadValueStruct(t *testing.T) {
|
||||
Field{"s", MakePrimitiveType(StringKind), false},
|
||||
Field{"b", MakePrimitiveType(BoolKind), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typ}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typ}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
|
||||
a := parseJson(`[%d, %d, "%s", "0", "42", "hi", true]`, ValueKind, UnresolvedKind, pkgRef.String())
|
||||
@@ -436,7 +436,7 @@ func TestReadStructWithBlob(t *testing.T) {
|
||||
typ := MakeStructType("A5", []Field{
|
||||
Field{"b", MakePrimitiveType(BlobKind), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typ}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typ}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
|
||||
a := parseJson(`[%d, "%s", "0", false, "AAE="]`, UnresolvedKind, pkgRef.String())
|
||||
@@ -451,7 +451,7 @@ func TestReadTypeValue(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
cs := NewTestValueStore()
|
||||
|
||||
test := func(expected Type, json string, vs ...interface{}) {
|
||||
test := func(expected *Type, json string, vs ...interface{}) {
|
||||
a := parseJson(json, vs...)
|
||||
r := newJsonArrayReader(a, cs)
|
||||
tr := r.readTopLevelValue()
|
||||
@@ -494,7 +494,7 @@ func TestReadPackage2(t *testing.T) {
|
||||
|
||||
rr := ref.Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d")
|
||||
setTref := MakeCompoundType(SetKind, MakePrimitiveType(Uint32Kind))
|
||||
pkg := NewPackage([]Type{setTref}, []ref.Ref{rr})
|
||||
pkg := NewPackage([]*Type{setTref}, []ref.Ref{rr})
|
||||
|
||||
a := []interface{}{float64(PackageKind), []interface{}{float64(SetKind), []interface{}{float64(Uint32Kind)}}, []interface{}{rr.String()}}
|
||||
r := newJsonArrayReader(a, cs)
|
||||
@@ -506,7 +506,7 @@ func TestReadPackageThroughChunkSource(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
cs := NewTestValueStore()
|
||||
|
||||
pkg := NewPackage([]Type{
|
||||
pkg := NewPackage([]*Type{
|
||||
MakeStructType("S", []Field{
|
||||
Field{"X", MakePrimitiveType(Int32Kind), false},
|
||||
}, []Field{}),
|
||||
|
||||
@@ -135,7 +135,7 @@ func (w *hrsWriter) Write(v Value) {
|
||||
w.write("}")
|
||||
|
||||
case TypeKind:
|
||||
w.writeTypeAsValue(v.(Type))
|
||||
w.writeTypeAsValue(v.(*Type))
|
||||
|
||||
case UnresolvedKind:
|
||||
w.writeUnresolved(v, true)
|
||||
@@ -218,7 +218,7 @@ func (w *hrsWriter) WriteTagged(v Value) {
|
||||
}
|
||||
}
|
||||
|
||||
func (w *hrsWriter) writeTypeAsValue(t Type) {
|
||||
func (w *hrsWriter) writeTypeAsValue(t *Type) {
|
||||
switch t.Kind() {
|
||||
case BlobKind, BoolKind, Float32Kind, Float64Kind, Int16Kind, Int32Kind, Int64Kind, Int8Kind, StringKind, TypeKind, Uint16Kind, Uint32Kind, Uint64Kind, Uint8Kind, ValueKind, PackageKind:
|
||||
w.write(KindToString[t.Kind()])
|
||||
@@ -272,7 +272,7 @@ func (w *hrsWriter) writeTypeAsValue(t Type) {
|
||||
}
|
||||
}
|
||||
|
||||
func (w *hrsWriter) writeUnresolvedTypeRef(t Type, printStructName bool) {
|
||||
func (w *hrsWriter) writeUnresolvedTypeRef(t *Type, printStructName bool) {
|
||||
if !t.HasPackageRef() {
|
||||
if t.Namespace() != "" {
|
||||
w.write(t.Namespace())
|
||||
|
||||
@@ -154,7 +154,7 @@ func TestWriteHumanReadableNested(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWriteHumanReadableStruct(t *testing.T) {
|
||||
pkg := NewPackage([]Type{
|
||||
pkg := NewPackage([]*Type{
|
||||
MakeStructType("S1", []Field{
|
||||
Field{Name: "x", T: Int32Type, Optional: false},
|
||||
Field{Name: "y", T: Int32Type, Optional: true},
|
||||
@@ -179,7 +179,7 @@ func TestWriteHumanReadableStruct(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWriteHumanReadableStructWithUnion(t *testing.T) {
|
||||
pkg := NewPackage([]Type{
|
||||
pkg := NewPackage([]*Type{
|
||||
MakeStructType("S2", []Field{}, []Field{
|
||||
Field{Name: "x", T: Int32Type, Optional: false},
|
||||
Field{Name: "y", T: Int32Type, Optional: false},
|
||||
@@ -203,7 +203,7 @@ func TestWriteHumanReadableStructWithUnion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWriteHumanReadableListOfStruct(t *testing.T) {
|
||||
pkg := NewPackage([]Type{
|
||||
pkg := NewPackage([]*Type{
|
||||
MakeStructType("S3", []Field{}, []Field{
|
||||
Field{Name: "x", T: Int32Type, Optional: false},
|
||||
}),
|
||||
@@ -302,7 +302,7 @@ func TestWriteHumanReadableType(t *testing.T) {
|
||||
assertWriteHRSEqual(t, "Ref<Int32>", MakeRefType(Int32Type))
|
||||
assertWriteHRSEqual(t, "Map<Int64, String>", MakeMapType(Int64Type, StringType))
|
||||
|
||||
pkg := NewPackage([]Type{
|
||||
pkg := NewPackage([]*Type{
|
||||
MakeStructType("Str", []Field{
|
||||
Field{Name: "c", T: MakeType(ref.Ref{}, 0), Optional: false},
|
||||
Field{Name: "o", T: StringType, Optional: true},
|
||||
|
||||
@@ -62,7 +62,7 @@ func (w *jsonArrayWriter) writeRef(r ref.Ref) {
|
||||
w.write(r.String())
|
||||
}
|
||||
|
||||
func (w *jsonArrayWriter) writeTypeAsTag(t Type) {
|
||||
func (w *jsonArrayWriter) writeTypeAsTag(t *Type) {
|
||||
k := t.Kind()
|
||||
w.write(k)
|
||||
switch k {
|
||||
@@ -91,7 +91,7 @@ func (w *jsonArrayWriter) writeTopLevelValue(v Value) {
|
||||
w.writeValue(v, tr, nil)
|
||||
}
|
||||
|
||||
func (w *jsonArrayWriter) maybeWriteMetaSequence(v Value, tr Type, pkg *Package) bool {
|
||||
func (w *jsonArrayWriter) maybeWriteMetaSequence(v Value, tr *Type, pkg *Package) bool {
|
||||
ms, ok := v.(metaSequence)
|
||||
if !ok {
|
||||
w.write(false) // not a meta sequence
|
||||
@@ -114,7 +114,7 @@ func (w *jsonArrayWriter) maybeWriteMetaSequence(v Value, tr Type, pkg *Package)
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *jsonArrayWriter) writeValue(v Value, tr Type, pkg *Package) {
|
||||
func (w *jsonArrayWriter) writeValue(v Value, tr *Type, pkg *Package) {
|
||||
switch tr.Kind() {
|
||||
case BlobKind:
|
||||
if w.maybeWriteMetaSequence(v, tr, pkg) {
|
||||
@@ -212,7 +212,7 @@ func (w *jsonArrayWriter) writeValue(v Value, tr Type, pkg *Package) {
|
||||
}
|
||||
}
|
||||
|
||||
func (w *jsonArrayWriter) writeTypeAsValue(t Type, pkg *Package) {
|
||||
func (w *jsonArrayWriter) writeTypeAsValue(t *Type, pkg *Package) {
|
||||
k := t.Kind()
|
||||
w.write(k)
|
||||
switch k {
|
||||
@@ -267,13 +267,14 @@ func (w *jsonArrayWriter) writeTypeAsValue(t Type, pkg *Package) {
|
||||
}
|
||||
|
||||
// writeTypeKindValue writes either a struct or a Type value
|
||||
func (w *jsonArrayWriter) writeTypeKindValue(v Value, tr Type, pkg *Package) {
|
||||
d.Chk.IsType(Type{}, v)
|
||||
w.writeTypeAsValue(v.(Type), pkg)
|
||||
func (w *jsonArrayWriter) writeTypeKindValue(v Value, tr *Type, pkg *Package) {
|
||||
_, ok := v.(*Type)
|
||||
d.Chk.True(ok)
|
||||
w.writeTypeAsValue(v.(*Type), pkg)
|
||||
}
|
||||
|
||||
// writeUnresolvedKindValue writes a struct.
|
||||
func (w *jsonArrayWriter) writeUnresolvedKindValue(v Value, tr Type, pkg *Package) {
|
||||
func (w *jsonArrayWriter) writeUnresolvedKindValue(v Value, tr *Type, pkg *Package) {
|
||||
d.Chk.NotNil(pkg)
|
||||
typeDef := pkg.types[tr.Ordinal()]
|
||||
switch typeDef.Kind() {
|
||||
@@ -294,7 +295,7 @@ func (w *jsonArrayWriter) writeBlob(b Blob) {
|
||||
w.write(buf.String())
|
||||
}
|
||||
|
||||
func (w *jsonArrayWriter) writeStruct(v Value, typ, typeDef Type, pkg *Package) {
|
||||
func (w *jsonArrayWriter) writeStruct(v Value, typ, typeDef *Type, pkg *Package) {
|
||||
i := 0
|
||||
values := structReaderForType(v, typ, typeDef)
|
||||
desc := typeDef.Desc.(StructDesc)
|
||||
|
||||
@@ -146,7 +146,7 @@ func TestWriteEmptyStruct(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
typeDef := MakeStructType("S", []Field{}, []Field{})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
v := NewStruct(typ, typeDef, nil)
|
||||
@@ -163,7 +163,7 @@ func TestWriteStruct(t *testing.T) {
|
||||
Field{"x", MakePrimitiveType(Int8Kind), false},
|
||||
Field{"b", MakePrimitiveType(BoolKind), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
v := NewStruct(typ, typeDef, structData{"x": Int8(42), "b": Bool(true)})
|
||||
@@ -180,7 +180,7 @@ func TestWriteStructOptionalField(t *testing.T) {
|
||||
Field{"x", MakePrimitiveType(Int8Kind), true},
|
||||
Field{"b", MakePrimitiveType(BoolKind), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
v := NewStruct(typ, typeDef, structData{"x": Int8(42), "b": Bool(true)})
|
||||
@@ -205,7 +205,7 @@ func TestWriteStructWithUnion(t *testing.T) {
|
||||
Field{"b", MakePrimitiveType(BoolKind), false},
|
||||
Field{"s", MakePrimitiveType(StringKind), false},
|
||||
})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
v := NewStruct(typ, typeDef, structData{"x": Int8(42), "s": NewString("hi")})
|
||||
@@ -227,7 +227,7 @@ func TestWriteStructWithList(t *testing.T) {
|
||||
typeDef := MakeStructType("S", []Field{
|
||||
Field{"l", MakeCompoundType(ListKind, MakePrimitiveType(StringKind)), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
|
||||
@@ -251,7 +251,7 @@ func TestWriteStructWithStruct(t *testing.T) {
|
||||
sTypeDef := MakeStructType("S", []Field{
|
||||
Field{"s", MakeType(ref.Ref{}, 0), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{s2TypeDef, sTypeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{s2TypeDef, sTypeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
s2Type := MakeType(pkgRef, 0)
|
||||
sType := MakeType(pkgRef, 1)
|
||||
@@ -268,7 +268,7 @@ func TestWriteStructWithBlob(t *testing.T) {
|
||||
typeDef := MakeStructType("S", []Field{
|
||||
Field{"b", MakePrimitiveType(BlobKind), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
b := NewBlob(bytes.NewBuffer([]byte{0x00, 0x01}))
|
||||
@@ -358,7 +358,7 @@ func TestWriteListOfValueWithStruct(t *testing.T) {
|
||||
typeDef := MakeStructType("S", []Field{
|
||||
Field{"x", MakePrimitiveType(Int32Kind), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
listType := MakeCompoundType(ListKind, MakePrimitiveType(ValueKind))
|
||||
structType := MakeType(pkgRef, 0)
|
||||
@@ -372,7 +372,7 @@ func TestWriteListOfValueWithStruct(t *testing.T) {
|
||||
func TestWriteListOfValueWithType(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
pkg := NewPackage([]Type{
|
||||
pkg := NewPackage([]*Type{
|
||||
MakeStructType("S", []Field{
|
||||
Field{"x", MakePrimitiveType(Int32Kind), false},
|
||||
}, []Field{})}, []ref.Ref{})
|
||||
@@ -398,10 +398,10 @@ func TestWriteListOfValueWithType(t *testing.T) {
|
||||
|
||||
type testRef struct {
|
||||
Value
|
||||
t Type
|
||||
t *Type
|
||||
}
|
||||
|
||||
func (r testRef) Type() Type {
|
||||
func (r testRef) Type() *Type {
|
||||
return r.t
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ func TestWriteRef(t *testing.T) {
|
||||
func TestWriteTypeValue(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
test := func(expected []interface{}, v Type) {
|
||||
test := func(expected []interface{}, v *Type) {
|
||||
w := newJSONArrayWriter(NewTestValueStore())
|
||||
w.writeTopLevelValue(v)
|
||||
assert.EqualValues(expected, w.toArray())
|
||||
@@ -478,7 +478,7 @@ func TestWritePackage(t *testing.T) {
|
||||
|
||||
setTref := MakeCompoundType(SetKind, MakePrimitiveType(Uint32Kind))
|
||||
r := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567")
|
||||
v := Package{[]Type{setTref}, []ref.Ref{r}, &ref.Ref{}}
|
||||
v := Package{[]*Type{setTref}, []ref.Ref{r}, &ref.Ref{}}
|
||||
|
||||
w := newJSONArrayWriter(NewTestValueStore())
|
||||
w.writeTopLevelValue(v)
|
||||
|
||||
+2
-2
@@ -1,13 +1,13 @@
|
||||
package types
|
||||
|
||||
// FixupType goes trough the object graph of tr and updates the PackageRef to pkg if the the old PackageRef was an empty ref.
|
||||
func FixupType(tr Type, pkg *Package) Type {
|
||||
func FixupType(tr *Type, pkg *Package) *Type {
|
||||
switch desc := tr.Desc.(type) {
|
||||
case PrimitiveDesc:
|
||||
return tr
|
||||
|
||||
case CompoundDesc:
|
||||
elemTypes := make([]Type, len(desc.ElemTypes))
|
||||
elemTypes := make([]*Type, len(desc.ElemTypes))
|
||||
for i, elemType := range desc.ElemTypes {
|
||||
elemTypes[i] = FixupType(elemType, pkg)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func (v {{.NomsType}}) ToPrimitive() interface{} {
|
||||
|
||||
var typeFor{{.NomsType}} = MakePrimitiveType({{.NomsType}}Kind)
|
||||
|
||||
func (v {{.NomsType}}) Type() Type {
|
||||
func (v {{.NomsType}}) Type() *Type {
|
||||
return typeFor{{.NomsType}}
|
||||
}
|
||||
{{if .IsOrdered}}
|
||||
|
||||
@@ -11,7 +11,7 @@ func newIndexedMetaSequenceBoundaryChecker() boundaryChecker {
|
||||
|
||||
// If |sink| is not nil, chunks will be eagerly written as they're created. Otherwise they are
|
||||
// written when the root is written.
|
||||
func newIndexedMetaSequenceChunkFn(t Type, source ValueReader, sink ValueWriter) makeChunkFn {
|
||||
func newIndexedMetaSequenceChunkFn(t *Type, source ValueReader, sink ValueWriter) makeChunkFn {
|
||||
return func(items []sequenceItem) (sequenceItem, Value) {
|
||||
tuples := make(metaSequenceData, len(items))
|
||||
numLeaves := uint64(0)
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ func NewList(v ...Value) List {
|
||||
}
|
||||
|
||||
// NewTypedList creates a new List with type t, populated with values, chunking if and when needed.
|
||||
func NewTypedList(t Type, values ...Value) List {
|
||||
func NewTypedList(t *Type, values ...Value) List {
|
||||
d.Chk.Equal(ListKind, t.Kind(), "Invalid type. Expected: ListKind, found: %s", t.Describe())
|
||||
seq := newEmptySequenceChunker(makeListLeafChunkFn(t, nil), newIndexedMetaSequenceChunkFn(t, nil, nil), newListLeafBoundaryChecker(), newIndexedMetaSequenceBoundaryChecker)
|
||||
for _, v := range values {
|
||||
@@ -44,7 +44,7 @@ func NewTypedList(t Type, values ...Value) List {
|
||||
}
|
||||
|
||||
// NewStreamingTypedList creates a new List with type t, populated with values, chunking if and when needed. As chunks are created, they're written to vrw -- including the root chunk of the list. Once the caller has closed values, she can read the completed List from the returned channel.
|
||||
func NewStreamingTypedList(t Type, vrw ValueReadWriter, values <-chan Value) <-chan List {
|
||||
func NewStreamingTypedList(t *Type, vrw ValueReadWriter, values <-chan Value) <-chan List {
|
||||
out := make(chan List)
|
||||
go func() {
|
||||
seq := newEmptySequenceChunker(makeListLeafChunkFn(t, vrw), newIndexedMetaSequenceChunkFn(t, vrw, vrw), newListLeafBoundaryChecker(), newIndexedMetaSequenceBoundaryChecker)
|
||||
|
||||
+4
-4
@@ -10,11 +10,11 @@ import (
|
||||
|
||||
type listLeaf struct {
|
||||
values []Value
|
||||
t Type
|
||||
t *Type
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func newListLeaf(t Type, v ...Value) List {
|
||||
func newListLeaf(t *Type, v ...Value) List {
|
||||
d.Chk.Equal(ListKind, t.Kind())
|
||||
return listLeaf{v, t, &ref.Ref{}}
|
||||
}
|
||||
@@ -183,10 +183,10 @@ func (l listLeaf) ChildValues() []Value {
|
||||
return append([]Value{}, l.values...)
|
||||
}
|
||||
|
||||
func (l listLeaf) Type() Type {
|
||||
func (l listLeaf) Type() *Type {
|
||||
return l.t
|
||||
}
|
||||
|
||||
func (l listLeaf) elemType() Type {
|
||||
func (l listLeaf) elemType() *Type {
|
||||
return l.t.Desc.(CompoundDesc).ElemTypes[0]
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@ type Map interface {
|
||||
IterAll(cb mapIterAllCallback)
|
||||
IterAllP(concurrency int, f mapIterAllCallback)
|
||||
Filter(cb mapFilterCallback) Map
|
||||
elemTypes() []Type
|
||||
elemTypes() []*Type
|
||||
}
|
||||
|
||||
type indexOfMapFn func(m mapData, v Value) int
|
||||
@@ -31,12 +31,12 @@ func NewMap(kv ...Value) Map {
|
||||
return NewTypedMap(mapType, kv...)
|
||||
}
|
||||
|
||||
func NewTypedMap(t Type, kv ...Value) Map {
|
||||
func NewTypedMap(t *Type, kv ...Value) Map {
|
||||
d.Chk.Equal(MapKind, t.Kind(), "Invalid type. Expected: MapKind, found: %s", t.Describe())
|
||||
return newTypedMap(t, buildMapData(mapData{}, kv, t)...)
|
||||
}
|
||||
|
||||
func newTypedMap(t Type, entries ...mapEntry) Map {
|
||||
func newTypedMap(t *Type, entries ...mapEntry) Map {
|
||||
seq := newEmptySequenceChunker(makeMapLeafChunkFn(t, nil), newOrderedMetaSequenceChunkFn(t, nil), newMapLeafBoundaryChecker(), newOrderedMetaSequenceBoundaryChecker)
|
||||
|
||||
for _, entry := range entries {
|
||||
|
||||
+7
-7
@@ -13,7 +13,7 @@ import (
|
||||
type mapLeaf struct {
|
||||
data mapData // sorted by entry.key.Ref()
|
||||
indexOf indexOfMapFn
|
||||
t Type
|
||||
t *Type
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ type mapEntry struct {
|
||||
value Value
|
||||
}
|
||||
|
||||
func newMapLeaf(t Type, data ...mapEntry) Map {
|
||||
func newMapLeaf(t *Type, data ...mapEntry) Map {
|
||||
return mapLeaf{data, getIndexFnForMapType(t), t, &ref.Ref{}}
|
||||
}
|
||||
|
||||
@@ -164,15 +164,15 @@ func (m mapLeaf) ChildValues() []Value {
|
||||
return res
|
||||
}
|
||||
|
||||
func (m mapLeaf) Type() Type {
|
||||
func (m mapLeaf) Type() *Type {
|
||||
return m.t
|
||||
}
|
||||
|
||||
func (m mapLeaf) elemTypes() []Type {
|
||||
func (m mapLeaf) elemTypes() []*Type {
|
||||
return m.t.Desc.(CompoundDesc).ElemTypes
|
||||
}
|
||||
|
||||
func buildMapData(oldData mapData, values []Value, t Type) mapData {
|
||||
func buildMapData(oldData mapData, values []Value, t *Type) mapData {
|
||||
idxFn := getIndexFnForMapType(t)
|
||||
elemTypes := t.Desc.(CompoundDesc).ElemTypes
|
||||
|
||||
@@ -202,7 +202,7 @@ func buildMapData(oldData mapData, values []Value, t Type) mapData {
|
||||
return data
|
||||
}
|
||||
|
||||
func getIndexFnForMapType(t Type) indexOfMapFn {
|
||||
func getIndexFnForMapType(t *Type) indexOfMapFn {
|
||||
orderByValue := t.Desc.(CompoundDesc).ElemTypes[0].IsOrdered()
|
||||
if orderByValue {
|
||||
return indexOfOrderedMapValue
|
||||
@@ -232,7 +232,7 @@ func newMapLeafBoundaryChecker() boundaryChecker {
|
||||
})
|
||||
}
|
||||
|
||||
func makeMapLeafChunkFn(t Type, vr ValueReader) makeChunkFn {
|
||||
func makeMapLeafChunkFn(t *Type, vr ValueReader) makeChunkFn {
|
||||
return func(items []sequenceItem) (sequenceItem, Value) {
|
||||
mapData := make([]mapEntry, len(items), len(items))
|
||||
|
||||
|
||||
+1
-1
@@ -251,7 +251,7 @@ func TestMapNotStringKeys(t *testing.T) {
|
||||
assert.Nil(m1.Get(Int32(42)))
|
||||
}
|
||||
|
||||
func testMapOrder(assert *assert.Assertions, keyType, valueType Type, tuples []Value, expectOrdering []Value) {
|
||||
func testMapOrder(assert *assert.Assertions, keyType, valueType *Type, tuples []Value, expectOrdering []Value) {
|
||||
mapTr := MakeCompoundType(MapKind, keyType, valueType)
|
||||
m := NewTypedMap(mapTr, tuples...)
|
||||
i := 0
|
||||
|
||||
@@ -64,7 +64,7 @@ func (msd metaSequenceData) last() metaTuple {
|
||||
|
||||
type metaSequenceObject struct {
|
||||
tuples metaSequenceData
|
||||
t Type
|
||||
t *Type
|
||||
}
|
||||
|
||||
func (ms metaSequenceObject) tupleAt(idx int) metaTuple {
|
||||
@@ -100,11 +100,11 @@ func (ms metaSequenceObject) Chunks() (chunks []RefBase) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ms metaSequenceObject) Type() Type {
|
||||
func (ms metaSequenceObject) Type() *Type {
|
||||
return ms.t
|
||||
}
|
||||
|
||||
type metaBuilderFunc func(tuples metaSequenceData, t Type, vr ValueReader) Value
|
||||
type metaBuilderFunc func(tuples metaSequenceData, t *Type, vr ValueReader) Value
|
||||
|
||||
var metaFuncMap = map[NomsKind]metaBuilderFunc{}
|
||||
|
||||
@@ -112,7 +112,7 @@ func registerMetaValue(k NomsKind, bf metaBuilderFunc) {
|
||||
metaFuncMap[k] = bf
|
||||
}
|
||||
|
||||
func newMetaSequenceFromData(tuples metaSequenceData, t Type, vr ValueReader) Value {
|
||||
func newMetaSequenceFromData(tuples metaSequenceData, t *Type, vr ValueReader) Value {
|
||||
if bf, ok := metaFuncMap[t.Kind()]; ok {
|
||||
return bf(tuples, t, vr)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
func isSequenceOrderedByIndexedType(t Type) bool {
|
||||
func isSequenceOrderedByIndexedType(t *Type) bool {
|
||||
return t.Desc.(CompoundDesc).ElemTypes[0].IsOrdered()
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ func isSequenceOrderedByIndexedType(t Type) bool {
|
||||
type getLeafOrderedValuesFn func(Value) []Value
|
||||
|
||||
// Returns a cursor to |key| in |ms|, plus the leaf + index that |key| is in. |t| is the type of the ordered values.
|
||||
func findLeafInOrderedSequence(ms metaSequence, t Type, key Value, getValues getLeafOrderedValuesFn, vr ValueReader) (cursor *sequenceCursor, leaf Value, idx int) {
|
||||
func findLeafInOrderedSequence(ms metaSequence, t *Type, key Value, getValues getLeafOrderedValuesFn, vr ValueReader) (cursor *sequenceCursor, leaf Value, idx int) {
|
||||
cursor, leaf = newMetaSequenceCursor(ms, vr)
|
||||
|
||||
if isSequenceOrderedByIndexedType(t) {
|
||||
@@ -54,7 +54,7 @@ func newOrderedMetaSequenceBoundaryChecker() boundaryChecker {
|
||||
})
|
||||
}
|
||||
|
||||
func newOrderedMetaSequenceChunkFn(t Type, vr ValueReader) makeChunkFn {
|
||||
func newOrderedMetaSequenceChunkFn(t *Type, vr ValueReader) makeChunkFn {
|
||||
return func(items []sequenceItem) (sequenceItem, Value) {
|
||||
tuples := make(metaSequenceData, len(items))
|
||||
numLeaves := uint64(0)
|
||||
|
||||
+5
-5
@@ -7,12 +7,12 @@ import (
|
||||
)
|
||||
|
||||
type Package struct {
|
||||
types []Type
|
||||
types []*Type
|
||||
dependencies ref.RefSlice
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewPackage(types []Type, dependencies ref.RefSlice) Package {
|
||||
func NewPackage(types []*Type, dependencies ref.RefSlice) Package {
|
||||
p := Package{types: types}
|
||||
// The order |Package.dependencies| must be stable for the Package to have a stable ref.
|
||||
// See https://github.com/attic-labs/noms/issues/814 for stable ordering of |Package.types|.
|
||||
@@ -21,7 +21,7 @@ func NewPackage(types []Type, dependencies ref.RefSlice) Package {
|
||||
r := getRef(p)
|
||||
p.ref = &r
|
||||
|
||||
newTypes := make([]Type, len(types))
|
||||
newTypes := make([]*Type, len(types))
|
||||
for i, t := range types {
|
||||
newTypes[i] = FixupType(t, &p)
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (p Package) ChildValues() (res []Value) {
|
||||
|
||||
var typeForPackage = PackageType
|
||||
|
||||
func (p Package) Type() Type {
|
||||
func (p Package) Type() *Type {
|
||||
return typeForPackage
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func (p Package) Dependencies() (dependencies []ref.Ref) {
|
||||
return
|
||||
}
|
||||
|
||||
func (p Package) Types() (types []Type) {
|
||||
func (p Package) Types() (types []*Type) {
|
||||
types = append(types, p.types...)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -48,25 +48,25 @@ func ReadPackage(r ref.Ref, vr ValueReader) *Package {
|
||||
return &p
|
||||
}
|
||||
|
||||
func RegisterStruct(t Type, bf structBuilderFunc, rf structReaderFunc) {
|
||||
func RegisterStruct(t *Type, bf structBuilderFunc, rf structReaderFunc) {
|
||||
structFuncMap[t.Ref()] = structFuncs{bf, rf}
|
||||
}
|
||||
|
||||
func structBuilderForType(values []Value, typ, typeDef Type) Value {
|
||||
func structBuilderForType(values []Value, typ, typeDef *Type) Value {
|
||||
if s, ok := structFuncMap[typ.Ref()]; ok {
|
||||
return s.builder(values)
|
||||
}
|
||||
return structBuilder(values, typ, typeDef)
|
||||
}
|
||||
|
||||
func structReaderForType(v Value, typ, typeDef Type) []Value {
|
||||
func structReaderForType(v Value, typ, typeDef *Type) []Value {
|
||||
if s, ok := structFuncMap[typ.Ref()]; ok {
|
||||
return s.reader(v)
|
||||
}
|
||||
return structReader(v.(Struct), typ, typeDef)
|
||||
}
|
||||
|
||||
func RegisterValue(t Type, bf valueBuilderFunc, rf valueReaderFunc) {
|
||||
func RegisterValue(t *Type, bf valueBuilderFunc, rf valueReaderFunc) {
|
||||
switch t.Kind() {
|
||||
case MapKind, ListKind, SetKind:
|
||||
valueFuncMap[t.Ref()] = valueFuncs{bf, rf}
|
||||
@@ -75,7 +75,7 @@ func RegisterValue(t Type, bf valueBuilderFunc, rf valueReaderFunc) {
|
||||
}
|
||||
}
|
||||
|
||||
func valueFromType(v Value, t Type) Value {
|
||||
func valueFromType(v Value, t *Type) Value {
|
||||
switch t.Kind() {
|
||||
case MapKind, ListKind, SetKind:
|
||||
if s, ok := valueFuncMap[t.Ref()]; ok {
|
||||
@@ -86,7 +86,7 @@ func valueFromType(v Value, t Type) Value {
|
||||
return v
|
||||
}
|
||||
|
||||
func internalValueFromType(v Value, t Type) Value {
|
||||
func internalValueFromType(v Value, t *Type) Value {
|
||||
switch t.Kind() {
|
||||
case MapKind, ListKind, SetKind:
|
||||
if s, ok := valueFuncMap[t.Ref()]; ok {
|
||||
@@ -97,11 +97,11 @@ func internalValueFromType(v Value, t Type) Value {
|
||||
return v
|
||||
}
|
||||
|
||||
func RegisterRef(t Type, bf refBuilderFunc) {
|
||||
func RegisterRef(t *Type, bf refBuilderFunc) {
|
||||
refFuncMap[t.Ref()] = bf
|
||||
}
|
||||
|
||||
func refFromType(target ref.Ref, t Type) RefBase {
|
||||
func refFromType(target ref.Ref, t *Type) RefBase {
|
||||
if f, ok := refFuncMap[t.Ref()]; ok {
|
||||
return f(target)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
func TestType(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
st := NewPackage([]Type{}, []ref.Ref{})
|
||||
st := NewPackage([]*Type{}, []ref.Ref{})
|
||||
typ := st.Type()
|
||||
assert.Equal(PackageKind, typ.Kind())
|
||||
}
|
||||
|
||||
+11
-11
@@ -31,7 +31,7 @@ func (v Bool) ToPrimitive() interface{} {
|
||||
|
||||
var typeForBool = MakePrimitiveType(BoolKind)
|
||||
|
||||
func (v Bool) Type() Type {
|
||||
func (v Bool) Type() *Type {
|
||||
return typeForBool
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func (v Float32) ToPrimitive() interface{} {
|
||||
|
||||
var typeForFloat32 = MakePrimitiveType(Float32Kind)
|
||||
|
||||
func (v Float32) Type() Type {
|
||||
func (v Float32) Type() *Type {
|
||||
return typeForFloat32
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ func (v Float64) ToPrimitive() interface{} {
|
||||
|
||||
var typeForFloat64 = MakePrimitiveType(Float64Kind)
|
||||
|
||||
func (v Float64) Type() Type {
|
||||
func (v Float64) Type() *Type {
|
||||
return typeForFloat64
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func (v Int16) ToPrimitive() interface{} {
|
||||
|
||||
var typeForInt16 = MakePrimitiveType(Int16Kind)
|
||||
|
||||
func (v Int16) Type() Type {
|
||||
func (v Int16) Type() *Type {
|
||||
return typeForInt16
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ func (v Int32) ToPrimitive() interface{} {
|
||||
|
||||
var typeForInt32 = MakePrimitiveType(Int32Kind)
|
||||
|
||||
func (v Int32) Type() Type {
|
||||
func (v Int32) Type() *Type {
|
||||
return typeForInt32
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ func (v Int64) ToPrimitive() interface{} {
|
||||
|
||||
var typeForInt64 = MakePrimitiveType(Int64Kind)
|
||||
|
||||
func (v Int64) Type() Type {
|
||||
func (v Int64) Type() *Type {
|
||||
return typeForInt64
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ func (v Int8) ToPrimitive() interface{} {
|
||||
|
||||
var typeForInt8 = MakePrimitiveType(Int8Kind)
|
||||
|
||||
func (v Int8) Type() Type {
|
||||
func (v Int8) Type() *Type {
|
||||
return typeForInt8
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ func (v Uint16) ToPrimitive() interface{} {
|
||||
|
||||
var typeForUint16 = MakePrimitiveType(Uint16Kind)
|
||||
|
||||
func (v Uint16) Type() Type {
|
||||
func (v Uint16) Type() *Type {
|
||||
return typeForUint16
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ func (v Uint32) ToPrimitive() interface{} {
|
||||
|
||||
var typeForUint32 = MakePrimitiveType(Uint32Kind)
|
||||
|
||||
func (v Uint32) Type() Type {
|
||||
func (v Uint32) Type() *Type {
|
||||
return typeForUint32
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ func (v Uint64) ToPrimitive() interface{} {
|
||||
|
||||
var typeForUint64 = MakePrimitiveType(Uint64Kind)
|
||||
|
||||
func (v Uint64) Type() Type {
|
||||
func (v Uint64) Type() *Type {
|
||||
return typeForUint64
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ func (v Uint8) ToPrimitive() interface{} {
|
||||
|
||||
var typeForUint8 = MakePrimitiveType(Uint8Kind)
|
||||
|
||||
func (v Uint8) Type() Type {
|
||||
func (v Uint8) Type() *Type {
|
||||
return typeForUint8
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type Ref struct {
|
||||
target ref.Ref
|
||||
t Type
|
||||
t *Type
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func NewRef(target ref.Ref) Ref {
|
||||
return NewTypedRef(refType, target)
|
||||
}
|
||||
|
||||
func NewTypedRef(t Type, target ref.Ref) Ref {
|
||||
func NewTypedRef(t *Type, target ref.Ref) Ref {
|
||||
d.Chk.Equal(RefKind, t.Kind(), "Invalid type. Expected: RefKind, found: %s", t.Describe())
|
||||
return Ref{target, t, &ref.Ref{}}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func (r Ref) TargetRef() ref.Ref {
|
||||
|
||||
var refType = MakeCompoundType(RefKind, MakePrimitiveType(ValueKind))
|
||||
|
||||
func (r Ref) Type() Type {
|
||||
func (r Ref) Type() *Type {
|
||||
return r.t
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -15,7 +15,7 @@ type Set interface {
|
||||
IterAll(cb setIterAllCallback)
|
||||
IterAllP(concurrency int, f setIterAllCallback)
|
||||
Filter(cb setFilterCallback) Set
|
||||
elemType() Type
|
||||
elemType() *Type
|
||||
sequenceCursorAtFirst() *sequenceCursor
|
||||
valueReader() ValueReader
|
||||
}
|
||||
@@ -31,12 +31,12 @@ func NewSet(v ...Value) Set {
|
||||
return NewTypedSet(setType, v...)
|
||||
}
|
||||
|
||||
func NewTypedSet(t Type, v ...Value) Set {
|
||||
func NewTypedSet(t *Type, v ...Value) Set {
|
||||
d.Chk.Equal(SetKind, t.Kind(), "Invalid type. Expected:SetKind, found: %s", t.Describe())
|
||||
return newTypedSet(t, buildSetData(setData{}, v, t)...)
|
||||
}
|
||||
|
||||
func newTypedSet(t Type, data ...Value) Set {
|
||||
func newTypedSet(t *Type, data ...Value) Set {
|
||||
seq := newEmptySequenceChunker(makeSetLeafChunkFn(t, nil), newOrderedMetaSequenceChunkFn(t, nil), newSetLeafBoundaryChecker(), newOrderedMetaSequenceBoundaryChecker)
|
||||
|
||||
for _, v := range data {
|
||||
|
||||
+7
-7
@@ -13,13 +13,13 @@ import (
|
||||
type setLeaf struct {
|
||||
data setData // sorted by Ref()
|
||||
indexOf indexOfSetFn
|
||||
t Type
|
||||
t *Type
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
type setData []Value
|
||||
|
||||
func newSetLeaf(t Type, m ...Value) setLeaf {
|
||||
func newSetLeaf(t *Type, m ...Value) setLeaf {
|
||||
return setLeaf{m, getIndexFnForSetType(t), t, &ref.Ref{}}
|
||||
}
|
||||
|
||||
@@ -131,11 +131,11 @@ func (s setLeaf) ChildValues() []Value {
|
||||
return append([]Value{}, s.data...)
|
||||
}
|
||||
|
||||
func (s setLeaf) Type() Type {
|
||||
func (s setLeaf) Type() *Type {
|
||||
return s.t
|
||||
}
|
||||
|
||||
func (s setLeaf) elemType() Type {
|
||||
func (s setLeaf) elemType() *Type {
|
||||
return s.t.Desc.(CompoundDesc).ElemTypes[0]
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ func copySetData(m setData) setData {
|
||||
return r
|
||||
}
|
||||
|
||||
func buildSetData(old setData, values []Value, t Type) setData {
|
||||
func buildSetData(old setData, values []Value, t *Type) setData {
|
||||
idxFn := getIndexFnForSetType(t)
|
||||
elemType := t.Desc.(CompoundDesc).ElemTypes[0]
|
||||
|
||||
@@ -166,7 +166,7 @@ func buildSetData(old setData, values []Value, t Type) setData {
|
||||
return data
|
||||
}
|
||||
|
||||
func getIndexFnForSetType(t Type) indexOfSetFn {
|
||||
func getIndexFnForSetType(t *Type) indexOfSetFn {
|
||||
orderByValue := t.Desc.(CompoundDesc).ElemTypes[0].IsOrdered()
|
||||
if orderByValue {
|
||||
return indexOfOrderedSetValue
|
||||
@@ -196,7 +196,7 @@ func newSetLeafBoundaryChecker() boundaryChecker {
|
||||
})
|
||||
}
|
||||
|
||||
func makeSetLeafChunkFn(t Type, vr ValueReader) makeChunkFn {
|
||||
func makeSetLeafChunkFn(t *Type, vr ValueReader) makeChunkFn {
|
||||
return func(items []sequenceItem) (sequenceItem, Value) {
|
||||
setData := make([]Value, len(items), len(items))
|
||||
|
||||
|
||||
+1
-1
@@ -203,7 +203,7 @@ func TestSetIterAllP(t *testing.T) {
|
||||
testIter(64, 200)
|
||||
}
|
||||
|
||||
func testSetOrder(assert *assert.Assertions, valueType Type, value []Value, expectOrdering []Value) {
|
||||
func testSetOrder(assert *assert.Assertions, valueType *Type, value []Value, expectOrdering []Value) {
|
||||
mapTr := MakeCompoundType(SetKind, valueType)
|
||||
m := NewTypedSet(mapTr, value...)
|
||||
i := 0
|
||||
|
||||
+1
-1
@@ -40,6 +40,6 @@ func (fs String) ChildValues() []Value {
|
||||
|
||||
var typeForString = MakePrimitiveType(StringKind)
|
||||
|
||||
func (fs String) Type() Type {
|
||||
func (fs String) Type() *Type {
|
||||
return typeForString
|
||||
}
|
||||
|
||||
+7
-7
@@ -9,14 +9,14 @@ type structData map[string]Value
|
||||
|
||||
type Struct struct {
|
||||
data structData
|
||||
t Type
|
||||
typeDef Type
|
||||
t *Type
|
||||
typeDef *Type
|
||||
unionIndex uint32
|
||||
unionValue Value
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func newStructFromData(data structData, unionIndex uint32, unionValue Value, typ, typeDef Type) Struct {
|
||||
func newStructFromData(data structData, unionIndex uint32, unionValue Value, typ, typeDef *Type) Struct {
|
||||
d.Chk.Equal(typ.Kind(), UnresolvedKind)
|
||||
d.Chk.True(typ.HasPackageRef())
|
||||
d.Chk.True(typ.HasOrdinal())
|
||||
@@ -24,7 +24,7 @@ func newStructFromData(data structData, unionIndex uint32, unionValue Value, typ
|
||||
return Struct{data, typ, typeDef, unionIndex, unionValue, &ref.Ref{}}
|
||||
}
|
||||
|
||||
func NewStruct(typ, typeDef Type, data structData) Struct {
|
||||
func NewStruct(typ, typeDef *Type, data structData) Struct {
|
||||
newData := make(structData)
|
||||
unionIndex := uint32(0)
|
||||
var unionValue Value
|
||||
@@ -88,7 +88,7 @@ func (s Struct) ChildValues() (res []Value) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s Struct) Type() Type {
|
||||
func (s Struct) Type() *Type {
|
||||
return s.t
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ func (s Struct) findField(n string) (Field, int32, bool) {
|
||||
return Field{}, -1, false
|
||||
}
|
||||
|
||||
func structBuilder(values []Value, typ, typeDef Type) Value {
|
||||
func structBuilder(values []Value, typ, typeDef *Type) Value {
|
||||
i := 0
|
||||
desc := typeDef.Desc.(StructDesc)
|
||||
data := structData{}
|
||||
@@ -200,7 +200,7 @@ func structBuilder(values []Value, typ, typeDef Type) Value {
|
||||
return newStructFromData(data, unionIndex, unionValue, typ, typeDef)
|
||||
}
|
||||
|
||||
func structReader(s Struct, typ, typeDef Type) []Value {
|
||||
func structReader(s Struct, typ, typeDef *Type) []Value {
|
||||
values := []Value{}
|
||||
|
||||
desc := typeDef.Desc.(StructDesc)
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestGenericStructEquals(t *testing.T) {
|
||||
Field{"x", MakePrimitiveType(BoolKind), false},
|
||||
Field{"o", MakePrimitiveType(StringKind), true},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestGenericStructChunks(t *testing.T) {
|
||||
typeDef := MakeStructType("S1", []Field{
|
||||
Field{"r", MakeCompoundType(RefKind, MakePrimitiveType(BoolKind)), false},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestGenericStructChunksOptional(t *testing.T) {
|
||||
typeDef := MakeStructType("S1", []Field{
|
||||
Field{"r", MakeCompoundType(RefKind, MakePrimitiveType(BoolKind)), true},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
|
||||
@@ -80,7 +80,7 @@ func TestGenericStructChunksUnion(t *testing.T) {
|
||||
Field{"r", MakeCompoundType(RefKind, MakePrimitiveType(BoolKind)), false},
|
||||
Field{"s", MakePrimitiveType(StringKind), false},
|
||||
})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
|
||||
@@ -105,7 +105,7 @@ func TestGenericStructNew(t *testing.T) {
|
||||
Field{"b", MakePrimitiveType(BoolKind), false},
|
||||
Field{"o", MakePrimitiveType(StringKind), true},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
|
||||
@@ -134,7 +134,7 @@ func TestGenericStructNewUnion(t *testing.T) {
|
||||
Field{"b", MakePrimitiveType(BoolKind), false},
|
||||
Field{"o", MakePrimitiveType(StringKind), false},
|
||||
})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
|
||||
@@ -151,7 +151,7 @@ func TestGenericStructSet(t *testing.T) {
|
||||
Field{"b", MakePrimitiveType(BoolKind), false},
|
||||
Field{"o", MakePrimitiveType(StringKind), true},
|
||||
}, []Field{})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
|
||||
@@ -172,7 +172,7 @@ func TestGenericStructSetUnion(t *testing.T) {
|
||||
Field{"b", MakePrimitiveType(BoolKind), false},
|
||||
Field{"s", MakePrimitiveType(StringKind), false},
|
||||
})
|
||||
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
typ := MakeType(pkgRef, 0)
|
||||
|
||||
|
||||
+35
-34
@@ -12,6 +12,7 @@ import (
|
||||
// If Kind() refers to List, Map, Set or Ref, then Desc is a list of Types describing the element type(s).
|
||||
// If Kind() refers to Struct, then Desc contains a []Field and Choices.
|
||||
// If Kind() refers to an UnresolvedKind, then Desc contains a PackageRef, which is the Ref of the package where the type definition is defined. The ordinal, if not -1, is the index into the Types list of the package. If the Name is set then the ordinal needs to be found.
|
||||
|
||||
type Type struct {
|
||||
name name
|
||||
Desc TypeDesc
|
||||
@@ -35,25 +36,25 @@ func (n name) compose() (out string) {
|
||||
}
|
||||
|
||||
// IsUnresolved returns true if t doesn't contain description information. The caller should look the type up by Ordinal in the Types of the appropriate Package.
|
||||
func (t Type) IsUnresolved() bool {
|
||||
func (t *Type) IsUnresolved() bool {
|
||||
_, ok := t.Desc.(UnresolvedDesc)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (t Type) HasPackageRef() bool {
|
||||
func (t *Type) HasPackageRef() bool {
|
||||
return t.IsUnresolved() && !t.PackageRef().IsEmpty()
|
||||
}
|
||||
|
||||
// Describe generate text that should parse into the struct being described.
|
||||
func (t Type) Describe() (out string) {
|
||||
func (t *Type) Describe() (out string) {
|
||||
return WriteHRS(t)
|
||||
}
|
||||
|
||||
func (t Type) Kind() NomsKind {
|
||||
func (t *Type) Kind() NomsKind {
|
||||
return t.Desc.Kind()
|
||||
}
|
||||
|
||||
func (t Type) IsOrdered() bool {
|
||||
func (t *Type) IsOrdered() bool {
|
||||
switch t.Desc.Kind() {
|
||||
case Float32Kind, Float64Kind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, Uint8Kind, Uint16Kind, Uint32Kind, Uint64Kind, StringKind, RefKind:
|
||||
return true
|
||||
@@ -62,38 +63,38 @@ func (t Type) IsOrdered() bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (t Type) PackageRef() ref.Ref {
|
||||
func (t *Type) PackageRef() ref.Ref {
|
||||
desc, ok := t.Desc.(UnresolvedDesc)
|
||||
d.Chk.True(ok, "PackageRef only works on unresolved types")
|
||||
return desc.pkgRef
|
||||
}
|
||||
|
||||
func (t Type) Ordinal() int16 {
|
||||
func (t *Type) Ordinal() int16 {
|
||||
d.Chk.True(t.HasOrdinal(), "Ordinal has not been set")
|
||||
return t.Desc.(UnresolvedDesc).ordinal
|
||||
}
|
||||
|
||||
func (t Type) HasOrdinal() bool {
|
||||
func (t *Type) HasOrdinal() bool {
|
||||
return t.IsUnresolved() && t.Desc.(UnresolvedDesc).ordinal >= 0
|
||||
}
|
||||
|
||||
func (t Type) Name() string {
|
||||
func (t *Type) Name() string {
|
||||
return t.name.name
|
||||
}
|
||||
|
||||
func (t Type) Namespace() string {
|
||||
func (t *Type) Namespace() string {
|
||||
return t.name.namespace
|
||||
}
|
||||
|
||||
func (t Type) Ref() ref.Ref {
|
||||
func (t *Type) Ref() ref.Ref {
|
||||
return EnsureRef(t.ref, t)
|
||||
}
|
||||
|
||||
func (t Type) Equals(other Value) (res bool) {
|
||||
func (t *Type) Equals(other Value) (res bool) {
|
||||
return other != nil && t.Ref() == other.Ref()
|
||||
}
|
||||
|
||||
func (t Type) Chunks() (chunks []RefBase) {
|
||||
func (t *Type) Chunks() (chunks []RefBase) {
|
||||
if t.IsUnresolved() {
|
||||
if t.HasPackageRef() {
|
||||
chunks = append(chunks, refFromType(t.PackageRef(), MakeRefType(typeForPackage)))
|
||||
@@ -108,7 +109,7 @@ func (t Type) Chunks() (chunks []RefBase) {
|
||||
return
|
||||
}
|
||||
|
||||
func (t Type) ChildValues() (res []Value) {
|
||||
func (t *Type) ChildValues() (res []Value) {
|
||||
if t.HasPackageRef() {
|
||||
res = append(res, NewTypedRef(MakeRefType(PackageType), t.PackageRef()))
|
||||
}
|
||||
@@ -138,19 +139,19 @@ func (t Type) ChildValues() (res []Value) {
|
||||
|
||||
var typeForType = MakePrimitiveType(TypeKind)
|
||||
|
||||
func (t Type) Type() Type {
|
||||
func (t *Type) Type() *Type {
|
||||
return typeForType
|
||||
}
|
||||
|
||||
func MakePrimitiveType(k NomsKind) Type {
|
||||
func MakePrimitiveType(k NomsKind) *Type {
|
||||
return buildType("", PrimitiveDesc(k))
|
||||
}
|
||||
|
||||
func MakePrimitiveTypeByString(p string) Type {
|
||||
func MakePrimitiveTypeByString(p string) *Type {
|
||||
return buildType("", primitiveToDesc(p))
|
||||
}
|
||||
|
||||
func MakeCompoundType(kind NomsKind, elemTypes ...Type) Type {
|
||||
func MakeCompoundType(kind NomsKind, elemTypes ...*Type) *Type {
|
||||
if len(elemTypes) == 1 {
|
||||
d.Chk.NotEqual(MapKind, kind, "MapKind requires 2 element types.")
|
||||
d.Chk.True(kind == RefKind || kind == ListKind || kind == SetKind)
|
||||
@@ -161,42 +162,42 @@ func MakeCompoundType(kind NomsKind, elemTypes ...Type) Type {
|
||||
return buildType("", CompoundDesc{kind, elemTypes})
|
||||
}
|
||||
|
||||
func MakeStructType(name string, fields []Field, choices []Field) Type {
|
||||
func MakeStructType(name string, fields []Field, choices []Field) *Type {
|
||||
return buildType(name, StructDesc{fields, choices})
|
||||
}
|
||||
|
||||
func MakeType(pkgRef ref.Ref, ordinal int16) Type {
|
||||
func MakeType(pkgRef ref.Ref, ordinal int16) *Type {
|
||||
d.Chk.True(ordinal >= 0)
|
||||
return Type{Desc: UnresolvedDesc{pkgRef, ordinal}, ref: &ref.Ref{}}
|
||||
return &Type{Desc: UnresolvedDesc{pkgRef, ordinal}, ref: &ref.Ref{}}
|
||||
}
|
||||
|
||||
func MakeUnresolvedType(namespace, n string) Type {
|
||||
return Type{name: name{namespace, n}, Desc: UnresolvedDesc{ordinal: -1}, ref: &ref.Ref{}}
|
||||
func MakeUnresolvedType(namespace, n string) *Type {
|
||||
return &Type{name: name{namespace, n}, Desc: UnresolvedDesc{ordinal: -1}, ref: &ref.Ref{}}
|
||||
}
|
||||
|
||||
func MakeListType(elemType Type) Type {
|
||||
return buildType("", CompoundDesc{ListKind, []Type{elemType}})
|
||||
func MakeListType(elemType *Type) *Type {
|
||||
return buildType("", CompoundDesc{ListKind, []*Type{elemType}})
|
||||
}
|
||||
|
||||
func MakeSetType(elemType Type) Type {
|
||||
return buildType("", CompoundDesc{SetKind, []Type{elemType}})
|
||||
func MakeSetType(elemType *Type) *Type {
|
||||
return buildType("", CompoundDesc{SetKind, []*Type{elemType}})
|
||||
}
|
||||
|
||||
func MakeMapType(keyType, valType Type) Type {
|
||||
return buildType("", CompoundDesc{MapKind, []Type{keyType, valType}})
|
||||
func MakeMapType(keyType, valType *Type) *Type {
|
||||
return buildType("", CompoundDesc{MapKind, []*Type{keyType, valType}})
|
||||
}
|
||||
|
||||
func MakeRefType(elemType Type) Type {
|
||||
return buildType("", CompoundDesc{RefKind, []Type{elemType}})
|
||||
func MakeRefType(elemType *Type) *Type {
|
||||
return buildType("", CompoundDesc{RefKind, []*Type{elemType}})
|
||||
}
|
||||
|
||||
func buildType(n string, desc TypeDesc) Type {
|
||||
func buildType(n string, desc TypeDesc) *Type {
|
||||
if IsPrimitiveKind(desc.Kind()) {
|
||||
return Type{name: name{name: n}, Desc: desc, ref: &ref.Ref{}}
|
||||
return &Type{name: name{name: n}, Desc: desc, ref: &ref.Ref{}}
|
||||
}
|
||||
switch desc.Kind() {
|
||||
case ListKind, RefKind, SetKind, MapKind, StructKind, UnresolvedKind:
|
||||
return Type{name: name{name: n}, Desc: desc, ref: &ref.Ref{}}
|
||||
return &Type{name: name{name: n}, Desc: desc, ref: &ref.Ref{}}
|
||||
default:
|
||||
d.Exp.Fail("Unrecognized Kind:", "%v", desc.Kind())
|
||||
panic("unreachable")
|
||||
|
||||
+2
-2
@@ -92,7 +92,7 @@ func (u UnresolvedDesc) Equals(other TypeDesc) bool {
|
||||
// ElemTypes indicates what type or types are in the container indicated by kind, e.g. Map key and value or Set element.
|
||||
type CompoundDesc struct {
|
||||
kind NomsKind
|
||||
ElemTypes []Type
|
||||
ElemTypes []*Type
|
||||
}
|
||||
|
||||
func (c CompoundDesc) Kind() NomsKind {
|
||||
@@ -143,7 +143,7 @@ func (s StructDesc) Equals(other TypeDesc) bool {
|
||||
// Neither Name nor T is allowed to be a zero-value, though T may be an unresolved Type.
|
||||
type Field struct {
|
||||
Name string
|
||||
T Type
|
||||
T *Type
|
||||
Optional bool
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ func TestTypes(t *testing.T) {
|
||||
Field{"StructField", mahType, false},
|
||||
Field{"StringField", stringType, false},
|
||||
})
|
||||
pkgRef := vs.WriteValue(NewPackage([]Type{}, ref.RefSlice{})).TargetRef()
|
||||
pkgRef := vs.WriteValue(NewPackage([]*Type{}, ref.RefSlice{})).TargetRef()
|
||||
trType := MakeType(pkgRef, 42)
|
||||
|
||||
mRef := vs.WriteValue(mapType).TargetRef()
|
||||
@@ -44,7 +44,7 @@ func TestTypeWithPkgRef(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
vs := NewTestValueStore()
|
||||
|
||||
pkg := NewPackage([]Type{MakePrimitiveType(Float64Kind)}, []ref.Ref{})
|
||||
pkg := NewPackage([]*Type{MakePrimitiveType(Float64Kind)}, []ref.Ref{})
|
||||
|
||||
pkgRef := RegisterPackage(&pkg)
|
||||
unresolvedType := MakeType(pkgRef, 42)
|
||||
|
||||
@@ -34,7 +34,7 @@ func (vbs *ValidatingBatchingSink) Enqueue(c chunks.Chunk) chunks.BackpressureEr
|
||||
v := DecodeChunk(c, vbs.vs)
|
||||
d.Exp.NotNil(v, "Chunk with hash %s failed to decode", r)
|
||||
vbs.vs.checkChunksInCache(v)
|
||||
vbs.vs.set(r, presentChunk(v.Type()))
|
||||
vbs.vs.set(r, (*presentChunk)(v.Type()))
|
||||
|
||||
vbs.batch[vbs.count] = c
|
||||
vbs.count++
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ type Value interface {
|
||||
// Returns the immediate children of this value in the DAG, if any, not including Type().
|
||||
ChildValues() []Value
|
||||
Chunks() []RefBase
|
||||
Type() Type
|
||||
Type() *Type
|
||||
}
|
||||
|
||||
type OrderedValue interface {
|
||||
|
||||
+10
-10
@@ -22,7 +22,7 @@ type ValueStore struct {
|
||||
type chunkCacheEntry interface {
|
||||
Present() bool
|
||||
Hint() ref.Ref
|
||||
Type() Type
|
||||
Type() *Type
|
||||
}
|
||||
|
||||
// NewTestValueStore creates a simple struct that satisfies ValueReadWriter and is backed by a chunks.TestStore.
|
||||
@@ -72,7 +72,7 @@ func (lvs *ValueStore) WriteValue(v Value) RefBase {
|
||||
c := EncodeValue(v, lvs)
|
||||
|
||||
hints := lvs.checkChunksInCache(v)
|
||||
lvs.set(targetRef, presentChunk(v.Type()))
|
||||
lvs.set(targetRef, (*presentChunk)(v.Type()))
|
||||
lvs.bs.SchedulePut(c, hints)
|
||||
|
||||
return r
|
||||
@@ -152,7 +152,7 @@ func (lvs *ValueStore) checkChunksInCache(v Value) map[ref.Ref]struct{} {
|
||||
return hints
|
||||
}
|
||||
|
||||
func getTargetType(refBase RefBase) Type {
|
||||
func getTargetType(refBase RefBase) *Type {
|
||||
refType := refBase.Type()
|
||||
d.Chk.Equal(RefKind, refType.Kind())
|
||||
return refType.Desc.(CompoundDesc).ElemTypes[0]
|
||||
@@ -160,20 +160,20 @@ func getTargetType(refBase RefBase) Type {
|
||||
|
||||
type presentChunk Type
|
||||
|
||||
func (p presentChunk) Present() bool {
|
||||
func (p *presentChunk) Present() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (p presentChunk) Hint() (r ref.Ref) {
|
||||
func (p *presentChunk) Hint() (r ref.Ref) {
|
||||
return
|
||||
}
|
||||
|
||||
func (p presentChunk) Type() Type {
|
||||
return Type(p)
|
||||
func (p *presentChunk) Type() *Type {
|
||||
return (*Type)(p)
|
||||
}
|
||||
|
||||
type hintedChunk struct {
|
||||
t Type
|
||||
t *Type
|
||||
hint ref.Ref
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ func (h hintedChunk) Hint() (r ref.Ref) {
|
||||
return h.hint
|
||||
}
|
||||
|
||||
func (h hintedChunk) Type() Type {
|
||||
func (h hintedChunk) Type() *Type {
|
||||
return h.t
|
||||
}
|
||||
|
||||
@@ -199,6 +199,6 @@ func (a absentChunk) Hint() (r ref.Ref) {
|
||||
return
|
||||
}
|
||||
|
||||
func (a absentChunk) Type() Type {
|
||||
func (a absentChunk) Type() *Type {
|
||||
panic("Not reached. Should never call Type() on an absentChunk.")
|
||||
}
|
||||
|
||||
@@ -50,9 +50,9 @@ func TestWriteValue(t *testing.T) {
|
||||
|
||||
testEncode(fmt.Sprintf("t [%d,\"hi\"]", StringKind), NewString("hi"))
|
||||
|
||||
testEncode(fmt.Sprintf("t [%d,[],[]]", PackageKind), Package{types: []Type{}, dependencies: []ref.Ref{}, ref: &ref.Ref{}})
|
||||
ref1 := testEncode(fmt.Sprintf("t [%d,[%d],[]]", PackageKind, BoolKind), Package{types: []Type{MakePrimitiveType(BoolKind)}, dependencies: []ref.Ref{}, ref: &ref.Ref{}})
|
||||
testEncode(fmt.Sprintf("t [%d,[],[\"%s\"]]", PackageKind, ref1), Package{types: []Type{}, dependencies: []ref.Ref{ref1}, ref: &ref.Ref{}})
|
||||
testEncode(fmt.Sprintf("t [%d,[],[]]", PackageKind), Package{types: []*Type{}, dependencies: []ref.Ref{}, ref: &ref.Ref{}})
|
||||
ref1 := testEncode(fmt.Sprintf("t [%d,[%d],[]]", PackageKind, BoolKind), Package{types: []*Type{MakePrimitiveType(BoolKind)}, dependencies: []ref.Ref{}, ref: &ref.Ref{}})
|
||||
testEncode(fmt.Sprintf("t [%d,[],[\"%s\"]]", PackageKind, ref1), Package{types: []*Type{}, dependencies: []ref.Ref{ref1}, ref: &ref.Ref{}})
|
||||
}
|
||||
|
||||
func TestWriteBlobLeaf(t *testing.T) {
|
||||
@@ -83,7 +83,7 @@ func TestWritePackageWhenValueIsWritten(t *testing.T) {
|
||||
typeDef := MakeStructType("S", []Field{
|
||||
Field{"X", MakePrimitiveType(Int32Kind), false},
|
||||
}, []Field{})
|
||||
pkg1 := NewPackage([]Type{typeDef}, []ref.Ref{})
|
||||
pkg1 := NewPackage([]*Type{typeDef}, []ref.Ref{})
|
||||
// Don't write package
|
||||
pkgRef1 := RegisterPackage(&pkg1)
|
||||
typ := MakeType(pkgRef1, 0)
|
||||
@@ -99,11 +99,11 @@ func TestWritePackageDepWhenPackageIsWritten(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
vs := NewTestValueStore()
|
||||
|
||||
pkg1 := NewPackage([]Type{}, []ref.Ref{})
|
||||
pkg1 := NewPackage([]*Type{}, []ref.Ref{})
|
||||
// Don't write package
|
||||
pkgRef1 := RegisterPackage(&pkg1)
|
||||
|
||||
pkg2 := NewPackage([]Type{}, []ref.Ref{pkgRef1})
|
||||
pkg2 := NewPackage([]*Type{}, []ref.Ref{pkgRef1})
|
||||
vs.WriteValue(pkg2)
|
||||
|
||||
pkg3 := vs.ReadValue(pkgRef1)
|
||||
@@ -117,7 +117,7 @@ func TestCheckChunksInCache(t *testing.T) {
|
||||
|
||||
b := NewEmptyBlob()
|
||||
cs.Put(EncodeValue(b, nil))
|
||||
cvs.set(b.Ref(), presentChunk(b.Type()))
|
||||
cvs.set(b.Ref(), (*presentChunk)(b.Type()))
|
||||
|
||||
bref := NewTypedRefFromValue(b)
|
||||
assert.NotPanics(func() { cvs.checkChunksInCache(bref) })
|
||||
|
||||
Reference in New Issue
Block a user