8000 Typing: clean the code & remove debug print function & modify a test … · compiler-experts/miniJava@66211ce · GitHub
[go: up one dir, main page]

Skip to content

Commit 66211ce

Browse files
committed
Typing: clean the code & remove debug print function & modify a test file
1 parent a2f4209 commit 66211ce

File tree

2 files changed

+5
-31
lines changed

2 files changed

+5
-31
lines changed

phase2/Typing/Typing.ml

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ let verify_invoke_args args const_info func_name =
5858
if(List.length args <> List.length const_info) then
5959
raise(WrongInvokedArgumentsLength("actual and formal argument lists differ in length"))
6060
else
61-
begin
62-
(* Use List.iter2 to compare to list*)
61+
(* Use List.iter2 to compare to list*)
6362
List.iter2 compare_args args const_info
64-
end
6563

6664
(* verify declared types of variables in constructor arguments or methods arguments *)
6765
let verify_declared_args current_env arguments =
@@ -101,28 +99,12 @@ let verify_name s env current_env =
10199
(* check the type of the assignment operation *)
102100
let verify_assignop_type t1 t2 op =
103101
if t1 <> t2 then
104-
begin
105-
raise(WrongTypesAssignOperation(stringOfOpt t1, string_of_assign_op op ,stringOfOpt t2));
106-
match t1 with
107-
| Some t ->
108-
print_string "\n************************\n";
109-
print_string ((stringOf t));
110-
print_string "\n************************\n";
111-
match t2 with
112-
| Some t ->
113-
print_string "\n++++++++++++++++++++++\n";
114-
print_string ((stringOf t));
115-
print_string "\n++++++++++++++++++++++\n";
116-
| None -> ()
117-
| None -> ()
118-
end
102+
raise(WrongTypesAssignOperation(stringOfOpt t1, string_of_assign_op op ,stringOfOpt t2))
119103

120104
(* check the type of the operation eg: ==, + *)
121105
let verify_operation_type t1 op t2 =
122106
if t1 <> t2 then
123-
begin
124-
raise(WrongTypesOperation(stringOfOpt t1, string_of_infix_op op, stringOfOpt t2));
125-
end
107+
raise(WrongTypesOperation(stringOfOpt t1, string_of_infix_op op, stringOfOpt t2))
126108

127109
(* check the type of call expression when it existe the method name, the arguments and global env *)
128110
let verify_call_expr meth_name args env class_name =
@@ -153,7 +135,6 @@ let rec verify_array_init_list el =
153135
raise(WrongTypeArrayInitList(stringOfOpt h.etype, stringOfOpt h1.etype)));
154136
verify_array_init_list t
155137

156-
157138
(* check the type of the expressions *)
158139
let rec verify_expression env current_env e =
159140
(* print_string(string_of_expression_desc(e.edesc)); *)
@@ -416,10 +397,6 @@ let rec verify_statement current_env envs statement =
416397

417398
(* check type for constructors *)
418399
let verify_constructors envs current_class consts =
419-
(* consts is of astconst structure *)
420-
(* print_endline ("=====verify_constructors======");
421-
print_class_env(Hashtbl.find envs current_class);
422-
print_endline ("=====verify_constructors======"); *)
423400
let current_env = {
424401
returntype = Type.Ref({ tpath = []; tid = consts.cname });
425402
variables = Hashtbl.create 17;
@@ -471,7 +448,6 @@ let add_constructors env current_class consts =
471448
let consts_table = (Hashtbl.find env current_class).constructors in
472449
if (Hashtbl.mem consts_table consts.cname) <> true
473450
then (
474-
(* print_const " " consts; *)
475451
Hashtbl.add consts_table consts.cname
476452
{ftype = Type.Ref {tpath=[]; tid=current_class};
477453
fargs = consts.cargstype;
@@ -484,21 +460,19 @@ let add_methods env current_class meths =
484460
let meths_table = (Hashtbl.find env current_class).methods in
485461
if (Hashtbl.mem meths_table meths.mname) <> true
486462
then (
487-
(* print_method " " meths; *)
488463
Hashtbl.add meths_table meths.mname
489464
{ftype = meths.mreturntype;
490465
fargs = meths.margstype;
491466
fthrows = meths.mthrows }
492467
)
493-
(*TODO: check override and overload*)
468+
(* TODO: check override and overload *)
494469
else raise(MethodAlreadyExists(meths.mname))
495470

496471
(* check if attribute has already exist in hash table *)
497472
let add_attributes env current_class attrs =
498473
let attrs_table = (Hashtbl.find env current_class).attributes in
499474
if (Hashtbl.mem attrs_table attrs.aname) <> true
500475
then (
501-
(* print_attribute " " attrs; *)
502476
Hashtbl.add attrs_table attrs.aname attrs.atype
503477
)
504478
else raise(AttributeAlreadyExists(attrs.aname))

phase2/tests/test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public I(int e) {
2121
boolean test = my instanceof I;
2222
int condop = (1 == 2) ? 1 : 5;
2323
int[] arr = new int[5];
24-
int[] arr2 = {1,2,8};
24+
int[][] arr2 = new int[][] {{1,2,8}};
2525
private String func1 (int a) {
2626
int b = 1;
2727
b += (5+4);

0 commit comments

Comments
 (0)
0