Groundwork. Prepare for automatic tagging

[Not compilable until the next commit]
This commit is contained in:
a3d4 2020-04-18 03:00:22 +02:00 committed by a3d4
parent 4c1e821e01
commit e3641b88ec
6 changed files with 76 additions and 41 deletions

View File

@ -28,6 +28,8 @@ using namespace std;
using namespace solidity; using namespace solidity;
using namespace solidity::langutil; using namespace solidity::langutil;
ErrorId solidity::langutil::operator"" _error(unsigned long long _error) { return ErrorId{ _error }; }
ErrorReporter& ErrorReporter::operator=(ErrorReporter const& _errorReporter) ErrorReporter& ErrorReporter::operator=(ErrorReporter const& _errorReporter)
{ {
if (&_errorReporter == this) if (&_errorReporter == this)
@ -36,30 +38,31 @@ ErrorReporter& ErrorReporter::operator=(ErrorReporter const& _errorReporter)
return *this; return *this;
} }
void ErrorReporter::warning(ErrorId _error, string const& _description)
void ErrorReporter::warning(string const& _description)
{ {
error(Error::Type::Warning, SourceLocation(), _description); error(_error, Error::Type::Warning, SourceLocation(), _description);
} }
void ErrorReporter::warning( void ErrorReporter::warning(
ErrorId _error,
SourceLocation const& _location, SourceLocation const& _location,
string const& _description string const& _description
) )
{ {
error(Error::Type::Warning, _location, _description); error(_error, Error::Type::Warning, _location, _description);
} }
void ErrorReporter::warning( void ErrorReporter::warning(
ErrorId _error,
SourceLocation const& _location, SourceLocation const& _location,
string const& _description, string const& _description,
SecondarySourceLocation const& _secondaryLocation SecondarySourceLocation const& _secondaryLocation
) )
{ {
error(Error::Type::Warning, _location, _secondaryLocation, _description); error(_error, Error::Type::Warning, _location, _secondaryLocation, _description);
} }
void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, string const& _description) void ErrorReporter::error(ErrorId, Error::Type _type, SourceLocation const& _location, string const& _description)
{ {
if (checkForExcessiveErrors(_type)) if (checkForExcessiveErrors(_type))
return; return;
@ -72,7 +75,7 @@ void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, st
m_errorList.push_back(err); m_errorList.push_back(err);
} }
void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description) void ErrorReporter::error(ErrorId, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
{ {
if (checkForExcessiveErrors(_type)) if (checkForExcessiveErrors(_type))
return; return;
@ -123,15 +126,15 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
return false; return false;
} }
void ErrorReporter::fatalError(Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description) void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
{ {
error(_type, _location, _secondaryLocation, _description); error(_error, _type, _location, _secondaryLocation, _description);
BOOST_THROW_EXCEPTION(FatalError()); BOOST_THROW_EXCEPTION(FatalError());
} }
void ErrorReporter::fatalError(Error::Type _type, SourceLocation const& _location, string const& _description) void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, string const& _description)
{ {
error(_type, _location, _description); error(_error, _type, _location, _description);
BOOST_THROW_EXCEPTION(FatalError()); BOOST_THROW_EXCEPTION(FatalError());
} }
@ -145,9 +148,10 @@ void ErrorReporter::clear()
m_errorList.clear(); m_errorList.clear();
} }
void ErrorReporter::declarationError(SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description) void ErrorReporter::declarationError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
{ {
error( error(
_error,
Error::Type::DeclarationError, Error::Type::DeclarationError,
_location, _location,
_secondaryLocation, _secondaryLocation,
@ -155,53 +159,59 @@ void ErrorReporter::declarationError(SourceLocation const& _location, SecondaryS
); );
} }
void ErrorReporter::declarationError(SourceLocation const& _location, string const& _description) void ErrorReporter::declarationError(ErrorId _error, SourceLocation const& _location, string const& _description)
{ {
error( error(
_error,
Error::Type::DeclarationError, Error::Type::DeclarationError,
_location, _location,
_description _description
); );
} }
void ErrorReporter::fatalDeclarationError(SourceLocation const& _location, std::string const& _description) void ErrorReporter::fatalDeclarationError(ErrorId _error, SourceLocation const& _location, std::string const& _description)
{ {
fatalError( fatalError(
_error,
Error::Type::DeclarationError, Error::Type::DeclarationError,
_location, _location,
_description); _description);
} }
void ErrorReporter::parserError(SourceLocation const& _location, string const& _description) void ErrorReporter::parserError(ErrorId _error, SourceLocation const& _location, string const& _description)
{ {
error( error(
_error,
Error::Type::ParserError, Error::Type::ParserError,
_location, _location,
_description _description
); );
} }
void ErrorReporter::fatalParserError(SourceLocation const& _location, string const& _description) void ErrorReporter::fatalParserError(ErrorId _error, SourceLocation const& _location, string const& _description)
{ {
fatalError( fatalError(
_error,
Error::Type::ParserError, Error::Type::ParserError,
_location, _location,
_description _description
); );
} }
void ErrorReporter::syntaxError(SourceLocation const& _location, string const& _description) void ErrorReporter::syntaxError(ErrorId _error, SourceLocation const& _location, string const& _description)
{ {
error( error(
_error,
Error::Type::SyntaxError, Error::Type::SyntaxError,
_location, _location,
_description _description
); );
} }
void ErrorReporter::typeError(SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description) void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
{ {
error( error(
_error,
Error::Type::TypeError, Error::Type::TypeError,
_location, _location,
_secondaryLocation, _secondaryLocation,
@ -209,18 +219,21 @@ void ErrorReporter::typeError(SourceLocation const& _location, SecondarySourceLo
); );
} }
void ErrorReporter::typeError(SourceLocation const& _location, string const& _description) void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, string const& _description)
{ {
error( error(
_error,
Error::Type::TypeError, Error::Type::TypeError,
_location, _location,
_description _description
); );
} }
void ErrorReporter::fatalTypeError(SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
{ {
fatalError( fatalError(
_error,
Error::Type::TypeError, Error::Type::TypeError,
_location, _location,
_secondaryLocation, _secondaryLocation,
@ -228,26 +241,30 @@ void ErrorReporter::fatalTypeError(SourceLocation const& _location, SecondarySou
); );
} }
void ErrorReporter::fatalTypeError(SourceLocation const& _location, string const& _description) void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _location, string const& _description)
{ {
fatalError(Error::Type::TypeError, fatalError(
_error,
Error::Type::TypeError,
_location, _location,
_description _description
); );
} }
void ErrorReporter::docstringParsingError(string const& _description) void ErrorReporter::docstringParsingError(ErrorId _error, string const& _description)
{ {
error( error(
_error,
Error::Type::DocstringParsingError, Error::Type::DocstringParsingError,
SourceLocation(), SourceLocation(),
_description _description
); );
} }
void ErrorReporter::docstringParsingError(SourceLocation const& _location, string const& _description) void ErrorReporter::docstringParsingError(ErrorId _error, SourceLocation const& _location, string const& _description)
{ {
error( error(
_error,
Error::Type::DocstringParsingError, Error::Type::DocstringParsingError,
_location, _location,
_description _description

View File

@ -33,6 +33,15 @@
namespace solidity::langutil namespace solidity::langutil
{ {
/**
* Unique identifiers are used to tag and track individual error cases.
* They are passed as the first parameter of error reporting functions.
* Suffix _error helps to find them in the sources.
* The struct ErrorId prevents incidental calls like typeError(3141) instead of typeError(3141_error).
*/
struct ErrorId { unsigned long long error = 0; };
ErrorId operator"" _error(unsigned long long error);
class ErrorReporter class ErrorReporter
{ {
public: public:
@ -50,64 +59,68 @@ public:
m_errorList += _errorList; m_errorList += _errorList;
} }
void warning(std::string const& _description); void warning(ErrorId _error, std::string const& _description);
void warning(SourceLocation const& _location, std::string const& _description); void warning(ErrorId _error, SourceLocation const& _location, std::string const& _description);
void warning( void warning(
ErrorId _error,
SourceLocation const& _location, SourceLocation const& _location,
std::string const& _description, std::string const& _description,
SecondarySourceLocation const& _secondaryLocation SecondarySourceLocation const& _secondaryLocation
); );
void error( void error(
ErrorId _error,
Error::Type _type, Error::Type _type,
SourceLocation const& _location, SourceLocation const& _location,
std::string const& _description std::string const& _description
); );
void declarationError( void declarationError(
ErrorId _error,
SourceLocation const& _location, SourceLocation const& _location,
SecondarySourceLocation const& _secondaryLocation, SecondarySourceLocation const& _secondaryLocation,
std::string const& _description std::string const& _description
); );
void declarationError(SourceLocation const& _location, std::string const& _description); void declarationError(ErrorId _error, SourceLocation const& _location, std::string const& _description);
void fatalDeclarationError(SourceLocation const& _location, std::string const& _description); void fatalDeclarationError(ErrorId _error, SourceLocation const& _location, std::string const& _description);
void parserError(SourceLocation const& _location, std::string const& _description); void parserError(ErrorId _error, SourceLocation const& _location, std::string const& _description);
void fatalParserError(SourceLocation const& _location, std::string const& _description); void fatalParserError(ErrorId _error, SourceLocation const& _location, std::string const& _description);
void syntaxError(SourceLocation const& _location, std::string const& _description); void syntaxError(ErrorId _error, SourceLocation const& _location, std::string const& _description);
void typeError( void typeError(
ErrorId _error,
SourceLocation const& _location, SourceLocation const& _location,
SecondarySourceLocation const& _secondaryLocation = SecondarySourceLocation(), SecondarySourceLocation const& _secondaryLocation = SecondarySourceLocation(),
std::string const& _description = std::string() std::string const& _description = std::string()
); );
void typeError(SourceLocation const& _location, std::string const& _description); void typeError(ErrorId _error, SourceLocation const& _location, std::string const& _description);
template <typename... Strings> template <typename... Strings>
void typeErrorConcatenateDescriptions(SourceLocation const& _location, Strings const&... _descriptions) void typeErrorConcatenateDescriptions(ErrorId _error, SourceLocation const& _location, Strings const&... _descriptions)
{ {
std::initializer_list<std::string> const descs = {_descriptions...}; std::initializer_list<std::string> const descs = { _descriptions... };
solAssert(descs.size() > 0, "Need error descriptions!"); solAssert(descs.size() > 0, "Need error descriptions!");
auto filterEmpty = boost::adaptors::filtered([](std::string const& _s) { return !_s.empty(); }); auto filterEmpty = boost::adaptors::filtered([](std::string const& _s) { return !_s.empty(); });
std::string errorStr = util::joinHumanReadable(descs | filterEmpty, " "); std::string errorStr = util::joinHumanReadable(descs | filterEmpty, " ");
error(Error::Type::TypeError, _location, errorStr); error(_error, Error::Type::TypeError, _location, errorStr);
} }
void fatalTypeError(SourceLocation const& _location, std::string const& _description); void fatalTypeError(ErrorId _error, SourceLocation const& _location, std::string const& _description);
void fatalTypeError(SourceLocation const& _location, SecondarySourceLocation const& _secondLocation, std::string const& _description); void fatalTypeError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondLocation, std::string const& _description);
void docstringParsingError(std::string const& _description); void docstringParsingError(ErrorId _error, std::string const& _description);
void docstringParsingError(SourceLocation const& _location, std::string const& _description); void docstringParsingError(ErrorId _error, SourceLocation const& _location, std::string const& _description);
ErrorList const& errors() const; ErrorList const& errors() const;
@ -124,18 +137,21 @@ public:
private: private:
void error( void error(
ErrorId _error,
Error::Type _type, Error::Type _type,
SourceLocation const& _location, SourceLocation const& _location,
SecondarySourceLocation const& _secondaryLocation, SecondarySourceLocation const& _secondaryLocation,
std::string const& _description = std::string()); std::string const& _description = std::string());
void fatalError( void fatalError(
ErrorId _error,
Error::Type _type, Error::Type _type,
SourceLocation const& _location, SourceLocation const& _location,
SecondarySourceLocation const& _secondaryLocation, SecondarySourceLocation const& _secondaryLocation,
std::string const& _description = std::string()); std::string const& _description = std::string());
void fatalError( void fatalError(
ErrorId _error,
Error::Type _type, Error::Type _type,
SourceLocation const& _location = SourceLocation(), SourceLocation const& _location = SourceLocation(),
std::string const& _description = std::string()); std::string const& _description = std::string());

View File

@ -29,6 +29,7 @@
using namespace std; using namespace std;
using namespace solidity; using namespace solidity;
using namespace solidity::frontend; using namespace solidity::frontend;
using namespace solidity::langutil;
void ConstantEvaluator::endVisit(UnaryOperation const& _operation) void ConstantEvaluator::endVisit(UnaryOperation const& _operation)
{ {

View File

@ -22,6 +22,7 @@
#include <boost/range/adaptor/reversed.hpp> #include <boost/range/adaptor/reversed.hpp>
using namespace solidity::frontend; using namespace solidity::frontend;
using namespace solidity::langutil;
void ImmutableValidator::analyze() void ImmutableValidator::analyze()
{ {

View File

@ -123,7 +123,7 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma)
m_errorReporter.syntaxError( m_errorReporter.syntaxError(
_pragma.location(), _pragma.location(),
"Source file requires different compiler version (current compiler is " + "Source file requires different compiler version (current compiler is " +
string(VersionString) + " - note that nightly builds are considered to be " string(VersionString) + ") - note that nightly builds are considered to be "
"strictly less than the released version" "strictly less than the released version"
); );
m_versionPragmaFound = true; m_versionPragmaFound = true;

View File

@ -130,7 +130,7 @@ void Parser::parsePragmaVersion(SourceLocation const& _location, vector<Token> c
m_errorReporter.fatalParserError( m_errorReporter.fatalParserError(
_location, _location,
"Source file requires different compiler version (current compiler is " + "Source file requires different compiler version (current compiler is " +
string(VersionString) + " - note that nightly builds are considered to be " string(VersionString) + ") - note that nightly builds are considered to be "
"strictly less than the released version" "strictly less than the released version"
); );
} }