-
Notifications
You must be signed in to change notification settings - Fork 0
/
Function.java
127 lines (107 loc) · 3.39 KB
/
Function.java
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.util.*;
public class Function {
int index;
int nameindex;
int return_slots = 0;
int param_slots = 0;
public int while_index = 0;
String name;
String type;
public ArrayList<Order> orders = new ArrayList<Order>();
public ArrayList<Variable> variables = new ArrayList<Variable>();
public ArrayList<Variable> parameters = new ArrayList<Variable>();
public Function(String name, String type) {
this.name = name;
this.type = type;
}
public void setindex(int index) {
this.index = index;
}
public void setnameindex(int nameindex) {
this.nameindex = nameindex;
}
public void set_return_slots(int return_slots){
this.return_slots = return_slots;
}
public void setparamslots(int paramssize) {
this.param_slots = paramssize;
}
public void setreturnslots(int return_slots) {
this.return_slots = return_slots;
}
public void addorders(Order order) {
this.orders.add(order);
}
public void add_variables(Variable variable) {
this.variables.add(variable);
}
public int get_return_slots() {
return this.return_slots;
}
public boolean is_variable(String name) {
for (int i = 0; i < variables.size(); i++)
if (variables.get(i).name.equals(name))
return true;
return false;
}
public boolean is_parameters(String name) {
for (int i = 0; i < parameters.size(); i++)
if (parameters.get(i).name.equals(name))
return true;
return false;
}
public String get_type() {
return this.type;
}
public Variable get_variable(String name, int level) {
int len = variables.size();
for (int i = len - 1; i >= 0; i--) {
if (variables.get(i).name.equals(name) && variables.get(i).level <= level)
return variables.get(i);
}
return null;
}
public Variable get_parameter(String name) {
int len = parameters.size();
for (int i = len - 1; i >= 0; i--) {
if (parameters.get(i).name.equals(name))
return parameters.get(i);
}
return null;
}
public boolean is_const(String name, int level) {
int len = variables.size();
for (int i = len - 1; i >= 0; i--) {
if (variables.get(i).name.equals(name) && variables.get(i).level <= level)
return variables.get(i).is_const;
}
return false;
}
public int get_index_variables(String name, int level) {
int len = variables.size();
for (int i = len - 1; i >= 0; i--) {
if (variables.get(i).name.equals(name) && variables.get(i).level <= level)
return i;
}
return -1;
}
public int get_index_parameter(String name) {
int len = parameters.size();
for (int i = len - 1; i >= 0; i--) {
if (parameters.get(i).name.equals(name))
return i;
}
return -1;
}
public boolean is_parameter_const(String name) {
int len = parameters.size();
for (int i = len - 1; i >= 0; i--) {
if (parameters.get(i).name.equals(name))
return parameters.get(i).is_const;
}
return false;
}
public int get_last_order_index() {
return orders.size();
}
}