KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > decompiler > LocalVariableRangeList


1 /* LocalVariableRangeList Copyright (C) 1998-2002 Jochen Hoenicke.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; see the file COPYING.LESSER. If not, write to
15  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id: LocalVariableRangeList.java,v 4.10.4.1 2002/05/28 17:34:03 hoenicke Exp $
18  */

19
20 package jode.decompiler;
21 import jode.GlobalOptions;
22 import jode.type.Type;
23
24 public class LocalVariableRangeList {
25
26     LocalVarEntry list = null;
27
28     LocalVariableRangeList() {
29     }
30
31     private void add(LocalVarEntry li) {
32         LocalVarEntry prev = null;
33         LocalVarEntry next = list;
34         while (next != null && next.endAddr < li.startAddr) {
35             prev = next;
36             next = next.next;
37         }
38     /* prev.endAddr < li.startAddr <= next.endAddr
39      */

40         if (next != null && li.endAddr >= next.startAddr) {
41         if (next.type.equals(li.type)
42         && next.name.equals(li.name)) {
43         /* Same type, same name and overlapping range.
44          * This is the same local: extend next to the common
45          * range and don't add li.
46          */

47         next.startAddr = Math.min(next.startAddr, li.startAddr);
48         next.endAddr = Math.max(next.endAddr, li.endAddr);
49         return;
50         }
51             GlobalOptions.err.println("warning: non disjoint locals");
52     }
53         li.next = next;
54         if (prev == null)
55             list = li;
56         else
57             prev.next = li;
58     }
59
60     private LocalVarEntry find(int addr) {
61         LocalVarEntry li = list;
62         while (li != null && li.endAddr < addr)
63             li = li.next;
64         if (li == null || li.startAddr > addr) {
65             return null;
66         }
67         return li;
68     }
69
70     public void addLocal(int startAddr, int endAddr,
71                          String JavaDoc name, Type type) {
72         LocalVarEntry li = new LocalVarEntry(startAddr,endAddr,name,type);
73         add (li);
74     }
75
76     public LocalVarEntry getInfo(int addr) {
77         return find(addr);
78     }
79 }
80
Popular Tags