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: TestGenerator.java,v 1.6 2004/02/16 22:26:44 minchau Exp $
  18. */
  19. package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
  20. import com.sun.org.apache.bcel.internal.generic.ALOAD;
  21. import com.sun.org.apache.bcel.internal.generic.ASTORE;
  22. import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
  23. import com.sun.org.apache.bcel.internal.generic.ILOAD;
  24. import com.sun.org.apache.bcel.internal.generic.ISTORE;
  25. import com.sun.org.apache.bcel.internal.generic.Instruction;
  26. import com.sun.org.apache.bcel.internal.generic.InstructionList;
  27. import com.sun.org.apache.bcel.internal.generic.Type;
  28. /**
  29. * @author Jacek Ambroziak
  30. * @author Santiago Pericas-Geertsen
  31. * @author Morten Jorgensen
  32. */
  33. public final class TestGenerator extends MethodGenerator {
  34. private static int CONTEXT_NODE_INDEX = 1;
  35. private static int CURRENT_NODE_INDEX = 4;
  36. private static int ITERATOR_INDEX = 6;
  37. private Instruction _aloadDom;
  38. private final Instruction _iloadCurrent;
  39. private final Instruction _iloadContext;
  40. private final Instruction _istoreCurrent;
  41. private final Instruction _istoreContext;
  42. private final Instruction _astoreIterator;
  43. private final Instruction _aloadIterator;
  44. public TestGenerator(int access_flags, Type return_type,
  45. Type[] arg_types, String[] arg_names,
  46. String method_name, String class_name,
  47. InstructionList il, ConstantPoolGen cp) {
  48. super(access_flags, return_type, arg_types, arg_names, method_name,
  49. class_name, il, cp);
  50. _iloadCurrent = new ILOAD(CURRENT_NODE_INDEX);
  51. _istoreCurrent = new ISTORE(CURRENT_NODE_INDEX);
  52. _iloadContext = new ILOAD(CONTEXT_NODE_INDEX);
  53. _istoreContext = new ILOAD(CONTEXT_NODE_INDEX);
  54. _astoreIterator = new ASTORE(ITERATOR_INDEX);
  55. _aloadIterator = new ALOAD(ITERATOR_INDEX);
  56. }
  57. public int getHandlerIndex() {
  58. return INVALID_INDEX; // not available
  59. }
  60. public int getIteratorIndex() {
  61. return ITERATOR_INDEX; // not available
  62. }
  63. public void setDomIndex(int domIndex) {
  64. _aloadDom = new ALOAD(domIndex);
  65. }
  66. public Instruction loadDOM() {
  67. return _aloadDom;
  68. }
  69. public Instruction loadCurrentNode() {
  70. return _iloadCurrent;
  71. }
  72. /** by default context node is the same as current node. MK437 */
  73. public Instruction loadContextNode() {
  74. return _iloadContext;
  75. }
  76. public Instruction storeContextNode() {
  77. return _istoreContext;
  78. }
  79. public Instruction storeCurrentNode() {
  80. return _istoreCurrent;
  81. }
  82. public Instruction storeIterator() {
  83. return _astoreIterator;
  84. }
  85. public Instruction loadIterator() {
  86. return _aloadIterator;
  87. }
  88. public int getLocalIndex(String name) {
  89. if (name.equals("current")) {
  90. return CURRENT_NODE_INDEX;
  91. }
  92. else {
  93. return super.getLocalIndex(name);
  94. }
  95. }
  96. }