P4C
The P4 Compiler
Loading...
Searching...
No Matches
bf_error_reporter.h
1
19#ifndef _BACKENDS_TOFINO_BF_P4C_LOGGING_BF_ERROR_REPORTER_H_
20#define _BACKENDS_TOFINO_BF_P4C_LOGGING_BF_ERROR_REPORTER_H_
21
22#include "ir/ir.h"
23#include "lib/error_reporter.h"
24
25bool get_has_output_already_been_silenced();
26void reset_has_output_already_been_silenced();
27
28class BfErrorReporter : public ErrorReporter {
29 struct Check {
30 std::string msg;
31 ErrorMessage::MessageType type;
32 bool matched;
33
34 Check(const std::string &msg, ErrorMessage::MessageType type)
35 : msg(msg), type(type), matched(false) {}
36 };
37
38 static constexpr int NO_SOURCE = 0;
39 // source line to expected warning/error messages on that line
40 std::unordered_map<int, std::vector<Check>> checks;
41 std::vector<std::string> unexpected_errors;
42 bool has_error_checks = false;
43 bool match_checks(const ErrorMessage &msg);
44 bool match_check(ErrorMessage::MessageType type, int line, const std::string &msg);
45
46 protected:
47 void emit_message(const ErrorMessage &msg) override;
48
49 void emit_message(const ParserErrorMessage &msg) override;
50
51 public:
52 enum class CheckResult { NO_TESTS, SUCCESS, FAILURE };
53
54 void increment_the_error_count() { ++this->errorCount; }
55
62 void add_check(ErrorMessage::MessageType type, const std::string &msg);
72 void add_check(ErrorMessage::MessageType type, int line, const std::string &msg);
73
85 CheckResult verify_checks() const;
86};
87
88#endif /* _BACKENDS_TOFINO_BF_P4C_LOGGING_BF_ERROR_REPORTER_H_ */
Definition bf_error_reporter.h:28
CheckResult verify_checks() const
Verify error/warning checks in the program. During compilation, if an error/warning message matches t...
Definition bf_error_reporter.cpp:151
void add_check(ErrorMessage::MessageType type, const std::string &msg)
Adds a check with no specified source code line.
Definition bf_error_reporter.cpp:98