1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler; 21 22 import java.util.Vector ; 23 24 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 25 import com.sun.org.apache.bcel.internal.generic.GETFIELD; 26 import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE; 27 import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC; 28 import com.sun.org.apache.bcel.internal.generic.InstructionList; 29 import com.sun.org.apache.bcel.internal.generic.PUSH; 30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; 32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 34 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 35 36 40 final class DocumentCall extends FunctionCall { 41 42 private Expression _arg1 = null; 43 private Expression _arg2 = null; 44 private Type _arg1Type; 45 46 49 public DocumentCall(QName fname, Vector arguments) { 50 super(fname, arguments); 51 } 52 53 58 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 59 final int ac = argumentCount(); 61 if ((ac < 1) || (ac > 2)) { 62 ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_ARG_ERR, this); 63 throw new TypeCheckError(msg); 64 } 65 if (getStylesheet() == null) { 66 ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_ARG_ERR, this); 67 throw new TypeCheckError(msg); 68 } 69 70 _arg1 = argument(0); 72 73 if (_arg1 == null) { ErrorMsg msg = new ErrorMsg(ErrorMsg.DOCUMENT_ARG_ERR, this); 75 throw new TypeCheckError(msg); 76 } 77 78 _arg1Type = _arg1.typeCheck(stable); 79 if ((_arg1Type != Type.NodeSet) && (_arg1Type != Type.String)) { 80 _arg1 = new CastExpr(_arg1, Type.String); 81 } 82 83 if (ac == 2) { 85 _arg2 = argument(1); 86 87 if (_arg2 == null) { ErrorMsg msg = new ErrorMsg(ErrorMsg.DOCUMENT_ARG_ERR, this); 89 throw new TypeCheckError(msg); 90 } 91 92 final Type arg2Type = _arg2.typeCheck(stable); 93 94 if (arg2Type.identicalTo(Type.Node)) { 95 _arg2 = new CastExpr(_arg2, Type.NodeSet); 96 } else if (arg2Type.identicalTo(Type.NodeSet)) { 97 } else { 99 ErrorMsg msg = new ErrorMsg(ErrorMsg.DOCUMENT_ARG_ERR, this); 100 throw new TypeCheckError(msg); 101 } 102 } 103 104 return _type = Type.NodeSet; 105 } 106 107 111 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 112 final ConstantPoolGen cpg = classGen.getConstantPool(); 113 final InstructionList il = methodGen.getInstructionList(); 114 final int ac = argumentCount(); 115 116 final int domField = cpg.addFieldref(classGen.getClassName(), 117 DOM_FIELD, 118 DOM_INTF_SIG); 119 120 String docParamList = null; 121 if (ac == 1) { 122 docParamList = "("+OBJECT_SIG+STRING_SIG+TRANSLET_SIG+DOM_INTF_SIG 124 +")"+NODE_ITERATOR_SIG; 125 } else { docParamList = "("+OBJECT_SIG+NODE_ITERATOR_SIG+STRING_SIG 128 +TRANSLET_SIG+DOM_INTF_SIG+")"+NODE_ITERATOR_SIG; 129 } 130 final int docIdx = cpg.addMethodref(LOAD_DOCUMENT_CLASS, "documentF", 131 docParamList); 132 133 134 _arg1.translate(classGen, methodGen); 136 if (_arg1Type == Type.NodeSet) { 137 _arg1.startIterator(classGen, methodGen); 138 } 139 140 if (ac == 2) { 141 _arg2.translate(classGen, methodGen); 143 _arg2.startIterator(classGen, methodGen); 144 } 145 146 il.append(new PUSH(cpg, getStylesheet().getSystemId())); 148 il.append(classGen.loadTranslet()); 149 il.append(DUP); 150 il.append(new GETFIELD(domField)); 151 il.append(new INVOKESTATIC(docIdx)); 152 } 153 154 } 155 | Popular Tags |