Add Error::parseErrorType()

This commit is contained in:
Kamil Śliwak 2023-09-29 22:07:44 +02:00
parent fe1f9c640e
commit fc37b4eeb6
2 changed files with 35 additions and 22 deletions

View File

@ -29,6 +29,26 @@
using namespace solidity; using namespace solidity;
using namespace solidity::langutil; using namespace solidity::langutil;
std::map<Error::Type, std::string> const Error::m_errorTypeNames = {
{Error::Type::IOError, "IOError"},
{Error::Type::FatalError, "FatalError"},
{Error::Type::JSONError, "JSONError"},
{Error::Type::InternalCompilerError, "InternalCompilerError"},
{Error::Type::CompilerError, "CompilerError"},
{Error::Type::Exception, "Exception"},
{Error::Type::CodeGenerationError, "CodeGenerationError"},
{Error::Type::DeclarationError, "DeclarationError"},
{Error::Type::DocstringParsingError, "DocstringParsingError"},
{Error::Type::ParserError, "ParserError"},
{Error::Type::SyntaxError, "SyntaxError"},
{Error::Type::TypeError, "TypeError"},
{Error::Type::UnimplementedFeatureError, "UnimplementedFeatureError"},
{Error::Type::YulException, "YulException"},
{Error::Type::SMTLogicException, "SMTLogicException"},
{Error::Type::Warning, "Warning"},
{Error::Type::Info, "Info"},
};
Error::Error( Error::Error(
ErrorId _errorId, Error::Type _type, ErrorId _errorId, Error::Type _type,
std::string const& _description, std::string const& _description,

View File

@ -33,10 +33,11 @@
#include <boost/preprocessor/facilities/overload.hpp> #include <boost/preprocessor/facilities/overload.hpp>
#include <boost/algorithm/string/case_conv.hpp> #include <boost/algorithm/string/case_conv.hpp>
#include <optional>
#include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <memory>
#include <variant> #include <variant>
namespace solidity::langutil namespace solidity::langutil
@ -269,27 +270,17 @@ public:
static std::string formatErrorType(Type _type) static std::string formatErrorType(Type _type)
{ {
switch (_type) return m_errorTypeNames.at(_type);
{ }
case Type::IOError: return "IOError";
case Type::FatalError: return "FatalError"; static std::optional<Type> parseErrorType(std::string _name)
case Type::JSONError: return "JSONError"; {
case Type::InternalCompilerError: return "InternalCompilerError"; static std::map<std::string, Error::Type> const m_errorTypesByName = util::invertMap(m_errorTypeNames);
case Type::CompilerError: return "CompilerError";
case Type::Exception: return "Exception"; if (m_errorTypesByName.count(_name) == 0)
case Type::CodeGenerationError: return "CodeGenerationError"; return std::nullopt;
case Type::DeclarationError: return "DeclarationError";
case Type::DocstringParsingError: return "DocstringParsingError"; return m_errorTypesByName.at(_name);
case Type::ParserError: return "ParserError";
case Type::SyntaxError: return "SyntaxError";
case Type::TypeError: return "TypeError";
case Type::UnimplementedFeatureError: return "UnimplementedFeatureError";
case Type::YulException: return "YulException";
case Type::SMTLogicException: return "SMTLogicException";
case Type::Warning: return "Warning";
case Type::Info: return "Info";
}
util::unreachable();
} }
static std::string formatTypeOrSeverity(std::variant<Error::Type, Error::Severity> _typeOrSeverity) static std::string formatTypeOrSeverity(std::variant<Error::Type, Error::Severity> _typeOrSeverity)
@ -309,6 +300,8 @@ public:
private: private:
ErrorId m_errorId; ErrorId m_errorId;
Type m_type; Type m_type;
static std::map<Type, std::string> const m_errorTypeNames;
}; };
} }