PageRenderTime 5ms CodeModel.GetById 2ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 1ms

/source/core/ast/Module.ooc

http://github.com/nddrylliog/oc
Unknown | 67 lines | 51 code | 16 blank | 0 comment | 0 complexity | ad6448b256418d4d635898971b6a5b49 MD5 | raw file
 1
 2import structs/[ArrayList, List]
 3
 4import frontend/BuildParams
 5import middle/Resolver
 6import Node, FuncDecl, Call, Import, Scope, Access, Var
 7
 8/**
 9 * A module contains types, functions, global variables.
10 *
11 * It has a name, a package, imports (ie. using another module's symbols)
12 * uses (for native libraries)
13 */
14Module: class extends Node {
15
16    /**
17     * The fullname is something like: "my/package/MyModule".
18     * It doesn't contain ".ooc", and it's always '/', never '\' even
19     * on win32 platforms.
20     */
21    fullName: String
22
23    body := Scope new()
24
25    imports := ArrayList<Import> new()
26    includes := ArrayList<String> new()
27
28    main? : Bool { get set }
29    
30    init: func (=fullName) {}
31
32
33    resolve: func (task: Task) {
34        task queue(body)
35    }
36
37    getDeps: func (list := ArrayList<Module> new()) -> List<Module> {
38        list add(this)
39        imports each(|i|
40            if(!list contains?(i module)) {
41                i module getDeps(list)
42            }
43        )
44        list
45    }
46    
47    resolveAccess: func (acc: Access, task: Task, suggest: Func (Var)) {
48        //"Resolving %s in %s, with %d import, task is %s" printfln(acc toString(), toString(), imports size, task toString())
49        
50        task set("noindex", true)
51        for(imp in imports) {
52            imp module body resolveAccess(acc, task, suggest)
53            if(acc ref) break
54        }
55        task unset("noindex")
56        
57        if(!acc ref) {
58            // combo X5!
59            task resolver params backend resolveAccess(acc, task, suggest)
60        }
61    }
62    
63    toString: func -> String {
64        "module " + fullName
65    }
66
67}