santiagopg 2003/02/26 12:11:19
Modified: java/src/org/apache/xalan/xsltc/compiler/util
ReferenceType.java
Log:
Fix for Bugzilla 17447. Conversion from reference type to string type
assumed the existence of the "current" local variable, which is
unavailable at top-level.
Revision Changes Path
1.15 +51 -43
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ReferenceType.java
Index: ReferenceType.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ReferenceType.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ReferenceType.java 30 Jan 2003 18:46:09 -0000 1.14
+++ ReferenceType.java 26 Feb 2003 20:11:19 -0000 1.15
@@ -64,6 +64,8 @@
package org.apache.xalan.xsltc.compiler.util;
+import org.apache.xalan.xsltc.DOM;
+import org.apache.bcel.generic.PUSH;
import org.apache.bcel.generic.ALOAD;
import org.apache.bcel.generic.ASTORE;
import org.apache.bcel.generic.ConstantPoolGen;
@@ -96,13 +98,13 @@
}
/**
- * Translates a reference to an object of internal type
<code>type</code>.
+ * Translates a reference to an object of internal type
<code>type</code>.
* The translation to int is undefined since references
* are always converted to reals in arithmetic expressions.
*
* @see org.apache.xalan.xsltc.compiler.util.Type#translateTo
*/
- public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
+ public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
Type type) {
if (type == Type.String) {
translateTo(classGen, methodGen, (StringType) type);
@@ -132,20 +134,26 @@
}
/**
- * Translates reference into object of internal type <code>type</code>.
+ * Translates reference into object of internal type <code>type</code>.
*
* @see org.apache.xalan.xsltc.compiler.util.Type#translateTo
*/
- public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
+ public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
StringType type) {
final int current = methodGen.getLocalIndex("current");
ConstantPoolGen cpg = classGen.getConstantPool();
InstructionList il = methodGen.getInstructionList();
- il.append(new ILOAD(current));
+ // If no current, conversion is a top-level
+ if (current < 0) {
+ il.append(new PUSH(cpg, DOM.ROOTNODE)); // push root node
+ }
+ else {
+ il.append(new ILOAD(current));
+ }
il.append(methodGen.loadDOM());
final int stringF = cpg.addMethodref(BASIS_LIBRARY_CLASS,
- "stringF",
+ "stringF",
"("
+ OBJECT_SIG
+ NODE_SIG
@@ -155,18 +163,18 @@
}
/**
- * Translates a reference into an object of internal type
<code>type</code>.
+ * Translates a reference into an object of internal type
<code>type</code>.
*
* @see org.apache.xalan.xsltc.compiler.util.Type#translateTo
*/
- public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
+ public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
RealType type) {
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
il.append(methodGen.loadDOM());
- int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "numberF",
- "("
+ int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "numberF",
+ "("
+ OBJECT_SIG
+ DOM_INTF_SIG
+ ")D");
@@ -174,17 +182,17 @@
}
/**
- * Translates a reference to an object of internal type
<code>type</code>.
+ * Translates a reference to an object of internal type
<code>type</code>.
*
* @see org.apache.xalan.xsltc.compiler.util.Type#translateTo
*/
- public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
+ public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
BooleanType type) {
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
- int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "booleanF",
- "("
+ int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "booleanF",
+ "("
+ OBJECT_SIG
+ ")Z");
il.append(new INVOKESTATIC(index));
@@ -195,17 +203,17 @@
*
* @see org.apache.xalan.xsltc.compiler.util.Type#translateTo
*/
- public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
+ public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
NodeSetType type) {
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
- int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToNodeSet",
+ int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToNodeSet",
"("
+ OBJECT_SIG
+ ")"
+ NODE_ITERATOR_SIG);
il.append(new INVOKESTATIC(index));
-
+
// Reset this iterator
index = cpg.addInterfaceMethodref(NODE_ITERATOR, RESET, RESET_SIG);
il.append(new INVOKEINTERFACE(index, 1));
@@ -227,11 +235,11 @@
*
* @see org.apache.xalan.xsltc.compiler.util.Type#translateTo
*/
- public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
+ public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
ResultTreeType type) {
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
- int index = cpg.addMethodref(BASIS_LIBRARY_CLASS,
"referenceToResultTree",
+ int index = cpg.addMethodref(BASIS_LIBRARY_CLASS,
"referenceToResultTree",
"(" + OBJECT_SIG + ")" + DOM_INTF_SIG);
il.append(new INVOKESTATIC(index));
}
@@ -241,21 +249,21 @@
*
* @see org.apache.xalan.xsltc.compiler.util.Type#translateTo
*/
- public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
+ public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
ObjectType type) {
- methodGen.getInstructionList().append(NOP);
+ methodGen.getInstructionList().append(NOP);
}
/**
- * Translates a reference into the Java type denoted by
<code>clazz</code>.
+ * Translates a reference into the Java type denoted by
<code>clazz</code>.
*/
- public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
+ public void translateTo(ClassGenerator classGen, MethodGenerator
methodGen,
Class clazz) {
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
-
+
if (clazz.getName().equals("java.lang.Object")) {
- il.append(NOP);
+ il.append(NOP);
}
else if (clazz == Double.TYPE) {
translateTo(classGen, methodGen, Type.Real);
@@ -264,20 +272,20 @@
translateTo(classGen, methodGen, Type.String);
}
else if (clazz.getName().equals("org.w3c.dom.Node")) {
- int index = cpg.addMethodref(BASIS_LIBRARY_CLASS,
"referenceToNode",
- "("
- + OBJECT_SIG
- + DOM_INTF_SIG
+ int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToNode",
+ "("
+ + OBJECT_SIG
+ + DOM_INTF_SIG
+ ")"
+ "Lorg/w3c/dom/Node;");
il.append(methodGen.loadDOM());
il.append(new INVOKESTATIC(index));
}
else if (clazz.getName().equals("org.w3c.dom.NodeList")) {
- int index = cpg.addMethodref(BASIS_LIBRARY_CLASS,
"referenceToNodeList",
- "("
- + OBJECT_SIG
- + DOM_INTF_SIG
+ int index = cpg.addMethodref(BASIS_LIBRARY_CLASS,
"referenceToNodeList",
+ "("
+ + OBJECT_SIG
+ + DOM_INTF_SIG
+ ")"
+ "Lorg/w3c/dom/NodeList;");
il.append(methodGen.loadDOM());
@@ -297,27 +305,27 @@
* Translates an external Java type into a reference. Only conversion
* allowed is from java.lang.Object.
*/
- public void translateFrom(ClassGenerator classGen, MethodGenerator
methodGen,
+ public void translateFrom(ClassGenerator classGen, MethodGenerator
methodGen,
Class clazz) {
if (clazz.getName().equals("java.lang.Object")) {
- methodGen.getInstructionList().append(NOP);
+ methodGen.getInstructionList().append(NOP);
}
else {
ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
toString(), clazz.getName());
classGen.getParser().reportError(Constants.FATAL, err);
- }
+ }
}
/**
* Expects a reference on the stack and translates it to a
non-synthesized
- * boolean. It does not push a 0 or a 1 but instead returns branchhandle
+ * boolean. It does not push a 0 or a 1 but instead returns branchhandle
* list to be appended to the false list.
*
* @see
org.apache.xalan.xsltc.compiler.util.Type#translateToDesynthesized
*/
- public FlowList translateToDesynthesized(ClassGenerator classGen,
- MethodGenerator methodGen,
+ public FlowList translateToDesynthesized(ClassGenerator classGen,
+ MethodGenerator methodGen,
BooleanType type) {
InstructionList il = methodGen.getInstructionList();
translateTo(classGen, methodGen, type);
@@ -326,14 +334,14 @@
/**
* Translates an object of this type to its boxed representation.
- */
+ */
public void translateBox(ClassGenerator classGen,
MethodGenerator methodGen) {
}
/**
* Translates an object of this type to its unboxed representation.
- */
+ */
public void translateUnBox(ClassGenerator classGen,
MethodGenerator methodGen) {
}
@@ -342,7 +350,7 @@
public Instruction LOAD(int slot) {
return new ALOAD(slot);
}
-
+
public Instruction STORE(int slot) {
return new ASTORE(slot);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]