diff options
-rw-r--r-- | docs/conf.py | 2 | ||||
-rw-r--r-- | docs/contracts.rst | 10 | ||||
-rw-r--r-- | docs/grammar.txt | 2 | ||||
-rw-r--r-- | docs/solidity-by-example.rst | 12 | ||||
-rw-r--r-- | libsolidity/ast/Types.cpp | 28 | ||||
-rw-r--r-- | libsolidity/ast/Types.h | 3 |
6 files changed, 25 insertions, 32 deletions
diff --git a/docs/conf.py b/docs/conf.py index ca8c0fec..3bbee671 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -50,7 +50,7 @@ master_doc = 'index' # General information about the project. project = 'Solidity' -copyright = '2016-2017, Ethereum' +copyright = '2016-2018, Ethereum' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff --git a/docs/contracts.rst b/docs/contracts.rst index 17eb23f7..5c298274 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -1066,12 +1066,15 @@ Multiple Inheritance and Linearization Languages that allow multiple inheritance have to deal with several problems. One is the `Diamond Problem <https://en.wikipedia.org/wiki/Multiple_inheritance#The_diamond_problem>`_. -Solidity follows the path of Python and uses "`C3 Linearization <https://en.wikipedia.org/wiki/C3_linearization>`_" +Solidity is similar to Python in that it uses "`C3 Linearization <https://en.wikipedia.org/wiki/C3_linearization>`_" to force a specific order in the DAG of base classes. This results in the desirable property of monotonicity but disallows some inheritance graphs. Especially, the order in which the base classes are given in the ``is`` directive is -important. In the following code, Solidity will give the +important: You have to list the direct base contracts +in the order from "most base-like" to "most derived". +Note that this order is different from the one used in Python. +In the following code, Solidity will give the error "Linearization of inheritance graph impossible". :: @@ -1089,9 +1092,6 @@ The reason for this is that ``C`` requests ``X`` to override ``A`` requests to override ``X``, which is a contradiction that cannot be resolved. -A simple rule to remember is to specify the base classes in -the order from "most base-like" to "most derived". - Inheriting Different Kinds of Members of the Same Name ====================================================== diff --git a/docs/grammar.txt b/docs/grammar.txt index b4ca5ca9..565db9a4 100644 --- a/docs/grammar.txt +++ b/docs/grammar.txt @@ -16,7 +16,7 @@ ContractPart = StateVariableDeclaration | UsingForDeclaration InheritanceSpecifier = UserDefinedTypeName ( '(' Expression ( ',' Expression )* ')' )? -StateVariableDeclaration = TypeName ( 'public' | 'internal' | 'private' | 'constant' )? Identifier ('=' Expression)? ';' +StateVariableDeclaration = TypeName ( 'public' | 'internal' | 'private' | 'constant' )* Identifier ('=' Expression)? ';' UsingForDeclaration = 'using' Identifier 'for' ('*' | TypeName) ';' StructDefinition = 'struct' Identifier '{' ( VariableDeclaration ';' (VariableDeclaration ';')* ) '}' diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst index 546767e4..f6038f7d 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`. - function Ballot(bytes32[] proposalNames) public { + constructor(bytes32[] proposalNames) public { chairperson = msg.sender; voters[chairperson].weight = 1; @@ -256,7 +256,7 @@ activate themselves. /// Create a simple auction with `_biddingTime` /// seconds bidding time on behalf of the /// beneficiary address `_beneficiary`. - function SimpleAuction( + constructor( uint _biddingTime, address _beneficiary ) public { @@ -418,7 +418,7 @@ high or low invalid bids. modifier onlyBefore(uint _time) { require(now < _time); _; } modifier onlyAfter(uint _time) { require(now > _time); _; } - function BlindAuction( + constructor( uint _biddingTime, uint _revealTime, address _beneficiary @@ -553,7 +553,7 @@ Safe Remote Purchase // Ensure that `msg.value` is an even number. // Division will truncate if it is an odd number. // Check via multiplication that it wasn't an odd number. - function Purchase() public payable { + constructor() public payable { seller = msg.sender; value = msg.value / 2; require((2 * value) == msg.value, "Value has to be even."); @@ -602,7 +602,7 @@ Safe Remote Purchase { emit Aborted(); state = State.Inactive; - seller.transfer(this.balance); + seller.transfer(address(this).balance); } /// Confirm the purchase as buyer. @@ -637,7 +637,7 @@ Safe Remote Purchase // block the refund - the withdraw pattern should be used. buyer.transfer(value); - seller.transfer(this.balance); + seller.transfer(address(this).balance); } } diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 425e5045..60b4d726 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -627,8 +627,7 @@ bool FixedPointType::isImplicitlyConvertibleTo(Type const& _convertTo) const bool FixedPointType::isExplicitlyConvertibleTo(Type const& _convertTo) const { return _convertTo.category() == category() || - _convertTo.category() == Category::Integer || - _convertTo.category() == Category::FixedBytes; + (_convertTo.category() == Category::Integer && !dynamic_cast<IntegerType const&>(_convertTo).isAddress()); } TypePointer FixedPointType::unaryOperatorResult(Token::Value _operator) const @@ -682,13 +681,7 @@ bigint FixedPointType::minIntegerValue() const TypePointer FixedPointType::binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const { - if ( - _other->category() != Category::RationalNumber && - _other->category() != category() && - _other->category() != Category::Integer - ) - return TypePointer(); - auto commonType = Type::commonType(shared_from_this(), _other); //might be fixed point or integer + auto commonType = Type::commonType(shared_from_this(), _other); if (!commonType) return TypePointer(); @@ -696,19 +689,16 @@ TypePointer FixedPointType::binaryOperatorResult(Token::Value _operator, TypePoi // All fixed types can be compared if (Token::isCompareOp(_operator)) return commonType; - if (Token::isBitOp(_operator) || Token::isBooleanOp(_operator)) + if (Token::isBitOp(_operator) || Token::isBooleanOp(_operator) || _operator == Token::Exp) return TypePointer(); - if (auto fixType = dynamic_pointer_cast<FixedPointType const>(commonType)) - { - if (Token::Exp == _operator) - return TypePointer(); - } - else if (auto intType = dynamic_pointer_cast<IntegerType const>(commonType)) - if (intType->isAddress()) - return TypePointer(); return commonType; } +std::shared_ptr<IntegerType> FixedPointType::asIntegerType() const +{ + return std::make_shared<IntegerType>(numBits(), isSigned() ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned); +} + tuple<bool, rational> RationalNumberType::parseRational(string const& _value) { rational value; @@ -1148,7 +1138,7 @@ u256 RationalNumberType::literalValue(Literal const*) const auto fixed = fixedPointType(); solAssert(fixed, ""); int fractionalDigits = fixed->fractionalDigits(); - shiftedValue = (m_value.numerator() / m_value.denominator()) * pow(bigint(10), fractionalDigits); + shiftedValue = m_value.numerator() * pow(bigint(10), fractionalDigits) / m_value.denominator(); } // we ignore the literal and hope that the type was correctly determined diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 345f84a1..b41b2235 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -396,6 +396,9 @@ public: /// smallest value in general. bigint minIntegerValue() const; + /// @returns the smallest integer type that can hold this type with fractional parts shifted to integers. + std::shared_ptr<IntegerType> asIntegerType() const; + private: int m_totalBits; int m_fractionalDigits; |