Skip to content

Commit

Permalink
Remove unused tests and add asserts for not implemented parts in code…
Browse files Browse the repository at this point in the history
… generation.

quick fix on christian's rational

change so that ubuntu will stop yelling

be more specific with rational declaration for Windows sake

rational in namespace correction for windows
  • Loading branch information
chriseth authored and VoR0220 committed May 10, 2016
1 parent 6564052 commit d4206b7
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 37 deletions.
2 changes: 2 additions & 0 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
solAssert(!var.typeName(), "");
var.annotation().type = valueComponentType->mobileType();
if (!var.annotation().type)
{
if (valueComponentType->category() == Type::Category::RationalNumber)
fatalTypeError(
_statement.initialValue()->location(),
Expand All @@ -783,6 +784,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
);
else
solAssert(false, "");
}
var.accept(*this);
}
else
Expand Down
5 changes: 2 additions & 3 deletions libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
using namespace std;
using namespace dev;
using namespace dev::solidity;
using rational = boost::rational<bigint>;

void StorageOffsets::computeOffsets(TypePointers const& _types)
{
Expand Down Expand Up @@ -769,8 +768,8 @@ shared_ptr<FixedPointType const> RationalNumberType::fixedPointType() const
unsigned fractionalBits = 0;
rational value = abs(m_value); // We care about the sign later.
rational maxValue = negative ?
rational(bigint(1) << 255):
rational((bigint(1) << 256) - 1);
rational(bigint(1) << 255, 1):
rational((bigint(1) << 256) - 1, 1);

while (value * 0x100 <= maxValue && value.denominator() != 1 && fractionalBits < 256)
{
Expand Down
4 changes: 2 additions & 2 deletions libsolidity/ast/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FunctionType; // forward
using TypePointer = std::shared_ptr<Type const>;
using FunctionTypePointer = std::shared_ptr<FunctionType const>;
using TypePointers = std::vector<TypePointer>;
using rational = boost::rational<bigint>;
using rational = boost::rational<dev::bigint>;


enum class DataLocation { Storage, CallData, Memory };
Expand Down Expand Up @@ -389,7 +389,7 @@ class RationalNumberType: public Type
/// If the integer part does not fit, returns an empty pointer.
std::shared_ptr<FixedPointType const> fixedPointType() const;

/// @returns true iff the value is not an integer.
/// @returns true if the value is not an integer.
bool isFractional() const { return m_value.denominator() != 1; }

private:
Expand Down
7 changes: 4 additions & 3 deletions libsolidity/codegen/CompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,11 @@ 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::RationalNumber:
case Type::Category::FixedPoint:
if (targetTypeCategory == Type::Category::FixedBytes)
{
solAssert(stackTypeCategory == Type::Category::Integer || stackTypeCategory == Type::Category::RationalNumber,
Expand Down Expand Up @@ -375,8 +376,7 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
if (auto typeOnStack = dynamic_cast<IntegerType const*>(&_typeOnStack))
if (targetFixedPointType.integerBits() > typeOnStack->numBits())
cleanHigherOrderBits(*typeOnStack);
//need m_context call here

solAssert(false, "Not yet implemented - FixedPointType.");
}
else
{
Expand All @@ -389,6 +389,7 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
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);
}
Expand Down
7 changes: 3 additions & 4 deletions libsolidity/codegen/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,6 @@ 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::RationalNumber)
{
m_context << _unaryOperation.annotation().type->literalValue(nullptr);
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions libsolidity/codegen/LValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,16 @@ 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 (
m_dataType->category() == Type::Category::Integer &&
dynamic_cast<IntegerType const&>(*m_dataType).isSigned()
)
m_context << u256(m_dataType->storageBytes() - 1) << Instruction::SIGNEXTEND;
//need something here for Fixed...guidance would be nice
else
m_context << ((u256(0x1) << (8 * m_dataType->storageBytes())) - 1) << Instruction::AND;
}
Expand Down Expand Up @@ -240,9 +242,10 @@ 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;
//else if (m_dataType->category() == Type::Category::Fixed)
//trying to figure out what this does...going to require some more assistance
// stack: value storage_ref updated_value
m_context << Instruction::SWAP1 << Instruction::SSTORE;
if (_move)
Expand Down
22 changes: 0 additions & 22 deletions test/libsolidity/SolidityEndToEndTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6634,28 +6634,6 @@ BOOST_AUTO_TEST_CASE(delete_on_array_of_structs)

}

/*BOOST_AUTO_TEST_CASE(fixed_data_type)
{
char const* sourceCode = R"(
contract C {
fixed public pi = 3.141592;
}
)";
compileAndRun(sourceCode, 0, "C");
}
BOOST_AUTO_TEST_CASE(fixed_data_type_expression)
{
char const* sourceCode = R"(
contract C {
function f(fixed a) returns (fixed) {
return (a + 3);
}
}
)";
compileAndRun(sourceCode, 0, "C");
}*/

BOOST_AUTO_TEST_CASE(internal_library_function)
{
// tests that internal library functions can be called from outside
Expand Down

0 comments on commit d4206b7

Please sign in to comment.