Package xtc.type

Examples of xtc.type.Type


      List<Sequence> newAlternatives =
        new ArrayList<Sequence>(oldAlternatives.size() +
                                ((r.once)? oldAlternatives.size() : 1));

      // Determine the production's generic list type.
      Type type = Wildcard.TYPE;
      if ((! isVoid()) && (! isTextOnly()) && (! isToken())) {
        for (Sequence s : oldAlternatives) {
          Binding  b = Analyzer.getBinding(s.elements);
          if (null == b) {
            runtime.error("unable to bind repeated element", s);
View Full Code Here


    }
    // While a new tail production may be transient, it is never
    // inline.
    attributes.remove(Constants.ATT_INLINE);

    Type type   = null;
    if (isGeneric) {
      if (runtime.test("optimizeLeftIterations")) {
        // The tail production returns a single action.
        type    = AST.actionOf(p.type);
View Full Code Here

            }
            seed = b;

            // Check the seed value's type.
            if (! Analyzer.DUMMY.equals(b.name)) {
              Type type = analyzer.type(b.element);

              if (AST.isAny(type)) {
                if ((! analyzer.module().
                     hasAttribute(Constants.ATT_NO_WARNINGS)) &&
                    (! analyzer.current().
                     hasAttribute(Constants.ATT_NO_WARNINGS))) {
                  runtime.error("value of recursion's base case may not " +
                                "be a node", b.element);
                }
              } else if ((! type.resolve().isWildcard()) &&
                         (! AST.isNode(type))) {
                runtime.error("value of recursion's base case not a node",
                              b.element);
              }
            }
View Full Code Here

    md.requiresBaseIndex  = requiresBaseIndex;

    // Patch the types for bound repetitions.
    int size = boundRepetitions.size();
    for (int i=0; i<size; i++) {
      Type t = boundRepetitions.get(i);
      if (null != t) {
        boundRepetitions.set(i, AST.listOf(ast.concretize(t, AST.ANY)));
      }
    }

    // Patch the types for bound options.
    size = options.size();
    for (int i=0; i<size; i++) {
      Type t = options.get(i);
      if (null != t) {
        options.set(i, ast.concretize(t, AST.ANY));
      }
    }
  }
View Full Code Here

      }

      // Get the binding, determine the bound element's type, and then
      // unify that type with any previously determined element type.
      final Binding b1    = Analyzer.getBinding(((Sequence)r.element).elements);
      final Type    t1    = analyzer.type(b1.element);
      final Type    unity =
        ast.unify(t1, boundRepetitions.get(repetitionLevel-1), false);
      boundRepetitions.set(repetitionLevel-1, unity);
    }

    dispatch(r.element);
View Full Code Here

      }

      // Get the binding, determine the bound element's type, and then
      // unify that type with any previously determined type.
      final Binding b1    = Analyzer.getBinding(((Sequence)o.element).elements);
      final Type    t1    = analyzer.type(b1.element);
      final Type    unity = ast.unify(t1, options.get(optionLevel-1), false);
      options.set(optionLevel-1, unity);
    }

    dispatch(o.element);
View Full Code Here

    List<Type> types = new ArrayList<Type>(size);

    if (isAction) {
      if (runtime.test("optionVariant")) {
        // Strip away any list and action types.
        Type t = analyzer.current().type;
        if (AST.isList(t)) t = AST.getArgument(t);
        if (AST.isAction(t)) t = AST.getArgument(t);
        types.add(t);

      } else {
        types.add(AST.NODE);
      }
    }

    for (Binding b : children) {
      types.add(analyzer.type(b.element));
    }

    // Unify the tuple type with any previous tuple type and update
    // its variant.
    final TupleT  t1    = ast.toTuple(name);
    final TupleT  t2    = new TupleT(name, types);
    final boolean fresh = (null == t1.getTypes());

    if (fresh && ! runtime.test("optionVariant")) {
      ast.add(t1, ast.toVariant("Node", false));
    }

    if (DEBUG) {
      runtime.console().p(name).p(" : ");
      ast.print(t2, runtime.console(), false, true, null);
      runtime.console().pln();
    }

    if (! fresh) {
      Type result = ast.combine(t1, t2, flatten, strict);
      if (result.isError()) {
        runtime.error("unable to consistently type tuple '" + name + "'",
                      sequence);
        runtime.errConsole().loc(sequence).p(": error: 1st type is '");
        ast.print(t1, runtime.errConsole(), false, true, null);
        runtime.errConsole().pln("'");
        runtime.errConsole().loc(sequence).p(": error: 2nd type is '");
        ast.print(t2, runtime.errConsole(), false, true, null);
        runtime.errConsole().pln("'").flush();

      } else {
        if (DEBUG) {
          runtime.console().p("  -> ");
          ast.print(result, runtime.console(), false, true, null);
          runtime.console().pln();
        }
        t1.setTypes(result.toTuple().getTypes());
      }

    } else if (flatten) {
      Type result = ast.flatten(t2, strict);
      if (result.isError()) {
        runtime.error("unable to flatten tuple '" + name + "'", sequence);
        runtime.errConsole().loc(sequence).p(": error: type is '");
        ast.print(t2, runtime.errConsole(), false, true, null);
        runtime.errConsole().pln("'").flush();

      } else {
        t1.setTypes(result.toTuple().getTypes());
      }

    } else {
      t1.setTypes(types);
    }
View Full Code Here

                 AST.isAny(p.type)) {
        analyzer.process(p);
        processed = true;

      } else if (AST.isList(p.type)) {
        final Type elem = AST.getArgument(p.type);

        if (AST.isString(elem) || AST.isNode(elem) || AST.isAny(elem)) {
          analyzer.process(p);
          processed = true;
        }
      }

      if (! processed) {
        // We don't know how to process the production.
        if ((! m.hasAttribute(Constants.ATT_NO_WARNINGS)) &&
            (! p.hasAttribute(Constants.ATT_NO_WARNINGS))) {
          runtime.warning("unable to add parse tree annotations", p);
        }
      }
    }

    // Retype the grammar's productions.
    for (Production p : m.productions) {
      // Skip productions that are not token-level but are lexical or
      // are void and do not consume the input.
      if ((! p.getBooleanProperty(Properties.TOKEN)) &&
          (p.getBooleanProperty(Properties.LEXICAL) ||
           (AST.isVoid(p.type) &&
            (! p.getBooleanProperty(Properties.CONSUMER))))) {
        continue;
      }

      if (p.getBooleanProperty(Properties.TOKEN)) {
        // The production is token-level.  Make it actually return a
        // token.
        p.type = AST.TOKEN;

      } else if (AST.isVoid(p.type)) {
        // The void production is not lexical and consumes the input.
        // Make it generic.
        p.type = AST.GENERIC;

      } else if (AST.isString(p.type) || AST.isToken(p.type)) {
        // The production is not lexical and returns a string or
        // token.  Make it return a node.
        p.type = AST.NODE;

      } else if (AST.isList(p.type)) {
        Type elem = AST.getArgument(p.type);

        if (AST.isString(elem) || AST.isToken(elem)) {
          // Change a list of strings or tokens into a list of nodes.
          p.type = AST.listOf(AST.NODE);
        }
View Full Code Here

   *   that can be processed by this visitor.
   */
  public static boolean isList(Type type) {
    if (! AST.isList(type)) return false;

    Type elem = AST.getArgument(type);

    return (AST.isAny(elem) || AST.isNode(elem) || AST.isString(elem));
  }
View Full Code Here

      runtime.errConsole().pln("'").flush();

      return ErrorT.TYPE;
    }

    Type result = v1;
    if (v2.isPolymorphic()) {
      for (TupleT tuple : v2.getTuples()) ast.add(tuple, v1);
    } else {
      ast.add(ast.toTuple(v2), v1);
    }
View Full Code Here

TOP

Related Classes of xtc.type.Type

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.