1 17 package org.apache.bcel.verifier.statics; 18 19 20 import java.util.Hashtable ; 21 import org.apache.bcel.generic.Type; 22 import org.apache.bcel.verifier.exc.LocalVariableInfoInconsistentException; 23 24 33 public class LocalVariableInfo{ 34 35 36 private Hashtable types = new Hashtable (); 37 38 private Hashtable names = new Hashtable (); 39 40 44 private void setName(int offset, String name){ 45 names.put( ((Integer.toString(offset))), name); 46 } 47 51 private void setType(int offset, Type t){ 52 types.put( ((Integer.toString(offset))), t); 53 } 54 55 63 public Type getType(int offset){ 64 return (Type) types.get(Integer.toString(offset)); 65 } 66 74 public String getName(int offset){ 75 return (String ) (names.get(Integer.toString(offset))); 76 } 77 82 public void add(String name, int startpc, int length, Type t) throws LocalVariableInfoInconsistentException{ 83 for (int i=startpc; i<=startpc+length; i++){ add(i,name,t); 85 } 86 } 87 88 93 private void add(int offset, String name, Type t) throws LocalVariableInfoInconsistentException{ 94 if (getName(offset) != null){ 95 if (! getName(offset).equals(name)){ 96 throw new LocalVariableInfoInconsistentException("At bytecode offset '"+offset+"' a local variable has two different names: '"+getName(offset)+"' and '"+name+"'."); 97 } 98 } 99 if (getType(offset) != null){ 100 if (! getType(offset).equals(t)){ 101 throw new LocalVariableInfoInconsistentException("At bytecode offset '"+offset+"' a local variable has two different types: '"+getType(offset)+"' and '"+t+"'."); 102 } 103 } 104 setName(offset, name); 105 setType(offset, t); 106 } 107 } 108 | Popular Tags |