Debian Codegraph @

parser/scope.go

raw symbols SCIP
1 package parser
2
3 import (
4 "github.com/robertkrimen/otto/ast"
5 )
6
7 type scope struct {
8 outer *scope
9 declarationList []ast.Declaration
10 labels []string
11 allowIn bool
12 inIteration bool
13 inSwitch bool
14 inFunction bool
15 }
16
17 func (p *parser) openScope() {
18 p.scope = &scope{
19 outer: p.scope,
20 allowIn: true,
21 }
22 }
23
24 func (p *parser) closeScope() {
25 p.scope = p.scope.outer
26 }
27
28 func (p *scope) declare(declaration ast.Declaration) {
29 p.declarationList = append(p.declarationList, declaration)
30 }
31
32 func (p *scope) hasLabel(name string) bool {
33 for _, label := range p.labels {
34 if label == name {
35 return true
36 }
37 }
38 if p.outer != nil && !p.inFunction {
39 // Crossing a function boundary to look for a label is verboten
40 return p.outer.hasLabel(name)
41 }
42 return false
43 }