Commit ff43f7af authored by Eric Myhre's avatar Eric Myhre

Cut gordian knot.

I'm solving the decorum problem by making "temporary" builder methods for the
schema.Type values as necessary.  This will allow the gengo package to use
them freely for now.  When we're done with all this, I want to restrict building
of schema.Type values to a single method in the schema package which takes the
"ast" types -- the ones we're hoping to codegen (!) -- and do lots of checks
and cross-linking; the temporary builder methods will do *none*, and *of course*
they can't take the "ast" types yet since they don't exist yet.

Boom, cycle broken.

Also: fix generateStringKind from taking a TypeName redundantly.
parent 3fde1f4c
......@@ -7,8 +7,7 @@ import (
)
type generateKindString struct {
Name schema.TypeName
Type schema.Type
schema.Type
// FUTURE: probably some adjunct config data should come with here as well.
// FUTURE: perhaps both a global one (e.g. output package name) and a per-type one.
}
......
package gengo
import (
"github.com/ipld/go-ipld-prime/schema"
)
type generateKindStruct struct {
schema.TypeStruct
// FUTURE: probably some adjunct config data should come with here as well.
// FUTURE: perhaps both a global one (e.g. output package name) and a per-type one.
}
......@@ -39,7 +39,20 @@ func TestNuevo(t *testing.T) {
f := openOrPanic("_test/minima.go")
emitMinima(f)
tStrang := schema.SpawnString("Strang")
tStract := schema.SpawnStruct("Stract",
[]schema.StructField{schema.SpawnStructField(
"aField", tStrang, false, false,
)},
schema.StructRepresentation_Map{},
)
f = openOrPanic("_test/tStrang.go")
emitFileHeader(f)
emitType(generateKindString{"Strang", schema.TypeString{}}, f)
emitType(generateKindString{tStrang}, f)
_ = generateKindStruct{tStract}
//f = openOrPanic("_test/tStract.go")
//emitFileHeader(f)
//emitType(generateKindStruct{tStract}, f)
}
package schema
// Everything in this file is __a temporary hack__ and will be __removed__.
//
// These methods will only hang around until more of the "ast" packages are finished;
// thereafter, building schema.Type and schema.TypeSystem values will only be
// possible through first constructing a schema AST, and *then* using Reify(),
// which will validate things correctly, cycle-check, cross-link, etc.
//
// (Meanwhile, we're using these methods in the codegen prototypes.)
func SpawnString(name TypeName) TypeString {
return TypeString{anyType{name, nil}}
}
func SpawnStruct(name TypeName, fields []StructField, repr StructRepresentation) TypeStruct {
return TypeStruct{anyType{name, nil}, fields, repr}
}
func SpawnStructField(name string, typ Type, optional bool, nullable bool) StructField {
return StructField{name, typ, optional, nullable}
}
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