View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 2001-2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  /*
21   * $Id: TestGenerator.java,v 1.2.4.1 2005/09/05 11:36:49 pvedula Exp $
22   */
23  
24  package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
25  
26  import com.sun.org.apache.bcel.internal.generic.ALOAD;
27  import com.sun.org.apache.bcel.internal.generic.ASTORE;
28  import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
29  import com.sun.org.apache.bcel.internal.generic.ILOAD;
30  import com.sun.org.apache.bcel.internal.generic.ISTORE;
31  import com.sun.org.apache.bcel.internal.generic.Instruction;
32  import com.sun.org.apache.bcel.internal.generic.InstructionList;
33  import com.sun.org.apache.bcel.internal.generic.Type;
34  
35  /**
36   * @author Jacek Ambroziak
37   * @author Santiago Pericas-Geertsen
38   * @author Morten Jorgensen
39   */
40  public final class TestGenerator extends MethodGenerator {
41      private static int CONTEXT_NODE_INDEX = 1;
42      private static int CURRENT_NODE_INDEX = 4;
43      private static int ITERATOR_INDEX = 6;
44  
45      private Instruction _aloadDom;
46      private final Instruction _iloadCurrent;
47      private final Instruction _iloadContext;
48      private final Instruction _istoreCurrent;
49      private final Instruction _istoreContext;
50      private final Instruction _astoreIterator;
51      private final Instruction _aloadIterator;
52  
53      public TestGenerator(int access_flags, Type return_type,
54                           Type[] arg_types, String[] arg_names,
55                           String method_name, String class_name,
56                           InstructionList il, ConstantPoolGen cp) {
57          super(access_flags, return_type, arg_types, arg_names, method_name,
58                class_name, il, cp);
59  
60          _iloadCurrent  = new ILOAD(CURRENT_NODE_INDEX);
61          _istoreCurrent = new ISTORE(CURRENT_NODE_INDEX);
62          _iloadContext  = new ILOAD(CONTEXT_NODE_INDEX);
63          _istoreContext  = new ILOAD(CONTEXT_NODE_INDEX);
64          _astoreIterator = new ASTORE(ITERATOR_INDEX);
65          _aloadIterator  = new ALOAD(ITERATOR_INDEX);
66      }
67  
68      public int getHandlerIndex() {
69          return INVALID_INDEX;           // not available
70      }
71  
72      public int getIteratorIndex() {
73          return ITERATOR_INDEX;          // not available
74      }
75  
76      public void setDomIndex(int domIndex) {
77          _aloadDom = new ALOAD(domIndex);
78      }
79  
80      public Instruction loadDOM() {
81          return _aloadDom;
82      }
83  
84      public Instruction loadCurrentNode() {
85          return _iloadCurrent;
86      }
87  
88      /** by default context node is the same as current node. MK437 */
89      public Instruction loadContextNode() {
90          return _iloadContext;
91      }
92  
93      public Instruction storeContextNode() {
94          return _istoreContext;
95      }
96  
97      public Instruction storeCurrentNode() {
98          return _istoreCurrent;
99      }
100 
101     public Instruction storeIterator() {
102         return _astoreIterator;
103     }
104 
105     public Instruction loadIterator() {
106         return _aloadIterator;
107     }
108 
109     public int getLocalIndex(String name) {
110         if (name.equals("current")) {
111             return CURRENT_NODE_INDEX;
112         }
113         else {
114             return super.getLocalIndex(name);
115         }
116     }
117 }