예제 #1
0
        public LoxFunction findMethod(string name)
        {
            if (methods.ContainsKey(name))
            {
                return(methods[name]);
            }
            LoxFunction method          = null;
            LoxClass    superClassFound = null;

            foreach (LoxClass superClass in superclasses)
            {
                if (superClass.findMethod(name) != null)
                {
                    if (method == null)
                    {
                        method          = superClass.findMethod(name);
                        superClassFound = superClass;
                    }
                    else
                    {
                        HelperFunctions.GetToken getToken = new HelperFunctions.GetToken();
                        throw new Exceptions.RuntimeError(new Token(Token.TokenType.CLASS, "", superClass, -1, -1),
                                                          "Error: Tried to call a method from subclass " + this.ToString() + " which exists in superclass " + superClassFound.ToString() +
                                                          " and superclass " + superClass.ToString() + ".");
                    }
                }
            }
            return(method);
        }
예제 #2
0
 public void resolve(List <Statement> statements)
 {
     foreach (Statement stmt in statements)
     {
         if (returned)
         {
             returned = false;
             Token name = new HelperFunctions.GetToken().evaluate(stmt);
             Lox.warn(name, "Unreachable code placed after return statement.");
         }
         resolve(stmt);
     }
     if (returned)
     {
         returned = false;
     }
 }