Package scriptingLanguage.errors

Examples of scriptingLanguage.errors.UnexpectedTypeException


  }

  @Override
  public AbstractObject<?> castData(AbstractClass<?> output, AbstractFrame frame) throws UnexpectedTypeException, UndefinedResultException, NullAccessException {
    if (extend(output) == -1)
      throw new UnexpectedTypeException("Instances of the " + getType().getName() + " type cannot be cast to " + output.getName());
    //TODO figure out how to implement method hiding when necessary
    return this; //Funny thing, actually.  The way that a cast object operates doesn't actually change all that much when generics aren't a factor.  Those would be hell.
  }
View Full Code Here


      while (!(parameters = parameters.getNextToken()).getCarType().equals(Interpreter.separatorType) && !parameters.isNull())
        head = head.append(parameters.singular());
      Token value = frame.getInterpreter().eval(caller, arg, frame);
      //TODO add type length checking, var args
      if (((AbstractObject<?>) value.getCar()).getType().extend(this.getParameters()[i].getType()) == -1)
        throw new UnexpectedTypeException(((AbstractObject<?>) value.getCar()).getType().getName() + " cannot be cast to " + this.getParameters()[i].getType().getName());
      args.add(arg);
      parameters = parameters.getNextToken();
    }
    return eval(args);
  }
View Full Code Here

    for (int i = 0; i < args.size(); i++)
      base.writeVariable(this.getParameters()[i].getName(), args.get(i), true);
    Token result = getDeclared().getInterpreter().eval(container, getSource(), base);
    AbstractClass<?> returnType = ((AbstractMethodClass) getType()).getReturnType();
    if (returnType.equals(Interpreter.voidClass) && !result.isNull())
      throw new UnexpectedTypeException("Cannot return a value from a void function.");
    if (((Variable<?>) (result = result.getNextToken()).getCar()).getType().extend(returnType) == -1)
      if (Interpreter.isPrimitive(getType()) && Interpreter.isPrimitive(((Variable<?>) result.getCar()).getType()))
        return ((PrimitiveClass<?>) returnType).eval(((PrimitiveClass<?>) ((Variable<?>) result.getCar()).getType()).cast(((Variable<?>) result.getCar()).getSource(), (PrimitiveClass<?>) returnType));
      else
        throw new UnexpectedTypeException("Cannot return a " + ((Variable<?>) result.getCar()).getType() + " from a function that should return a " + getType());
    return result;
  }
View Full Code Here

  }
 
  @Override
  public AbstractObject<?> castData(AbstractClass<?> output, AbstractFrame frame) throws UnexpectedTypeException, UndefinedResultException, NullAccessException {
    if (extend(output) == -1)
      throw new UnexpectedTypeException("Instances of the " + getType().getName() + " type cannot be cast to " + output.getName());
    //TODO figure out how to implement method hiding when necessary
    return this; //Funny thing, actually.  The way that a cast object operates doesn't actually change all that much when generics aren't a factor.  Those would be hell.
  }
View Full Code Here

  @Override
  public AbstractObject<?> castData(AbstractClass<?> output, AbstractFrame frame) throws UnexpectedTypeException, UndefinedResultException, NullAccessException {
    if (output.equals(Interpreter.stringClass))
      return new JavaObject<String>(Interpreter.stringClass, toString());
    if (!(output instanceof JavaClass))
      throw new UnexpectedTypeException("Instances of the " + getType().getName() + " type cannot be cast to " + output.getName());
    switch (getType().extend(output)) {
      case -1:
        throw new UnexpectedTypeException("Instances of the " + getType().getName() + " type cannot be cast to " + output.getName());
      case 0: //They are the same type
        return this;
      default:
        return new JavaObject<Object>((JavaClass<Object>) output, getSource());
    }
View Full Code Here

      }
      catch (UnexpectedTypeException e) {
        return ((PrimitiveClass<T>) output).makePrimitiveObject(getType().narrow(getSource(), (PrimitiveClass<?>) output));
      }
    }
    throw new UnexpectedTypeException("Instances of the " + getType().getName() + " type cannot be cast to " + output.getName());
  }
View Full Code Here

        catch (ClassNotFoundException e) {
          e.printStackTrace();
        }
      }
    } while (frame.previous instanceof RootFrame && (frame = (RootFrame) frame.previous) != null);
    throw new UnexpectedTypeException(type + " is not a valid type.");
  }
View Full Code Here

  @Override
  public Token eval(AbstractClass<?> caller, Token first, Token last, AbstractFrame frame) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, InterpreterException {
    if (data.equals("!")) {
      Variable<?> value = (Variable<?>) last.getCar();
      if (!value.getType().equals(Interpreter.booleanClass))
        throw new UnexpectedTypeException("The logical inverse operation, !, is not valid for the type, " + value.getType());
      return new Token(new PrimitiveObject<>(Interpreter.booleanClass, !((PrimitiveObject<Boolean>) value).getSource()), Interpreter.booleanType);
    }
    if (!last.getCarType().equals(Interpreter.identifierType))
      throw new UnexpectedTypeException("The type, " + last.getCarType() + ", is not compatible with the " + data + " operation.");
    AbstractObject<?> val = (AbstractObject<?>) frame.readVariable((String) last.getCar()).getCar();
    if (!Interpreter.isNumber(val.getType()) && !val.getType().equals(Interpreter.characterClass))
      throw new UnexpectedTypeException("The type, " + val.getType() + ", is not compatible with the " + data + " operation.");
    PrimitiveObject<?> value = (PrimitiveObject<?>) val;
    Token result = null;
    if (data.equals("++")) {
      PrimitiveObject<?>[] p = Interpreter.castPrimitives(value, new PrimitiveObject<>(Interpreter.integerClass, 1));
      value.write(value.getType().makePrimitiveObject(p[0].getType().narrow(p[0].getType().add(p[0].getSource(), p[1].getSource()), value.getType())));
View Full Code Here

      PrimitiveObject<?>[] p = Interpreter.castPrimitives((PrimitiveObject<?>) f, (PrimitiveObject<?>) l);
      if (data.equals("+"))
        return new Token(p[0].getType().makePrimitiveObject(p[0].getType().add(p[0].getSource(), p[1].getSource())), p[0].getType().getTokenType());
      return new Token(p[0].getType().makePrimitiveObject(p[0].getType().subtract(p[0].getSource(), p[1].getSource())), p[0].getType().getTokenType());
    }
    throw new UnexpectedTypeException("The types, " + f.getType().getName() + " and " + l.getType().getName() + ", are not compatible with the operation, " + data + ".");
  }
View Full Code Here

      else if (data.equals("/"))
        return new Token(p[0].getType().makePrimitiveObject(p[0].getType().divide(p[0].getSource(), p[1].getSource())), p[0].getType().getTokenType());
      // Then this is mod
      return new Token(p[0].getType().makePrimitiveObject(p[0].getType().mod(p[0].getSource(), p[1].getSource())), p[0].getType().getTokenType());
    }
    throw new UnexpectedTypeException("The types, " + f.getType().getName() + " and " + l.getType().getName() + ", are not compatible with the operation, " + data + ".");
  }
View Full Code Here

TOP

Related Classes of scriptingLanguage.errors.UnexpectedTypeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.