Merge pull request #2727 from ethereum/simplify-types

Simplify if/else statements in Types
This commit is contained in:
chriseth 2017-08-11 11:46:16 +02:00 committed by GitHub
commit a7a9ed4718

View File

@ -525,20 +525,21 @@ bool FixedPointType::isExplicitlyConvertibleTo(Type const& _convertTo) const
TypePointer FixedPointType::unaryOperatorResult(Token::Value _operator) const TypePointer FixedPointType::unaryOperatorResult(Token::Value _operator) const
{ {
switch(_operator)
{
case Token::Delete:
// "delete" is ok for all fixed types // "delete" is ok for all fixed types
if (_operator == Token::Delete)
return make_shared<TupleType>(); return make_shared<TupleType>();
case Token::Add:
case Token::Sub:
case Token::Inc:
case Token::Dec:
// for fixed, we allow +, -, ++ and -- // for fixed, we allow +, -, ++ and --
else if (
_operator == Token::Add ||
_operator == Token::Sub ||
_operator == Token::Inc ||
_operator == Token::Dec
)
return shared_from_this(); return shared_from_this();
else default:
return TypePointer(); return TypePointer();
} }
}
bool FixedPointType::operator==(Type const& _other) const bool FixedPointType::operator==(Type const& _other) const
{ {
@ -2355,14 +2356,26 @@ unsigned FunctionType::sizeOnStack() const
} }
unsigned size = 0; unsigned size = 0;
if (kind == Kind::External || kind == Kind::CallCode || kind == Kind::DelegateCall)
switch(kind)
{
case Kind::External:
case Kind::CallCode:
case Kind::DelegateCall:
size = 2; size = 2;
else if (kind == Kind::BareCall || kind == Kind::BareCallCode || kind == Kind::BareDelegateCall) break;
size = 1; case Kind::BareCall:
else if (kind == Kind::Internal) case Kind::BareCallCode:
size = 1; case Kind::BareDelegateCall:
else if (kind == Kind::ArrayPush || kind == Kind::ByteArrayPush) case Kind::Internal:
case Kind::ArrayPush:
case Kind::ByteArrayPush:
size = 1; size = 1;
break;
default:
break;
}
if (m_gasSet) if (m_gasSet)
size++; size++;
if (m_valueSet) if (m_valueSet)