Skip to content

Commit

Permalink
Merge pull request #33 from hra687261/fix-issue-32
Browse files Browse the repository at this point in the history
Deduplication of idds (ident_desc) in env.ident_map
  • Loading branch information
hra687261 authored Jun 15, 2022
2 parents 9c03ceb + 02d3e6a commit 2e22dc6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
60 changes: 46 additions & 14 deletions src/solidity-typechecker/solidity_tenv_builder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,35 @@ let idd_pos = function
| Modifier (md) -> md.modifier_def.mod_name.pos
| Event (ed) -> ed.event_def.event_name.pos

(** [idd_eq_pos id1 id2] returns true if the idds [id1] and [id2] are of the
same type and located in the same position. *)
let idd_eq_pos id1 id2 =
match id1, id2 with
| Alias (ad1), Alias (ad2) ->
ad1.alias_pos = ad2.alias_pos
| Module (md1), Module (md2) ->
md1.module_pos = md2.module_pos
| Contract (cd1), Contract (cd2) ->
cd1.contract_def.contract_name.pos = cd2.contract_def.contract_name.pos
| Type (TDStruct (sd1)), Type (TDStruct (sd2)) ->
(fst sd1.struct_def).pos = (fst sd2.struct_def).pos
| Type (TDEnum (ed1)), Type (TDEnum (ed2)) ->
ed1.enum_pos = ed2.enum_pos
| Variable ({ variable_def = Some (vd1); _ }),
Variable ({ variable_def = Some (vd2); _ }) ->
vd1.var_name.pos = vd2.var_name.pos
| Function ({ function_def = Some (fd1); _ }),
Function ({ function_def = Some (fd2); _ }) ->
fd1.fun_name.pos = fd2.fun_name.pos
| Modifier (md1), Modifier (md2) ->
md1.modifier_def.mod_name.pos = md2.modifier_def.mod_name.pos
| Event (ed1), Event (ed2) ->
ed1.event_def.event_name.pos = ed2.event_def.event_name.pos
| _ -> false

let new_env ?upper_env () =
{ upper_env; ident_map = IdentMap.empty; using_for = AbsLongIdentMap.empty }



(* Functions for building and checking module environments *)

let add_module_ident env id idd =
Expand Down Expand Up @@ -130,18 +153,27 @@ let resolve_aliases menvs m =
()
) menv.ident_map;
let rec aux iddl =
List.flatten @@
List.map (fun (idd, id_origin) ->
match idd with
| Alias ({ alias_abs_name; alias_pos; alias_targets = []; _ }) ->
error alias_pos "Alias %s not resolved"
(Ident.to_string (LongIdent.last alias_abs_name))
| Alias ({ alias_targets; _ }) ->
let at_iddl = aux alias_targets in
List.map (fun (idd, _id_origin) -> (idd, Imported)) at_iddl
| _ ->
[(idd, id_origin)]
) iddl
List.fold_left (
fun acc (idd, id_origin) ->
match idd with
| Alias ({ alias_abs_name; alias_pos; alias_targets = []; _ }) ->
error alias_pos "Alias %s not resolved"
(Ident.to_string (LongIdent.last alias_abs_name))
| Alias ({ alias_targets; _ }) ->
let at_iddl = aux alias_targets in
List.fold_left (
fun acc (idd, _id_origin) ->
(idd, Imported) ::
List.filter (fun (it_idd, _) ->
not (idd_eq_pos idd it_idd)
) acc
) acc at_iddl
| _ ->
(idd, id_origin) ::
List.filter (fun (it_idd, _) ->
not (idd_eq_pos idd it_idd)
) acc
) [] iddl
in
menv.ident_map <- IdentMap.map aux menv.ident_map

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pragma solidity >=0.6.0;

contract A {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma solidity >=0.6.0;

import "./multiple_import_1.sol";

contract B is A {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pragma solidity >=0.6.0;

import {A} from "./multiple_import_1.sol";
import "./multiple_import_2.sol";

0 comments on commit 2e22dc6

Please sign in to comment.