diff --git a/src/solidity-typechecker/solidity_primitives.ml b/src/solidity-typechecker/solidity_primitives.ml index 9d9291c..6b4fbbc 100644 --- a/src/solidity-typechecker/solidity_primitives.ml +++ b/src/solidity-typechecker/solidity_primitives.ml @@ -17,10 +17,27 @@ open Solidity_exceptions let error = type_error +module UTILS = struct + let register id p f_desc = Solidity_common.add_primitive id p; Solidity_tenv.add_primitive_desc id f_desc +let primitive_fun_named ?(returns_lvalue=false) + arg_types ret_types function_mutability = + Function { function_abs_name = LongIdent.empty; + function_params = arg_types; + function_returns = List.map (fun t -> (t, None)) ret_types; + function_returns_lvalue = returns_lvalue; + function_visibility = VPublic; + function_mutability; + function_override = None; + function_selector = None; + function_is_method = false; (* can be true *) + function_is_primitive = true; + function_def = None; + function_assigns = []; + } let make_fun = Solidity_type_builder.primitive_fun @@ -47,6 +64,8 @@ let preprocess_arg_1 pos t atl_opt = error pos "Need at least 1 argument for function \ call, but provided only 0" +end +open UTILS let register_primitives () = diff --git a/src/solidity-typechecker/solidity_primitives.mli b/src/solidity-typechecker/solidity_primitives.mli index 02b95ff..e43bdf3 100644 --- a/src/solidity-typechecker/solidity_primitives.mli +++ b/src/solidity-typechecker/solidity_primitives.mli @@ -11,3 +11,37 @@ (**************************************************************************) val init : unit -> unit + +module UTILS : sig + val register : + int -> + Solidity_common.primitive -> + (Solidity_common.pos -> + Solidity_checker_TYPES.options -> + Solidity_checker_TYPES.type_ option -> + Solidity_checker_TYPES.ident_desc option) -> + unit + val primitive_fun_named : + ?returns_lvalue:bool -> + (Solidity_checker_TYPES.type_ * + Solidity_common.IdentSet.elt option) + list -> + Solidity_checker_TYPES.type_ list -> + Solidity_ast.fun_mutability -> Solidity_checker_TYPES.ident_desc + + val make_var : + Solidity_checker_TYPES.type_ -> Solidity_checker_TYPES.ident_desc + val make_fun : + ?returns_lvalue:bool -> + Solidity_checker_TYPES.type_ list -> + Solidity_checker_TYPES.type_ list -> + Solidity_ast.fun_mutability -> Solidity_checker_TYPES.ident_desc + val make_prim_args : + Solidity_common.pos -> + Solidity_checker_TYPES.options -> + Solidity_checker_TYPES.type_ list option + val preprocess_arg_0 : 'a -> 'b list option -> 'b list + val preprocess_arg_1 : + Solidity_common.pos -> 'a -> 'a list option -> 'a list + +end