📄 copytable.java
字号:
package CatDecaf.Optimizer;
import CatDecaf.IR.*;
import CatDecaf.Utilities.*;
import java6035.tools.ASM.*;
import java.io.*;
import java.util.*;
import CatDecaf.SymTable.*;
import parser.*;
public class CopyTable{
public LinkedHashMap table;
public CopyTable parent;
public CopyTable child1;
public CopyTable child2;
public HashSet loopKillSet;
public boolean optFlag;
public HashSet killSet; //an IDDescriptor in this killSet means it cannot be looked up from the parent table
public CopyTable(){
table = new LinkedHashMap();
killSet = new HashSet();
//parent = p;
parent = null;
//optFlag = true;
}
public Object lookupValue(IDDescriptor idd){
if(table.containsKey(idd)) return table.get(idd);
if(parent != null && !killSet.contains(idd)) return parent.lookupValue(idd);;
return null;
}
public boolean checkIDDInParents(IDDescriptor idd){ //true if idd exists in ancestors
if(parent == null) return false;
if(parent.table.containsKey(idd)) return true;
else return parent.checkIDDInParents(idd);
}
public boolean checkIDDInParents(IDDescriptor idd, Object o){ //true if idd exists with same value in ancestors
if(parent == null) return false;
if(parent.table.containsKey(idd)){
Object o2 = parent.table.get(idd);
return o==o2;
}
else return parent.checkIDDInParents(idd, o);
}
public LinkedHashMap checkIDDInParentsAndGetTable(IDDescriptor idd, Object o){ //true if idd exists with same value in ancestors
if(parent == null) return null;
if(parent.table.containsKey(idd)){
Object o2 = parent.table.get(idd);
boolean equal = false;
equal = o== o2 ;
if(equal) return parent.table;
return null;
}
else return parent.checkIDDInParentsAndGetTable(idd, o);
}
private void kill(IDDescriptor idd){
if(table.containsKey(idd)) table.remove(idd);
if(parent != null) parent.kill(idd);
}
public void kill(HashSet ks){
for(Iterator i = ks.iterator(); i.hasNext(); )
kill((IDDescriptor)i.next());
}
public void removeAllKeysFromAllTablesContainingValue(Object oValue){
if(table.containsValue(oValue)){
//Iterate to remove all the related keys
//do it by create a new list that doesn't contain those keys
//to solve concurrent modification problem
LinkedHashMap tempTable = new LinkedHashMap();
for(Iterator i=table.keySet().iterator();i.hasNext();){
Object key = i.next();
if(table.get(key) != oValue) tempTable.put(key, table.get(key));
}
table = tempTable;
}
if(parent!=null) parent.removeAllKeysFromAllTablesContainingValue( oValue);
else return;
}
public void getAllKeysFromAllTablesContainingValue(Object oValue, Set keys){
if(table.containsValue(oValue)){
for(Iterator i=table.keySet().iterator();i.hasNext();){
Object key = i.next();
if(table.get(key) == oValue) keys.add(key);
}
}
if(parent!=null) parent.getAllKeysFromAllTablesContainingValue( oValue, keys);
else return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -