blob: 56abd145a0fe29577d4766257e748a1d173b2896 (
plain) (
blame)
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
|
package submit.ast;
import java.util.ArrayList;
import java.util.List;
public class FunctionDeclaration implements Declaration {
private VarType rType;
private Statement statement;
private ArrayList<Param> params;
private String id;
public FunctionDeclaration(VarType rType, String id, List<Param> params,
Statement statement) {
this.rType = rType;
this.id = id;
this.params = new ArrayList<>(params);
this.statement = statement;
}
@Override
public void toCminus(StringBuilder builder, String prefix) {
builder.append("\n").append(rType).append(" ").append(id).append("(");
int numParams = params.size();
if (numParams >= 1)
params.get(0).toCminus(builder, "");
if (numParams > 1)
for (Param param : params.subList(1, numParams))
param.toCminus(builder, ", ");
builder.append(")").append("\n");
statement.toCminus(builder, "");
}
}
|