Skip to content

Commit fa2a4fb

Browse files
committed
Add some comments.
1 parent 1dab87a commit fa2a4fb

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

linter/internal/types/build_graph.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,22 @@ func (g *typeGraph) getExprPlaceholder(node ast.Node) placeholderID {
3333
return g.exprPlaceholder[node]
3434
}
3535

36-
// XXX(sbarzowski): Tests for imported type
37-
// XXX(sbarzowski): explain the difference between prepare and calc
36+
// prepareTP recursively creates type placeholders for all expressions
37+
// in a subtree and calculates the definitions for them.
38+
func prepareTP(node ast.Node, varAt map[ast.Node]*common.Variable, g *typeGraph) {
39+
if node == nil {
40+
panic("Node cannot be nil")
41+
}
42+
p := g.newPlaceholder()
43+
g.exprPlaceholder[node] = p
44+
prepareTPWithPlaceholder(node, varAt, g, p)
45+
}
46+
47+
// prepareTPWithPlaceholder recursively creates type placeholders for all
48+
// expressions in a subtree.
49+
//
50+
// The type placeholder for the root of the subtree is not created, but already provided.
51+
// This allows us to express mutually recursive relationships.
3852
func prepareTPWithPlaceholder(node ast.Node, varAt map[ast.Node]*common.Variable, g *typeGraph, p placeholderID) {
3953
if node == nil {
4054
panic("Node cannot be nil")
@@ -74,15 +88,6 @@ func prepareTPWithPlaceholder(node ast.Node, varAt map[ast.Node]*common.Variable
7488
*(g.placeholder(p)) = calcTP(node, varAt, g)
7589
}
7690

77-
func prepareTP(node ast.Node, varAt map[ast.Node]*common.Variable, g *typeGraph) {
78-
if node == nil {
79-
panic("Node cannot be nil")
80-
}
81-
p := g.newPlaceholder()
82-
g.exprPlaceholder[node] = p
83-
prepareTPWithPlaceholder(node, varAt, g, p)
84-
}
85-
8691
func (g *typeGraph) addRoots(roots map[string]ast.Node, vars map[string]map[ast.Node]*common.Variable) {
8792
for _, rootNode := range roots {
8893
p := g.newPlaceholder()
@@ -104,6 +109,7 @@ func countRequiredParameters(params []ast.Parameter) int {
104109
return count
105110
}
106111

112+
// calcTP calculates a definition for a type placeholder.
107113
func calcTP(node ast.Node, varAt map[ast.Node]*common.Variable, g *typeGraph) typePlaceholder {
108114
switch node := node.(type) {
109115
case *ast.Array:

0 commit comments

Comments
 (0)