get-scope --with-types flag
This commit is contained in:
parent
21904f7e53
commit
4026411e10
@ -96,6 +96,13 @@ let disable_michelson_typechecking =
|
||||
info ~doc ["disable-michelson-typechecking"] in
|
||||
value @@ flag info
|
||||
|
||||
let with_types =
|
||||
let open Arg in
|
||||
let info =
|
||||
let doc = "tries to infer types for all named expressions" in
|
||||
info ~doc ["with-types"] in
|
||||
value @@ flag info
|
||||
|
||||
let predecessor_timestamp =
|
||||
let open Arg in
|
||||
let info =
|
||||
@ -485,12 +492,12 @@ let transpile_expression =
|
||||
|
||||
|
||||
let get_scope =
|
||||
let f source_file syntax display_format =
|
||||
let f source_file syntax display_format with_types =
|
||||
return_result ~display_format Ligo.Scopes.Formatter.scope_format @@
|
||||
Ligo.Scopes.scopes source_file syntax
|
||||
Ligo.Scopes.scopes ~with_types source_file syntax
|
||||
in
|
||||
let term =
|
||||
Term.(const f $ source_file 0 $ syntax $ display_format) in
|
||||
Term.(const f $ source_file 0 $ syntax $ display_format $ with_types) in
|
||||
let cmdname = "get-scope" in
|
||||
let doc = "Subcommand: Return the JSON encoded environment for a given file." in
|
||||
(Term.ret term , Term.info ~doc cmdname)
|
||||
|
@ -19,8 +19,8 @@ let add_shadowing_def : (int * _ Var.t) -> def -> def_map -> (int * def_map) =
|
||||
let env = Def_map.add definition_id def shadow in
|
||||
(i,env)
|
||||
|
||||
let make_v_def_from_core : string -> string -> string -> Ast_core.expression -> Location.t -> Location.t -> def =
|
||||
fun source_file syntax name exp range body_range ->
|
||||
let make_v_def_from_core : with_types:bool -> string -> string -> string -> Ast_core.expression -> Location.t -> Location.t -> def =
|
||||
fun ~with_types source_file syntax name exp range body_range ->
|
||||
let t = to_option @@
|
||||
let%bind typed_prg,state = Compile.Utils.type_file source_file syntax Env in
|
||||
let env = Ast_typed.program_environment Environment.default typed_prg in
|
||||
@ -29,27 +29,27 @@ let make_v_def_from_core : string -> string -> string -> Ast_core.expression ->
|
||||
in
|
||||
(* TODO : the source_file is given here but it should only be the declarations seen so far,
|
||||
otherwise nothing will be typed if an error occurs later in the file *)
|
||||
make_v_def name t range body_range
|
||||
make_v_def ~with_types name t range body_range
|
||||
|
||||
let make_v_def_option_type : string -> string -> string -> Ast_core.type_expression option -> Location.t -> Location.t -> def =
|
||||
fun source_file syntax name maybe_typed range body_range ->
|
||||
let make_v_def_option_type : with_types:bool -> string -> string -> string -> Ast_core.type_expression option -> Location.t -> Location.t -> def =
|
||||
fun ~with_types source_file syntax name maybe_typed range body_range ->
|
||||
match maybe_typed with
|
||||
| Some t ->
|
||||
let t' = to_option @@
|
||||
let%bind typed_prg,_ = Compile.Utils.type_file source_file syntax Env in
|
||||
let env = Ast_typed.program_environment Environment.default typed_prg in
|
||||
Compile.Of_core.evaluate_type env t in
|
||||
make_v_def name t' range body_range
|
||||
| None -> make_v_def name None range body_range
|
||||
make_v_def ~with_types name t' range body_range
|
||||
| None -> make_v_def ~with_types name None range body_range
|
||||
|
||||
let make_v_def_ppx_type :
|
||||
string -> string -> string -> (Ast_typed.type_expression -> Ast_typed.type_expression) ->
|
||||
with_types:bool -> string -> string -> string -> (Ast_typed.type_expression -> Ast_typed.type_expression) ->
|
||||
Ast_core.expression -> Location.t -> Location.t -> def =
|
||||
fun source_file syntax name f exp range body_range ->
|
||||
fun ~with_types source_file syntax name f exp range body_range ->
|
||||
let t = to_option @@
|
||||
let%bind typed_prg,state = Compile.Utils.type_file source_file syntax Env in
|
||||
let env = Ast_typed.program_environment Environment.default typed_prg in
|
||||
let%bind (e,_) = Compile.Of_core.compile_expression ~env ~state exp in
|
||||
let v = f e.type_expression in ok v
|
||||
in
|
||||
make_v_def name t range body_range
|
||||
make_v_def ~with_types name t range body_range
|
@ -4,10 +4,10 @@ open Misc
|
||||
|
||||
module Formatter = Formatter
|
||||
|
||||
let scopes : string -> string -> ((def_map * scopes), Main_errors.all) result = fun source_file syntax ->
|
||||
let make_v_def_from_core = make_v_def_from_core source_file syntax in
|
||||
let make_v_def_option_type = make_v_def_option_type source_file syntax in
|
||||
let make_v_def_ppx_type = make_v_def_ppx_type source_file syntax in
|
||||
let scopes : with_types:bool -> string -> string -> ((def_map * scopes), Main_errors.all) result = fun ~with_types source_file syntax ->
|
||||
let make_v_def_from_core = make_v_def_from_core ~with_types source_file syntax in
|
||||
let make_v_def_option_type = make_v_def_option_type ~with_types source_file syntax in
|
||||
let make_v_def_ppx_type = make_v_def_ppx_type ~with_types source_file syntax in
|
||||
|
||||
let rec find_scopes' = fun (i,all_defs,env,scopes,lastloc) (e : Ast_core.expression) ->
|
||||
match e.content with
|
||||
|
@ -27,8 +27,9 @@ module Definitions = struct
|
||||
| Type t -> t.range
|
||||
| Variable v -> v.range
|
||||
|
||||
let make_v_def : string -> Ast_typed.type_expression option -> Location.t -> Location.t -> def =
|
||||
fun name t range body_range ->
|
||||
let make_v_def : with_types:bool -> string -> Ast_typed.type_expression option -> Location.t -> Location.t -> def =
|
||||
fun ~with_types name t range body_range ->
|
||||
let t = if with_types then t else None in
|
||||
Variable { name ; range ; body_range ; t ; references = None }
|
||||
|
||||
let make_t_def : string -> Ast_core.declaration Location.wrap -> Ast_core.type_expression -> def =
|
||||
|
Loading…
Reference in New Issue
Block a user