1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import org.apache.bcel.generic.ConstantPoolGen; 23 import org.apache.bcel.generic.INVOKEINTERFACE; 24 import org.apache.bcel.generic.INVOKESPECIAL; 25 import org.apache.bcel.generic.INVOKEVIRTUAL; 26 import org.apache.bcel.generic.InstructionList; 27 import org.apache.bcel.generic.NEW; 28 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 29 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 30 import org.apache.xalan.xsltc.compiler.util.NodeSetType; 31 import org.apache.xalan.xsltc.compiler.util.NodeType; 32 import org.apache.xalan.xsltc.compiler.util.ReferenceType; 33 import org.apache.xalan.xsltc.compiler.util.Type; 34 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 35 36 40 final class FilterParentPath extends Expression { 41 42 private Expression _filterExpr; 43 private Expression _path; 44 private boolean _hasDescendantAxis = false; 45 46 public FilterParentPath(Expression filterExpr, Expression path) { 47 (_path = path).setParent(this); 48 (_filterExpr = filterExpr).setParent(this); 49 } 50 51 public void setParser(Parser parser) { 52 super.setParser(parser); 53 _filterExpr.setParser(parser); 54 _path.setParser(parser); 55 } 56 57 public String toString() { 58 return "FilterParentPath(" + _filterExpr + ", " + _path + ')'; 59 } 60 61 public void setDescendantAxis() { 62 _hasDescendantAxis = true; 63 } 64 65 70 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 71 final Type ftype = _filterExpr.typeCheck(stable); 72 if (ftype instanceof NodeSetType == false) { 73 if (ftype instanceof ReferenceType) { 74 _filterExpr = new CastExpr(_filterExpr, Type.NodeSet); 75 } 76 81 else if (ftype instanceof NodeType) { 82 _filterExpr = new CastExpr(_filterExpr, Type.NodeSet); 83 } 84 else { 85 throw new TypeCheckError(this); 86 } 87 } 88 89 final Type ptype = _path.typeCheck(stable); 91 if (!(ptype instanceof NodeSetType)) { 92 _path = new CastExpr(_path, Type.NodeSet); 93 } 94 95 return _type = Type.NodeSet; 96 } 97 98 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 99 final ConstantPoolGen cpg = classGen.getConstantPool(); 100 final InstructionList il = methodGen.getInstructionList(); 101 final int initSI = cpg.addMethodref(STEP_ITERATOR_CLASS, 103 "<init>", 104 "(" 105 +NODE_ITERATOR_SIG 106 +NODE_ITERATOR_SIG 107 +")V"); 108 il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS))); 109 il.append(DUP); 110 111 _filterExpr.translate(classGen, methodGen); 113 _path.translate(classGen, methodGen); 114 115 il.append(new INVOKESPECIAL(initSI)); 117 118 if (_hasDescendantAxis) { 120 final int incl = cpg.addMethodref(NODE_ITERATOR_BASE, 121 "includeSelf", 122 "()" + NODE_ITERATOR_SIG); 123 il.append(new INVOKEVIRTUAL(incl)); 124 } 125 126 if (!(getParent() instanceof RelativeLocationPath) && 127 !(getParent() instanceof FilterParentPath)) { 128 final int order = cpg.addInterfaceMethodref(DOM_INTF, 129 ORDER_ITERATOR, 130 ORDER_ITERATOR_SIG); 131 il.append(methodGen.loadDOM()); 132 il.append(SWAP); 133 il.append(methodGen.loadContextNode()); 134 il.append(new INVOKEINTERFACE(order, 3)); 135 } 136 } 137 } 138 | Popular Tags |