1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: ParameterRef.java,v 1.17 2004/02/16 22:24:28 minchau Exp $
  18. */
  19. package com.sun.org.apache.xalan.internal.xsltc.compiler;
  20. import com.sun.org.apache.bcel.internal.generic.CHECKCAST;
  21. import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
  22. import com.sun.org.apache.bcel.internal.generic.GETFIELD;
  23. import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
  24. import com.sun.org.apache.bcel.internal.generic.InstructionList;
  25. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
  26. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
  27. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSetType;
  28. import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary;
  29. /**
  30. * @author Jacek Ambroziak
  31. * @author Santiago Pericas-Geertsen
  32. * @author Morten Jorgensen
  33. * @author Erwin Bolwidt <ejb@klomp.org>
  34. */
  35. final class ParameterRef extends VariableRefBase {
  36. /**
  37. * Name of param being referenced.
  38. */
  39. QName _name = null;
  40. public ParameterRef(Param param) {
  41. super(param);
  42. _name = param._name;
  43. }
  44. public String toString() {
  45. return "parameter-ref("+_variable.getName()+'/'+_variable.getType()+')';
  46. }
  47. public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  48. final ConstantPoolGen cpg = classGen.getConstantPool();
  49. final InstructionList il = methodGen.getInstructionList();
  50. /*
  51. * To fix bug 24518 related to setting parameters of the form
  52. * {namespaceuri}localName, which will get mapped to an instance
  53. * variable in the class.
  54. */
  55. final String name = BasisLibrary.mapQNameToJavaName (_name.toString());
  56. final String signature = _type.toSignature();
  57. if (_variable.isLocal()) {
  58. if (classGen.isExternal()) {
  59. Closure variableClosure = _closure;
  60. while (variableClosure != null) {
  61. if (variableClosure.inInnerClass()) break;
  62. variableClosure = variableClosure.getParentClosure();
  63. }
  64. if (variableClosure != null) {
  65. il.append(ALOAD_0);
  66. il.append(new GETFIELD(
  67. cpg.addFieldref(variableClosure.getInnerClassName(),
  68. name, signature)));
  69. }
  70. else {
  71. il.append(_variable.loadInstruction());
  72. _variable.removeReference(this);
  73. }
  74. }
  75. else {
  76. il.append(_variable.loadInstruction());
  77. _variable.removeReference(this);
  78. }
  79. }
  80. else {
  81. final String className = classGen.getClassName();
  82. il.append(classGen.loadTranslet());
  83. if (classGen.isExternal()) {
  84. il.append(new CHECKCAST(cpg.addClass(className)));
  85. }
  86. il.append(new GETFIELD(cpg.addFieldref(className,name,signature)));
  87. }
  88. if (_variable.getType() instanceof NodeSetType) {
  89. // The method cloneIterator() also does resetting
  90. final int clone = cpg.addInterfaceMethodref(NODE_ITERATOR,
  91. "cloneIterator",
  92. "()" +
  93. NODE_ITERATOR_SIG);
  94. il.append(new INVOKEINTERFACE(clone, 1));
  95. }
  96. }
  97. }