mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Added stringToSeverity(), Rebbased to latest devlop && fixed formatting
This commit is contained in:
parent
ef21e43fa3
commit
58851e751b
@ -23,31 +23,44 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <libsolutil/Exceptions.h>
|
#include <liblangutil/SourceLocation.h>
|
||||||
#include <libsolutil/Assertions.h>
|
#include <libsolutil/Assertions.h>
|
||||||
#include <libsolutil/CommonData.h>
|
#include <libsolutil/CommonData.h>
|
||||||
#include <liblangutil/SourceLocation.h>
|
#include <libsolutil/Exceptions.h>
|
||||||
|
|
||||||
#include <boost/preprocessor/cat.hpp>
|
#include <boost/preprocessor/cat.hpp>
|
||||||
#include <boost/preprocessor/facilities/empty.hpp>
|
#include <boost/preprocessor/facilities/empty.hpp>
|
||||||
#include <boost/preprocessor/facilities/overload.hpp>
|
#include <boost/preprocessor/facilities/overload.hpp>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace solidity::langutil
|
namespace solidity::langutil
|
||||||
{
|
{
|
||||||
class Error;
|
class Error;
|
||||||
using ErrorList = std::vector<std::shared_ptr<Error const>>;
|
using ErrorList = std::vector<std::shared_ptr<Error const>>;
|
||||||
|
|
||||||
struct CompilerError: virtual util::Exception {};
|
struct CompilerError: virtual util::Exception
|
||||||
struct StackTooDeepError: virtual CompilerError {};
|
{
|
||||||
struct InternalCompilerError: virtual util::Exception {};
|
};
|
||||||
struct FatalError: virtual util::Exception {};
|
struct StackTooDeepError: virtual CompilerError
|
||||||
struct UnimplementedFeatureError: virtual util::Exception {};
|
{
|
||||||
struct InvalidAstError: virtual util::Exception {};
|
};
|
||||||
|
struct InternalCompilerError: virtual util::Exception
|
||||||
|
{
|
||||||
|
};
|
||||||
|
struct FatalError: virtual util::Exception
|
||||||
|
{
|
||||||
|
};
|
||||||
|
struct UnimplementedFeatureError: virtual util::Exception
|
||||||
|
{
|
||||||
|
};
|
||||||
|
struct InvalidAstError: virtual util::Exception
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Assertion that throws an InternalCompilerError containing the given description if it is not met.
|
/// Assertion that throws an InternalCompilerError containing the given description if it is not met.
|
||||||
@ -111,7 +124,6 @@ struct InvalidAstError: virtual util::Exception {};
|
|||||||
"AST assertion failed" \
|
"AST assertion failed" \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
using errorSourceLocationInfo = std::pair<std::string, SourceLocation>;
|
using errorSourceLocationInfo = std::pair<std::string, SourceLocation>;
|
||||||
|
|
||||||
class SecondarySourceLocation
|
class SecondarySourceLocation
|
||||||
@ -161,7 +173,7 @@ struct ErrorId
|
|||||||
bool operator!=(ErrorId const& _rhs) const { return !(*this == _rhs); }
|
bool operator!=(ErrorId const& _rhs) const { return !(*this == _rhs); }
|
||||||
bool operator<(ErrorId const& _rhs) const { return error < _rhs.error; }
|
bool operator<(ErrorId const& _rhs) const { return error < _rhs.error; }
|
||||||
};
|
};
|
||||||
constexpr ErrorId operator"" _error(unsigned long long _error) { return ErrorId{ _error }; }
|
constexpr ErrorId operator"" _error(unsigned long long _error) { return ErrorId{_error}; }
|
||||||
|
|
||||||
class Error: virtual public util::Exception
|
class Error: virtual public util::Exception
|
||||||
{
|
{
|
||||||
@ -190,8 +202,7 @@ public:
|
|||||||
Type _type,
|
Type _type,
|
||||||
std::string const& _description,
|
std::string const& _description,
|
||||||
SourceLocation const& _location = SourceLocation(),
|
SourceLocation const& _location = SourceLocation(),
|
||||||
SecondarySourceLocation const& _secondaryLocation = SecondarySourceLocation()
|
SecondarySourceLocation const& _secondaryLocation = SecondarySourceLocation());
|
||||||
);
|
|
||||||
|
|
||||||
ErrorId errorId() const { return m_errorId; }
|
ErrorId errorId() const { return m_errorId; }
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
@ -215,15 +226,9 @@ public:
|
|||||||
return Severity::Error;
|
return Severity::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isError(Severity _severity)
|
static bool isError(Severity _severity) { return _severity == Severity::Error; }
|
||||||
{
|
|
||||||
return _severity == Severity::Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isError(Type _type)
|
static bool isError(Type _type) { return isError(errorSeverity(_type)); }
|
||||||
{
|
|
||||||
return isError(errorSeverity(_type));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool containsErrors(ErrorList const& _list)
|
static bool containsErrors(ErrorList const& _list)
|
||||||
{
|
{
|
||||||
@ -243,6 +248,11 @@ public:
|
|||||||
return "Error";
|
return "Error";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::optional<std::string> stringToSeverity(Severity _severity)
|
||||||
|
{
|
||||||
|
return _severity ? std::optional<std::string>{"Error, Warning, Info"} : std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
static std::string formatErrorSeverityLowercase(Severity _severity)
|
static std::string formatErrorSeverityLowercase(Severity _severity)
|
||||||
{
|
{
|
||||||
switch (_severity)
|
switch (_severity)
|
||||||
@ -263,5 +273,4 @@ private:
|
|||||||
Type m_type;
|
Type m_type;
|
||||||
std::string m_typeName;
|
std::string m_typeName;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,12 @@
|
|||||||
* Formatting functions for errors referencing positions and locations in the source.
|
* Formatting functions for errors referencing positions and locations in the source.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <liblangutil/SourceReferenceFormatter.h>
|
#include <iomanip>
|
||||||
#include <liblangutil/Exceptions.h>
|
|
||||||
#include <liblangutil/CharStream.h>
|
#include <liblangutil/CharStream.h>
|
||||||
#include <liblangutil/CharStreamProvider.h>
|
#include <liblangutil/CharStreamProvider.h>
|
||||||
|
#include <liblangutil/Exceptions.h>
|
||||||
|
#include <liblangutil/SourceReferenceFormatter.h>
|
||||||
#include <libsolutil/UTF8.h>
|
#include <libsolutil/UTF8.h>
|
||||||
#include <iomanip>
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -35,7 +35,6 @@ using namespace solidity::util::formatting;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string replaceNonTabs(std::string_view _utf8Input, char _filler)
|
std::string replaceNonTabs(std::string_view _utf8Input, char _filler)
|
||||||
{
|
{
|
||||||
std::string output;
|
std::string output;
|
||||||
@ -49,25 +48,31 @@ std::string replaceNonTabs(std::string_view _utf8Input, char _filler)
|
|||||||
|
|
||||||
std::string SourceReferenceFormatter::formatErrorInformation(Error const& _error, CharStream const& _charStream)
|
std::string SourceReferenceFormatter::formatErrorInformation(Error const& _error, CharStream const& _charStream)
|
||||||
{
|
{
|
||||||
return formatErrorInformation(
|
return formatErrorInformation(_error, SingletonCharStreamProvider(_charStream));
|
||||||
_error,
|
|
||||||
SingletonCharStreamProvider(_charStream)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AnsiColorized SourceReferenceFormatter::normalColored() const
|
AnsiColorized SourceReferenceFormatter::normalColored() const { return AnsiColorized(m_stream, m_colored, {WHITE}); }
|
||||||
{
|
|
||||||
return AnsiColorized(m_stream, m_colored, {WHITE});
|
|
||||||
}
|
|
||||||
|
|
||||||
AnsiColorized SourceReferenceFormatter::frameColored() const
|
AnsiColorized SourceReferenceFormatter::frameColored() const
|
||||||
{
|
{
|
||||||
return AnsiColorized(m_stream, m_colored, {BOLD, BLUE});
|
return AnsiColorized(m_stream, m_colored, {BOLD, BLUE});
|
||||||
}
|
}
|
||||||
|
|
||||||
AnsiColorized SourceReferenceFormatter::errorColored() const
|
AnsiColorized SourceReferenceFormatter::errorColored() const { return AnsiColorized(m_stream, m_colored, {BOLD, RED}); }
|
||||||
|
|
||||||
|
AnsiColorized SourceReferenceFormatter::infoColored() const
|
||||||
{
|
{
|
||||||
return AnsiColorized(m_stream, m_colored, {BOLD, RED});
|
return AnsiColorized(m_stream, m_colored, {BOLD, WHITE});
|
||||||
|
}
|
||||||
|
|
||||||
|
AnsiColorized SourceReferenceFormatter::warningColored() const
|
||||||
|
{
|
||||||
|
return AnsiColorized(m_stream, m_colored, {BOLD, YELLOW});
|
||||||
|
}
|
||||||
|
|
||||||
|
AnsiColorized SourceReferenceFormatter::unknownColored() const
|
||||||
|
{
|
||||||
|
return AnsiColorized(m_stream, m_colored, {BOLD, WHITE});
|
||||||
}
|
}
|
||||||
|
|
||||||
AnsiColorized SourceReferenceFormatter::messageColored() const
|
AnsiColorized SourceReferenceFormatter::messageColored() const
|
||||||
@ -133,11 +138,10 @@ void SourceReferenceFormatter::printSourceLocation(SourceReference const& _ref)
|
|||||||
frameColored() << '|';
|
frameColored() << '|';
|
||||||
|
|
||||||
m_stream << ' ' << replaceNonTabs(text.substr(0, static_cast<size_t>(_ref.startColumn)), ' ');
|
m_stream << ' ' << replaceNonTabs(text.substr(0, static_cast<size_t>(_ref.startColumn)), ' ');
|
||||||
diagColored() << (
|
diagColored()
|
||||||
locationLength == 0 ?
|
<< (locationLength == 0
|
||||||
"^" :
|
? "^"
|
||||||
replaceNonTabs(text.substr(static_cast<size_t>(_ref.startColumn), locationLength), '^')
|
: replaceNonTabs(text.substr(static_cast<size_t>(_ref.startColumn), locationLength), '^'));
|
||||||
);
|
|
||||||
m_stream << '\n';
|
m_stream << '\n';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -164,10 +168,20 @@ void SourceReferenceFormatter::printSourceLocation(SourceReference const& _ref)
|
|||||||
void SourceReferenceFormatter::printExceptionInformation(SourceReferenceExtractor::Message const& _msg)
|
void SourceReferenceFormatter::printExceptionInformation(SourceReferenceExtractor::Message const& _msg)
|
||||||
{
|
{
|
||||||
// exception header line
|
// exception header line
|
||||||
errorColored() << _msg.severity;
|
if (_msg.errorId.has_value())
|
||||||
if (m_withErrorIds && _msg.errorId.has_value())
|
{
|
||||||
|
if (_msg.severity == "Error")
|
||||||
errorColored() << " (" << _msg.errorId.value().error << ")";
|
errorColored() << " (" << _msg.errorId.value().error << ")";
|
||||||
messageColored() << ": " << _msg.primary.message << '\n';
|
|
||||||
|
else if (_msg.severity == "Warning")
|
||||||
|
warningColored() << " (" << _msg.errorId.value().error << ")";
|
||||||
|
|
||||||
|
else if (_msg.severity == "Info")
|
||||||
|
infoColored() << " (" << _msg.errorId.value().error << ")";
|
||||||
|
|
||||||
|
else
|
||||||
|
unknownColored() << " (" << _msg.errorId.value().error << ")";
|
||||||
|
}
|
||||||
|
|
||||||
printSourceLocation(_msg.primary);
|
printSourceLocation(_msg.primary);
|
||||||
|
|
||||||
@ -181,7 +195,8 @@ void SourceReferenceFormatter::printExceptionInformation(SourceReferenceExtracto
|
|||||||
m_stream << '\n';
|
m_stream << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void SourceReferenceFormatter::printExceptionInformation(util::Exception const& _exception, std::string const& _severity)
|
void SourceReferenceFormatter::printExceptionInformation(
|
||||||
|
util::Exception const& _exception, std::string const& _severity)
|
||||||
{
|
{
|
||||||
printExceptionInformation(SourceReferenceExtractor::extract(m_charStreamProvider, _exception, _severity));
|
printExceptionInformation(SourceReferenceExtractor::extract(m_charStreamProvider, _exception, _severity));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user