1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import org.apache.bcel.generic.BranchHandle; 23 import org.apache.bcel.generic.ConstantPoolGen; 24 import org.apache.bcel.generic.GOTO_W; 25 import org.apache.bcel.generic.IF_ICMPEQ; 26 import org.apache.bcel.generic.ILOAD; 27 import org.apache.bcel.generic.INVOKEINTERFACE; 28 import org.apache.bcel.generic.ISTORE; 29 import org.apache.bcel.generic.InstructionHandle; 30 import org.apache.bcel.generic.InstructionList; 31 import org.apache.bcel.generic.LocalVariableGen; 32 import org.apache.bcel.generic.PUSH; 33 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 34 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 35 import org.apache.xalan.xsltc.compiler.util.Type; 36 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 37 import org.apache.xalan.xsltc.compiler.util.Util; 38 import org.apache.xml.dtm.DTM; 39 40 44 final class AbsolutePathPattern extends LocationPathPattern { 45 private final RelativePathPattern _left; 47 public AbsolutePathPattern(RelativePathPattern left) { 48 _left = left; 49 if (left != null) { 50 left.setParent(this); 51 } 52 } 53 54 public void setParser(Parser parser) { 55 super.setParser(parser); 56 if (_left != null) 57 _left.setParser(parser); 58 } 59 60 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 61 return _left == null ? Type.Root : _left.typeCheck(stable); 62 } 63 64 public boolean isWildcard() { 65 return false; 66 } 67 68 public StepPattern getKernelPattern() { 69 return _left != null ? _left.getKernelPattern() : null; 70 } 71 72 public void reduceKernelPattern() { 73 _left.reduceKernelPattern(); 74 } 75 76 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 77 final ConstantPoolGen cpg = classGen.getConstantPool(); 78 final InstructionList il = methodGen.getInstructionList(); 79 80 if (_left != null) { 81 if (_left instanceof StepPattern) { 82 final LocalVariableGen local = 83 methodGen.addLocalVariable2("apptmp", 85 Util.getJCRefType(NODE_SIG), 86 il.getEnd()); 87 il.append(DUP); 88 il.append(new ISTORE(local.getIndex())); 89 _left.translate(classGen, methodGen); 90 il.append(methodGen.loadDOM()); 91 local.setEnd(il.append(new ILOAD(local.getIndex()))); 92 methodGen.removeLocalVariable(local); 93 } 94 else { 95 _left.translate(classGen, methodGen); 96 } 97 } 98 99 final int getParent = cpg.addInterfaceMethodref(DOM_INTF, 100 GET_PARENT, 101 GET_PARENT_SIG); 102 final int getType = cpg.addInterfaceMethodref(DOM_INTF, 103 "getExpandedTypeID", 104 "(I)I"); 105 106 InstructionHandle begin = il.append(methodGen.loadDOM()); 107 il.append(SWAP); 108 il.append(new INVOKEINTERFACE(getParent, 2)); 109 if (_left instanceof AncestorPattern) { 110 il.append(methodGen.loadDOM()); 111 il.append(SWAP); 112 } 113 il.append(new INVOKEINTERFACE(getType, 2)); 114 il.append(new PUSH(cpg, DTM.DOCUMENT_NODE)); 115 116 final BranchHandle skip = il.append(new IF_ICMPEQ(null)); 117 _falseList.add(il.append(new GOTO_W(null))); 118 skip.setTarget(il.append(NOP)); 119 120 if (_left != null) { 121 _left.backPatchTrueList(begin); 122 123 127 if (_left instanceof AncestorPattern) { 128 final AncestorPattern ancestor = (AncestorPattern) _left; 129 _falseList.backPatch(ancestor.getLoopHandle()); } 131 _falseList.append(_left._falseList); 132 } 133 } 134 135 public String toString() { 136 return "absolutePathPattern(" + (_left != null ? _left.toString() : ")"); 137 } 138 } 139 | Popular Tags |