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
77 lines (60 loc) · 1.96 KB
/
Copy pathSymbol.java
File metadata and controls
77 lines (60 loc) · 1.96 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
71
72
73
74
75
76
77
/**
* A programming language symbol. This includes fields, locals,
* method parameters/arguments, and even methods themselves.
*/
public class Symbol {
//The name of this symbol.
protected String name;
//The type of this symbol.
private Klass type;
//A flag representing whether or not this Symbol is a field.
private boolean isField;
//The unique identifier of this Symbol if it is a local.
//Used exclusively in code generation.
private int localIdentifier = -1;
//The unique identifier of this symbol if it is a parameter.
//Used exclusively in code generation.
private int parameterListIdentifier = -1;
public boolean isParameter(){
return parameterListIdentifier!=-1;
}
public void setParameterIdentifier(int parameterListIdentifier){
this.parameterListIdentifier=parameterListIdentifier;
}
public int getParameterListIdentifier(){
return parameterListIdentifier;
}
public boolean isField(){
return isField;
}
/**
* @return true if this symbol is a local variable and
* it has been assigned a unique identifier.
*/
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();
}
}