PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms 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. import middle/Resolver
  2. import Expression, Type, Var, Node, Scope, Statement, FuncDecl
  3. Access: class extends Expression {
  4. name: String { get set }
  5. expr: Expression { get set }
  6. ref: Var { get set }
  7. init: func (=expr, =name) {}
  8. getType: func -> Type {
  9. ref ? ref type : null
  10. }
  11. toString: func -> String {
  12. (expr ? expr toString() + " " : "") + name
  13. }
  14. resolve: func (task: Task) {
  15. marker : FuncDecl = null
  16. if(expr) task queue(expr)
  17. task walkBackward(|node|
  18. //"Resolving access %s, in node %s" printfln(toString(), node toString())
  19. node resolveAccess(this, task, |var|
  20. ref = var
  21. )
  22. if(ref != null) return true // break if resolved
  23. // if still not resolved and was a function, mark the access
  24. if(!marker && node class == FuncDecl) {
  25. fd := node as FuncDecl
  26. if(fd anon?()) marker = fd
  27. }
  28. false
  29. )
  30. if(!ref) {
  31. "Undefined symbol `%s`" printfln(name)
  32. exit(1)
  33. }
  34. if(marker && !ref global) marker markAccess(this)
  35. }
  36. }