Commit 5042c7e4 authored by Eric Myhre's avatar Eric Myhre

Fix generality of codegen helper mixins.

So far everything we've used these mixins for was generating based on
a *schema.Type*.  This isn't true anymore: representation nodes are
still nodes, so most of the same helpers are useful for the same
reasons and we want to reuse them... but then now they're not always
directly related to a particular reified schema.Type anymore.

Correspondingly, these helper templates were using the .Type.Kind
property as a shortcut to avoid more args, but that is wrong now:
for example, if we're going to generate the representation node for
a struct with a stringjoin representation, the closest thing we would
have to a schema.Type is the struct; but that kind clearly isn't right.
So, now that is another property passed internally to the embeddable
helpers (the helper-helpers, I guess?), and affixed by the helper
rather than provided by a schema.Type param (which, again, we no
longer have).

Note for more future work: this is the first time that a "TypeIdent"
property has shown up explicitly, but it's also *all over* in the
templates in a defacto way.  So far, my policy has been that extracting
consts from the templates isn't a priority until it proves it has a
reason to also be handled *outside* the immediate locality of the
templates (because if we pulled *everything* out the templates will
become a thin unreadable soup; and doing bulk sed-like edits to the
templates is fairly easy as long as they're consistent).  Now, that
criteria is probably satisfied, so more refactors on this are probably
due very soon.

And one more further sub-note on that note: I'm not actually sure if
some of these types should have a "_" prefix on them or not.
"$T_NodeBuilder" currently doesn't -- meaning it's exported -- and that
might not be desirable.  I started them that way, so for now I'm just
sticking with it, but it's a thing that deserves consideration.
(It might be nice for godoc readability if there's a clear hint that
the builders exist; but also, at present, there's no guarantee that
their zero values are at all usable, and that should be cause for
concern.  Other considerations may also exist; I haven't attepmted to
weigh them all yet.)
Signed-off-by: default avatarEric Myhre <hash@exultant.us>
parent a753b902
......@@ -3,202 +3,208 @@ package gengo
import (
"io"
"github.com/ipld/go-ipld-prime/schema"
ipld "github.com/ipld/go-ipld-prime"
)
type generateKindedRejections struct{}
type generateKindedRejections struct {
TypeIdent string // the identifier in code (sometimes is munged internals like "_Thing__Repr" corresponding to no publicly admitted schema.Type.Name).
TypeProse string // as will be printed in messages (e.g. can be goosed up a bit, like "Thing.Repr" instead of "_Thing__Repr").
Kind ipld.ReprKind
}
func (generateKindedRejections) emitNodeMethodLookupString(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodLookupString(w io.Writer) {
doTemplate(`
func ({{ .Name }}) LookupString(string) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "LookupString", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) LookupString(string) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "LookupString", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodLookup(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodLookup(w io.Writer) {
doTemplate(`
func ({{ .Name }}) Lookup(ipld.Node) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "Lookup", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) Lookup(ipld.Node) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "Lookup", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodLookupIndex(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodLookupIndex(w io.Writer) {
doTemplate(`
func ({{ .Name }}) LookupIndex(idx int) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "LookupIndex", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) LookupIndex(idx int) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "LookupIndex", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodMapIterator(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodMapIterator(w io.Writer) {
doTemplate(`
func ({{ .Name }}) MapIterator() ipld.MapIterator {
return mapIteratorReject{ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "MapIterator", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}}
func ({{ .TypeIdent }}) MapIterator() ipld.MapIterator {
return mapIteratorReject{ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "MapIterator", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind | ReprKindConst }}}}
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodListIterator(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodListIterator(w io.Writer) {
doTemplate(`
func ({{ .Name }}) ListIterator() ipld.ListIterator {
return listIteratorReject{ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "ListIterator", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}}
func ({{ .TypeIdent }}) ListIterator() ipld.ListIterator {
return listIteratorReject{ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "ListIterator", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: {{ .Kind | ReprKindConst }}}}
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodLength(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodLength(w io.Writer) {
doTemplate(`
func ({{ .Name }}) Length() int {
func ({{ .TypeIdent }}) Length() int {
return -1
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodIsUndefined(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodIsUndefined(w io.Writer) {
doTemplate(`
func ({{ .Name }}) IsUndefined() bool {
func ({{ .TypeIdent }}) IsUndefined() bool {
return false
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodIsNull(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodIsNull(w io.Writer) {
doTemplate(`
func ({{ .Name }}) IsNull() bool {
func ({{ .TypeIdent }}) IsNull() bool {
return false
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodAsBool(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodAsBool(w io.Writer) {
doTemplate(`
func ({{ .Name }}) AsBool() (bool, error) {
return false, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AsBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) AsBool() (bool, error) {
return false, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "AsBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodAsInt(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodAsInt(w io.Writer) {
doTemplate(`
func ({{ .Name }}) AsInt() (int, error) {
return 0, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AsInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) AsInt() (int, error) {
return 0, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "AsInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodAsFloat(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodAsFloat(w io.Writer) {
doTemplate(`
func ({{ .Name }}) AsFloat() (float64, error) {
return 0, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AsFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) AsFloat() (float64, error) {
return 0, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "AsFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodAsString(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodAsString(w io.Writer) {
doTemplate(`
func ({{ .Name }}) AsString() (string, error) {
return "", ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AsString", AppropriateKind: ipld.ReprKindSet_JustString, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) AsString() (string, error) {
return "", ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "AsString", AppropriateKind: ipld.ReprKindSet_JustString, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodAsBytes(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodAsBytes(w io.Writer) {
doTemplate(`
func ({{ .Name }}) AsBytes() ([]byte, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AsBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) AsBytes() ([]byte, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "AsBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (generateKindedRejections) emitNodeMethodAsLink(w io.Writer, t schema.Type) {
func (d generateKindedRejections) emitNodeMethodAsLink(w io.Writer) {
doTemplate(`
func ({{ .Name }}) AsLink() (ipld.Link, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AsLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) AsLink() (ipld.Link, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "AsLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
// Embeddable to do all the "nope" methods at once.
type generateKindedRejections_String struct {
Type schema.Type // used so we can generate error messages with the type name.
TypeIdent string // see doc in generateKindedRejections
TypeProse string // see doc in generateKindedRejections
}
func (gk generateKindedRejections_String) EmitNodeMethodLookupString(w io.Writer) {
generateKindedRejections{}.emitNodeMethodLookupString(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodLookupString(w)
}
func (gk generateKindedRejections_String) EmitNodeMethodLookup(w io.Writer) {
generateKindedRejections{}.emitNodeMethodLookup(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodLookup(w)
}
func (gk generateKindedRejections_String) EmitNodeMethodLookupIndex(w io.Writer) {
generateKindedRejections{}.emitNodeMethodLookupIndex(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodLookupIndex(w)
}
func (gk generateKindedRejections_String) EmitNodeMethodMapIterator(w io.Writer) {
generateKindedRejections{}.emitNodeMethodMapIterator(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodMapIterator(w)
}
func (gk generateKindedRejections_String) EmitNodeMethodListIterator(w io.Writer) {
generateKindedRejections{}.emitNodeMethodListIterator(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodListIterator(w)
}
func (gk generateKindedRejections_String) EmitNodeMethodLength(w io.Writer) {
generateKindedRejections{}.emitNodeMethodLength(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodLength(w)
}
func (gk generateKindedRejections_String) EmitNodeMethodIsUndefined(w io.Writer) {
generateKindedRejections{}.emitNodeMethodIsUndefined(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodIsUndefined(w)
}
func (gk generateKindedRejections_String) EmitNodeMethodIsNull(w io.Writer) {
generateKindedRejections{}.emitNodeMethodIsNull(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodIsNull(w)
}
func (gk generateKindedRejections_String) EmitNodeMethodAsBool(w io.Writer) {
generateKindedRejections{}.emitNodeMethodAsBool(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodAsBool(w)
}
func (gk generateKindedRejections_String) EmitNodeMethodAsInt(w io.Writer) {
generateKindedRejections{}.emitNodeMethodAsInt(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodAsInt(w)
}
func (gk generateKindedRejections_String) EmitNodeMethodAsFloat(w io.Writer) {
generateKindedRejections{}.emitNodeMethodAsFloat(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodAsFloat(w)
}
func (gk generateKindedRejections_String) EmitNodeMethodAsBytes(w io.Writer) {
generateKindedRejections{}.emitNodeMethodAsBytes(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodAsBytes(w)
}
func (gk generateKindedRejections_String) EmitNodeMethodAsLink(w io.Writer) {
generateKindedRejections{}.emitNodeMethodAsLink(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodeMethodAsLink(w)
}
// Embeddable to do all the "nope" methods at once.
//
// Used for anything that "acts like" map (so, also struct).
type generateKindedRejections_Map struct {
Type schema.Type // used so we can generate error messages with the type name.
TypeIdent string // see doc in generateKindedRejections
TypeProse string // see doc in generateKindedRejections
}
func (gk generateKindedRejections_Map) EmitNodeMethodLookupIndex(w io.Writer) {
generateKindedRejections{}.emitNodeMethodLookupIndex(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodeMethodLookupIndex(w)
}
func (gk generateKindedRejections_Map) EmitNodeMethodListIterator(w io.Writer) {
generateKindedRejections{}.emitNodeMethodListIterator(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodeMethodListIterator(w)
}
func (gk generateKindedRejections_Map) EmitNodeMethodIsUndefined(w io.Writer) {
generateKindedRejections{}.emitNodeMethodIsUndefined(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodeMethodIsUndefined(w)
}
func (gk generateKindedRejections_Map) EmitNodeMethodIsNull(w io.Writer) {
generateKindedRejections{}.emitNodeMethodIsNull(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodeMethodIsNull(w)
}
func (gk generateKindedRejections_Map) EmitNodeMethodAsBool(w io.Writer) {
generateKindedRejections{}.emitNodeMethodAsBool(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodeMethodAsBool(w)
}
func (gk generateKindedRejections_Map) EmitNodeMethodAsInt(w io.Writer) {
generateKindedRejections{}.emitNodeMethodAsInt(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodeMethodAsInt(w)
}
func (gk generateKindedRejections_Map) EmitNodeMethodAsFloat(w io.Writer) {
generateKindedRejections{}.emitNodeMethodAsFloat(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodeMethodAsFloat(w)
}
func (gk generateKindedRejections_Map) EmitNodeMethodAsString(w io.Writer) {
generateKindedRejections{}.emitNodeMethodAsString(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodeMethodAsString(w)
}
func (gk generateKindedRejections_Map) EmitNodeMethodAsBytes(w io.Writer) {
generateKindedRejections{}.emitNodeMethodAsBytes(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodeMethodAsBytes(w)
}
func (gk generateKindedRejections_Map) EmitNodeMethodAsLink(w io.Writer) {
generateKindedRejections{}.emitNodeMethodAsLink(w, gk.Type)
generateKindedRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodeMethodAsLink(w)
}
......@@ -3,154 +3,160 @@ package gengo
import (
"io"
"github.com/ipld/go-ipld-prime/schema"
ipld "github.com/ipld/go-ipld-prime"
)
type genKindedNbRejections struct{}
type genKindedNbRejections struct {
TypeIdent string // the identifier in code (sometimes is munged internals like "_Thing__Repr" corresponding to no publicly admitted schema.Type.Name).
TypeProse string // as will be printed in messages (e.g. can be goosed up a bit, like "Thing.Repr" instead of "_Thing__Repr").
Kind ipld.ReprKind
}
func (genKindedNbRejections) emitNodebuilderMethodCreateMap(w io.Writer, t schema.Type) {
func (d genKindedNbRejections) emitNodebuilderMethodCreateMap(w io.Writer) {
doTemplate(`
func ({{ .Name }}__NodeBuilder) CreateMap() (ipld.MapBuilder, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "CreateMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) CreateMap() (ipld.MapBuilder, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "CreateMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (genKindedNbRejections) emitNodebuilderMethodAmendMap(w io.Writer, t schema.Type) {
func (d genKindedNbRejections) emitNodebuilderMethodAmendMap(w io.Writer) {
doTemplate(`
func ({{ .Name }}__NodeBuilder) AmendMap() (ipld.MapBuilder, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AmendMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) AmendMap() (ipld.MapBuilder, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "AmendMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (genKindedNbRejections) emitNodebuilderMethodCreateList(w io.Writer, t schema.Type) {
func (d genKindedNbRejections) emitNodebuilderMethodCreateList(w io.Writer) {
doTemplate(`
func ({{ .Name }}__NodeBuilder) CreateList() (ipld.ListBuilder, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "CreateList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) CreateList() (ipld.ListBuilder, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "CreateList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (genKindedNbRejections) emitNodebuilderMethodAmendList(w io.Writer, t schema.Type) {
func (d genKindedNbRejections) emitNodebuilderMethodAmendList(w io.Writer) {
doTemplate(`
func ({{ .Name }}__NodeBuilder) AmendList() (ipld.ListBuilder, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AmendList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) AmendList() (ipld.ListBuilder, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "AmendList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (genKindedNbRejections) emitNodebuilderMethodCreateNull(w io.Writer, t schema.Type) {
func (d genKindedNbRejections) emitNodebuilderMethodCreateNull(w io.Writer) {
doTemplate(`
func ({{ .Name }}__NodeBuilder) CreateNull() (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "CreateNull", AppropriateKind: ipld.ReprKindSet_JustNull, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) CreateNull() (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "CreateNull", AppropriateKind: ipld.ReprKindSet_JustNull, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (genKindedNbRejections) emitNodebuilderMethodCreateBool(w io.Writer, t schema.Type) {
func (d genKindedNbRejections) emitNodebuilderMethodCreateBool(w io.Writer) {
doTemplate(`
func ({{ .Name }}__NodeBuilder) CreateBool(bool) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "CreateBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) CreateBool(bool) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "CreateBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (genKindedNbRejections) emitNodebuilderMethodCreateInt(w io.Writer, t schema.Type) {
func (d genKindedNbRejections) emitNodebuilderMethodCreateInt(w io.Writer) {
doTemplate(`
func ({{ .Name }}__NodeBuilder) CreateInt(int) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "CreateInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) CreateInt(int) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "CreateInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (genKindedNbRejections) emitNodebuilderMethodCreateFloat(w io.Writer, t schema.Type) {
func (d genKindedNbRejections) emitNodebuilderMethodCreateFloat(w io.Writer) {
doTemplate(`
func ({{ .Name }}__NodeBuilder) CreateFloat(float64) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "CreateFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) CreateFloat(float64) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "CreateFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (genKindedNbRejections) emitNodebuilderMethodCreateString(w io.Writer, t schema.Type) {
func (d genKindedNbRejections) emitNodebuilderMethodCreateString(w io.Writer) {
doTemplate(`
func ({{ .Name }}__NodeBuilder) CreateString(string) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "CreateString", AppropriateKind: ipld.ReprKindSet_JustString, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) CreateString(string) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "CreateString", AppropriateKind: ipld.ReprKindSet_JustString, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (genKindedNbRejections) emitNodebuilderMethodCreateBytes(w io.Writer, t schema.Type) {
func (d genKindedNbRejections) emitNodebuilderMethodCreateBytes(w io.Writer) {
doTemplate(`
func ({{ .Name }}__NodeBuilder) CreateBytes([]byte) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "CreateBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) CreateBytes([]byte) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "CreateBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
func (genKindedNbRejections) emitNodebuilderMethodCreateLink(w io.Writer, t schema.Type) {
func (d genKindedNbRejections) emitNodebuilderMethodCreateLink(w io.Writer) {
doTemplate(`
func ({{ .Name }}__NodeBuilder) CreateLink(ipld.Link) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "CreateLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
func ({{ .TypeIdent }}) CreateLink(ipld.Link) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{TypeName: "{{ .TypeProse }}", MethodName: "CreateLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: {{ .Kind | ReprKindConst }}}
}
`, w, t)
`, w, d)
}
// Embeddable to do all the "nope" methods at once.
type genKindedNbRejections_String struct {
Type schema.Type // used so we can generate error messages with the type name.
TypeIdent string // see doc in generateKindedRejections
TypeProse string // see doc in generateKindedRejections
}
func (gk genKindedNbRejections_String) EmitNodebuilderMethodCreateMap(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateMap(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodebuilderMethodCreateMap(w)
}
func (gk genKindedNbRejections_String) EmitNodebuilderMethodAmendMap(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodAmendMap(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodebuilderMethodAmendMap(w)
}
func (gk genKindedNbRejections_String) EmitNodebuilderMethodCreateList(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateList(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodebuilderMethodCreateList(w)
}
func (gk genKindedNbRejections_String) EmitNodebuilderMethodAmendList(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodAmendList(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodebuilderMethodAmendList(w)
}
func (gk genKindedNbRejections_String) EmitNodebuilderMethodCreateNull(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateNull(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodebuilderMethodCreateNull(w)
}
func (gk genKindedNbRejections_String) EmitNodebuilderMethodCreateBool(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateBool(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodebuilderMethodCreateBool(w)
}
func (gk genKindedNbRejections_String) EmitNodebuilderMethodCreateInt(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateInt(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodebuilderMethodCreateInt(w)
}
func (gk genKindedNbRejections_String) EmitNodebuilderMethodCreateFloat(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateFloat(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodebuilderMethodCreateFloat(w)
}
func (gk genKindedNbRejections_String) EmitNodebuilderMethodCreateBytes(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateBytes(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodebuilderMethodCreateBytes(w)
}
func (gk genKindedNbRejections_String) EmitNodebuilderMethodCreateLink(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateLink(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_String}.emitNodebuilderMethodCreateLink(w)
}
// Embeddable to do all the "nope" methods at once.
type genKindedNbRejections_Map struct {
Type schema.Type // used so we can generate error messages with the type name.
TypeIdent string // see doc in generateKindedRejections
TypeProse string // see doc in generateKindedRejections
}
func (gk genKindedNbRejections_Map) EmitNodebuilderMethodCreateList(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateList(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodebuilderMethodCreateList(w)
}
func (gk genKindedNbRejections_Map) EmitNodebuilderMethodAmendList(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodAmendList(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodebuilderMethodAmendList(w)
}
func (gk genKindedNbRejections_Map) EmitNodebuilderMethodCreateNull(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateNull(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodebuilderMethodCreateNull(w)
}
func (gk genKindedNbRejections_Map) EmitNodebuilderMethodCreateBool(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateBool(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodebuilderMethodCreateBool(w)
}
func (gk genKindedNbRejections_Map) EmitNodebuilderMethodCreateInt(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateInt(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodebuilderMethodCreateInt(w)
}
func (gk genKindedNbRejections_Map) EmitNodebuilderMethodCreateFloat(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateFloat(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodebuilderMethodCreateFloat(w)
}
func (gk genKindedNbRejections_Map) EmitNodebuilderMethodCreateString(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateString(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodebuilderMethodCreateString(w)
}
func (gk genKindedNbRejections_Map) EmitNodebuilderMethodCreateBytes(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateBytes(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodebuilderMethodCreateBytes(w)
}
func (gk genKindedNbRejections_Map) EmitNodebuilderMethodCreateLink(w io.Writer) {
genKindedNbRejections{}.emitNodebuilderMethodCreateLink(w, gk.Type)
genKindedNbRejections{gk.TypeIdent, gk.TypeProse, ipld.ReprKind_Map}.emitNodebuilderMethodCreateLink(w)
}
......@@ -9,7 +9,10 @@ import (
func NewGeneratorForKindString(t schema.Type) typedNodeGenerator {
return generateKindString{
t.(schema.TypeString),
generateKindedRejections_String{t},
generateKindedRejections_String{
string(t.Name()),
string(t.Name()),
},
}
}
......
......@@ -9,7 +9,10 @@ import (
func (gk generateKindString) GetNodeBuilderGen() nodebuilderGenerator {
return generateNbKindString{
gk.Type,
genKindedNbRejections_String{gk.Type},
genKindedNbRejections_String{
string(gk.Type.Name()) + "__NodeBuilder",
string(gk.Type.Name()) + ".Builder",
},
}
}
......
......@@ -9,7 +9,10 @@ import (
func NewGeneratorForKindStruct(t schema.Type) typedNodeGenerator {
return generateKindStruct{
t.(schema.TypeStruct),
generateKindedRejections_Map{t},
generateKindedRejections_Map{
string(t.Name()),
string(t.Name()),
},
}
}
......
......@@ -9,7 +9,10 @@ import (
func (gk generateKindStruct) GetNodeBuilderGen() nodebuilderGenerator {
return generateNbKindStruct{
gk.Type,
genKindedNbRejections_Map{gk.Type},
genKindedNbRejections_Map{
string(gk.Type.Name()) + "__NodeBuilder",
string(gk.Type.Name()) + ".Builder",
},
}
}
......
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