-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVarList.java
More file actions
57 lines (48 loc) · 1.52 KB
/
VarList.java
File metadata and controls
57 lines (48 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.ArrayList;
import java.util.HashMap;
public class VarList {
HashMap<String,Variable> variableHashMap = new HashMap<>();
public int blockNum;
public int regNum;
public VarList prevVarList ;
public VarList(int blockNum,VarList prevVarList) {
this.blockNum = blockNum;
this.prevVarList = prevVarList;
this.regNum = 0;
}
/**
* 添加数组变量
* @param name 变量名
* @param BType 变量类型
* @param arrayDimensions 数组维数列表
*/
public void putVariable(String name,int BType,ArrayList<Integer> arrayDimensions,boolean isConst){
variableHashMap.put(name,new Variable(name,BType,this.blockNum,this.regNum++,arrayDimensions,isConst));
}
/**
* 添加普通变量
* @param name 变量名
* @param BType 变量类型
*/
public void putVariable(String name,int BType){
variableHashMap.put(name,new Variable(name,BType,this.blockNum,this.regNum++));
}
/**
* 添加常量
* @param name 变量名
* @param BType 变量类型
* @param value 常量值
*/
public void putVariable(String name,int BType,int value){
variableHashMap.put(name,new Variable(name,BType,value));
}
public void putVariable(String name,Variable variable){
variableHashMap.put(name,variable);
}
public Variable getVariable(String name){
return variableHashMap.get(name);
}
public void setRegNum(int regNum) {
this.regNum = regNum;
}
}