Skip to content

Commit

Permalink
Replace all solAsserts with yulAsserts in libyul
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Dec 3, 2019
1 parent a13416f commit 7e8f0a1
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 161 deletions.
46 changes: 23 additions & 23 deletions libyul/AsmAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ bool AsmAnalyzer::analyze(Block const& _block)

success = (*this)(_block);
if (!success)
solAssert(m_errorReporter.hasErrors(), "No success but no error.");
yulAssert(m_errorReporter.hasErrors(), "No success but no error.");
}
catch (FatalError const&)
{
// This FatalError con occur if the errorReporter has too many errors.
solAssert(!m_errorReporter.errors().empty(), "Fatal error detected, but no error is reported.");
yulAssert(!m_errorReporter.errors().empty(), "Fatal error detected, but no error is reported.");
}
return success && !m_errorReporter.hasErrors();
}
Expand All @@ -83,13 +83,13 @@ AsmAnalysisInfo AsmAnalyzer::analyzeStrictAssertCorrect(Dialect const& _dialect,
{},
_object.dataNames()
).analyze(*_object.code);
solAssert(success && errorList.empty(), "Invalid assembly/yul code.");
yulAssert(success && errorList.empty(), "Invalid assembly/yul code.");
return analysisInfo;
}

bool AsmAnalyzer::operator()(Label const& _label)
{
solAssert(!_label.name.empty(), "");
yulAssert(!_label.name.empty(), "");
checkLooseFeature(
_label.location,
"The use of labels is disallowed. Please use \"if\", \"switch\", \"for\" or function calls instead."
Expand Down Expand Up @@ -134,16 +134,16 @@ bool AsmAnalyzer::operator()(Literal const& _literal)
}
else if (_literal.kind == LiteralKind::Boolean)
{
solAssert(m_dialect.flavour == AsmFlavour::Yul, "");
solAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, "");
yulAssert(m_dialect.flavour == AsmFlavour::Yul, "");
yulAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, "");
}
m_info.stackHeightInfo[&_literal] = m_stackHeight;
return true;
}

bool AsmAnalyzer::operator()(Identifier const& _identifier)
{
solAssert(!_identifier.name.empty(), "");
yulAssert(!_identifier.name.empty(), "");
size_t numErrorsBefore = m_errorReporter.errors().size();
bool success = true;
if (m_currentScope->lookup(_identifier.name, GenericVisitor{
Expand Down Expand Up @@ -197,14 +197,14 @@ bool AsmAnalyzer::operator()(Identifier const& _identifier)

bool AsmAnalyzer::operator()(FunctionalInstruction const& _instr)
{
solAssert(m_dialect.flavour != AsmFlavour::Yul, "");
yulAssert(m_dialect.flavour != AsmFlavour::Yul, "");
bool success = true;
for (auto const& arg: _instr.arguments | boost::adaptors::reversed)
if (!expectExpression(arg))
success = false;
// Parser already checks that the number of arguments is correct.
auto const& info = instructionInfo(_instr.instruction);
solAssert(info.args == int(_instr.arguments.size()), "");
yulAssert(info.args == int(_instr.arguments.size()), "");
m_stackHeight += info.ret - info.args;
m_info.stackHeightInfo[&_instr] = m_stackHeight;
warnOnInstructions(_instr.instruction, _instr.location);
Expand Down Expand Up @@ -245,9 +245,9 @@ bool AsmAnalyzer::operator()(StackAssignment const& _assignment)

bool AsmAnalyzer::operator()(Assignment const& _assignment)
{
solAssert(_assignment.value, "");
yulAssert(_assignment.value, "");
int const expectedItems = _assignment.variableNames.size();
solAssert(expectedItems >= 1, "");
yulAssert(expectedItems >= 1, "");
int const stackHeight = m_stackHeight;
bool success = std::visit(*this, *_assignment.value);
if ((m_stackHeight - stackHeight) != expectedItems)
Expand Down Expand Up @@ -306,9 +306,9 @@ bool AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)

bool AsmAnalyzer::operator()(FunctionDefinition const& _funDef)
{
solAssert(!_funDef.name.empty(), "");
yulAssert(!_funDef.name.empty(), "");
Block const* virtualBlock = m_info.virtualBlocks.at(&_funDef).get();
solAssert(virtualBlock, "");
yulAssert(virtualBlock, "");
Scope& varScope = scope(virtualBlock);
for (auto const& var: _funDef.parameters + _funDef.returnVariables)
{
Expand All @@ -328,7 +328,7 @@ bool AsmAnalyzer::operator()(FunctionDefinition const& _funDef)

bool AsmAnalyzer::operator()(FunctionCall const& _funCall)
{
solAssert(!_funCall.functionName.name.empty(), "");
yulAssert(!_funCall.functionName.name.empty(), "");
bool success = true;
size_t parameters = 0;
size_t returns = 0;
Expand Down Expand Up @@ -426,7 +426,7 @@ bool AsmAnalyzer::operator()(If const& _if)

bool AsmAnalyzer::operator()(Switch const& _switch)
{
solAssert(_switch.expression, "");
yulAssert(_switch.expression, "");

bool success = true;

Expand Down Expand Up @@ -498,7 +498,7 @@ bool AsmAnalyzer::operator()(Switch const& _switch)

bool AsmAnalyzer::operator()(ForLoop const& _for)
{
solAssert(_for.condition, "");
yulAssert(_for.condition, "");

Scope* outerScope = m_currentScope;

Expand Down Expand Up @@ -609,7 +609,7 @@ bool AsmAnalyzer::expectDeposit(int _deposit, int _oldHeight, SourceLocation con

bool AsmAnalyzer::checkAssignment(Identifier const& _variable, size_t _valueSize)
{
solAssert(!_variable.name.empty(), "");
yulAssert(!_variable.name.empty(), "");
bool success = true;
size_t numErrorsBefore = m_errorReporter.errors().size();
size_t variableSize(-1);
Expand Down Expand Up @@ -665,9 +665,9 @@ bool AsmAnalyzer::checkAssignment(Identifier const& _variable, size_t _valueSize

Scope& AsmAnalyzer::scope(Block const* _block)
{
solAssert(m_info.scopes.count(_block) == 1, "Scope requested but not present.");
yulAssert(m_info.scopes.count(_block) == 1, "Scope requested but not present.");
auto scopePtr = m_info.scopes.at(_block);
solAssert(scopePtr, "Scope requested but not present.");
yulAssert(scopePtr, "Scope requested but not present.");
return *scopePtr;
}
void AsmAnalyzer::expectValidType(string const& type, SourceLocation const& _location)
Expand All @@ -686,10 +686,10 @@ void AsmAnalyzer::warnOnInstructions(dev::eth::Instruction _instr, SourceLocatio
{
// We assume that returndatacopy, returndatasize and staticcall are either all available
// or all not available.
solAssert(m_evmVersion.supportsReturndata() == m_evmVersion.hasStaticCall(), "");
yulAssert(m_evmVersion.supportsReturndata() == m_evmVersion.hasStaticCall(), "");
// Similarly we assume bitwise shifting and create2 go together.
solAssert(m_evmVersion.hasBitwiseShifting() == m_evmVersion.hasCreate2(), "");
solAssert(m_dialect.flavour != AsmFlavour::Yul, "");
yulAssert(m_evmVersion.hasBitwiseShifting() == m_evmVersion.hasCreate2(), "");
yulAssert(m_dialect.flavour != AsmFlavour::Yul, "");

auto errorForVM = [=](string const& vmKindMessage) {
m_errorReporter.typeError(
Expand Down Expand Up @@ -768,7 +768,7 @@ void AsmAnalyzer::warnOnInstructions(dev::eth::Instruction _instr, SourceLocatio
void AsmAnalyzer::checkLooseFeature(SourceLocation const& _location, string const& _description)
{
if (m_dialect.flavour != AsmFlavour::Loose)
solAssert(false, _description);
yulAssert(false, _description);
else if (m_errorTypeForLoose)
m_errorReporter.error(*m_errorTypeForLoose, _location, _description);
}
15 changes: 8 additions & 7 deletions libyul/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include <libyul/AsmParser.h>
#include <libyul/Exceptions.h>
#include <liblangutil/Scanner.h>
#include <liblangutil/ErrorReporter.h>
#include <libdevcore/Common.h>
Expand Down Expand Up @@ -52,7 +53,7 @@ shared_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _
}
catch (FatalError const&)
{
solAssert(!m_errorReporter.errors().empty(), "Fatal error detected, but no error is reported.");
yulAssert(!m_errorReporter.errors().empty(), "Fatal error detected, but no error is reported.");
}

return nullptr;
Expand Down Expand Up @@ -257,7 +258,7 @@ Statement Parser::parseStatement()
}
else
{
solAssert(holds_alternative<Instruction>(elementary), "Invalid elementary operation.");
yulAssert(holds_alternative<Instruction>(elementary), "Invalid elementary operation.");
return std::get<Instruction>(elementary);
}
}
Expand All @@ -277,7 +278,7 @@ Case Parser::parseCase()
_case.value = make_unique<Literal>(std::get<Literal>(std::move(literal)));
}
else
solAssert(false, "Case or default case expected.");
yulAssert(false, "Case or default case expected.");
_case.body = parseBlock();
_case.location.end = _case.body.location.end;
return _case;
Expand Down Expand Up @@ -315,7 +316,7 @@ Expression Parser::parseExpression()
return parseCall(std::move(operation));
else if (holds_alternative<Instruction>(operation))
{
solAssert(m_dialect.flavour == AsmFlavour::Loose, "");
yulAssert(m_dialect.flavour == AsmFlavour::Loose, "");
Instruction const& instr = std::get<Instruction>(operation);
// Disallow instructions returning multiple values (and DUP/SWAP) as expression.
if (
Expand Down Expand Up @@ -348,15 +349,15 @@ Expression Parser::parseExpression()
else if (holds_alternative<Instruction>(operation))
{
// Instructions not taking arguments are allowed as expressions.
solAssert(m_dialect.flavour == AsmFlavour::Loose, "");
yulAssert(m_dialect.flavour == AsmFlavour::Loose, "");
Instruction& instr = std::get<Instruction>(operation);
return FunctionalInstruction{std::move(instr.location), instr.instruction, {}};
}
else if (holds_alternative<Identifier>(operation))
return std::get<Identifier>(operation);
else
{
solAssert(holds_alternative<Literal>(operation), "");
yulAssert(holds_alternative<Literal>(operation), "");
return std::get<Literal>(operation);
}
}
Expand Down Expand Up @@ -539,7 +540,7 @@ Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp)
RecursionGuard recursionGuard(*this);
if (holds_alternative<Instruction>(_initialOp))
{
solAssert(m_dialect.flavour != AsmFlavour::Yul, "Instructions are invalid in Yul");
yulAssert(m_dialect.flavour != AsmFlavour::Yul, "Instructions are invalid in Yul");
Instruction& instruction = std::get<Instruction>(_initialOp);
FunctionalInstruction ret;
ret.instruction = instruction.instruction;
Expand Down
36 changes: 18 additions & 18 deletions libyul/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <libyul/AsmPrinter.h>
#include <libyul/AsmData.h>
#include <liblangutil/Exceptions.h>
#include <libyul/Exceptions.h>

#include <libdevcore/CommonData.h>

Expand All @@ -41,8 +41,8 @@ using namespace yul;

string AsmPrinter::operator()(yul::Instruction const& _instruction) const
{
solAssert(!m_yul, "");
solAssert(isValidInstruction(_instruction.instruction), "Invalid instruction");
yulAssert(!m_yul, "");
yulAssert(isValidInstruction(_instruction.instruction), "Invalid instruction");
return boost::to_lower_copy(instructionInfo(_instruction.instruction).name);
}

Expand All @@ -51,10 +51,10 @@ string AsmPrinter::operator()(Literal const& _literal) const
switch (_literal.kind)
{
case LiteralKind::Number:
solAssert(isValidDecimal(_literal.value.str()) || isValidHex(_literal.value.str()), "Invalid number literal");
yulAssert(isValidDecimal(_literal.value.str()) || isValidHex(_literal.value.str()), "Invalid number literal");
return _literal.value.str() + appendTypeName(_literal.type);
case LiteralKind::Boolean:
solAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, "Invalid bool literal.");
yulAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, "Invalid bool literal.");
return ((_literal.value == "true"_yulstring) ? "true" : "false") + appendTypeName(_literal.type);
case LiteralKind::String:
break;
Expand Down Expand Up @@ -91,14 +91,14 @@ string AsmPrinter::operator()(Literal const& _literal) const

string AsmPrinter::operator()(Identifier const& _identifier) const
{
solAssert(!_identifier.name.empty(), "Invalid identifier.");
yulAssert(!_identifier.name.empty(), "Invalid identifier.");
return _identifier.name.str();
}

string AsmPrinter::operator()(FunctionalInstruction const& _functionalInstruction) const
{
solAssert(!m_yul, "");
solAssert(isValidInstruction(_functionalInstruction.instruction), "Invalid instruction");
yulAssert(!m_yul, "");
yulAssert(isValidInstruction(_functionalInstruction.instruction), "Invalid instruction");
return
boost::to_lower_copy(instructionInfo(_functionalInstruction.instruction).name) +
"(" +
Expand All @@ -116,21 +116,21 @@ string AsmPrinter::operator()(ExpressionStatement const& _statement) const

string AsmPrinter::operator()(Label const& _label) const
{
solAssert(!m_yul, "");
solAssert(!_label.name.empty(), "Invalid label.");
yulAssert(!m_yul, "");
yulAssert(!_label.name.empty(), "Invalid label.");
return _label.name.str() + ":";
}

string AsmPrinter::operator()(StackAssignment const& _assignment) const
{
solAssert(!m_yul, "");
solAssert(!_assignment.variableName.name.empty(), "Invalid variable name.");
yulAssert(!m_yul, "");
yulAssert(!_assignment.variableName.name.empty(), "Invalid variable name.");
return "=: " + (*this)(_assignment.variableName);
}

string AsmPrinter::operator()(Assignment const& _assignment) const
{
solAssert(_assignment.variableNames.size() >= 1, "");
yulAssert(_assignment.variableNames.size() >= 1, "");
string variables = (*this)(_assignment.variableNames.front());
for (size_t i = 1; i < _assignment.variableNames.size(); ++i)
variables += ", " + (*this)(_assignment.variableNames[i]);
Expand All @@ -156,7 +156,7 @@ string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration) c

string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition) const
{
solAssert(!_functionDefinition.name.empty(), "Invalid function name.");
yulAssert(!_functionDefinition.name.empty(), "Invalid function name.");
string out = "function " + _functionDefinition.name.str() + "(";
out += boost::algorithm::join(
_functionDefinition.parameters | boost::adaptors::transformed(
Expand Down Expand Up @@ -191,7 +191,7 @@ string AsmPrinter::operator()(FunctionCall const& _functionCall) const

string AsmPrinter::operator()(If const& _if) const
{
solAssert(_if.condition, "Invalid if condition.");
yulAssert(_if.condition, "Invalid if condition.");
string body = (*this)(_if.body);
char delim = '\n';
if (body.find('\n') == string::npos)
Expand All @@ -201,7 +201,7 @@ string AsmPrinter::operator()(If const& _if) const

string AsmPrinter::operator()(Switch const& _switch) const
{
solAssert(_switch.expression, "Invalid expression pointer.");
yulAssert(_switch.expression, "Invalid expression pointer.");
string out = "switch " + std::visit(*this, *_switch.expression);
for (auto const& _case: _switch.cases)
{
Expand All @@ -216,7 +216,7 @@ string AsmPrinter::operator()(Switch const& _switch) const

string AsmPrinter::operator()(ForLoop const& _forLoop) const
{
solAssert(_forLoop.condition, "Invalid for loop condition.");
yulAssert(_forLoop.condition, "Invalid for loop condition.");
string pre = (*this)(_forLoop.pre);
string condition = std::visit(*this, *_forLoop.condition);
string post = (*this)(_forLoop.post);
Expand Down Expand Up @@ -261,7 +261,7 @@ string AsmPrinter::operator()(Block const& _block) const

string AsmPrinter::formatTypedName(TypedName _variable) const
{
solAssert(!_variable.name.empty(), "Invalid variable name.");
yulAssert(!_variable.name.empty(), "Invalid variable name.");
return _variable.name.str() + appendTypeName(_variable.type);
}

Expand Down
4 changes: 2 additions & 2 deletions libyul/AsmScopeFiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#include <libyul/AsmData.h>
#include <libyul/AsmScope.h>
#include <libyul/AsmAnalysisInfo.h>
#include <libyul/Exceptions.h>

#include <liblangutil/ErrorReporter.h>
#include <liblangutil/Exceptions.h>

#include <libdevcore/CommonData.h>

Expand Down Expand Up @@ -88,7 +88,7 @@ bool ScopeFiller::operator()(FunctionDefinition const& _funDef)
if (!(*this)(_funDef.body))
success = false;

solAssert(m_currentScope == &varScope, "");
yulAssert(m_currentScope == &varScope, "");
m_currentScope = m_currentScope->superScope;

return success;
Expand Down
Loading

0 comments on commit 7e8f0a1

Please sign in to comment.