File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ exception ConstructorAlreadyExists of string
10
10
exception DuplicateLocalVariable of string
11
11
exception IncompatibleTypes of string
12
12
exception InvalidMethodDeclaration of string
13
+ exception InvalidTypeCondOperation of Type.t * Type.t
13
14
exception MethodAlreadyExists of string
14
15
exception UnknownAttribute of string * string
15
16
exception UnknownVariable of string
@@ -20,4 +21,5 @@ exception WrongTypePrefixOperation of string * string
20
21
exception WrongTypePostfixOperation of string
21
22
exception WrongInvokedArgumentsLength of string
22
23
exception WrongTypesAssignOperation of Type.t option * Type.t option
24
+ exception WrongTypeCondOperation of Type.t option
23
25
exception WrongTypesOperation of Type.t option * Type.t option
Original file line number Diff line number Diff line change @@ -237,7 +237,18 @@ let rec verify_expression env current_env e =
237
237
(match op with
238
238
| Op_cor | Op_cand | Op_eq | Op_ne | Op_gt | Op_lt | Op_ge | Op_le -> e.etype < - Some (Primitive (Boolean ))
239
239
| Op_or | Op_and | Op_xor | Op_shl | Op_shr | Op_shrr | Op_add | Op_sub | Op_mul | Op_div | Op_mod -> e.etype < - e1.etype)
240
- | CondOp (e1 ,e2 ,e3 ) -> () (* TODO*)
240
+ | CondOp (e1 ,e2 ,e3 ) ->
241
+ verify_expression env current_env e1;
242
+ verify_expression env current_env e2;
243
+ verify_expression env current_env e3;
244
+ (* check if e1.etype is boolean and e2.etype equals e3.etype *)
245
+ if e1.etype <> Some (Primitive (Boolean ))
246
+ then raise(WrongTypeCondOperation (e1.etype))
247
+ (match e2.etype, e3.etype with
248
+ | Some (_ ), None -> ()
249
+ | None , Some (_ ) -> ()
250
+ | Some (t1 ), Some (t2 ) -> if t1 <> t2 then raise(InvalidTypeCondOperation (t1, t2)));
251
+ if e2.etype <> None then e.etype < - e2.etype else e.etype < - e3.etype
241
252
| Cast (t ,e1 ) ->
242
253
verify_expression env current_env e1;
243
254
e.etype < - Some (t)
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ public I(int e) {
19
19
int sr = 5 ;
20
20
long l = (long ) sr ;
21
21
boolean test = my instanceof I ;
22
+ int condop = (1 == 2 ) ? 1 : 5 ;
22
23
private String func1 (int a ) {
23
24
int b = 1 ;
24
25
b += (5 +4 );
You can’t perform that action at this time.
0 commit comments