diff options
author | Son Ho | 2022-03-04 13:15:16 +0100 |
---|---|---|
committer | Son Ho | 2022-03-04 13:15:16 +0100 |
commit | 3ecca99a25369fecf990d922e6ccbaa31f71190a (patch) | |
tree | 1c87f1c678a06456662e22a375e6144abfe6a99d /src | |
parent | 69042fd599c2a965b9bc9d3eadc0acff314367a6 (diff) |
Make minor modifications to the variable names generation
Diffstat (limited to 'src')
-rw-r--r-- | src/ExtractToFStar.ml | 10 | ||||
-rw-r--r-- | src/Names.ml | 5 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/ExtractToFStar.ml b/src/ExtractToFStar.ml index 9ec74ff0..1f59075a 100644 --- a/src/ExtractToFStar.ml +++ b/src/ExtractToFStar.ml @@ -321,11 +321,15 @@ let mk_formatter (ctx : trans_ctx) (crate_name : string) TypeDeclId.Map.find adt_id ctx.type_context.type_decls in (* We do the following: - * - compute the type name converted_to_snake_case + * - compute the type name, and retrieve the last ident + * - convert this to snake case * - take the first letter of every "letter group" - * Ex.: "TypeVar" -> "type_var" -> "tv" + * Ex.: ["hashmap"; "HashMap"] ~~> "HashMap" -> "hash_map" -> "hm" *) - let cl = type_name_to_snake_case def.name in + (* Thename shouldn't be empty, and its last element should + * be an ident *) + let cl = List.nth def.name (List.length def.name - 1) in + let cl = to_snake_case (Names.as_ident cl) in let cl = String.split_on_char '_' cl in let cl = List.filter (fun s -> String.length s > 0) cl in assert (List.length cl > 0); diff --git a/src/Names.ml b/src/Names.ml index 41177c37..5785d06f 100644 --- a/src/Names.ml +++ b/src/Names.ml @@ -60,3 +60,8 @@ let filter_disambiguators_zero (n : name) : name = match pe with Ident _ -> true | Disambiguator d -> d <> Disambiguator.zero in List.filter pred n + +let as_ident (pe : path_elem) : string = + match pe with + | Ident s -> s + | Disambiguator _ -> raise (Failure "Improper variant") |