aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-12-10 03:18:37 +0800
committerchriseth <c@ethdev.com>2016-12-12 18:12:12 +0800
commitcc117399281361124714dfd0914fa92e6aec78ef (patch)
tree95cc64e2674f10d9550220083e9f5a55ed57a1d5 /docs
parent2fac1d23a78d898ab78f1a8e347c40ae673c039c (diff)
downloaddexon-solidity-cc117399281361124714dfd0914fa92e6aec78ef.tar.gz
dexon-solidity-cc117399281361124714dfd0914fa92e6aec78ef.tar.zst
dexon-solidity-cc117399281361124714dfd0914fa92e6aec78ef.zip
Documentation.
Diffstat (limited to 'docs')
-rw-r--r--docs/control-structures.rst19
-rw-r--r--docs/types.rst13
2 files changed, 21 insertions, 11 deletions
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index 974a093f..0802c085 100644
--- a/docs/control-structures.rst
+++ b/docs/control-structures.rst
@@ -382,17 +382,18 @@ In the following example, we show how ``throw`` can be used to easily revert an
}
}
-Currently, there are situations, where exceptions happen automatically in Solidity:
+Currently, Solidity automatically generates a runtime exception in the following situations:
1. If you access an array at a too large or negative index (i.e. ``x[i]`` where ``i >= x.length`` or ``i < 0``).
-2. If you access a fixed-length ``bytesN`` at a too large or negative index.
-3. If you call a function via a message call but it does not finish properly (i.e. it runs out of gas, has no matching function, or throws an exception itself), except when a low level operation ``call``, ``send``, ``delegatecall`` or ``callcode`` is used. The low level operations never throw exceptions but indicate failures by returning ``false``.
-4. If you create a contract using the ``new`` keyword but the contract creation does not finish properly (see above for the definition of "not finish properly").
-5. If you divide or modulo by zero (e.g. ``5 / 0`` or ``23 % 0``).
-6. If you convert a value too big or negative into an enum type.
-7. If you perform an external function call targeting a contract that contains no code.
-8. If your contract receives Ether via a public function without ``payable`` modifier (including the constructor and the fallback function).
-9. If your contract receives Ether via a public accessor function.
+1. If you access a fixed-length ``bytesN`` at a too large or negative index.
+1. If you call a function via a message call but it does not finish properly (i.e. it runs out of gas, has no matching function, or throws an exception itself), except when a low level operation ``call``, ``send``, ``delegatecall`` or ``callcode`` is used. The low level operations never throw exceptions but indicate failures by returning ``false``.
+1. If you create a contract using the ``new`` keyword but the contract creation does not finish properly (see above for the definition of "not finish properly").
+1. If you divide or modulo by zero (e.g. ``5 / 0`` or ``23 % 0``).
+1. If you shift by a negative amount.
+1. If you convert a value too big or negative into an enum type.
+1. If you perform an external function call targeting a contract that contains no code.
+1. If your contract receives Ether via a public function without ``payable`` modifier (including the constructor and the fallback function).
+1. If your contract receives Ether via a public accessor function.
Internally, Solidity performs an "invalid jump" when an exception is thrown and thus causes the EVM to revert all changes made to the state. The reason for this is that there is no safe way to continue execution, because an expected effect did not occur. Because we want to retain the atomicity of transactions, the safest thing to do is to revert all changes and make the whole transaction (or at least call) without effect.
diff --git a/docs/types.rst b/docs/types.rst
index 896910ff..59b9771b 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -51,7 +51,7 @@ Integers
Operators:
* Comparisons: ``<=``, ``<``, ``==``, ``!=``, ``>=``, ``>`` (evaluate to ``bool``)
-* Bit operators: ``&``, ``|``, ``^`` (bitwise exclusive or), ``~`` (bitwise negation)
+* Bit operators: ``&``, ``|``, ``^`` (bitwise exclusive or), ``~`` (bitwise negation), ``<<`` (left shift), ``>>`` (right shift)
* Arithmetic operators: ``+``, ``-``, unary ``-``, unary ``+``, ``*``, ``/``, ``%`` (remainder), ``**`` (exponentiation)
Division always truncates (it just maps to the DIV opcode of the EVM), but it does not truncate if both
@@ -59,6 +59,11 @@ operators are :ref:`literals<rational_literals>` (or literal expressions).
Division by zero and modulus with zero throws an exception.
+The result of a shift operation is the type of the left operand. The
+expression ``x << y`` is equivalent to ``x * 2**y`` and ``x >> y`` is
+equivalent to ``x / 2**y``. This means that shifting negative numbers
+sign extends. Shifting by a negative amount throws an exception.
+
.. index:: address, balance, send, call, callcode, delegatecall
.. _address:
@@ -136,9 +141,13 @@ Fixed-size byte arrays
Operators:
* Comparisons: ``<=``, ``<``, ``==``, ``!=``, ``>=``, ``>`` (evaluate to ``bool``)
-* Bit operators: ``&``, ``|``, ``^`` (bitwise exclusive or), ``~`` (bitwise negation)
+* Bit operators: ``&``, ``|``, ``^`` (bitwise exclusive or), ``~`` (bitwise negation), ``<<`` (left shift), ``>>`` (right shift)
* Index access: If ``x`` is of type ``bytesI``, then ``x[k]`` for ``0 <= k < I`` returns the ``k`` th byte (read-only).
+The shifting operator wors with any integer type as right operand (bit will
+return the type of the left operand). Shifting by a negative amount will cause
+a runtime exception.
+
Members:
* ``.length`` yields the fixed length of the byte array (read-only).