PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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