Add new info severity

This commit is contained in:
Leo Alt
2021-09-13 22:48:22 +02:00
parent 49cde9d47b
commit e72fa7fc10
38 changed files with 191 additions and 97 deletions
+19
View File
@@ -94,6 +94,16 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
if (m_warningCount >= c_maxWarningsAllowed)
return true;
}
else if (_type == Error::Type::Info)
{
m_infoCount++;
if (m_infoCount == c_maxInfosAllowed)
m_errorList.push_back(make_shared<Error>(2833_error, Error::Type::Info, "There are more than 256 infos. Ignoring the rest."));
if (m_infoCount >= c_maxInfosAllowed)
return true;
}
else
{
m_errorCount++;
@@ -242,3 +252,12 @@ void ErrorReporter::docstringParsingError(ErrorId _error, SourceLocation const&
_description
);
}
void ErrorReporter::info(
ErrorId _error,
SourceLocation const& _location,
string const& _description
)
{
error(_error, Error::Type::Info, _location, _description);
}
+6 -2
View File
@@ -63,6 +63,8 @@ public:
SecondarySourceLocation const& _secondaryLocation
);
void info(ErrorId _error, SourceLocation const& _location, std::string const& _description);
void error(
ErrorId _error,
Error::Type _type,
@@ -118,13 +120,13 @@ public:
void clear();
/// @returns true iff there is any error (ignores warnings).
/// @returns true iff there is any error (ignores warnings and infos).
bool hasErrors() const
{
return m_errorCount > 0;
}
/// @returns the number of errors (ignores warnings).
/// @returns the number of errors (ignores warnings and infos).
unsigned errorCount() const
{
return m_errorCount;
@@ -183,9 +185,11 @@ private:
unsigned m_errorCount = 0;
unsigned m_warningCount = 0;
unsigned m_infoCount = 0;
unsigned const c_maxWarningsAllowed = 256;
unsigned const c_maxErrorsAllowed = 256;
unsigned const c_maxInfosAllowed = 256;
};
}
+3
View File
@@ -47,6 +47,9 @@ Error::Error(
case Type::DocstringParsingError:
m_typeName = "DocstringParsingError";
break;
case Type::Info:
m_typeName = "Info";
break;
case Type::ParserError:
m_typeName = "ParserError";
break;
+59 -9
View File
@@ -120,7 +120,15 @@ public:
ParserError,
TypeError,
SyntaxError,
Warning
Warning,
Info
};
enum class Severity
{
Error,
Warning,
Info
};
Error(
@@ -139,21 +147,63 @@ public:
static Error const* containsErrorOfType(ErrorList const& _list, Error::Type _type)
{
for (auto e: _list)
{
if (e->type() == _type)
return e.get();
}
return nullptr;
}
static bool containsOnlyWarnings(ErrorList const& _list)
static Severity errorSeverity(Type _type)
{
if (_type == Type::Info)
return Severity::Info;
if (_type == Type::Warning)
return Severity::Warning;
return Severity::Error;
}
static bool isError(Severity _severity)
{
return _severity == Severity::Error;
}
static bool isError(Type _type)
{
return isError(errorSeverity(_type));
}
static bool containsErrors(ErrorList const& _list)
{
for (auto e: _list)
{
if (e->type() != Type::Warning)
return false;
}
return true;
if (isError(e->type()))
return true;
return false;
}
static std::string formatErrorSeverity(Severity _severity)
{
if (_severity == Severity::Info)
return "Info";
if (_severity == Severity::Warning)
return "Warning";
solAssert(isError(_severity), "");
return "Error";
}
static std::string formatErrorSeverityLowercase(Severity _severity)
{
switch (_severity)
{
case Severity::Info:
return "info";
case Severity::Warning:
return "warning";
case Severity::Error:
solAssert(isError(_severity), "");
return "error";
}
solAssert(false, "");
}
private:
ErrorId m_errorId;
Type m_type;
+1 -1
View File
@@ -104,7 +104,7 @@ protected:
void fatalParserError(ErrorId _error, SourceLocation const& _location, std::string const& _description);
std::shared_ptr<Scanner> m_scanner;
/// The reference to the list of errors and warning to add errors/warnings during parsing
/// The reference to the list of errors, warnings and infos to add errors/warnings/infos during parsing
ErrorReporter& m_errorReporter;
/// Current recursion depth during parsing.
size_t m_recursionDepth = 0;
+4 -4
View File
@@ -30,7 +30,7 @@ using namespace solidity::langutil;
SourceReferenceExtractor::Message SourceReferenceExtractor::extract(
CharStreamProvider const& _charStreamProvider,
util::Exception const& _exception,
string _category
string _severity
)
{
SourceLocation const* location = boost::get_error_info<errinfo_sourceLocation>(_exception);
@@ -44,7 +44,7 @@ SourceReferenceExtractor::Message SourceReferenceExtractor::extract(
for (auto const& info: secondaryLocation->infos)
secondary.emplace_back(extract(_charStreamProvider, &info.second, info.first));
return Message{std::move(primary), _category, std::move(secondary), nullopt};
return Message{std::move(primary), _severity, std::move(secondary), nullopt};
}
SourceReferenceExtractor::Message SourceReferenceExtractor::extract(
@@ -52,8 +52,8 @@ SourceReferenceExtractor::Message SourceReferenceExtractor::extract(
Error const& _error
)
{
string category = (_error.type() == Error::Type::Warning) ? "Warning" : "Error";
Message message = extract(_charStreamProvider, _error, category);
string severity = Error::formatErrorSeverity(Error::errorSeverity(_error.type()));
Message message = extract(_charStreamProvider, _error, severity);
message.errorId = _error.errorId();
return message;
}
+3 -3
View File
@@ -41,7 +41,7 @@ struct LineColumn
struct SourceReference
{
std::string message; ///< A message that relates to this source reference (such as a warning or an error message).
std::string message; ///< A message that relates to this source reference (such as a warning, info or an error message).
std::string sourceName; ///< Underlying source name (for example the filename).
LineColumn position; ///< Actual (error) position this source reference is surrounding.
bool multiline = {false}; ///< Indicates whether the actual SourceReference is truncated to one line.
@@ -64,12 +64,12 @@ namespace SourceReferenceExtractor
struct Message
{
SourceReference primary;
std::string category; // "Error", "Warning", ...
std::string severity; // "Error", "Warning", "Info", ...
std::vector<SourceReference> secondary;
std::optional<ErrorId> errorId;
};
Message extract(CharStreamProvider const& _charStreamProvider, util::Exception const& _exception, std::string _category);
Message extract(CharStreamProvider const& _charStreamProvider, util::Exception const& _exception, std::string _severity);
Message extract(CharStreamProvider const& _charStreamProvider, Error const& _error);
SourceReference extract(CharStreamProvider const& _charStreamProvider, SourceLocation const* _location, std::string message = "");
}
+3 -3
View File
@@ -164,7 +164,7 @@ void SourceReferenceFormatter::printSourceLocation(SourceReference const& _ref)
void SourceReferenceFormatter::printExceptionInformation(SourceReferenceExtractor::Message const& _msg)
{
// exception header line
errorColored() << _msg.category;
errorColored() << _msg.severity;
if (m_withErrorIds && _msg.errorId.has_value())
errorColored() << " (" << _msg.errorId.value().error << ")";
messageColored() << ": " << _msg.primary.message << '\n';
@@ -181,9 +181,9 @@ void SourceReferenceFormatter::printExceptionInformation(SourceReferenceExtracto
m_stream << '\n';
}
void SourceReferenceFormatter::printExceptionInformation(util::Exception const& _exception, std::string const& _category)
void SourceReferenceFormatter::printExceptionInformation(util::Exception const& _exception, std::string const& _severity)
{
printExceptionInformation(SourceReferenceExtractor::extract(m_charStreamProvider, _exception, _category));
printExceptionInformation(SourceReferenceExtractor::extract(m_charStreamProvider, _exception, _severity));
}
void SourceReferenceFormatter::printErrorInformation(ErrorList const& _errors)
+2 -2
View File
@@ -52,7 +52,7 @@ public:
/// Prints source location if it is given.
void printSourceLocation(SourceReference const& _ref);
void printExceptionInformation(SourceReferenceExtractor::Message const& _msg);
void printExceptionInformation(util::Exception const& _exception, std::string const& _category);
void printExceptionInformation(util::Exception const& _exception, std::string const& _severity);
void printErrorInformation(langutil::ErrorList const& _errors);
void printErrorInformation(Error const& _error);
@@ -77,7 +77,7 @@ public:
{
return formatExceptionInformation(
_error,
(_error.type() == Error::Type::Warning) ? "Warning" : "Error",
Error::formatErrorSeverity(Error::errorSeverity(_error.type())),
_charStreamProvider
);
}