aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorChase McDermott <chasemcd1745@tamu.edu>2018-07-15 05:42:01 +0800
committerChase McDermott <chasemcd1745@tamu.edu>2018-07-15 05:42:43 +0800
commit3267adcd14ba10e27a4b177e771fca9c9ab39646 (patch)
tree1c9b69f82d2af0e7eaf56b17188014b541b66ce8 /docs
parent31e56f9f9976cee44f000226318dca566f0f0b79 (diff)
downloaddexon-solidity-3267adcd14ba10e27a4b177e771fca9c9ab39646.tar.gz
dexon-solidity-3267adcd14ba10e27a4b177e771fca9c9ab39646.tar.zst
dexon-solidity-3267adcd14ba10e27a4b177e771fca9c9ab39646.zip
Added default data locations to docs and other external tests.
Diffstat (limited to 'docs')
-rw-r--r--docs/abi-spec.rst8
-rw-r--r--docs/assembly.rst8
-rw-r--r--docs/contracts.rst6
-rw-r--r--docs/frequently-asked-questions.rst11
-rw-r--r--docs/solidity-by-example.rst8
-rw-r--r--docs/types.rst20
6 files changed, 30 insertions, 31 deletions
diff --git a/docs/abi-spec.rst b/docs/abi-spec.rst
index ab1650d8..5f6d7d50 100644
--- a/docs/abi-spec.rst
+++ b/docs/abi-spec.rst
@@ -193,9 +193,9 @@ Given the contract:
pragma solidity ^0.4.16;
contract Foo {
- function bar(bytes3[2]) public pure {}
+ function bar(bytes3[2] memory) public pure {}
function baz(uint32 x, bool y) public pure returns (bool r) { r = x > 32 || y; }
- function sam(bytes, bool, uint[]) public pure {}
+ function sam(bytes memory, bool, uint[] memory) public pure {}
}
@@ -490,8 +490,8 @@ As an example, the code
contract Test {
struct S { uint a; uint[] b; T[] c; }
struct T { uint x; uint y; }
- function f(S s, T t, uint a) public { }
- function g() public returns (S s, T t, uint a) {}
+ function f(S memory s, T memory t, uint a) public { }
+ function g() public returns (S memory s, T memory t, uint a) {}
}
would result in the JSON:
diff --git a/docs/assembly.rst b/docs/assembly.rst
index cf114c12..ec6ac876 100644
--- a/docs/assembly.rst
+++ b/docs/assembly.rst
@@ -54,7 +54,7 @@ idea is that assembly libraries will be used to enhance the language in such way
pragma solidity ^0.4.0;
library GetCode {
- function at(address _addr) public view returns (bytes o_code) {
+ function at(address _addr) public view returns (bytes memory o_code) {
assembly {
// retrieve the size of the code, this needs assembly
let size := extcodesize(_addr)
@@ -83,7 +83,7 @@ you really know what you are doing.
library VectorSum {
// This function is less efficient because the optimizer currently fails to
// remove the bounds checks in array access.
- function sumSolidity(uint[] _data) public view returns (uint o_sum) {
+ function sumSolidity(uint[] memory _data) public view returns (uint o_sum) {
for (uint i = 0; i < _data.length; ++i)
o_sum += _data[i];
}
@@ -91,7 +91,7 @@ you really know what you are doing.
// We know that we only access the array in bounds, so we can avoid the check.
// 0x20 needs to be added to an array because the first slot contains the
// array length.
- function sumAsm(uint[] _data) public view returns (uint o_sum) {
+ function sumAsm(uint[] memory _data) public view returns (uint o_sum) {
for (uint i = 0; i < _data.length; ++i) {
assembly {
o_sum := add(o_sum, mload(add(add(_data, 0x20), mul(i, 0x20))))
@@ -100,7 +100,7 @@ you really know what you are doing.
}
// Same as above, but accomplish the entire code within inline assembly.
- function sumPureAsm(uint[] _data) public view returns (uint o_sum) {
+ function sumPureAsm(uint[] memory _data) public view returns (uint o_sum) {
assembly {
// Load the length (first 32 bytes)
let len := mload(_data)
diff --git a/docs/contracts.rst b/docs/contracts.rst
index fa6df6bf..ea41cb54 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -1295,12 +1295,12 @@ custom types without the overhead of external function calls:
uint[] limbs;
}
- function fromUint(uint x) internal pure returns (bigint r) {
+ function fromUint(uint x) internal pure returns (bigint memory r) {
r.limbs = new uint[](1);
r.limbs[0] = x;
}
- function add(bigint _a, bigint _b) internal pure returns (bigint r) {
+ function add(bigint memory _a, bigint memory _b) internal pure returns (bigint memory r) {
r.limbs = new uint[](max(_a.limbs.length, _b.limbs.length));
uint carry = 0;
for (uint i = 0; i < r.limbs.length; ++i) {
@@ -1323,7 +1323,7 @@ custom types without the overhead of external function calls:
}
}
- function limb(bigint _a, uint _limb) internal pure returns (uint) {
+ function limb(bigint memory _a, uint _limb) internal pure returns (uint) {
return _limb < _a.limbs.length ? _a.limbs[_limb] : 0;
}
diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst
index 17e71747..36eaf534 100644
--- a/docs/frequently-asked-questions.rst
+++ b/docs/frequently-asked-questions.rst
@@ -85,7 +85,7 @@ Example::
pragma solidity ^0.4.16;
contract C {
- function f() public pure returns (uint8[5]) {
+ function f() public pure returns (uint8[5] memory) {
string[4] memory adaArr = ["This", "is", "an", "array"];
return ([1, 2, 3, 4, 5]);
}
@@ -445,7 +445,7 @@ independent copies will be created::
h(x);
}
- function g(uint[20] y) internal pure {
+ function g(uint[20] memory y) internal pure {
y[2] = 3;
}
@@ -455,10 +455,9 @@ independent copies will be created::
}
The call to ``g(x)`` will not have an effect on ``x`` because it needs
-to create an independent copy of the storage value in memory
-(the default storage location is memory). On the other hand,
-``h(x)`` successfully modifies ``x`` because only a reference
-and not a copy is passed.
+to create an independent copy of the storage value in memory.
+On the other hand, ``h(x)`` successfully modifies ``x`` because only
+a reference and not a copy is passed.
Sometimes, when I try to change the length of an array with ex: ``arrayname.length = 7;`` I get a compiler error ``Value must be an lvalue``. Why?
==================================================================================================================================================
diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst
index b1985426..0ee6c4df 100644
--- a/docs/solidity-by-example.rst
+++ b/docs/solidity-by-example.rst
@@ -66,7 +66,7 @@ of votes.
Proposal[] public proposals;
/// Create a new ballot to choose one of `proposalNames`.
- constructor(bytes32[] proposalNames) public {
+ constructor(bytes32[] memory proposalNames) public {
chairperson = msg.sender;
voters[chairperson].weight = 1;
@@ -452,9 +452,9 @@ high or low invalid bids.
/// correctly blinded invalid bids and for all bids except for
/// the totally highest.
function reveal(
- uint[] _values,
- bool[] _fake,
- bytes32[] _secret
+ uint[] memory _values,
+ bool[] memory _fake,
+ bytes32[] memory _secret
)
public
onlyAfter(biddingEnd)
diff --git a/docs/types.rst b/docs/types.rst
index 16445a34..46e1a869 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -471,11 +471,11 @@ Another example that uses external function types::
}
Request[] requests;
event NewRequest(uint);
- function query(bytes data, function(bytes memory) external callback) public {
+ function query(bytes memory data, function(bytes memory) external callback) public {
requests.push(Request(data, callback));
emit NewRequest(requests.length - 1);
}
- function reply(uint requestID, bytes response) public {
+ function reply(uint requestID, bytes memory response) public {
// Here goes the check that the reply comes from a trusted source
requests[requestID].callback(response);
}
@@ -486,7 +486,7 @@ Another example that uses external function types::
function buySomething() {
oracle.query("USD", this.oracleResponse);
}
- function oracleResponse(bytes response) public {
+ function oracleResponse(bytes memory response) public {
require(
msg.sender == address(oracle),
"Only oracle can call this."
@@ -540,7 +540,7 @@ memory-stored reference type do not create a copy.
uint[] x; // the data location of x is storage
// the data location of memoryArray is memory
- function f(uint[] memoryArray) public {
+ function f(uint[] memory memoryArray) public {
x = memoryArray; // works, copies the whole array to storage
uint[] storage y = x; // works, assigns a pointer, data location of y is storage
y[7]; // fine, returns the 8th element
@@ -557,7 +557,7 @@ memory-stored reference type do not create a copy.
}
function g(uint[] storage storageArray) internal {}
- function h(uint[] memoryArray) public {}
+ function h(uint[] memory memoryArray) public {}
}
Summary
@@ -646,7 +646,7 @@ assigned to a variable right away.
function f() public pure {
g([uint(1), 2, 3]);
}
- function g(uint[3] _data) public pure {
+ function g(uint[3] memory _data) public pure {
// ...
}
}
@@ -713,7 +713,7 @@ Members
bool[2][] m_pairsOfFlags;
// newPairs is stored in memory - the default for function arguments
- function setAllFlagPairs(bool[2][] newPairs) public {
+ function setAllFlagPairs(bool[2][] memory newPairs) public {
// assignment to a storage array replaces the complete array
m_pairsOfFlags = newPairs;
}
@@ -739,7 +739,7 @@ Members
bytes m_byteData;
- function byteArrays(bytes data) public {
+ function byteArrays(bytes memory data) public {
// byte arrays ("bytes") are different as they are stored without padding,
// but can be treated identical to "uint8[]"
m_byteData = data;
@@ -748,11 +748,11 @@ Members
delete m_byteData[2];
}
- function addFlag(bool[2] flag) public returns (uint) {
+ function addFlag(bool[2] memory flag) public returns (uint) {
return m_pairsOfFlags.push(flag);
}
- function createMemoryArray(uint size) public pure returns (bytes) {
+ function createMemoryArray(uint size) public pure returns (bytes memory) {
// Dynamic memory arrays are created using `new`:
uint[2][] memory arrayOfPairs = new uint[2][](size);
// Create a dynamic byte array: