OptimiserSuite: Define NonStepAbbreviations and use it for extra sanity checks

This commit is contained in:
Kamil Śliwak 2020-04-24 14:13:34 +02:00
parent 5a515240ac
commit e2c0e6331c
2 changed files with 15 additions and 0 deletions

View File

@ -67,6 +67,7 @@
#include <libsolutil/CommonData.h>
#include <boost/range/adaptor/map.hpp>
#include <boost/range/algorithm_ext/erase.hpp>
using namespace std;
@ -235,6 +236,12 @@ map<string, char> const& OptimiserSuite::stepNameToAbbreviationMap()
{VarDeclInitializer::name, 'd'},
};
yulAssert(lookupTable.size() == allSteps().size(), "");
yulAssert((
util::convertContainer<set<char>>(string(NonStepAbbreviations)) -
util::convertContainer<set<char>>(lookupTable | boost::adaptors::map_values)
).size() == string(NonStepAbbreviations).size(),
"Step abbreviation conflicts with a character reserved for another syntactic element"
);
return lookupTable;
}
@ -265,6 +272,10 @@ void OptimiserSuite::runSequence(string const& _stepAbbreviations, Block& _ast)
insideLoop = false;
break;
default:
yulAssert(
string(NonStepAbbreviations).find(abbreviation) == string::npos,
"Unhandled syntactic element in the abbreviation sequence"
);
assertThrow(
stepAbbreviationToNameMap().find(abbreviation) != stepAbbreviationToNameMap().end(),
OptimizerException,

View File

@ -47,6 +47,10 @@ class OptimiserSuite
public:
static constexpr size_t MaxRounds = 12;
/// Special characters that do not represent optimiser steps but are allowed in abbreviation sequences.
/// Some of them (like whitespace) are ignored, others (like brackets) are a part of the syntax.
static constexpr char NonStepAbbreviations[] = " \n[]";
enum class Debug
{
None,