@@ -33,8 +33,22 @@ func (g *typeGraph) getExprPlaceholder(node ast.Node) placeholderID {
33
33
return g .exprPlaceholder [node ]
34
34
}
35
35
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.
38
52
func prepareTPWithPlaceholder (node ast.Node , varAt map [ast.Node ]* common.Variable , g * typeGraph , p placeholderID ) {
39
53
if node == nil {
40
54
panic ("Node cannot be nil" )
@@ -74,15 +88,6 @@ func prepareTPWithPlaceholder(node ast.Node, varAt map[ast.Node]*common.Variable
74
88
* (g .placeholder (p )) = calcTP (node , varAt , g )
75
89
}
76
90
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
-
86
91
func (g * typeGraph ) addRoots (roots map [string ]ast.Node , vars map [string ]map [ast.Node ]* common.Variable ) {
87
92
for _ , rootNode := range roots {
88
93
p := g .newPlaceholder ()
@@ -104,6 +109,7 @@ func countRequiredParameters(params []ast.Parameter) int {
104
109
return count
105
110
}
106
111
112
+ // calcTP calculates a definition for a type placeholder.
107
113
func calcTP (node ast.Node , varAt map [ast.Node ]* common.Variable , g * typeGraph ) typePlaceholder {
108
114
switch node := node .(type ) {
109
115
case * ast.Array :
0 commit comments