1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| func NewClass(name string) *Class { return &Class{name: name, vars: []string{}, funcs: map[string]*Fuction{}, } }
func (vl *SymTable) getClass(name string) (*Class, bool) { for _, c := range vl.Classes { if name == c.name { return c, true } } return nil, false }
func (vl *SymTable) addClass(class *Class) { vl.Classes = append(vl.Classes, class) }
func (c *Class) addVar(name string) { c.vars = append(c.vars, name) }
func (c *Class) initFunc(m *Jsp.ConsContext) { currentT := current defer func() { current = currentT }()
name := fmt.Sprintf("%v", m.GetChild(0)) current = name
params := m.GetChild(2) var args []string for _, param := range params.GetChildren() { if param.GetChild(0) != nil { arg := fmt.Sprintf("%v", param.GetChild(0)) args = append(args, arg) } } method := NewFunction(name, args, m.GetChild(4).(*Jsp.BlockContext)) c.funcs[name] = method }
func (c *Class) addFunc(m *Jsp.MethodContext) { currentT := current defer func() { current = currentT }()
name := fmt.Sprintf("%v", m.GetChild(0)) current = name
params := m.GetChild(2) var args []string for _, param := range params.GetChildren() { if param.GetChild(0) != nil { arg := fmt.Sprintf("%v", param.GetChild(0)) args = append(args, arg) } } method := NewFunction(name, args, m.GetChild(4).(*Jsp.BlockContext)) c.funcs[name] = method }
func (c *Class) getFunc(name string) (*Fuction, bool) { if _, ok := c.funcs[name]; ok { return c.funcs[name], true } return nil, false }
|