PageRenderTime 17ms CodeModel.GetById 1ms RepoModel.GetById 1ms 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. import middle/Resolver
  2. import Type, Expression
  3. Var: class extends Expression {
  4. global := false
  5. _type: Type
  6. name: String { get set }
  7. expr: Expression { get set }
  8. init: func (=name) {}
  9. setType: func (=_type) {}
  10. getType: func -> Type {
  11. _type
  12. }
  13. resolve: func (task: Task) {
  14. if(!_type) {
  15. if(!expr)
  16. Exception new("Can't infer type of " + toString() + ", null expr") throw()
  17. task queue(expr)
  18. _type = expr getType()
  19. if(!_type)
  20. Exception new("Couldn't infer type of " + toString()) throw()
  21. }
  22. task queue(type)
  23. }
  24. toString: func -> String {
  25. name + (type ? ": " + type toString() : " :") + (expr ? "= " + expr toString() : "")
  26. }
  27. }