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

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


            // in temporary variables, create the object and reload the
            // arguments from the temporaries to avoid the problem.

      for (int i = 0; i < n; i++) {
    final Expression exp = argument(i);
                Type expType = exp.getType();
    exp.translate(classGen, methodGen);
    // Convert the argument to its Java type
    exp.startIterator(classGen, methodGen);
    expType.translateTo(classGen, methodGen, paramTypes[i]);
                paramTemp[i] =
                    methodGen.addLocalVariable("function_call_tmp"+i,
                                               expType.toJCType(),
                                               null, null);
                paramTemp[i].setStart(
                        il.append(expType.STORE(paramTemp[i].getIndex())));
      }

      il.append(new NEW(cpg.addClass(_className)));
      il.append(InstructionConstants.DUP);
View Full Code Here


   final StringBuffer buf = new StringBuffer(_className);
        buf.append('.').append(_fname.getLocalPart()).append('(');
   
  int nArgs = argsType.size();     
  for (int i = 0; i < nArgs; i++) {
      final Type intType = (Type)argsType.elementAt(i);
      buf.append(intType.toString());
      if (i < nArgs - 1) buf.append(", ");
  }
   
  buf.append(')');
  return buf.toString();
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
  }
  else if (tleft instanceof ResultTreeType) {
      tleft = Type.ResultTree; // multiple instances
  }
  if (InternalTypeMap.maps(tleft, _type) != null) {
      return _type;
  }
  // throw new TypeCheckError(this); 
  throw new TypeCheckError(new ErrorMsg(
      ErrorMsg.DATA_CONVERSION_ERR, tleft.toString(), _type.toString()));
    }
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,
                  "getExpandedTypeID",
                                                      "(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.startIterator(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.startIterator(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.getOpNames(_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 == Operators.LT || _op == Operators.LE));
    tleft = Type.Int;
    tozero = true;
      }

      switch (_op) {
        case Operators.LT:
    bi = tleft.GE(tozero)
    break;
   
        case Operators.GT:
    bi = tleft.LE(tozero);
    break;
   
        case Operators.LE:
    bi = tleft.GT(tozero);
    break;
   
        case Operators.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

  _left.setParser(parser);
  _right.setParser(parser);
    }
   
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  final Type tleft = _left.typeCheck(stable);
  final Type tright = _right.typeCheck(stable);
  final MethodType ptype = lookupPrimop(stable, Ops[_op],
                new MethodType(Type.Void,
                   tleft, tright));
  if (ptype != null) {
      final Type arg1 = (Type) ptype.argsType().elementAt(0);
      if (!arg1.identicalTo(tleft)) {
    _left = new CastExpr(_left, arg1);
      }
      final 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

      throw new TypeCheckError(ErrorMsg.ILLEGAL_ARG_ERR, getName(), this);
  }

  // The first argument must be a String, or cast to a String
  _base = argument(0);
  Type baseType = _base.typeCheck(stable)
  if (baseType != Type.String)
      _base = new CastExpr(_base, Type.String);

  // The second argument must also be a String, or cast to a String
  _token = argument(1);
  Type tokenType = _token.typeCheck(stable)
  if (tokenType != Type.String)
      _token = new CastExpr(_token, Type.String);

  return _type = Type.Boolean;
    }
View Full Code Here

     * to a string, and the lookup-value must be a string or a node-set.
     * @param stable The parser's symbol table
     * @throws TypeCheckError When the parameters have illegal type
     */
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  final Type returnType = super.typeCheck(stable);

  // Run type check on the key name (first argument) - must be a string,
  // and if it is not it must be converted to one using string() rules.
  if (_name != null) {
      final Type nameType = _name.typeCheck(stable);

      if (_name instanceof LiteralExpr) {
    final LiteralExpr literal = (LiteralExpr) _name;
    _resolvedQName =
        getParser().getQNameIgnoreDefaultNs(literal.getValue());
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.