From e3641b88ec59895762dbb649830da5aea4a94a5e Mon Sep 17 00:00:00 2001 From: a3d4 Date: Sat, 18 Apr 2020 03:00:22 +0200 Subject: [PATCH] Groundwork. Prepare for automatic tagging [Not compilable until the next commit] --- liblangutil/ErrorReporter.cpp | 65 +++++++++++++-------- liblangutil/ErrorReporter.h | 46 ++++++++++----- libsolidity/analysis/ConstantEvaluator.cpp | 1 + libsolidity/analysis/ImmutableValidator.cpp | 1 + libsolidity/analysis/SyntaxChecker.cpp | 2 +- libsolidity/parsing/Parser.cpp | 2 +- 6 files changed, 76 insertions(+), 41 deletions(-) diff --git a/liblangutil/ErrorReporter.cpp b/liblangutil/ErrorReporter.cpp index c6c059bc7..d06fbc65b 100644 --- a/liblangutil/ErrorReporter.cpp +++ b/liblangutil/ErrorReporter.cpp @@ -28,6 +28,8 @@ using namespace std; using namespace solidity; using namespace solidity::langutil; +ErrorId solidity::langutil::operator"" _error(unsigned long long _error) { return ErrorId{ _error }; } + ErrorReporter& ErrorReporter::operator=(ErrorReporter const& _errorReporter) { if (&_errorReporter == this) @@ -36,30 +38,31 @@ ErrorReporter& ErrorReporter::operator=(ErrorReporter const& _errorReporter) return *this; } - -void ErrorReporter::warning(string const& _description) +void ErrorReporter::warning(ErrorId _error, string const& _description) { - error(Error::Type::Warning, SourceLocation(), _description); + error(_error, Error::Type::Warning, SourceLocation(), _description); } void ErrorReporter::warning( + ErrorId _error, SourceLocation const& _location, string const& _description ) { - error(Error::Type::Warning, _location, _description); + error(_error, Error::Type::Warning, _location, _description); } void ErrorReporter::warning( + ErrorId _error, SourceLocation const& _location, string const& _description, 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)) return; @@ -72,7 +75,7 @@ void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, st 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)) return; @@ -123,15 +126,15 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type) 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()); } -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()); } @@ -145,9 +148,10 @@ void ErrorReporter::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::Type::DeclarationError, _location, _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::Type::DeclarationError, _location, _description ); } -void ErrorReporter::fatalDeclarationError(SourceLocation const& _location, std::string const& _description) +void ErrorReporter::fatalDeclarationError(ErrorId _error, SourceLocation const& _location, std::string const& _description) { fatalError( + _error, Error::Type::DeclarationError, _location, _description); } -void ErrorReporter::parserError(SourceLocation const& _location, string const& _description) +void ErrorReporter::parserError(ErrorId _error, SourceLocation const& _location, string const& _description) { error( + _error, Error::Type::ParserError, _location, _description ); } -void ErrorReporter::fatalParserError(SourceLocation const& _location, string const& _description) +void ErrorReporter::fatalParserError(ErrorId _error, SourceLocation const& _location, string const& _description) { fatalError( + _error, Error::Type::ParserError, _location, _description ); } -void ErrorReporter::syntaxError(SourceLocation const& _location, string const& _description) +void ErrorReporter::syntaxError(ErrorId _error, SourceLocation const& _location, string const& _description) { error( + _error, Error::Type::SyntaxError, _location, _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::Type::TypeError, _location, _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::Type::TypeError, _location, _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( + _error, Error::Type::TypeError, _location, _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, _description ); } -void ErrorReporter::docstringParsingError(string const& _description) +void ErrorReporter::docstringParsingError(ErrorId _error, string const& _description) { error( + _error, Error::Type::DocstringParsingError, SourceLocation(), _description ); } -void ErrorReporter::docstringParsingError(SourceLocation const& _location, string const& _description) +void ErrorReporter::docstringParsingError(ErrorId _error, SourceLocation const& _location, string const& _description) { error( + _error, Error::Type::DocstringParsingError, _location, _description diff --git a/liblangutil/ErrorReporter.h b/liblangutil/ErrorReporter.h index 5aca4beb9..17e236e61 100644 --- a/liblangutil/ErrorReporter.h +++ b/liblangutil/ErrorReporter.h @@ -33,6 +33,15 @@ 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 { public: @@ -50,64 +59,68 @@ public: 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( + ErrorId _error, SourceLocation const& _location, std::string const& _description, SecondarySourceLocation const& _secondaryLocation ); void error( + ErrorId _error, Error::Type _type, SourceLocation const& _location, std::string const& _description ); void declarationError( + ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, 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( + ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation = SecondarySourceLocation(), 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 - void typeErrorConcatenateDescriptions(SourceLocation const& _location, Strings const&... _descriptions) + void typeErrorConcatenateDescriptions(ErrorId _error, SourceLocation const& _location, Strings const&... _descriptions) { - std::initializer_list const descs = {_descriptions...}; + std::initializer_list const descs = { _descriptions... }; solAssert(descs.size() > 0, "Need error descriptions!"); auto filterEmpty = boost::adaptors::filtered([](std::string const& _s) { return !_s.empty(); }); 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(SourceLocation const& _location, SecondarySourceLocation const& _secondLocation, std::string const& _description); + void fatalTypeError(ErrorId _error, SourceLocation const& _location, 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(SourceLocation const& _location, std::string const& _description); + void docstringParsingError(ErrorId _error, std::string const& _description); + void docstringParsingError(ErrorId _error, SourceLocation const& _location, std::string const& _description); ErrorList const& errors() const; @@ -124,18 +137,21 @@ public: private: void error( + ErrorId _error, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description = std::string()); void fatalError( + ErrorId _error, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description = std::string()); void fatalError( + ErrorId _error, Error::Type _type, SourceLocation const& _location = SourceLocation(), std::string const& _description = std::string()); diff --git a/libsolidity/analysis/ConstantEvaluator.cpp b/libsolidity/analysis/ConstantEvaluator.cpp index d48d640ce..7617cc518 100644 --- a/libsolidity/analysis/ConstantEvaluator.cpp +++ b/libsolidity/analysis/ConstantEvaluator.cpp @@ -29,6 +29,7 @@ using namespace std; using namespace solidity; using namespace solidity::frontend; +using namespace solidity::langutil; void ConstantEvaluator::endVisit(UnaryOperation const& _operation) { diff --git a/libsolidity/analysis/ImmutableValidator.cpp b/libsolidity/analysis/ImmutableValidator.cpp index 598f43e50..a63d38ccf 100644 --- a/libsolidity/analysis/ImmutableValidator.cpp +++ b/libsolidity/analysis/ImmutableValidator.cpp @@ -22,6 +22,7 @@ #include using namespace solidity::frontend; +using namespace solidity::langutil; void ImmutableValidator::analyze() { diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index c9ad29d33..bd2060d6a 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -123,7 +123,7 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma) m_errorReporter.syntaxError( _pragma.location(), "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" ); m_versionPragmaFound = true; diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index c6da9a55b..d3c4a2cdd 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -130,7 +130,7 @@ void Parser::parsePragmaVersion(SourceLocation const& _location, vector c m_errorReporter.fatalParserError( _location, "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" ); }