Skip to content

Commit

Permalink
Try out the new assertion macro variants with less arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
cameel authored and chriseth committed Oct 4, 2021
1 parent 0745842 commit 7f71074
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 41 deletions.
12 changes: 6 additions & 6 deletions libsmtutil/CHCSmtLib2Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ void CHCSmtLib2Interface::reset()

void CHCSmtLib2Interface::registerRelation(Expression const& _expr)
{
smtAssert(_expr.sort, "");
smtAssert(_expr.sort->kind == Kind::Function, "");
smtAssert(_expr.sort);
smtAssert(_expr.sort->kind == Kind::Function);
if (!m_variables.count(_expr.name))
{
auto fSort = dynamic_pointer_cast<FunctionSort>(_expr.sort);
Expand Down Expand Up @@ -124,7 +124,7 @@ pair<CheckResult, CHCSolverInterface::CexGraph> CHCSmtLib2Interface::query(Expre

void CHCSmtLib2Interface::declareVariable(string const& _name, SortPointer const& _sort)
{
smtAssert(_sort, "");
smtAssert(_sort);
if (_sort->kind == Kind::Function)
declareFunction(_name, _sort);
else if (!m_variables.count(_name))
Expand Down Expand Up @@ -172,13 +172,13 @@ string CHCSmtLib2Interface::forall()

void CHCSmtLib2Interface::declareFunction(string const& _name, SortPointer const& _sort)
{
smtAssert(_sort, "");
smtAssert(_sort->kind == Kind::Function, "");
smtAssert(_sort);
smtAssert(_sort->kind == Kind::Function);
// TODO Use domain and codomain as key as well
if (!m_variables.count(_name))
{
auto fSort = dynamic_pointer_cast<FunctionSort>(_sort);
smtAssert(fSort->codomain, "");
smtAssert(fSort->codomain);
string domain = toSmtLibSort(fSort->domain);
string codomain = toSmtLibSort(*fSort->codomain);
m_variables.insert(_name);
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/analysis/ControlFlowBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ void ControlFlowBuilder::operator()(yul::FunctionDefinition const&)
void ControlFlowBuilder::operator()(yul::Leave const&)
{
// This has to be implemented, if we ever decide to visit functions.
solUnimplementedAssert(false, "");
solUnimplemented("");
}

bool ControlFlowBuilder::visit(VariableDeclaration const& _variableDeclaration)
Expand Down
8 changes: 4 additions & 4 deletions libsolidity/ast/ASTJsonImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ map<string, ASTPointer<SourceUnit>> ASTJsonImporter::jsonToSourceUnit(map<string
m_sourceNames.emplace_back(make_shared<string const>(src.first));
for (auto const& srcPair: _sourceList)
{
astAssert(!srcPair.second.isNull(), "");
astAssert(!srcPair.second.isNull());
astAssert(member(srcPair.second,"nodeType") == "SourceUnit", "The 'nodeType' of the highest node must be 'SourceUnit'.");
m_sourceUnits[srcPair.first] = createSourceUnit(srcPair.second, srcPair.first);
}
Expand Down Expand Up @@ -485,17 +485,17 @@ ASTPointer<VariableDeclaration> ASTJsonImporter::createVariableDeclaration(Json:
if (mutabilityStr == "constant")
{
mutability = VariableDeclaration::Mutability::Constant;
astAssert(memberAsBool(_node, "constant"), "");
astAssert(memberAsBool(_node, "constant"));
}
else
{
astAssert(!memberAsBool(_node, "constant"), "");
astAssert(!memberAsBool(_node, "constant"));
if (mutabilityStr == "mutable")
mutability = VariableDeclaration::Mutability::Mutable;
else if (mutabilityStr == "immutable")
mutability = VariableDeclaration::Mutability::Immutable;
else
astAssert(false, "");
astAssert(false);
}

return createASTNode<VariableDeclaration>(
Expand Down
3 changes: 1 addition & 2 deletions libsolidity/codegen/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2112,8 +2112,7 @@ bool ExpressionCompiler::visit(IndexRangeAccess const& _indexAccess)
solUnimplementedAssert(
arrayType->location() == DataLocation::CallData &&
arrayType->isDynamicallySized() &&
!arrayType->baseType()->isDynamicallyEncoded(),
""
!arrayType->baseType()->isDynamicallyEncoded()
);

if (_indexAccess.startExpression())
Expand Down
4 changes: 2 additions & 2 deletions libsolidity/codegen/LValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ ImmutableItem::ImmutableItem(CompilerContext& _compilerContext, VariableDeclarat

void ImmutableItem::retrieveValue(SourceLocation const&, bool) const
{
solUnimplementedAssert(m_dataType->isValueType(), "");
solUnimplementedAssert(m_dataType->isValueType());

if (m_context.runtimeContext())
CompilerUtils(m_context).loadFromMemory(
Expand All @@ -172,7 +172,7 @@ void ImmutableItem::retrieveValue(SourceLocation const&, bool) const
void ImmutableItem::storeValue(Type const& _sourceType, SourceLocation const&, bool _move) const
{
CompilerUtils utils(m_context);
solUnimplementedAssert(m_dataType->isValueType(), "");
solUnimplementedAssert(m_dataType->isValueType());
solAssert(_sourceType.isValueType(), "");

utils.convertType(_sourceType, *m_dataType, true);
Expand Down
18 changes: 9 additions & 9 deletions libsolidity/codegen/YulUtilFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ string YulUtilFunctions::extractByteArrayLengthFunction()
std::string YulUtilFunctions::resizeArrayFunction(ArrayType const& _type)
{
solAssert(_type.location() == DataLocation::Storage, "");
solUnimplementedAssert(_type.baseType()->storageBytes() <= 32, "...");
solUnimplementedAssert(_type.baseType()->storageBytes() <= 32);

if (_type.isByteArray())
return resizeDynamicByteArrayFunction(_type);
Expand Down Expand Up @@ -1259,7 +1259,7 @@ string YulUtilFunctions::cleanUpStorageArrayEndFunction(ArrayType const& _type)
solAssert(_type.location() == DataLocation::Storage, "");
solAssert(_type.baseType()->category() != Type::Category::Mapping, "");
solAssert(!_type.isByteArray(), "");
solUnimplementedAssert(_type.baseType()->storageBytes() <= 32, "");
solUnimplementedAssert(_type.baseType()->storageBytes() <= 32);

string functionName = "cleanup_storage_array_end_" + _type.identifier();
return m_functionCollector.createFunction(functionName, [&](vector<string>& _args, vector<string>&) {
Expand Down Expand Up @@ -1555,7 +1555,7 @@ string YulUtilFunctions::storageArrayPushFunction(ArrayType const& _type, Type c
if (!_fromType)
_fromType = _type.baseType();
else if (_fromType->isValueType())
solUnimplementedAssert(*_fromType == *_type.baseType(), "");
solUnimplementedAssert(*_fromType == *_type.baseType());

string functionName =
string{"array_push_from_"} +
Expand Down Expand Up @@ -3304,10 +3304,10 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
if (auto const* toFixedBytes = dynamic_cast<FixedBytesType const*>(&_to))
convert = shiftLeftFunction(256 - toFixedBytes->numBytes() * 8);
else if (dynamic_cast<FixedPointType const*>(&_to))
solUnimplementedAssert(false, "");
solUnimplemented("");
else if (dynamic_cast<IntegerType const*>(&_to))
{
solUnimplementedAssert(fromCategory != Type::Category::FixedPoint, "");
solUnimplementedAssert(fromCategory != Type::Category::FixedPoint);
convert = identityFunction();
}
else if (toCategory == Type::Category::Enum)
Expand Down Expand Up @@ -3346,8 +3346,8 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
body = "converted := value";
else
{
solUnimplementedAssert(toStructType.location() == DataLocation::Memory, "");
solUnimplementedAssert(fromStructType.location() != DataLocation::Memory, "");
solUnimplementedAssert(toStructType.location() == DataLocation::Memory);
solUnimplementedAssert(fromStructType.location() != DataLocation::Memory);

if (fromStructType.location() == DataLocation::CallData)
body = Whiskers(R"(
Expand Down Expand Up @@ -3416,7 +3416,7 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
}
case Type::Category::Tuple:
{
solUnimplementedAssert(false, "Tuple conversion not implemented.");
solUnimplemented("Tuple conversion not implemented.");
break;
}
case Type::Category::TypeType:
Expand Down Expand Up @@ -4107,7 +4107,7 @@ string YulUtilFunctions::zeroValueFunction(Type const& _type, bool _splitFunctio
else if (auto const* structType = dynamic_cast<StructType const*>(&_type))
templ("zeroValue", allocateAndInitializeMemoryStructFunction(*structType) + "()");
else
solUnimplementedAssert(false, "");
solUnimplemented("");
}

return templ.render();
Expand Down
6 changes: 3 additions & 3 deletions libsolidity/codegen/ir/IRGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ string IRGenerator::generateGetter(VariableDeclaration const& _varDecl)
if (_varDecl.immutable())
{
solAssert(paramTypes.empty(), "");
solUnimplementedAssert(type->sizeOnStack() == 1, "");
solUnimplementedAssert(type->sizeOnStack() == 1);
return Whiskers(R"(
/// @ast-id <astID>
<sourceLocationComment>
Expand Down Expand Up @@ -925,8 +925,8 @@ string IRGenerator::deployCode(ContractDefinition const& _contract)
else
for (VariableDeclaration const* immutable: ContractType(_contract).immutableVariables())
{
solUnimplementedAssert(immutable->type()->isValueType(), "");
solUnimplementedAssert(immutable->type()->sizeOnStack() == 1, "");
solUnimplementedAssert(immutable->type()->isValueType());
solUnimplementedAssert(immutable->type()->sizeOnStack() == 1);
immutables.emplace_back(map<string, string>{
{"immutableName"s, to_string(immutable->id())},
{"value"s, "mload(" + to_string(m_context.immutableMemoryOffset(*immutable)) + ")"}
Expand Down
20 changes: 10 additions & 10 deletions libsolidity/codegen/ir/IRGeneratorForStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct CopyTranslate: public yul::ASTCopier
{
auto const& reference = m_references.at(&_identifier);
auto const varDecl = dynamic_cast<VariableDeclaration const*>(reference.declaration);
solUnimplementedAssert(varDecl, "");
solUnimplementedAssert(varDecl);
string const& suffix = reference.suffix;

string value;
Expand Down Expand Up @@ -737,7 +737,7 @@ bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation)
) << "(" << IRVariable(_unaryOperation.subExpression()).name() << ")\n";
}
else
solUnimplementedAssert(false, "Unary operator not yet implemented");
solUnimplemented("Unary operator not yet implemented");
}
else if (resultType.category() == Type::Category::FixedBytes)
{
Expand All @@ -755,7 +755,7 @@ bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation)
appendSimpleUnaryOperation(_unaryOperation, _unaryOperation.subExpression());
}
else
solUnimplementedAssert(false, "Unary operator not yet implemented");
solUnimplemented("Unary operator not yet implemented");

return false;
}
Expand Down Expand Up @@ -1546,7 +1546,7 @@ void IRGeneratorForStatements::endVisit(FunctionCallOptions const& _options)
setLocation(_options);
FunctionType const& previousType = dynamic_cast<FunctionType const&>(*_options.expression().annotation().type);

solUnimplementedAssert(!previousType.bound(), "");
solUnimplementedAssert(!previousType.bound());

// Copy over existing values.
for (auto const& item: previousType.stackItems())
Expand Down Expand Up @@ -1716,7 +1716,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
{
solUnimplementedAssert(
dynamic_cast<FunctionType const&>(*_memberAccess.expression().annotation().type).kind() ==
FunctionType::Kind::External, ""
FunctionType::Kind::External
);
define(IRVariable{_memberAccess}, IRVariable(_memberAccess.expression()).part("address"));
}
Expand Down Expand Up @@ -2264,7 +2264,7 @@ void IRGeneratorForStatements::endVisit(IndexRangeAccess const& _indexRangeAcces
break;
}
default:
solUnimplementedAssert(false, "Index range accesses is implemented only on calldata arrays.");
solUnimplemented("Index range accesses is implemented only on calldata arrays.");
}
}

Expand Down Expand Up @@ -2910,8 +2910,8 @@ void IRGeneratorForStatements::writeToLValue(IRLValue const& _lvalue, IRVariable
[&](IRLValue::Stack const& _stack) { assign(_stack.variable, _value); },
[&](IRLValue::Immutable const& _immutable)
{
solUnimplementedAssert(_lvalue.type.isValueType(), "");
solUnimplementedAssert(_lvalue.type.sizeOnStack() == 1, "");
solUnimplementedAssert(_lvalue.type.isValueType());
solUnimplementedAssert(_lvalue.type.sizeOnStack() == 1);
solAssert(_lvalue.type == *_immutable.variable->type(), "");
size_t memOffset = m_context.immutableMemoryOffset(*_immutable.variable);

Expand Down Expand Up @@ -2970,8 +2970,8 @@ IRVariable IRGeneratorForStatements::readFromLValue(IRLValue const& _lvalue)
define(result, _stack.variable);
},
[&](IRLValue::Immutable const& _immutable) {
solUnimplementedAssert(_lvalue.type.isValueType(), "");
solUnimplementedAssert(_lvalue.type.sizeOnStack() == 1, "");
solUnimplementedAssert(_lvalue.type.isValueType());
solUnimplementedAssert(_lvalue.type.sizeOnStack() == 1);
solAssert(_lvalue.type == *_immutable.variable->type(), "");
if (m_context.executionContext() == IRGenerationContext::ExecutionContext::Creation)
{
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void CompilerStack::setRevertStringBehaviour(RevertStrings _revertStrings)
{
if (m_stackState >= ParsedAndImported)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Must set revert string settings before parsing."));
solUnimplementedAssert(_revertStrings != RevertStrings::VerboseDebug, "");
solUnimplementedAssert(_revertStrings != RevertStrings::VerboseDebug);
m_revertStrings = _revertStrings;
}

Expand Down
2 changes: 1 addition & 1 deletion solc/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ bool CommandLineParser::processArgs()
if (m_options.input.mode == InputMode::Compiler)
m_options.input.errorRecovery = (m_args.count(g_strErrorRecovery) > 0);

solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions test/tools/yulopti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class YulOpti
size_t _columns
)
{
yulAssert(_columns > 0, "");
yulAssert(_columns > 0);

auto hasShorterString = [](auto const& a, auto const& b) { return a.second.size() < b.second.size(); };
size_t longestDescriptionLength = std::max(
Expand Down Expand Up @@ -151,7 +151,7 @@ class YulOpti
);
});

yulAssert(sortedOptions.size() > 0, "");
yulAssert(sortedOptions.size() > 0);
size_t rows = (sortedOptions.size() - 1) / _columns + 1;
for (size_t row = 0; row < rows; ++row)
{
Expand Down

0 comments on commit 7f71074

Please sign in to comment.