lang: interfaces, ast: Add debug methods for graphing scope

This can occasionally help in our debugging of the scope graph.

Co-authored-by: Samuel Gélineau <gelisam@gmail.com>
This commit is contained in:
James Shubin
2023-09-25 17:03:39 -04:00
parent fcc76809e3
commit b4a8d0d783
3 changed files with 215 additions and 0 deletions

View File

@@ -134,6 +134,15 @@ type Expr interface {
Value() (types.Value, error)
}
// ScopeGrapher adds a method to turn an AST (Expr or Stmt) into a graph so that
// we can debug the SetScope compilation phase.
type ScopeGrapher interface {
Node
// ScopeGraph adds nodes and vertices to the supplied graph.
ScopeGraph(g *pgraph.Graph)
}
// Data provides some data to the node that could be useful during its lifetime.
type Data struct {
// Fs represents a handle to the filesystem that we're running on. This

View File

@@ -187,3 +187,8 @@ func (obj *ExprAny) Value() (types.Value, error) {
}
return obj.V, nil
}
// ScopeGraph adds nodes and vertices to the supplied graph.
func (obj *ExprAny) ScopeGraph(g *pgraph.Graph) {
g.AddVertex(obj)
}