diff options
author | Son Ho | 2023-11-24 17:38:44 +0100 |
---|---|---|
committer | Son Ho | 2023-11-24 17:38:44 +0100 |
commit | 1c8187d7f4129e09f23d3b5caf33938a0c91ea77 (patch) | |
tree | f6346d2668df498cea49475819ae068cf85d3808 /compiler | |
parent | 3fb8105afe1d43beb326906f124d7e0e7cefe7bc (diff) |
Add the alloc::string::String type in the builtins
Diffstat (limited to '')
-rw-r--r-- | compiler/ExtractBase.ml | 5 | ||||
-rw-r--r-- | compiler/ExtractBuiltin.ml | 15 | ||||
-rw-r--r-- | compiler/ExtractName.ml | 1 |
3 files changed, 16 insertions, 5 deletions
diff --git a/compiler/ExtractBase.ml b/compiler/ExtractBase.ml index 43e7f158..1ca68120 100644 --- a/compiler/ExtractBase.ml +++ b/compiler/ExtractBase.ml @@ -1109,8 +1109,9 @@ let initialize_names_maps () : names_maps = let init = names_map_init () in let int_names = List.map int_name T.all_int_types in let keywords = - List.concat - [ [ bool_name (); char_name (); str_name () ]; int_names; init.keywords ] + (* Remark: we don't put "str_name()" below because it clashes with + "alloc::string::String", which we register elsewhere. *) + List.concat [ [ bool_name (); char_name () ]; int_names; init.keywords ] in let names_set = StringSet.empty in let name_to_id = StringMap.empty in diff --git a/compiler/ExtractBuiltin.ml b/compiler/ExtractBuiltin.ml index 30ec7c19..24d16dca 100644 --- a/compiler/ExtractBuiltin.ml +++ b/compiler/ExtractBuiltin.ml @@ -127,9 +127,15 @@ let mk_struct_constructor (type_name : string) : string = a type parameter for the allocator to use, which we want to filter. *) let builtin_types () : builtin_type_info list = - let mk_type (rust_name : string) ?(keep_params : bool list option = None) + let mk_type (rust_name : string) ?(custom_name : string option = None) + ?(keep_params : bool list option = None) ?(kind : type_variant_kind = KOpaque) () : builtin_type_info = - let extract_name = flatten_name (split_on_separator rust_name) in + let rust_name = parse_pattern rust_name in + let extract_name = + match custom_name with + | None -> flatten_name (pattern_to_type_extract_name rust_name) + | Some name -> flatten_name (split_on_separator name) + in let body_info : builtin_type_body_info option = match kind with | KOpaque -> None @@ -147,13 +153,16 @@ let builtin_types () : builtin_type_info list = Some (Struct (constructor, fields)) | KEnum -> raise (Failure "TODO") in - let rust_name = parse_pattern rust_name in { rust_name; extract_name; keep_params; body_info } in [ (* Alloc *) mk_type "alloc::alloc::Global" (); + (* String *) + mk_type "alloc::string::String" + ~custom_name:(Some (backend_choice "string" "String")) + (); (* Vec *) mk_type "alloc::vec::Vec" ~keep_params:(Some [ true; false ]) (); (* Range *) diff --git a/compiler/ExtractName.ml b/compiler/ExtractName.ml index c0a23080..a916bffb 100644 --- a/compiler/ExtractName.ml +++ b/compiler/ExtractName.ml @@ -76,6 +76,7 @@ let pattern_to_extract_name (is_trait_impl : bool) (name : pattern) : in pattern_to_string name +let pattern_to_type_extract_name = pattern_to_extract_name false let pattern_to_fun_extract_name = pattern_to_extract_name false let pattern_to_trait_impl_extract_name = pattern_to_extract_name true |