-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisitor2.java
78 lines (59 loc) · 2.69 KB
/
Visitor2.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
import minipython.analysis.DepthFirstAdapter;
import minipython.node.*;
import java.util.Hashtable;
import java.util.LinkedList;
public class Visitor2 extends DepthFirstAdapter {
private Hashtable symtable;
public static int errors;
Visitor2(Hashtable symtable)
{
this.symtable = symtable;
errors = 0;
}
/** Check function call arguments */
@Override
public void inAFunctionCall(AFunctionCall node) {
String fName = node.getId().toString().trim();
int line = ((TId)node.getId()).getLine();
int position = ((TId)node.getId()).getPos();
if(Visitor.symtable.containsKey(fName)){
LinkedList node_arguments = node.getArglist();
AFunction function = (AFunction)symtable.get(fName);
LinkedList function_arguments = function.getArgument();
// check number of arguments for node
int node_max_args = 0;
if(node_arguments.size() == 1) {
node_max_args++;
AArglist argument = (AArglist) node_arguments.get(0);
LinkedList commaExpression = argument.getCommaExpression();
node_max_args+=commaExpression.size();
}
// check number of arguments for other function
int other_function_default_args = 0;
int other_function_max_args = 0;
if(function_arguments.size() == 1) {
AArgument argument = (AArgument)function_arguments.get(0);
LinkedList assigns_value = argument.getAssignValue();
if(assigns_value.size() == 1){
other_function_default_args++;
}
LinkedList comma_assigns = argument.getCommaAssign();
for(int j =0;j< comma_assigns.size();j++){
ACommaAssign comma_assign = (ACommaAssign) comma_assigns.get(j);
LinkedList default_values = comma_assign.getAssignValue();
if(default_values.size() == 1){
other_function_default_args++;
}
}
other_function_max_args = comma_assigns.size() + 1;
}
if(other_function_max_args - other_function_default_args != node_max_args || other_function_max_args != node_max_args ){
System.out.println("[line : " + line + ", position : " + position + "] :" + " Function " + fName + " is does not have proper number of arguments");
errors++;
}
} else {
System.out.println("[line : " + line + ", position : " + position + "] :" + " Function " + fName + " is not defined");
errors++;
}
}
}