Skip to content

Commit

Permalink
clean up and fix expected type printing
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Oct 25, 2024
1 parent 25d36a6 commit b4201f9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/context/display/displayException.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ let to_json ctx de =
let named_source_kind = function
| WithType.FunctionArgument name -> (0, name)
| WithType.StructureField name -> (1, name)
| _ -> die "" __LOC__
| LocalVariable name -> (2, name)
| ImplicitReturn -> die "" __LOC__
in
let ctx = Genjson.create_context GMFull in
let generate_name kind =
Expand Down
58 changes: 36 additions & 22 deletions src/core/withType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ type with_type_source_information = {
type with_type_source =
| FunctionArgument of with_type_source_information
| StructureField of with_type_source_information
| LocalVariable of with_type_source_information
| ImplicitReturn
| LocalVariable of string

type t =
| NoValue
Expand All @@ -26,32 +26,46 @@ let of_implicit_return t = WithType(t,Some ImplicitReturn)
let with_argument t name = WithType(t,Some(FunctionArgument (make_with_type_source_information name None)))
let with_argument_and_doc t name doc = WithType(t,Some(FunctionArgument (make_with_type_source_information name (Some doc))))
let with_structure_field t name = WithType(t,Some(StructureField (make_with_type_source_information name None)))
let with_local_variable t name = WithType(t,Some(LocalVariable name))
let with_local_variable t name = WithType(t,Some(LocalVariable (make_with_type_source_information name None)))
let value = Value None
let named_argument name = Value (Some(FunctionArgument (make_with_type_source_information name None)))
let named_structure_field name = Value (Some(StructureField (make_with_type_source_information name None)))
let no_value = NoValue

let to_string = function
| NoValue -> "NoValue"
| Value (None | Some ImplicitReturn) -> "Value"
| Value (Some(FunctionArgument si | StructureField si)) -> "Value " ^ si.si_name
| Value (Some(LocalVariable name)) -> "Value " ^ name
| WithType(t,s) ->
let name = match s with
| Some(FunctionArgument si | StructureField si) -> si.si_name
| Some(LocalVariable name) -> name
| _ -> "None"
in
Printf.sprintf "WithType(%s, %s)" (s_type (print_context()) t) name
let get_source_info_name = function
| FunctionArgument si -> Some si.si_name
| StructureField si -> Some si.si_name
| LocalVariable si -> Some si.si_name
| ImplicitReturn -> None

let string_of_with_type_source = function
| FunctionArgument si ->
Printf.sprintf "FunctionArgument(%s)" si.si_name
| StructureField si ->
Printf.sprintf "StructureField(%s)" si.si_name
| LocalVariable si ->
Printf.sprintf "LocalVariable(%s)" si.si_name
| ImplicitReturn ->
"ImplicitReturn"

let get_expected_name with_type = match with_type with
| Value (Some src) | WithType(_,Some src) ->
(match src with
| FunctionArgument si -> Some si.si_name
| StructureField si -> Some si.si_name
| LocalVariable name -> Some name
| ImplicitReturn -> None
)
| Value (Some si) | WithType(_,Some si) ->
get_source_info_name si
| _ ->
None
None

let to_string = function
| NoValue ->
"NoValue"
| Value None ->
"Value(None)"
| Value (Some wts) ->
Printf.sprintf "Value(Some(%s))" (string_of_with_type_source wts)
| WithType(t,wts) ->
let s = match wts with
| None ->
"None"
| Some wts ->
Printf.sprintf "Some(%s)" (string_of_with_type_source wts)
in
Printf.sprintf "WithType(%s, %s)" (s_type (print_context()) t) s

0 comments on commit b4201f9

Please sign in to comment.