KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > xsltc > compiler > util > CompareGenerator


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
20 package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
21
22 import com.sun.org.apache.bcel.internal.generic.ACONST_NULL;
23 import com.sun.org.apache.bcel.internal.generic.ALOAD;
24 import com.sun.org.apache.bcel.internal.generic.ASTORE;
25 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
26 import com.sun.org.apache.bcel.internal.generic.ILOAD;
27 import com.sun.org.apache.bcel.internal.generic.ISTORE;
28 import com.sun.org.apache.bcel.internal.generic.Instruction;
29 import com.sun.org.apache.bcel.internal.generic.InstructionList;
30 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
31 import com.sun.org.apache.bcel.internal.generic.Type;
32 import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
33
34 /**
35  * @author Jacek Ambroziak
36  * @author Santiago Pericas-Geertsen
37  */

38 public final class CompareGenerator extends MethodGenerator {
39
40     private static int DOM_INDEX = 1;
41     private static int CURRENT_INDEX = 2;
42     private static int LEVEL_INDEX = 3;
43     private static int TRANSLET_INDEX = 4;
44     private static int LAST_INDEX = 5;
45     private int ITERATOR_INDEX = 6;
46
47     private final Instruction _iloadCurrent;
48     private final Instruction _istoreCurrent;
49     private final Instruction _aloadDom;
50     private final Instruction _iloadLast;
51     private final Instruction _aloadIterator;
52     private final Instruction _astoreIterator;
53
54     public CompareGenerator(int access_flags, Type return_type,
55                 Type[] arg_types, String JavaDoc[] arg_names,
56                 String JavaDoc method_name, String JavaDoc class_name,
57                 InstructionList il, ConstantPoolGen cp) {
58     super(access_flags, return_type, arg_types, arg_names, method_name,
59           class_name, il, cp);
60     
61     _iloadCurrent = new ILOAD(CURRENT_INDEX);
62     _istoreCurrent = new ISTORE(CURRENT_INDEX);
63     _aloadDom = new ALOAD(DOM_INDEX);
64     _iloadLast = new ILOAD(LAST_INDEX);
65
66     LocalVariableGen iterator =
67         addLocalVariable("iterator",
68                  Util.getJCRefType(Constants.NODE_ITERATOR_SIG),
69                  null, null);
70     ITERATOR_INDEX = iterator.getIndex();
71     _aloadIterator = new ALOAD(ITERATOR_INDEX);
72     _astoreIterator = new ASTORE(ITERATOR_INDEX);
73     il.append(new ACONST_NULL());
74     il.append(storeIterator());
75     }
76
77     public Instruction loadLastNode() {
78     return _iloadLast;
79     }
80
81     public Instruction loadCurrentNode() {
82     return _iloadCurrent;
83     }
84
85     public Instruction storeCurrentNode() {
86     return _istoreCurrent;
87     }
88
89     public Instruction loadDOM() {
90     return _aloadDom;
91     }
92
93     public int getHandlerIndex() {
94     return INVALID_INDEX; // not available
95
}
96
97     public int getIteratorIndex() {
98     return INVALID_INDEX;
99     }
100
101     public Instruction storeIterator() {
102     return _astoreIterator;
103     }
104     
105     public Instruction loadIterator() {
106     return _aloadIterator;
107     }
108
109     //??? may not be used anymore
110
public int getLocalIndex(String JavaDoc name) {
111     if (name.equals("current")) {
112         return CURRENT_INDEX;
113     }
114     return super.getLocalIndex(name);
115     }
116 }
117
Popular Tags