diff --git a/.drom b/.drom index 3195a74..d201acb 100644 --- a/.drom +++ b/.drom @@ -2,7 +2,7 @@ # hash of toml configuration files # used for generation of all files -0c9d153828991ed03dadaee3e6e912de:. +bb15025d460dd55499bf2bc9c5f0999d:. # end context for . # begin context for .github/workflows/doc-deploy.yml @@ -37,7 +37,7 @@ a8d1bcd6f62c6b813b77d3ff8959d8d2:.ocamlformat-ignore # begin context for CHANGES.md # file CHANGES.md -873ca123aaa4f12aedad55595c52d1ea:CHANGES.md +d56aaadd8e0fec3ee5e644de78212d04:CHANGES.md # end context for CHANGES.md # begin context for LICENSE.md @@ -97,12 +97,12 @@ c8281f46ba9a11d0b61bc8ef67eaa357:docs/style.css # begin context for dune-project # file dune-project -b877b563b3a1da795b26be4319d5dcc2:dune-project +541e00af0f32fd619fcb9aca4e3ade30:dune-project # end context for dune-project # begin context for ez_hash.opam # file ez_hash.opam -62344d70f0815962091e077cca95a645:ez_hash.opam +adc64b244d25333acc55f7c38036f253:ez_hash.opam # end context for ez_hash.opam # begin context for scripts/after.sh @@ -122,27 +122,27 @@ bb3a9d286f0dc64021db4194427263ee:scripts/copy-bin.sh # begin context for solidity-alcotest.opam # file solidity-alcotest.opam -54623069b08f8d7342d62e5d21abf615:solidity-alcotest.opam +f958c6503f3651e8e4859f3ee7763c9a:solidity-alcotest.opam # end context for solidity-alcotest.opam # begin context for solidity-common.opam # file solidity-common.opam -42a80a0071000e29f533534d2e640113:solidity-common.opam +f10218980e927b8cd0b2487e7f3de7b7:solidity-common.opam # end context for solidity-common.opam # begin context for solidity-parser.opam # file solidity-parser.opam -c105f5cd63f7bdc137cacd90655d3960:solidity-parser.opam +f5ff692dad3f98ac6ac96d1a29e88b8f:solidity-parser.opam # end context for solidity-parser.opam # begin context for solidity-test.opam # file solidity-test.opam -386c907f168ab33fb2489810d9b8321d:solidity-test.opam +133ababf9254e0141d3ef6f8fa311667:solidity-test.opam # end context for solidity-test.opam # begin context for solidity-typechecker.opam # file solidity-typechecker.opam -4675cef4797ec67b1c5959d5973396db:solidity-typechecker.opam +26a81559f44a76a7b2612c2e4fce13f4:solidity-typechecker.opam # end context for solidity-typechecker.opam # begin context for sphinx/_static/css/fixes.css @@ -197,7 +197,7 @@ e86f9a67236dac57aaae3ca819cb7dbb:src/ocaml-solidity/package.toml # begin context for src/solidity-alcotest/version.mlt # file src/solidity-alcotest/version.mlt -47d835b1b3ec0a463928fd2af319b6c0:src/solidity-alcotest/version.mlt +4857ca979c211e298734d127807f6a09:src/solidity-alcotest/version.mlt # end context for src/solidity-alcotest/version.mlt # begin context for src/solidity-common/dune @@ -217,7 +217,7 @@ e86f9a67236dac57aaae3ca819cb7dbb:src/ocaml-solidity/package.toml # begin context for src/solidity-common/version.mlt # file src/solidity-common/version.mlt -47d835b1b3ec0a463928fd2af319b6c0:src/solidity-common/version.mlt +4857ca979c211e298734d127807f6a09:src/solidity-common/version.mlt # end context for src/solidity-common/version.mlt # begin context for src/solidity-parser/dune @@ -237,7 +237,7 @@ be413a351ddaf3cdf0d44e91ad35680e:src/solidity-parser/main.ml # begin context for src/solidity-parser/version.mlt # file src/solidity-parser/version.mlt -47d835b1b3ec0a463928fd2af319b6c0:src/solidity-parser/version.mlt +4857ca979c211e298734d127807f6a09:src/solidity-parser/version.mlt # end context for src/solidity-parser/version.mlt # begin context for src/solidity-test/dune @@ -247,7 +247,7 @@ be413a351ddaf3cdf0d44e91ad35680e:src/solidity-parser/main.ml # begin context for src/solidity-test/version.mlt # file src/solidity-test/version.mlt -47d835b1b3ec0a463928fd2af319b6c0:src/solidity-test/version.mlt +4857ca979c211e298734d127807f6a09:src/solidity-test/version.mlt # end context for src/solidity-test/version.mlt # begin context for src/solidity-typechecker/dune @@ -267,5 +267,5 @@ be413a351ddaf3cdf0d44e91ad35680e:src/solidity-parser/main.ml # begin context for src/solidity-typechecker/version.mlt # file src/solidity-typechecker/version.mlt -47d835b1b3ec0a463928fd2af319b6c0:src/solidity-typechecker/version.mlt +4857ca979c211e298734d127807f6a09:src/solidity-typechecker/version.mlt # end context for src/solidity-typechecker/version.mlt diff --git a/CHANGES.md b/CHANGES.md index c5fdf4b..172b1b5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,4 @@ -## v0.1.0 ( 2021-07-20 ) +## v0.1.0 ( 2021-07-22 ) * Initial commit diff --git a/drom.toml b/drom.toml index c533612..dd716d3 100644 --- a/drom.toml +++ b/drom.toml @@ -15,7 +15,7 @@ license = "LGPL2" min-edition = "4.08.0" name = "ocaml-solidity" synopsis = "The ocaml-solidity project" -version = "0.3.1" +version = "0.3.2" # keys that you could also define: # odoc-target = "...odoc-target..." diff --git a/dune-project b/dune-project index 283682e..49f1ded 100644 --- a/dune-project +++ b/dune-project @@ -3,7 +3,7 @@ (name ocaml-solidity) (allow_approximate_merlin) (generate_opam_files false) -(version 0.3.1) +(version 0.3.2) (formatting (enabled_for ocaml reason)) (using menhir 2.0) diff --git a/ez_hash.opam b/ez_hash.opam index a95cf8b..2b60fa1 100644 --- a/ez_hash.opam +++ b/ez_hash.opam @@ -2,7 +2,7 @@ # Do not modify, or add to the `skip` field of `drom.toml`. opam-version: "2.0" name: "ez_hash" -version: "0.3.1" +version: "0.3.2" license: "LGPL-2.1-only with OCaml-LGPL-linking-exception" synopsis: "Hash functions: sha3, sha256, blake2b" description: """ diff --git a/solidity-alcotest.opam b/solidity-alcotest.opam index fcc9d9c..c59846f 100644 --- a/solidity-alcotest.opam +++ b/solidity-alcotest.opam @@ -2,7 +2,7 @@ # Do not modify, or add to the `skip` field of `drom.toml`. opam-version: "2.0" name: "solidity-alcotest" -version: "0.3.1" +version: "0.3.2" license: "LGPL-2.1-only with OCaml-LGPL-linking-exception" synopsis: "The ocaml-solidity project" description: """ diff --git a/solidity-common.opam b/solidity-common.opam index c4e7446..8cd3b9f 100644 --- a/solidity-common.opam +++ b/solidity-common.opam @@ -2,7 +2,7 @@ # Do not modify, or add to the `skip` field of `drom.toml`. opam-version: "2.0" name: "solidity-common" -version: "0.3.1" +version: "0.3.2" license: "LGPL-2.1-only with OCaml-LGPL-linking-exception" synopsis: "The ocaml-solidity project" description: """ diff --git a/solidity-parser.opam b/solidity-parser.opam index c2609c9..b6b6746 100644 --- a/solidity-parser.opam +++ b/solidity-parser.opam @@ -2,7 +2,7 @@ # Do not modify, or add to the `skip` field of `drom.toml`. opam-version: "2.0" name: "solidity-parser" -version: "0.3.1" +version: "0.3.2" license: "LGPL-2.1-only with OCaml-LGPL-linking-exception" synopsis: "The ocaml-solidity project" description: """ diff --git a/solidity-test.opam b/solidity-test.opam index ae7c6fc..ba017f1 100644 --- a/solidity-test.opam +++ b/solidity-test.opam @@ -2,7 +2,7 @@ # Do not modify, or add to the `skip` field of `drom.toml`. opam-version: "2.0" name: "solidity-test" -version: "0.3.1" +version: "0.3.2" license: "LGPL-2.1-only with OCaml-LGPL-linking-exception" synopsis: "The ocaml-solidity project" description: """ diff --git a/solidity-typechecker.opam b/solidity-typechecker.opam index 0c7e6fd..2050d49 100644 --- a/solidity-typechecker.opam +++ b/solidity-typechecker.opam @@ -2,7 +2,7 @@ # Do not modify, or add to the `skip` field of `drom.toml`. opam-version: "2.0" name: "solidity-typechecker" -version: "0.3.1" +version: "0.3.2" license: "LGPL-2.1-only with OCaml-LGPL-linking-exception" synopsis: "The ocaml-solidity project" description: """ diff --git a/src/solidity-alcotest/version.mlt b/src/solidity-alcotest/version.mlt index 1b5969f..4d66c71 100644 --- a/src/solidity-alcotest/version.mlt +++ b/src/solidity-alcotest/version.mlt @@ -13,7 +13,7 @@ let query cmd = let commit_hash = query "git show -s --pretty=format:%H" let commit_date = query "git show -s --pretty=format:%ci" -let version = "0.3.1" +let version = "0.3.2" let version = match commit_hash with | Some commit_hash -> diff --git a/src/solidity-common/solidity_common.ml b/src/solidity-common/solidity_common.ml index 2127917..7983e24 100644 --- a/src/solidity-common/solidity_common.ml +++ b/src/solidity-common/solidity_common.ml @@ -449,10 +449,10 @@ let string_of_pos (file, pos1, pos2) = Buffer.contents b with _ -> "" in - Printf.sprintf "%s:%d-%d:%d-%d" + Printf.sprintf "%s:%d.%d-%d.%d" file - (fst pos1) (snd pos1) - (fst pos2) (snd pos2), + (fst pos1) (snd pos1+1) + (fst pos2) (snd pos2+1), source let set_annot n annot = diff --git a/src/solidity-common/solidity_printer.ml b/src/solidity-common/solidity_printer.ml index dea4c25..9f0bfa6 100644 --- a/src/solidity-common/solidity_printer.ml +++ b/src/solidity-common/solidity_printer.ml @@ -257,7 +257,7 @@ and variable_definition b indent ~freeton { var_mutability; var_override; var_init; var_static } = bprint b indent - (Format.sprintf "%s%s%s %s%s%s%s%s" + (Format.sprintf "%s%s%s%s %s%s%s%s" (string_of_type var_type) (if var_static then " static" else "") (if freeton then @@ -266,10 +266,10 @@ and variable_definition b indent ~freeton { | m -> " " ^ (string_of_var_mutability m) else "" ) - (string_of_ident var_name) (match var_visibility with | VInternal -> "" | v -> " " ^ (string_of_visibility v)) + (string_of_ident var_name) (if freeton then "" else match var_mutability with diff --git a/src/solidity-common/version.mlt b/src/solidity-common/version.mlt index 1b5969f..4d66c71 100644 --- a/src/solidity-common/version.mlt +++ b/src/solidity-common/version.mlt @@ -13,7 +13,7 @@ let query cmd = let commit_hash = query "git show -s --pretty=format:%H" let commit_date = query "git show -s --pretty=format:%ci" -let version = "0.3.1" +let version = "0.3.2" let version = match commit_hash with | Some commit_hash -> diff --git a/src/solidity-parser/version.mlt b/src/solidity-parser/version.mlt index 1b5969f..4d66c71 100644 --- a/src/solidity-parser/version.mlt +++ b/src/solidity-parser/version.mlt @@ -13,7 +13,7 @@ let query cmd = let commit_hash = query "git show -s --pretty=format:%H" let commit_date = query "git show -s --pretty=format:%ci" -let version = "0.3.1" +let version = "0.3.2" let version = match commit_hash with | Some commit_hash -> diff --git a/src/solidity-test/version.mlt b/src/solidity-test/version.mlt index 1b5969f..4d66c71 100644 --- a/src/solidity-test/version.mlt +++ b/src/solidity-test/version.mlt @@ -13,7 +13,7 @@ let query cmd = let commit_hash = query "git show -s --pretty=format:%H" let commit_date = query "git show -s --pretty=format:%ci" -let version = "0.3.1" +let version = "0.3.2" let version = match commit_hash with | Some commit_hash -> diff --git a/src/solidity-typechecker/solidity_checker_TYPES.ml b/src/solidity-typechecker/solidity_checker_TYPES.ml index 60b007d..df0db87 100644 --- a/src/solidity-typechecker/solidity_checker_TYPES.ml +++ b/src/solidity-typechecker/solidity_checker_TYPES.ml @@ -135,12 +135,14 @@ and fun_kind = | KOther | KNewContract | KExtContractFun + | KReturn and function_options = { kind : fun_kind; value : bool; gas : bool; salt : bool; + fields : StringSet.t ; } and location = diff --git a/src/solidity-typechecker/solidity_type_builder.ml b/src/solidity-typechecker/solidity_type_builder.ml index 56e26eb..b160bea 100644 --- a/src/solidity-typechecker/solidity_type_builder.ml +++ b/src/solidity-typechecker/solidity_type_builder.ml @@ -31,7 +31,8 @@ let compute_selector pos ~library id args = Bytes.to_string (Bytes.sub (sha3kec (Bytes.of_string fun_sig)) 0 4) let new_fun_options = { - kind = KOther; value = false; gas = false; salt = false + kind = KOther; value = false; gas = false; salt = false ; + fields = StringSet.empty ; } let eval_array_length_exp env e = diff --git a/src/solidity-typechecker/solidity_typechecker.ml b/src/solidity-typechecker/solidity_typechecker.ml index 8119df0..7b87df1 100644 --- a/src/solidity-typechecker/solidity_typechecker.ml +++ b/src/solidity-typechecker/solidity_typechecker.ml @@ -567,6 +567,12 @@ let type_ident opt env base_t_opt id_node = set_annot id_node a; t, lv + +let type_options_ref = ref ( fun _ -> assert false ) + +let type_options opt env pos is_payable fo opts = + !type_options_ref opt env pos is_payable fo opts + let rec type_expression opt env exp : type_ = let t, _lv = type_expression_lv opt env exp in t @@ -963,7 +969,7 @@ and expect_type pos ~expected ~provided = (Solidity_type_printer.string_of_type provided) (Solidity_type_printer.string_of_type expected) -and type_options opt env pos is_payable fo opts = +and type_options_fun opt env pos is_payable fo opts = List.fold_left (fun fo (id, e) -> let id = strip id in let fo, already_set = @@ -993,51 +999,6 @@ and type_options opt env pos is_payable fo opts = error pos "Function call option \"%s\" can \ only be used with \"new\"" (Ident.to_string id); - (* FREETON *) - (* TODO: check that mandatory fields are provided *) - | "pubkey", ( KNewContract | KExtContractFun ) - when !for_freeton -> - expect_expression_type opt env e - ( TOptional (TUint 256)); - fo, false (* TODO *) - | "code", KNewContract when !for_freeton -> - expect_expression_type opt env e (TAbstract TvmCell); - fo, false (* TODO *) - | "flag", ( KExtContractFun | KNewContract ) when !for_freeton -> - expect_expression_type opt env e (TUint 8); - fo, false (* TODO *) - | "varInit", KNewContract when !for_freeton -> - fo, false (* TODO *) - | "abiVer", KExtContractFun when !for_freeton -> - expect_expression_type opt env e (TUint 8); - fo, false (* TODO *) - | "extMsg", KExtContractFun when !for_freeton -> - expect_expression_type opt env e TBool ; - fo, false (* TODO *) - | "sign", KExtContractFun when !for_freeton -> - expect_expression_type opt env e TBool ; - fo, false (* TODO *) - | "bounce", KExtContractFun when !for_freeton -> - expect_expression_type opt env e TBool ; - fo, false (* TODO *) - | "stateInit", KNewContract when !for_freeton -> - expect_expression_type opt env e (TAbstract TvmCell) ; - fo, false (* TODO *) - | "wid", KNewContract when !for_freeton -> - expect_expression_type opt env e (TUint 8) ; - fo, false (* TODO *) - | "time", KExtContractFun when !for_freeton -> - expect_expression_type opt env e (TUint 64) ; - fo, false (* TODO *) - | "expire", KExtContractFun when !for_freeton -> - expect_expression_type opt env e (TUint 64) ; - fo, false (* TODO *) - | "callbackId", KExtContractFun when !for_freeton -> - expect_expression_type opt env e (TUint 64) ; - fo, false (* TODO *) - | "onErrorId", KExtContractFun when !for_freeton -> - expect_expression_type opt env e (TUint 64) ; - fo, false (* TODO *) | _, KOther -> error pos "Function call options can only be set on \ external function calls or contract creations" @@ -1177,7 +1138,7 @@ let rec type_statement opt env s = in let is_payable = true in let fo = { Solidity_type_builder.new_fun_options - with kind = KExtContractFun } in + with kind = KReturn } in let _fo = type_options opt env pos is_payable fo opts in set_annot s (AType annot); begin @@ -2168,3 +2129,6 @@ let type_program ?(init = Solidity_primitives.init) p = ) ordered_modules; {p with program_modules = ordered_modules} + +let () = + type_options_ref := type_options_fun diff --git a/src/solidity-typechecker/solidity_typechecker.mli b/src/solidity-typechecker/solidity_typechecker.mli index a14cb01..ed58735 100644 --- a/src/solidity-typechecker/solidity_typechecker.mli +++ b/src/solidity-typechecker/solidity_typechecker.mli @@ -16,3 +16,19 @@ val type_program : ?init:(unit -> unit) -> Solidity_ast.program -> Solidity_ast.program + + +val expect_expression_type : + Solidity_checker_TYPES.options -> + Solidity_checker_TYPES.env -> + Solidity_ast.expression -> Solidity_checker_TYPES.type_ -> unit + +val type_options_ref : + (Solidity_checker_TYPES.options -> + Solidity_checker_TYPES.env -> + Solidity_common.pos -> + bool -> + Solidity_checker_TYPES.function_options -> + (Solidity_ast.ident * Solidity_ast.expression) list -> + Solidity_checker_TYPES.function_options) + ref diff --git a/src/solidity-typechecker/version.mlt b/src/solidity-typechecker/version.mlt index 1b5969f..4d66c71 100644 --- a/src/solidity-typechecker/version.mlt +++ b/src/solidity-typechecker/version.mlt @@ -13,7 +13,7 @@ let query cmd = let commit_hash = query "git show -s --pretty=format:%H" let commit_date = query "git show -s --pretty=format:%ci" -let version = "0.3.1" +let version = "0.3.2" let version = match commit_hash with | Some commit_hash ->