-
Notifications
You must be signed in to change notification settings - Fork 0
/
JavaDBTypeCheck.jrag
104 lines (86 loc) · 3.13 KB
/
JavaDBTypeCheck.jrag
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
aspect L1TypeCheck {
public void OwnerOfExpr.typeCheck() {
TypeDecl ty = getOperand().type();
if (!ty.isClassDecl()) {
error("Ownerof must have a class type as operand");
}
TypeDecl oty = ty.getOwnerType();
if (oty.isUnknown()) {
error("ownerof cannot perform on class not owned by others");
}
}
refine TypeCheck public void ClassInstanceExpr.typeCheck() {
TypeCheck.ClassInstanceExpr.typeCheck();
TypeDecl dty = type();
if (dty.hasOwnerType()) {
TypeDecl oty = dty.getOwnerType();
if (inStaticContext())
error(dty.typeName() + " cannot be instantial in static context");
if (oty != hostType() )
error(dty.typeName() + " is owned by another class " + oty.typeName());
}
}
public void ParMemberClassInstanceExpr.typeCheck() {
super.typeCheck();
//check the match of argument
List<MemberVariable> fieldPars = type().getMemberPars();
List<ParMemberAccess> fieldArgs = this.getMemberArguments();
for (int i = 0; i < fieldArgs.getNumChild(); i++) {
MemberVariable fv = fieldPars.getChild(i);
ParMemberAccess fa = fieldArgs.getChild(i);
TypeDecl ty1 = fv.getTypeAccess().type();
TypeDecl ty2 = null;
if (fv instanceof FieldVariable) {
// SimpleSet decls = fa.getReceiverTypeAccess().type().memberFields(fa.getMemberName());
// if (decls.size() != 1) {
// continue;
// }
// ty2 = ((FieldDeclaration) decls.iterator().next()).getTypeAccess().type();
ty2 = fa.getFieldType();
} else {
// MethodVariable methodVar = (MethodVariable) fv;
// Collection<MethodDecl> decls = fa.getReceiverTypeAccess().type().memberMethods(fa.getMemberName());
// for (MethodDecl method : decls) {
// boolean flag = true;
// if (methodVar.getNumArgumentTypes() != method.getNumParameter()) flag = false;
// else {
// for (int j = 0; j < methodVar.getNumArgumentTypes(); j++) {
// TypeDecl parType = methodVar.getArgumentTypes(j).type();
// TypeDecl argType = method.getParameter(j).getTypeAccess().type();
// if (!parType.equals(argType)) {
// flag = false;
// break;
// }
// }
// }
// if (flag) {
// ty2 = method.getTypeAccess().type();
// break;
// }
// }
ty2 = fa.getMethodType();
if (ty2 == null) {
error("The method type of " + i + " cannont match the declaration");
continue;
}
}
if (!ty1.original().equals(ty2.original())) { //TODO use cleaner API
error("The Type of field argument " + i + " cannot match to the declaration.");
}
TypeDecl rty1 = fv.getReceiverTypeAccess().type();
TypeDecl rty2 = fa.getReceiverTypeAccess().type();
if (rty1.isTypeVariable()) {
//do substitute for rt1
if (type() instanceof ParClassDecl) {
ParClassDecl parType = (ParClassDecl) type();
rty1 = parType.substitute((TypeVariable)rty1);
} else {
error("The class is instantiated without type argument to support the field parameters.");
}
}
if (rty1 != null && rty2 != null && !rty2.subtype(rty1)) {
error("The reciver type of field argument " + i + " cannot match to the declaration.");
}
}
}
}