forked from NomicFoundation/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Binding rules for supporting mapping types
Key and value types are resolved, as well as indexing in a mapping variable will output the correct type to allow chaining, eg. member access expressions
- Loading branch information
Showing
14 changed files
with
434 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...s/solidity/outputs/cargo/slang_solidity/src/generated/bindings/generated/binding_rules.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
crates/solidity/outputs/cargo/tests/src/bindings_assertions/generated/mappings.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
crates/solidity/outputs/cargo/tests/src/bindings_assertions/generated/mod.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
crates/solidity/outputs/cargo/tests/src/bindings_output/generated/mappings.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
crates/solidity/outputs/cargo/tests/src/bindings_output/generated/mod.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
crates/solidity/testing/snapshots/bindings_assertions/mappings/nested.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
contract NestedMapping { | ||
mapping(address => mapping(uint256 => bool)) public nested; | ||
// ^def:1 | ||
|
||
function get(address _addr1, uint256 _i) public view returns (bool) { | ||
// ^def:2 | ||
// ^def:3 | ||
return nested[_addr1][_i]; | ||
// ^ref:2 | ||
// ^ref:3 | ||
// ^ref:1 | ||
} | ||
|
||
function set(address _addr1, uint256 _i, bool _boo) public { | ||
// ^def:4 | ||
// ^def:5 | ||
// ^def:6 | ||
nested[_addr1][_i] = _boo; | ||
// ^ref:4 | ||
// ^ref:5 | ||
// ^ref:6 | ||
//<ref:1 | ||
} | ||
|
||
function remove(address _addr1, uint256 _i) public { | ||
// ^def:7 | ||
// ^def:8 | ||
delete nested[_addr1][_i]; | ||
// ^ref:7 | ||
// ^ref:8 | ||
// ^ref:1 | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
crates/solidity/testing/snapshots/bindings_assertions/mappings/nested_custom.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
contract NestedCustom { | ||
enum Kind { Alpha, Beta } | ||
// ^def:1 | ||
struct Values { | ||
// ^def:2 | ||
uint balance; | ||
// ^def:3 | ||
} | ||
mapping(address => mapping(Kind => Values)) vaults; | ||
// ^def:4 | ||
// ^ref:2 | ||
// ^ref:1 | ||
|
||
function store(address _addr, Kind _kind, uint _amount) public { | ||
// ^def:5 | ||
// ^def:6 | ||
// ^def:7 | ||
vaults[_addr][_kind].balance += _amount; | ||
// ^ref:5 | ||
// ^ref:3 | ||
// ^ref:6 | ||
// ^ref:7 | ||
//<ref:4 | ||
} | ||
|
||
function balance(address _addr, Kind _kind) public returns (uint) { | ||
// ^def:8 | ||
// ^def:9 | ||
return vaults[_addr][_kind].balance; | ||
// ^ref:3 | ||
// ^ref:8 | ||
// ^ref:9 | ||
// ^ref:4 | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
crates/solidity/testing/snapshots/bindings_assertions/mappings/simple.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
contract Mapping { | ||
mapping(address => uint256) public myMap; | ||
// ^def:1 | ||
|
||
function get(address _addr) public view returns (uint256) { | ||
// ^def:2 | ||
return myMap[_addr]; | ||
// ^ref:2 | ||
// ^ref:1 | ||
} | ||
|
||
function set(address _addr, uint256 _i) public { | ||
// ^def:3 | ||
// ^def:4 | ||
myMap[_addr] = _i; | ||
// ^ref:3 | ||
// ^ref:4 | ||
//<ref:1 | ||
} | ||
|
||
function remove(address _addr) public { | ||
// ^def:5 | ||
delete myMap[_addr]; | ||
// ^ref:5 | ||
// ^ref:1 | ||
} | ||
} |
Oops, something went wrong.