P4C
The P4 Compiler
Loading...
Searching...
No Matches
error_helper.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_HELPER_H_
8#define LIB_ERROR_HELPER_H_
9
10#include <utility>
11
12#include "lib/error_message.h"
13#include "lib/format.h"
14#include "lib/source_file.h"
15
16namespace P4 {
17// Invoked from ErrorReporter
18template <class... Args>
19ErrorMessage error_helper(const char *format, ErrorMessage msg, const Args &...args) {
20 if constexpr (sizeof...(Args) != 0) {
21 auto collect = [&](const Util::SourceInfo &info) { msg.locations.push_back(info); };
22 (FormatDetail::visitSourceInfo(args, collect), ...);
23 }
24 msg.message = createFormattedMessage(format, args...);
25 return msg;
26}
27
28// This overload exists for backwards compatibility
29template <class... Args>
30ErrorMessage error_helper(const char *format, const std::string &prefix,
31 const Util::SourceInfo &info, const std::string &suffix,
32 const Args &...args) {
33 return error_helper(format, ErrorMessage(prefix, info, suffix), args...);
34}
35
36// Most direct invocations of error_helper usually only reduce arguments.
37template <class... Args>
38ErrorMessage error_helper(const char *format, const Args &...args) {
39 return error_helper(format, ErrorMessage{}, args...);
40}
41
42} // namespace P4
43
44#endif /* LIB_ERROR_HELPER_H_ */
Definition source_file.h:123
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:157
Definition error_message.h:29
std::string message
Typically error/warning type from catalog.
Definition error_message.h:34