PageRenderTime 26ms CodeModel.GetById 23ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/source/core/ast/Scope.ooc

http://github.com/nddrylliog/oc
Unknown | 61 lines | 48 code | 13 blank | 0 comment | 0 complexity | 515c2f648c6f4ef0c129e3b60cba0ec1 MD5 | raw file
 1
 2import structs/[ArrayList, List]
 3
 4import middle/Resolver
 5import Node, Statement, Var, Access
 6
 7Scope: class extends Node {
 8
 9    body: List<Statement> { get set }
10
11    init: func {
12        body = ArrayList<Statement> new()
13    }
14
15    resolve: func (task: Task) {
16        task queueList(body)
17    }
18
19    resolveAccess: func (acc: Access, task: Task, suggest: Func (Var)) {
20        idx : Int = -1
21        //"Looking for %s in %s" printfln(acc toString(), toString())
22
23        if(task has("noindex")) {
24            size := body size
25            idx = size
26        } else {
27            previous := task
28            task walkBackwardTasks(|t|
29                if(t node == this) {
30                    idx = previous get("index", Int)
31                    return true
32                }
33                previous = t
34                false
35            )
36            if(idx == -1) return // not found, don't resolve
37        }
38        
39        // idx + 1 to allow recursion, of course :)
40        for(i in 0..(idx + 1)) {
41            node := body[i]
42            match (node class) {
43                case Var =>
44                    v := node as Var
45                    if(v name == acc name)
46                        suggest(v)
47            }
48        }
49    }
50
51    accessResolver?: func -> Bool { true }
52
53    add: func (s: Statement) {
54        body add(s)
55    }
56
57    toString: func -> String {
58        "{}"
59    }
60
61}