Merge pull request #1229 from ethereum/lll-error-reporting

LLL: better error reporting
This commit is contained in:
chriseth 2016-10-17 14:16:41 +02:00 committed by GitHub
commit 07d32937fd
5 changed files with 38 additions and 16 deletions

View File

@ -52,17 +52,18 @@ void CodeFragment::finalise(CompilerState const& _cs)
CodeFragment::CodeFragment(sp::utree const& _t, CompilerState& _s, bool _allowASM) CodeFragment::CodeFragment(sp::utree const& _t, CompilerState& _s, bool _allowASM)
{ {
/* cdebug << "CodeFragment. Locals:"; /*
std::cout << "CodeFragment. Locals:";
for (auto const& i: _s.defs) for (auto const& i: _s.defs)
cdebug << i.first << ":" << toHex(i.second.m_code); std::cout << i.first << ":" << i.second.m_asm.out();
cdebug << "Args:"; std::cout << "Args:";
for (auto const& i: _s.args) for (auto const& i: _s.args)
cdebug << i.first << ":" << toHex(i.second.m_code); std::cout << i.first << ":" << i.second.m_asm.out();
cdebug << "Outers:"; std::cout << "Outers:";
for (auto const& i: _s.outers) for (auto const& i: _s.outers)
cdebug << i.first << ":" << toHex(i.second.m_code); std::cout << i.first << ":" << i.second.m_asm.out();
debugOutAST(cout, _t); debugOutAST(std::cout, _t);
cout << endl << flush; std::cout << endl << flush;
*/ */
switch (_t.which()) switch (_t.which())
{ {

View File

@ -45,13 +45,21 @@ bytes dev::eth::compileLLL(string const& _src, bool _opt, vector<string>* _error
if (_errors) if (_errors)
{ {
_errors->push_back("Parse error."); _errors->push_back("Parse error.");
_errors->push_back(diagnostic_information(_e)); _errors->push_back(boost::diagnostic_information(_e));
} }
} }
catch (std::exception) catch (std::exception const& _e)
{ {
if (_errors) if (_errors)
_errors->push_back("Parse error."); {
_errors->push_back("Parse exception.");
_errors->push_back(boost::diagnostic_information(_e));
}
}
catch (...)
{
if (_errors)
_errors->push_back("Internal parse exception.");
} }
return bytes(); return bytes();
} }
@ -70,12 +78,22 @@ std::string dev::eth::compileLLLToAsm(std::string const& _src, bool _opt, std::v
catch (Exception const& _e) catch (Exception const& _e)
{ {
if (_errors) if (_errors)
_errors->push_back(diagnostic_information(_e)); {
_errors->push_back("Parse error.");
_errors->push_back(boost::diagnostic_information(_e));
}
} }
catch (std::exception) catch (std::exception const& _e)
{
if (_errors) {
_errors->push_back("Parse exception.");
_errors->push_back(boost::diagnostic_information(_e));
}
}
catch (...)
{ {
if (_errors) if (_errors)
_errors->push_back("Parse error."); _errors->push_back("Internal parse exception.");
} }
return string(); return string();
} }

View File

@ -39,6 +39,7 @@ class InvalidName: public CompilerException {};
class InvalidMacroArgs: public CompilerException {}; class InvalidMacroArgs: public CompilerException {};
class InvalidLiteral: public CompilerException {}; class InvalidLiteral: public CompilerException {};
class BareSymbol: public CompilerException {}; class BareSymbol: public CompilerException {};
class ParserException: public CompilerException {};
} }
} }

View File

@ -143,7 +143,8 @@ void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out)
auto ret = s.cbegin(); auto ret = s.cbegin();
qi::phrase_parse(ret, s.cend(), element, space, qi::skip_flag::dont_postskip, o_out); qi::phrase_parse(ret, s.cend(), element, space, qi::skip_flag::dont_postskip, o_out);
for (auto i = ret; i != s.cend(); ++i) for (auto i = ret; i != s.cend(); ++i)
if (!isspace(*i)) if (!isspace(*i)) {
BOOST_THROW_EXCEPTION(std::exception()); BOOST_THROW_EXCEPTION(ParserException() << errinfo_comment("Non-whitespace left in parser"));
}
} }

View File

@ -24,6 +24,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include "Exceptions.h"
namespace boost { namespace spirit { class utree; } } namespace boost { namespace spirit { class utree; } }
namespace sp = boost::spirit; namespace sp = boost::spirit;