1/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements.  See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
23
24import com.sun.org.apache.bcel.internal.generic.ACONST_NULL;
25import com.sun.org.apache.bcel.internal.generic.ALOAD;
26import com.sun.org.apache.bcel.internal.generic.ASTORE;
27import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
28import com.sun.org.apache.bcel.internal.generic.ILOAD;
29import com.sun.org.apache.bcel.internal.generic.ISTORE;
30import com.sun.org.apache.bcel.internal.generic.Instruction;
31import com.sun.org.apache.bcel.internal.generic.InstructionList;
32import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
33import com.sun.org.apache.bcel.internal.generic.Type;
34import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
35
36/**
37 * @author Jacek Ambroziak
38 * @author Santiago Pericas-Geertsen
39 */
40public final class CompareGenerator extends MethodGenerator {
41
42    private static int DOM_INDEX      = 1;
43    private static int CURRENT_INDEX  = 2;
44    private static int LEVEL_INDEX    = 3;
45    private static int TRANSLET_INDEX = 4;
46    private static int LAST_INDEX     = 5;
47    private int ITERATOR_INDEX = 6;
48
49    private final Instruction _iloadCurrent;
50    private final Instruction _istoreCurrent;
51    private final Instruction _aloadDom;
52    private final Instruction _iloadLast;
53    private final Instruction _aloadIterator;
54    private final Instruction _astoreIterator;
55
56    public CompareGenerator(int access_flags, Type return_type,
57                            Type[] arg_types, String[] arg_names,
58                            String method_name, String class_name,
59                            InstructionList il, ConstantPoolGen cp) {
60        super(access_flags, return_type, arg_types, arg_names, method_name,
61              class_name, il, cp);
62
63        _iloadCurrent = new ILOAD(CURRENT_INDEX);
64        _istoreCurrent = new ISTORE(CURRENT_INDEX);
65        _aloadDom = new ALOAD(DOM_INDEX);
66        _iloadLast = new ILOAD(LAST_INDEX);
67
68        LocalVariableGen iterator =
69            addLocalVariable("iterator",
70                             Util.getJCRefType(Constants.NODE_ITERATOR_SIG),
71                             null, null);
72        ITERATOR_INDEX = iterator.getIndex();
73        _aloadIterator = new ALOAD(ITERATOR_INDEX);
74        _astoreIterator = new ASTORE(ITERATOR_INDEX);
75        il.append(new ACONST_NULL());
76        il.append(storeIterator());
77    }
78
79    public Instruction loadLastNode() {
80        return _iloadLast;
81    }
82
83    public Instruction loadCurrentNode() {
84        return _iloadCurrent;
85    }
86
87    public Instruction storeCurrentNode() {
88        return _istoreCurrent;
89    }
90
91    public Instruction loadDOM() {
92        return _aloadDom;
93    }
94
95    public int getHandlerIndex() {
96        return INVALID_INDEX;           // not available
97    }
98
99    public int getIteratorIndex() {
100        return INVALID_INDEX;
101    }
102
103    public Instruction storeIterator() {
104        return _astoreIterator;
105    }
106
107    public Instruction loadIterator() {
108        return _aloadIterator;
109    }
110
111    //??? may not be used anymore
112    public int getLocalIndex(String name) {
113        if (name.equals("current")) {
114            return CURRENT_INDEX;
115        }
116        return super.getLocalIndex(name);
117    }
118}
119