Package org.apache.xalan.xsltc.compiler.util

Examples of org.apache.xalan.xsltc.compiler.util.Type


    /**
     * Typing rules: see XSLT Reference by M. Kay page 345.
     */
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  final Type tleft = _left.typeCheck(stable);
  final Type tright = _right.typeCheck(stable);

  if (tleft.isSimple() && tright.isSimple()) {
      if (tleft != tright) {
    if (tleft instanceof BooleanType) {
        _right = new CastExpr(_right, Type.Boolean);
    }
    else if (tright instanceof BooleanType) {
View Full Code Here


  return _type = Type.Boolean;
    }

    public void translateDesynthesized(ClassGenerator classGen,
               MethodGenerator methodGen) {
  final Type tleft = _left.getType();
  final InstructionList il = methodGen.getInstructionList();

  if (tleft instanceof BooleanType) {
      _left.translate(classGen, methodGen);
      _right.translate(classGen, methodGen);
View Full Code Here

    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  final Type tleft = _left.getType();
  Type tright = _right.getType();

  if (tleft instanceof BooleanType || tleft instanceof NumberType) {
      translateDesynthesized(classGen, methodGen);
      synthesize(classGen, methodGen);
      return;
  }

  if (tleft instanceof StringType) {
      final int equals = cpg.addMethodref(STRING_CLASS,
            "equals",
            "(" + OBJECT_SIG +")Z");
      _left.translate(classGen, methodGen);
      _right.translate(classGen, methodGen);
      il.append(new INVOKEVIRTUAL(equals));

      if (_op == Operators.NE) {
    il.append(ICONST_1);
    il.append(IXOR);      // not x <-> x xor 1
      }
      return;
  }

  BranchHandle truec, falsec;
 
  if (tleft instanceof ResultTreeType) {
      if (tright instanceof BooleanType) {
    _right.translate(classGen, methodGen);
    if (_op == Operators.NE) {
        il.append(ICONST_1);
        il.append(IXOR); // not x <-> x xor 1
    }
    return;
      }

      if (tright instanceof RealType) {
    _left.translate(classGen, methodGen);
    tleft.translateTo(classGen, methodGen, Type.Real);
    _right.translate(classGen, methodGen);

    il.append(DCMPG);
    falsec = il.append(_op == Operators.EQ ?
           (BranchInstruction) new IFNE(null) :
           (BranchInstruction) new IFEQ(null));
    il.append(ICONST_1);
    truec = il.append(new GOTO(null));
    falsec.setTarget(il.append(ICONST_0));
    truec.setTarget(il.append(NOP));
    return;
      }

      // Next, result-tree/string and result-tree/result-tree comparisons

      _left.translate(classGen, methodGen);
      tleft.translateTo(classGen, methodGen, Type.String);
      _right.translate(classGen, methodGen);

      if (tright instanceof ResultTreeType) {
    tright.translateTo(classGen, methodGen, Type.String);
      }

      final int equals = cpg.addMethodref(STRING_CLASS,
            "equals",
            "(" +OBJECT_SIG+ ")Z");
      il.append(new INVOKEVIRTUAL(equals));

      if (_op == Operators.NE) {
    il.append(ICONST_1);
    il.append(IXOR);      // not x <-> x xor 1
      }
      return;
  }

  if (tleft instanceof NodeSetType && tright instanceof BooleanType) {
      _left.translate(classGen, methodGen);
      _left.startResetIterator(classGen, methodGen);
      Type.NodeSet.translateTo(classGen, methodGen, Type.Boolean);
      _right.translate(classGen, methodGen);

      il.append(IXOR); // x != y <-> x xor y
      if (_op == EQ) {
    il.append(ICONST_1);
    il.append(IXOR); // not x <-> x xor 1
      }
      return;
  }

  if (tleft instanceof NodeSetType && tright instanceof StringType) {
      _left.translate(classGen, methodGen);
      _left.startResetIterator(classGen, methodGen); // needed ?
      _right.translate(classGen, methodGen);
      il.append(new PUSH(cpg, _op));
      il.append(methodGen.loadDOM());
      final int cmp = cpg.addMethodref(BASIS_LIBRARY_CLASS,
               "compare",
               "("
               + tleft.toSignature()
               + tright.toSignature()
               + "I"
               + DOM_INTF_SIG
               + ")Z");
      il.append(new INVOKESTATIC(cmp));
      return;
  }

  // Next, node-set/t for t in {real, string, node-set, result-tree}
  _left.translate(classGen, methodGen);
  _left.startResetIterator(classGen, methodGen);
  _right.translate(classGen, methodGen);
  _right.startResetIterator(classGen, methodGen);

  // Cast a result tree to a string to use an existing compare
  if (tright instanceof ResultTreeType) {
      tright.translateTo(classGen, methodGen, Type.String)
      tright = Type.String;
  }

  // Call the appropriate compare() from the BasisLibrary
  il.append(new PUSH(cpg, _op));
  il.append(methodGen.loadDOM());

  final int compare = cpg.addMethodref(BASIS_LIBRARY_CLASS,
               "compare",
               "("
               + tleft.toSignature()
               + tright.toSignature()
               + "I"
               + DOM_INTF_SIG
               + ")Z");
  il.append(new INVOKESTATIC(compare));
    }
View Full Code Here

     * type conversion is legal. Cast expressions are created during
     * type checking, but typeCheck() is usually not called on them.
     * As a result, this method is called from the constructor.
     */ 
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  Type tleft = _left.getType();
  if (tleft == null) {
      tleft = _left.typeCheck(stable);
  }
  if (tleft instanceof NodeType) {
      tleft = Type.Node;  // multiple instances
View Full Code Here

    }

    public void translateDesynthesized(ClassGenerator classGen,
               MethodGenerator methodGen) {
  FlowList fl;
  final Type ltype = _left.getType();

  // This is a special case for the self:: axis. Instead of letting
  // the Step object create and iterator that we cast back to a single
  // node, we simply ask the DOM for the node type.
  if (_typeTest) {
      final ConstantPoolGen cpg = classGen.getConstantPool();
      final InstructionList il = methodGen.getInstructionList();

      final int idx = cpg.addInterfaceMethodref(DOM_INTF,
                  "getType", "(I)I");
      il.append(new SIPUSH((short)((Step)_left).getNodeType()));
      il.append(methodGen.loadDOM());
      il.append(methodGen.loadContextNode());
      il.append(new INVOKEINTERFACE(idx, 2));
      _falseList.add(il.append(new IF_ICMPNE(null)));
  }
  else {

      _left.translate(classGen, methodGen);
      if (_type != ltype) {
    _left.startResetIterator(classGen, methodGen);
    if (_type instanceof BooleanType) {
        fl = ltype.translateToDesynthesized(classGen, methodGen,
              _type);
        if (fl != null) {
      _falseList.append(fl);
        }
    }
    else {
        ltype.translateTo(classGen, methodGen, _type)
    }
      }
  }
    }
View Full Code Here

      }
  }
    }

    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final Type ltype = _left.getType();
  _left.translate(classGen, methodGen);
  if (_type.identicalTo(ltype) == false) {
      _left.startResetIterator(classGen, methodGen);
      ltype.translateTo(classGen, methodGen, _type);
  }
    }
View Full Code Here

  return _left.getType() instanceof NodeSetType ||
      _right.getType() instanceof NodeSetType;
    }

    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  Type tleft = _left.typeCheck(stable);
  Type tright = _right.typeCheck(stable);

  //bug fix # 2838, cast to reals if both are result tree fragments
  if (tleft instanceof ResultTreeType &&
      tright instanceof ResultTreeType )
    {
      _right = new CastExpr(_right, Type.Real);
      _left = new CastExpr(_left, Type.Real);
      return _type = Type.Boolean;
  }

  // If one is of reference type, then convert the other too
  if (hasReferenceArgs()) {
      Type type = null;
      Type typeL = null;
      Type typeR = null;
      if (tleft instanceof ReferenceType) {
    if (_left instanceof VariableRefBase) {
        VariableRefBase ref = (VariableRefBase)_left;
        VariableBase var = ref.getVariable();
        typeL = var.getType();
    }
      }
      if (tright instanceof ReferenceType) {
    if (_right instanceof VariableRefBase) {
        VariableRefBase ref = (VariableRefBase)_right;
        VariableBase var = ref.getVariable();
        typeR = var.getType();
    }
      }
      // bug fix # 2838
      if (typeL == null)
    type = typeR;
      else if (typeR == null)
    type = typeL;
      else {
    type = Type.Real;
      }
      if (type == null) type = Type.Real;

      _right = new CastExpr(_right, type);
            _left = new CastExpr(_left, type);
      return _type = Type.Boolean;
  }

  if (hasNodeSetArgs()) {
      // Ensure that the node-set is the left argument
      if (tright instanceof NodeSetType) {
    final Expression temp = _right; _right = _left; _left = temp;
    _op = (_op == Operators.GT) ? Operators.LT :
        (_op == Operators.LT) ? Operators.GT :
        (_op == Operators.GE) ? Operators.LE : Operators.GE;
    tright = _right.getType();
      }

      // Promote nodes to node sets
      if (tright instanceof NodeType) {
    _right = new CastExpr(_right, Type.NodeSet);
      }
      // Promote integer to doubles to have fewer compares
      if (tright instanceof IntType) {
    _right = new CastExpr(_right, Type.Real);
      }
      // Promote result-trees to strings
      if (tright instanceof ResultTreeType) {
    _right = new CastExpr(_right, Type.String);
      }
      return _type = Type.Boolean;
  }

  // In the node-boolean case, convert node to boolean first
  if (hasNodeArgs()) {
      if (tleft instanceof BooleanType) {
    _right = new CastExpr(_right, Type.Boolean);
    tright = Type.Boolean;
      }
      if (tright instanceof BooleanType) {
    _left = new CastExpr(_left, Type.Boolean);
    tleft = Type.Boolean;
      }
  }

  // Lookup the table of primops to find the best match
  MethodType ptype = lookupPrimop(stable, Operators.names[_op],
          new MethodType(Type.Void,
                   tleft, tright));

  if (ptype != null) {
      Type arg1 = (Type) ptype.argsType().elementAt(0);
      if (!arg1.identicalTo(tleft)) {
    _left = new CastExpr(_left, arg1);
      }
      Type arg2 = (Type) ptype.argsType().elementAt(1);
      if (!arg2.identicalTo(tright)) {
    _right = new CastExpr(_right, arg1);       
      }
      return _type = ptype.resultType();
  }
  throw new TypeCheckError(this);
View Full Code Here

      _right.translate(classGen, methodGen);

      // TODO: optimize if one of the args is 0

      boolean tozero = false;
      Type tleft = _left.getType();

      if (tleft instanceof RealType) {
    il.append(tleft.CMP(_op == LT || _op == LE));
    tleft = Type.Int;
    tozero = true;
      }

      switch (_op) {
      case LT:
    bi = tleft.GE(tozero)
    break;
   
      case GT:
    bi = tleft.LE(tozero);
    break;
   
      case LE:
    bi = tleft.GT(tozero);
    break;
   
      case GE:
    bi = tleft.LT(tozero);
    break;
   
      default:
    ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_RELAT_OP_ERR,this);
    getParser().reportError(Constants.FATAL, msg);
View Full Code Here

   
    /**
     * Type checks the 'file' attribute (must be able to convert it to a str).
     */
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  final Type type = _filename.typeCheck(stable);
  if (type instanceof StringType == false) {
      _filename = new CastExpr(_filename, Type.String);
  }
  typeCheckContents(stable);
  return Type.Void;
View Full Code Here

  final MethodType ptype =
      lookupPrimop(stable, _fname.getLocalPart(), args);

  if (ptype != null) {
      for (int i = 0; i < n; i++) {
    final Type argType = (Type) ptype.argsType().elementAt(i);
    final Expression exp = (Expression)_arguments.elementAt(i);
    if (!argType.identicalTo(exp.getType())) {
        try {
      _arguments.setElementAt(new CastExpr(exp, argType), i);
        }
        catch (TypeCheckError e) {
      throw new TypeCheckError(this)// invalid conversion
View Full Code Here

TOP

Related Classes of org.apache.xalan.xsltc.compiler.util.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.