Next Previous Contents

7. Package for output of compiler messages

The most of compilers report error messages for incorrect program. Here the package `errors' which serves to output one-pass or multi-pass compiler messages of various modes (errors, warnings, fatal, system errors and appended messages) in Unix style or for traditional listing is suggested. The package also permits adequate error reporting for included files.

The package uses packages `vlobject', `objstack', `position' which use package `allocate'. Therefore package `position' have to be initiated before any work with this package. The interface part of the package is file `errors.h'. The implementation part is file `errors.c'. The maximum length of generated error message is suggested to be not greater then `MAX_ERROR_MESSAGE_LENGTH'. The default value (150) of this macro can be redefined with corresponding C compiler option `-DMAX_ERROR_MESSAGE_LENGTH=...' during compilation of file `errors.c'. The interface contains the following external definitions:

Integer variables `number_of_errors', `number_of_warnings'

have values which are number of correspondingly errors and warnings fixed after the most recent package initiation.

Integer variable `maximum_number_of_errors'

has value which is maximum number of errors which will be fixed. If an error is fixed with number equals to `maximum_number_of_errors' then special fatal error `fatal error -- too many errors' with position of given error is fixed instead of the error. And all following errors are ignored. Zero value of the variable means that the special fatal error will never fixed.

Integer constant `default_maximum_number_of_errors'

defines originally value of variable `maximum_number_of_errors'. The constant value is `50'.

Variable `fatal_error_function'

contains pointer to function without parameters which will be called after fixing a fatal error. The fatal error function is suggested to do not return the control back.

Function `default_fatal_error_function'

        `void default_fatal_error_function (void)'
        
defines originally value of variable `fatal_error_function'. The function only calls `exit (1)'.

Function `initiate_errors'

        `void initiate_errors (int immediate_output_flag)'
        
initiates the package in regime depending on parameter value. If the parameter value is nonzero than all fixed messages are output immediately. Otherwise the compiler messages are stored until function `output_errors' are called.

Function `finish_errors'

        `void finish_errors (void)'
        
frees all memory allocated during package work.

Function `output_errors'

        `void output_errors (void)'
        
sorts (stable sorting) all fixed messages by their positions, outputs ones, and deletes ones. Appended messages will be output after corresponding error or warning. This function should be used only in regime of storing messages.

Function `error'

        `void error (int fatal_error_flag, position_t
                     position, const char *format, ...)'
        
fixes error (fatal error if the first parameter value is nonzero) at the position given as the second parameter. If the error is fatal than functions `output_errors' and `*fatal_error_function' are called. The diagnostic messages are formed analogous to output of function `printf'. For example,
           error (1, current_position, "fatal error - no memory");
        

Function `warning'

        `void warning (position_t position, const char *format, ...)'
        
is analogous to the previous but is used to fix a warning.

Function `append_message'

        `void append_message (position_t position,
                              const char *format, ...)'
        
When regime of immediately output of fixed message is on this function is analogous to the previous (except for incrementing variable `number_of_warnings'). In opposite case the appended message will be output with the most recent fixed error or warning independently from value of the first parameter. Of course the previously fixed error or warning must exist.

For example, this function may be used for generation of messages of type

              `<file>:<line>:<position-1>: repeated declaration'
        
and then
              `<file>:<line>:<position-1>: previous declaration'.
        
Description of function `default_output_error_function' contains explanation why decremented position is output.

Function `system_error'

        `void system_error (int fatal_error_flag,
                            position_t position,
                            const char *format, ...)'
        
is analogous to function `error' but serves to fix a system error. The current system message without head blanks (given by standard function `strerror') is placed after the message formed by the function parameters. For example, the following call may be used when a file is not opened

             system_error  (1, current_position,
                            "fatal error - %s:", new_file_name);
        

Variable `output_error_function'

contains pointer to function which is used to output error message. The function has three parameters -- flag of appended message, message position and message itself.

Function `default_output_error_function'

        `void default_output_error_function
              (int appended_message_flag, position_t position,
               const char *message)'
        
Originally value of variable `output_error_function' is equal to this function. The function is oriented to output in Unix style according to GNU standard. To output a listing the value of variable `output_error_function' should be changed. The function output message in the following formats:
  MESSAGE                              (NULL file name)
  FILE_NAME:1: MESSAGE                 (zero line number)
  FILE_NAME:LINE_NUMBER: MESSAGE       (zero column number)
  FILE_NAME:LINE_NUMBER:COLUMN_NUMBER-1: MESSAGE  (all other cases)
        
After that the function outputs newline. The function also outputs additional messages `in file processed from ...' if given message is not appended message and corresponds to file different from one of previous output error. This message reflects path of the message position (see package `position'), i.e. reflects positions of corresponding include-clauses. Decremented column number is output in order to be in concordance with editor Emacs in which positions start with 0.


Next Previous Contents