P4C
The P4 Compiler
Loading...
Searching...
No Matches
error_message.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef LIB_ERROR_MESSAGE_H_
17#define LIB_ERROR_MESSAGE_H_
18
19#include <cstring>
20#include <vector>
21
22#include "lib/source_file.h"
23
24namespace P4 {
25
39 enum class MessageType : std::size_t { None, Error, Warning, Info };
40
41 MessageType type = MessageType::None;
42 std::string prefix;
43 std::string message;
44 std::vector<Util::SourceInfo> locations = {};
45 std::string suffix;
46
48 // Invoked from backwards compatible error_helper
49 ErrorMessage(std::string prefix, Util::SourceInfo info, std::string suffix)
50 : prefix(std::move(prefix)), locations({info}), suffix(std::move(suffix)) {}
51 // Invoked from error_reporter
52 ErrorMessage(MessageType type, std::string prefix, std::string suffix)
53 : type(type), prefix(std::move(prefix)), suffix(std::move(suffix)) {}
54 ErrorMessage(MessageType type, std::string prefix, std::string message,
55 const std::vector<Util::SourceInfo> &locations, std::string suffix)
56 : type(type),
57 prefix(std::move(prefix)),
58 message(std::move(message)),
60 suffix(std::move(suffix)) {}
61
62 std::string getPrefix() const;
63 std::string toString() const;
64};
65
71 Util::SourceInfo location;
72 std::string message;
73
74 ParserErrorMessage(Util::SourceInfo loc, std::string msg)
75 : location(loc), message(std::move(msg)) {}
76
77 std::string toString() const;
78};
79
80} // namespace P4
81
82#endif /* LIB_ERROR_MESSAGE_H_ */
Definition source_file.h:131
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
@ Info
Take no action and continue compilation.
@ Error
Print a warning and continue compilation.
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:148
STL namespace.
Definition error_message.h:38
ErrorMessage()
Used by errorWithSuffix.
Definition error_message.h:47
std::vector< Util::SourceInfo > locations
Particular formatted message.
Definition error_message.h:44
std::string suffix
Relevant source locations for this error.
Definition error_message.h:45
std::string message
Typically error/warning type from catalog.
Definition error_message.h:43
Definition error_message.h:70