diff options
author | chriseth <c@ethdev.com> | 2016-05-12 18:30:10 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-05-12 18:30:10 +0800 |
commit | 1ab0f25dffe19f2cc9e1a0e2fa03a1091679f5a0 (patch) | |
tree | 267d5df3091710f7a1c3b54ddb8fcac5ab794015 /libsolidity/codegen | |
parent | 9e36bdda8a9552f1885e0a63a85db588623b39b2 (diff) | |
parent | d4206b7cd0bb0b8a3364c29fe097db035f308388 (diff) | |
download | dexon-solidity-1ab0f25dffe19f2cc9e1a0e2fa03a1091679f5a0.tar dexon-solidity-1ab0f25dffe19f2cc9e1a0e2fa03a1091679f5a0.tar.gz dexon-solidity-1ab0f25dffe19f2cc9e1a0e2fa03a1091679f5a0.tar.bz2 dexon-solidity-1ab0f25dffe19f2cc9e1a0e2fa03a1091679f5a0.tar.lz dexon-solidity-1ab0f25dffe19f2cc9e1a0e2fa03a1091679f5a0.tar.xz dexon-solidity-1ab0f25dffe19f2cc9e1a0e2fa03a1091679f5a0.tar.zst dexon-solidity-1ab0f25dffe19f2cc9e1a0e2fa03a1091679f5a0.zip |
Merge pull request #402 from VoR0220/fixedDataType
Fixed Type initial PR
Diffstat (limited to 'libsolidity/codegen')
-rw-r--r-- | libsolidity/codegen/CompilerUtils.cpp | 26 | ||||
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 15 | ||||
-rw-r--r-- | libsolidity/codegen/LValue.cpp | 6 |
3 files changed, 35 insertions, 12 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 36ed480e..e35f3374 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -343,12 +343,14 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp case Type::Category::Enum: solAssert(targetTypeCategory == Type::Category::Integer || targetTypeCategory == Type::Category::Enum, ""); break; + case Type::Category::FixedPoint: + solAssert(false, "Not yet implemented - FixedPointType."); case Type::Category::Integer: case Type::Category::Contract: - case Type::Category::IntegerConstant: + case Type::Category::RationalNumber: if (targetTypeCategory == Type::Category::FixedBytes) { - solAssert(stackTypeCategory == Type::Category::Integer || stackTypeCategory == Type::Category::IntegerConstant, + solAssert(stackTypeCategory == Type::Category::Integer || stackTypeCategory == Type::Category::RationalNumber, "Invalid conversion to FixedBytesType requested."); // conversion from bytes to string. no need to clean the high bit // only to shift left because of opposite alignment @@ -361,17 +363,33 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp else if (targetTypeCategory == Type::Category::Enum) // just clean convertType(_typeOnStack, *_typeOnStack.mobileType(), true); + else if (targetTypeCategory == Type::Category::FixedPoint) + { + solAssert( + stackTypeCategory == Type::Category::Integer || + stackTypeCategory == Type::Category::RationalNumber || + stackTypeCategory == Type::Category::FixedPoint, + "Invalid conversion to FixedMxNType requested." + ); + //shift all integer bits onto the left side of the fixed type + FixedPointType const& targetFixedPointType = dynamic_cast<FixedPointType const&>(_targetType); + if (auto typeOnStack = dynamic_cast<IntegerType const*>(&_typeOnStack)) + if (targetFixedPointType.integerBits() > typeOnStack->numBits()) + cleanHigherOrderBits(*typeOnStack); + solAssert(false, "Not yet implemented - FixedPointType."); + } else { solAssert(targetTypeCategory == Type::Category::Integer || targetTypeCategory == Type::Category::Contract, ""); IntegerType addressType(0, IntegerType::Modifier::Address); IntegerType const& targetType = targetTypeCategory == Type::Category::Integer ? dynamic_cast<IntegerType const&>(_targetType) : addressType; - if (stackTypeCategory == Type::Category::IntegerConstant) + if (stackTypeCategory == Type::Category::RationalNumber) { - IntegerConstantType const& constType = dynamic_cast<IntegerConstantType const&>(_typeOnStack); + RationalNumberType const& constType = dynamic_cast<RationalNumberType const&>(_typeOnStack); // We know that the stack is clean, we only have to clean for a narrowing conversion // where cleanup is forced. + solAssert(!constType.isFractional(), "Not yet implemented - FixedPointType."); if (targetType.numBits() < constType.integerType()->numBits() && _cleanupNeeded) cleanHigherOrderBits(targetType); } diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index ab02e0b5..a01e306e 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -281,11 +281,7 @@ bool ExpressionCompiler::visit(TupleExpression const& _tuple) bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation) { CompilerContext::LocationSetter locationSetter(m_context, _unaryOperation); - //@todo type checking and creating code for an operator should be in the same place: - // the operator should know how to convert itself and to which types it applies, so - // put this code together with "Type::acceptsBinary/UnaryOperator" into a class that - // represents the operator - if (_unaryOperation.annotation().type->category() == Type::Category::IntegerConstant) + if (_unaryOperation.annotation().type->category() == Type::Category::RationalNumber) { m_context << _unaryOperation.annotation().type->literalValue(nullptr); return false; @@ -360,7 +356,7 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation) if (c_op == Token::And || c_op == Token::Or) // special case: short-circuiting appendAndOrOperatorCode(_binaryOperation); - else if (commonType.category() == Type::Category::IntegerConstant) + else if (commonType.category() == Type::Category::RationalNumber) m_context << commonType.literalValue(nullptr); else { @@ -370,7 +366,7 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation) // for commutative operators, push the literal as late as possible to allow improved optimization auto isLiteral = [](Expression const& _e) { - return dynamic_cast<Literal const*>(&_e) || _e.annotation().type->category() == Type::Category::IntegerConstant; + return dynamic_cast<Literal const*>(&_e) || _e.annotation().type->category() == Type::Category::RationalNumber; }; bool swap = m_optimize && Token::isCommutativeOp(c_op) && isLiteral(rightExpression) && !isLiteral(leftExpression); if (swap) @@ -1225,7 +1221,7 @@ void ExpressionCompiler::endVisit(Literal const& _literal) switch (type->category()) { - case Type::Category::IntegerConstant: + case Type::Category::RationalNumber: case Type::Category::Bool: m_context << type->literalValue(&_literal); break; @@ -1306,6 +1302,9 @@ void ExpressionCompiler::appendArithmeticOperatorCode(Token::Value _operator, Ty IntegerType const& type = dynamic_cast<IntegerType const&>(_type); bool const c_isSigned = type.isSigned(); + if (_type.category() == Type::Category::FixedPoint) + solAssert(false, "Not yet implemented - FixedPointType."); + switch (_operator) { case Token::Add: diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index fcadd2ff..ea8bc1ba 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -179,6 +179,9 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const m_context << Instruction::SWAP1 << Instruction::SLOAD << Instruction::SWAP1 << u256(0x100) << Instruction::EXP << Instruction::SWAP1 << Instruction::DIV; + if (m_dataType->category() == Type::Category::FixedPoint) + // implementation should be very similar to the integer case. + solAssert(false, "Not yet implemented - FixedPointType."); if (m_dataType->category() == Type::Category::FixedBytes) m_context << (u256(0x1) << (256 - 8 * m_dataType->storageBytes())) << Instruction::MUL; else if ( @@ -239,6 +242,9 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc << Instruction::DUP2 << Instruction::MUL << Instruction::DIV; + else if (m_dataType->category() == Type::Category::FixedPoint) + // implementation should be very similar to the integer case. + solAssert(false, "Not yet implemented - FixedPointType."); m_context << Instruction::MUL << Instruction::OR; // stack: value storage_ref updated_value m_context << Instruction::SWAP1 << Instruction::SSTORE; |