mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
fix: apply coding style suggestions
This commit is contained in:
parent
2549184205
commit
c2d2eec85c
@ -51,6 +51,7 @@
|
|||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
#include <range/v3/action/sort.hpp>
|
#include <range/v3/action/sort.hpp>
|
||||||
|
#include <range/v3/algorithm/find_if.hpp>
|
||||||
#include <range/v3/range/conversion.hpp>
|
#include <range/v3/range/conversion.hpp>
|
||||||
#include <range/v3/view/concat.hpp>
|
#include <range/v3/view/concat.hpp>
|
||||||
#include <range/v3/view/drop.hpp>
|
#include <range/v3/view/drop.hpp>
|
||||||
@ -100,10 +101,9 @@ public:
|
|||||||
const auto subObjectPath = _qualifiedPath.substr(_object->name.str().length() + 1);
|
const auto subObjectPath = _qualifiedPath.substr(_object->name.str().length() + 1);
|
||||||
const auto subObjectName = subObjectPath.substr(0, subObjectPath.find_first_of('.'));
|
const auto subObjectName = subObjectPath.substr(0, subObjectPath.find_first_of('.'));
|
||||||
|
|
||||||
auto subObjectIt = find_if(
|
auto subObjectIt = ranges::find_if(
|
||||||
_object->subObjects.begin(),
|
_object->subObjects,
|
||||||
_object->subObjects.end(),
|
[subObjectName](auto const& _subObject) { return _subObject->name.str() == subObjectName; }
|
||||||
[subObjectName](auto const& subObject) { return subObject->name.str() == subObjectName; }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
yulAssert(
|
yulAssert(
|
||||||
@ -125,13 +125,13 @@ public:
|
|||||||
{
|
{
|
||||||
ErrorList errors;
|
ErrorList errors;
|
||||||
ErrorReporter errorReporter(errors);
|
ErrorReporter errorReporter(errors);
|
||||||
CharStream _charStream(_input, "");
|
CharStream charStream(_input, "");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ObjectParser parser(errorReporter, m_dialect);
|
ObjectParser parser(errorReporter, m_dialect);
|
||||||
|
|
||||||
auto scanner = make_shared<Scanner>(_charStream);
|
auto scanner = make_shared<Scanner>(charStream);
|
||||||
|
|
||||||
if (!m_inputWasCodeBlock && scanner->currentToken() == Token::LBrace)
|
if (!m_inputWasCodeBlock && scanner->currentToken() == Token::LBrace)
|
||||||
m_inputWasCodeBlock = true;
|
m_inputWasCodeBlock = true;
|
||||||
@ -144,16 +144,16 @@ public:
|
|||||||
if (!m_object || !errorReporter.errors().empty())
|
if (!m_object || !errorReporter.errors().empty())
|
||||||
{
|
{
|
||||||
cerr << "Error parsing source." << endl;
|
cerr << "Error parsing source." << endl;
|
||||||
printErrors(_charStream, errors);
|
printErrors(charStream, errors);
|
||||||
throw std::runtime_error("Could not parse source.");
|
throw runtime_error("Could not parse source.");
|
||||||
}
|
}
|
||||||
|
|
||||||
analyze(errorReporter);
|
runCodeAnalyzer(errorReporter);
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
cerr << "Fatal error during parsing: " << endl;
|
cerr << "Fatal error during parsing: " << endl;
|
||||||
printErrors(_charStream, errors);
|
printErrors(charStream, errors);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ public:
|
|||||||
yulAssert(_columns > 0);
|
yulAssert(_columns > 0);
|
||||||
auto const& optimiserSteps = OptimiserSuite::stepAbbreviationToNameMap();
|
auto const& optimiserSteps = OptimiserSuite::stepAbbreviationToNameMap();
|
||||||
auto hasShorterString = [](auto const& a, auto const& b) { return a.second.size() < b.second.size(); };
|
auto hasShorterString = [](auto const& a, auto const& b) { return a.second.size() < b.second.size(); };
|
||||||
size_t longestDescriptionLength = std::max(
|
size_t longestDescriptionLength = max(
|
||||||
max_element(optimiserSteps.begin(), optimiserSteps.end(), hasShorterString)->second.size(),
|
max_element(optimiserSteps.begin(), optimiserSteps.end(), hasShorterString)->second.size(),
|
||||||
max_element(_extraOptions.begin(), _extraOptions.end(), hasShorterString)->second.size()
|
max_element(_extraOptions.begin(), _extraOptions.end(), hasShorterString)->second.size()
|
||||||
);
|
);
|
||||||
@ -207,66 +207,86 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void objectApply(shared_ptr<Object> _object, function<void(Object&)> _fn)
|
void objectApplyFunction(shared_ptr<Object> _object, function<void(Object&)> _fn)
|
||||||
{
|
{
|
||||||
for (auto const& subObjectNode: _object->subObjects) {
|
for (auto const& subObjectNode: _object->subObjects) {
|
||||||
auto subObject = dynamic_pointer_cast<Object>(subObjectNode);
|
auto subObject = dynamic_pointer_cast<Object>(subObjectNode);
|
||||||
|
|
||||||
if (subObject != nullptr)
|
if (subObject != nullptr)
|
||||||
objectApply(subObject, _fn);
|
objectApplyFunction(subObject, _fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
_fn(*_object);
|
_fn(*_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void analyze(ErrorReporter& errorReporter)
|
void runCodeAnalyzer(ErrorReporter& _errorReporter)
|
||||||
{
|
{
|
||||||
objectApply(m_object, [&](Object& object) {
|
objectApplyFunction(
|
||||||
object.analysisInfo = make_shared<yul::AsmAnalysisInfo>();
|
m_object,
|
||||||
|
[&](Object& _object)
|
||||||
|
{
|
||||||
|
_object.analysisInfo = make_shared<yul::AsmAnalysisInfo>();
|
||||||
|
|
||||||
AsmAnalyzer analyzer(
|
AsmAnalyzer analyzer(
|
||||||
*object.analysisInfo,
|
*_object.analysisInfo,
|
||||||
errorReporter,
|
_errorReporter,
|
||||||
m_dialect,
|
m_dialect,
|
||||||
{},
|
{},
|
||||||
object.qualifiedDataNames()
|
_object.qualifiedDataNames()
|
||||||
);
|
);
|
||||||
|
|
||||||
bool success = analyzer.analyze(*object.code);
|
bool success = analyzer.analyze(*_object.code);
|
||||||
yulAssert(success && !errorReporter.hasErrors(), "Invalid assembly/yul code.");
|
yulAssert(success && !_errorReporter.hasErrors(), "Invalid assembly/yul code.");
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void disambiguate()
|
void runCodeDisambiguator()
|
||||||
{
|
{
|
||||||
objectApply(m_object, [&](Object& object) {
|
objectApplyFunction(
|
||||||
object.code = make_shared<yul::Block>(
|
m_object,
|
||||||
std::get<yul::Block>(Disambiguator(m_dialect, *object.analysisInfo)(*object.code))
|
[&](Object& _object)
|
||||||
|
{
|
||||||
|
_object.code = make_shared<yul::Block>(
|
||||||
|
get<yul::Block>(Disambiguator(m_dialect, *_object.analysisInfo)(*_object.code))
|
||||||
);
|
);
|
||||||
|
|
||||||
object.analysisInfo.reset();
|
_object.analysisInfo.reset();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void runSequence(string_view _steps)
|
void runSequence(string_view _steps)
|
||||||
{
|
{
|
||||||
objectApply(m_object, [&](Object& object) {
|
objectApplyFunction(
|
||||||
OptimiserSuite{*m_context}.runSequence(_steps, *object.code);
|
m_object,
|
||||||
});
|
[&](Object& _object)
|
||||||
|
{
|
||||||
|
OptimiserSuite{*m_context}.runSequence(_steps, *_object.code);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void runVarNameCleaner()
|
void runVarNameCleaner()
|
||||||
{
|
{
|
||||||
objectApply(m_object, [&](Object& object) {
|
objectApplyFunction(
|
||||||
VarNameCleaner::run(*m_context, *object.code);
|
m_object,
|
||||||
});
|
[&](Object& _object)
|
||||||
|
{
|
||||||
|
VarNameCleaner::run(*m_context, *_object.code);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void runStackCompressor()
|
void runStackCompressor()
|
||||||
{
|
{
|
||||||
objectApply(m_object, [&](Object& object) {
|
objectApplyFunction(
|
||||||
StackCompressor::run(m_dialect, object, true, 16);
|
m_object,
|
||||||
});
|
[&](Object& _object)
|
||||||
|
{
|
||||||
|
StackCompressor::run(m_dialect, _object, true, 16);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void parseAndPrint(string _source, string _objectPath)
|
void parseAndPrint(string _source, string _objectPath)
|
||||||
@ -303,7 +323,7 @@ public:
|
|||||||
void runSteps(string _source, string _objectPath, string _steps)
|
void runSteps(string _source, string _objectPath, string _steps)
|
||||||
{
|
{
|
||||||
parse(_source, _objectPath);
|
parse(_source, _objectPath);
|
||||||
disambiguate();
|
runCodeDisambiguator();
|
||||||
runSequence(_steps);
|
runSequence(_steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +337,7 @@ public:
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
disambiguated = disambiguated || (disambiguate(), true);
|
disambiguated = disambiguated || (runCodeDisambiguator(), true);
|
||||||
|
|
||||||
map<char, string> const& extraOptions = {
|
map<char, string> const& extraOptions = {
|
||||||
// QUIT starts with a non-letter character on purpose to get it to show up on top of the list
|
// QUIT starts with a non-letter character on purpose to get it to show up on top of the list
|
||||||
@ -345,16 +365,14 @@ public:
|
|||||||
disambiguated = false;
|
disambiguated = false;
|
||||||
break;
|
break;
|
||||||
case ';':
|
case ';':
|
||||||
{
|
|
||||||
runStackCompressor();
|
runStackCompressor();
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
runSequence(std::string_view(&option, 1));
|
runSequence(string_view(&option, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
resetNameDispenser();
|
resetNameDispenser();
|
||||||
analyze(errorReporter);
|
runCodeAnalyzer(errorReporter);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user