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: MatchGenerator.java,v 1.5 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.ALOAD;
  21. import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
  22. import com.sun.org.apache.bcel.internal.generic.ILOAD;
  23. import com.sun.org.apache.bcel.internal.generic.ISTORE;
  24. import com.sun.org.apache.bcel.internal.generic.Instruction;
  25. import com.sun.org.apache.bcel.internal.generic.InstructionList;
  26. import com.sun.org.apache.bcel.internal.generic.Type;
  27. /**
  28. * @author Jacek Ambroziak
  29. * @author Santiago Pericas-Geertsen
  30. */
  31. public final class MatchGenerator extends MethodGenerator {
  32. private static int CURRENT_INDEX = 1;
  33. private int _iteratorIndex = INVALID_INDEX;
  34. private final Instruction _iloadCurrent;
  35. private final Instruction _istoreCurrent;
  36. private Instruction _aloadDom;
  37. public MatchGenerator(int access_flags, Type return_type,
  38. Type[] arg_types, String[] arg_names,
  39. String method_name, String class_name,
  40. InstructionList il, ConstantPoolGen cp) {
  41. super(access_flags, return_type, arg_types, arg_names, method_name,
  42. class_name, il, cp);
  43. _iloadCurrent = new ILOAD(CURRENT_INDEX);
  44. _istoreCurrent = new ISTORE(CURRENT_INDEX);
  45. }
  46. public Instruction loadCurrentNode() {
  47. return _iloadCurrent;
  48. }
  49. public Instruction storeCurrentNode() {
  50. return _istoreCurrent;
  51. }
  52. public int getHandlerIndex() {
  53. return INVALID_INDEX; // not available
  54. }
  55. /**
  56. * Get index of the register where the DOM is stored.
  57. */
  58. public Instruction loadDOM() {
  59. return _aloadDom;
  60. }
  61. /**
  62. * Set index where the reference to the DOM is stored.
  63. */
  64. public void setDomIndex(int domIndex) {
  65. _aloadDom = new ALOAD(domIndex);
  66. }
  67. /**
  68. * Get index of the register where the current iterator is stored.
  69. */
  70. public int getIteratorIndex() {
  71. return _iteratorIndex;
  72. }
  73. /**
  74. * Set index of the register where the current iterator is stored.
  75. */
  76. public void setIteratorIndex(int iteratorIndex) {
  77. _iteratorIndex = iteratorIndex;
  78. }
  79. public int getLocalIndex(String name) {
  80. if (name.equals("current")) {
  81. return CURRENT_INDEX;
  82. }
  83. return super.getLocalIndex(name);
  84. }
  85. }