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: MatchGenerator.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.ConstantPoolGen;
026 import org.apache.bcel.generic.ILOAD;
027 import org.apache.bcel.generic.ISTORE;
028 import org.apache.bcel.generic.Instruction;
029 import org.apache.bcel.generic.InstructionList;
030 import org.apache.bcel.generic.Type;
031
032 /**
033 * @author Jacek Ambroziak
034 * @author Santiago Pericas-Geertsen
035 */
036 public final class MatchGenerator extends MethodGenerator {
037 private static int CURRENT_INDEX = 1;
038
039 private int _iteratorIndex = INVALID_INDEX;
040
041 private final Instruction _iloadCurrent;
042 private final Instruction _istoreCurrent;
043 private Instruction _aloadDom;
044
045 public MatchGenerator(int access_flags, Type return_type,
046 Type[] arg_types, String[] arg_names,
047 String method_name, String class_name,
048 InstructionList il, ConstantPoolGen cp) {
049 super(access_flags, return_type, arg_types, arg_names, method_name,
050 class_name, il, cp);
051
052 _iloadCurrent = new ILOAD(CURRENT_INDEX);
053 _istoreCurrent = new ISTORE(CURRENT_INDEX);
054 }
055
056 public Instruction loadCurrentNode() {
057 return _iloadCurrent;
058 }
059
060 public Instruction storeCurrentNode() {
061 return _istoreCurrent;
062 }
063
064 public int getHandlerIndex() {
065 return INVALID_INDEX; // not available
066 }
067
068 /**
069 * Get index of the register where the DOM is stored.
070 */
071 public Instruction loadDOM() {
072 return _aloadDom;
073 }
074
075 /**
076 * Set index where the reference to the DOM is stored.
077 */
078 public void setDomIndex(int domIndex) {
079 _aloadDom = new ALOAD(domIndex);
080 }
081
082 /**
083 * Get index of the register where the current iterator is stored.
084 */
085 public int getIteratorIndex() {
086 return _iteratorIndex;
087 }
088
089 /**
090 * Set index of the register where the current iterator is stored.
091 */
092 public void setIteratorIndex(int iteratorIndex) {
093 _iteratorIndex = iteratorIndex;
094 }
095
096 public int getLocalIndex(String name) {
097 if (name.equals("current")) {
098 return CURRENT_INDEX;
099 }
100 return super.getLocalIndex(name);
101 }
102 }