Skip to content

Commit

Permalink
add variable assignments to annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabrice Le Fessant committed Jul 27, 2021
1 parent 46ca2b7 commit ccc3aab
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 72 deletions.
8 changes: 4 additions & 4 deletions src/solidity-common/solidity_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ module Ident = struct
let to_string id = id
let of_string id = id
let printf fmt id = Format.fprintf fmt "%s" id
let constructor = "#"
let onBounce = "!"
let receive = "@"
let fallback = "*"
let constructor = ":constructor"
let onBounce = ":onBounce"
let receive = ":receive"
let fallback = ":fallback"
end

module LongIdent = struct
Expand Down
4 changes: 3 additions & 1 deletion src/solidity-typechecker/solidity_checker_TYPES.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ and variable_desc = {
mutable variable_getter : function_desc option; (* when the variable has a getter*)
variable_is_primitive : bool;
variable_def : Solidity_ast.state_variable_definition option; (* module/contract*)
mutable variable_assigns : function_desc list ;
}

and function_desc = {
Expand All @@ -116,6 +117,7 @@ and function_desc = {
function_is_method : bool;
function_is_primitive : bool;
function_def : Solidity_ast.function_definition option; (* Primitives have no definition *)
mutable function_assigns : variable_desc list ;
}

and modifier_desc = {
Expand Down Expand Up @@ -241,7 +243,7 @@ type options = {
call_args: args option; (* could just have an in_lvalue flag *)
fun_returns : type_ list;
in_loop: bool;
in_function: bool;
in_function: function_desc option;
in_modifier: bool;
current_hierarchy: absolute LongIdent.t list;
current_contract: contract_desc option;
Expand Down
4 changes: 3 additions & 1 deletion src/solidity-typechecker/solidity_tenv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ let find_constructor pos { contract_abs_name; contract_env; _ } =
function_selector = None;
function_is_method = true;
function_is_primitive = false;
function_def = None; }
function_def = None;
function_assigns = [];
}

let has_abstract_function cd =
let exception Found of Ident.t in
Expand Down
32 changes: 24 additions & 8 deletions src/solidity-typechecker/solidity_type_builder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ and function_type_to_desc pos env ft =
function_selector = None;
function_is_method = false;
function_is_primitive = false;
function_def = None; }
function_def = None;
function_assigns = [];
}

and process_fun_params pos env ~ext params =
List.map (fun (t, loc_opt, name_opt) ->
Expand Down Expand Up @@ -321,7 +323,9 @@ let variable_desc_to_function_desc pos vid variable_abs_name vt :
function_selector;
function_is_method = true;
function_is_primitive = false;
function_def = None; }
function_def = None;
function_assigns = [];
}

(* Build the function corresponding to an event *)
let event_desc_to_function_desc (ed : event_desc) : function_desc =
Expand All @@ -335,7 +339,9 @@ let event_desc_to_function_desc (ed : event_desc) : function_desc =
function_selector = None;
function_is_method = false;
function_is_primitive = false;
function_def = None; }
function_def = None;
function_assigns = [];
}

(* Make a ident description for a local variable *)
let local_variable_desc variable_type : variable_desc =
Expand All @@ -347,7 +353,9 @@ let local_variable_desc variable_type : variable_desc =
variable_override = None;
variable_getter = None;
variable_is_primitive = false;
variable_def = None; }
variable_def = None;
variable_assigns = [] ;
}



Expand Down Expand Up @@ -395,7 +403,9 @@ let make_variable_desc vlid vd =
variable_override = None;
variable_getter = None;
variable_is_primitive = false;
variable_def = Some (vd); }
variable_def = Some (vd);
variable_assigns = [] ;
}

let update_variable_desc pos env vd kind_opt =
let vd' =
Expand Down Expand Up @@ -428,7 +438,9 @@ let make_function_desc flid fd method_ =
function_selector = None;
function_is_method = method_;
function_is_primitive = false;
function_def = Some (fd); }
function_def = Some (fd);
function_assigns = [];
}

let update_function_desc pos env fd kind_opt =
let fd' =
Expand Down Expand Up @@ -479,7 +491,9 @@ let primitive_fun_desc ?(returns_lvalue=false)
function_selector = None;
function_is_method = false; (* can be true *)
function_is_primitive = true;
function_def = None; }
function_def = None;
function_assigns = [];
}

let primitive_fun_type ?(kind=KOther) ?(returns_lvalue=false)
arg_types ret_types function_mutability =
Expand All @@ -502,7 +516,9 @@ let primitive_var_desc (*?(is_lvalue=false)*) variable_type =
variable_override = None;
variable_getter = None;
variable_is_primitive = true;
variable_def = None; }
variable_def = None;
variable_assigns = [] ;
}

let primitive_var (*?(is_lvalue=false)*) variable_type =
let vd = primitive_var_desc variable_type in
Expand Down
Loading

0 comments on commit ccc3aab

Please sign in to comment.