P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::ErrorReporter Class Reference

Public Member Functions

template<typename... Args>
std::string bug_message (const char *format, Args &&...args)
 
template<typename... Args>
void diagnose (DiagnosticAction action, const char *diagnosticName, const char *format, const char *suffix, Args &&...args)
 
template<typename... Args>
void diagnose (DiagnosticAction action, const int errorCode, const char *format, const char *suffix, Args &&...args)
 
template<class T , typename = decltype(std::declval<T>()->getSourceInfo()), typename... Args>
void diagnose (DiagnosticAction action, const int errorCode, const char *format, const char *suffix, T node, Args &&...args)
 
template<typename... Args>
std::string format_message (const char *format, Args &&...args)
 
DiagnosticAction getDefaultInfoDiagnosticAction ()
 
DiagnosticAction getDefaultWarningDiagnosticAction ()
 
DiagnosticAction getDiagnosticAction (int errorCode, cstring diagnostic, DiagnosticAction defaultAction)
 
unsigned getDiagnosticCount () const
 
unsigned getErrorCount () const
 
unsigned getInfoCount () const
 
unsigned getMaxErrorCount () const
 
std::ostream * getOutputStream () const
 
unsigned getWarningCount () const
 
template<typename... Args>
void parser_error (const Util::InputSources *sources, const char *fmt, Args &&...args)
 
template<typename T >
void parser_error (const Util::SourceInfo &location, const T &message)
 
void setDefaultInfoDiagnosticAction (DiagnosticAction action)
 set the default diagnostic action for calls to P4::info().
 
void setDefaultWarningDiagnosticAction (DiagnosticAction action)
 set the default diagnostic action for calls to P4::warning().
 
void setDiagnosticAction (std::string_view diagnostic, DiagnosticAction action)
 Set the action to take for the given diagnostic.
 
unsigned setMaxErrorCount (unsigned newMaxCount)
 set maxErrorCount to a the @newMaxCount threshold and return the previous value
 
void setOutputStream (std::ostream *stream)
 

Protected Member Functions

virtual void emit_message (const ErrorMessage &msg)
 Output the message and flush the stream.
 
virtual void emit_message (const ParserErrorMessage &msg)
 
bool error_reported (int err, const Util::SourceInfo source)
 
cstring get_error_name (int errorCode)
 retrieve the format from the error catalog
 

Protected Attributes

unsigned int errorCount
 
std::set< std::pair< int, const Util::SourceInfo > > errorTracker
 Track errors or warnings that have already been issued for a particular source location.
 
unsigned int infoCount
 
unsigned int maxErrorCount
 
std::ostream * outputstream
 the maximum number of errors that we print before fail
 
unsigned int warningCount
 

Member Function Documentation

◆ diagnose()

template<typename... Args>
void P4::ErrorReporter::diagnose ( DiagnosticAction action,
const char * diagnosticName,
const char * format,
const char * suffix,
Args &&... args )
inline

The sink of all the diagnostic functions. Here the error gets printed or an exception thrown if the error count exceeds maxErrorCount.

◆ error_reported()

bool P4::ErrorReporter::error_reported ( int err,
const Util::SourceInfo source )
inlineprotected

Check whether an error has already been reported, by keeping track of error type and source info. If the error has been reported, return true. Otherwise, insert add the error to the list of seen errors, and return false.

◆ getDefaultInfoDiagnosticAction()

DiagnosticAction P4::ErrorReporter::getDefaultInfoDiagnosticAction ( )
inline
Returns
the default diagnostic action for calls to P4::info().

◆ getDefaultWarningDiagnosticAction()

DiagnosticAction P4::ErrorReporter::getDefaultWarningDiagnosticAction ( )
inline
Returns
the default diagnostic action for calls to P4::warning().

◆ getDiagnosticAction()

DiagnosticAction P4::ErrorReporter::getDiagnosticAction ( int errorCode,
cstring diagnostic,
DiagnosticAction defaultAction )
inline
Returns
the action to take for the given diagnostic, falling back to the default action if it wasn't overridden via the command line or a pragma.

◆ getDiagnosticCount()

unsigned P4::ErrorReporter::getDiagnosticCount ( ) const
inline
Returns
the number of diagnostics (warnings and errors) encountered in the current CompileContext.

◆ parser_error() [1/2]

template<typename... Args>
void P4::ErrorReporter::parser_error ( const Util::InputSources * sources,
const char * fmt,
Args &&... args )
inline

Reports an error specified by @fmt and @args at the current position in the input represented by @sources. This is necessary for the IR generator's C-based Bison parser, which doesn't have location information available.

◆ parser_error() [2/2]

template<typename T >
void P4::ErrorReporter::parser_error ( const Util::SourceInfo & location,
const T & message )
inline

Reports an error @message at @location. This allows us to use the position information provided by Bison.