mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Refactored the code
This commit is contained in:
parent
053689d25d
commit
64c2d4d33b
@ -71,3 +71,14 @@ Error::Error(
|
||||
if (!_description.empty())
|
||||
*this << util::errinfo_comment(_description);
|
||||
}
|
||||
|
||||
static std::optional<Severity> severityFromString(std::string _severity)
|
||||
{
|
||||
boost::algorithm::to_lower(_severity);
|
||||
|
||||
_severity = boost::algorithm::trim_copy(_severity);
|
||||
|
||||
_severity[0] = toupper(_severity[0]);
|
||||
|
||||
return std::make_optional<Severity>(_severity).has_value() ? std::optional<Severity>(_severity).value() : std::nullopt;
|
||||
}
|
@ -33,8 +33,6 @@
|
||||
#include <boost/preprocessor/facilities/overload.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <regex>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
@ -244,19 +242,6 @@ public:
|
||||
return "Error";
|
||||
}
|
||||
|
||||
static std::optional<Severity> stringToSeverity(std::string _severity)
|
||||
{
|
||||
_severity = tolower(_severity);
|
||||
|
||||
_severity = std::regex_replace(_severity, std::regex("^ +| +$|( ) +"), "$1");
|
||||
|
||||
_severity.erase(_severity.begin(), std::find_if(_severity.begin(), _severity.end(), std::bind1st(std::not_equal_to<char>(), ' ')));
|
||||
|
||||
_severity[0] = toupper(_severity[0]);
|
||||
|
||||
return std::make_optional<Severity>(_severity).has_value() ? std::optional<Severity>(_severity).value() : std::nullopt;
|
||||
}
|
||||
|
||||
static std::string formatErrorSeverityLowercase(Severity _severity)
|
||||
{
|
||||
switch (_severity)
|
||||
|
@ -55,13 +55,6 @@ std::string SourceReferenceFormatter::formatErrorInformation(Error const& _error
|
||||
);
|
||||
}
|
||||
|
||||
enum class Severity//have to define if used in switch
|
||||
{
|
||||
Error,
|
||||
Warning,
|
||||
Info
|
||||
};
|
||||
|
||||
AnsiColorized SourceReferenceFormatter::normalColored() const
|
||||
{
|
||||
return AnsiColorized(m_stream, m_colored, {WHITE});
|
||||
@ -188,7 +181,7 @@ void SourceReferenceFormatter::printExceptionInformation(SourceReferenceExtracto
|
||||
// exception header line
|
||||
if (_msg.errorId.has_value())
|
||||
{
|
||||
switch(stringToSeverity(_msg.severity))
|
||||
switch(severityFromString(_msg.severity))
|
||||
{
|
||||
case Severity::Error : errorColored() << " (" << _msg.errorId.value().error << ")";
|
||||
break;
|
||||
@ -201,6 +194,7 @@ void SourceReferenceFormatter::printExceptionInformation(SourceReferenceExtracto
|
||||
|
||||
default : unknownColored() << " (" << _msg.errorId.value().error << ")";
|
||||
}
|
||||
}
|
||||
|
||||
printSourceLocation(_msg.primary);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user