PageRenderTime 52ms CodeModel.GetById 30ms app.highlight 1ms RepoModel.GetById 19ms app.codeStats 0ms

/source/core/ast/Access.ooc

http://github.com/nddrylliog/oc
Unknown | 51 lines | 36 code | 15 blank | 0 comment | 0 complexity | 4b97948d46fb2ea94b6ca96e7c6d8515 MD5 | raw file
 1
 2
 3import middle/Resolver
 4import Expression, Type, Var, Node, Scope, Statement, FuncDecl
 5
 6Access: class extends Expression {
 7
 8    name: String { get set }
 9    expr: Expression { get set }
10    
11    ref: Var { get set }
12
13    init: func (=expr, =name) {}
14
15    getType: func -> Type {
16        ref ? ref type : null
17    }
18
19    toString: func -> String {
20        (expr ? expr toString() + " " : "") + name
21    }
22
23    resolve: func (task: Task) {
24        marker : FuncDecl = null
25        
26        if(expr) task queue(expr)
27        
28        task walkBackward(|node|
29            //"Resolving access %s, in node %s" printfln(toString(), node toString())
30            node resolveAccess(this, task, |var|
31                ref = var
32            )
33            if(ref != null) return true // break if resolved
34            
35            // if still not resolved and was a function, mark the access
36            if(!marker && node class == FuncDecl) {
37                fd := node as FuncDecl
38                if(fd anon?()) marker = fd
39            }
40            false
41        )
42        
43        if(!ref) {
44            "Undefined symbol `%s`" printfln(name)
45            exit(1)
46        }
47        
48        if(marker && !ref global) marker markAccess(this)
49    }
50
51}