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; 25 import org.apache.bcel.generic.IFEQ; 26 import org.apache.bcel.generic.IF_ICMPEQ; 27 import org.apache.bcel.generic.INVOKEINTERFACE; 28 import org.apache.bcel.generic.INVOKEVIRTUAL; 29 import org.apache.bcel.generic.InstructionHandle; 30 import org.apache.bcel.generic.InstructionList; 31 import org.apache.bcel.generic.PUSH; 32 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 33 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 34 import org.apache.xalan.xsltc.compiler.util.Type; 35 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 36 import org.apache.xalan.xsltc.dom.Axis; 37 import org.apache.xml.dtm.DTM; 38 39 42 final class ProcessingInstructionPattern extends StepPattern { 43 44 private String _name = null; 45 private boolean _typeChecked = false; 46 47 50 public ProcessingInstructionPattern(String name) { 51 super(Axis.CHILD, DTM.PROCESSING_INSTRUCTION_NODE, null); 52 _name = name; 53 } 55 56 59 public double getDefaultPriority() { 60 return (_name != null) ? 0.0 : -0.5; 61 } 62 public String toString() { 63 if (_predicates == null) 64 return "processing-instruction("+_name+")"; 65 else 66 return "processing-instruction("+_name+")"+_predicates; 67 } 68 69 public void reduceKernelPattern() { 70 _typeChecked = true; 71 } 72 73 public boolean isWildcard() { 74 return false; 75 } 76 77 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 78 if (hasPredicates()) { 79 final int n = _predicates.size(); 81 for (int i = 0; i < n; i++) { 82 final Predicate pred = (Predicate)_predicates.elementAt(i); 83 pred.typeCheck(stable); 84 } 85 } 86 return Type.NodeSet; 87 } 88 89 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 90 final ConstantPoolGen cpg = classGen.getConstantPool(); 91 final InstructionList il = methodGen.getInstructionList(); 92 93 int gname = cpg.addInterfaceMethodref(DOM_INTF, 95 "getNodeName", 96 "(I)Ljava/lang/String;"); 97 int cmp = cpg.addMethodref(STRING_CLASS, 98 "equals", "(Ljava/lang/Object;)Z"); 99 100 il.append(methodGen.loadCurrentNode()); 102 il.append(SWAP); 103 104 il.append(methodGen.storeCurrentNode()); 106 107 if (!_typeChecked) { 109 il.append(methodGen.loadCurrentNode()); 110 final int getType = cpg.addInterfaceMethodref(DOM_INTF, 111 "getExpandedTypeID", 112 "(I)I"); 113 il.append(methodGen.loadDOM()); 114 il.append(methodGen.loadCurrentNode()); 115 il.append(new INVOKEINTERFACE(getType, 2)); 116 il.append(new PUSH(cpg, DTM.PROCESSING_INSTRUCTION_NODE)); 117 _falseList.add(il.append(new IF_ICMPEQ(null))); 118 } 119 120 il.append(new PUSH(cpg, _name)); 122 il.append(methodGen.loadDOM()); 124 il.append(methodGen.loadCurrentNode()); 125 il.append(new INVOKEINTERFACE(gname, 2)); 126 il.append(new INVOKEVIRTUAL(cmp)); 128 _falseList.add(il.append(new IFEQ(null))); 129 130 if (hasPredicates()) { 132 final int n = _predicates.size(); 133 for (int i = 0; i < n; i++) { 134 Predicate pred = (Predicate)_predicates.elementAt(i); 135 Expression exp = pred.getExpr(); 136 exp.translateDesynthesized(classGen, methodGen); 137 _trueList.append(exp._trueList); 138 _falseList.append(exp._falseList); 139 } 140 } 141 142 InstructionHandle restore; 144 restore = il.append(methodGen.storeCurrentNode()); 145 backPatchTrueList(restore); 146 BranchHandle skipFalse = il.append(new GOTO(null)); 147 148 restore = il.append(methodGen.storeCurrentNode()); 150 backPatchFalseList(restore); 151 _falseList.add(il.append(new GOTO(null))); 152 153 skipFalse.setTarget(il.append(NOP)); 155 } 156 } 157 | Popular Tags |