libyasm
Macros | Typedefs | Enumerations | Functions | Variables
errwarn.h File Reference

YASM error and warning reporting interface. More...

Go to the source code of this file.

Macros

#define YASM_LIB_DECL
 
#define yasm_internal_error(message)   yasm_internal_error_(__FILE__, __LINE__, message)
 Easily-callable version of yasm_internal_error_(). More...
 

Typedefs

typedef enum yasm_warn_class yasm_warn_class
 Warning classes (that may be enabled/disabled). More...
 
typedef enum yasm_error_class yasm_error_class
 Error classes. More...
 
typedef void(* yasm_print_error_func )(const char *fn, unsigned long line, const char *msg, const char *xref_fn, unsigned long xref_line, const char *xref_msg)
 Print out an error. More...
 
typedef void(* yasm_print_warning_func )(const char *fn, unsigned long line, const char *msg)
 Print out a warning. More...
 

Enumerations

enum  yasm_warn_class {
  YASM_WARN_NONE = 0, YASM_WARN_GENERAL, YASM_WARN_UNREC_CHAR, YASM_WARN_PREPROC,
  YASM_WARN_ORPHAN_LABEL, YASM_WARN_UNINIT_CONTENTS, YASM_WARN_SIZE_OVERRIDE, YASM_WARN_IMPLICIT_SIZE_OVERRIDE
}
 Warning classes (that may be enabled/disabled). More...
 
enum  yasm_error_class {
  YASM_ERROR_NONE = 0x0000, YASM_ERROR_GENERAL = 0xFFFF, YASM_ERROR_ARITHMETIC = 0x0001, YASM_ERROR_OVERFLOW = 0x8001,
  YASM_ERROR_FLOATING_POINT = 0x4001, YASM_ERROR_ZERO_DIVISION = 0x2001, YASM_ERROR_ASSERTION = 0x0002, YASM_ERROR_VALUE = 0x0004,
  YASM_ERROR_NOT_ABSOLUTE = 0x8004, YASM_ERROR_TOO_COMPLEX = 0x4004, YASM_ERROR_NOT_CONSTANT = 0x2004, YASM_ERROR_IO = 0x0008,
  YASM_ERROR_NOT_IMPLEMENTED = 0x0010, YASM_ERROR_TYPE = 0x0020, YASM_ERROR_SYNTAX = 0x0040, YASM_ERROR_PARSE = 0x8040
}
 Error classes. More...
 

Functions

YASM_LIB_DECL void yasm_errwarn_initialize (void)
 Initialize any internal data structures. More...
 
YASM_LIB_DECL void yasm_errwarn_cleanup (void)
 Clean up any memory allocated by yasm_errwarn_initialize() or other functions.
 
YASM_LIB_DECL void yasm__fatal (const char *message,...)
 Reporting point of fatal errors, with variable arguments (internal only). More...
 
YASM_LIB_DECL void yasm_error_clear (void)
 Unconditionally clear the error indicator, freeing any associated data. More...
 
yasm_error_class yasm_error_occurred (void)
 Get the error indicator. More...
 
YASM_LIB_DECL int yasm_error_matches (yasm_error_class eclass)
 Check the error indicator against an error class. More...
 
YASM_LIB_DECL void yasm_error_set_va (yasm_error_class eclass, const char *format, va_list va)
 Set the error indicator (va_list version). More...
 
YASM_LIB_DECL void yasm_error_set (yasm_error_class eclass, const char *format,...)
 Set the error indicator. More...
 
YASM_LIB_DECL void yasm_error_set_xref_va (unsigned long xrefline, const char *format, va_list va)
 Set a cross-reference for a new error (va_list version). More...
 
YASM_LIB_DECL void yasm_error_set_xref (unsigned long xrefline, const char *format,...)
 Set a cross-reference for a new error. More...
 
YASM_LIB_DECL void yasm_error_fetch (yasm_error_class *eclass, char **str, unsigned long *xrefline, char **xrefstr)
 Fetch the error indicator and all associated data. More...
 
YASM_LIB_DECL void yasm_warn_clear (void)
 Unconditionally clear all warning indicators, freeing any associated data. More...
 
YASM_LIB_DECL yasm_warn_class yasm_warn_occurred (void)
 Get the first warning indicator. More...
 
YASM_LIB_DECL void yasm_warn_set_va (yasm_warn_class wclass, const char *format, va_list va)
 Add a warning indicator (va_list version). More...
 
YASM_LIB_DECL void yasm_warn_set (yasm_warn_class wclass, const char *format,...)
 Add a warning indicator. More...
 
YASM_LIB_DECL void yasm_warn_fetch (yasm_warn_class *wclass, char **str)
 Fetch the first warning indicator and all associated data. More...
 
YASM_LIB_DECL void yasm_warn_enable (yasm_warn_class wclass)
 Enable a class of warnings. More...
 
YASM_LIB_DECL void yasm_warn_disable (yasm_warn_class wclass)
 Disable a class of warnings. More...
 
YASM_LIB_DECL void yasm_warn_disable_all (void)
 Disable all classes of warnings. More...
 
YASM_LIB_DECL yasm_errwarnsyasm_errwarns_create (void)
 Create an error/warning set for collection of multiple error/warnings. More...
 
YASM_LIB_DECL void yasm_errwarns_destroy (yasm_errwarns *errwarns)
 Destroy an error/warning set. More...
 
YASM_LIB_DECL void yasm_errwarn_propagate (yasm_errwarns *errwarns, unsigned long line)
 Propagate error indicator and warning indicator(s) to an error/warning set. More...
 
YASM_LIB_DECL unsigned int yasm_errwarns_num_errors (yasm_errwarns *errwarns, int warning_as_error)
 Get total number of errors logged. More...
 
YASM_LIB_DECL void yasm_errwarns_output_all (yasm_errwarns *errwarns, yasm_linemap *lm, int warning_as_error, yasm_print_error_func print_error, yasm_print_warning_func print_warning)
 Outputs error/warning set in sorted order (sorted by virtual line number). More...
 
YASM_LIB_DECL char * yasm__conv_unprint (int ch)
 Convert a possibly unprintable character into a printable string. More...
 

Variables

YASM_LIB_DECL void(* yasm_internal_error_ )(const char *file, unsigned int line, const char *message)
 Reporting point of internal errors. More...
 
YASM_LIB_DECL void(* yasm_fatal )(const char *message, va_list va)
 Reporting point of fatal errors. More...
 
YASM_LIB_DECL const char *(* yasm_gettext_hook )(const char *msgid)
 Hook for library users to map to gettext() if GNU gettext is being used. More...
 

Detailed Description

YASM error and warning reporting interface.

Definition in file errwarn.h.

Macro Definition Documentation

#define yasm_internal_error (   message)    yasm_internal_error_(__FILE__, __LINE__, message)

Easily-callable version of yasm_internal_error_().

Automatically uses FILE and LINE as the file and line.

Parameters
messageinternal error message

Definition at line 96 of file errwarn.h.

Typedef Documentation

Error classes.

Bitmask-based to support limited subclassing.

typedef void(* yasm_print_error_func)(const char *fn, unsigned long line, const char *msg,const char *xref_fn, unsigned long xref_line,const char *xref_msg)

Print out an error.

Parameters
fnfilename of source file
lineline number
msgerror message
xref_fncross-referenced source filename
xref_linecross-referenced line number
xref_msgcross-referenced error message

Definition at line 309 of file errwarn.h.

typedef void(* yasm_print_warning_func)(const char *fn, unsigned long line, const char *msg)

Print out a warning.

Parameters
fnfilename of source file
lineline number
msgwarning message

Definition at line 319 of file errwarn.h.

Warning classes (that may be enabled/disabled).

Enumeration Type Documentation

Error classes.

Bitmask-based to support limited subclassing.

Enumerator
YASM_ERROR_NONE 

No error.

YASM_ERROR_GENERAL 

Non-specific.

YASM_ERROR_ARITHMETIC 

Arithmetic error (general)

YASM_ERROR_OVERFLOW 

Arithmetic overflow.

YASM_ERROR_FLOATING_POINT 

Floating point error.

YASM_ERROR_ZERO_DIVISION 

Divide-by-zero.

YASM_ERROR_ASSERTION 

Assertion error.

YASM_ERROR_VALUE 

Value inappropriate (e.g.

not in range)

YASM_ERROR_NOT_ABSOLUTE 

Absolute expression required.

YASM_ERROR_TOO_COMPLEX 

Expression too complex.

YASM_ERROR_NOT_CONSTANT 

Constant expression required.

YASM_ERROR_IO 

I/O error.

YASM_ERROR_NOT_IMPLEMENTED 

Not implemented error.

YASM_ERROR_TYPE 

Type error.

YASM_ERROR_SYNTAX 

Syntax error.

YASM_ERROR_PARSE 

Parser error.

Definition at line 50 of file errwarn.h.

Warning classes (that may be enabled/disabled).

Enumerator
YASM_WARN_NONE 

No warning.

YASM_WARN_GENERAL 

Non-specific warnings.

YASM_WARN_UNREC_CHAR 

Unrecognized characters (while tokenizing)

YASM_WARN_PREPROC 

Preprocessor warnings.

YASM_WARN_ORPHAN_LABEL 

Label alone on a line without a colon.

YASM_WARN_UNINIT_CONTENTS 

Uninitialized space in code/data section.

YASM_WARN_SIZE_OVERRIDE 

Double size override.

YASM_WARN_IMPLICIT_SIZE_OVERRIDE 

Implicit size override.

Definition at line 38 of file errwarn.h.

Function Documentation

YASM_LIB_DECL char* yasm__conv_unprint ( int  ch)

Convert a possibly unprintable character into a printable string.

Parameters
chpossibly unprintable character
Returns
Printable string representation (static buffer).
YASM_LIB_DECL void yasm__fatal ( const char *  message,
  ... 
)

Reporting point of fatal errors, with variable arguments (internal only).

Warning
This function calls yasm_fatal, and thus does not return to the calling code.
Parameters
messagefatal error message
...argument list for message
YASM_LIB_DECL void yasm_error_clear ( void  )

Unconditionally clear the error indicator, freeing any associated data.

Has no effect if the error indicator is not set.

YASM_LIB_DECL void yasm_error_fetch ( yasm_error_class eclass,
char **  str,
unsigned long *  xrefline,
char **  xrefstr 
)

Fetch the error indicator and all associated data.

If the error indicator is set, the output pointers are set to the current error indicator values, and the error indicator is cleared. The code using this function is then responsible for yasm_xfree()'ing str and xrefstr (if non-NULL). If the error indicator is not set, all output values are set to 0 (including eclass, which is set to YASM_ERROR_NONE).

Parameters
eclasserror class (output)
strerror message
xreflinevirtual line used for cross-referencing (0 if no xref)
xrefstrcross-reference error message (NULL if no xref)
YASM_LIB_DECL int yasm_error_matches ( yasm_error_class  eclass)

Check the error indicator against an error class.

To check if any error has been set, check against the YASM_ERROR_GENERAL class. This function properly checks error subclasses.

Parameters
eclassbase error class to check against
Returns
Nonzero if error indicator is set and a subclass of eclass, 0 otherwise.
yasm_error_class yasm_error_occurred ( void  )

Get the error indicator.

YASM_ERROR_NONE is returned if no error has been set. Note that as YASM_ERROR_NONE is 0, the return value can also be treated as a boolean value.

Returns
Current error indicator.
YASM_LIB_DECL void yasm_error_set ( yasm_error_class  eclass,
const char *  format,
  ... 
)

Set the error indicator.

Has no effect if the error indicator is already set.

Parameters
eclasserror class
formatprintf format string
...argument list for format
YASM_LIB_DECL void yasm_error_set_va ( yasm_error_class  eclass,
const char *  format,
va_list  va 
)

Set the error indicator (va_list version).

Has no effect if the error indicator is already set.

Parameters
eclasserror class
formatprintf format string
vaargument list for format
YASM_LIB_DECL void yasm_error_set_xref ( unsigned long  xrefline,
const char *  format,
  ... 
)

Set a cross-reference for a new error.

Has no effect if the error indicator is already set (e.g. with yasm_error_set()). This function must be called prior to its corresponding yasm_error_set() call.

Parameters
xreflinevirtual line to cross-reference to (should not be 0)
formatprintf format string
...argument list for format
YASM_LIB_DECL void yasm_error_set_xref_va ( unsigned long  xrefline,
const char *  format,
va_list  va 
)

Set a cross-reference for a new error (va_list version).

Has no effect if the error indicator is already set (e.g. with yasm_error_set()). This function must be called prior to its corresponding yasm_error_set() call.

Parameters
xreflinevirtual line to cross-reference to (should not be 0)
formatprintf format string
vaargument list for format
YASM_LIB_DECL void yasm_errwarn_initialize ( void  )

Initialize any internal data structures.

YASM_LIB_DECL void yasm_errwarn_propagate ( yasm_errwarns errwarns,
unsigned long  line 
)

Propagate error indicator and warning indicator(s) to an error/warning set.

Has no effect if the error indicator and warning indicator are not set. Does not print immediately; yasm_errwarn_output_all() outputs accumulated errors and warnings. Generally multiple errors on the same line will be reported, but errors of class YASM_ERROR_PARSE will get overwritten by any other class on the same line.

Parameters
errwarnserror/warning set
linevirtual line
YASM_LIB_DECL yasm_errwarns* yasm_errwarns_create ( void  )

Create an error/warning set for collection of multiple error/warnings.

Returns
Newly allocated set.
YASM_LIB_DECL void yasm_errwarns_destroy ( yasm_errwarns errwarns)

Destroy an error/warning set.

Parameters
errwarnserror/warning set
YASM_LIB_DECL unsigned int yasm_errwarns_num_errors ( yasm_errwarns errwarns,
int  warning_as_error 
)

Get total number of errors logged.

Parameters
errwarnserror/warning set
warning_as_errorif nonzero, warnings are treated as errors.
Returns
Number of errors.
YASM_LIB_DECL void yasm_errwarns_output_all ( yasm_errwarns errwarns,
yasm_linemap lm,
int  warning_as_error,
yasm_print_error_func  print_error,
yasm_print_warning_func  print_warning 
)

Outputs error/warning set in sorted order (sorted by virtual line number).

Parameters
errwarnserror/warning set
lmline map (to convert virtual lines into filename/line pairs)
warning_as_errorif nonzero, treat warnings as errors.
print_errorfunction called to print out errors
print_warningfunction called to print out warnings
YASM_LIB_DECL void yasm_warn_clear ( void  )

Unconditionally clear all warning indicators, freeing any associated data.

Has no effect if no warning indicators have been set.

YASM_LIB_DECL void yasm_warn_disable ( yasm_warn_class  wclass)

Disable a class of warnings.

Parameters
wclasswarning class
YASM_LIB_DECL void yasm_warn_disable_all ( void  )

Disable all classes of warnings.

YASM_LIB_DECL void yasm_warn_enable ( yasm_warn_class  wclass)

Enable a class of warnings.

Parameters
wclasswarning class
YASM_LIB_DECL void yasm_warn_fetch ( yasm_warn_class wclass,
char **  str 
)

Fetch the first warning indicator and all associated data.

If there is at least one warning indicator, the output pointers are set to the first warning indicator values, and first warning indicator is removed. The code using this function is then responsible for yasm_xfree()'ing str and xrefstr (if non-NULL). If there is no warning indicator set, all output values are set to 0 (including wclass, which is set to YASM_WARN_NONE).

Parameters
wclasswarning class (output)
strwarning message
YASM_LIB_DECL yasm_warn_class yasm_warn_occurred ( void  )

Get the first warning indicator.

YASM_WARN_NONE is returned if no warning has been set. Note that as YASM_WARN_NONE is 0, the return value can also be treated as a boolean value.

Returns
First warning indicator.
YASM_LIB_DECL void yasm_warn_set ( yasm_warn_class  wclass,
const char *  format,
  ... 
)

Add a warning indicator.

Parameters
wclasswarning class
formatprintf format string
...argument list for format
YASM_LIB_DECL void yasm_warn_set_va ( yasm_warn_class  wclass,
const char *  format,
va_list  va 
)

Add a warning indicator (va_list version).

Parameters
wclasswarning class
formatprintf format string
vaargument list for format

Variable Documentation

YASM_LIB_DECL void(* yasm_fatal)(const char *message, va_list va)

Reporting point of fatal errors.

Warning
This function must NOT return to calling code; exit or longjmp instead.
Parameters
messagefatal error message
vava_list argument list for message
YASM_LIB_DECL const char*(* yasm_gettext_hook)(const char *msgid)

Hook for library users to map to gettext() if GNU gettext is being used.

Parameters
msgidmessage catalog identifier
Returns
Translated message.
YASM_LIB_DECL void(* yasm_internal_error_)(const char *file, unsigned int line, const char *message)

Reporting point of internal errors.

These are usually due to sanity check failures in the code.

Warning
This function must NOT return to calling code; exit or longjmp instead.
Parameters
filesource file (ala FILE)
linesource line (ala LINE)
messageinternal error message