📄 number.java
字号:
il.append(ALOAD_0); // this il.append(ALOAD_1); // translet il.append(ALOAD_2); // DOM il.append(new ALOAD(3));// iterator int index = cpg.addMethodref(ClassNames[_level], "<init>", "(" + TRANSLET_INTF_SIG + DOM_INTF_SIG + NODE_ITERATOR_SIG + ")V"); il.append(new INVOKESPECIAL(index)); il.append(RETURN); cons.stripAttributes(true); cons.setMaxLocals(); cons.setMaxStack(); classGen.addMethod(cons.getMethod()); } /** * This method compiles code that is common to matchesFrom() and * matchesCount() in the auxillary class. */ private void compileLocals(NodeCounterGenerator nodeCounterGen, MatchGenerator matchGen, InstructionList il) { int field; LocalVariableGen local; ConstantPoolGen cpg = nodeCounterGen.getConstantPool(); // Get NodeCounter._iterator and store locally local = matchGen.addLocalVariable("iterator", Util.getJCRefType(NODE_ITERATOR_SIG), null, null); field = cpg.addFieldref(NODE_COUNTER, "_iterator", ITERATOR_FIELD_SIG); il.append(ALOAD_0); // 'this' pointer on stack il.append(new GETFIELD(field)); il.append(new ASTORE(local.getIndex())); matchGen.setIteratorIndex(local.getIndex()); // Get NodeCounter._translet and store locally local = matchGen.addLocalVariable("translet", Util.getJCRefType(TRANSLET_SIG), null, null); field = cpg.addFieldref(NODE_COUNTER, "_translet", "Lcom/sun/org/apache/xalan/internal/xsltc/Translet;"); il.append(ALOAD_0); // 'this' pointer on stack il.append(new GETFIELD(field)); il.append(new CHECKCAST(cpg.addClass(TRANSLET_CLASS))); il.append(new ASTORE(local.getIndex())); nodeCounterGen.setTransletIndex(local.getIndex()); // Get NodeCounter._document and store locally local = matchGen.addLocalVariable("document", Util.getJCRefType(DOM_INTF_SIG), null, null); field = cpg.addFieldref(_className, "_document", DOM_INTF_SIG); il.append(ALOAD_0); // 'this' pointer on stack il.append(new GETFIELD(field)); // Make sure we have the correct DOM type on the stack!!! il.append(new ASTORE(local.getIndex())); matchGen.setDomIndex(local.getIndex()); } private void compilePatterns(ClassGenerator classGen, MethodGenerator methodGen) { int current; int field; LocalVariableGen local; MatchGenerator matchGen; NodeCounterGenerator nodeCounterGen; _className = getXSLTC().getHelperClassName(); nodeCounterGen = new NodeCounterGenerator(_className, ClassNames[_level], toString(), ACC_PUBLIC | ACC_SUPER, null, classGen.getStylesheet()); InstructionList il = null; ConstantPoolGen cpg = nodeCounterGen.getConstantPool(); // Add a new instance variable for each var in closure final int closureLen = (_closureVars == null) ? 0 : _closureVars.size(); for (int i = 0; i < closureLen; i++) { VariableBase var = ((VariableRefBase) _closureVars.get(i)).getVariable(); nodeCounterGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool())); } // Add a single constructor to the class compileConstructor(nodeCounterGen); /* * Compile method matchesFrom() */ if (_from != null) { il = new InstructionList(); matchGen = new MatchGenerator(ACC_PUBLIC | ACC_FINAL, com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN, new com.sun.org.apache.bcel.internal.generic.Type[] { com.sun.org.apache.bcel.internal.generic.Type.INT, }, new String[] { "node", }, "matchesFrom", _className, il, cpg); compileLocals(nodeCounterGen,matchGen,il); // Translate Pattern il.append(matchGen.loadContextNode()); _from.translate(nodeCounterGen, matchGen); _from.synthesize(nodeCounterGen, matchGen); il.append(IRETURN); matchGen.stripAttributes(true); matchGen.setMaxLocals(); matchGen.setMaxStack(); matchGen.removeNOPs(); nodeCounterGen.addMethod(matchGen.getMethod()); } /* * Compile method matchesCount() */ if (_count != null) { il = new InstructionList(); matchGen = new MatchGenerator(ACC_PUBLIC | ACC_FINAL, com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN, new com.sun.org.apache.bcel.internal.generic.Type[] { com.sun.org.apache.bcel.internal.generic.Type.INT, }, new String[] { "node", }, "matchesCount", _className, il, cpg); compileLocals(nodeCounterGen,matchGen,il); // Translate Pattern il.append(matchGen.loadContextNode()); _count.translate(nodeCounterGen, matchGen); _count.synthesize(nodeCounterGen, matchGen); il.append(IRETURN); matchGen.stripAttributes(true); matchGen.setMaxLocals(); matchGen.setMaxStack(); matchGen.removeNOPs(); nodeCounterGen.addMethod(matchGen.getMethod()); } getXSLTC().dumpClass(nodeCounterGen.getJavaClass()); // Push an instance of the newly created class cpg = classGen.getConstantPool(); il = methodGen.getInstructionList(); final int index = cpg.addMethodref(_className, "<init>", "(" + TRANSLET_INTF_SIG + DOM_INTF_SIG + NODE_ITERATOR_SIG + ")V"); il.append(new NEW(cpg.addClass(_className))); il.append(DUP); il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(new INVOKESPECIAL(index)); // Initialize closure variables for (int i = 0; i < closureLen; i++) { final VariableRefBase varRef = (VariableRefBase) _closureVars.get(i); final VariableBase var = varRef.getVariable(); final Type varType = var.getType(); // Store variable in new closure il.append(DUP); il.append(var.loadInstruction()); il.append(new PUTFIELD( cpg.addFieldref(_className, var.getEscapedName(), varType.toSignature()))); } } public void translate(ClassGenerator classGen, MethodGenerator methodGen) { int index; final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // Push "this" for the call to characters() il.append(classGen.loadTranslet()); if (hasValue()) { compileDefault(classGen, methodGen); _value.translate(classGen, methodGen); // Using java.lang.Math.floor(number + 0.5) to return a double value il.append(new PUSH(cpg, 0.5)); il.append(DADD); index = cpg.addMethodref(MATH_CLASS, "floor", "(D)D"); il.append(new INVOKESTATIC(index)); // Call setValue on the node counter index = cpg.addMethodref(NODE_COUNTER, "setValue", "(D)" + NODE_COUNTER_SIG); il.append(new INVOKEVIRTUAL(index)); } else if (isDefault()) { compileDefault(classGen, methodGen); } else { compilePatterns(classGen, methodGen); } // Call setStartNode() if (!hasValue()) { il.append(methodGen.loadContextNode()); index = cpg.addMethodref(NODE_COUNTER, SET_START_NODE, "(I)" + NODE_COUNTER_SIG); il.append(new INVOKEVIRTUAL(index)); } // Call getCounter() with or without args if (_formatNeeded) { if (_format != null) { _format.translate(classGen, methodGen); } else { il.append(new PUSH(cpg, "1")); } if (_lang != null) { _lang.translate(classGen, methodGen); } else { il.append(new PUSH(cpg, "en")); // TODO ?? } if (_letterValue != null) { _letterValue.translate(classGen, methodGen); } else { il.append(new PUSH(cpg, Constants.EMPTYSTRING)); } if (_groupingSeparator != null) { _groupingSeparator.translate(classGen, methodGen); } else { il.append(new PUSH(cpg, Constants.EMPTYSTRING)); } if (_groupingSize != null) { _groupingSize.translate(classGen, methodGen); } else { il.append(new PUSH(cpg, "0")); } index = cpg.addMethodref(NODE_COUNTER, "getCounter", "(" + STRING_SIG + STRING_SIG + STRING_SIG + STRING_SIG + STRING_SIG + ")" + STRING_SIG); il.append(new INVOKEVIRTUAL(index)); } else { index = cpg.addMethodref(NODE_COUNTER, "setDefaultFormatting", "()" + NODE_COUNTER_SIG); il.append(new INVOKEVIRTUAL(index)); index = cpg.addMethodref(NODE_COUNTER, "getCounter", "()" + STRING_SIG); il.append(new INVOKEVIRTUAL(index)); } // Output the resulting string to the handler il.append(methodGen.loadHandler()); index = cpg.addMethodref(TRANSLET_CLASS, CHARACTERSW, CHARACTERSW_SIG); il.append(new INVOKEVIRTUAL(index)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -