forked from csaroff/MiniJava-Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbol.java
More file actions
70 lines (70 loc) · 2.2 KB
/
Copy pathSymbol.java
File metadata and controls
70 lines (70 loc) · 2.2 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
58
59
60
61
62
63
64
65
66
67
68
69
70
public class Symbol { // A generic programming language symbol
String name; // All symbols at least have a name
Klass type;
private boolean isField;
private int localIdentifier = -1;
private int parameterListIdentifier = -1;
private boolean hasBeenInitialized = false;
//private boolean hasIfInitialization = false;
//private boolean hasElseInitialization = false;
public void initialize(){
hasBeenInitialized=true;
}
//public void uninitialize(){
// hasBeenInitialized=false;
//}
public boolean hasBeenInitialized(){
return hasBeenInitialized;
}
//public void initializeIf(){
// hasIfInitialization=true;
//}
//public boolean hasIfInitialization(){
// return hasBeenInitialized || hasIfInitialization;
//}
//public void initializeElse(){
// if(hasIfInitialization){ initialize(); }
// hasElseInitialization=true;
//}
//public boolean hasElseInitialization(){
// return hasBeenInitialized || hasElseInitialization;
//}
public boolean isParameter(){
return parameterListIdentifier!=-1;
}
public void setParameterIdentifier(int parameterListIdentifier){
this.parameterListIdentifier=parameterListIdentifier;
}
public int getParameterListIdentifier(){
return parameterListIdentifier;
}
public boolean isField(){
return isField;
}
public boolean hasLocalIdentifier(){
return localIdentifier!=-1;
}
public int getLocalIdentifier(){
assert localIdentifier >= 0;
assert !isField;
return localIdentifier;
}
public void setLocalIdentifier(int localIdentifier){
assert !isField;
this.localIdentifier = localIdentifier;
}
public Symbol(String name, boolean isField) {
this.name = name;
this.isField = isField;
}
public Symbol(String name, Klass type, boolean isField) {
this(name, isField);
this.type = type;
}
public Klass getType(){return type;}
public String getName() { return name; }
public String toString() {
if ( type!=null ) return '<'+getName()+":"+type+'>';
return getName();
}
}