Skip to content

Commit

Permalink
Merge pull request #21 from lefessan/z-2021-08-23-use-cpp
Browse files Browse the repository at this point in the history
Fixes for FreeTON
  • Loading branch information
lefessan authored Aug 28, 2021
2 parents 0a4271c + 5278542 commit abfefe9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
14 changes: 13 additions & 1 deletion src/solidity-common/solidity_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,13 @@ and number_unit =
| Days
| Weeks
| Years
| Ton (* freeton *)
| Nanoton (* freeton *)
| Microton (* freeton *)
| Milliton (* freeton *)
| Ton (* freeton *)
| Kiloton (* freeton *)
| Megaton (* freeton *)
| Gigaton (* freeton *)

and unary_operator =
| UPlus
Expand Down Expand Up @@ -401,7 +407,13 @@ let unit_factor unit =
| Days -> ExtZ._24x3600
| Weeks -> ExtZ._7x24x3600
| Years -> ExtZ._365x24x3600
| Nanoton -> Z.one
| Microton -> ExtZ._10_3
| Milliton -> ExtZ._10_6
| Ton -> ExtZ._10_9
| Kiloton -> ExtZ._10_12
| Megaton -> ExtZ._10_15
| Gigaton -> ExtZ._10_18
in
Q.of_bigint z

Expand Down
8 changes: 7 additions & 1 deletion src/solidity-common/solidity_ast.mli
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,13 @@ and number_unit =
| Days
| Weeks
| Years
| Ton (* freeton *)
| Nanoton (* freeton *)
| Microton (* freeton *)
| Milliton (* freeton *)
| Ton (* freeton *)
| Kiloton (* freeton *)
| Megaton (* freeton *)
| Gigaton (* freeton *)

and unary_operator =
| UPlus
Expand Down
9 changes: 8 additions & 1 deletion src/solidity-common/solidity_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ let string_of_number_unit = function
| Days -> "days"
| Weeks -> "weeks"
| Years -> "years"
| Ton -> "ton"

| Nanoton -> "nanoton"
| Microton -> "microton"
| Milliton -> "milliton"
| Ton -> "ton"
| Kiloton -> "kiloton"
| Megaton -> "megaton"
| Gigaton -> "gigaton"

let string_of_unop = function
| UPlus -> "+"
Expand Down
25 changes: 23 additions & 2 deletions src/solidity-parser/solidity_lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ let identifier =
['a'-'z' 'A'-'Z' '_' '$'] ['a'-'z' 'A'-'Z' '_' '$' '0'-'9']*

let hex_digit =
['0'-'9' 'a'-'f' 'A'-'F']
['0'-'9' 'a'-'f' 'A'-'F' '_']

let size_32 =
'0'* ( "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" |
Expand Down Expand Up @@ -301,7 +301,6 @@ let init ~freeton =
"catch", CATCH;
"true", BOOLEANLITERAL (true);
"false", BOOLEANLITERAL (false);
"ton", NUMBERUNIT (Ton);
"wei", NUMBERUNIT (Wei);
"gwei", NUMBERUNIT (Gwei);
"szabo", NUMBERUNIT (Twei);
Expand All @@ -324,6 +323,28 @@ if freeton then
"onBounce", ONBOUNCE;
"repeat", REPEAT;
"responsible", RESPONSIBLE;

"nano", NUMBERUNIT (Nanoton);
"nanoton", NUMBERUNIT (Nanoton);
"nTon", NUMBERUNIT (Nanoton);

"micro", NUMBERUNIT (Microton);
"microton", NUMBERUNIT (Microton);

"milli", NUMBERUNIT (Milliton);
"milliton", NUMBERUNIT (Milliton);

"ton", NUMBERUNIT (Ton);
"Ton", NUMBERUNIT (Ton);

"kiloton", NUMBERUNIT (Kiloton);
"kTon", NUMBERUNIT (Kiloton);

"megaton", NUMBERUNIT (Megaton);
"MTon", NUMBERUNIT (Megaton);

"gigaton", NUMBERUNIT (Gigaton);
"GTon", NUMBERUNIT (Gigaton);
];
()
end
Expand Down
9 changes: 6 additions & 3 deletions src/solidity-typechecker/solidity_typechecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -932,9 +932,12 @@ and type_expression_lv opt env exp
let t = Solidity_type.change_type_location LMemory t in
replace_annot e (AType (TType t));
let fp =
List.map (fun (fid, ft) ->
(Solidity_type.change_type_location LMemory ft, Some (fid))
) sd.struct_fields
List.fold_right (fun (fid, ft) fs ->
let ty = Solidity_type.change_type_location LMemory ft in
match ty with
| TMapping _ -> fs
| _ -> ( ty, Some fid) :: fs
) sd.struct_fields []
in
check_function_application pos "struct constructor" fp args;
t, RightValue
Expand Down

0 comments on commit abfefe9

Please sign in to comment.