23#ifndef BM_BM_SIM_PARSER_ERROR_H_
24#define BM_BM_SIM_PARSER_ERROR_H_
29#include <unordered_map>
43 type_t get() {
return v; }
47 return (v == other.v);
52 return !(*
this == other);
62 static constexpr type_t INVALID_V = std::numeric_limits<type_t>::max();
87 bool add(
const std::string &name, ErrorCode::type_t v);
88 bool exists(
const std::string &name)
const;
89 bool exists(ErrorCode::type_t v)
const;
107 static const char *core_to_name(
const Core &core);
109 std::unordered_map<ErrorCode::type_t, std::string> map_v_to_name{};
110 std::unordered_map<std::string, ErrorCode::type_t> map_name_to_v{};
113class parser_exception :
public std::exception {
115 virtual ~parser_exception() { }
117 virtual ErrorCode get(
const ErrorCodeMap &error_codes)
const = 0;
120class parser_exception_arch :
public parser_exception {
122 explicit parser_exception_arch(
const ErrorCode &code);
124 ErrorCode get(
const ErrorCodeMap &error_codes)
const override;
127 const ErrorCode code;
130class parser_exception_core :
public parser_exception {
134 ErrorCode get(
const ErrorCodeMap &error_codes)
const override;
A bi-directional map between error codes and their P4 names.
Definition parser_error.h:66
Core
The core erros, as per core.p4.
Definition parser_error.h:69
@ PacketTooShort
Not enough bits in packet for extract or lookahead.
@ StackOutOfBounds
Reference to invalid element of a header stack (partial support)
@ NoError
No error raised in parser.
@ NoMatch
Match statement has no matches (unused for now)
@ ParserTimeout
Parser execution time limit exceeded (unused for now)
@ HeaderTooShort
Extracting too many bits into a varbit field (unused for now)
const std::string & to_name(const ErrorCode &code) const
ErrorCode from_core(const Core &core) const
Retrieve an error code for one of the core errors.
ErrorCode from_name(const std::string &name) const
Definition parser_error.h:35
static ErrorCode make_invalid()
Definition parser_error.h:57
bool operator!=(const ErrorCode &other) const
Inequality operator.
Definition parser_error.h:51
bool operator==(const ErrorCode &other) const
Equality operator.
Definition parser_error.h:46