Package sizzle.types

Examples of sizzle.types.SizzleType


  }

  /** {@inheritDoc} */
  @Override
  public SizzleType visit(final Index n, final SymbolTable argu) {
    final SizzleType index = n.f1.accept(this, argu);

    if (index == null)
      throw new RuntimeException();

    if (n.f2.present()) {
      if (!(index instanceof SizzleInt))
        throw new RuntimeException("invalid type " + index + " for slice expression");

      final SizzleType slice = ((NodeSequence) n.f2.node).elementAt(1).accept(this, argu);

      if (!(slice instanceof SizzleInt))
        throw new RuntimeException("invalid type " + slice + " for slice expression");
    }

View Full Code Here


    final String id = n.f0.f0.tokenImage;

    if (argu.contains(id))
      throw new TypeException("variable " + id + " already declared as " + argu.get(id));

    SizzleType rhs = null;
    if (n.f3.present()) {
      final NodeChoice nodeChoice = (NodeChoice) n.f3.node;
      switch (nodeChoice.which) {
      case 0: // initializer
        rhs = ((NodeSequence) nodeChoice.choice).elementAt(1).accept(this, argu);
        break;
      default:
        throw new RuntimeException("unexpected choice " + nodeChoice.which + " is " + nodeChoice.choice.getClass());
      }
    }

    SizzleType lhs;
    if (n.f2.present()) {
      lhs = n.f2.node.accept(this, argu);

      if (rhs != null && !lhs.assigns(rhs) && !argu.hasCast(lhs, rhs))
        throw new TypeException("incorrect type " + rhs + " for assignment to " + id + ':' + lhs);
    } else {
      if (rhs == null)
        throw new TypeException("variable declaration requires a type or an initializer");
View Full Code Here

    List<SizzleScalar> indexTypes = null;
    if (n.f3.present()) {
      indexTypes = new ArrayList<SizzleScalar>();

      for (final Node node : n.f3.nodes) {
        final SizzleType sizzleType = ((NodeSequence) node).elementAt(1).accept(this, argu);

        if (!(sizzleType instanceof SizzleScalar))
          throw new TypeException("incorrect type " + sizzleType + " for index");

        indexTypes.add((SizzleScalar) sizzleType);
      }
    }

    final SizzleType type = n.f5.accept(this, argu);

    final AggregatorSpec annotation = argu.getAggregators(n.f1.f0.tokenImage, type).get(0).getAnnotation(AggregatorSpec.class);

    SizzleScalar tweight = null;
    if (n.f6.present()) {
      if (annotation.weightType().equals("none"))
        throw new TypeException("unexpected weight for table declaration");

      final SizzleType aweight = argu.getType(annotation.weightType());
      tweight = (SizzleScalar) ((NodeSequence) n.f6.node).nodes.get(1).accept(this, argu);

      if (!aweight.assigns(tweight))
        throw new TypeException("incorrect weight type for table declaration");
    } else if (!annotation.weightType().equals("none"))
      throw new TypeException("missing weight for table declaration");

    if (n.f2.present())
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public SizzleType visit(final ExprList n, final SymbolTable argu) {
    final List<SizzleType> types = this.check(n, argu);

    final SizzleType t = types.get(0);

    for (int i = 1; i < types.size(); i++)
      if (!t.assigns(types.get(i)))
        return new SizzleTuple(types);

    return new SizzleArray(t);
  }
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public SizzleType visit(final Assignment n, final SymbolTable argu) {
    final SizzleType lhs = n.f0.accept(this, argu);
    final SizzleType rhs = n.f2.accept(this, argu);

    if (!lhs.assigns(rhs))
      throw new TypeException("invalid type " + rhs + " for assignment to " + lhs);

    return null;
View Full Code Here

        if (!t.getIndex(i).assigns(indices.get(i)))
          throw new TypeException("incorrect type " + indices.get(i) + " for index " + i);
    } else if (t.countIndices() > 0)
      throw new TypeException("indices missing from emit");

    final SizzleType expression = n.f4.accept(this, argu);
    if (!t.accepts(expression))
      throw new TypeException("incorrect type " + expression + " for " + id + ":" + t);

    if (n.f5.present()) {
      if (t.getWeightType() == null)
        throw new TypeException("unexpected weight specified by emit");

      final SizzleType wtype = ((NodeSequence) n.f5.node).nodes.get(1).accept(this, argu);

      if (!t.acceptsWeight(wtype))
        throw new TypeException("incorrect type " + wtype + " for weight of " + id + ":" + t.getWeightType());
    } else if (t.getWeightType() != null)
      throw new TypeException("no weight specified by emit");
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public SizzleType visit(final ExprStatement n, final SymbolTable argu) {
    final SizzleType type = n.f0.accept(this, argu);

    if (n.f1.present() && !(type instanceof SizzleInt))
      throw new TypeException(type + " not valid for operator " + n.f1.toString());

    return type;
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public SizzleType visit(final IfStatement n, final SymbolTable argu) {
    final SizzleType test = n.f2.accept(this, argu);

    if (!(test instanceof SizzleBool) && !(test instanceof SizzleFunction && ((SizzleFunction) test).getType() instanceof SizzleBool))
      throw new TypeException("invalid type " + test + " for if test");

    n.f4.accept(this, argu);
View Full Code Here

    } catch (final IOException e) {
      throw new RuntimeException(e.getClass().getSimpleName() + " caught", e);
    }

    for (final Node node : n.f2.nodes) {
      final SizzleType type = ((NodeSequence) node).nodes.get(3).accept(this, argu);

      final IdentifierList identifierList = (IdentifierList) ((NodeSequence) node).nodes.get(0);

      st.set(identifierList.f0.f0.tokenImage, type);
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public SizzleType visit(final Expression n, final SymbolTable argu) {
    final SizzleType ltype = n.f0.accept(this, argu);

    if (n.f1.present()) {
      if (!(ltype instanceof SizzleBool))
        throw new TypeException("invalid type " + ltype + " for disjunction");

      final SizzleType rtype = n.f0.accept(this, argu);

      if (!(rtype instanceof SizzleBool))
        throw new TypeException("invalid type " + rtype + " for disjunction");

      return new SizzleBool();
View Full Code Here

TOP

Related Classes of sizzle.types.SizzleType

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.