P4C
The P4 Compiler
Loading...
Searching...
No Matches
error_message.h
1/*
2 * SPDX-FileCopyrightText: 2013 Barefoot Networks, Inc.
3 * Copyright 2013-present Barefoot Networks, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7#ifndef LIB_ERROR_MESSAGE_H_
8#define LIB_ERROR_MESSAGE_H_
9
10#include <cstring>
11#include <vector>
12
13#include "lib/source_file.h"
14
15namespace P4 {
16
30 enum class MessageType : std::size_t { None, Error, Warning, Info };
31
32 MessageType type = MessageType::None;
33 std::string prefix;
34 std::string message;
35 std::vector<Util::SourceInfo> locations = {};
36 std::string suffix;
37
39 // Invoked from backwards compatible error_helper
40 ErrorMessage(std::string prefix, Util::SourceInfo info, std::string suffix)
41 : prefix(std::move(prefix)), locations({info}), suffix(std::move(suffix)) {}
42 // Invoked from error_reporter
43 ErrorMessage(MessageType type, std::string prefix, std::string suffix)
44 : type(type), prefix(std::move(prefix)), suffix(std::move(suffix)) {}
45 ErrorMessage(MessageType type, std::string prefix, std::string message,
46 const std::vector<Util::SourceInfo> &locations, std::string suffix)
47 : type(type),
48 prefix(std::move(prefix)),
49 message(std::move(message)),
51 suffix(std::move(suffix)) {}
52
53 std::string getPrefix() const;
54 std::string toString() const;
55};
56
61struct ParserErrorMessage {
62 Util::SourceInfo location;
63 std::string message;
64
65 ParserErrorMessage(Util::SourceInfo loc, std::string msg)
66 : location(loc), message(std::move(msg)) {}
67
68 std::string toString() const;
69};
70
71} // namespace P4
72
73#endif /* LIB_ERROR_MESSAGE_H_ */
Definition source_file.h:132
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
void info(const int kind, const char *format, const T *node, Args &&...args)
Report info messages of type kind. Requires that the node argument have source info.
Definition lib/error.h:167
STL namespace.
ErrorMessage()
Used by errorWithSuffix.
Definition error_message.h:38
std::vector< Util::SourceInfo > locations
Particular formatted message.
Definition error_message.h:35
std::string suffix
Relevant source locations for this error.
Definition error_message.h:36
std::string message
Typically error/warning type from catalog.
Definition error_message.h:34
Definition register_reference.h:28