diagnostic.h revision 117395
1157188Sache/* Various declarations for language-independent diagnostics subroutines. 221308Sache Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. 321308Sache Contributed by Gabriel Dos Reis <gdr@codesourcery.com> 4157188Sache 521308SacheThis file is part of GCC. 621308Sache 721308SacheGCC is free software; you can redistribute it and/or modify it under 821308Sachethe terms of the GNU General Public License as published by the Free 921308SacheSoftware Foundation; either version 2, or (at your option) any later 1021308Sacheversion. 1158314Sache 1221308SacheGCC is distributed in the hope that it will be useful, but WITHOUT ANY 1321308SacheWARRANTY; without even the implied warranty of MERCHANTABILITY or 1421308SacheFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1521308Sachefor more details. 1621308Sache 1721308SacheYou should have received a copy of the GNU General Public License 1821308Sachealong with GCC; see the file COPYING. If not, write to the Free 1921308SacheSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA 2021308Sache02111-1307, USA. */ 2121308Sache 2258314Sache#ifndef GCC_DIAGNOSTIC_H 23123279Sobrien#define GCC_DIAGNOSTIC_H 2421308Sache 2521308Sache#include "obstack.h" 2621308Sache#include "location.h" 2747563Sache 2847563Sache/* The type of a text to be formatted according a format specification 2947563Sache along with a list of things. */ 3047563Sachetypedef struct 3121308Sache{ 3247563Sache const char *format_spec; 33119614Sache va_list *args_ptr; 3421308Sache} text_info; 3521308Sache 3621308Sache/* Contants used to discreminate diagnostics. */ 3747563Sachetypedef enum 38119614Sache{ 3921308Sache#define DEFINE_DIAGNOSTIC_KIND(K, M) K, 4021308Sache#include "diagnostic.def" 4121308Sache#undef DEFINE_DIAGNOSTIC_KIND 4221308Sache DK_LAST_DIAGNOSTIC_KIND 43119614Sache} diagnostic_t; 44165675Sache 45136652Sache/* A diagnostic is described by the MESSAGE to send, the FILE and LINE of 46165675Sache its context and its KIND (ice, error, warning, note, ...) See complete 47119614Sache list in diagnostic.def. */ 4821308Sachetypedef struct 4921308Sache{ 5021308Sache text_info message; 5121308Sache location_t location; 5221308Sache /* The kind of diagnostic it is about. */ 5321308Sache diagnostic_t kind; 5421308Sache} diagnostic_info; 5521308Sache 5621308Sache#define pedantic_error_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING) 5721308Sache 5821308Sache/* How often diagnostics are prefixed by their locations: 5921308Sache o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported; 6021308Sache o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit only once; 6121308Sache o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit each time a physical 6221308Sache line is started. */ 6321308Sachetypedef enum 6421308Sache{ 6521308Sache DIAGNOSTICS_SHOW_PREFIX_ONCE = 0x0, 6621308Sache DIAGNOSTICS_SHOW_PREFIX_NEVER = 0x1, 6721308Sache DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2 6821308Sache} diagnostic_prefixing_rule_t; 6921308Sache 7021308Sache/* This data structure encapsulates an output_buffer's state. */ 7175409Sachetypedef struct 7275409Sache{ 7321308Sache /* The prefix for each new line. */ 7421308Sache const char *prefix; 7521308Sache 7621308Sache /* The real upper bound of number of characters per line, taking into 7747563Sache account the case of a very very looong prefix. */ 7847563Sache int maximum_length; 7947563Sache 8047563Sache /* The ideal upper bound of number of characters per line, as suggested 8147563Sache by front-end. */ 8221308Sache int ideal_maximum_length; 8347563Sache 84119614Sache /* Indentation count. */ 85119614Sache int indent_skip; 8621308Sache 8747563Sache /* Nonzero if current PREFIX was emitted at least once. */ 88119614Sache bool emitted_prefix_p; 89119614Sache 90119614Sache /* Nonzero means one should emit a newline before outputing anything. */ 91119614Sache bool need_newline_p; 92119614Sache 93119614Sache /* Current prefixing rule. */ 94119614Sache diagnostic_prefixing_rule_t prefixing_rule; 95119614Sache} output_state; 96119614Sache 97119614Sache/* The type of a hook that formats client-specific data (trees mostly) into 98119614Sache an output_buffer. A client-supplied formatter returns true if everything 99119614Sache goes well. */ 100119614Sachetypedef struct output_buffer output_buffer; 10121308Sachetypedef bool (*printer_fn) PARAMS ((output_buffer *, text_info *)); 10247563Sache 103119614Sache/* The output buffer datatype. This is best seen as an abstract datatype 104119614Sache whose fields should not be accessed directly by clients. */ 105119614Sachestruct output_buffer 106119614Sache{ 107119614Sache /* The current state of the buffer. */ 108119614Sache output_state state; 109119614Sache 110119614Sache /* Where to output formatted text. */ 111119614Sache FILE* stream; 112119614Sache 113119614Sache /* The obstack where the text is built up. */ 11447563Sache struct obstack obstack; 11547563Sache 116119614Sache /* The amount of characters output so far. */ 117119614Sache int line_length; 118119614Sache 11947563Sache /* This must be large enough to hold any printed integer or 12047563Sache floating-point value. */ 121119614Sache char digit_buffer[128]; 122119614Sache 12347563Sache /* If non-NULL, this function formats a TEXT into the BUFFER. When called, 12447563Sache TEXT->format_spec points to a format code. FORMAT_DECODER should call 125119614Sache output_add_string (and related functions) to add data to the BUFFER. 126119614Sache FORMAT_DECODER can read arguments from *TEXT->args_pts using VA_ARG. 12747563Sache If the BUFFER needs additional characters from the format string, it 12847563Sache should advance the TEXT->format_spec as it goes. When FORMAT_DECODER 129119614Sache returns, TEXT->format_spec should point to the last character processed. 130119614Sache */ 131119614Sache printer_fn format_decoder; 132119614Sache} ; 13347563Sache 13447563Sache#define output_prefix(BUFFER) (BUFFER)->state.prefix 135119614Sache 136119614Sache/* The stream attached to the output_buffer, where the formatted 13747563Sache diagnostics will ultimately go. Works only on `output_buffer *'. */ 13847563Sache#define output_buffer_attached_stream(BUFFER) (BUFFER)->stream 139119614Sache 140119614Sache/* In line-wrapping mode, whether we should start a new line. */ 14147563Sache#define output_needs_newline(BUFFER) (BUFFER)->state.need_newline_p 142119614Sache 143119614Sache/* The amount of whitespace to be emitted when starting a new line. */ 144119614Sache#define output_indentation(BUFFER) (BUFFER)->state.indent_skip 14547563Sache 146119614Sache/* A pointer to the formatted diagnostic message. */ 147119614Sache#define output_message_text(BUFFER) \ 148119614Sache ((const char *) obstack_base (&(BUFFER)->obstack)) 149119614Sache 15047563Sache/* Client supplied function used to decode formats. */ 15147563Sache#define output_format_decoder(BUFFER) (BUFFER)->format_decoder 152119614Sache 153119614Sache/* Prefixing rule used in formatting a diagnostic message. */ 154119614Sache#define output_prefixing_rule(BUFFER) (BUFFER)->state.prefixing_rule 155119614Sache 15647563Sache/* Maximum characters per line in automatic line wrapping mode. 15747563Sache Zero means don't wrap lines. */ 158119614Sache#define output_line_cutoff(BUFFER) (BUFFER)->state.ideal_maximum_length 159119614Sache 160119614Sache/* True if BUFFER is in line-wrapping mode. */ 161119614Sache#define output_is_line_wrapping(BUFFER) (output_line_cutoff (BUFFER) > 0) 162119614Sache 163119614Sache#define output_formatted_scalar(BUFFER, FORMAT, INTEGER) \ 164136652Sache do \ 165119614Sache { \ 166119614Sache sprintf ((BUFFER)->digit_buffer, FORMAT, INTEGER); \ 167119614Sache output_add_string (BUFFER, (BUFFER)->digit_buffer); \ 168119614Sache } \ 169119614Sache while (0) 170119614Sache 171119614Sache/* Forward declarations. */ 172119614Sachetypedef struct diagnostic_context diagnostic_context; 173119614Sachetypedef void (*diagnostic_starter_fn) PARAMS ((diagnostic_context *, 17475409Sache diagnostic_info *)); 17575409Sachetypedef diagnostic_starter_fn diagnostic_finalizer_fn; 176119614Sache 17735493Sache/* This data structure bundles altogether any information relevant to 17835493Sache the context of a diagnostic message. */ 17947563Sachestruct diagnostic_context 180119614Sache{ 181119614Sache /* Where most of the diagnostic formatting work is done. In Object 18221308Sache Oriented terms, we'll say that diagnostic_context is a sub-class of 18347563Sache output_buffer. */ 184119614Sache output_buffer buffer; 185119614Sache 186119614Sache /* The number of times we have issued diagnostics. */ 18721308Sache int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND]; 18847563Sache 189119614Sache /* True if we should display the "warnings are being tread as error" 190119614Sache message, usually displayed once per compiler run. */ 19147563Sache bool warnings_are_errors_message; 19247563Sache 193119614Sache /* This function is called before any message is printed out. It is 19447563Sache responsible for preparing message prefix and such. For example, it 19547563Sache might say: 196119614Sache In file included from "/usr/local/include/curses.h:5: 197119614Sache from "/home/gdr/src/nifty_printer.h:56: 19847563Sache ... 19947563Sache */ 200119614Sache diagnostic_starter_fn begin_diagnostic; 201119614Sache 20247563Sache /* This function is called after the diagnostic message is printed. */ 20347563Sache diagnostic_finalizer_fn end_diagnostic; 204119614Sache 205119614Sache /* Client hook to report an internal error. */ 206119614Sache void (*internal_error) PARAMS ((const char *, va_list *)); 207119614Sache 208119614Sache /* Function of last diagnostic message; more generally, function such that 209119614Sache if next diagnostic message is in it then we don't have to mention the 21047563Sache function name. */ 21158314Sache tree last_function; 212119614Sache 21347563Sache /* Used to detect when input_file_stack has changed since last described. */ 21447563Sache int last_module; 215119614Sache 216119614Sache int lock; 217119614Sache 21847563Sache /* Hook for front-end extensions. */ 21921308Sache void *x_data; 22047563Sache}; 221119614Sache 222119614Sache/* Client supplied function to announce a diagnostic. */ 223119614Sache#define diagnostic_starter(DC) (DC)->begin_diagnostic 224119614Sache 225119614Sache/* Client supplied function called after a diagnostic message is 226119614Sache displayed. */ 227119614Sache#define diagnostic_finalizer(DC) (DC)->end_diagnostic 228119614Sache 229119614Sache/* Extension hook for client. */ 230119614Sache#define diagnostic_auxiliary_data(DC) (DC)->x_data 231119614Sache 232119614Sache/* Same as output_format_decoder. Works on 'diagnostic_context *'. */ 233119614Sache#define diagnostic_format_decoder(DC) output_format_decoder (&(DC)->buffer) 234119614Sache 235119614Sache/* Same as output_prefixing_rule. Works on 'diagnostic_context *'. */ 236119614Sache#define diagnostic_prefixing_rule(DC) output_prefixing_rule (&(DC)->buffer) 237119614Sache 238119614Sache/* Maximum characters per line in automatic line wrapping mode. 239119614Sache Zero means don't wrap lines. */ 240119614Sache#define diagnostic_line_cutoff(DC) output_line_cutoff (&(DC)->buffer) 241119614Sache 242119614Sache/* True if the last function in which a diagnostic was reported is 243119614Sache different from the current one. */ 244119614Sache#define diagnostic_last_function_changed(DC) \ 245157188Sache ((DC)->last_function != current_function_decl) 246119614Sache 247119614Sache/* Remember the current function as being the last one in which we report 248119614Sache a diagnostic. */ 249119614Sache#define diagnostic_set_last_function(DC) \ 250119614Sache (DC)->last_function = current_function_decl 251119614Sache 252119614Sache/* True if the last module or file in which a diagnostic was reported is 253119614Sache different from the current one. */ 254119614Sache#define diagnostic_last_module_changed(DC) \ 255119614Sache ((DC)->last_module != input_file_stack_tick) 256119614Sache 257119614Sache/* Remember the current module or file as being the last one in which we 25821308Sache report a diagnostic. */ 25947563Sache#define diagnostic_set_last_module(DC) \ 260119614Sache (DC)->last_module = input_file_stack_tick 261119614Sache 262119614Sache/* This diagnostic_context is used by front-ends that directly output 26321308Sache diagnostic messages without going through `error', `warning', 264136652Sache and similar functions. */ 265136652Sacheextern diagnostic_context *global_dc; 26647563Sache 267119614Sache/* The total count of a KIND of diagnostics meitted so far. */ 268119614Sache#define diagnostic_kind_count(DC, DK) (DC)->diagnostic_count[(int) (DK)] 269119614Sache 270119614Sache/* The number of errors that have been issued so far. Ideally, these 271119614Sache would take a diagnostic_context as an argument. */ 272119614Sache#define errorcount diagnostic_kind_count (global_dc, DK_ERROR) 27321308Sache/* Similarly, but for warnings. */ 27421308Sache#define warningcount diagnostic_kind_count (global_dc, DK_WARNING) 27521308Sache/* Similarly, but for sorrys. */ 27621308Sache#define sorrycount diagnostic_kind_count (global_dc, DK_SORRY) 27721308Sache 27821308Sache/* Returns nonzero if warnings should be emitted. */ 27921308Sache#define diagnostic_report_warnings_p() \ 28021308Sache (!inhibit_warnings \ 28121308Sache && !(in_system_header && !warn_system_headers)) 282119614Sache 28321308Sache#define report_diagnostic(D) diagnostic_report_diagnostic (global_dc, D) 284119614Sache 285119614Sache/* Dignostic related functions. */ 28675409Sacheextern void diagnostic_initialize PARAMS ((diagnostic_context *)); 287119614Sacheextern void diagnostic_report_current_module PARAMS ((diagnostic_context *)); 28821308Sacheextern void diagnostic_report_current_function PARAMS ((diagnostic_context *)); 28975409Sacheextern void diagnostic_flush_buffer PARAMS ((diagnostic_context *)); 290119614Sacheextern bool diagnostic_count_diagnostic PARAMS ((diagnostic_context *, 29121308Sache diagnostic_t)); 29247563Sacheextern void diagnostic_report_diagnostic PARAMS ((diagnostic_context *, 293119614Sache diagnostic_info *)); 294119614Sacheextern void diagnostic_set_info PARAMS ((diagnostic_info *, 295119614Sache const char *, va_list *, 296119614Sache const char *, int, 297119614Sache diagnostic_t)); 298136652Sacheextern char *diagnostic_build_prefix PARAMS ((diagnostic_info *)); 299136652Sache 300119614Sache/* Pure text formatting support functions. */ 301119614Sacheextern void init_output_buffer PARAMS ((output_buffer *, 302136652Sache const char *, int)); 303136652Sacheextern void output_clear PARAMS ((output_buffer *)); 304136652Sacheextern const char *output_last_position PARAMS ((const output_buffer *)); 305136652Sacheextern void output_set_prefix PARAMS ((output_buffer *, 306119614Sache const char *)); 307157188Sacheextern void output_destroy_prefix PARAMS ((output_buffer *)); 308157188Sacheextern void output_set_maximum_length PARAMS ((output_buffer *, int)); 309119614Sacheextern void output_emit_prefix PARAMS ((output_buffer *)); 31047563Sacheextern void output_add_newline PARAMS ((output_buffer *)); 311136652Sacheextern void output_add_space PARAMS ((output_buffer *)); 312136652Sacheextern int output_space_left PARAMS ((const output_buffer *)); 313136652Sacheextern void output_append PARAMS ((output_buffer *, const char *, 31421308Sache const char *)); 315119614Sacheextern void output_add_character PARAMS ((output_buffer *, int)); 31621308Sacheextern void output_decimal PARAMS ((output_buffer *, int)); 31747563Sacheextern void output_add_string PARAMS ((output_buffer *, 318119614Sache const char *)); 319119614Sacheextern void output_add_identifier PARAMS ((output_buffer *, tree)); 32021308Sacheextern const char *output_finalize_message PARAMS ((output_buffer *)); 321119614Sacheextern void output_clear_message_text PARAMS ((output_buffer *)); 322119614Sacheextern void output_printf PARAMS ((output_buffer *, const char *, 32321308Sache ...)) ATTRIBUTE_PRINTF_2; 324119614Sacheextern void output_verbatim PARAMS ((output_buffer *, const char *, 325119614Sache ...)); 326119614Sacheextern void verbatim PARAMS ((const char *, ...)); 32747563Sacheextern char *file_name_as_prefix PARAMS ((const char *)); 328119614Sacheextern void inform PARAMS ((const char *, ...)); 329119614Sache 330119614Sache#endif /* ! GCC_DIAGNOSTIC_H */ 33121308Sache