jaroslav@378: /** jaroslav@378: * Back 2 Browser Bytecode Translator jaroslav@378: * Copyright (C) 2012 Jaroslav Tulach jaroslav@378: * jaroslav@378: * This program is free software: you can redistribute it and/or modify jaroslav@378: * it under the terms of the GNU General Public License as published by jaroslav@378: * the Free Software Foundation, version 2 of the License. jaroslav@378: * jaroslav@378: * This program is distributed in the hope that it will be useful, jaroslav@378: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@378: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@378: * GNU General Public License for more details. jaroslav@378: * jaroslav@378: * You should have received a copy of the GNU General Public License jaroslav@378: * along with this program. Look for COPYING file in the top folder. jaroslav@378: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@288: */ jaroslav@288: package org.apidesign.javap; jaroslav@288: jaroslav@288: /** jaroslav@288: * jaroslav@288: * @author Jaroslav Tulach jaroslav@288: */ jaroslav@288: public final class TrapDataIterator { jaroslav@290: private final Hashtable exStart = new Hashtable(); jaroslav@290: private final Hashtable exStop = new Hashtable(); jaroslav@289: private TrapData[] current = new TrapData[10]; jaroslav@289: private int currentCount; jaroslav@288: jaroslav@288: TrapDataIterator(Vector exceptionTable) { jaroslav@288: for (int i=0 ; i < exceptionTable.size(); i++) { jaroslav@288: final TrapData td = (TrapData)exceptionTable.elementAt(i); jaroslav@288: exStart.put(td.start_pc, td); jaroslav@288: exStop.put(td.end_pc, td); jaroslav@288: } jaroslav@288: } jaroslav@288: jaroslav@288: public void advanceTo(int i) { jaroslav@290: Short s = Short.valueOf((short)i); jaroslav@290: TrapData e = (TrapData) exStart.get(s); jaroslav@288: if (e != null) { jaroslav@289: add(e); jaroslav@288: } jaroslav@290: e = (TrapData) exStop.get(s); jaroslav@288: if (e != null) { jaroslav@289: remove(e); jaroslav@288: } jaroslav@288: } jaroslav@288: jaroslav@288: public boolean useTry() { jaroslav@289: return currentCount > 0; jaroslav@288: } jaroslav@288: jaroslav@288: public TrapData[] current() { jaroslav@289: return current; jaroslav@289: } jaroslav@289: jaroslav@289: private void add(TrapData e) { jaroslav@289: if (currentCount == current.length) { jaroslav@289: TrapData[] data = new TrapData[currentCount * 2]; jaroslav@289: for (int i = 0; i < currentCount; i++) { jaroslav@289: data[i] = current[i]; jaroslav@289: } jaroslav@289: current = data; jaroslav@289: } jaroslav@289: current[currentCount++] = e; jaroslav@289: } jaroslav@289: jaroslav@289: private void remove(TrapData e) { jaroslav@289: int from = 0; jaroslav@289: while (from < currentCount) { jaroslav@289: if (e == current[from++]) { jaroslav@289: break; jaroslav@289: } jaroslav@289: } jaroslav@289: while (from < currentCount) { jaroslav@289: current[from - 1] = current[from]; jaroslav@289: current[from] = null; jaroslav@289: from++; jaroslav@289: } jaroslav@289: currentCount--; jaroslav@288: } jaroslav@288: }