Skip to content

Commit

Permalink
Merge pull request #16 from codinuum/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
codinuum authored Feb 21, 2022
2 parents 85fd442 + bbc1be6 commit e35a575
Show file tree
Hide file tree
Showing 15 changed files with 442 additions and 138 deletions.
27 changes: 25 additions & 2 deletions src/ast/analyzing/common/comparison.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1460,12 +1460,33 @@ class ['node_t, 'tree_t] c
let ancsim_old = self#get_ancestors_similarity nd1old nd2old in
let ancsim_new = self#get_ancestors_similarity nd1new nd2new in

let ancsim_old, ancsim_new, prefer_sim =
if nd1old == nd1new then
if nd2old#initial_parent == nd2new && nd2new#initial_nchildren = 1 then
ancsim_new, ancsim_new, true
else if nd2old == nd2new#initial_parent && nd2old#initial_nchildren = 1 then
ancsim_old, ancsim_old, true
else
ancsim_old, ancsim_new, false
else if nd2old == nd2new then
if nd1old#initial_parent == nd1new && nd1new#initial_nchildren = 1 then
ancsim_new, ancsim_new, true
else if nd1old == nd1new#initial_parent && nd1old#initial_nchildren = 1 then
ancsim_old, ancsim_old, true
else
ancsim_old, ancsim_new, false
else
ancsim_old, ancsim_new, false
in

DEBUG_MSG "ancestors similarity: %f --> %f" ancsim_old ancsim_new;

let anc_sim_ratio = (Xlist.min [ancsim_old; ancsim_new]) /. (Xlist.max [ancsim_old; ancsim_new]) in

DEBUG_MSG "ancestors similarity ratio: %f" anc_sim_ratio;

DEBUG_MSG "prefer_sim: %B" prefer_sim;


let subtree_sim_old = self#get_similarity_score nd1old nd2old in
let subtree_sim_new = self#get_similarity_score nd1new nd2new in
Expand Down Expand Up @@ -1566,7 +1587,8 @@ class ['node_t, 'tree_t] c
if
(ancsim_old = 1.0 && subtree_sim_old = 1.0 && ancsim_new < 1.0 && subtree_sim_new < 1.0) ||
(anc_sim_almost_same && subtree_sim_old = 1.0 && subtree_sim_new < 1.0 && chk_for_old() ||
is_plausible nd1old nd2old && not (is_plausible nd1new nd2new))
is_plausible nd1old nd2old && not (is_plausible nd1new nd2new)) ||
prefer_sim && subtree_sim_old > subtree_sim_new
(* || (subtree_sim_old > subtree_sim_new && subtree_sim_ratio < subtree_similarity_ratio_lower_thresh) *)
then begin
let b, ncd, ncsim =
Expand All @@ -1578,7 +1600,8 @@ class ['node_t, 'tree_t] c
else if
(ancsim_new = 1.0 && subtree_sim_new = 1.0 && ancsim_old < 1.0 && subtree_sim_old < 1.0) ||
(anc_sim_almost_same && subtree_sim_new = 1.0 && subtree_sim_old < 1.0 && chk_for_new() ||
is_plausible nd1new nd2new && not (is_plausible nd1old nd2old))
is_plausible nd1new nd2new && not (is_plausible nd1old nd2old)) ||
prefer_sim && subtree_sim_new > subtree_sim_old
(* || (subtree_sim_new > subtree_sim_old && subtree_sim_ratio < subtree_similarity_ratio_lower_thresh) *)
then begin
let b, ncd, ncsim =
Expand Down
26 changes: 20 additions & 6 deletions src/ast/analyzing/common/delta.ml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ module Edit = struct
edit_seq
(*(edit_seq : ('data node_t, 'tree tree_t) Edit_base.seq_base)*)
=
let is_indivisible_move = edits_copy#is_indivisible_move in
let edit_list =
(*if options#minimize_delta_flag then
Xlist.filter_map (op_of_editop_filt ~more uidmapping edit_seq tree1) edit_seq#content
Expand Down Expand Up @@ -11090,8 +11091,14 @@ module Edit = struct
in

if irreversible_flag then begin
let mctl_opt =
if is_indivisible_move mid then
Some Mfull
else
None
in
let fmt =
irrf (Fmt.Irr.mkmov mid
irrf (Fmt.Irr.mkmov mid mctl_opt
path1from excepted_paths1from path1to excepted_paths1to
key_opt1 adj_opt1 depth_opt1 shift_opt1)
in
Expand Down Expand Up @@ -11328,8 +11335,15 @@ module Edit = struct

self#reg_parent_key2 excepted_paths2to mid_key;

let mctl_opt =
if is_indivisible_move mid then
Some Mfull
else
None
in

let fmt =
revf (Fmt.Rev.mkmov mid
revf (Fmt.Rev.mkmov mid mctl_opt
path1from excepted_paths1from path1to excepted_paths1to
key_opt1 adj_opt1 depth_opt1 shift_opt1
path2from excepted_paths2from path2to excepted_paths2to
Expand Down Expand Up @@ -11707,25 +11721,25 @@ module Edit = struct
with
Not_found -> fmt
end
| Irr (Irr.Mov(mid, path1, paths1, path2, paths2, x0, x1, x2, x3)) -> begin
| Irr (Irr.Mov(mid, mctl_opt, path1, paths1, path2, paths2, x0, x1, x2, x3)) -> begin
modify lift_tbl1 edit_parent_tbl1 path1 paths1;
try
let c = get_conv conv_tbl1 (K_mid mid) in
Irr (Irr.Mov(mid, path1, paths1,
Irr (Irr.Mov(mid, mctl_opt, path1, paths1,
conv_path path2 c, conv_paths paths2 c,
x0, x1, x2, x3))
with
Not_found -> fmt
end
| Rev (Rev.Mov(mid, path1, paths1, path2, paths2, x0, x1, x2, x3,
| Rev (Rev.Mov(mid, mctl_opt, path1, paths1, path2, paths2, x0, x1, x2, x3,
path1', paths1', path2', paths2', x4, x5, x6, x7))
-> begin
modify lift_tbl1 edit_parent_tbl1 path1 paths1;
modify lift_tbl2 edit_parent_tbl2 path1' paths1';
try
let c = get_conv conv_tbl1 (K_mid mid) in
let c' = get_conv conv_tbl2 (K_mid mid) in
Rev (Rev.Mov(mid, path1, paths1,
Rev (Rev.Mov(mid, mctl_opt, path1, paths1,
conv_path path2 c, conv_paths paths2 c,
x0, x1, x2, x3, path1', paths1',
conv_path path2' c', conv_paths paths2' c',
Expand Down
82 changes: 61 additions & 21 deletions src/ast/analyzing/common/delta_base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ let shift1_attr = mktag "shift"
let shift2_attr = mktag "shift_"

(* for partial application of move *)
type move_control = Mfull | MdeleteOnly | MinsertOnly

let move_control_to_string = function
| Mfull -> "F"
| MdeleteOnly -> "D"
| MinsertOnly -> "I"

let move_control_of_string = function
| "F" -> Mfull
| "D" -> MdeleteOnly
| "I" -> MinsertOnly
| _ -> Mfull

let move_control_attr = mktag "mctl"

let is_file_edit_tag n =
Expand Down Expand Up @@ -711,14 +724,25 @@ let make_change_file_elem path ch =


(* for move *)
let output_elem_mov ch mid
let output_elem_mov ch mid mctl_opt
path_from paths_from path_to paths_to key_opt adj_opt depth_opt shift_opt
=
let _al =
match mctl_opt with
| Some mctl ->
[ mid_attr, MID.to_raw mid;
move_control_attr, move_control_to_string mctl;
path_from_attr,path_from#to_string;
path_to_attr, path_to#to_string;
]
| None ->
[ mid_attr, MID.to_raw mid;
path_from_attr,path_from#to_string;
path_to_attr, path_to#to_string;
]
in
let al =
[ mid_attr, MID.to_raw mid;
path_from_attr,path_from#to_string;
path_to_attr, path_to#to_string;
] @
_al @
(key_opt_to_attr parent_attr key_opt) @
(int_opt_to_attr adj_attr adj_opt) @
(int_opt_to_attr depth_attr depth_opt) @
Expand All @@ -727,17 +751,30 @@ let output_elem_mov ch mid
fprintf ch "<%s %s%s%s/>" mov_tag
(attrs_to_string al) (mkbdry_from paths_from) (mkbdry_to paths_to)

let output_elem_bi_mov ch mid
let output_elem_bi_mov ch mid mctl_opt
path1from paths1from path1to paths1to key_opt1 adj_opt1 depth_opt1 shift_opt1
path2from paths2from path2to paths2to key_opt2 adj_opt2 depth_opt2 shift_opt2
=
let _al =
match mctl_opt with
| Some mctl ->
[ mid_attr, MID.to_raw mid;
move_control_attr, move_control_to_string mctl;
path1from_attr,path1from#to_string;
path1to_attr, path1to#to_string;
path2from_attr,path2from#to_string;
path2to_attr, path2to#to_string;
]
| None ->
[ mid_attr, MID.to_raw mid;
path1from_attr,path1from#to_string;
path1to_attr, path1to#to_string;
path2from_attr,path2from#to_string;
path2to_attr, path2to#to_string;
]
in
let al =
[ mid_attr, MID.to_raw mid;
path1from_attr,path1from#to_string;
path1to_attr, path1to#to_string;
path2from_attr,path2from#to_string;
path2to_attr, path2to#to_string;
] @
_al @
(key_opt_to_attr parent1_attr key_opt1) @
(int_opt_to_attr adj1_attr adj_opt1) @
(int_opt_to_attr depth1_attr depth_opt1) @
Expand Down Expand Up @@ -1000,6 +1037,7 @@ module Fmt = struct
* content_dumper

| Mov of MID.t
* move_control option
* path_c * boundary * path_c * boundary
* subtree_key option * int option * int option * int option

Expand All @@ -1015,9 +1053,9 @@ module Fmt = struct
let mkins stid path paths key_opt adj_opt depth_opt shift_opt dumper =
Ins(stid, path, paths, key_opt, adj_opt, depth_opt, shift_opt, dumper)

let mkmov mid path_from paths_from path_to paths_to
let mkmov mid mctl_opt path_from paths_from path_to paths_to
key_opt adj_opt depth_opt shift_opt =
Mov(mid, path_from, paths_from, path_to, paths_to,
Mov(mid, mctl_opt, path_from, paths_from, path_to, paths_to,
key_opt, adj_opt, depth_opt, shift_opt)

let mkchg path paths dumper =
Expand All @@ -1043,9 +1081,9 @@ module Fmt = struct
dumper ch;
output_ed_elem_ins ch

| Mov(mid, path_from, paths_from, path_to, paths_to,
| Mov(mid, mctl_opt, path_from, paths_from, path_to, paths_to,
key_opt, adj_opt, depth_opt, shift_opt) ->
output_elem_mov ch mid
output_elem_mov ch mid mctl_opt
path_from paths_from path_to paths_to
key_opt adj_opt depth_opt shift_opt

Expand Down Expand Up @@ -1080,6 +1118,7 @@ module Fmt = struct
* path_c * boundary

| Mov of MID.t
* move_control option
* path_c * boundary * path_c * boundary
* subtree_key option * int option * int option * int option
* path_c * boundary * path_c * boundary
Expand All @@ -1104,11 +1143,12 @@ module Fmt = struct
path', paths')

let mkmov mid
mctl_opt
path_from paths_from path_to paths_to
key_opt adj_opt depth_opt shift_opt
path_from' paths_from' path_to' paths_to'
key_opt' adj_opt' depth_opt' shift_opt' =
Mov(mid, path_from, paths_from, path_to, paths_to,
Mov(mid, mctl_opt, path_from, paths_from, path_to, paths_to,
key_opt, adj_opt, depth_opt, shift_opt,
path_from', paths_from', path_to', paths_to',
key_opt', adj_opt', depth_opt', shift_opt')
Expand Down Expand Up @@ -1142,12 +1182,12 @@ module Fmt = struct
dumper ch;
output_ed_elem_ins ch

| Mov(mid, path_from, paths_from, path_to, paths_to,
| Mov(mid, mctl_opt, path_from, paths_from, path_to, paths_to,
key_opt, adj_opt, depth_opt, shift_opt,
path_from', paths_from', path_to', paths_to',
key_opt', adj_opt', depth_opt', shift_opt')
->
output_elem_bi_mov ch mid
output_elem_bi_mov ch mid mctl_opt
path_from paths_from path_to paths_to
key_opt adj_opt depth_opt shift_opt
path_from' paths_from' path_to' paths_to'
Expand Down Expand Up @@ -1180,12 +1220,12 @@ module Fmt = struct
Del(stid, path', paths',
path, paths, key_opt, adj_opt, depth_opt, shift_opt, dumper)

| Mov(mid, path_from, paths_from, path_to, paths_to,
| Mov(mid, mctl_opt, path_from, paths_from, path_to, paths_to,
key_opt, adj_opt, depth_opt, shift_opt,
path_from', paths_from', path_to', paths_to',
key_opt', adj_opt', depth_opt', shift_opt')
->
Mov(mid, path_from', paths_from', path_to', paths_to',
Mov(mid, mctl_opt, path_from', paths_from', path_to', paths_to',
key_opt', adj_opt', depth_opt', shift_opt',
path_from, paths_from, path_to, paths_to,
key_opt, adj_opt, depth_opt, shift_opt)
Expand Down
13 changes: 0 additions & 13 deletions src/ast/analyzing/common/delta_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -435,19 +435,6 @@ let postorder_node_sort rt nds = (* when gindexes not set *)
in
List.fast_sort cmp nds

type move_control = Mfull | MdeleteOnly | MinsertOnly

let move_control_to_string = function
| Mfull -> "F"
| MdeleteOnly -> "D"
| MinsertOnly -> "I"

let move_control_of_string = function
| "F" -> Mfull
| "D" -> MdeleteOnly
| "I" -> MinsertOnly
| _ -> Mfull

let get_adjusted_path
?(get_group=fun _ -> raise Not_found)
?(group_heads=[])
Expand Down
10 changes: 7 additions & 3 deletions src/ast/analyzing/common/delta_format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,17 @@ module IrreversibleFormat = struct
DEBUG_MSG "_ppath=%s elem=%s nd=%a %s %s" (Path.to_string _ppath) (Path.Elem.to_string elem)
nps nd nd#data#label (Loc.to_string nd#data#src_loc);
DEBUG_MSG "mid=%a" MID.ps mid;
let _rp' = ref Path.root in
match Hashtbl.find mov_tbl mid with
| Dmove(mctl, mid, path_from, paths_from, path_to, (*[]*)_, _, _, _, _) as mov when begin
DEBUG_MSG "checking %s" (edit_to_string mov);
path_to#parent_path <> path_from#path &&
List.for_all (fun p -> p#upstream = 0 && p#key_opt = None) paths_from
let _ = _rp' := Path.remove_head path_from#path _ppath in
List.for_all (fun p -> p#upstream = 0 && p#key_opt = None && !_rp' <> p#parent_path) paths_from
end -> begin
DEBUG_MSG "found: %s" (edit_to_string mov);
let _path', depth' =
let rp' = Path.append (Path.remove_head path_from#path _ppath) elem in
let rp' = Path.append !_rp' elem in
Path.concat path_to#path rp', Path.length rp'
in
let path' = new path_c _path' in
Expand Down Expand Up @@ -364,14 +366,16 @@ module IrreversibleFormat = struct
DEBUG_MSG "_ppath=%s elem=%s nd=%a %s %s" (Path.to_string _ppath) (Path.Elem.to_string elem)
nps nd nd#data#label (Loc.to_string nd#data#src_loc);
DEBUG_MSG "mid=%a" MID.ps mid;
let _rp' = ref Path.root in
match Hashtbl.find mov_tbl mid with
| Dmove(mctl, mid, path_from, paths_from, path_to, (*[]*)_, _, _, _, _) as mov when begin
path_to#parent_path <> path_from#path &&
let _ = _rp' := Path.remove_head path_from#path _ppath in
List.for_all (fun p -> p#upstream = 0 && p#key_opt = None) paths_from
end -> begin
DEBUG_MSG "found: %s" (edit_to_string mov);
let _path', depth' =
let rp' = Path.append (Path.remove_head path_from#path _ppath) elem in
let rp' = Path.append !_rp' elem in
Path.concat path_to#path rp', Path.length rp'
in
let path' = new path_c _path' in
Expand Down
Loading

0 comments on commit e35a575

Please sign in to comment.