WriteTo writes a string representation of the scope to w, with the scope elements sorted by name. The level of indentation is controlled by n >= 0, with n == 0 for no indentation. If recurse is set, it also writes nested (children) scopes.
(w io.Writer, n int, recurse bool)
| 212 | // n == 0 for no indentation. |
| 213 | // If recurse is set, it also writes nested (children) scopes. |
| 214 | func (s *Scope) WriteTo(w io.Writer, n int, recurse bool) { |
| 215 | const ind = ". " |
| 216 | indn := strings.Repeat(ind, n) |
| 217 | |
| 218 | fmt.Fprintf(w, "%s%s scope %p {\n", indn, s.comment, s) |
| 219 | |
| 220 | indn1 := indn + ind |
| 221 | for _, name := range s.Names() { |
| 222 | fmt.Fprintf(w, "%s%s\n", indn1, s.Lookup(name)) |
| 223 | } |
| 224 | |
| 225 | if recurse { |
| 226 | for _, s := range s.children { |
| 227 | s.WriteTo(w, n+1, recurse) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | fmt.Fprintf(w, "%s}\n", indn) |
| 232 | } |
| 233 | |
| 234 | // String returns a string representation of the scope, for debugging. |
| 235 | func (s *Scope) String() string { |