mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2645 from ethereum/asserts
Use solAssert where possible
This commit is contained in:
commit
89fadd6935
@ -797,11 +797,11 @@ public:
|
|||||||
Declaration(SourceLocation(), std::make_shared<ASTString>(_name)), m_type(_type) {}
|
Declaration(SourceLocation(), std::make_shared<ASTString>(_name)), m_type(_type) {}
|
||||||
virtual void accept(ASTVisitor&) override
|
virtual void accept(ASTVisitor&) override
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("MagicVariableDeclaration used inside real AST."));
|
solAssert(false, "MagicVariableDeclaration used inside real AST.");
|
||||||
}
|
}
|
||||||
virtual void accept(ASTConstVisitor&) const override
|
virtual void accept(ASTConstVisitor&) const override
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("MagicVariableDeclaration used inside real AST."));
|
solAssert(false, "MagicVariableDeclaration used inside real AST.");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual TypePointer type() const override { return m_type; }
|
virtual TypePointer type() const override { return m_type; }
|
||||||
|
@ -743,7 +743,7 @@ string ASTJsonConverter::visibility(Declaration::Visibility const& _visibility)
|
|||||||
case Declaration::Visibility::External:
|
case Declaration::Visibility::External:
|
||||||
return "external";
|
return "external";
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown declaration visibility."));
|
solAssert(false, "Unknown declaration visibility.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -758,7 +758,7 @@ string ASTJsonConverter::location(VariableDeclaration::Location _location)
|
|||||||
case VariableDeclaration::Location::Memory:
|
case VariableDeclaration::Location::Memory:
|
||||||
return "memory";
|
return "memory";
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown declaration location."));
|
solAssert(false, "Unknown declaration location.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -773,7 +773,7 @@ string ASTJsonConverter::contractKind(ContractDefinition::ContractKind _kind)
|
|||||||
case ContractDefinition::ContractKind::Library:
|
case ContractDefinition::ContractKind::Library:
|
||||||
return "library";
|
return "library";
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown kind of contract."));
|
solAssert(false, "Unknown kind of contract.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -788,7 +788,7 @@ string ASTJsonConverter::functionCallKind(FunctionCallKind _kind)
|
|||||||
case FunctionCallKind::StructConstructorCall:
|
case FunctionCallKind::StructConstructorCall:
|
||||||
return "structConstructorCall";
|
return "structConstructorCall";
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown kind of function call ."));
|
solAssert(false, "Unknown kind of function call.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -804,7 +804,7 @@ string ASTJsonConverter::literalTokenKind(Token::Value _token)
|
|||||||
case dev::solidity::Token::FalseLiteral:
|
case dev::solidity::Token::FalseLiteral:
|
||||||
return "bool";
|
return "bool";
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown kind of literal token."));
|
solAssert(false, "Unknown kind of literal token.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,9 +211,10 @@ TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type)
|
|||||||
return make_shared<ArrayType>(DataLocation::Storage, true);
|
return make_shared<ArrayType>(DataLocation::Storage, true);
|
||||||
//no types found
|
//no types found
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment(
|
solAssert(
|
||||||
|
false,
|
||||||
"Unable to convert elementary typename " + _type.toString() + " to type."
|
"Unable to convert elementary typename " + _type.toString() + " to type."
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1176,7 +1177,7 @@ u256 BoolType::literalValue(Literal const* _literal) const
|
|||||||
else if (_literal->token() == Token::FalseLiteral)
|
else if (_literal->token() == Token::FalseLiteral)
|
||||||
return u256(0);
|
return u256(0);
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Bool type constructed from non-boolean literal."));
|
solAssert(false, "Bool type constructed from non-boolean literal.");
|
||||||
}
|
}
|
||||||
|
|
||||||
TypePointer BoolType::unaryOperatorResult(Token::Value _operator) const
|
TypePointer BoolType::unaryOperatorResult(Token::Value _operator) const
|
||||||
@ -1938,10 +1939,7 @@ string TupleType::toString(bool _short) const
|
|||||||
|
|
||||||
u256 TupleType::storageSize() const
|
u256 TupleType::storageSize() const
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(
|
solAssert(false, "Storage size of non-storable tuple type requested.");
|
||||||
InternalCompilerError() <<
|
|
||||||
errinfo_comment("Storage size of non-storable tuple type requested.")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned TupleType::sizeOnStack() const
|
unsigned TupleType::sizeOnStack() const
|
||||||
@ -2323,9 +2321,7 @@ u256 FunctionType::storageSize() const
|
|||||||
if (m_kind == Kind::External || m_kind == Kind::Internal)
|
if (m_kind == Kind::External || m_kind == Kind::Internal)
|
||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(
|
solAssert(false, "Storage size of non-storable function type requested.");
|
||||||
InternalCompilerError()
|
|
||||||
<< errinfo_comment("Storage size of non-storable function type requested."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned FunctionType::storageBytes() const
|
unsigned FunctionType::storageBytes() const
|
||||||
@ -2335,9 +2331,7 @@ unsigned FunctionType::storageBytes() const
|
|||||||
else if (m_kind == Kind::Internal)
|
else if (m_kind == Kind::Internal)
|
||||||
return 8; // it should really not be possible to create larger programs
|
return 8; // it should really not be possible to create larger programs
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(
|
solAssert(false, "Storage size of non-storable function type requested.");
|
||||||
InternalCompilerError()
|
|
||||||
<< errinfo_comment("Storage size of non-storable function type requested."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned FunctionType::sizeOnStack() const
|
unsigned FunctionType::sizeOnStack() const
|
||||||
@ -2695,9 +2689,7 @@ bool TypeType::operator==(Type const& _other) const
|
|||||||
|
|
||||||
u256 TypeType::storageSize() const
|
u256 TypeType::storageSize() const
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(
|
solAssert(false, "Storage size of non-storable type type requested.");
|
||||||
InternalCompilerError()
|
|
||||||
<< errinfo_comment("Storage size of non-storable type type requested."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned TypeType::sizeOnStack() const
|
unsigned TypeType::sizeOnStack() const
|
||||||
@ -2764,9 +2756,7 @@ ModifierType::ModifierType(const ModifierDefinition& _modifier)
|
|||||||
|
|
||||||
u256 ModifierType::storageSize() const
|
u256 ModifierType::storageSize() const
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(
|
solAssert(false, "Storage size of non-storable type type requested.");
|
||||||
InternalCompilerError()
|
|
||||||
<< errinfo_comment("Storage size of non-storable type type requested."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string ModifierType::identifier() const
|
string ModifierType::identifier() const
|
||||||
@ -2875,7 +2865,7 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
|
|||||||
{"gasprice", make_shared<IntegerType>(256)}
|
{"gasprice", make_shared<IntegerType>(256)}
|
||||||
});
|
});
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown kind of magic."));
|
solAssert(false, "Unknown kind of magic.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2890,6 +2880,6 @@ string MagicType::toString(bool) const
|
|||||||
case Kind::Transaction:
|
case Kind::Transaction:
|
||||||
return "tx";
|
return "tx";
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown kind of magic."));
|
solAssert(false, "Unknown kind of magic.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,10 +245,7 @@ public:
|
|||||||
virtual std::string canonicalName(bool /*_addDataLocation*/) const { return toString(true); }
|
virtual std::string canonicalName(bool /*_addDataLocation*/) const { return toString(true); }
|
||||||
virtual u256 literalValue(Literal const*) const
|
virtual u256 literalValue(Literal const*) const
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(
|
solAssert(false, "Literal value requested for type without literals.");
|
||||||
InternalCompilerError() <<
|
|
||||||
errinfo_comment("Literal value requested for type without literals.")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @returns a (simpler) type that is encoded in the same way for external function calls.
|
/// @returns a (simpler) type that is encoded in the same way for external function calls.
|
||||||
|
@ -196,8 +196,7 @@ ModifierDefinition const& CompilerContext::functionModifier(string const& _name)
|
|||||||
for (ModifierDefinition const* modifier: contract->functionModifiers())
|
for (ModifierDefinition const* modifier: contract->functionModifiers())
|
||||||
if (modifier->name() == _name)
|
if (modifier->name() == _name)
|
||||||
return *modifier;
|
return *modifier;
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError()
|
solAssert(false, "Function modifier " + _name + " not found.");
|
||||||
<< errinfo_comment("Function modifier " + _name + " not found."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned CompilerContext::baseStackOffsetOfVariable(Declaration const& _declaration) const
|
unsigned CompilerContext::baseStackOffsetOfVariable(Declaration const& _declaration) const
|
||||||
|
@ -378,8 +378,7 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
|
|||||||
m_context << u256(0) << Instruction::SUB;
|
m_context << u256(0) << Instruction::SUB;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid unary operator: " +
|
solAssert(false, "Invalid unary operator: " + string(Token::toString(_unaryOperation.getOperator())));
|
||||||
string(Token::toString(_unaryOperation.getOperator()))));
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -900,7 +899,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid function type."));
|
solAssert(false, "Invalid function type.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -1066,7 +1065,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid member access to integer."));
|
solAssert(false, "Invalid member access to integer");
|
||||||
break;
|
break;
|
||||||
case Type::Category::Function:
|
case Type::Category::Function:
|
||||||
solAssert(!!_memberAccess.expression().annotation().type->memberType(member),
|
solAssert(!!_memberAccess.expression().annotation().type->memberType(member),
|
||||||
@ -1100,7 +1099,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
|||||||
m_context << u256(0) << Instruction::CALLDATALOAD
|
m_context << u256(0) << Instruction::CALLDATALOAD
|
||||||
<< (u256(0xffffffff) << (256 - 32)) << Instruction::AND;
|
<< (u256(0xffffffff) << (256 - 32)) << Instruction::AND;
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown magic member."));
|
solAssert(false, "Unknown magic member.");
|
||||||
break;
|
break;
|
||||||
case Type::Category::Struct:
|
case Type::Category::Struct:
|
||||||
{
|
{
|
||||||
@ -1177,7 +1176,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Member access to unknown type."));
|
solAssert(false, "Member access to unknown type.");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1332,7 +1331,7 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Identifier type not expected in expression context."));
|
solAssert(false, "Identifier type not expected in expression context.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1415,7 +1414,7 @@ void ExpressionCompiler::appendCompareOperatorCode(Token::Value _operator, Type
|
|||||||
m_context << (isSigned ? Instruction::SLT : Instruction::LT);
|
m_context << (isSigned ? Instruction::SLT : Instruction::LT);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown comparison operator."));
|
solAssert(false, "Unknown comparison operator.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1427,7 +1426,7 @@ void ExpressionCompiler::appendOrdinaryBinaryOperatorCode(Token::Value _operator
|
|||||||
else if (Token::isBitOp(_operator))
|
else if (Token::isBitOp(_operator))
|
||||||
appendBitOperatorCode(_operator);
|
appendBitOperatorCode(_operator);
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown binary operator."));
|
solAssert(false, "Unknown binary operator.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressionCompiler::appendArithmeticOperatorCode(Token::Value _operator, Type const& _type)
|
void ExpressionCompiler::appendArithmeticOperatorCode(Token::Value _operator, Type const& _type)
|
||||||
@ -1466,7 +1465,7 @@ void ExpressionCompiler::appendArithmeticOperatorCode(Token::Value _operator, Ty
|
|||||||
m_context << Instruction::EXP;
|
m_context << Instruction::EXP;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown arithmetic operator."));
|
solAssert(false, "Unknown arithmetic operator.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1484,7 +1483,7 @@ void ExpressionCompiler::appendBitOperatorCode(Token::Value _operator)
|
|||||||
m_context << Instruction::XOR;
|
m_context << Instruction::XOR;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown bit operator."));
|
solAssert(false, "Unknown bit operator.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1528,7 +1527,7 @@ void ExpressionCompiler::appendShiftOperatorCode(Token::Value _operator, Type co
|
|||||||
break;
|
break;
|
||||||
case Token::SHR:
|
case Token::SHR:
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown shift operator."));
|
solAssert(false, "Unknown shift operator.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,7 +435,7 @@ Json::Value const& CompilerStack::natspec(Contract const& _contract, Documentati
|
|||||||
doc->reset(new Json::Value(Natspec::devDocumentation(*_contract.contract)));
|
doc->reset(new Json::Value(Natspec::devDocumentation(*_contract.contract)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Illegal documentation type."));
|
solAssert(false, "Illegal documentation type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return *(*doc);
|
return *(*doc);
|
||||||
@ -665,11 +665,11 @@ void CompilerStack::compileContract(
|
|||||||
}
|
}
|
||||||
catch(eth::OptimizerException const&)
|
catch(eth::OptimizerException const&)
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Assembly optimizer exception for bytecode"));
|
solAssert(false, "Assembly optimizer exception for bytecode");
|
||||||
}
|
}
|
||||||
catch(eth::AssemblyException const&)
|
catch(eth::AssemblyException const&)
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Assembly exception for bytecode"));
|
solAssert(false, "Assembly exception for bytecode");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -678,11 +678,11 @@ void CompilerStack::compileContract(
|
|||||||
}
|
}
|
||||||
catch(eth::OptimizerException const&)
|
catch(eth::OptimizerException const&)
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Assembly optimizer exception for deployed bytecode"));
|
solAssert(false, "Assembly optimizer exception for deployed bytecode");
|
||||||
}
|
}
|
||||||
catch(eth::AssemblyException const&)
|
catch(eth::AssemblyException const&)
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Assembly exception for deployed bytecode"));
|
solAssert(false, "Assembly exception for deployed bytecode");
|
||||||
}
|
}
|
||||||
|
|
||||||
compiledContract.metadata = metadata;
|
compiledContract.metadata = metadata;
|
||||||
|
Loading…
Reference in New Issue
Block a user