diff options
author | Son Ho | 2023-09-14 00:24:29 +0200 |
---|---|---|
committer | Son Ho | 2023-09-14 00:24:29 +0200 |
commit | 378bfbd1be69ee54cfe7fad97ca3b09d0f80f62b (patch) | |
tree | 03dd58e88263fa7a3ad983887804f56fbcae0525 /compiler | |
parent | 60aa9ff5b31e47ecc2ac2dff55ee06582af62806 (diff) |
Fix some issues with the name collisions
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ExtractBase.ml | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/compiler/ExtractBase.ml b/compiler/ExtractBase.ml index 438a3475..6789b5b8 100644 --- a/compiler/ExtractBase.ml +++ b/compiler/ExtractBase.ml @@ -840,7 +840,8 @@ let id_to_string (id : id) (ctx : extraction_ctx) : string = (** We might not check for collisions for some specific ids (ex.: field names) *) let allow_collisions (id : id) : bool = match id with - | FieldId _ | TraitItemClauseId _ | TraitParentClauseId _ | TraitItemId _ -> + | FieldId _ | TraitItemClauseId _ | TraitParentClauseId _ | TraitItemId _ + | TraitMethodId _ -> !Config.record_fields_short_names | _ -> false @@ -1285,19 +1286,29 @@ let ctx_add_trait_const (d : trait_decl) (item : string) (ctx : extraction_ctx) : extraction_ctx = let is_opaque = false in let name = ctx.fmt.trait_const_name d item in + (* Add a prefix if necessary *) + let name = + if !Config.record_fields_short_names then name + else ctx.fmt.trait_decl_name d ^ name + in ctx_add is_opaque (TraitItemId (d.def_id, item)) name ctx let ctx_add_trait_type (d : trait_decl) (item : string) (ctx : extraction_ctx) : extraction_ctx = let is_opaque = false in let name = ctx.fmt.trait_type_name d item in + (* Add a prefix if necessary *) + let name = + if !Config.record_fields_short_names then name + else ctx.fmt.trait_decl_name d ^ name + in ctx_add is_opaque (TraitItemId (d.def_id, item)) name ctx let ctx_add_trait_method (d : trait_decl) (item_name : string) (f : fun_decl) (ctx : extraction_ctx) : extraction_ctx = (* We do something special: we use the base name but remove everything - but the crate (because [get_name] removes it) and the last ident. - This allows us to reuse the [ctx_compute_fun_decl] function. + but the crate (because [get_name] removes it) and the last ident. + This allows us to reuse the [ctx_compute_fun_decl] function. *) let basename : name = match (f.basename : name) with @@ -1307,6 +1318,11 @@ let ctx_add_trait_method (d : trait_decl) (item_name : string) (f : fun_decl) let f = { f with basename } in let trans = A.FunDeclId.Map.find f.def_id ctx.trans_funs in let name = ctx_compute_fun_name trans f ctx in + (* Add a prefix if necessary *) + let name = + if !Config.record_fields_short_names then name + else ctx.fmt.trait_decl_name d ^ name + in let is_opaque = false in ctx_add is_opaque (TraitMethodId (d.def_id, item_name, f.back_id)) name ctx @@ -1314,12 +1330,22 @@ let ctx_add_trait_parent_clause (d : trait_decl) (clause : trait_clause) (ctx : extraction_ctx) : extraction_ctx = let is_opaque = false in let name = ctx.fmt.trait_parent_clause_name d clause in + (* Add a prefix if necessary *) + let name = + if !Config.record_fields_short_names then name + else ctx.fmt.trait_decl_name d ^ name + in ctx_add is_opaque (TraitParentClauseId (d.def_id, clause.clause_id)) name ctx let ctx_add_trait_type_clause (d : trait_decl) (item : string) (clause : trait_clause) (ctx : extraction_ctx) : extraction_ctx = let is_opaque = false in let name = ctx.fmt.trait_type_clause_name d item clause in + (* Add a prefix if necessary *) + let name = + if !Config.record_fields_short_names then name + else ctx.fmt.trait_decl_name d ^ name + in ctx_add is_opaque (TraitItemClauseId (d.def_id, item, clause.clause_id)) name ctx |