mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Change optimizer sequence validations to allow nested brackets
This commit is contained in:
parent
b415e94e19
commit
79d9d5bf0d
@ -78,6 +78,8 @@
|
|||||||
#include <range/v3/view/map.hpp>
|
#include <range/v3/view/map.hpp>
|
||||||
#include <range/v3/action/remove.hpp>
|
#include <range/v3/action/remove.hpp>
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::yul;
|
using namespace solidity::yul;
|
||||||
@ -269,7 +271,7 @@ map<char, string> const& OptimiserSuite::stepAbbreviationToNameMap()
|
|||||||
|
|
||||||
void OptimiserSuite::validateSequence(string const& _stepAbbreviations)
|
void OptimiserSuite::validateSequence(string const& _stepAbbreviations)
|
||||||
{
|
{
|
||||||
bool insideLoop = false;
|
int8_t nestingLevel = 0;
|
||||||
for (char abbreviation: _stepAbbreviations)
|
for (char abbreviation: _stepAbbreviations)
|
||||||
switch (abbreviation)
|
switch (abbreviation)
|
||||||
{
|
{
|
||||||
@ -277,12 +279,12 @@ void OptimiserSuite::validateSequence(string const& _stepAbbreviations)
|
|||||||
case '\n':
|
case '\n':
|
||||||
break;
|
break;
|
||||||
case '[':
|
case '[':
|
||||||
assertThrow(!insideLoop, OptimizerException, "Nested brackets are not supported");
|
assertThrow(nestingLevel < numeric_limits<int8_t>::max(), OptimizerException, "Brackets nested too deep");
|
||||||
insideLoop = true;
|
nestingLevel++;
|
||||||
break;
|
break;
|
||||||
case ']':
|
case ']':
|
||||||
assertThrow(insideLoop, OptimizerException, "Unbalanced brackets");
|
nestingLevel--;
|
||||||
insideLoop = false;
|
assertThrow(nestingLevel >= 0, OptimizerException, "Unbalanced brackets");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
@ -301,10 +303,9 @@ void OptimiserSuite::validateSequence(string const& _stepAbbreviations)
|
|||||||
OptimizerException,
|
OptimizerException,
|
||||||
"'"s + abbreviation + "' is invalid in the current environment: " + *invalid
|
"'"s + abbreviation + "' is invalid in the current environment: " + *invalid
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertThrow(!insideLoop, OptimizerException, "Unbalanced brackets");
|
assertThrow(nestingLevel == 0, OptimizerException, "Unbalanced brackets");
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptimiserSuite::runSequence(string const& _stepAbbreviations, Block& _ast)
|
void OptimiserSuite::runSequence(string const& _stepAbbreviations, Block& _ast)
|
||||||
|
Loading…
Reference in New Issue
Block a user