PageRenderTime 383ms CodeModel.GetById 181ms app.highlight 1ms RepoModel.GetById 200ms app.codeStats 0ms

/source/core/ast/Var.ooc

http://github.com/nddrylliog/oc
Unknown | 39 lines | 27 code | 12 blank | 0 comment | 0 complexity | ab1b2b41b239836f821a9f79b6a34183 MD5 | raw file
 1
 2
 3import middle/Resolver
 4import Type, Expression
 5
 6Var: class extends Expression {
 7
 8    global := false
 9
10    _type: Type
11    name: String { get set }
12    expr: Expression { get set }
13
14    init: func (=name) {}
15
16    setType: func (=_type) {}
17
18    getType: func -> Type {
19        _type
20    }
21
22    resolve: func (task: Task) {
23        if(!_type) {
24            if(!expr)
25                Exception new("Can't infer type of " + toString() + ", null expr") throw()
26            task queue(expr)
27            _type = expr getType()
28            if(!_type)
29                Exception new("Couldn't infer type of " + toString()) throw()
30        }
31
32        task queue(type)
33    }
34
35    toString: func -> String {
36        name + (type ? ": " + type toString() : " :") + (expr ? "= " + expr toString() : "")
37    }
38
39}