NomDL Codegen: Add TypeRef method to typed objects

This commit is contained in:
Erik Arvidsson
2015-09-30 17:11:49 -04:00
parent ede5f43204
commit 8c2caa3b27
29 changed files with 814 additions and 463 deletions
+47 -10
View File
@@ -16,7 +16,7 @@ func __mainPackageInFile_types_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"Pitch": __typeRefOfPitch(),
"Pitch": __typeRefForPitch,
},
}.New()
return types.RegisterPackage(&p)
@@ -67,6 +67,13 @@ func (l ListOfMapOfStringToValue) Ref() ref.Ref {
return l.l.Ref()
}
// A Noms Value that describes ListOfMapOfStringToValue.
var __typeRefForListOfMapOfStringToValue = types.MakeCompoundTypeRef("", types.ListKind, types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakePrimitiveTypeRef(types.ValueKind)))
func (m ListOfMapOfStringToValue) TypeRef() types.TypeRef {
return __typeRefForListOfMapOfStringToValue
}
func (l ListOfMapOfStringToValue) Len() uint64 {
return l.l.Len()
}
@@ -185,6 +192,13 @@ func (m MapOfStringToValue) Ref() ref.Ref {
return m.m.Ref()
}
// A Noms Value that describes MapOfStringToValue.
var __typeRefForMapOfStringToValue = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakePrimitiveTypeRef(types.ValueKind))
func (m MapOfStringToValue) TypeRef() types.TypeRef {
return __typeRefForMapOfStringToValue
}
func (m MapOfStringToValue) Empty() bool {
return m.m.Empty()
}
@@ -285,6 +299,13 @@ func (m MapOfStringToListOfPitch) Ref() ref.Ref {
return m.m.Ref()
}
// A Noms Value that describes MapOfStringToListOfPitch.
var __typeRefForMapOfStringToListOfPitch = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Pitch", ref.Ref{})))
func (m MapOfStringToListOfPitch) TypeRef() types.TypeRef {
return __typeRefForMapOfStringToListOfPitch
}
func (m MapOfStringToListOfPitch) Empty() bool {
return m.m.Empty()
}
@@ -384,6 +405,13 @@ func (l ListOfPitch) Ref() ref.Ref {
return l.l.Ref()
}
// A Noms Value that describes ListOfPitch.
var __typeRefForListOfPitch = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Pitch", ref.Ref{}))
func (m ListOfPitch) TypeRef() types.TypeRef {
return __typeRefForListOfPitch
}
func (l ListOfPitch) Len() uint64 {
return l.l.Len()
}
@@ -492,15 +520,17 @@ func (s Pitch) Def() (d PitchDef) {
return
}
// Creates and returns a Noms Value that describes Pitch.
func __typeRefOfPitch() types.TypeRef {
return types.MakeStructTypeRef("Pitch",
[]types.Field{
types.Field{"X", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"Z", types.MakePrimitiveTypeRef(types.Float64Kind), false},
},
types.Choices{},
)
// A Noms Value that describes Pitch.
var __typeRefForPitch = types.MakeStructTypeRef("Pitch",
[]types.Field{
types.Field{"X", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"Z", types.MakePrimitiveTypeRef(types.Float64Kind), false},
},
types.Choices{},
)
func (m Pitch) TypeRef() types.TypeRef {
return __typeRefForPitch
}
func PitchFromVal(val types.Value) Pitch {
@@ -586,6 +616,13 @@ func (m MapOfStringToString) Ref() ref.Ref {
return m.m.Ref()
}
// A Noms Value that describes MapOfStringToString.
var __typeRefForMapOfStringToString = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakePrimitiveTypeRef(types.StringKind))
func (m MapOfStringToString) TypeRef() types.TypeRef {
return __typeRefForMapOfStringToString
}
func (m MapOfStringToString) Empty() bool {
return m.m.Empty()
}
+110 -58
View File
@@ -17,11 +17,11 @@ func __mainPackageInFile_types_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"Geoposition": __typeRefOfGeoposition(),
"Georectangle": __typeRefOfGeorectangle(),
"Node": __typeRefOfNode(),
"QuadTree": __typeRefOfQuadTree(),
"SQuadTree": __typeRefOfSQuadTree(),
"Geoposition": __typeRefForGeoposition,
"Georectangle": __typeRefForGeorectangle,
"Node": __typeRefForNode,
"QuadTree": __typeRefForQuadTree,
"SQuadTree": __typeRefForSQuadTree,
},
}.New()
return types.RegisterPackage(&p)
@@ -63,15 +63,17 @@ func (s Geoposition) Def() (d GeopositionDef) {
return
}
// Creates and returns a Noms Value that describes Geoposition.
func __typeRefOfGeoposition() types.TypeRef {
return types.MakeStructTypeRef("Geoposition",
[]types.Field{
types.Field{"Latitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
types.Field{"Longitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
},
types.Choices{},
)
// A Noms Value that describes Geoposition.
var __typeRefForGeoposition = types.MakeStructTypeRef("Geoposition",
[]types.Field{
types.Field{"Latitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
types.Field{"Longitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
},
types.Choices{},
)
func (m Geoposition) TypeRef() types.TypeRef {
return __typeRefForGeoposition
}
func GeopositionFromVal(val types.Value) Geoposition {
@@ -147,15 +149,17 @@ func (s Georectangle) Def() (d GeorectangleDef) {
return
}
// Creates and returns a Noms Value that describes Georectangle.
func __typeRefOfGeorectangle() types.TypeRef {
return types.MakeStructTypeRef("Georectangle",
[]types.Field{
types.Field{"TopLeft", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
types.Field{"BottomRight", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
},
types.Choices{},
)
// A Noms Value that describes Georectangle.
var __typeRefForGeorectangle = types.MakeStructTypeRef("Georectangle",
[]types.Field{
types.Field{"TopLeft", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
types.Field{"BottomRight", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
},
types.Choices{},
)
func (m Georectangle) TypeRef() types.TypeRef {
return __typeRefForGeorectangle
}
func GeorectangleFromVal(val types.Value) Georectangle {
@@ -231,15 +235,17 @@ func (s Node) Def() (d NodeDef) {
return
}
// Creates and returns a Noms Value that describes Node.
func __typeRefOfNode() types.TypeRef {
return types.MakeStructTypeRef("Node",
[]types.Field{
types.Field{"Geoposition", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
types.Field{"Reference", types.MakeCompoundTypeRef("", types.RefKind, types.MakePrimitiveTypeRef(types.ValueKind)), false},
},
types.Choices{},
)
// A Noms Value that describes Node.
var __typeRefForNode = types.MakeStructTypeRef("Node",
[]types.Field{
types.Field{"Geoposition", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
types.Field{"Reference", types.MakeCompoundTypeRef("", types.RefKind, types.MakePrimitiveTypeRef(types.ValueKind)), false},
},
types.Choices{},
)
func (m Node) TypeRef() types.TypeRef {
return __typeRefForNode
}
func NodeFromVal(val types.Value) Node {
@@ -297,6 +303,13 @@ func (r RefOfValue) Equals(other RefOfValue) bool {
return r.Ref() == other.Ref()
}
// A Noms Value that describes RefOfValue.
var __typeRefForRefOfValue = types.MakeCompoundTypeRef("", types.RefKind, types.MakePrimitiveTypeRef(types.ValueKind))
func (m RefOfValue) TypeRef() types.TypeRef {
return __typeRefForRefOfValue
}
func (r RefOfValue) NomsValue() types.Value {
return types.Ref{R: r.r}
}
@@ -366,19 +379,21 @@ func (s QuadTree) Def() (d QuadTreeDef) {
return
}
// Creates and returns a Noms Value that describes QuadTree.
func __typeRefOfQuadTree() types.TypeRef {
return types.MakeStructTypeRef("QuadTree",
[]types.Field{
types.Field{"Nodes", types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Node", ref.Ref{})), false},
types.Field{"Tiles", types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef("QuadTree", ref.Ref{})), false},
types.Field{"Depth", types.MakePrimitiveTypeRef(types.UInt8Kind), false},
types.Field{"NumDescendents", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
types.Field{"Path", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Georectangle", types.MakeTypeRef("Georectangle", ref.Ref{}), false},
},
types.Choices{},
)
// A Noms Value that describes QuadTree.
var __typeRefForQuadTree = types.MakeStructTypeRef("QuadTree",
[]types.Field{
types.Field{"Nodes", types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Node", ref.Ref{})), false},
types.Field{"Tiles", types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef("QuadTree", ref.Ref{})), false},
types.Field{"Depth", types.MakePrimitiveTypeRef(types.UInt8Kind), false},
types.Field{"NumDescendents", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
types.Field{"Path", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Georectangle", types.MakeTypeRef("Georectangle", ref.Ref{}), false},
},
types.Choices{},
)
func (m QuadTree) TypeRef() types.TypeRef {
return __typeRefForQuadTree
}
func QuadTreeFromVal(val types.Value) QuadTree {
@@ -495,6 +510,13 @@ func (l ListOfNode) Ref() ref.Ref {
return l.l.Ref()
}
// A Noms Value that describes ListOfNode.
var __typeRefForListOfNode = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Node", ref.Ref{}))
func (m ListOfNode) TypeRef() types.TypeRef {
return __typeRefForListOfNode
}
func (l ListOfNode) Len() uint64 {
return l.l.Len()
}
@@ -613,6 +635,13 @@ func (m MapOfStringToQuadTree) Ref() ref.Ref {
return m.m.Ref()
}
// A Noms Value that describes MapOfStringToQuadTree.
var __typeRefForMapOfStringToQuadTree = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef("QuadTree", ref.Ref{}))
func (m MapOfStringToQuadTree) TypeRef() types.TypeRef {
return __typeRefForMapOfStringToQuadTree
}
func (m MapOfStringToQuadTree) Empty() bool {
return m.m.Empty()
}
@@ -719,19 +748,21 @@ func (s SQuadTree) Def() (d SQuadTreeDef) {
return
}
// Creates and returns a Noms Value that describes SQuadTree.
func __typeRefOfSQuadTree() types.TypeRef {
return types.MakeStructTypeRef("SQuadTree",
[]types.Field{
types.Field{"Nodes", types.MakeCompoundTypeRef("", types.ListKind, types.MakeCompoundTypeRef("", types.RefKind, types.MakePrimitiveTypeRef(types.ValueKind))), false},
types.Field{"Tiles", types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeCompoundTypeRef("", types.RefKind, types.MakeTypeRef("SQuadTree", ref.Ref{}))), false},
types.Field{"Depth", types.MakePrimitiveTypeRef(types.UInt8Kind), false},
types.Field{"NumDescendents", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
types.Field{"Path", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Georectangle", types.MakeTypeRef("Georectangle", ref.Ref{}), false},
},
types.Choices{},
)
// A Noms Value that describes SQuadTree.
var __typeRefForSQuadTree = types.MakeStructTypeRef("SQuadTree",
[]types.Field{
types.Field{"Nodes", types.MakeCompoundTypeRef("", types.ListKind, types.MakeCompoundTypeRef("", types.RefKind, types.MakePrimitiveTypeRef(types.ValueKind))), false},
types.Field{"Tiles", types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeCompoundTypeRef("", types.RefKind, types.MakeTypeRef("SQuadTree", ref.Ref{}))), false},
types.Field{"Depth", types.MakePrimitiveTypeRef(types.UInt8Kind), false},
types.Field{"NumDescendents", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
types.Field{"Path", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Georectangle", types.MakeTypeRef("Georectangle", ref.Ref{}), false},
},
types.Choices{},
)
func (m SQuadTree) TypeRef() types.TypeRef {
return __typeRefForSQuadTree
}
func SQuadTreeFromVal(val types.Value) SQuadTree {
@@ -848,6 +879,13 @@ func (l ListOfRefOfValue) Ref() ref.Ref {
return l.l.Ref()
}
// A Noms Value that describes ListOfRefOfValue.
var __typeRefForListOfRefOfValue = types.MakeCompoundTypeRef("", types.ListKind, types.MakeCompoundTypeRef("", types.RefKind, types.MakePrimitiveTypeRef(types.ValueKind)))
func (m ListOfRefOfValue) TypeRef() types.TypeRef {
return __typeRefForListOfRefOfValue
}
func (l ListOfRefOfValue) Len() uint64 {
return l.l.Len()
}
@@ -966,6 +1004,13 @@ func (m MapOfStringToRefOfSQuadTree) Ref() ref.Ref {
return m.m.Ref()
}
// A Noms Value that describes MapOfStringToRefOfSQuadTree.
var __typeRefForMapOfStringToRefOfSQuadTree = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeCompoundTypeRef("", types.RefKind, types.MakeTypeRef("SQuadTree", ref.Ref{})))
func (m MapOfStringToRefOfSQuadTree) TypeRef() types.TypeRef {
return __typeRefForMapOfStringToRefOfSQuadTree
}
func (m MapOfStringToRefOfSQuadTree) Empty() bool {
return m.m.Empty()
}
@@ -1038,6 +1083,13 @@ func (r RefOfSQuadTree) Equals(other RefOfSQuadTree) bool {
return r.Ref() == other.Ref()
}
// A Noms Value that describes RefOfSQuadTree.
var __typeRefForRefOfSQuadTree = types.MakeCompoundTypeRef("", types.RefKind, types.MakeTypeRef("SQuadTree", ref.Ref{}))
func (m RefOfSQuadTree) TypeRef() types.TypeRef {
return __typeRefForRefOfSQuadTree
}
func (r RefOfSQuadTree) NomsValue() types.Value {
return types.Ref{R: r.r}
}
+186 -118
View File
@@ -7,18 +7,34 @@ import (
"github.com/attic-labs/noms/types"
)
var __mainPackageInFile_types_CachedRef = __mainPackageInFile_types_Ref()
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func __mainPackageInFile_types_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"Geoposition": __typeRefForGeoposition,
"Incident": __typeRefForIncident,
},
}.New()
return types.RegisterPackage(&p)
}
// ListOfIncident
type ListOfIncident struct {
l types.List
}
type ListOfIncidentDef []IncidentDef
func NewListOfIncident() ListOfIncident {
return ListOfIncident{types.NewList()}
}
type ListOfIncidentDef []IncidentDef
func (def ListOfIncidentDef) New() ListOfIncident {
l := make([]types.Value, len(def))
for i, d := range def {
@@ -27,21 +43,21 @@ func (def ListOfIncidentDef) New() ListOfIncident {
return ListOfIncident{types.NewList(l...)}
}
func (l ListOfIncident) Def() ListOfIncidentDef {
d := make([]IncidentDef, l.Len())
for i := uint64(0); i < l.Len(); i++ {
d[i] = IncidentFromVal(l.l.Get(i)).Def()
}
return d
}
func ListOfIncidentFromVal(val types.Value) ListOfIncident {
// TODO: Validate here
return ListOfIncident{val.(types.List)}
}
func (self ListOfIncident) Def() ListOfIncidentDef {
l := make([]IncidentDef, self.Len())
for i := uint64(0); i < self.Len(); i++ {
l[i] = IncidentFromVal(self.l.Get(i)).Def()
}
return l
}
func (self ListOfIncident) NomsValue() types.Value {
return self.l
func (l ListOfIncident) NomsValue() types.Value {
return l.l
}
func (l ListOfIncident) Equals(p ListOfIncident) bool {
@@ -52,6 +68,13 @@ func (l ListOfIncident) Ref() ref.Ref {
return l.l.Ref()
}
// A Noms Value that describes ListOfIncident.
var __typeRefForListOfIncident = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Incident", ref.Ref{}))
func (m ListOfIncident) TypeRef() types.TypeRef {
return __typeRefForListOfIncident
}
func (l ListOfIncident) Len() uint64 {
return l.l.Len()
}
@@ -60,16 +83,16 @@ func (l ListOfIncident) Empty() bool {
return l.Len() == uint64(0)
}
func (self ListOfIncident) Get(i uint64) Incident {
return IncidentFromVal(self.l.Get(i))
func (l ListOfIncident) Get(i uint64) Incident {
return IncidentFromVal(l.l.Get(i))
}
func (l ListOfIncident) Slice(idx uint64, end uint64) ListOfIncident {
return ListOfIncident{l.l.Slice(idx, end)}
}
func (self ListOfIncident) Set(i uint64, val Incident) ListOfIncident {
return ListOfIncident{self.l.Set(i, val.NomsValue())}
func (l ListOfIncident) Set(i uint64, val Incident) ListOfIncident {
return ListOfIncident{l.l.Set(i, val.NomsValue())}
}
func (l ListOfIncident) Append(v ...Incident) ListOfIncident {
@@ -126,20 +149,6 @@ func (l ListOfIncident) Filter(cb ListOfIncidentFilterCallback) ListOfIncident {
// Incident
type IncidentDef struct {
ID int64
Category string
Description string
DayOfWeek string
Date string
Time string
PdDistrict string
Resolution string
Address string
Geoposition GeopositionDef
PdID string
}
type Incident struct {
m types.Map
}
@@ -147,6 +156,7 @@ type Incident struct {
func NewIncident() Incident {
return Incident{types.NewMap(
types.NewString("$name"), types.NewString("Incident"),
types.NewString("$type"), types.MakeTypeRef("Incident", __mainPackageInFile_types_CachedRef),
types.NewString("ID"), types.Int64(0),
types.NewString("Category"), types.NewString(""),
types.NewString("Description"), types.NewString(""),
@@ -161,10 +171,25 @@ func NewIncident() Incident {
)}
}
type IncidentDef struct {
ID int64
Category string
Description string
DayOfWeek string
Date string
Time string
PdDistrict string
Resolution string
Address string
Geoposition GeopositionDef
PdID string
}
func (def IncidentDef) New() Incident {
return Incident{
types.NewMap(
types.NewString("$name"), types.NewString("Incident"),
types.NewString("$type"), types.MakeTypeRef("Incident", __mainPackageInFile_types_CachedRef),
types.NewString("ID"), types.Int64(def.ID),
types.NewString("Category"), types.NewString(def.Category),
types.NewString("Description"), types.NewString(def.Description),
@@ -179,20 +204,41 @@ func (def IncidentDef) New() Incident {
)}
}
func (self Incident) Def() IncidentDef {
return IncidentDef{
int64(self.m.Get(types.NewString("ID")).(types.Int64)),
self.m.Get(types.NewString("Category")).(types.String).String(),
self.m.Get(types.NewString("Description")).(types.String).String(),
self.m.Get(types.NewString("DayOfWeek")).(types.String).String(),
self.m.Get(types.NewString("Date")).(types.String).String(),
self.m.Get(types.NewString("Time")).(types.String).String(),
self.m.Get(types.NewString("PdDistrict")).(types.String).String(),
self.m.Get(types.NewString("Resolution")).(types.String).String(),
self.m.Get(types.NewString("Address")).(types.String).String(),
GeopositionFromVal(self.m.Get(types.NewString("Geoposition"))).Def(),
self.m.Get(types.NewString("PdID")).(types.String).String(),
}
func (s Incident) Def() (d IncidentDef) {
d.ID = int64(s.m.Get(types.NewString("ID")).(types.Int64))
d.Category = s.m.Get(types.NewString("Category")).(types.String).String()
d.Description = s.m.Get(types.NewString("Description")).(types.String).String()
d.DayOfWeek = s.m.Get(types.NewString("DayOfWeek")).(types.String).String()
d.Date = s.m.Get(types.NewString("Date")).(types.String).String()
d.Time = s.m.Get(types.NewString("Time")).(types.String).String()
d.PdDistrict = s.m.Get(types.NewString("PdDistrict")).(types.String).String()
d.Resolution = s.m.Get(types.NewString("Resolution")).(types.String).String()
d.Address = s.m.Get(types.NewString("Address")).(types.String).String()
d.Geoposition = GeopositionFromVal(s.m.Get(types.NewString("Geoposition"))).Def()
d.PdID = s.m.Get(types.NewString("PdID")).(types.String).String()
return
}
// A Noms Value that describes Incident.
var __typeRefForIncident = types.MakeStructTypeRef("Incident",
[]types.Field{
types.Field{"ID", types.MakePrimitiveTypeRef(types.Int64Kind), false},
types.Field{"Category", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Description", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"DayOfWeek", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Date", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Time", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"PdDistrict", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Resolution", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Address", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Geoposition", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
types.Field{"PdID", types.MakePrimitiveTypeRef(types.StringKind), false},
},
types.Choices{},
)
func (m Incident) TypeRef() types.TypeRef {
return __typeRefForIncident
}
func IncidentFromVal(val types.Value) Incident {
@@ -200,113 +246,112 @@ func IncidentFromVal(val types.Value) Incident {
return Incident{val.(types.Map)}
}
func (self Incident) NomsValue() types.Value {
return self.m
func (s Incident) NomsValue() types.Value {
return s.m
}
func (self Incident) Equals(other Incident) bool {
return self.m.Equals(other.m)
func (s Incident) Equals(other Incident) bool {
return s.m.Equals(other.m)
}
func (self Incident) Ref() ref.Ref {
return self.m.Ref()
func (s Incident) Ref() ref.Ref {
return s.m.Ref()
}
func (self Incident) ID() int64 {
return int64(self.m.Get(types.NewString("ID")).(types.Int64))
func (s Incident) Type() types.TypeRef {
return s.m.Get(types.NewString("$type")).(types.TypeRef)
}
func (self Incident) SetID(val int64) Incident {
return Incident{self.m.Set(types.NewString("ID"), types.Int64(val))}
func (s Incident) ID() int64 {
return int64(s.m.Get(types.NewString("ID")).(types.Int64))
}
func (self Incident) Category() string {
return self.m.Get(types.NewString("Category")).(types.String).String()
func (s Incident) SetID(val int64) Incident {
return Incident{s.m.Set(types.NewString("ID"), types.Int64(val))}
}
func (self Incident) SetCategory(val string) Incident {
return Incident{self.m.Set(types.NewString("Category"), types.NewString(val))}
func (s Incident) Category() string {
return s.m.Get(types.NewString("Category")).(types.String).String()
}
func (self Incident) Description() string {
return self.m.Get(types.NewString("Description")).(types.String).String()
func (s Incident) SetCategory(val string) Incident {
return Incident{s.m.Set(types.NewString("Category"), types.NewString(val))}
}
func (self Incident) SetDescription(val string) Incident {
return Incident{self.m.Set(types.NewString("Description"), types.NewString(val))}
func (s Incident) Description() string {
return s.m.Get(types.NewString("Description")).(types.String).String()
}
func (self Incident) DayOfWeek() string {
return self.m.Get(types.NewString("DayOfWeek")).(types.String).String()
func (s Incident) SetDescription(val string) Incident {
return Incident{s.m.Set(types.NewString("Description"), types.NewString(val))}
}
func (self Incident) SetDayOfWeek(val string) Incident {
return Incident{self.m.Set(types.NewString("DayOfWeek"), types.NewString(val))}
func (s Incident) DayOfWeek() string {
return s.m.Get(types.NewString("DayOfWeek")).(types.String).String()
}
func (self Incident) Date() string {
return self.m.Get(types.NewString("Date")).(types.String).String()
func (s Incident) SetDayOfWeek(val string) Incident {
return Incident{s.m.Set(types.NewString("DayOfWeek"), types.NewString(val))}
}
func (self Incident) SetDate(val string) Incident {
return Incident{self.m.Set(types.NewString("Date"), types.NewString(val))}
func (s Incident) Date() string {
return s.m.Get(types.NewString("Date")).(types.String).String()
}
func (self Incident) Time() string {
return self.m.Get(types.NewString("Time")).(types.String).String()
func (s Incident) SetDate(val string) Incident {
return Incident{s.m.Set(types.NewString("Date"), types.NewString(val))}
}
func (self Incident) SetTime(val string) Incident {
return Incident{self.m.Set(types.NewString("Time"), types.NewString(val))}
func (s Incident) Time() string {
return s.m.Get(types.NewString("Time")).(types.String).String()
}
func (self Incident) PdDistrict() string {
return self.m.Get(types.NewString("PdDistrict")).(types.String).String()
func (s Incident) SetTime(val string) Incident {
return Incident{s.m.Set(types.NewString("Time"), types.NewString(val))}
}
func (self Incident) SetPdDistrict(val string) Incident {
return Incident{self.m.Set(types.NewString("PdDistrict"), types.NewString(val))}
func (s Incident) PdDistrict() string {
return s.m.Get(types.NewString("PdDistrict")).(types.String).String()
}
func (self Incident) Resolution() string {
return self.m.Get(types.NewString("Resolution")).(types.String).String()
func (s Incident) SetPdDistrict(val string) Incident {
return Incident{s.m.Set(types.NewString("PdDistrict"), types.NewString(val))}
}
func (self Incident) SetResolution(val string) Incident {
return Incident{self.m.Set(types.NewString("Resolution"), types.NewString(val))}
func (s Incident) Resolution() string {
return s.m.Get(types.NewString("Resolution")).(types.String).String()
}
func (self Incident) Address() string {
return self.m.Get(types.NewString("Address")).(types.String).String()
func (s Incident) SetResolution(val string) Incident {
return Incident{s.m.Set(types.NewString("Resolution"), types.NewString(val))}
}
func (self Incident) SetAddress(val string) Incident {
return Incident{self.m.Set(types.NewString("Address"), types.NewString(val))}
func (s Incident) Address() string {
return s.m.Get(types.NewString("Address")).(types.String).String()
}
func (self Incident) Geoposition() Geoposition {
return GeopositionFromVal(self.m.Get(types.NewString("Geoposition")))
func (s Incident) SetAddress(val string) Incident {
return Incident{s.m.Set(types.NewString("Address"), types.NewString(val))}
}
func (self Incident) SetGeoposition(val Geoposition) Incident {
return Incident{self.m.Set(types.NewString("Geoposition"), val.NomsValue())}
func (s Incident) Geoposition() Geoposition {
return GeopositionFromVal(s.m.Get(types.NewString("Geoposition")))
}
func (self Incident) PdID() string {
return self.m.Get(types.NewString("PdID")).(types.String).String()
func (s Incident) SetGeoposition(val Geoposition) Incident {
return Incident{s.m.Set(types.NewString("Geoposition"), val.NomsValue())}
}
func (self Incident) SetPdID(val string) Incident {
return Incident{self.m.Set(types.NewString("PdID"), types.NewString(val))}
func (s Incident) PdID() string {
return s.m.Get(types.NewString("PdID")).(types.String).String()
}
func (s Incident) SetPdID(val string) Incident {
return Incident{s.m.Set(types.NewString("PdID"), types.NewString(val))}
}
// Geoposition
type GeopositionDef struct {
Latitude float32
Longitude float32
}
type Geoposition struct {
m types.Map
}
@@ -314,25 +359,44 @@ type Geoposition struct {
func NewGeoposition() Geoposition {
return Geoposition{types.NewMap(
types.NewString("$name"), types.NewString("Geoposition"),
types.NewString("$type"), types.MakeTypeRef("Geoposition", __mainPackageInFile_types_CachedRef),
types.NewString("Latitude"), types.Float32(0),
types.NewString("Longitude"), types.Float32(0),
)}
}
type GeopositionDef struct {
Latitude float32
Longitude float32
}
func (def GeopositionDef) New() Geoposition {
return Geoposition{
types.NewMap(
types.NewString("$name"), types.NewString("Geoposition"),
types.NewString("$type"), types.MakeTypeRef("Geoposition", __mainPackageInFile_types_CachedRef),
types.NewString("Latitude"), types.Float32(def.Latitude),
types.NewString("Longitude"), types.Float32(def.Longitude),
)}
}
func (self Geoposition) Def() GeopositionDef {
return GeopositionDef{
float32(self.m.Get(types.NewString("Latitude")).(types.Float32)),
float32(self.m.Get(types.NewString("Longitude")).(types.Float32)),
}
func (s Geoposition) Def() (d GeopositionDef) {
d.Latitude = float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
d.Longitude = float32(s.m.Get(types.NewString("Longitude")).(types.Float32))
return
}
// A Noms Value that describes Geoposition.
var __typeRefForGeoposition = types.MakeStructTypeRef("Geoposition",
[]types.Field{
types.Field{"Latitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
types.Field{"Longitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
},
types.Choices{},
)
func (m Geoposition) TypeRef() types.TypeRef {
return __typeRefForGeoposition
}
func GeopositionFromVal(val types.Value) Geoposition {
@@ -340,30 +404,34 @@ func GeopositionFromVal(val types.Value) Geoposition {
return Geoposition{val.(types.Map)}
}
func (self Geoposition) NomsValue() types.Value {
return self.m
func (s Geoposition) NomsValue() types.Value {
return s.m
}
func (self Geoposition) Equals(other Geoposition) bool {
return self.m.Equals(other.m)
func (s Geoposition) Equals(other Geoposition) bool {
return s.m.Equals(other.m)
}
func (self Geoposition) Ref() ref.Ref {
return self.m.Ref()
func (s Geoposition) Ref() ref.Ref {
return s.m.Ref()
}
func (self Geoposition) Latitude() float32 {
return float32(self.m.Get(types.NewString("Latitude")).(types.Float32))
func (s Geoposition) Type() types.TypeRef {
return s.m.Get(types.NewString("$type")).(types.TypeRef)
}
func (self Geoposition) SetLatitude(val float32) Geoposition {
return Geoposition{self.m.Set(types.NewString("Latitude"), types.Float32(val))}
func (s Geoposition) Latitude() float32 {
return float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
}
func (self Geoposition) Longitude() float32 {
return float32(self.m.Get(types.NewString("Longitude")).(types.Float32))
func (s Geoposition) SetLatitude(val float32) Geoposition {
return Geoposition{s.m.Set(types.NewString("Latitude"), types.Float32(val))}
}
func (self Geoposition) SetLongitude(val float32) Geoposition {
return Geoposition{self.m.Set(types.NewString("Longitude"), types.Float32(val))}
func (s Geoposition) Longitude() float32 {
return float32(s.m.Get(types.NewString("Longitude")).(types.Float32))
}
func (s Geoposition) SetLongitude(val float32) Geoposition {
return Geoposition{s.m.Set(types.NewString("Longitude"), types.Float32(val))}
}
+69 -47
View File
@@ -16,10 +16,10 @@ func __mainPackageInFile_types_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"Geoposition": __typeRefOfGeoposition(),
"Georectangle": __typeRefOfGeorectangle(),
"Incident": __typeRefOfIncident(),
"SQuadTree": __typeRefOfSQuadTree(),
"Geoposition": __typeRefForGeoposition,
"Georectangle": __typeRefForGeorectangle,
"Incident": __typeRefForIncident,
"SQuadTree": __typeRefForSQuadTree,
},
}.New()
return types.RegisterPackage(&p)
@@ -70,6 +70,13 @@ func (l ListOfIncident) Ref() ref.Ref {
return l.l.Ref()
}
// A Noms Value that describes ListOfIncident.
var __typeRefForListOfIncident = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Incident", ref.Ref{}))
func (m ListOfIncident) TypeRef() types.TypeRef {
return __typeRefForListOfIncident
}
func (l ListOfIncident) Len() uint64 {
return l.l.Len()
}
@@ -190,18 +197,20 @@ func (s Incident) Def() (d IncidentDef) {
return
}
// Creates and returns a Noms Value that describes Incident.
func __typeRefOfIncident() types.TypeRef {
return types.MakeStructTypeRef("Incident",
[]types.Field{
types.Field{"Category", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Description", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Address", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Date", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Geoposition", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
},
types.Choices{},
)
// A Noms Value that describes Incident.
var __typeRefForIncident = types.MakeStructTypeRef("Incident",
[]types.Field{
types.Field{"Category", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Description", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Address", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Date", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Geoposition", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
},
types.Choices{},
)
func (m Incident) TypeRef() types.TypeRef {
return __typeRefForIncident
}
func IncidentFromVal(val types.Value) Incident {
@@ -301,15 +310,17 @@ func (s Geoposition) Def() (d GeopositionDef) {
return
}
// Creates and returns a Noms Value that describes Geoposition.
func __typeRefOfGeoposition() types.TypeRef {
return types.MakeStructTypeRef("Geoposition",
[]types.Field{
types.Field{"Latitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
types.Field{"Longitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
},
types.Choices{},
)
// A Noms Value that describes Geoposition.
var __typeRefForGeoposition = types.MakeStructTypeRef("Geoposition",
[]types.Field{
types.Field{"Latitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
types.Field{"Longitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
},
types.Choices{},
)
func (m Geoposition) TypeRef() types.TypeRef {
return __typeRefForGeoposition
}
func GeopositionFromVal(val types.Value) Geoposition {
@@ -385,15 +396,17 @@ func (s Georectangle) Def() (d GeorectangleDef) {
return
}
// Creates and returns a Noms Value that describes Georectangle.
func __typeRefOfGeorectangle() types.TypeRef {
return types.MakeStructTypeRef("Georectangle",
[]types.Field{
types.Field{"TopLeft", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
types.Field{"BottomRight", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
},
types.Choices{},
)
// A Noms Value that describes Georectangle.
var __typeRefForGeorectangle = types.MakeStructTypeRef("Georectangle",
[]types.Field{
types.Field{"TopLeft", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
types.Field{"BottomRight", types.MakeTypeRef("Geoposition", ref.Ref{}), false},
},
types.Choices{},
)
func (m Georectangle) TypeRef() types.TypeRef {
return __typeRefForGeorectangle
}
func GeorectangleFromVal(val types.Value) Georectangle {
@@ -485,19 +498,21 @@ func (s SQuadTree) Def() (d SQuadTreeDef) {
return
}
// Creates and returns a Noms Value that describes SQuadTree.
func __typeRefOfSQuadTree() types.TypeRef {
return types.MakeStructTypeRef("SQuadTree",
[]types.Field{
types.Field{"Nodes", types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Incident", ref.Ref{})), false},
types.Field{"Tiles", types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef("SQuadTree", ref.Ref{})), false},
types.Field{"Depth", types.MakePrimitiveTypeRef(types.UInt8Kind), false},
types.Field{"NumDescendents", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
types.Field{"Path", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Georectangle", types.MakeTypeRef("Georectangle", ref.Ref{}), false},
},
types.Choices{},
)
// A Noms Value that describes SQuadTree.
var __typeRefForSQuadTree = types.MakeStructTypeRef("SQuadTree",
[]types.Field{
types.Field{"Nodes", types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Incident", ref.Ref{})), false},
types.Field{"Tiles", types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef("SQuadTree", ref.Ref{})), false},
types.Field{"Depth", types.MakePrimitiveTypeRef(types.UInt8Kind), false},
types.Field{"NumDescendents", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
types.Field{"Path", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Georectangle", types.MakeTypeRef("Georectangle", ref.Ref{}), false},
},
types.Choices{},
)
func (m SQuadTree) TypeRef() types.TypeRef {
return __typeRefForSQuadTree
}
func SQuadTreeFromVal(val types.Value) SQuadTree {
@@ -615,6 +630,13 @@ func (m MapOfStringToSQuadTree) Ref() ref.Ref {
return m.m.Ref()
}
// A Noms Value that describes MapOfStringToSQuadTree.
var __typeRefForMapOfStringToSQuadTree = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef("SQuadTree", ref.Ref{}))
func (m MapOfStringToSQuadTree) TypeRef() types.TypeRef {
return __typeRefForMapOfStringToSQuadTree
}
func (m MapOfStringToSQuadTree) Empty() bool {
return m.m.Empty()
}
+19 -10
View File
@@ -16,7 +16,7 @@ func __datasPackageInFile_types_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"Commit": __typeRefOfCommit(),
"Commit": __typeRefForCommit,
},
}.New()
return types.RegisterPackage(&p)
@@ -37,15 +37,17 @@ func NewCommit() Commit {
)}
}
// Creates and returns a Noms Value that describes Commit.
func __typeRefOfCommit() types.TypeRef {
return types.MakeStructTypeRef("Commit",
[]types.Field{
types.Field{"value", types.MakePrimitiveTypeRef(types.ValueKind), false},
types.Field{"parents", types.MakeCompoundTypeRef("", types.SetKind, types.MakeTypeRef("Commit", ref.Ref{})), false},
},
types.Choices{},
)
// A Noms Value that describes Commit.
var __typeRefForCommit = types.MakeStructTypeRef("Commit",
[]types.Field{
types.Field{"value", types.MakePrimitiveTypeRef(types.ValueKind), false},
types.Field{"parents", types.MakeCompoundTypeRef("", types.SetKind, types.MakeTypeRef("Commit", ref.Ref{})), false},
},
types.Choices{},
)
func (m Commit) TypeRef() types.TypeRef {
return __typeRefForCommit
}
func CommitFromVal(val types.Value) Commit {
@@ -111,6 +113,13 @@ func (s SetOfCommit) Ref() ref.Ref {
return s.s.Ref()
}
// A Noms Value that describes SetOfCommit.
var __typeRefForSetOfCommit = types.MakeCompoundTypeRef("", types.SetKind, types.MakeTypeRef("Commit", ref.Ref{}))
func (m SetOfCommit) TypeRef() types.TypeRef {
return __typeRefForSetOfCommit
}
func (s SetOfCommit) Empty() bool {
return s.s.Empty()
}
+19 -10
View File
@@ -16,7 +16,7 @@ func __mgmtPackageInFile_types_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"Dataset": __typeRefOfDataset(),
"Dataset": __typeRefForDataset,
},
}.New()
return types.RegisterPackage(&p)
@@ -69,6 +69,13 @@ func (s SetOfDataset) Ref() ref.Ref {
return s.s.Ref()
}
// A Noms Value that describes SetOfDataset.
var __typeRefForSetOfDataset = types.MakeCompoundTypeRef("", types.SetKind, types.MakeTypeRef("Dataset", ref.Ref{}))
func (m SetOfDataset) TypeRef() types.TypeRef {
return __typeRefForSetOfDataset
}
func (s SetOfDataset) Empty() bool {
return s.s.Empty()
}
@@ -181,15 +188,17 @@ func (s Dataset) Def() (d DatasetDef) {
return
}
// Creates and returns a Noms Value that describes Dataset.
func __typeRefOfDataset() types.TypeRef {
return types.MakeStructTypeRef("Dataset",
[]types.Field{
types.Field{"id", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"head", types.MakePrimitiveTypeRef(types.ValueKind), false},
},
types.Choices{},
)
// A Noms Value that describes Dataset.
var __typeRefForDataset = types.MakeStructTypeRef("Dataset",
[]types.Field{
types.Field{"id", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"head", types.MakePrimitiveTypeRef(types.ValueKind), false},
},
types.Choices{},
)
func (m Dataset) TypeRef() types.TypeRef {
return __typeRefForDataset
}
func DatasetFromVal(val types.Value) Dataset {
+19 -4
View File
@@ -73,6 +73,9 @@ func generate(packageName, in, out string) {
gen.WritePackage(packageName)
bs, err := imports.Process(out, buf.Bytes(), nil)
if err != nil {
fmt.Println(buf.String())
}
d.Chk.NoError(err)
outFile, err := os.OpenFile(out, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
@@ -400,7 +403,7 @@ func (gen *codeGen) toTypesTypeRef(t types.TypeRef) string {
}
return fmt.Sprintf(`types.MakeCompoundTypeRef("%s", types.%sKind, %s)`, t.Name(), kindToString(t.Desc.Kind()), strings.Join(typerefs, ", "))
case types.EnumDesc:
return fmt.Sprintf(`types.MakeEnumTypeRef("%s", %s)`, t.Name(), strings.Join(desc.IDs, ", "))
return fmt.Sprintf(`types.MakeEnumTypeRef("%s", "%s")`, t.Name(), strings.Join(desc.IDs, `", "`))
case types.StructDesc:
flatten := func(f []types.Field) string {
out := make([]string, 0, len(f))
@@ -409,9 +412,9 @@ func (gen *codeGen) toTypesTypeRef(t types.TypeRef) string {
}
return strings.Join(out, "\n")
}
fields := fmt.Sprintf("[]types.Field{%s}", flatten(desc.Fields))
choices := fmt.Sprintf("types.Choices{%s}", flatten(desc.Union))
return fmt.Sprintf(`types.MakeStructTypeRef("%s", %s, %s)`, t.Name(), fields, choices)
fields := fmt.Sprintf("[]types.Field{\n%s\n}", flatten(desc.Fields))
choices := fmt.Sprintf("types.Choices{\n%s\n}", flatten(desc.Union))
return fmt.Sprintf("types.MakeStructTypeRef(\"%s\",\n%s,\n%s,\n)", t.Name(), fields, choices)
default:
d.Chk.Fail("Unknown TypeDesc.", "%#v (%T)", desc, desc)
}
@@ -493,6 +496,7 @@ func (gen *codeGen) writeStruct(t types.TypeRef) {
FileID string
PackageName string
Name string
Type types.TypeRef
Fields []types.Field
Choices types.Choices
HasUnion bool
@@ -502,6 +506,7 @@ func (gen *codeGen) writeStruct(t types.TypeRef) {
gen.fileid,
gen.pkg.Name,
gen.userName(t),
t,
desc.Fields,
nil,
desc.Union != nil,
@@ -527,10 +532,12 @@ func (gen *codeGen) writeList(t types.TypeRef) {
elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
data := struct {
Name string
Type types.TypeRef
ElemType types.TypeRef
CanUseDef bool
}{
gen.userName(t),
t,
elemTypes[0],
gen.canUseDef(t),
}
@@ -542,11 +549,13 @@ func (gen *codeGen) writeMap(t types.TypeRef) {
elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
data := struct {
Name string
Type types.TypeRef
KeyType types.TypeRef
ValueType types.TypeRef
CanUseDef bool
}{
gen.userName(t),
t,
elemTypes[0],
elemTypes[1],
gen.canUseDef(t),
@@ -560,9 +569,11 @@ func (gen *codeGen) writeRef(t types.TypeRef) {
elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
data := struct {
Name string
Type types.TypeRef
ElemType types.TypeRef
}{
gen.userName(t),
t,
elemTypes[0],
}
gen.writeTemplate("ref.tmpl", t, data)
@@ -573,10 +584,12 @@ func (gen *codeGen) writeSet(t types.TypeRef) {
elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
data := struct {
Name string
Type types.TypeRef
ElemType types.TypeRef
CanUseDef bool
}{
gen.userName(t),
t,
elemTypes[0],
gen.canUseDef(t),
}
@@ -587,9 +600,11 @@ func (gen *codeGen) writeSet(t types.TypeRef) {
func (gen *codeGen) writeEnum(t types.TypeRef) {
data := struct {
Name string
Type types.TypeRef
Ids []string
}{
t.Name(),
t,
t.Desc.(types.EnumDesc).IDs,
}
gen.writeTemplate("enum.tmpl", t, data)
+2 -6
View File
@@ -7,9 +7,5 @@ const ({{range $index, $id := .Ids}}
{{title $id}}{{if eq $index 0}} {{$name}} = iota{{end}}{{end}}
)
// Creates and returns a Noms Value that describes {{.Name}}.
func __typeRefOf{{.Name}}() types.TypeRef {
return types.MakeEnumTypeRef("{{.Name}}", {{range $id := .Ids}}"{{$id}}",
{{end}})
}
// A Noms Value that describes {{.Name}}.
var __typeRefFor{{.Name}} = {{toTypesTypeRef .Type}}
+1 -1
View File
@@ -12,7 +12,7 @@ func __{{.Name}}PackageInFile_{{.FileID}}_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
{{range $name, $t := .NamedTypes}}
"{{$name}}": __typeRefOf{{$name}}(),{{end}}
"{{$name}}": __typeRefFor{{$name}},{{end}}
},
}.New()
return types.RegisterPackage(&p)
+2
View File
@@ -46,6 +46,8 @@ func (l {{.Name}}) Ref() ref.Ref {
return l.l.Ref()
}
{{template "type_ref.tmpl" .}}
func (l {{.Name}}) Len() uint64 {
return l.l.Len()
}
+2
View File
@@ -47,6 +47,8 @@ func (m {{.Name}}) Ref() ref.Ref {
return m.m.Ref()
}
{{template "type_ref.tmpl" .}}
func (m {{.Name}}) Empty() bool {
return m.m.Empty()
}
+2
View File
@@ -16,6 +16,8 @@ func (r {{.Name}}) Equals(other {{.Name}}) bool {
return r.Ref() == other.Ref()
}
{{template "type_ref.tmpl" .}}
func (r {{.Name}}) NomsValue() types.Value {
return types.Ref{R: r.r}
}
+2
View File
@@ -47,6 +47,8 @@ func (s {{.Name}}) Ref() ref.Ref {
return s.s.Ref()
}
{{template "type_ref.tmpl" .}}
func (s {{.Name}}) Empty() bool {
return s.s.Empty()
}
+1 -13
View File
@@ -61,19 +61,7 @@ func New{{.Name}}() {{.Name}} {
{{end}}
{{end}}
// Creates and returns a Noms Value that describes {{.Name}}.
func __typeRefOf{{.Name}}() types.TypeRef {
return types.MakeStructTypeRef("{{.Name}}",
[]types.Field{
{{range .Fields}}types.Field{"{{.Name}}", {{toTypesTypeRef .T}}, {{.Optional}}},
{{end}}
},
types.Choices{
{{range .Choices}}types.Field{"{{.Name}}", {{toTypesTypeRef .T}}, {{.Optional}}},
{{end}}
},
)
}
{{template "type_ref.tmpl" .}}
func {{.Name}}FromVal(val types.Value) {{.Name}} {
// TODO: Validate here
+14 -17
View File
@@ -16,8 +16,8 @@ func __testPackageInFile_enum_struct_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"EnumStruct": __typeRefOfEnumStruct(),
"Handedness": __typeRefOfHandedness(),
"EnumStruct": __typeRefForEnumStruct,
"Handedness": __typeRefForHandedness,
},
}.New()
return types.RegisterPackage(&p)
@@ -55,14 +55,16 @@ func (s EnumStruct) Def() (d EnumStructDef) {
return
}
// Creates and returns a Noms Value that describes EnumStruct.
func __typeRefOfEnumStruct() types.TypeRef {
return types.MakeStructTypeRef("EnumStruct",
[]types.Field{
types.Field{"hand", types.MakeTypeRef("Handedness", ref.Ref{}), false},
},
types.Choices{},
)
// A Noms Value that describes EnumStruct.
var __typeRefForEnumStruct = types.MakeStructTypeRef("EnumStruct",
[]types.Field{
types.Field{"hand", types.MakeTypeRef("Handedness", ref.Ref{}), false},
},
types.Choices{},
)
func (m EnumStruct) TypeRef() types.TypeRef {
return __typeRefForEnumStruct
}
func EnumStructFromVal(val types.Value) EnumStruct {
@@ -104,10 +106,5 @@ const (
Switch
)
// Creates and returns a Noms Value that describes Handedness.
func __typeRefOfHandedness() types.TypeRef {
return types.MakeEnumTypeRef("Handedness", "right",
"left",
"switch",
)
}
// A Noms Value that describes Handedness.
var __typeRefForHandedness = types.MakeEnumTypeRef("Handedness", "right", "left", "switch")
+7
View File
@@ -52,6 +52,13 @@ func (l ListOfInt64) Ref() ref.Ref {
return l.l.Ref()
}
// A Noms Value that describes ListOfInt64.
var __typeRefForListOfInt64 = types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.Int64Kind))
func (m ListOfInt64) TypeRef() types.TypeRef {
return __typeRefForListOfInt64
}
func (l ListOfInt64) Len() uint64 {
return l.l.Len()
}
+14
View File
@@ -53,6 +53,13 @@ func (m MapOfBoolToString) Ref() ref.Ref {
return m.m.Ref()
}
// A Noms Value that describes MapOfBoolToString.
var __typeRefForMapOfBoolToString = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.BoolKind), types.MakePrimitiveTypeRef(types.StringKind))
func (m MapOfBoolToString) TypeRef() types.TypeRef {
return __typeRefForMapOfBoolToString
}
func (m MapOfBoolToString) Empty() bool {
return m.m.Empty()
}
@@ -153,6 +160,13 @@ func (m MapOfStringToValue) Ref() ref.Ref {
return m.m.Ref()
}
// A Noms Value that describes MapOfStringToValue.
var __typeRefForMapOfStringToValue = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakePrimitiveTypeRef(types.ValueKind))
func (m MapOfStringToValue) TypeRef() types.TypeRef {
return __typeRefForMapOfStringToValue
}
func (m MapOfStringToValue) Empty() bool {
return m.m.Empty()
}
+53 -9
View File
@@ -17,7 +17,7 @@ func __testPackageInFile_ref_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"StructWithRef": __typeRefOfStructWithRef(),
"StructWithRef": __typeRefForStructWithRef,
},
}.New()
return types.RegisterPackage(&p)
@@ -41,6 +41,13 @@ func (r RefOfListOfString) Equals(other RefOfListOfString) bool {
return r.Ref() == other.Ref()
}
// A Noms Value that describes RefOfListOfString.
var __typeRefForRefOfListOfString = types.MakeCompoundTypeRef("", types.RefKind, types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.StringKind)))
func (m RefOfListOfString) TypeRef() types.TypeRef {
return __typeRefForRefOfListOfString
}
func (r RefOfListOfString) NomsValue() types.Value {
return types.Ref{R: r.r}
}
@@ -103,6 +110,13 @@ func (l ListOfString) Ref() ref.Ref {
return l.l.Ref()
}
// A Noms Value that describes ListOfString.
var __typeRefForListOfString = types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.StringKind))
func (m ListOfString) TypeRef() types.TypeRef {
return __typeRefForListOfString
}
func (l ListOfString) Len() uint64 {
return l.l.Len()
}
@@ -220,6 +234,13 @@ func (l ListOfRefOfFloat32) Ref() ref.Ref {
return l.l.Ref()
}
// A Noms Value that describes ListOfRefOfFloat32.
var __typeRefForListOfRefOfFloat32 = types.MakeCompoundTypeRef("", types.ListKind, types.MakeCompoundTypeRef("", types.RefKind, types.MakePrimitiveTypeRef(types.Float32Kind)))
func (m ListOfRefOfFloat32) TypeRef() types.TypeRef {
return __typeRefForListOfRefOfFloat32
}
func (l ListOfRefOfFloat32) Len() uint64 {
return l.l.Len()
}
@@ -310,6 +331,13 @@ func (r RefOfFloat32) Equals(other RefOfFloat32) bool {
return r.Ref() == other.Ref()
}
// A Noms Value that describes RefOfFloat32.
var __typeRefForRefOfFloat32 = types.MakeCompoundTypeRef("", types.RefKind, types.MakePrimitiveTypeRef(types.Float32Kind))
func (m RefOfFloat32) TypeRef() types.TypeRef {
return __typeRefForRefOfFloat32
}
func (r RefOfFloat32) NomsValue() types.Value {
return types.Ref{R: r.r}
}
@@ -359,14 +387,16 @@ func (s StructWithRef) Def() (d StructWithRefDef) {
return
}
// Creates and returns a Noms Value that describes StructWithRef.
func __typeRefOfStructWithRef() types.TypeRef {
return types.MakeStructTypeRef("StructWithRef",
[]types.Field{
types.Field{"r", types.MakeCompoundTypeRef("", types.RefKind, types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.Float32Kind))), false},
},
types.Choices{},
)
// A Noms Value that describes StructWithRef.
var __typeRefForStructWithRef = types.MakeStructTypeRef("StructWithRef",
[]types.Field{
types.Field{"r", types.MakeCompoundTypeRef("", types.RefKind, types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.Float32Kind))), false},
},
types.Choices{},
)
func (m StructWithRef) TypeRef() types.TypeRef {
return __typeRefForStructWithRef
}
func StructWithRefFromVal(val types.Value) StructWithRef {
@@ -416,6 +446,13 @@ func (r RefOfSetOfFloat32) Equals(other RefOfSetOfFloat32) bool {
return r.Ref() == other.Ref()
}
// A Noms Value that describes RefOfSetOfFloat32.
var __typeRefForRefOfSetOfFloat32 = types.MakeCompoundTypeRef("", types.RefKind, types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.Float32Kind)))
func (m RefOfSetOfFloat32) TypeRef() types.TypeRef {
return __typeRefForRefOfSetOfFloat32
}
func (r RefOfSetOfFloat32) NomsValue() types.Value {
return types.Ref{R: r.r}
}
@@ -480,6 +517,13 @@ func (s SetOfFloat32) Ref() ref.Ref {
return s.s.Ref()
}
// A Noms Value that describes SetOfFloat32.
var __typeRefForSetOfFloat32 = types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.Float32Kind))
func (m SetOfFloat32) TypeRef() types.TypeRef {
return __typeRefForSetOfFloat32
}
func (s SetOfFloat32) Empty() bool {
return s.s.Empty()
}
+7
View File
@@ -54,6 +54,13 @@ func (s SetOfBool) Ref() ref.Ref {
return s.s.Ref()
}
// A Noms Value that describes SetOfBool.
var __typeRefForSetOfBool = types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.BoolKind))
func (m SetOfBool) TypeRef() types.TypeRef {
return __typeRefForSetOfBool
}
func (s SetOfBool) Empty() bool {
return s.s.Empty()
}
+12 -10
View File
@@ -16,7 +16,7 @@ func __testPackageInFile_struct_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"Struct": __typeRefOfStruct(),
"Struct": __typeRefForStruct,
},
}.New()
return types.RegisterPackage(&p)
@@ -58,15 +58,17 @@ func (s Struct) Def() (d StructDef) {
return
}
// Creates and returns a Noms Value that describes Struct.
func __typeRefOfStruct() types.TypeRef {
return types.MakeStructTypeRef("Struct",
[]types.Field{
types.Field{"s", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"b", types.MakePrimitiveTypeRef(types.BoolKind), false},
},
types.Choices{},
)
// A Noms Value that describes Struct.
var __typeRefForStruct = types.MakeStructTypeRef("Struct",
[]types.Field{
types.Field{"s", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"b", types.MakePrimitiveTypeRef(types.BoolKind), false},
},
types.Choices{},
)
func (m Struct) TypeRef() types.TypeRef {
return __typeRefForStruct
}
func StructFromVal(val types.Value) Struct {
+12 -10
View File
@@ -16,7 +16,7 @@ func __testPackageInFile_struct_optional_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"OptionalStruct": __typeRefOfOptionalStruct(),
"OptionalStruct": __typeRefForOptionalStruct,
},
}.New()
return types.RegisterPackage(&p)
@@ -60,15 +60,17 @@ func (s OptionalStruct) Def() (d OptionalStructDef) {
return
}
// Creates and returns a Noms Value that describes OptionalStruct.
func __typeRefOfOptionalStruct() types.TypeRef {
return types.MakeStructTypeRef("OptionalStruct",
[]types.Field{
types.Field{"s", types.MakePrimitiveTypeRef(types.StringKind), true},
types.Field{"b", types.MakePrimitiveTypeRef(types.BoolKind), true},
},
types.Choices{},
)
// A Noms Value that describes OptionalStruct.
var __typeRefForOptionalStruct = types.MakeStructTypeRef("OptionalStruct",
[]types.Field{
types.Field{"s", types.MakePrimitiveTypeRef(types.StringKind), true},
types.Field{"b", types.MakePrimitiveTypeRef(types.BoolKind), true},
},
types.Choices{},
)
func (m OptionalStruct) TypeRef() types.TypeRef {
return __typeRefForOptionalStruct
}
func OptionalStructFromVal(val types.Value) OptionalStruct {
+24 -22
View File
@@ -16,7 +16,7 @@ func __testPackageInFile_struct_primitives_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"StructPrimitives": __typeRefOfStructPrimitives(),
"StructPrimitives": __typeRefForStructPrimitives,
},
}.New()
return types.RegisterPackage(&p)
@@ -106,27 +106,29 @@ func (s StructPrimitives) Def() (d StructPrimitivesDef) {
return
}
// Creates and returns a Noms Value that describes StructPrimitives.
func __typeRefOfStructPrimitives() types.TypeRef {
return types.MakeStructTypeRef("StructPrimitives",
[]types.Field{
types.Field{"uint64", types.MakePrimitiveTypeRef(types.UInt64Kind), false},
types.Field{"uint32", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
types.Field{"uint16", types.MakePrimitiveTypeRef(types.UInt16Kind), false},
types.Field{"uint8", types.MakePrimitiveTypeRef(types.UInt8Kind), false},
types.Field{"int64", types.MakePrimitiveTypeRef(types.Int64Kind), false},
types.Field{"int32", types.MakePrimitiveTypeRef(types.Int32Kind), false},
types.Field{"int16", types.MakePrimitiveTypeRef(types.Int16Kind), false},
types.Field{"int8", types.MakePrimitiveTypeRef(types.Int8Kind), false},
types.Field{"float64", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"float32", types.MakePrimitiveTypeRef(types.Float32Kind), false},
types.Field{"bool", types.MakePrimitiveTypeRef(types.BoolKind), false},
types.Field{"string", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"blob", types.MakePrimitiveTypeRef(types.BlobKind), false},
types.Field{"value", types.MakePrimitiveTypeRef(types.ValueKind), false},
},
types.Choices{},
)
// A Noms Value that describes StructPrimitives.
var __typeRefForStructPrimitives = types.MakeStructTypeRef("StructPrimitives",
[]types.Field{
types.Field{"uint64", types.MakePrimitiveTypeRef(types.UInt64Kind), false},
types.Field{"uint32", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
types.Field{"uint16", types.MakePrimitiveTypeRef(types.UInt16Kind), false},
types.Field{"uint8", types.MakePrimitiveTypeRef(types.UInt8Kind), false},
types.Field{"int64", types.MakePrimitiveTypeRef(types.Int64Kind), false},
types.Field{"int32", types.MakePrimitiveTypeRef(types.Int32Kind), false},
types.Field{"int16", types.MakePrimitiveTypeRef(types.Int16Kind), false},
types.Field{"int8", types.MakePrimitiveTypeRef(types.Int8Kind), false},
types.Field{"float64", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"float32", types.MakePrimitiveTypeRef(types.Float32Kind), false},
types.Field{"bool", types.MakePrimitiveTypeRef(types.BoolKind), false},
types.Field{"string", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"blob", types.MakePrimitiveTypeRef(types.BlobKind), false},
types.Field{"value", types.MakePrimitiveTypeRef(types.ValueKind), false},
},
types.Choices{},
)
func (m StructPrimitives) TypeRef() types.TypeRef {
return __typeRefForStructPrimitives
}
func StructPrimitivesFromVal(val types.Value) StructPrimitives {
+18 -9
View File
@@ -16,7 +16,7 @@ func __testPackageInFile_struct_recursive_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"Tree": __typeRefOfTree(),
"Tree": __typeRefForTree,
},
}.New()
return types.RegisterPackage(&p)
@@ -54,14 +54,16 @@ func (s Tree) Def() (d TreeDef) {
return
}
// Creates and returns a Noms Value that describes Tree.
func __typeRefOfTree() types.TypeRef {
return types.MakeStructTypeRef("Tree",
[]types.Field{
types.Field{"children", types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Tree", ref.Ref{})), false},
},
types.Choices{},
)
// A Noms Value that describes Tree.
var __typeRefForTree = types.MakeStructTypeRef("Tree",
[]types.Field{
types.Field{"children", types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Tree", ref.Ref{})), false},
},
types.Choices{},
)
func (m Tree) TypeRef() types.TypeRef {
return __typeRefForTree
}
func TreeFromVal(val types.Value) Tree {
@@ -138,6 +140,13 @@ func (l ListOfTree) Ref() ref.Ref {
return l.l.Ref()
}
// A Noms Value that describes ListOfTree.
var __typeRefForListOfTree = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Tree", ref.Ref{}))
func (m ListOfTree) TypeRef() types.TypeRef {
return __typeRefForListOfTree
}
func (l ListOfTree) Len() uint64 {
return l.l.Len()
}
+21 -12
View File
@@ -16,7 +16,7 @@ func __testPackageInFile_struct_with_list_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"StructWithList": __typeRefOfStructWithList(),
"StructWithList": __typeRefForStructWithList,
},
}.New()
return types.RegisterPackage(&p)
@@ -66,17 +66,19 @@ func (s StructWithList) Def() (d StructWithListDef) {
return
}
// Creates and returns a Noms Value that describes StructWithList.
func __typeRefOfStructWithList() types.TypeRef {
return types.MakeStructTypeRef("StructWithList",
[]types.Field{
types.Field{"l", types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.UInt8Kind)), false},
types.Field{"b", types.MakePrimitiveTypeRef(types.BoolKind), false},
types.Field{"s", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"i", types.MakePrimitiveTypeRef(types.Int64Kind), false},
},
types.Choices{},
)
// A Noms Value that describes StructWithList.
var __typeRefForStructWithList = types.MakeStructTypeRef("StructWithList",
[]types.Field{
types.Field{"l", types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.UInt8Kind)), false},
types.Field{"b", types.MakePrimitiveTypeRef(types.BoolKind), false},
types.Field{"s", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"i", types.MakePrimitiveTypeRef(types.Int64Kind), false},
},
types.Choices{},
)
func (m StructWithList) TypeRef() types.TypeRef {
return __typeRefForStructWithList
}
func StructWithListFromVal(val types.Value) StructWithList {
@@ -177,6 +179,13 @@ func (l ListOfUInt8) Ref() ref.Ref {
return l.l.Ref()
}
// A Noms Value that describes ListOfUInt8.
var __typeRefForListOfUInt8 = types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.UInt8Kind))
func (m ListOfUInt8) TypeRef() types.TypeRef {
return __typeRefForListOfUInt8
}
func (l ListOfUInt8) Len() uint64 {
return l.l.Len()
}
+24 -15
View File
@@ -16,7 +16,7 @@ func __testPackageInFile_struct_with_union_field_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"StructWithUnionField": __typeRefOfStructWithUnionField(),
"StructWithUnionField": __typeRefForStructWithUnionField,
},
}.New()
return types.RegisterPackage(&p)
@@ -94,20 +94,22 @@ func (s StructWithUnionField) __unionValueToDef() interface{} {
panic("unreachable")
}
// Creates and returns a Noms Value that describes StructWithUnionField.
func __typeRefOfStructWithUnionField() types.TypeRef {
return types.MakeStructTypeRef("StructWithUnionField",
[]types.Field{
types.Field{"a", types.MakePrimitiveTypeRef(types.Float32Kind), false},
},
types.Choices{
types.Field{"b", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"c", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"d", types.MakePrimitiveTypeRef(types.BlobKind), false},
types.Field{"e", types.MakePrimitiveTypeRef(types.ValueKind), false},
types.Field{"f", types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.UInt8Kind)), false},
},
)
// A Noms Value that describes StructWithUnionField.
var __typeRefForStructWithUnionField = types.MakeStructTypeRef("StructWithUnionField",
[]types.Field{
types.Field{"a", types.MakePrimitiveTypeRef(types.Float32Kind), false},
},
types.Choices{
types.Field{"b", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"c", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"d", types.MakePrimitiveTypeRef(types.BlobKind), false},
types.Field{"e", types.MakePrimitiveTypeRef(types.ValueKind), false},
types.Field{"f", types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.UInt8Kind)), false},
},
)
func (m StructWithUnionField) TypeRef() types.TypeRef {
return __typeRefForStructWithUnionField
}
func StructWithUnionFieldFromVal(val types.Value) StructWithUnionField {
@@ -306,6 +308,13 @@ func (s SetOfUInt8) Ref() ref.Ref {
return s.s.Ref()
}
// A Noms Value that describes SetOfUInt8.
var __typeRefForSetOfUInt8 = types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.UInt8Kind))
func (m SetOfUInt8) TypeRef() types.TypeRef {
return __typeRefForSetOfUInt8
}
func (s SetOfUInt8) Empty() bool {
return s.s.Empty()
}
+46 -30
View File
@@ -16,7 +16,7 @@ func __testPackageInFile_struct_with_unions_Ref() ref.Ref {
p := types.PackageDef{
NamedTypes: types.MapOfStringToTypeRefDef{
"StructWithUnions": __typeRefOfStructWithUnions(),
"StructWithUnions": __typeRefForStructWithUnions,
},
}.New()
return types.RegisterPackage(&p)
@@ -58,17 +58,29 @@ func (s StructWithUnions) Def() (d StructWithUnionsDef) {
return
}
// Creates and returns a Noms Value that describes StructWithUnions.
func __typeRefOfStructWithUnions() types.TypeRef {
return types.MakeStructTypeRef("StructWithUnions",
[]types.Field{
types.Field{"a", types.MakeStructTypeRef("", []types.Field{}, types.Choices{types.Field{"b", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"c", types.MakePrimitiveTypeRef(types.StringKind), false}}), false},
types.Field{"d", types.MakeStructTypeRef("", []types.Field{}, types.Choices{types.Field{"e", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"f", types.MakePrimitiveTypeRef(types.StringKind), false}}), false},
},
types.Choices{},
)
// A Noms Value that describes StructWithUnions.
var __typeRefForStructWithUnions = types.MakeStructTypeRef("StructWithUnions",
[]types.Field{
types.Field{"a", types.MakeStructTypeRef("",
[]types.Field{},
types.Choices{
types.Field{"b", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"c", types.MakePrimitiveTypeRef(types.StringKind), false},
},
), false},
types.Field{"d", types.MakeStructTypeRef("",
[]types.Field{},
types.Choices{
types.Field{"e", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"f", types.MakePrimitiveTypeRef(types.StringKind), false},
},
), false},
},
types.Choices{},
)
func (m StructWithUnions) TypeRef() types.TypeRef {
return __typeRefForStructWithUnions
}
func StructWithUnionsFromVal(val types.Value) StructWithUnions {
@@ -164,15 +176,17 @@ func (s __unionOfBOfFloat64AndCOfString) __unionValueToDef() interface{} {
panic("unreachable")
}
// Creates and returns a Noms Value that describes __unionOfBOfFloat64AndCOfString.
func __typeRefOf__unionOfBOfFloat64AndCOfString() types.TypeRef {
return types.MakeStructTypeRef("__unionOfBOfFloat64AndCOfString",
[]types.Field{},
types.Choices{
types.Field{"b", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"c", types.MakePrimitiveTypeRef(types.StringKind), false},
},
)
// A Noms Value that describes __unionOfBOfFloat64AndCOfString.
var __typeRefFor__unionOfBOfFloat64AndCOfString = types.MakeStructTypeRef("",
[]types.Field{},
types.Choices{
types.Field{"b", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"c", types.MakePrimitiveTypeRef(types.StringKind), false},
},
)
func (m __unionOfBOfFloat64AndCOfString) TypeRef() types.TypeRef {
return __typeRefFor__unionOfBOfFloat64AndCOfString
}
func __unionOfBOfFloat64AndCOfStringFromVal(val types.Value) __unionOfBOfFloat64AndCOfString {
@@ -300,15 +314,17 @@ func (s __unionOfEOfFloat64AndFOfString) __unionValueToDef() interface{} {
panic("unreachable")
}
// Creates and returns a Noms Value that describes __unionOfEOfFloat64AndFOfString.
func __typeRefOf__unionOfEOfFloat64AndFOfString() types.TypeRef {
return types.MakeStructTypeRef("__unionOfEOfFloat64AndFOfString",
[]types.Field{},
types.Choices{
types.Field{"e", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"f", types.MakePrimitiveTypeRef(types.StringKind), false},
},
)
// A Noms Value that describes __unionOfEOfFloat64AndFOfString.
var __typeRefFor__unionOfEOfFloat64AndFOfString = types.MakeStructTypeRef("",
[]types.Field{},
types.Choices{
types.Field{"e", types.MakePrimitiveTypeRef(types.Float64Kind), false},
types.Field{"f", types.MakePrimitiveTypeRef(types.StringKind), false},
},
)
func (m __unionOfEOfFloat64AndFOfString) TypeRef() types.TypeRef {
return __typeRefFor__unionOfEOfFloat64AndFOfString
}
func __unionOfEOfFloat64AndFOfStringFromVal(val types.Value) __unionOfEOfFloat64AndFOfString {
+6
View File
@@ -0,0 +1,6 @@
// A Noms Value that describes {{.Name}}.
var __typeRefFor{{.Name}} = {{toTypesTypeRef .Type}}
func (m {{.Name}}) TypeRef() types.TypeRef {
return __typeRefFor{{.Name}}
}
+72 -49
View File
@@ -9,6 +9,20 @@ import (
// Package
type Package struct {
m Map
}
func NewPackage() Package {
return Package{NewMap(
NewString("$name"), NewString("Package"),
NewString("$type"), __typeRefForPackage,
NewString("Dependencies"), NewSet(),
NewString("NamedTypes"), NewMap(),
)}
}
// PackageDef defines a Package object, which represents a Noms type package.
// Dependencies is a set of refs that point to other type packages required to resolve all the types in this pacakge.
// NamedTypes is a lookup table for types defined in this package. These should all be EnumKind or StructKind. When traversing the definition of a given type, you may run into a TypeRef that IsUnresolved(). In that case, look it up by name in the NamedTypes of the appropriate package.
@@ -17,45 +31,33 @@ type PackageDef struct {
NamedTypes MapOfStringToTypeRefDef
}
type Package struct {
m Map
}
func NewPackage() Package {
return Package{NewMap(
NewString("$name"), NewString("Package"),
NewString("$type"), __typeRefOfPackage(),
NewString("Dependencies"), NewSet(),
NewString("NamedTypes"), NewMap(),
)}
}
func (def PackageDef) New() Package {
return Package{
NewMap(
NewString("$name"), NewString("Package"),
NewString("$type"), __typeRefOfPackage(),
NewString("$type"), __typeRefForPackage,
NewString("Dependencies"), def.Dependencies.New().NomsValue(),
NewString("NamedTypes"), def.NamedTypes.New().NomsValue(),
)}
}
func (self Package) Def() PackageDef {
return PackageDef{
SetOfRefOfPackageFromVal(self.m.Get(NewString("Dependencies"))).Def(),
MapOfStringToTypeRefFromVal(self.m.Get(NewString("NamedTypes"))).Def(),
}
func (s Package) Def() (d PackageDef) {
d.Dependencies = SetOfRefOfPackageFromVal(s.m.Get(NewString("Dependencies"))).Def()
d.NamedTypes = MapOfStringToTypeRefFromVal(s.m.Get(NewString("NamedTypes"))).Def()
return
}
// Creates and returns a Noms Value that describes Package.
func __typeRefOfPackage() TypeRef {
return MakeStructTypeRef("Package",
[]Field{
Field{"Dependencies", MakeCompoundTypeRef("", SetKind, MakeCompoundTypeRef("", RefKind, MakeTypeRef("Package", ref.Ref{}))), false},
Field{"NamedTypes", MakeCompoundTypeRef("", MapKind, MakePrimitiveTypeRef(StringKind), MakePrimitiveTypeRef(TypeRefKind)), false},
},
Choices{})
// A Noms Value that describes Package.
var __typeRefForPackage = MakeStructTypeRef("Package",
[]Field{
Field{"Dependencies", MakeCompoundTypeRef("", SetKind, MakeCompoundTypeRef("", RefKind, MakeTypeRef("Package", ref.Ref{}))), false},
Field{"NamedTypes", MakeCompoundTypeRef("", MapKind, MakePrimitiveTypeRef(StringKind), MakePrimitiveTypeRef(TypeRefKind)), false},
},
Choices{},
)
func (m Package) TypeRef() TypeRef {
return __typeRefForPackage
}
func PackageFromVal(val Value) Package {
@@ -63,36 +65,36 @@ func PackageFromVal(val Value) Package {
return Package{val.(Map)}
}
func (self Package) NomsValue() Value {
return self.m
func (s Package) NomsValue() Value {
return s.m
}
func (self Package) Equals(other Package) bool {
return self.m.Equals(other.m)
func (s Package) Equals(other Package) bool {
return s.m.Equals(other.m)
}
func (self Package) Ref() ref.Ref {
return self.m.Ref()
func (s Package) Ref() ref.Ref {
return s.m.Ref()
}
func (self Package) Type() TypeRef {
return self.m.Get(NewString("$type")).(TypeRef)
func (s Package) Type() TypeRef {
return s.m.Get(NewString("$type")).(TypeRef)
}
func (self Package) Dependencies() SetOfRefOfPackage {
return SetOfRefOfPackageFromVal(self.m.Get(NewString("Dependencies")))
func (s Package) Dependencies() SetOfRefOfPackage {
return SetOfRefOfPackageFromVal(s.m.Get(NewString("Dependencies")))
}
func (self Package) SetDependencies(val SetOfRefOfPackage) Package {
return Package{self.m.Set(NewString("Dependencies"), val.NomsValue())}
func (s Package) SetDependencies(val SetOfRefOfPackage) Package {
return Package{s.m.Set(NewString("Dependencies"), val.NomsValue())}
}
func (self Package) NamedTypes() MapOfStringToTypeRef {
return MapOfStringToTypeRefFromVal(self.m.Get(NewString("NamedTypes")))
func (s Package) NamedTypes() MapOfStringToTypeRef {
return MapOfStringToTypeRefFromVal(s.m.Get(NewString("NamedTypes")))
}
func (self Package) SetTypes(val MapOfStringToTypeRef) Package {
return Package{self.m.Set(NewString("NamedTypes"), val.NomsValue())}
func (s Package) SetNamedTypes(val MapOfStringToTypeRef) Package {
return Package{s.m.Set(NewString("NamedTypes"), val.NomsValue())}
}
// SetOfRefOfPackage
@@ -101,12 +103,12 @@ type SetOfRefOfPackage struct {
s Set
}
type SetOfRefOfPackageDef map[ref.Ref]bool
func NewSetOfRefOfPackage() SetOfRefOfPackage {
return SetOfRefOfPackage{NewSet()}
}
type SetOfRefOfPackageDef map[ref.Ref]bool
func (def SetOfRefOfPackageDef) New() SetOfRefOfPackage {
l := make([]Value, len(def))
i := 0
@@ -142,6 +144,13 @@ func (s SetOfRefOfPackage) Ref() ref.Ref {
return s.s.Ref()
}
// A Noms Value that describes SetOfRefOfPackage.
var __typeRefForSetOfRefOfPackage = MakeCompoundTypeRef("", SetKind, MakeCompoundTypeRef("", RefKind, MakeTypeRef("Package", ref.Ref{})))
func (m SetOfRefOfPackage) TypeRef() TypeRef {
return __typeRefForSetOfRefOfPackage
}
func (s SetOfRefOfPackage) Empty() bool {
return s.s.Empty()
}
@@ -236,6 +245,13 @@ func (r RefOfPackage) Equals(other RefOfPackage) bool {
return r.Ref() == other.Ref()
}
// A Noms Value that describes RefOfPackage.
var __typeRefForRefOfPackage = MakeCompoundTypeRef("", RefKind, MakeTypeRef("Package", ref.Ref{}))
func (m RefOfPackage) TypeRef() TypeRef {
return __typeRefForRefOfPackage
}
func (r RefOfPackage) NomsValue() Value {
return Ref{R: r.r}
}
@@ -259,12 +275,12 @@ type MapOfStringToTypeRef struct {
m Map
}
type MapOfStringToTypeRefDef map[string]TypeRef
func NewMapOfStringToTypeRef() MapOfStringToTypeRef {
return MapOfStringToTypeRef{NewMap()}
}
type MapOfStringToTypeRefDef map[string]TypeRef
func (def MapOfStringToTypeRefDef) New() MapOfStringToTypeRef {
kv := make([]Value, 0, len(def)*2)
for k, v := range def {
@@ -273,9 +289,9 @@ func (def MapOfStringToTypeRefDef) New() MapOfStringToTypeRef {
return MapOfStringToTypeRef{NewMap(kv...)}
}
func (self MapOfStringToTypeRef) Def() MapOfStringToTypeRefDef {
func (m MapOfStringToTypeRef) Def() MapOfStringToTypeRefDef {
def := make(map[string]TypeRef)
self.m.Iter(func(k, v Value) bool {
m.m.Iter(func(k, v Value) bool {
def[k.(String).String()] = v.(TypeRef)
return false
})
@@ -299,6 +315,13 @@ func (m MapOfStringToTypeRef) Ref() ref.Ref {
return m.m.Ref()
}
// A Noms Value that describes MapOfStringToTypeRef.
var __typeRefForMapOfStringToTypeRef = MakeCompoundTypeRef("", MapKind, MakePrimitiveTypeRef(StringKind), MakePrimitiveTypeRef(TypeRefKind))
func (m MapOfStringToTypeRef) TypeRef() TypeRef {
return __typeRefForMapOfStringToTypeRef
}
func (m MapOfStringToTypeRef) Empty() bool {
return m.m.Empty()
}
+3 -3
View File
@@ -1,4 +1,4 @@
struct Package {
Dependencies :Set(Ref(Package))
Types :Map(String, TypeRef)
}
Dependencies: Set(Ref(Package))
NamedTypes: Map(String, TypeRef)
}