Skip to content

Commit

Permalink
all: rename AssignNode to ConvertFrom
Browse files Browse the repository at this point in the history
This should be more intuitive to Go programmers, since assignments are
generally trivial operations, but conversions imply that extra work
might be needed to adapt the value to fit in the recipient.

The entire change is just:

	sed -ri 's/AssignNode/ConvertFrom/g' **/*.go

Downstream users can very likely use the same line to fix their function
declarations and calls.

Fixes #95.
  • Loading branch information
mvdan committed Dec 17, 2020
1 parent f6e9a89 commit 6e6625b
Show file tree
Hide file tree
Showing 48 changed files with 640 additions and 640 deletions.
2 changes: 1 addition & 1 deletion adl/rot13adl/rot13node.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (_R13String__Assembler) AssignBytes([]byte) error {
func (_R13String__Assembler) AssignLink(ipld.Link) error {
return mixins.StringAssembler{TypeName: "rot13adl.R13String"}.AssignLink(nil)
}
func (na *_R13String__Assembler) AssignNode(v ipld.Node) error {
func (na *_R13String__Assembler) ConvertFrom(v ipld.Node) error {
if v.IsNull() {
return na.AssignNull()
}
Expand Down
8 changes: 4 additions & 4 deletions adl/rot13adl/rot13reification.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func Reify(maybeSubstrateRoot ipld.Node) (ipld.Node, error) {
// and assign into it from the raw node, validating in the process,
// which again just leans directly on the shape validation logic already given to us by the schema logic on that type.
// (Checking the concrete type of maybeSubstrateRoot in search of a shortcut is seemingly a tad redundant,
// because the AssignNode path later also has such a check!
// because the ConvertFrom path later also has such a check!
// However, doing it earlier allows us to avoid an allocation;
// the AssignNode path doesn't become available until after NewBuilder is invoked, and NewBuilder is where allocations happen.)
// the ConvertFrom path doesn't become available until after NewBuilder is invoked, and NewBuilder is where allocations happen.)

// Check if we can recognize the maybeSubstrateRoot as being our own substrate types;
// if it is, we can shortcut pretty drastically.
Expand All @@ -63,9 +63,9 @@ func Reify(maybeSubstrateRoot ipld.Node) (ipld.Node, error) {
}

// Shortcut didn't work. Process via the data model.
// The AssignNode method on the substrate type already contains all the logic necessary for this, so we use that.
// The ConvertFrom method on the substrate type already contains all the logic necessary for this, so we use that.
nb := Prototype.SubstrateRoot.NewBuilder()
if err := nb.AssignNode(maybeSubstrateRoot); err != nil {
if err := nb.ConvertFrom(maybeSubstrateRoot); err != nil {
fmt.Errorf("rot13adl.Reify failed: data does not match expected shape for substrate: %w", err)
}
return (*_R13String)(nb.Build().(*_Substrate)), nil
Expand Down
2 changes: 1 addition & 1 deletion adl/rot13adl/rot13substrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (_Substrate__Assembler) AssignBytes([]byte) error {
func (_Substrate__Assembler) AssignLink(ipld.Link) error {
return mixins.StringAssembler{TypeName: "rot13adl.internal.Substrate"}.AssignLink(nil)
}
func (na *_Substrate__Assembler) AssignNode(v ipld.Node) error {
func (na *_Substrate__Assembler) ConvertFrom(v ipld.Node) error {
if v.IsNull() {
return na.AssignNull()
}
Expand Down
6 changes: 3 additions & 3 deletions fluent/fluentBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type NodeAssembler interface {
AssignString(string)
AssignBytes([]byte)
AssignLink(ipld.Link)
AssignNode(ipld.Node)
ConvertFrom(ipld.Node)

Prototype() ipld.NodePrototype
}
Expand Down Expand Up @@ -143,8 +143,8 @@ func (fna *nodeAssembler) AssignLink(v ipld.Link) {
panic(Error{err})
}
}
func (fna *nodeAssembler) AssignNode(v ipld.Node) {
if err := fna.na.AssignNode(v); err != nil {
func (fna *nodeAssembler) ConvertFrom(v ipld.Node) {
if err := fna.na.ConvertFrom(v); err != nil {
panic(Error{err})
}
}
Expand Down
2 changes: 1 addition & 1 deletion node/basic/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (nb *anyBuilder) AssignLink(v ipld.Link) error {
nb.scalarNode = NewLink(v)
return nil
}
func (nb *anyBuilder) AssignNode(v ipld.Node) error {
func (nb *anyBuilder) ConvertFrom(v ipld.Node) error {
if nb.kind != ipld.ReprKind_Invalid {
panic("misuse")
}
Expand Down
2 changes: 1 addition & 1 deletion node/basic/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (plainBool__Assembler) AssignBytes([]byte) error {
func (plainBool__Assembler) AssignLink(ipld.Link) error {
return mixins.BoolAssembler{TypeName: "bool"}.AssignLink(nil)
}
func (na *plainBool__Assembler) AssignNode(v ipld.Node) error {
func (na *plainBool__Assembler) ConvertFrom(v ipld.Node) error {
if v2, err := v.AsBool(); err != nil {
return err
} else {
Expand Down
2 changes: 1 addition & 1 deletion node/basic/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (na *plainBytes__Assembler) AssignBytes(v []byte) error {
func (plainBytes__Assembler) AssignLink(ipld.Link) error {
return mixins.BytesAssembler{TypeName: "bytes"}.AssignLink(nil)
}
func (na *plainBytes__Assembler) AssignNode(v ipld.Node) error {
func (na *plainBytes__Assembler) ConvertFrom(v ipld.Node) error {
if v2, err := v.AsBytes(); err != nil {
return err
} else {
Expand Down
2 changes: 1 addition & 1 deletion node/basic/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (plainFloat__Assembler) AssignBytes([]byte) error {
func (plainFloat__Assembler) AssignLink(ipld.Link) error {
return mixins.FloatAssembler{TypeName: "float"}.AssignLink(nil)
}
func (na *plainFloat__Assembler) AssignNode(v ipld.Node) error {
func (na *plainFloat__Assembler) ConvertFrom(v ipld.Node) error {
if v2, err := v.AsFloat(); err != nil {
return err
} else {
Expand Down
2 changes: 1 addition & 1 deletion node/basic/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (plainInt__Assembler) AssignBytes([]byte) error {
func (plainInt__Assembler) AssignLink(ipld.Link) error {
return mixins.IntAssembler{TypeName: "int"}.AssignLink(nil)
}
func (na *plainInt__Assembler) AssignNode(v ipld.Node) error {
func (na *plainInt__Assembler) ConvertFrom(v ipld.Node) error {
if v2, err := v.AsInt(); err != nil {
return err
} else {
Expand Down
2 changes: 1 addition & 1 deletion node/basic/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (na *plainLink__Assembler) AssignLink(v ipld.Link) error {
na.w.x = v
return nil
}
func (na *plainLink__Assembler) AssignNode(v ipld.Node) error {
func (na *plainLink__Assembler) ConvertFrom(v ipld.Node) error {
if v2, err := v.AsLink(); err != nil {
return err
} else {
Expand Down
28 changes: 14 additions & 14 deletions node/basic/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (plainList__Assembler) AssignBytes([]byte) error {
func (plainList__Assembler) AssignLink(ipld.Link) error {
return mixins.ListAssembler{TypeName: "list"}.AssignLink(nil)
}
func (na *plainList__Assembler) AssignNode(v ipld.Node) error {
func (na *plainList__Assembler) ConvertFrom(v ipld.Node) error {
// Sanity check, then update, assembler state.
// Update of state to 'finished' comes later; where exactly depends on if shortcuts apply.
if na.state != laState_initial {
Expand All @@ -197,17 +197,17 @@ func (na *plainList__Assembler) AssignNode(v ipld.Node) error {
return nil
}
// If the above shortcut didn't work, resort to a generic copy.
// We call AssignNode for all the child values, giving them a chance to hit shortcuts even if we didn't.
// We call ConvertFrom for all the child values, giving them a chance to hit shortcuts even if we didn't.
if v.ReprKind() != ipld.ReprKind_List {
return ipld.ErrWrongKind{TypeName: "list", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: v.ReprKind()}
return ipld.ErrWrongKind{TypeName: "list", MethodName: "ConvertFrom", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: v.ReprKind()}
}
itr := v.ListIterator()
for !itr.Done() {
_, v, err := itr.Next()
if err != nil {
return err
}
if err := na.AssembleValue().AssignNode(v); err != nil {
if err := na.AssembleValue().ConvertFrom(v); err != nil {
return err
}
}
Expand Down Expand Up @@ -264,33 +264,33 @@ func (lva *plainList__ValueAssembler) BeginList(sizeHint int64) (ipld.ListAssemb
return &la, err
}
func (lva *plainList__ValueAssembler) AssignNull() error {
return lva.AssignNode(ipld.Null)
return lva.ConvertFrom(ipld.Null)
}
func (lva *plainList__ValueAssembler) AssignBool(v bool) error {
vb := plainBool(v)
return lva.AssignNode(&vb)
return lva.ConvertFrom(&vb)
}
func (lva *plainList__ValueAssembler) AssignInt(v int64) error {
vb := plainInt(v)
return lva.AssignNode(&vb)
return lva.ConvertFrom(&vb)
}
func (lva *plainList__ValueAssembler) AssignFloat(v float64) error {
vb := plainFloat(v)
return lva.AssignNode(&vb)
return lva.ConvertFrom(&vb)
}
func (lva *plainList__ValueAssembler) AssignString(v string) error {
vb := plainString(v)
return lva.AssignNode(&vb)
return lva.ConvertFrom(&vb)
}
func (lva *plainList__ValueAssembler) AssignBytes(v []byte) error {
vb := plainBytes(v)
return lva.AssignNode(&vb)
return lva.ConvertFrom(&vb)
}
func (lva *plainList__ValueAssembler) AssignLink(v ipld.Link) error {
vb := plainLink{v}
return lva.AssignNode(&vb)
return lva.ConvertFrom(&vb)
}
func (lva *plainList__ValueAssembler) AssignNode(v ipld.Node) error {
func (lva *plainList__ValueAssembler) ConvertFrom(v ipld.Node) error {
lva.la.w.x = append(lva.la.w.x, v)
lva.la.state = laState_initial
lva.la = nil // invalidate self to prevent further incorrect use.
Expand Down Expand Up @@ -331,7 +331,7 @@ func (ma *plainList__ValueAssemblerMap) Finish() error {
}
w := ma.ca.w
ma.ca.w = nil
return ma.p.va.AssignNode(w)
return ma.p.va.ConvertFrom(w)
}

type plainList__ValueAssemblerList struct {
Expand All @@ -356,5 +356,5 @@ func (la *plainList__ValueAssemblerList) Finish() error {
}
w := la.ca.w
la.ca.w = nil
return la.p.va.AssignNode(w)
return la.p.va.ConvertFrom(w)
}
32 changes: 16 additions & 16 deletions node/basic/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (plainMap__Assembler) AssignBytes([]byte) error {
func (plainMap__Assembler) AssignLink(ipld.Link) error {
return mixins.MapAssembler{TypeName: "map"}.AssignLink(nil)
}
func (na *plainMap__Assembler) AssignNode(v ipld.Node) error {
func (na *plainMap__Assembler) ConvertFrom(v ipld.Node) error {
// Sanity check assembler state.
// Update of state to 'finished' comes later; where exactly depends on if shortcuts apply.
if na.state != maState_initial {
Expand All @@ -213,20 +213,20 @@ func (na *plainMap__Assembler) AssignNode(v ipld.Node) error {
return nil
}
// If the above shortcut didn't work, resort to a generic copy.
// We call AssignNode for all the child values, giving them a chance to hit shortcuts even if we didn't.
// We call ConvertFrom for all the child values, giving them a chance to hit shortcuts even if we didn't.
if v.ReprKind() != ipld.ReprKind_Map {
return ipld.ErrWrongKind{TypeName: "map", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: v.ReprKind()}
return ipld.ErrWrongKind{TypeName: "map", MethodName: "ConvertFrom", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: v.ReprKind()}
}
itr := v.MapIterator()
for !itr.Done() {
k, v, err := itr.Next()
if err != nil {
return err
}
if err := na.AssembleKey().AssignNode(k); err != nil {
if err := na.AssembleKey().ConvertFrom(k); err != nil {
return err
}
if err := na.AssembleValue().AssignNode(v); err != nil {
if err := na.AssembleValue().ConvertFrom(v); err != nil {
return err
}
}
Expand Down Expand Up @@ -348,7 +348,7 @@ func (plainMap__KeyAssembler) AssignBytes([]byte) error {
func (plainMap__KeyAssembler) AssignLink(ipld.Link) error {
return mixins.StringAssembler{TypeName: "string"}.AssignLink(nil)
}
func (mka *plainMap__KeyAssembler) AssignNode(v ipld.Node) error {
func (mka *plainMap__KeyAssembler) ConvertFrom(v ipld.Node) error {
vs, err := v.AsString()
if err != nil {
return fmt.Errorf("cannot assign non-string node into map key assembler") // FIXME:errors: this doesn't quite fit in ErrWrongKind cleanly; new error type?
Expand Down Expand Up @@ -376,33 +376,33 @@ func (mva *plainMap__ValueAssembler) BeginList(sizeHint int64) (ipld.ListAssembl
return &la, err
}
func (mva *plainMap__ValueAssembler) AssignNull() error {
return mva.AssignNode(ipld.Null)
return mva.ConvertFrom(ipld.Null)
}
func (mva *plainMap__ValueAssembler) AssignBool(v bool) error {
vb := plainBool(v)
return mva.AssignNode(&vb)
return mva.ConvertFrom(&vb)
}
func (mva *plainMap__ValueAssembler) AssignInt(v int64) error {
vb := plainInt(v)
return mva.AssignNode(&vb)
return mva.ConvertFrom(&vb)
}
func (mva *plainMap__ValueAssembler) AssignFloat(v float64) error {
vb := plainFloat(v)
return mva.AssignNode(&vb)
return mva.ConvertFrom(&vb)
}
func (mva *plainMap__ValueAssembler) AssignString(v string) error {
vb := plainString(v)
return mva.AssignNode(&vb)
return mva.ConvertFrom(&vb)
}
func (mva *plainMap__ValueAssembler) AssignBytes(v []byte) error {
vb := plainBytes(v)
return mva.AssignNode(&vb)
return mva.ConvertFrom(&vb)
}
func (mva *plainMap__ValueAssembler) AssignLink(v ipld.Link) error {
vb := plainLink{v}
return mva.AssignNode(&vb)
return mva.ConvertFrom(&vb)
}
func (mva *plainMap__ValueAssembler) AssignNode(v ipld.Node) error {
func (mva *plainMap__ValueAssembler) ConvertFrom(v ipld.Node) error {
l := len(mva.ma.w.t) - 1
mva.ma.w.t[l].v = v
mva.ma.w.m[string(mva.ma.w.t[l].k)] = v
Expand Down Expand Up @@ -445,7 +445,7 @@ func (ma *plainMap__ValueAssemblerMap) Finish() error {
}
w := ma.ca.w
ma.ca.w = nil
return ma.p.va.AssignNode(w)
return ma.p.va.ConvertFrom(w)
}

type plainMap__ValueAssemblerList struct {
Expand All @@ -470,5 +470,5 @@ func (la *plainMap__ValueAssemblerList) Finish() error {
}
w := la.ca.w
la.ca.w = nil
return la.p.va.AssignNode(w)
return la.p.va.ConvertFrom(w)
}
2 changes: 1 addition & 1 deletion node/basic/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (plainString__Assembler) AssignBytes([]byte) error {
func (plainString__Assembler) AssignLink(ipld.Link) error {
return mixins.StringAssembler{TypeName: "string"}.AssignLink(nil)
}
func (na *plainString__Assembler) AssignNode(v ipld.Node) error {
func (na *plainString__Assembler) ConvertFrom(v ipld.Node) error {
if v2, err := v.AsString(); err != nil {
return err
} else {
Expand Down
2 changes: 1 addition & 1 deletion node/gendemo/ipldsch_minima.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6e6625b

Please sign in to comment.