@@ -22,6 +22,12 @@ type class_env = {
22
22
parent : Type .ref_type ;
23
23
}
24
24
25
+ (* print Type.t option *)
26
+ let stringOfOpt s =
27
+ match s with
28
+ | None -> " null"
29
+ | Some t -> stringOf t
30
+
25
31
(* auxiliary print functions *)
26
32
let print_arguments tab arguments =
27
33
List. iter (fun a -> print_string(tab ^ AST. stringOf_arg a)) arguments
@@ -92,10 +98,10 @@ let verify_name s env current_env =
92
98
else Some (Hashtbl. find current_env.variables s)
93
99
94
100
(* check the type of the assignment operation *)
95
- let verify_assignop_type t1 t2 =
101
+ let verify_assignop_type t1 t2 op =
96
102
if t1 <> t2 then
97
103
begin
98
- raise(WrongTypesAssignOperation (t1, t2));
104
+ raise(WrongTypesAssignOperation (stringOfOpt t1, string_of_assign_op op ,stringOfOpt t2));
99
105
match t1 with
100
106
| Some t ->
101
107
print_string " \n ************************\n " ;
@@ -114,7 +120,7 @@ let verify_assignop_type t1 t2 =
114
120
let verify_operation_type t1 op t2 =
115
121
if t1 <> t2 then
116
122
begin
117
- raise(WrongTypesOperation (t1, t2));
123
+ raise(WrongTypesOperation (stringOfOpt t1, string_of_infix_op op, stringOfOpt t2));
118
124
end
119
125
120
126
(* check the type of call expression when it existe the method name, the arguments and global env *)
@@ -135,6 +141,8 @@ let verify_call_expr meth_name args env class_name =
135
141
| WrongInvokedArgumentsLength s -> raise(WrongInvokedArgumentsLength (s))
136
142
end
137
143
144
+
145
+
138
146
(* check the type of the expressions *)
139
147
let rec verify_expression env current_env e =
140
148
(* print_string(string_of_expression_desc(e.edesc)); *)
@@ -166,7 +174,7 @@ let rec verify_expression env current_env e =
166
174
| WrongInvokedArgumentsLength s -> raise(WrongInvokedArgumentsLength (s))
167
175
end
168
176
end
169
- (* | NewArray (Some n1,n2,al ) -> () (* TODO *) * )
177
+ | NewArray (t , args , target ) -> e.etype < - Some ( Array (t, List. length args) )
170
178
| Call (r ,m ,al ) ->
171
179
(match r with
172
180
| None -> (* when method is called without declaring class name*)
@@ -203,7 +211,7 @@ let rec verify_expression env current_env e =
203
211
| AssignExp (e1 ,op ,e2 ) ->
204
212
verify_expression env current_env e1;
205
213
verify_expression env current_env e2;
206
- verify_assignop_type e1.etype e2.etype;
214
+ verify_assignop_type e1.etype e2.etype op ;
207
215
e.etype < - e1.etype
208
216
| Post (e1 ,op ) ->
209
217
verify_expression env current_env e1;
@@ -243,11 +251,11 @@ let rec verify_expression env current_env e =
243
251
verify_expression env current_env e3;
244
252
(* check if e1.etype is boolean and e2.etype equals e3.etype *)
245
253
if e1.etype <> Some (Primitive (Boolean ))
246
- then raise(WrongTypeCondOperation (e1.etype))
254
+ then raise(WrongTypeCondOperation (stringOfOpt e1.etype))
247
255
(match e2.etype, e3.etype with
248
256
| Some (_ ), None -> ()
249
257
| None , Some (_ ) -> ()
250
- | Some (t1 ), Some (t2 ) -> if t1 <> t2 then raise(InvalidTypeCondOperation (t1, t2)));
258
+ | Some (t1 ), Some (t2 ) -> if t1 <> t2 then raise(InvalidTypeCondOperation (stringOf t1, stringOf t2)));
251
259
if e2.etype <> None then e.etype < - e2.etype else e.etype < - e3.etype
252
260
| Cast (t ,e1 ) ->
253
261
verify_expression env current_env e1;
@@ -409,7 +417,7 @@ let verify_attributes envs current_class attrs =
409
417
verify_expression envs current_env e;
410
418
(* Verify the assignment operation's type is coherent *)
411
419
let mytype = Some (attrs.atype) in
412
- verify_assignop_type mytype e.etype
420
+ verify_assignop_type mytype e.etype AST. Assign
413
421
| None -> ()
414
422
415
423
(* check the type of the class *)
0 commit comments