Commit 4d56c5e6 authored by Eric Myhre's avatar Eric Myhre

Dry'ing more templates across repr-or-not.

Wanting this as I work on list representations, and making
target-of-opportunity improvements as I encounter them.
parent 38a6fd02
......@@ -14,6 +14,8 @@ type boolGenerator struct {
Type schema.TypeBool
}
func (boolGenerator) IsRepr() bool { return false } // hint used in some generalized templates.
// --- native content and specializations --->
func (g boolGenerator) EmitNativeType(w io.Writer) {
......
......@@ -14,6 +14,8 @@ type bytesGenerator struct {
Type schema.TypeBytes
}
func (bytesGenerator) IsRepr() bool { return false } // hint used in some generalized templates.
// --- native content and specializations --->
func (g bytesGenerator) EmitNativeType(w io.Writer) {
......
......@@ -102,8 +102,8 @@ func emitNodeMethodAsKind_scalar(w io.Writer, adjCfg *AdjunctCfg, data interface
func emitNodeMethodStyle_typical(w io.Writer, adjCfg *AdjunctCfg, data interface{}) {
doTemplate(`
func ({{ .Type | TypeSymbol }}) Style() ipld.NodeStyle {
return _{{ .Type | TypeSymbol }}__Style{}
func ({{ if .IsRepr }}_{{end}}{{ .Type | TypeSymbol }}{{ if .IsRepr }}__Repr{{end}}) Style() ipld.NodeStyle {
return _{{ .Type | TypeSymbol }}__{{ if .IsRepr }}Repr{{end}}Style{}
}
`, w, adjCfg, data)
}
......@@ -112,10 +112,10 @@ func emitNodeMethodStyle_typical(w io.Writer, adjCfg *AdjunctCfg, data interface
// because it's just builders and standard resets.
func emitNodeStyleType_typical(w io.Writer, adjCfg *AdjunctCfg, data interface{}) {
doTemplate(`
type _{{ .Type | TypeSymbol }}__Style struct{}
type _{{ .Type | TypeSymbol }}__{{ if .IsRepr }}Repr{{end}}Style struct{}
func (_{{ .Type | TypeSymbol }}__Style) NewBuilder() ipld.NodeBuilder {
var nb _{{ .Type | TypeSymbol }}__Builder
func (_{{ .Type | TypeSymbol }}__{{ if .IsRepr }}Repr{{end}}Style) NewBuilder() ipld.NodeBuilder {
var nb _{{ .Type | TypeSymbol }}__{{ if .IsRepr }}Repr{{end}}Builder
nb.Reset()
return &nb
}
......
......@@ -14,6 +14,8 @@ type float64Generator struct {
Type schema.TypeFloat
}
func (float64Generator) IsRepr() bool { return false } // hint used in some generalized templates.
// --- native content and specializations --->
func (g float64Generator) EmitNativeType(w io.Writer) {
......
......@@ -14,6 +14,8 @@ type intGenerator struct {
Type schema.TypeInt
}
func (intGenerator) IsRepr() bool { return false } // hint used in some generalized templates.
// --- native content and specializations --->
func (g intGenerator) EmitNativeType(w io.Writer) {
......
......@@ -14,6 +14,8 @@ type linkGenerator struct {
Type schema.TypeLink
}
func (linkGenerator) IsRepr() bool { return false } // hint used in some generalized templates.
// --- native content and specializations --->
func (g linkGenerator) EmitNativeType(w io.Writer) {
......
......@@ -14,6 +14,8 @@ type listGenerator struct {
Type schema.TypeList
}
func (listGenerator) IsRepr() bool { return false } // hint used in some generalized templates.
// --- native content and specializations --->
func (g listGenerator) EmitNativeType(w io.Writer) {
......
......@@ -14,6 +14,8 @@ type mapGenerator struct {
Type schema.TypeMap
}
func (mapGenerator) IsRepr() bool { return false } // hint used in some generalized templates.
// --- native content and specializations --->
func (g mapGenerator) EmitNativeType(w io.Writer) {
......
......@@ -14,6 +14,8 @@ type stringGenerator struct {
Type schema.TypeString
}
func (stringGenerator) IsRepr() bool { return false } // hint used in some generalized templates.
// --- native content and specializations --->
func (g stringGenerator) EmitNativeType(w io.Writer) {
......
......@@ -14,6 +14,8 @@ type structGenerator struct {
Type schema.TypeStruct
}
func (structGenerator) IsRepr() bool { return false } // hint used in some generalized templates.
// --- native content and specializations --->
func (g structGenerator) EmitNativeType(w io.Writer) {
......
......@@ -49,6 +49,8 @@ type structReprMapReprGenerator struct {
Type schema.TypeStruct
}
func (structReprMapReprGenerator) IsRepr() bool { return true } // hint used in some generalized templates.
func (g structReprMapReprGenerator) EmitNodeType(w io.Writer) {
// The type is structurally the same, but will have a different set of methods.
doTemplate(`
......@@ -252,25 +254,11 @@ func (g structReprMapReprGenerator) EmitNodeMethodLength(w io.Writer) {
}
func (g structReprMapReprGenerator) EmitNodeMethodStyle(w io.Writer) {
// REVIEW: this appears to be standard even across kinds; can we extract it?
doTemplate(`
func (_{{ .Type | TypeSymbol }}__Repr) Style() ipld.NodeStyle {
return _{{ .Type | TypeSymbol }}__ReprStyle{}
}
`, w, g.AdjCfg, g)
emitNodeMethodStyle_typical(w, g.AdjCfg, g)
}
func (g structReprMapReprGenerator) EmitNodeStyleType(w io.Writer) {
// REVIEW: this appears to be standard even across kinds; can we extract it?
doTemplate(`
type _{{ .Type | TypeSymbol }}__ReprStyle struct{}
func (_{{ .Type | TypeSymbol }}__ReprStyle) NewBuilder() ipld.NodeBuilder {
var nb _{{ .Type | TypeSymbol }}__ReprBuilder
nb.Reset()
return &nb
}
`, w, g.AdjCfg, g)
emitNodeStyleType_typical(w, g.AdjCfg, g)
}
// --- NodeBuilder and NodeAssembler --->
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment