From dfe55a929d78657544e744f12c13d73983671b7f Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 20 Jul 2016 15:29:28 -0400 Subject: [PATCH 1/8] Create order of precedence table --- docs/miscellaneous.rst | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 825be2ce1..55582eedb 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -149,6 +149,64 @@ Tips and Tricks Cheatsheet ********** +.. index:: precedence + +Order of Precedence of Operators +================================ + +The following is the order of precedence for operators, listed in order of evaluation. + ++------------+-------------------------------------+--------------------------------------------+ +| Precedence | Description | Operator | ++============+=====================================+============================================+ +| *1* | Postfix increment and decrement | ``++``, ``--`` | ++ +-------------------------------------+--------------------------------------------+ +| | Function-like call | ``()`` | ++ +-------------------------------------+--------------------------------------------+ +| | Array subscripting | ``[]`` | ++ +-------------------------------------+--------------------------------------------+ +| | Member access | ``.`` | ++ +-------------------------------------+--------------------------------------------+ +| | Parentheses | ``()`` | ++------------+-------------------------------------+--------------------------------------------+ +| *2* | Prefix increment and decrement | ``++``, ``--`` | ++ +-------------------------------------+--------------------------------------------+ +| | Unary plus and minus | ``+``, ``-`` | ++ +-------------------------------------+--------------------------------------------+ +| | Logical NOT | ``!`` | ++ +-------------------------------------+--------------------------------------------+ +| | Bitwise NOT | ``~`` | ++------------+-------------------------------------+--------------------------------------------+ +| *3* | Exponentiation | ``**`` | ++------------+-------------------------------------+--------------------------------------------+ +| *4* | Multiplication, division and modulo | ``*``, ``/``, ``%`` | ++------------+-------------------------------------+--------------------------------------------+ +| *5* | Addition and subtraction | ``+``, ``-`` | ++------------+-------------------------------------+--------------------------------------------+ +| *6* | Bitwise shift operators | ``<<``, ``>>``, ``>>>`` | ++------------+-------------------------------------+--------------------------------------------+ +| *7* | Bitwise AND | ``&`` | ++------------+-------------------------------------+--------------------------------------------+ +| *8* | Bitwise XOR | ``^`` | ++------------+-------------------------------------+--------------------------------------------+ +| *9* | Bitwise OR | ``|`` | ++------------+-------------------------------------+--------------------------------------------+ +| *10* | Inequality operators | ``<``, ``>``, ``<=``, ``>=`` | ++------------+-------------------------------------+--------------------------------------------+ +| *11* | Equality operators | ``==``, ``!=`` | ++------------+-------------------------------------+--------------------------------------------+ +| *12* | Logical AND | ``&&`` | ++------------+-------------------------------------+--------------------------------------------+ +| *13* | Logical OR | ``||`` | ++------------+-------------------------------------+--------------------------------------------+ +| *14* | Ternary operator | `` ? : `` | ++------------+-------------------------------------+--------------------------------------------+ +| *15* | Assignment operators | ``=``, ``|=``, ``^=``, ``&=``, ``<<=``, | +| | | ``/=``, ``%=`` | ++------------+-------------------------------------+--------------------------------------------+ +| *16* | Comma operator | ``,`` | ++------------+-------------------------------------+--------------------------------------------+ + .. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, sha3, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send Global Variables From 5d09211d50c4284d936ef725b7d4dd693aef620a Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 20 Jul 2016 15:35:38 -0400 Subject: [PATCH 2/8] Add link to operator table --- docs/miscellaneous.rst | 2 ++ docs/types.rst | 3 +++ 2 files changed, 5 insertions(+) diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 55582eedb..83bbb8288 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -151,6 +151,8 @@ Cheatsheet .. index:: precedence +.. _order: + Order of Precedence of Operators ================================ diff --git a/docs/types.rst b/docs/types.rst index 50e86ed06..d7681ee54 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -12,6 +12,9 @@ see :ref:`type-deduction` below) at compile-time. Solidity provides several elementary types which can be combined to form complex types. +In addition, types can interact with each other in expressions containing +operators. For a quick reference of the various operators, see :ref:`order`. + .. index:: ! value type, ! type;value Value Types From 1ec74f8cc4b952331b3003e2326eb90aa7fc2e55 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Tue, 26 Jul 2016 13:54:17 -0400 Subject: [PATCH 3/8] Remove comma operator --- docs/miscellaneous.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 83bbb8288..46867ab55 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -206,8 +206,6 @@ The following is the order of precedence for operators, listed in order of evalu | *15* | Assignment operators | ``=``, ``|=``, ``^=``, ``&=``, ``<<=``, | | | | ``/=``, ``%=`` | +------------+-------------------------------------+--------------------------------------------+ -| *16* | Comma operator | ``,`` | -+------------+-------------------------------------+--------------------------------------------+ .. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, sha3, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send @@ -265,4 +263,3 @@ Modifiers - ``constant`` for functions: Disallows modification of state - this is not enforced yet. - ``anonymous`` for events: Does not store event signature as topic. - ``indexed`` for event parameters: Stores the parameter as topic. - From ca5e6a6bd4734483c2ead97562286f9c32033bc0 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Tue, 26 Jul 2016 14:01:01 -0400 Subject: [PATCH 4/8] Fix assignment operators --- docs/miscellaneous.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 46867ab55..dd4bb9b01 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -204,6 +204,7 @@ The following is the order of precedence for operators, listed in order of evalu | *14* | Ternary operator | `` ? : `` | +------------+-------------------------------------+--------------------------------------------+ | *15* | Assignment operators | ``=``, ``|=``, ``^=``, ``&=``, ``<<=``, | +| | | ``>>=``, ``>>>=``, ``+=``, ``-=``, ``*=``, | | | | ``/=``, ``%=`` | +------------+-------------------------------------+--------------------------------------------+ From 71438157ce8455cbc14939b95e1a28236f10ed46 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Jul 2016 10:26:39 -0400 Subject: [PATCH 5/8] Revert "Remove comma operator" This reverts commit 1ec74f8cc4b952331b3003e2326eb90aa7fc2e55. --- docs/miscellaneous.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index dd4bb9b01..61dc9a166 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -207,6 +207,8 @@ The following is the order of precedence for operators, listed in order of evalu | | | ``>>=``, ``>>>=``, ``+=``, ``-=``, ``*=``, | | | | ``/=``, ``%=`` | +------------+-------------------------------------+--------------------------------------------+ +| *16* | Comma operator | ``,`` | ++------------+-------------------------------------+--------------------------------------------+ .. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, sha3, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send @@ -264,3 +266,4 @@ Modifiers - ``constant`` for functions: Disallows modification of state - this is not enforced yet. - ``anonymous`` for events: Does not store event signature as topic. - ``indexed`` for event parameters: Stores the parameter as topic. + From 8bf96b1c43febe3c082a9d60af6ebdc44d4eca68 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Jul 2016 10:30:20 -0400 Subject: [PATCH 6/8] Remove >>> and >>>= operators --- docs/miscellaneous.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 61dc9a166..e56b1d245 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -185,7 +185,7 @@ The following is the order of precedence for operators, listed in order of evalu +------------+-------------------------------------+--------------------------------------------+ | *5* | Addition and subtraction | ``+``, ``-`` | +------------+-------------------------------------+--------------------------------------------+ -| *6* | Bitwise shift operators | ``<<``, ``>>``, ``>>>`` | +| *6* | Bitwise shift operators | ``<<``, ``>>`` | +------------+-------------------------------------+--------------------------------------------+ | *7* | Bitwise AND | ``&`` | +------------+-------------------------------------+--------------------------------------------+ @@ -204,8 +204,8 @@ The following is the order of precedence for operators, listed in order of evalu | *14* | Ternary operator | `` ? : `` | +------------+-------------------------------------+--------------------------------------------+ | *15* | Assignment operators | ``=``, ``|=``, ``^=``, ``&=``, ``<<=``, | -| | | ``>>=``, ``>>>=``, ``+=``, ``-=``, ``*=``, | -| | | ``/=``, ``%=`` | +| | | ``>>=``, ``+=``, ``-=``, ``*=``, ``/=``, | +| | | ``%=`` | +------------+-------------------------------------+--------------------------------------------+ | *16* | Comma operator | ``,`` | +------------+-------------------------------------+--------------------------------------------+ From 7a203241420fa266cff5640acdc9015f04804901 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 28 Jul 2016 15:16:52 -0400 Subject: [PATCH 7/8] Link to order of precedence table --- docs/control-structures.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/control-structures.rst b/docs/control-structures.rst index f30a5bddc..9d7ebeacf 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -113,7 +113,7 @@ The evaluation order of expressions is not specified (more formally, the order in which the children of one node in the expression tree are evaluated is not specified, but they are of course evaluated before the node itself). It is only guaranteed that statements are executed in order and short-circuiting for -boolean expressions is done. +boolean expressions is done. See :ref:`order` for more information. .. index:: ! assignment From 5687beb424663871d3d59c6bd12d71fff79d5200 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 28 Jul 2016 15:25:58 -0400 Subject: [PATCH 8/8] Add unary operations to the table --- docs/miscellaneous.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index e56b1d245..26901946a 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -175,6 +175,8 @@ The following is the order of precedence for operators, listed in order of evalu + +-------------------------------------+--------------------------------------------+ | | Unary plus and minus | ``+``, ``-`` | + +-------------------------------------+--------------------------------------------+ +| | Unary operations | ``after``, ``delete`` | ++ +-------------------------------------+--------------------------------------------+ | | Logical NOT | ``!`` | + +-------------------------------------+--------------------------------------------+ | | Bitwise NOT | ``~`` |