P4C
The P4 Compiler
Loading...
Searching...
No Matches
backends/p4tools/modules/testgen/lib/exceptions.h
1/*
2 * SPDX-FileCopyrightText: 2022 The P4 Language Consortium
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_EXCEPTIONS_H_
8#define BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_EXCEPTIONS_H_
9
10#include "absl/strings/str_cat.h"
11#include "lib/exceptions.h"
12
13namespace P4::P4Tools::P4Testgen {
14
17class TestgenUnimplemented final : public Util::P4CExceptionBase {
18 public:
19 template <typename... Args>
20 explicit TestgenUnimplemented(const char *format, Args &&...args)
21 : P4CExceptionBase(format, std::forward<Args>(args)...) {
22 // Check if output is redirected and if so, then don't color text so that
23 // escape characters are not present
24 message = absl::StrCat(Util::cerr_colorize(Util::ANSI_BLUE), "Not yet implemented",
25 Util::cerr_clear_colors(), ":\n", message);
26 }
27
28 template <typename... Args>
29 TestgenUnimplemented(int line, const char *file, const char *format, Args &&...args)
30 : P4CExceptionBase(format, std::forward<Args>(args)...) {
31 message = absl::StrCat(
32 "In file: ", file, ":", line, "\n", Util::cerr_colorize(Util::ANSI_BLUE),
33 "Unimplemented compiler support", Util::cerr_clear_colors(), ": ", message);
34 }
35};
36
37#define TESTGEN_UNIMPLEMENTED(...) \
38 do { \
39 throw TestgenUnimplemented(__LINE__, __FILE__, __VA_ARGS__); \
40 } while (0)
41
42} // namespace P4::P4Tools::P4Testgen
43
44#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_EXCEPTIONS_H_ */
Definition lib/exceptions.h:70