mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Groundwork. Prepare for automatic tagging
[Not compilable until the next commit]
This commit is contained in:
parent
4c1e821e01
commit
e3641b88ec
@ -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
|
||||
|
@ -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 <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!");
|
||||
|
||||
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());
|
||||
|
@ -29,6 +29,7 @@
|
||||
using namespace std;
|
||||
using namespace solidity;
|
||||
using namespace solidity::frontend;
|
||||
using namespace solidity::langutil;
|
||||
|
||||
void ConstantEvaluator::endVisit(UnaryOperation const& _operation)
|
||||
{
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
|
||||
using namespace solidity::frontend;
|
||||
using namespace solidity::langutil;
|
||||
|
||||
void ImmutableValidator::analyze()
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -130,7 +130,7 @@ void Parser::parsePragmaVersion(SourceLocation const& _location, vector<Token> 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"
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user