public object visitSuperExpr(Expr.Super super) { int distance = -1; locals.TryGetValue(super, out distance); List <LoxClass> superClasses = (List <LoxClass>)environment.getAt(distance, "super"); LoxInstance _object = (LoxInstance)environment.getAt(distance - 1, "this"); LoxFunction method = null; LoxClass foundInClass = null; foreach (LoxClass superClass in superClasses) { LoxFunction methodFind = superClass.findMethod(super.method.lexeme); if (methodFind != null) { if (method != null) { throw new Exceptions.RuntimeError(super.method, "Error: Found '" + super.method.lexeme + "' in " + foundInClass.name + " and " + superClass.name + "."); } method = methodFind; foundInClass = superClass; } } if (method == null) { throw new Exceptions.RuntimeError(super.method, "Undefined property '" + super.method.lexeme + "'."); } return(method.bind(_object)); }
public object VisitSuperExpr(Expr.Super expr) { if (currentClass != ClassType.SUBCLASS) { Lox.Error(expr.keyword, "Cannot use 'super' outside of a class that has a superclass."); } ResolveLocal(expr, expr.keyword); return(null); }
public object VisitSuperExpr(Expr.Super expr) { int distance = locals[expr]; // Find reference to the superclass and current instance ("this"). IClass superclass = (IClass)environment.GetAt(distance, "super"); LoxInstance thisInstance = (LoxInstance)environment.GetAt(distance, "this"); // Find method from superclass. LoxFunction method = superclass.FindMethod(thisInstance, expr.method.lexeme); return(method); }
public object visitSuperExpr(Expr.Super super) { if (currentClass == ClassType.NONE) { Lox.error(super.keyword, "Can't use 'super' outside of a class."); } else if (currentClass != ClassType.SUBCLASS) { Lox.error(super.keyword, "Can't use 'super' in a class with no superclass."); } resolveLocal(super, super.keyword); return(null); }
public Void VisitSuperExpr(Expr.Super expr) { if (_currentClass == ClassType.NONE) { Lox.Error(expr.Keyword, "Can't use 'super' outside of a class"); } else if (_currentClass != ClassType.SUBCLASS) { Lox.Error(expr.Keyword, "Can't use 'super' in a class with no superclass."); } ResolveLocal(expr, expr.Keyword); return(null); }
public object VisitSuperExpr(Expr.Super expr) { var distance = _locals[expr]; var superclass = _environment.GetAt(distance, "super") as LoxClass; var obj = _environment.GetAt(distance - 1, "this") as LoxInstance; var method = superclass.FindMethod(expr.Method.Lexeme); if (method == null) { throw new RuntimeError(expr.Method, $"Undefined property '{expr.Method.Lexeme}'."); } return(method.Bind(obj)); }
public object Visit(Expr.Super _super) { if (_currentClass == ClassType.NONE) { Lox.Error(_super.keyword, "Cannot use 'super' outside of a class."); } else if (_currentClass != ClassType.SUBCLASS) { Lox.Error(_super.keyword, "Cannot use 'super' in a class with no superclass."); } ResolveLocal(_super, _super.keyword); return(null); }
object Expr.IVisitor <object> .Visit(Expr.Super _super) { int distance = _locals[_super]; LoxClass superclass = (LoxClass)_environment.GetAt(distance, "super"); // "this" is always one level nearer than "super"'s environment. LoxInstance _object = (LoxInstance)_environment.GetAt(distance - 1, "this"); LoxFunction method = superclass.FindMethod(_super.method.lexeme); if (method == null) { throw new RuntimeError(_super.method, "Undefined property '" + _super.method.lexeme + "'."); } return(method.Bind(_object)); }
string Expr.IVisitor <string> .Visit(Expr.Super _super) { throw new NotImplementedException(); }
public string visitSuperExpr(Expr.Super super) { return("(super)"); }
public string VisitSuperExpr(Expr.Super expr) { throw new NotImplementedException(); }