blob: 850b8e8159990714ea5f6eca40b5dc6b022c371d (
plain)
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
|
package ast.nodes;
import java.util.ArrayList;
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
import ast.types.*;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* Node for the `trailer` statement of the grammar.
*/
public class TrailerNode implements Node {
private Node arglist;
private ArrayList<Node> exprs;
private TerminalNode methodCall;
private boolean isEmpty;
public TrailerNode(Node arglist, ArrayList<Node> exprs, TerminalNode methodCall) {
this.arglist = arglist;
this.exprs = exprs;
this.methodCall = methodCall;
this.isEmpty = (this.arglist == null && this.exprs.size() == 0 && this.methodCall == null);
}
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
if (arglist != null) {
errors.addAll(arglist.checkSemantics(ST, _nesting));
}
for (var expr : exprs) {
errors.addAll(expr.checkSemantics(ST, _nesting));
}
return errors;
}
public int getArgumentNumber() {
return ((ArglistNode) arglist).getArgumentNumber();
}
@Override
public Type typeCheck() {
return new VoidType();
}
// TODO: add code generation for trailer node
@Override
public String codeGeneration() {
return "";
}
@Override
public String toPrint(String prefix) {
String str = prefix + "TrailerNode\n";
prefix += " ";
if (arglist != null) {
str += arglist.toPrint(prefix);
}
for (var expr : exprs) {
str += expr.toPrint(prefix);
}
if (methodCall != null) {
str += prefix + "Method(" + methodCall + ")\n";
}
if (isEmpty) {
str += prefix + "()\n";
}
return str;
}
}
|