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: CompareGenerator.java,v 1.7 2004/02/16 22:26:45 minchau Exp $
  18. */
  19. package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
  20. import com.sun.org.apache.bcel.internal.generic.ACONST_NULL;
  21. import com.sun.org.apache.bcel.internal.generic.ALOAD;
  22. import com.sun.org.apache.bcel.internal.generic.ASTORE;
  23. import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
  24. import com.sun.org.apache.bcel.internal.generic.ILOAD;
  25. import com.sun.org.apache.bcel.internal.generic.ISTORE;
  26. import com.sun.org.apache.bcel.internal.generic.Instruction;
  27. import com.sun.org.apache.bcel.internal.generic.InstructionList;
  28. import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
  29. import com.sun.org.apache.bcel.internal.generic.Type;
  30. import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
  31. /**
  32. * @author Jacek Ambroziak
  33. * @author Santiago Pericas-Geertsen
  34. */
  35. public final class CompareGenerator extends MethodGenerator {
  36. private static int DOM_INDEX = 1;
  37. private static int CURRENT_INDEX = 2;
  38. private static int LEVEL_INDEX = 3;
  39. private static int TRANSLET_INDEX = 4;
  40. private static int LAST_INDEX = 5;
  41. private int ITERATOR_INDEX = 6;
  42. private final Instruction _iloadCurrent;
  43. private final Instruction _istoreCurrent;
  44. private final Instruction _aloadDom;
  45. private final Instruction _iloadLast;
  46. private final Instruction _aloadIterator;
  47. private final Instruction _astoreIterator;
  48. public CompareGenerator(int access_flags, Type return_type,
  49. Type[] arg_types, String[] arg_names,
  50. String method_name, String class_name,
  51. InstructionList il, ConstantPoolGen cp) {
  52. super(access_flags, return_type, arg_types, arg_names, method_name,
  53. class_name, il, cp);
  54. _iloadCurrent = new ILOAD(CURRENT_INDEX);
  55. _istoreCurrent = new ISTORE(CURRENT_INDEX);
  56. _aloadDom = new ALOAD(DOM_INDEX);
  57. _iloadLast = new ILOAD(LAST_INDEX);
  58. LocalVariableGen iterator =
  59. addLocalVariable("iterator",
  60. Util.getJCRefType(Constants.NODE_ITERATOR_SIG),
  61. null, null);
  62. ITERATOR_INDEX = iterator.getIndex();
  63. _aloadIterator = new ALOAD(ITERATOR_INDEX);
  64. _astoreIterator = new ASTORE(ITERATOR_INDEX);
  65. il.append(new ACONST_NULL());
  66. il.append(storeIterator());
  67. }
  68. public Instruction loadLastNode() {
  69. return _iloadLast;
  70. }
  71. public Instruction loadCurrentNode() {
  72. return _iloadCurrent;
  73. }
  74. public Instruction storeCurrentNode() {
  75. return _istoreCurrent;
  76. }
  77. public Instruction loadDOM() {
  78. return _aloadDom;
  79. }
  80. public int getHandlerIndex() {
  81. return INVALID_INDEX; // not available
  82. }
  83. public int getIteratorIndex() {
  84. return INVALID_INDEX;
  85. }
  86. public Instruction storeIterator() {
  87. return _astoreIterator;
  88. }
  89. public Instruction loadIterator() {
  90. return _aloadIterator;
  91. }
  92. //??? may not be used anymore
  93. public int getLocalIndex(String name) {
  94. if (name.equals("current")) {
  95. return CURRENT_INDEX;
  96. }
  97. return super.getLocalIndex(name);
  98. }
  99. }