Name drawFence's receiver f, and say a survey route reaches a read
This commit is contained in:
+14
-14
@@ -51,14 +51,14 @@ type hasReadMemo struct {
|
|||||||
|
|
||||||
// checkDrawGroup refuses a draw group that splits nothing: one whose render reads every reference
|
// checkDrawGroup refuses a draw group that splits nothing: one whose render reads every reference
|
||||||
// path inside a repeat or a nested draw group, which draw apart from it whatever it names.
|
// path inside a repeat or a nested draw group, which draw apart from it whatever it names.
|
||||||
func (c *drawFence) checkDrawGroup(path string, n node) error {
|
func (f *drawFence) checkDrawGroup(path string, n node) error {
|
||||||
if t, ok := n.(*template); ok && t.drawGroup != "" && !c.splitsDraws(t) {
|
if t, ok := n.(*template); ok && t.drawGroup != "" && !f.splitsDraws(t) {
|
||||||
return fmt.Errorf("%s: drawGroup %q splits nothing, since nothing it renders reads a reference path outside a repeat or a nested drawGroup; drop it", path, t.drawGroup)
|
return fmt.Errorf("%s: drawGroup %q splits nothing, since nothing it renders reads a reference path outside a repeat or a nested drawGroup; drop it", path, t.drawGroup)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *drawFence) checkDraws(path string, n node) error {
|
func (f *drawFence) checkDraws(path string, n node) error {
|
||||||
t, ok := n.(*template)
|
t, ok := n.(*template)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
@@ -66,7 +66,7 @@ func (c *drawFence) checkDraws(path string, n node) error {
|
|||||||
if err := checkOwnFamily(t); err != nil {
|
if err := checkOwnFamily(t); err != nil {
|
||||||
return fmt.Errorf("%s: %w", path, err)
|
return fmt.Errorf("%s: %w", path, err)
|
||||||
}
|
}
|
||||||
if !c.readsPath(t) {
|
if !f.readsPath(t) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := surveyRender(t).check(); err != nil {
|
if err := surveyRender(t).check(); err != nil {
|
||||||
@@ -116,7 +116,7 @@ func checkOwnFamily(t *template) error {
|
|||||||
// checkRecordDraws fences the columns of a record — a template compiled at the top without a
|
// checkRecordDraws fences the columns of a record — a template compiled at the top without a
|
||||||
// repeat — so a load proves the record view of it as well as the string view.
|
// repeat — so a load proves the record view of it as well as the string view.
|
||||||
// docs/decisions.md#a-category-never-references-itself-and-a-records-fences-run-at-load
|
// docs/decisions.md#a-category-never-references-itself-and-a-records-fences-run-at-load
|
||||||
func (c *drawFence) checkRecordDraws(path string, n node) error {
|
func (f *drawFence) checkRecordDraws(path string, n node) error {
|
||||||
t, ok := n.(*template)
|
t, ok := n.(*template)
|
||||||
if !ok || !t.isRecord {
|
if !ok || !t.isRecord {
|
||||||
return nil
|
return nil
|
||||||
@@ -125,7 +125,7 @@ func (c *drawFence) checkRecordDraws(path string, n node) error {
|
|||||||
columns := sortedNames(t.fields)
|
columns := sortedNames(t.fields)
|
||||||
reads := false
|
reads := false
|
||||||
for _, name := range columns {
|
for _, name := range columns {
|
||||||
reads = reads || c.readsPath(t.fields[name])
|
reads = reads || f.readsPath(t.fields[name])
|
||||||
}
|
}
|
||||||
if !reads {
|
if !reads {
|
||||||
return nil
|
return nil
|
||||||
@@ -138,30 +138,30 @@ func (c *drawFence) checkRecordDraws(path string, n node) error {
|
|||||||
|
|
||||||
// readsPath reports whether rendering n reads a reference path, short of a repeat, which renders
|
// readsPath reports whether rendering n reads a reference path, short of a repeat, which renders
|
||||||
// over draws of its own.
|
// over draws of its own.
|
||||||
func (c *drawFence) readsPath(n node) bool { return c.hasRead(n, false) }
|
func (f *drawFence) readsPath(n node) bool { return f.hasRead(n, false) }
|
||||||
|
|
||||||
// splitsDraws reports whether rendering n reads a reference path that n's own draw group answers
|
// splitsDraws reports whether rendering n reads a reference path that n's own draw group answers
|
||||||
// for: one outside a repeat and outside a nested draw group, which hold their own draws.
|
// for: one outside a repeat and outside a nested draw group, which hold their own draws.
|
||||||
func (c *drawFence) splitsDraws(n node) bool { return c.hasRead(n, true) }
|
func (f *drawFence) splitsDraws(n node) bool { return f.hasRead(n, true) }
|
||||||
|
|
||||||
// hasRead walks what rendering n renders for a reference path, stopping at a repeat — and at a nested
|
// hasRead walks what rendering n renders for a reference path, stopping at a repeat — and at a nested
|
||||||
// draw group when stopAtGroup — since each holds draws of its own.
|
// draw group when stopAtGroup — since each holds draws of its own.
|
||||||
func (c *drawFence) hasRead(n node, stopAtGroup bool) bool {
|
func (f *drawFence) hasRead(n node, stopAtGroup bool) bool {
|
||||||
k := hasReadMemo{n, stopAtGroup}
|
k := hasReadMemo{n, stopAtGroup}
|
||||||
if r, done := c.memo[k]; done {
|
if r, done := f.memo[k]; done {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
r := false
|
r := false
|
||||||
for _, e := range renderEdges(n) {
|
for _, e := range renderEdges(n) {
|
||||||
if readsOnEdge(n, e) || (walksInto(e.to, stopAtGroup) && c.hasRead(e.to, stopAtGroup)) {
|
if readsOnEdge(n, e) || (walksInto(e.to, stopAtGroup) && f.hasRead(e.to, stopAtGroup)) {
|
||||||
r = true
|
r = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.memo == nil {
|
if f.memo == nil {
|
||||||
c.memo = map[hasReadMemo]bool{}
|
f.memo = map[hasReadMemo]bool{}
|
||||||
}
|
}
|
||||||
c.memo[k] = r
|
f.memo[k] = r
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -24,7 +24,7 @@ type surveyAt struct {
|
|||||||
wholePins pinSet
|
wholePins pinSet
|
||||||
}
|
}
|
||||||
|
|
||||||
// surveyRoute is how a render reaches a draw: as its author spells it, and the root edge's label.
|
// surveyRoute is how a render reaches a read: as its author spells it, and the root edge's label.
|
||||||
type surveyRoute struct{ spelling, label string }
|
type surveyRoute struct{ spelling, label string }
|
||||||
|
|
||||||
// pathRead is one reference a render reads: a path, or a bare reference with no tail.
|
// pathRead is one reference a render reads: a path, or a bare reference with no tail.
|
||||||
@@ -153,7 +153,7 @@ func (s *readSurvey) edge(from node, e renderEdge, at surveyAt) {
|
|||||||
s.walk(e.to, at)
|
s.walk(e.to, at)
|
||||||
}
|
}
|
||||||
|
|
||||||
// spelled names the route, and the reference it reaches a draw by where its root edge is not that
|
// spelled names the route, and the reference it reaches a read by where its root edge is not that
|
||||||
// reference.
|
// reference.
|
||||||
func (r surveyRoute) spelled(ref string) string {
|
func (r surveyRoute) spelled(ref string) string {
|
||||||
if ref == "" || ref == r.label {
|
if ref == "" || ref == r.label {
|
||||||
|
|||||||
Reference in New Issue
Block a user