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