Avoid switch fallthrough in ExpressionCompiler

This commit is contained in:
Alex Beregszaszi 2017-09-19 19:02:16 +01:00
parent 3e5d81578a
commit 74972f5fa6

View File

@ -1014,41 +1014,46 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
switch (_memberAccess.expression().annotation().type->category()) switch (_memberAccess.expression().annotation().type->category())
{ {
case Type::Category::Contract: case Type::Category::Contract:
case Type::Category::Integer:
{ {
bool alsoSearchInteger = false; bool alsoSearchInteger = false;
ContractType const& type = dynamic_cast<ContractType const&>(*_memberAccess.expression().annotation().type); if (_memberAccess.expression().annotation().type->category() == Type::Category::Contract)
if (type.isSuper())
{ {
solAssert(!!_memberAccess.annotation().referencedDeclaration, "Referenced declaration not resolved."); ContractType const& type = dynamic_cast<ContractType const&>(*_memberAccess.expression().annotation().type);
utils().pushCombinedFunctionEntryLabel(m_context.superFunction( if (type.isSuper())
dynamic_cast<FunctionDefinition const&>(*_memberAccess.annotation().referencedDeclaration),
type.contractDefinition()
));
}
else
{
// ordinary contract type
if (Declaration const* declaration = _memberAccess.annotation().referencedDeclaration)
{ {
u256 identifier; solAssert(!!_memberAccess.annotation().referencedDeclaration, "Referenced declaration not resolved.");
if (auto const* variable = dynamic_cast<VariableDeclaration const*>(declaration)) utils().pushCombinedFunctionEntryLabel(m_context.superFunction(
identifier = FunctionType(*variable).externalIdentifier(); dynamic_cast<FunctionDefinition const&>(*_memberAccess.annotation().referencedDeclaration),
else if (auto const* function = dynamic_cast<FunctionDefinition const*>(declaration)) type.contractDefinition()
identifier = FunctionType(*function).externalIdentifier(); ));
else
solAssert(false, "Contract member is neither variable nor function.");
utils().convertType(type, IntegerType(0, IntegerType::Modifier::Address), true);
m_context << identifier;
} }
else else
// not found in contract, search in members inherited from address {
alsoSearchInteger = true; // ordinary contract type
if (Declaration const* declaration = _memberAccess.annotation().referencedDeclaration)
{
u256 identifier;
if (auto const* variable = dynamic_cast<VariableDeclaration const*>(declaration))
identifier = FunctionType(*variable).externalIdentifier();
else if (auto const* function = dynamic_cast<FunctionDefinition const*>(declaration))
identifier = FunctionType(*function).externalIdentifier();
else
solAssert(false, "Contract member is neither variable nor function.");
utils().convertType(type, IntegerType(0, IntegerType::Modifier::Address), true);
m_context << identifier;
}
else
// not found in contract, search in members inherited from address
alsoSearchInteger = true;
}
} }
else
alsoSearchInteger = true;
if (!alsoSearchInteger) if (!alsoSearchInteger)
break; break;
}
// fall-through
case Type::Category::Integer:
if (member == "balance") if (member == "balance")
{ {
utils().convertType( utils().convertType(
@ -1067,6 +1072,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
else else
solAssert(false, "Invalid member access to integer"); solAssert(false, "Invalid member access to integer");
break; break;
}
case Type::Category::Function: case Type::Category::Function:
if (member == "selector") if (member == "selector")
{ {