Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from ipld/updates
Browse files Browse the repository at this point in the history
Updates to dependencies
  • Loading branch information
hannahhoward authored Sep 15, 2020
2 parents ae0aea0 + da0ab5c commit 38f5640
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 246 deletions.
133 changes: 15 additions & 118 deletions gen/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io"
"io/ioutil"
"os"
"regexp"
Expand All @@ -10,97 +9,6 @@ import (
gengo "github.com/ipld/go-ipld-prime/schema/gen/go"
)

type typedNodeGenerator interface {

// -- the natively-typed apis -->
// (might be more readable to group these in another interface and have it
// return a `typedNodeGenerator` with the rest? but structurally same.)

EmitNativeType(io.Writer)
EmitNativeAccessors(io.Writer) // depends on the kind -- field accessors for struct, typed iterators for map, etc.
EmitNativeBuilder(io.Writer) // typically emits some kind of struct that has a Build method.
EmitNativeMaybe(io.Writer) // a pointer-free 'maybe' mechanism is generated for all types.

// -- the schema.TypedNode.Type method and vars -->

EmitTypedNodeMethodType(io.Writer) // these emit dummies for now

// -- all node methods -->
// (and note that the nodeBuilder for this one should be the "semantic" one,
// e.g. it *always* acts like a map for structs, even if the repr is different.)

nodeGenerator

// -- and the representation and its node and nodebuilder -->

EmitTypedNodeMethodRepresentation(io.Writer)
}

type typedLinkNodeGenerator interface {
// all methods in typedNodeGenerator
typedNodeGenerator

// as typed.LinkNode.ReferencedNodeBuilder generator
EmitTypedLinkNodeMethodReferencedNodeBuilder(io.Writer)
}

type nodeGenerator interface {
EmitNodeType(io.Writer)
EmitNodeMethodReprKind(io.Writer)
EmitNodeMethodLookupString(io.Writer)
EmitNodeMethodLookup(io.Writer)
EmitNodeMethodLookupIndex(io.Writer)
EmitNodeMethodLookupSegment(io.Writer)
EmitNodeMethodMapIterator(io.Writer) // also iterator itself
EmitNodeMethodListIterator(io.Writer) // also iterator itself
EmitNodeMethodLength(io.Writer)
EmitNodeMethodIsUndefined(io.Writer)
EmitNodeMethodIsNull(io.Writer)
EmitNodeMethodAsBool(io.Writer)
EmitNodeMethodAsInt(io.Writer)
EmitNodeMethodAsFloat(io.Writer)
EmitNodeMethodAsString(io.Writer)
EmitNodeMethodAsBytes(io.Writer)
EmitNodeMethodAsLink(io.Writer)
}

func emitEntireType(ng nodeGenerator, w io.Writer) {
if ng == nil {
return
}
ng.EmitNodeType(w)
ng.EmitNodeMethodReprKind(w)
ng.EmitNodeMethodLookupString(w)
ng.EmitNodeMethodLookup(w)
ng.EmitNodeMethodLookupIndex(w)
ng.EmitNodeMethodLookupSegment(w)
ng.EmitNodeMethodMapIterator(w)
ng.EmitNodeMethodListIterator(w)
ng.EmitNodeMethodLength(w)
ng.EmitNodeMethodIsUndefined(w)
ng.EmitNodeMethodIsNull(w)
ng.EmitNodeMethodAsBool(w)
ng.EmitNodeMethodAsInt(w)
ng.EmitNodeMethodAsFloat(w)
ng.EmitNodeMethodAsString(w)
ng.EmitNodeMethodAsBytes(w)
ng.EmitNodeMethodAsLink(w)

tg, ok := ng.(typedNodeGenerator)
if ok {
tg.EmitNativeType(w)
tg.EmitNativeAccessors(w)
tg.EmitNativeBuilder(w)
tg.EmitNativeMaybe(w)
tg.EmitTypedNodeMethodType(w)
tg.EmitTypedNodeMethodRepresentation(w)
}
tlg, ok := ng.(typedLinkNodeGenerator)
if ok {
tlg.EmitTypedLinkNodeMethodReferencedNodeBuilder(w)
}
}

func main() {
openOrPanic := func(filename string) *os.File {
y, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
Expand Down Expand Up @@ -136,32 +44,23 @@ func main() {

tRaw := schema.SpawnBytes("RawNode")

adjCfg := &gengo.AdjunctCfg{}

pkgName := "dagpb"

f := openOrPanic("common_gen.go")
gengo.EmitMinima("dagpb", f)
gengo.EmitInternalEnums(pkgName, f)

f = openOrPanic("pb_node_gen.go")
gengo.EmitFileHeader("dagpb", f)
tg := gengo.NewGeneratorForKindString(tString)
emitEntireType(tg, f)
emitEntireType(tg.GetRepresentationNodeGen(), f)
tg = gengo.NewGeneratorForKindInt(tInt)
emitEntireType(tg, f)
emitEntireType(tg.GetRepresentationNodeGen(), f)
tg = gengo.NewGeneratorForKindBytes(tBytes)
emitEntireType(tg, f)
emitEntireType(tg.GetRepresentationNodeGen(), f)
tg = gengo.NewGeneratorForKindLink(tLink)
emitEntireType(tg, f)
emitEntireType(tg.GetRepresentationNodeGen(), f)
tg = gengo.NewGeneratorForKindStruct(tPBLink)
emitEntireType(tg, f)
emitEntireType(tg.GetRepresentationNodeGen(), f)
tg = gengo.NewGeneratorForKindList(tPBLinks)
emitEntireType(tg, f)
emitEntireType(tg.GetRepresentationNodeGen(), f)
tg = gengo.NewGeneratorForKindStruct(tPBNode)
emitEntireType(tg, f)
emitEntireType(tg.GetRepresentationNodeGen(), f)
gengo.EmitFileHeader(pkgName, f)
gengo.EmitEntireType(gengo.NewStringReprStringGenerator(pkgName, tString, adjCfg), f)
gengo.EmitEntireType(gengo.NewIntReprIntGenerator(pkgName, tInt, adjCfg), f)
gengo.EmitEntireType(gengo.NewBytesReprBytesGenerator(pkgName, tBytes, adjCfg), f)
gengo.EmitEntireType(gengo.NewLinkReprLinkGenerator(pkgName, tLink, adjCfg), f)
gengo.EmitEntireType(gengo.NewStructReprMapGenerator(pkgName, tPBLink, adjCfg), f)
gengo.EmitEntireType(gengo.NewListReprListGenerator(pkgName, tPBLinks, adjCfg), f)
gengo.EmitEntireType(gengo.NewStructReprMapGenerator(pkgName, tPBNode, adjCfg), f)

if err := f.Close(); err != nil {
panic(err)
}
Expand All @@ -180,7 +79,5 @@ func main() {

f = openOrPanic("raw_node_gen.go")
gengo.EmitFileHeader("dagpb", f)
tg = gengo.NewGeneratorForKindBytes(tRaw)
emitEntireType(tg, f)
emitEntireType(tg.GetRepresentationNodeGen(), f)
gengo.EmitEntireType(gengo.NewBytesReprBytesGenerator(pkgName, tRaw, adjCfg), f)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-merkledag v0.3.1
github.com/ipfs/go-unixfs v0.2.4
github.com/ipld/go-ipld-prime v0.0.2-0.20200428162820-8b59dc292b8e
github.com/ipld/go-ipld-prime v0.5.0
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
github.com/multiformats/go-multihash v0.0.13
github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
github.com/ipld/go-ipld-prime v0.0.2-0.20200428162820-8b59dc292b8e h1:ZISbJlM0urTANR9KRfRaqlBmyOj5uUtxs2r4Up9IXsA=
github.com/ipld/go-ipld-prime v0.0.2-0.20200428162820-8b59dc292b8e/go.mod h1:uVIwe/u0H4VdKv3kaN1ck7uCb6yD9cFLS9/ELyXbsw8=
github.com/ipld/go-ipld-prime v0.4.0 h1:ySDtWeWl+TDMokXlwGANSMeD5TN618cZp9NnxqZ452M=
github.com/ipld/go-ipld-prime v0.4.0/go.mod h1:uVIwe/u0H4VdKv3kaN1ck7uCb6yD9cFLS9/ELyXbsw8=
github.com/ipld/go-ipld-prime v0.5.0 h1:kr3nB6/JcFpc3Yj7vveXYuiVyZJzWUkJyLMjQbnoswE=
github.com/ipld/go-ipld-prime v0.5.0/go.mod h1:uVIwe/u0H4VdKv3kaN1ck7uCb6yD9cFLS9/ELyXbsw8=
github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc=
github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA=
github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA=
Expand Down
8 changes: 4 additions & 4 deletions node_builder_chooser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (

// AddDagPBSupportToChooser takes an existing NodeBuilderChooser and subs in
// Protobuf and Raw node builders where neccesary
func AddDagPBSupportToChooser(existing traversal.LinkTargetNodeStyleChooser) traversal.LinkTargetNodeStyleChooser {
return func(lnk ipld.Link, lnkCtx ipld.LinkContext) (ipld.NodeStyle, error) {
func AddDagPBSupportToChooser(existing traversal.LinkTargetNodePrototypeChooser) traversal.LinkTargetNodePrototypeChooser {
return func(lnk ipld.Link, lnkCtx ipld.LinkContext) (ipld.NodePrototype, error) {
c, ok := lnk.(cidlink.Link)
if !ok {
return existing(lnk, lnkCtx)
}
switch c.Cid.Prefix().Codec {
case 0x70:
return _PBNode__NodeStyle{}, nil
return _PBNode__NodePrototype{}, nil
case 0x55:
return _RawNode__NodeStyle{}, nil
return _RawNode__NodePrototype{}, nil
default:
return existing(lnk, lnkCtx)
}
Expand Down
8 changes: 4 additions & 4 deletions node_builder_chooser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
)

func TestNodeBuilderChooser(t *testing.T) {
nb1 := basicnode.Style__Any{}
nb2 := basicnode.Style__String{}
var nb1Chooser traversal.LinkTargetNodeStyleChooser = dagpb.AddDagPBSupportToChooser(func(ipld.Link, ipld.LinkContext) (ipld.NodeStyle, error) {
nb1 := basicnode.Prototype.Any
nb2 := basicnode.Prototype.String
var nb1Chooser traversal.LinkTargetNodePrototypeChooser = dagpb.AddDagPBSupportToChooser(func(ipld.Link, ipld.LinkContext) (ipld.NodePrototype, error) {
return nb1, nil
})
var nb2Chooser traversal.LinkTargetNodeStyleChooser = dagpb.AddDagPBSupportToChooser(func(ipld.Link, ipld.LinkContext) (ipld.NodeStyle, error) {
var nb2Chooser traversal.LinkTargetNodePrototypeChooser = dagpb.AddDagPBSupportToChooser(func(ipld.Link, ipld.LinkContext) (ipld.NodePrototype, error) {
return nb2, nil
})
bytes := randomBytes(256)
Expand Down
44 changes: 22 additions & 22 deletions nodestyles.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
var Style style

type style struct {
Protobuf _PBNode__NodeStyle
Raw _RawNode__NodeStyle
Protobuf _PBNode__NodePrototype
Raw _RawNode__NodePrototype
}

type _PBNode__NodeStyle struct {
type _PBNode__NodePrototype struct {
}

func (ns _PBNode__NodeStyle) NewBuilder() ipld.NodeBuilder {
func (ns _PBNode__NodePrototype) NewBuilder() ipld.NodeBuilder {
var nd PBNode
return &_PBNode__NodeBuilder{_PBNode__NodeAssembler{nd: &nd}}
}
Expand Down Expand Up @@ -76,50 +76,50 @@ func (na *_PBNode__NodeAssembler) AssignNode(_ ipld.Node) error {
panic("not implemented")
}

func (na *_PBNode__NodeAssembler) Style() ipld.NodeStyle {
return _PBNode__NodeStyle{}
func (na *_PBNode__NodeAssembler) Prototype() ipld.NodePrototype {
return _PBNode__NodePrototype{}
}

func (nd PBNode) Style() ipld.NodeStyle {
return _PBNode__NodeStyle{}
func (nd PBNode) Prototype() ipld.NodePrototype {
return _PBNode__NodePrototype{}
}

func (nd _PBNode__Repr) Style() ipld.NodeStyle {
func (nd _PBNode__Repr) Prototype() ipld.NodePrototype {
return nil
}

func (nd PBLinks) Style() ipld.NodeStyle {
func (nd PBLinks) Prototype() ipld.NodePrototype {
return nil
}

func (nd PBLink) Style() ipld.NodeStyle {
func (nd PBLink) Prototype() ipld.NodePrototype {
return nil
}

func (nd _PBLink__Repr) Style() ipld.NodeStyle {
func (nd _PBLink__Repr) Prototype() ipld.NodePrototype {
return nil
}

func (nb Link) Style() ipld.NodeStyle {
func (nb Link) Prototype() ipld.NodePrototype {
return nil
}

func (nb Bytes) Style() ipld.NodeStyle {
func (nb Bytes) Prototype() ipld.NodePrototype {
return nil
}

func (nb Int) Style() ipld.NodeStyle {
func (nb Int) Prototype() ipld.NodePrototype {
return nil
}

func (nb String) Style() ipld.NodeStyle {
func (nb String) Prototype() ipld.NodePrototype {
return nil
}

type _RawNode__NodeStyle struct {
type _RawNode__NodePrototype struct {
}

func (ns _RawNode__NodeStyle) NewBuilder() ipld.NodeBuilder {
func (ns _RawNode__NodePrototype) NewBuilder() ipld.NodeBuilder {
var nd RawNode
return &_RawNode__NodeBuilder{_RawNode__NodeAssembler{nd: &nd}}
}
Expand Down Expand Up @@ -182,10 +182,10 @@ func (na *_RawNode__NodeAssembler) AssignNode(_ ipld.Node) error {
panic("not implemented")
}

func (na *_RawNode__NodeAssembler) Style() ipld.NodeStyle {
return _RawNode__NodeStyle{}
func (na *_RawNode__NodeAssembler) Prototype() ipld.NodePrototype {
return _RawNode__NodePrototype{}
}

func (nd RawNode) Style() ipld.NodeStyle {
return _RawNode__NodeStyle{}
func (nd RawNode) Prototype() ipld.NodePrototype {
return _RawNode__NodePrototype{}
}
Loading

0 comments on commit 38f5640

Please sign in to comment.