Skip to content

Commit 47a120b

Browse files
committed
[Src] refactoring
2 parents 642930a + 932900f commit 47a120b

17 files changed

+286
-258
lines changed

src/ast.ml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ module AST = struct
183183

184184
let is_file f =
185185
let fname = (get_func f).method_name in
186-
if Str.string_match (Str.regexp "java\\.io\\.File\\.<init>") fname 0 then
187-
true
188-
else false
186+
if Str.string_match Regexp.java_file fname 0 then true else false
189187

190188
(* ************************************** *
191189
Checking for Synthesis Rules
@@ -532,12 +530,11 @@ module AST = struct
532530
* ************************************** *)
533531

534532
let get_method_name m =
535-
Regexp.first_rm (Str.regexp "(.*)") m
533+
Regexp.first_rm Regexp.method_params m
536534
|> Str.split Regexp.dot |> List.rev |> List.hd
537535

538536
let get_short_class_name c =
539-
Regexp.first_rm (Str.regexp "\\.<init>(.*)") c
540-
|> Str.split Regexp.dot |> List.rev |> List.hd
537+
Regexp.first_rm Regexp.init c |> Str.split Regexp.dot |> List.rev |> List.hd
541538

542539
let array_code dim content =
543540
let rec code d = if d = 0 then "" else "[" ^ content ^ "]" ^ code (d - 1) in
@@ -578,7 +575,7 @@ module AST = struct
578575
if is_array_init func then
579576
Utils.rm_object_array_import f.typ
580577
|> Str.split Regexp.dot |> List.rev |> List.hd
581-
|> Regexp.first_rm (Str.regexp "Array[0-9]*")
578+
|> Regexp.first_rm Regexp.modeling_array
582579
|> Utils.get_array_class_name |> String.cat "new "
583580
else if is_array_set func then ""
584581
else if Utils.is_init_method f.method_name then
@@ -661,9 +658,9 @@ module AST = struct
661658
| C c -> "\'" ^ String.make 1 c ^ "\'"
662659
| S s ->
663660
let replace s =
664-
Str.global_replace (Str.regexp "\\") "\\\\\\\\" s
665-
|> Str.global_replace (Str.regexp "\"") "\\\""
666-
|> Str.global_replace (Str.regexp "\'") "\\\'"
661+
Str.global_replace Regexp.backslash "\\\\\\\\" s
662+
|> Str.global_replace Regexp.double_quote "\\\""
663+
|> Str.global_replace Regexp.single_quote "\\\'"
667664
in
668665
"\"" ^ replace s ^ "\""
669666

src/classInfo.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ let is_file f =
1010
with Unix.Unix_error (Unix.ENOENT, _, _) -> false
1111

1212
let is_test_class name =
13-
Str.string_match (Str.regexp "Test.*") name 0
14-
|| Str.string_match (Str.regexp ".*Test$") name 0
13+
Str.string_match Regexp.test_start_class name 0
14+
|| Str.string_match Regexp.test_end_class name 0
1515

1616
let is_lambda_class name =
17-
match Str.search_forward (Str.regexp "\\$Lambda\\$[_0-9]+") name 0 with
17+
match Str.search_forward Regexp.lambda_num name 0 with
1818
| exception Not_found -> false
1919
| _ -> true
2020

2121
let is_anonymous name =
2222
let check_int name =
23-
match Str.search_forward (Str.regexp "\\$[0-9]+") name 0 with
23+
match Str.search_forward Regexp.anony_num name 0 with
2424
| exception Not_found -> false
2525
| _ -> true
2626
in
@@ -140,7 +140,7 @@ let string_of_args args =
140140
let rec make_arg_code args =
141141
match args with hd :: tl -> "," ^ hd ^ make_arg_code tl | _ -> ""
142142
in
143-
"(" ^ Regexp.first_rm (Str.regexp "^,") (make_arg_code args) ^ ")"
143+
"(" ^ Regexp.first_rm Regexp.start_rest (make_arg_code args) ^ ")"
144144

145145
let string_of_jmethod_or_interface joi =
146146
match joi with

src/commandMaker.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ let make_jar_with_dependencies p =
6969
let execute_build_cmd p =
7070
let build_cmd_file = Filename.(Filename.(p / input_path) / "build-command") in
7171
let ic = open_in build_cmd_file in
72-
let cmds = read_all_string ic |> Str.split (Str.regexp "\n") in
72+
let cmds = read_all_string ic |> Str.split Regexp.new_line in
7373
close_in ic;
7474
let rec execute cmds =
7575
match cmds with

src/constant.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let default_primitive =
5353
PrimitiveInfo.TypeMap.empty typ_list
5454

5555
let expand_string_value m_name p_info =
56-
let method_name = Regexp.first_rm ("(.*)" |> Str.regexp) m_name in
56+
let method_name = Regexp.first_rm Regexp.method_params m_name in
5757
let default_map, default =
5858
match PrimitiveInfo.TypeMap.find_opt String p_info with
5959
| Some map -> (

src/constantInfo.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ let is_file f =
99
with Unix.Unix_error (Unix.ENOENT, _, _) -> false
1010

1111
let is_test_class name =
12-
Str.string_match (Str.regexp "Test.*") name 0
13-
|| Str.string_match (Str.regexp ".*Test$") name 0
12+
Str.string_match Regexp.test_start_class name 0
13+
|| Str.string_match Regexp.test_end_class name 0
1414

1515
let is_lambda_class name =
16-
match Str.search_forward (Str.regexp "\\$Lambda\\$[_0-9]+") name 0 with
16+
match Str.search_forward Regexp.lambda_num name 0 with
1717
| exception Not_found -> false
1818
| _ -> true
1919

2020
let is_anonymous name =
2121
let check_int name =
22-
match Str.search_forward (Str.regexp "\\$[0-9]+") name 0 with
22+
match Str.search_forward Regexp.anony_num name 0 with
2323
| exception Not_found -> false
2424
| _ -> true
2525
in

src/dug.ml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,7 @@ module DUG = struct
211211

212212
let is_file f =
213213
let fname = (get_func f).method_name in
214-
if Str.string_match (Str.regexp "java\\.io\\.File\\.<init>") fname 0 then
215-
true
216-
else false
214+
Str.string_match Regexp.java_file fname 0
217215

218216
(* ************************************** *
219217
Checking for Synthesis Rules
@@ -784,12 +782,11 @@ module DUG = struct
784782
* ************************************** *)
785783

786784
let get_method_name m =
787-
Regexp.first_rm (Str.regexp "(.*)") m
785+
Regexp.first_rm Regexp.method_params m
788786
|> Str.split Regexp.dot |> List.rev |> List.hd
789787

790788
let get_short_class_name c =
791-
Regexp.first_rm (Str.regexp "\\.<init>(.*)") c
792-
|> Str.split Regexp.dot |> List.rev |> List.hd
789+
Regexp.first_rm Regexp.init c |> Str.split Regexp.dot |> List.rev |> List.hd
793790

794791
let array_code dim content =
795792
let rec code d = if d = 0 then "" else "[" ^ content ^ "]" ^ code (d - 1) in
@@ -830,7 +827,7 @@ module DUG = struct
830827
if is_array_init func then
831828
Utils.rm_object_array_import f.typ
832829
|> Str.split Regexp.dot |> List.rev |> List.hd
833-
|> Regexp.first_rm (Str.regexp "Array[0-9]*")
830+
|> Regexp.first_rm Regexp.modeling_array
834831
|> Utils.get_array_class_name |> String.cat "new "
835832
else if is_array_set func then ""
836833
else if Utils.is_init_method f.method_name then
@@ -913,9 +910,9 @@ module DUG = struct
913910
| C c -> "\'" ^ String.make 1 c ^ "\'"
914911
| S s ->
915912
let replace s =
916-
Str.global_replace (Str.regexp "\\") "\\\\\\\\" s
917-
|> Str.global_replace (Str.regexp "\"") "\\\""
918-
|> Str.global_replace (Str.regexp "\'") "\\\'"
913+
Str.global_replace Regexp.backslash "\\\\\\\\" s
914+
|> Str.global_replace Regexp.double_quote "\\\""
915+
|> Str.global_replace Regexp.single_quote "\\\'"
919916
in
920917
"\"" ^ replace s ^ "\""
921918

src/generator.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ let get_predef_value_list typ p_info =
398398
let get_extra_value_list typ import p_info =
399399
match PrimitiveInfo.TypeMap.find_opt typ p_info with
400400
| Some map -> (
401-
let file = Regexp.first_rm (Str.regexp "\\$.*$") import in
401+
let file = Regexp.first_rm Regexp.dollar_to_all import in
402402
match
403403
( PrimitiveInfo.ClassMap.find_opt import map,
404404
PrimitiveInfo.ClassMap.find_opt file map )
@@ -1219,7 +1219,8 @@ let is_receiver id = if id = "con_recv" || id = "con_outer" then true else false
12191219

12201220
let is_nested_class name = String.contains name '$'
12211221

1222-
let is_test_file f_name = Str.string_match (Str.regexp ".*/test/.*") f_name 0
1222+
let is_test_file f_name =
1223+
Utils.exist_regexp (Regexp.test_dir Filename.dir_sep) f_name
12231224

12241225
let is_public_class class_name c_info =
12251226
let is_public_class_type typ =
@@ -1268,8 +1269,8 @@ let is_static_class name (c_info, _) =
12681269
| _ -> false
12691270
in
12701271
let name =
1271-
Regexp.global_rm (Str.regexp "\\.<.*>(.*)$") name
1272-
|> Regexp.global_rm (Str.regexp "(.*)$")
1272+
Regexp.global_rm Regexp.init_end name
1273+
|> Regexp.global_rm Regexp.method_params_end
12731274
in
12741275
match ClassInfo.M.find_opt name c_info with
12751276
| Some typ -> is_static_class_type typ
@@ -1706,7 +1707,7 @@ let append l1 l2 =
17061707

17071708
let add_import import set =
17081709
(if is_nested_class import then
1709-
ImportSet.add (Str.replace_first (Str.regexp "\\$.*$") "" import) set
1710+
ImportSet.add (Str.replace_first Regexp.dollar_to_all "" import) set
17101711
else set)
17111712
|> ImportSet.add import
17121713

0 commit comments

Comments
 (0)