001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: TestGenerator.java 468649 2006-10-28 07:00:55Z minchau $
020     */
021    
022    package org.apache.xalan.xsltc.compiler.util;
023    
024    import org.apache.bcel.generic.ALOAD;
025    import org.apache.bcel.generic.ASTORE;
026    import org.apache.bcel.generic.ConstantPoolGen;
027    import org.apache.bcel.generic.ILOAD;
028    import org.apache.bcel.generic.ISTORE;
029    import org.apache.bcel.generic.Instruction;
030    import org.apache.bcel.generic.InstructionList;
031    import org.apache.bcel.generic.Type;
032    
033    /**
034     * @author Jacek Ambroziak
035     * @author Santiago Pericas-Geertsen
036     * @author Morten Jorgensen
037     */
038    public final class TestGenerator extends MethodGenerator {
039        private static int CONTEXT_NODE_INDEX = 1;
040        private static int CURRENT_NODE_INDEX = 4;
041        private static int ITERATOR_INDEX = 6;
042    
043        private Instruction _aloadDom;
044        private final Instruction _iloadCurrent;
045        private final Instruction _iloadContext;
046        private final Instruction _istoreCurrent;
047        private final Instruction _istoreContext;
048        private final Instruction _astoreIterator;
049        private final Instruction _aloadIterator;
050    
051        public TestGenerator(int access_flags, Type return_type,
052                             Type[] arg_types, String[] arg_names,
053                             String method_name, String class_name,
054                             InstructionList il, ConstantPoolGen cp) {
055            super(access_flags, return_type, arg_types, arg_names, method_name, 
056                  class_name, il, cp);
057            
058            _iloadCurrent  = new ILOAD(CURRENT_NODE_INDEX);
059            _istoreCurrent = new ISTORE(CURRENT_NODE_INDEX);
060            _iloadContext  = new ILOAD(CONTEXT_NODE_INDEX);
061            _istoreContext  = new ILOAD(CONTEXT_NODE_INDEX);
062            _astoreIterator = new ASTORE(ITERATOR_INDEX);
063            _aloadIterator  = new ALOAD(ITERATOR_INDEX);
064        }
065    
066        public int getHandlerIndex() {
067            return INVALID_INDEX;           // not available
068        }
069    
070        public int getIteratorIndex() {
071            return ITERATOR_INDEX;          // not available
072        }
073    
074        public void setDomIndex(int domIndex) {
075            _aloadDom = new ALOAD(domIndex);
076        }
077    
078        public Instruction loadDOM() {
079            return _aloadDom;
080        }
081    
082        public Instruction loadCurrentNode() {
083            return _iloadCurrent;
084        }
085    
086        /** by default context node is the same as current node. MK437 */
087        public Instruction loadContextNode() {
088            return _iloadContext;
089        }
090    
091        public Instruction storeContextNode() {
092            return _istoreContext;
093        }
094    
095        public Instruction storeCurrentNode() {
096            return _istoreCurrent;
097        }
098    
099        public Instruction storeIterator() {
100            return _astoreIterator;
101        }
102        
103        public Instruction loadIterator() {
104            return _aloadIterator;
105        }
106    
107        public int getLocalIndex(String name) {
108            if (name.equals("current")) {
109                return CURRENT_NODE_INDEX;
110            }
111            else {
112                return super.getLocalIndex(name);
113            }
114        }
115    }