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: CompareGenerator.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.ACONST_NULL; 025 import org.apache.bcel.generic.ALOAD; 026 import org.apache.bcel.generic.ASTORE; 027 import org.apache.bcel.generic.ConstantPoolGen; 028 import org.apache.bcel.generic.ILOAD; 029 import org.apache.bcel.generic.ISTORE; 030 import org.apache.bcel.generic.Instruction; 031 import org.apache.bcel.generic.InstructionList; 032 import org.apache.bcel.generic.LocalVariableGen; 033 import org.apache.bcel.generic.Type; 034 import org.apache.xalan.xsltc.compiler.Constants; 035 036 /** 037 * @author Jacek Ambroziak 038 * @author Santiago Pericas-Geertsen 039 */ 040 public final class CompareGenerator extends MethodGenerator { 041 042 private static int DOM_INDEX = 1; 043 private static int CURRENT_INDEX = 2; 044 private static int LEVEL_INDEX = 3; 045 private static int TRANSLET_INDEX = 4; 046 private static int LAST_INDEX = 5; 047 private int ITERATOR_INDEX = 6; 048 049 private final Instruction _iloadCurrent; 050 private final Instruction _istoreCurrent; 051 private final Instruction _aloadDom; 052 private final Instruction _iloadLast; 053 private final Instruction _aloadIterator; 054 private final Instruction _astoreIterator; 055 056 public CompareGenerator(int access_flags, Type return_type, 057 Type[] arg_types, String[] arg_names, 058 String method_name, String class_name, 059 InstructionList il, ConstantPoolGen cp) { 060 super(access_flags, return_type, arg_types, arg_names, method_name, 061 class_name, il, cp); 062 063 _iloadCurrent = new ILOAD(CURRENT_INDEX); 064 _istoreCurrent = new ISTORE(CURRENT_INDEX); 065 _aloadDom = new ALOAD(DOM_INDEX); 066 _iloadLast = new ILOAD(LAST_INDEX); 067 068 LocalVariableGen iterator = 069 addLocalVariable("iterator", 070 Util.getJCRefType(Constants.NODE_ITERATOR_SIG), 071 null, null); 072 ITERATOR_INDEX = iterator.getIndex(); 073 _aloadIterator = new ALOAD(ITERATOR_INDEX); 074 _astoreIterator = new ASTORE(ITERATOR_INDEX); 075 il.append(new ACONST_NULL()); 076 il.append(storeIterator()); 077 } 078 079 public Instruction loadLastNode() { 080 return _iloadLast; 081 } 082 083 public Instruction loadCurrentNode() { 084 return _iloadCurrent; 085 } 086 087 public Instruction storeCurrentNode() { 088 return _istoreCurrent; 089 } 090 091 public Instruction loadDOM() { 092 return _aloadDom; 093 } 094 095 public int getHandlerIndex() { 096 return INVALID_INDEX; // not available 097 } 098 099 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 }