mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Simplify disambiguator.
This commit is contained in:
parent
cba58629d2
commit
30d7afc2e3
@ -31,11 +31,6 @@ using namespace dev;
|
|||||||
using namespace dev::julia;
|
using namespace dev::julia;
|
||||||
|
|
||||||
|
|
||||||
shared_ptr<Block> ASTCopier::run()
|
|
||||||
{
|
|
||||||
return make_shared<Block>(translate(m_block));
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement ASTCopier::operator()(Instruction const& _instruction)
|
Statement ASTCopier::operator()(Instruction const& _instruction)
|
||||||
{
|
{
|
||||||
return _instruction;
|
return _instruction;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
@ -39,13 +40,6 @@ namespace julia
|
|||||||
*/
|
*/
|
||||||
class ASTCopier: public boost::static_visitor<Statement>
|
class ASTCopier: public boost::static_visitor<Statement>
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
ASTCopier(Block const& _block):
|
|
||||||
m_block(_block)
|
|
||||||
{}
|
|
||||||
|
|
||||||
std::shared_ptr<Block> run();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Statement operator()(Literal const& _literal);
|
Statement operator()(Literal const& _literal);
|
||||||
Statement operator()(Instruction const& _instruction);
|
Statement operator()(Instruction const& _instruction);
|
||||||
@ -78,13 +72,11 @@ protected:
|
|||||||
Literal translate(Literal const& _literal);
|
Literal translate(Literal const& _literal);
|
||||||
TypedName translate(TypedName const& _typedName);
|
TypedName translate(TypedName const& _typedName);
|
||||||
|
|
||||||
virtual void enterScope(Block const& _block) = 0;
|
virtual void enterScope(Block const&) { }
|
||||||
virtual void leaveScope(Block const& _block) = 0;
|
virtual void leaveScope(Block const&) { }
|
||||||
virtual void enterFunction(FunctionDefinition const& _function) = 0;
|
virtual void enterFunction(FunctionDefinition const&) { }
|
||||||
virtual void leaveFunction(FunctionDefinition const& _function) = 0;
|
virtual void leaveFunction(FunctionDefinition const&) { }
|
||||||
virtual std::string translateIdentifier(std::string const& _name) { return _name; }
|
virtual std::string translateIdentifier(std::string const& _name) { return _name; }
|
||||||
|
|
||||||
Block const& m_block;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -43,10 +43,8 @@ class EVMAssembly;
|
|||||||
class Disambiguator: public ASTCopier
|
class Disambiguator: public ASTCopier
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Disambiguator(
|
Disambiguator(solidity::assembly::AsmAnalysisInfo const& _analysisInfo):
|
||||||
Block const& _block,
|
m_info(_analysisInfo)
|
||||||
solidity::assembly::AsmAnalysisInfo const& _analysisInfo
|
|
||||||
): ASTCopier(_block), m_info(_analysisInfo)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -55,12 +55,12 @@ pair<shared_ptr<Block>, shared_ptr<assembly::AsmAnalysisInfo>> dev::julia::test:
|
|||||||
ErrorList errors;
|
ErrorList errors;
|
||||||
ErrorReporter errorReporter(errors);
|
ErrorReporter errorReporter(errors);
|
||||||
auto scanner = make_shared<Scanner>(CharStream(_source), "");
|
auto scanner = make_shared<Scanner>(CharStream(_source), "");
|
||||||
auto parserResult = assembly::Parser(errorReporter, true).parse(scanner);
|
auto parserResult = assembly::Parser(errorReporter, _julia).parse(scanner);
|
||||||
if (parserResult)
|
if (parserResult)
|
||||||
{
|
{
|
||||||
BOOST_REQUIRE(errorReporter.errors().empty());
|
BOOST_REQUIRE(errorReporter.errors().empty());
|
||||||
auto analysisInfo = make_shared<assembly::AsmAnalysisInfo>();
|
auto analysisInfo = make_shared<assembly::AsmAnalysisInfo>();
|
||||||
assembly::AsmAnalyzer analyzer(*analysisInfo, errorReporter, true);
|
assembly::AsmAnalyzer analyzer(*analysisInfo, errorReporter, _julia);
|
||||||
if (analyzer.analyze(*parserResult))
|
if (analyzer.analyze(*parserResult))
|
||||||
{
|
{
|
||||||
BOOST_REQUIRE(errorReporter.errors().empty());
|
BOOST_REQUIRE(errorReporter.errors().empty());
|
||||||
@ -74,14 +74,13 @@ pair<shared_ptr<Block>, shared_ptr<assembly::AsmAnalysisInfo>> dev::julia::test:
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<assembly::Block> dev::julia::test::disambiguate(string const& _source)
|
assembly::Block dev::julia::test::disambiguate(string const& _source, bool _julia)
|
||||||
{
|
{
|
||||||
auto result = parse(_source);
|
auto result = parse(_source, _julia);
|
||||||
Disambiguator disambiguator(*result.first, *result.second);
|
return boost::get<Block>(Disambiguator(*result.second)(*result.first));
|
||||||
return disambiguator.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string dev::julia::test::format(string const& _source)
|
string dev::julia::test::format(string const& _source, bool _julia)
|
||||||
{
|
{
|
||||||
return assembly::AsmPrinter(_julia)(*parse(_source, _julia).first);
|
return assembly::AsmPrinter(_julia)(*parse(_source, _julia).first);
|
||||||
}
|
}
|
||||||
|
@ -45,9 +45,10 @@ namespace test
|
|||||||
{
|
{
|
||||||
|
|
||||||
void printErrors(solidity::ErrorList const& _errors, solidity::Scanner const& _scanner);
|
void printErrors(solidity::ErrorList const& _errors, solidity::Scanner const& _scanner);
|
||||||
std::pair<std::shared_ptr<solidity::assembly::Block>, std::shared_ptr<solidity::assembly::AsmAnalysisInfo>> parse(std::string const& _source);
|
std::pair<std::shared_ptr<solidity::assembly::Block>, std::shared_ptr<solidity::assembly::AsmAnalysisInfo>>
|
||||||
std::shared_ptr<solidity::assembly::Block> disambiguate(std::string const& _source);
|
parse(std::string const& _source, bool _julia = true);
|
||||||
std::string format(std::string const& _source);
|
solidity::assembly::Block disambiguate(std::string const& _source, bool _julia = true);
|
||||||
|
std::string format(std::string const& _source, bool _julia = true);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,9 @@ using namespace dev::solidity;
|
|||||||
do\
|
do\
|
||||||
{\
|
{\
|
||||||
assembly::AsmPrinter p(true);\
|
assembly::AsmPrinter p(true);\
|
||||||
string result = p(*disambiguate(_original));\
|
string result = p(disambiguate(_original));\
|
||||||
BOOST_CHECK_EQUAL(result, format(_expectation));\
|
BOOST_CHECK_EQUAL(result, format(_expectation));\
|
||||||
BOOST_CHECK_EQUAL(result, p(*disambiguate(result)));\
|
BOOST_CHECK_EQUAL(result, p(disambiguate(result)));\
|
||||||
}\
|
}\
|
||||||
while(false)
|
while(false)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user