File tree 3 files changed +32
-2
lines changed 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -17,3 +17,5 @@ exception InvalidMethodDeclaration of string
17
17
exception ArgumentTypeNotMatch of string
18
18
exception UnknownMethod of string
19
19
exception UnknowActualType of string
20
+ exception WrongTypePrefixOperation of string * string
21
+ exception WrongTypePostfixOperation of string
Original file line number Diff line number Diff line change @@ -185,8 +185,31 @@ let rec verify_expression env current_env e =
185
185
verify_expression env current_env e2;
186
186
verify_assignop_type e1.etype e2.etype;
187
187
e.etype < - e1.etype
188
- | Post (e ,op ) -> () (* TODO*)
189
- | Pre (op ,e ) -> () (* TODO*)
188
+ | Post (e1 ,op ) ->
189
+ verify_expression env current_env e1;
190
+ (match op with
191
+ | Incr ->
192
+ if (e1.etype <> Some (Primitive (Int )) && e1.etype <> Some (Primitive (Float ))) then
193
+ raise(WrongTypePostfixOperation (string_of_expression(e1)^ " ++" ))
194
+ | Decr ->
195
+ if (e1.etype <> Some (Primitive (Int )) && e1.etype <> Some (Primitive (Float ))) then
196
+ raise(WrongTypePostfixOperation (string_of_expression(e1)^ " --" ))
197
+ );
198
+ e.etype < - e1.etype;
199
+ | Pre (op ,e1 ) ->
200
+ verify_expression env current_env e1;
201
+ (match op with
202
+ | Op_not ->
203
+ if e1.etype <> Some (Primitive (Boolean )) then
204
+ raise(WrongTypePrefixOperation (string_of_prefix_op(op), string_of_expression(e1)))
205
+ | Op_bnot ->
206
+ if e1.etype <> Some (Primitive (Int )) then
207
+ raise(WrongTypePrefixOperation (string_of_prefix_op(op), string_of_expression(e1)))
208
+ | Op_neg | Op_incr | Op_decr | Op_plus ->
209
+ if (e1.etype <> Some (Primitive (Int )) && e1.etype <> Some (Primitive (Float ))) then
210
+ raise(WrongTypePrefixOperation (string_of_prefix_op(op), string_of_expression(e1)))
211
+ );
212
+ e.etype < - e1.etype;
190
213
| Op (e1 ,op ,e2 ) ->
191
214
verify_expression env current_env e1;
192
215
verify_expression env current_env e2;
Original file line number Diff line number Diff line change @@ -12,9 +12,14 @@ public I(int e) {
12
12
I my = new I (i );
13
13
String mystring1 = I .func1 (j );
14
14
String mystring2 = func1 (i );
15
+ boolean f = !a ;
16
+ int g = ~5 ;
17
+ float h = (-8.5f );
15
18
private String func1 (int a ) {
16
19
int b = 1 ;
17
20
b += (5 +4 );
21
+ ++b ;
22
+ b --;
18
23
return "YES" ;
19
24
}
20
25
You can’t perform that action at this time.
0 commit comments