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

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


            if (_arg2 == null) {// should not happened
                ErrorMsg msg = new ErrorMsg(ErrorMsg.DOCUMENT_ARG_ERR, this);
                throw new TypeCheckError(msg);
            }

            final Type arg2Type = _arg2.typeCheck(stable);

            if (arg2Type.identicalTo(Type.Node)) {
                _arg2 = new CastExpr(_arg2, Type.NodeSet);
            } else if (arg2Type.identicalTo(Type.NodeSet)) {
                // falls through
            } else {
                ErrorMsg msg = new ErrorMsg(ErrorMsg.DOCUMENT_ARG_ERR, this);
                throw new TypeCheckError(msg);
            }
View Full Code Here


  return _type = Type.Real;
    }

    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final InstructionList il = methodGen.getInstructionList();
  Type targ;
 
  if (argumentCount() == 0) {
      il.append(methodGen.loadContextNode());
      targ = Type.Node;
  }
  else {
      final Expression arg = argument();
      arg.translate(classGen, methodGen);
      arg.startIterator(classGen, methodGen);
      targ = arg.getType();
  }

  if (!targ.identicalTo(Type.Real)) {
      targ.translateTo(classGen, methodGen, Type.Real);
  }
    }
View Full Code Here

        super(fname, arguments);
        _entity = argument();
    }

    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
        final Type entity = _entity.typeCheck(stable);
        if (entity instanceof StringType == false) {
            _entity = new CastExpr(_entity, Type.String);
        }
        return _type = Type.String;
    }
View Full Code Here

        final String str = getAttribute("disable-output-escaping");
        if ((str != null) && (str.equals("yes"))) _escaping = false;
    }

    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
        Type type = _select.typeCheck(stable);

        // Prefer to handle the value as a node; fall back to String, otherwise
        if (type != null && !type.identicalTo(Type.Node)) {
            /***
             *** %HZ% Would like to treat result-tree fragments in the same
             *** %HZ% way as node sets for value-of, but that's running into
             *** %HZ% some snags.  Instead, they'll be converted to String
            if (type.identicalTo(Type.ResultTree)) {
                _select = new CastExpr(new CastExpr(_select, Type.NodeSet),
                                       Type.Node);
            } else
            ***/
            if (type.identicalTo(Type.NodeSet)) {
                _select = new CastExpr(_select, Type.Node);
            } else {
                _isString = true;
                if (!type.identicalTo(Type.String)) {
                    _select = new CastExpr(_select, Type.String);
                }
                _isString = true;
            }
        }
View Full Code Here

    /**
     * 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.startIterator(classGen, methodGen);
      Type.NodeSet.translateTo(classGen, methodGen, Type.Boolean);
      _right.translate(classGen, methodGen);

      il.append(IXOR); // x != y <-> x xor y
        if (_op == Operators.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.startIterator(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.startIterator(classGen, methodGen);
  _right.translate(classGen, methodGen);
  _right.startIterator(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

    public Type typeCheck(SymbolTable stable) throws TypeCheckError {

  // Inform stylesheet to instantiate a DecimalFormat object
  getStylesheet().numberFormattingUsed();

  final Type tvalue = _value.typeCheck(stable);
  if (tvalue instanceof RealType == false) {
      _value = new CastExpr(_value, Type.Real);
  }
  final Type tformat = _format.typeCheck(stable);
  if (tformat instanceof StringType == false) {
      _format = new CastExpr(_format, Type.String);
  }
  if (argumentCount() == 3) {
      final Type tname = _name.typeCheck(stable);

      if (_name instanceof LiteralExpr) {
    final LiteralExpr literal = (LiteralExpr) _name;
    _resolvedQName =
        getParser().getQNameIgnoreDefaultNs(literal.getValue());
View Full Code Here

                                                  getName(), this));
        }
       
         // Second argument must be of type reference or object
        _right = argument(1);
        Type tright = _right.typeCheck(stable);
        if (tright != Type.Reference &&
            tright instanceof ObjectType == false)
        {
      throw new TypeCheckError(new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
                                                  tright, _type, this));
View Full Code Here

  }
    }

    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  if (_value != null) {
      Type tvalue = _value.typeCheck(stable);
      if (tvalue instanceof RealType == false) {
    _value = new CastExpr(_value, Type.Real);
      }
  }
  if (_count != null) {
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.