get_scope fixes:

- merge inner_def maps in the main fold
- make use of the expression variable locations
This commit is contained in:
Lesenechal Remi 2020-07-01 13:10:52 +02:00
parent f9b3887753
commit 728cf3f1ba
2 changed files with 63 additions and 60 deletions

View File

@ -13,13 +13,13 @@ let%expect_test _ =
[ ] in file "lambda_letin.mligo", line 1, characters 0-9
Variable definitions:
(k#4 -> k) in file "lambda_letin.mligo", line 6, characters 12-25
(j#2 -> j) in file "lambda_letin.mligo", line 5, character 4 to line 7, character 21
(i#1 -> i) in file "lambda_letin.mligo", line 4, character 32 to line 7, character 21
(g#3 -> g) in file "lambda_letin.mligo", line 5, characters 12-21
(f#5 -> f) in file "lambda_letin.mligo", line 4, characters 8-9
(b#6 -> b) in file "lambda_letin.mligo", line 3, character 0 to line 9, character 7
(a#0 -> a) in file "lambda_letin.mligo", line 1, characters 0-9
(k#4 -> k) in file "lambda_letin.mligo", line 6, characters 8-9
(j#2 -> j) in file "lambda_letin.mligo", line 4, characters 47-48
(i#1 -> i) in file "lambda_letin.mligo", line 4, characters 37-38
(g#3 -> g) in file "lambda_letin.mligo", line 5, characters 8-9
(f#5 -> f) in file "lambda_letin.mligo", line 4, characters 6-7
(b#6 -> b) in file "lambda_letin.mligo", line 3, characters 4-5
(a#0 -> a) in file "lambda_letin.mligo", line 1, characters 4-5
Type definitions: |} ];
run_ligo_good [ "get-scope" ; gs "letin.mligo" ; "--format=dev" ] ;
@ -33,12 +33,12 @@ let%expect_test _ =
[ ] in file "letin.mligo", line 1, characters 0-9
Variable definitions:
(f#3 -> f) in file "letin.mligo", line 7, characters 12-21
(e#2 -> e) in file "letin.mligo", line 6, characters 12-17
(d#4 -> d) in file "letin.mligo", line 6, character 4 to line 8, character 17
(c#1 -> c) in file "letin.mligo", line 4, characters 10-15
(b#5 -> b) in file "letin.mligo", line 3, character 0 to line 10, character 11
(a#0 -> a) in file "letin.mligo", line 1, characters 0-9
(f#3 -> f) in file "letin.mligo", line 7, characters 8-9
(e#2 -> e) in file "letin.mligo", line 6, characters 8-9
(d#4 -> d) in file "letin.mligo", line 5, characters 6-7
(c#1 -> c) in file "letin.mligo", line 4, characters 6-7
(b#5 -> b) in file "letin.mligo", line 3, characters 4-5
(a#0 -> a) in file "letin.mligo", line 1, characters 4-5
Type definitions: |} ] ;
run_ligo_good [ "get-scope" ; gs "lambda.mligo" ; "--format=dev" ] ;
@ -49,11 +49,11 @@ let%expect_test _ =
[ ] in file "lambda.mligo", line 1, characters 0-9
Variable definitions:
(j#2 -> j) in file "lambda.mligo", line 4, characters 58-63
(i#1 -> i) in file "lambda.mligo", line 4, characters 31-63
(f#3 -> f) in file "lambda.mligo", line 4, characters 8-9
(b#4 -> b) in file "lambda.mligo", line 3, character 0 to line 5, character 7
(a#0 -> a) in file "lambda.mligo", line 1, characters 0-9
(j#2 -> j) in file "lambda.mligo", line 4, characters 46-47
(i#1 -> i) in file "lambda.mligo", line 4, characters 36-37
(f#3 -> f) in file "lambda.mligo", line 4, characters 6-7
(b#4 -> b) in file "lambda.mligo", line 3, characters 4-5
(a#0 -> a) in file "lambda.mligo", line 1, characters 4-5
Type definitions: |} ] ;
run_ligo_good [ "get-scope" ; gs "match.mligo" ; "--format=dev" ] ;
@ -74,12 +74,18 @@ let%expect_test _ =
[ mytype#0 ] in file "match.mligo", line 3, characters 0-9
Variable definitions:
(s#11 -> s) in file "match.mligo", line 19, characters 16-21
(d#12 -> d) in file "match.mligo", line 17, character 0 to line 20, character 3
(d#10 -> d) in file "match.mligo", line 18, characters 17-18
(c#9 -> c) in file "match.mligo", line 10, character 0 to line 15, character 3
(b#5 -> b) in file "match.mligo", line 5, character 0 to line 8, character 3
(a#1 -> a) in file "match.mligo", line 3, characters 0-9
(y#4 -> y) in file "match.mligo", line 8, characters 8-9
(x#3 -> x) in file "match.mligo", line 7, characters 8-9
(tl#8 -> tl) in file "match.mligo", line 15, characters 8-10
(s#11 -> s) in file "match.mligo", line 19, characters 10-11
(hd#7 -> hd) in file "match.mligo", line 15, characters 4-6
(d#12 -> d) in file "match.mligo", line 17, characters 4-5
(d#10 -> d) in file "match.mligo", line 18, characters 13-14
(c#9 -> c) in file "match.mligo", line 10, characters 4-5
(c#6 -> c) in file "match.mligo", line 13, characters 8-9
(c#2 -> c) in file "match.mligo", line 6, characters 13-14
(b#5 -> b) in file "match.mligo", line 5, characters 4-5
(a#1 -> a) in file "match.mligo", line 3, characters 4-5
Type definitions:
(mytype#0 -> mytype) in file "match.mligo", line 1, characters 0-40 |} ] ;
@ -96,14 +102,14 @@ let%expect_test _ =
[ ] in file "rec.mligo", line 1, characters 0-9
Variable definitions:
(k#4 -> k) in file "rec.mligo", line 5, characters 12-21
(j#3 -> j)
(i#2 -> i)
(c#5 -> c) in file "rec.mligo", line 4, characters 12-13
(c#1 -> c) in file "rec.mligo", line 4, characters 12-13
(b#7 -> b) in file "rec.mligo", line 3, character 0 to line 9, character 10
(b#6 -> b) in file "rec.mligo", line 8, characters 10-11
(a#0 -> a) in file "rec.mligo", line 1, characters 0-9
(k#4 -> k) in file "rec.mligo", line 5, characters 8-9
(j#3 -> j) in file "rec.mligo", line 4, characters 39-40
(i#2 -> i) in file "rec.mligo", line 4, characters 37-38
(c#5 -> c) in file "rec.mligo", line 4, characters 10-11
(c#1 -> c) in file "rec.mligo", line 4, characters 10-11
(b#7 -> b) in file "rec.mligo", line 3, characters 4-5
(b#6 -> b) in file "rec.mligo", line 8, characters 6-7
(a#0 -> a) in file "rec.mligo", line 1, characters 4-5
Type definitions: |} ] ;
run_ligo_good [ "get-scope" ; gs "shadowing.mligo" ; "--format=dev" ] ;
@ -117,10 +123,10 @@ let%expect_test _ =
[ ] in file "shadowing.mligo", line 1, characters 0-9
Variable definitions:
(e#2 -> e) in file "shadowing.mligo", line 6, characters 12-17
(d#4 -> d) in file "shadowing.mligo", line 6, character 4 to line 8, character 13
(c#1 -> c) in file "shadowing.mligo", line 4, characters 10-15
(b#5 -> b) in file "shadowing.mligo", line 3, character 0 to line 10, character 11
(a#3 -> a) in file "shadowing.mligo", line 7, characters 12-21
(a#0 -> a) in file "shadowing.mligo", line 1, characters 0-9
(e#2 -> e) in file "shadowing.mligo", line 6, characters 8-9
(d#4 -> d) in file "shadowing.mligo", line 5, characters 6-7
(c#1 -> c) in file "shadowing.mligo", line 4, characters 6-7
(b#5 -> b) in file "shadowing.mligo", line 3, characters 4-5
(a#3 -> a) in file "shadowing.mligo", line 7, characters 8-9
(a#0 -> a) in file "shadowing.mligo", line 1, characters 4-5
Type definitions: |} ] ;

View File

@ -11,39 +11,37 @@ let scopes : with_types:bool -> string -> string -> ((def_map * scopes), Main_er
let rec find_scopes' = fun (i,all_defs,env,scopes,lastloc) (e : Ast_core.expression) ->
match e.content with
| E_let_in { let_binder = (fn,_) ; rhs ; let_result } -> (
(*TODO : n needs location and should be used bellow in union with rhs *)
| E_let_in { let_binder = ({wrap_content=fn;location=fn_loc},_) ; rhs ; let_result } -> (
let (i,all_defs,_, scopes) = find_scopes' (i,all_defs,env,scopes,e.location) rhs in
let (i,env) = add_shadowing_def (i,fn) (make_v_def_from_core fn rhs rhs.location rhs.location) env in
let (i,env) = add_shadowing_def (i,fn) (make_v_def_from_core fn rhs fn_loc rhs.location) env in
let all_defs = merge_defs env all_defs in
find_scopes' (i,all_defs,env,scopes,let_result.location) let_result
)
| E_recursive { fun_name ; fun_type ; lambda = { result;_ } } -> (
| E_recursive { fun_name={wrap_content=fn;location=fn_loc} ; fun_type ; lambda = { result;_ } } -> (
(* Note:
It is not entirely true that 'fun_name' is in 'result' scope; because only tail calls are allowed
*)
let def = make_v_def_option_type fun_name (Some fun_type) e.location e.location in
let (i,env) = add_shadowing_def (i,fun_name) def env in
let def = make_v_def_option_type fn (Some fun_type) fn_loc result.location in
let (i,env) = add_shadowing_def (i,fn) def env in
find_scopes' (i,all_defs,env,scopes,result.location) result
)
| E_lambda { binder ; input_type ; output_type = _ ; result } -> (
let (i,env) = add_shadowing_def (i,binder) (make_v_def_option_type binder input_type result.location result.location) env in
| E_lambda { binder={wrap_content=fun_name;location=fn_loc} ; input_type ; output_type = _ ; result } -> (
let (i,env) = add_shadowing_def (i,fun_name) (make_v_def_option_type fun_name input_type fn_loc result.location) env in
let all_defs = merge_defs env all_defs in
find_scopes' (i,all_defs,env,scopes,result.location) result
)
| E_matching {matchee; cases} -> (
let (i,all_defs,_,scopes) = find_scopes' (i,all_defs,env,scopes,matchee.location) matchee in
match cases with
| Match_list { match_nil ; match_cons = (hd , tl , match_cons) } -> (
| Match_list { match_nil ; match_cons = ({wrap_content=hd;location=hd_loc} , {wrap_content=tl;location=tl_loc} , match_cons) } -> (
let (i,all_defs,_,scopes) = find_scopes' (i,all_defs,env,scopes,match_nil.location) match_nil in
let all_defs = merge_defs env all_defs in
(* TODO hd and tl needs location and should be used bellow instead of match_cons .. *)
let list_f = fun (t:Ast_typed.type_expression) -> match Ast_typed.get_t_list t with
| None -> failwith "Could not get the type of a list"
| Some t -> t in
let hd_def = make_v_def_ppx_type hd list_f matchee match_cons.location match_cons.location in
let tl_def = make_v_def_from_core tl matchee match_cons.location match_cons.location in
let hd_def = make_v_def_ppx_type hd list_f matchee hd_loc hd_loc in
let tl_def = make_v_def_from_core tl matchee tl_loc tl_loc in
let (i,env) = add_shadowing_def (i,hd) hd_def env in
let (i,env) = add_shadowing_def (i,tl) tl_def env in
@ -52,12 +50,11 @@ let scopes : with_types:bool -> string -> string -> ((def_map * scopes), Main_er
let all_defs = merge_defs env all_defs in
(i,all_defs,env,scopes)
)
| Match_option { match_none ; match_some = (some , match_some) } -> (
| Match_option { match_none ; match_some = ({wrap_content=some;location=some_loc} , match_some) } -> (
let (i,all_defs,_,scopes) = find_scopes' (i,all_defs,env,scopes,match_none.location) match_none in
let all_defs = merge_defs env all_defs in
(* TODO some needs location and should be used bellow instead of match_some .. *)
let tl_def = make_v_def_from_core some matchee match_some.location match_some.location in
let tl_def = make_v_def_from_core some matchee some_loc some_loc in
let (i,env) = add_shadowing_def (i,some) tl_def env in
let (i,all_defs,_,scopes) = find_scopes' (i,all_defs,env,scopes,match_some.location) match_some in
@ -65,14 +62,13 @@ let scopes : with_types:bool -> string -> string -> ((def_map * scopes), Main_er
(i,all_defs,env,scopes)
)
| Match_variant lst -> (
let aux = fun (i,all_defs,scopes) ((c,proj),(match_variant:Ast_core.expression)) ->
let aux = fun (i,all_defs,scopes) ((c,(proj:Ast_core.expression_variable)),(match_variant:Ast_core.expression)) ->
let proj_f = fun (t:Ast_typed.type_expression) -> match Ast_typed.get_t_sum t with
| Some t -> (Ast_typed.CMap.find (Ast_typed.Environment.convert_constructor' c) t).ctor_type
| None -> failwith "Could not get the inner type of a constructor" in
(* TODO proj needs location and should be used bellow instead of match_variant .. *)
let proj_def = make_v_def_ppx_type proj proj_f matchee match_variant.location match_variant.location in
let (i,env) = add_shadowing_def (i,proj) proj_def env in
let proj_def = make_v_def_ppx_type proj.wrap_content proj_f matchee proj.location proj.location in
let (i,env) = add_shadowing_def (i,proj.wrap_content) proj_def env in
let (i,all_defs,_,scopes) = find_scopes' (i,all_defs,env,scopes,match_variant.location) match_variant in
let all_defs = merge_defs env all_defs in
(i,all_defs,scopes)
@ -92,9 +88,10 @@ let scopes : with_types:bool -> string -> string -> ((def_map * scopes), Main_er
let aux = fun (i,top_def_map,inner_def_map,scopes) (x : Ast_core.declaration Location.wrap) ->
match x.wrap_content with
| Declaration_constant (v , _o , _i, e) ->
let (i,inner_def_map,scopes) = find_scopes (i,top_def_map,scopes,x.location) e in
let def = make_v_def_from_core v e x.location e.location in
| Declaration_constant ({wrap_content=v;location=v_loc} , _o , _i, e) ->
let (i,new_inner_def_map,scopes) = find_scopes (i,top_def_map,scopes,x.location) e in
let inner_def_map = merge_defs new_inner_def_map inner_def_map in
let def = make_v_def_from_core v e v_loc e.location in
let (i,top_def_map) = add_shadowing_def (i,v) def top_def_map in
( i, top_def_map, inner_def_map, scopes )