diagnostic.h revision 90075
190075Sobrien/* Various declarations for language-independent diagnostics subroutines. 290075Sobrien Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. 390075Sobrien Contributed by Gabriel Dos Reis <gdr@codesourcery.com> 490075Sobrien 590075SobrienThis file is part of GCC. 690075Sobrien 790075SobrienGCC is free software; you can redistribute it and/or modify it under 890075Sobrienthe terms of the GNU General Public License as published by the Free 990075SobrienSoftware Foundation; either version 2, or (at your option) any later 1090075Sobrienversion. 1190075Sobrien 1290075SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY 1390075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or 1490075SobrienFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1590075Sobrienfor more details. 1690075Sobrien 1790075SobrienYou should have received a copy of the GNU General Public License 1890075Sobrienalong with GCC; see the file COPYING. If not, write to the Free 1990075SobrienSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA 2090075Sobrien02111-1307, USA. */ 2190075Sobrien 2290075Sobrien#ifndef GCC_DIAGNOSTIC_H 2390075Sobrien#define GCC_DIAGNOSTIC_H 2490075Sobrien 2590075Sobrien#include "obstack.h" 2690075Sobrien 2790075Sobrien/* Forward declarations. */ 2890075Sobrientypedef struct output_buffer output_buffer; 2990075Sobrientypedef struct diagnostic_context diagnostic_context; 3090075Sobrientypedef void (*diagnostic_starter_fn) PARAMS ((output_buffer *, 3190075Sobrien diagnostic_context *)); 3290075Sobrientypedef diagnostic_starter_fn diagnostic_finalizer_fn; 3390075Sobrien 3490075Sobrientypedef enum 3590075Sobrien{ 3690075Sobrien#define DEFINE_DIAGNOSTIC_KIND(K, M) K, 3790075Sobrien#include "diagnostic.def" 3890075Sobrien#undef DEFINE_DIAGNOSTIC_KIND 3990075Sobrien DK_LAST_DIAGNOSTIC_KIND 4090075Sobrien} diagnostic_t; 4190075Sobrien 4290075Sobrien#define pedantic_error_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING) 4390075Sobrien 4490075Sobrien/* How often diagnostics are prefixed by their locations: 4590075Sobrien o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported; 4690075Sobrien o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit only once; 4790075Sobrien o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit each time a physical 4890075Sobrien line is started. */ 4990075Sobrientypedef enum 5090075Sobrien{ 5190075Sobrien DIAGNOSTICS_SHOW_PREFIX_ONCE = 0x0, 5290075Sobrien DIAGNOSTICS_SHOW_PREFIX_NEVER = 0x1, 5390075Sobrien DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2 5490075Sobrien} diagnostic_prefixing_rule_t; 5590075Sobrien 5690075Sobrien/* The type of front-end specific hook that formats trees into an 5790075Sobrien output_buffer. A language specific printer returns a truth value if 5890075Sobrien everything goes well. */ 5990075Sobrientypedef int (*printer_fn) PARAMS ((output_buffer *)); 6090075Sobrien 6190075Sobrien/* This data structure encapsulates an output_buffer's state. */ 6290075Sobrientypedef struct 6390075Sobrien{ 6490075Sobrien /* The prefix for each new line. */ 6590075Sobrien const char *prefix; 6690075Sobrien 6790075Sobrien /* The real upper bound of number of characters per line, taking into 6890075Sobrien account the case of a very very looong prefix. */ 6990075Sobrien int maximum_length; 7090075Sobrien 7190075Sobrien /* The ideal upper bound of number of characters per line, as suggested 7290075Sobrien by front-end. */ 7390075Sobrien int ideal_maximum_length; 7490075Sobrien 7590075Sobrien /* Indentation count. */ 7690075Sobrien int indent_skip; 7790075Sobrien 7890075Sobrien /* Nonzero if current PREFIX was emitted at least once. */ 7990075Sobrien bool emitted_prefix_p; 8090075Sobrien 8190075Sobrien /* Nonzero means one should emit a newline before outputing anything. */ 8290075Sobrien bool need_newline_p; 8390075Sobrien 8490075Sobrien /* Current prefixing rule. */ 8590075Sobrien diagnostic_prefixing_rule_t prefixing_rule; 8690075Sobrien 8790075Sobrien /* The current char to output. Updated by front-end (*format_map) when 8890075Sobrien it is called to report front-end printer for a specified format. */ 8990075Sobrien const char *cursor; 9090075Sobrien 9190075Sobrien /* A pointer to the variable argument-list for formatting. */ 9290075Sobrien va_list *format_args; 9390075Sobrien 9490075Sobrien /* The number of times we have issued diagnostics. */ 9590075Sobrien int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND]; 9690075Sobrien} output_state; 9790075Sobrien 9890075Sobrien/* The output buffer datatype. This is best seen as an abstract datatype. */ 9990075Sobrienstruct output_buffer 10090075Sobrien{ 10190075Sobrien /* Internal data. These fields should not be accessed directly by 10290075Sobrien front-ends. */ 10390075Sobrien 10490075Sobrien /* The current state of the buffer. */ 10590075Sobrien output_state state; 10690075Sobrien 10790075Sobrien /* Where to output formatted text. */ 10890075Sobrien FILE* stream; 10990075Sobrien 11090075Sobrien /* The obstack where the text is built up. */ 11190075Sobrien struct obstack obstack; 11290075Sobrien 11390075Sobrien /* The amount of characters output so far. */ 11490075Sobrien int line_length; 11590075Sobrien 11690075Sobrien /* This must be large enough to hold any printed integer or 11790075Sobrien floating-point value. */ 11890075Sobrien char digit_buffer[128]; 11990075Sobrien 12090075Sobrien/* If non-NULL, this function formats data in the BUFFER. When called, 12190075Sobrien output_buffer_text_cursor (BUFFER) points to a format code. 12290075Sobrien FORMAT_DECODER should call output_add_string (and related functions) 12390075Sobrien to add data to the BUFFER. FORMAT_DECODER can read arguments from 12490075Sobrien output_buffer_format_args (BUFFER) using VA_ARG. If the BUFFER needs 12590075Sobrien additional characters from the format string, it should advance 12690075Sobrien the output_buffer_text_cursor (BUFFER) as it goes. When FORMAT_DECODER 12790075Sobrien returns, output_buffer_text_cursor (BUFFER) should point to the last 12890075Sobrien character processed. */ 12990075Sobrien 13090075Sobrien printer_fn format_decoder; 13190075Sobrien}; 13290075Sobrien 13390075Sobrien/* Current state of the diagnostic_context' output_buffer. This macro 13490075Sobrien accepts both `diagnostic_context *' and `output_buffer *'. */ 13590075Sobrien#define output_buffer_state(BUFFER) ((output_buffer *)(BUFFER))->state 13690075Sobrien 13790075Sobrien/* The stream attached to the output_buffer, where the formatted 13890075Sobrien diagnostics will ultimately go. Works only on `output_buffer *'. */ 13990075Sobrien#define output_buffer_attached_stream(BUFFER) (BUFFER)->stream 14090075Sobrien 14190075Sobrien/* This points to the beginning of the rest of the diagnostic message 14290075Sobrien to be formatted. Accepts only `output_buffer *'s. */ 14390075Sobrien#define output_buffer_text_cursor(BUFFER) (BUFFER)->state.cursor 14490075Sobrien 14590075Sobrien/* The rest of the `variable argument list' not yet processed. 14690075Sobrien This macro works on both `output_state *' and `output_buffer *'. */ 14790075Sobrien#define output_buffer_format_args(BUFFER) \ 14890075Sobrien *(((output_state *)(BUFFER))->format_args) 14990075Sobrien 15090075Sobrien/* In line-wrapping mode, whether we should start a new line. */ 15190075Sobrien#define output_needs_newline(BUFFER) (BUFFER)->state.need_newline_p 15290075Sobrien 15390075Sobrien/* The amount of whitespace to be emitted when starting a new line. */ 15490075Sobrien#define output_indentation(BUFFER) (BUFFER)->state.indent_skip 15590075Sobrien 15690075Sobrien/* A pointer to the formatted diagonstic message. */ 15790075Sobrien#define output_message_text(BUFFER) \ 15890075Sobrien ((const char *) obstack_base (&(BUFFER)->obstack)) 15990075Sobrien 16090075Sobrien/* This data structure bundles altogether any information relevant to 16190075Sobrien the context of a diagnostic message. */ 16290075Sobrienstruct diagnostic_context 16390075Sobrien{ 16490075Sobrien /* Where most of the diagnostic formatting work is done. In Object 16590075Sobrien Oriented terms, we'll say that diagnostic_context is a sub-class of 16690075Sobrien output_buffer. */ 16790075Sobrien output_buffer buffer; 16890075Sobrien 16990075Sobrien /* The diagnostic message to output. */ 17090075Sobrien const char *message; 17190075Sobrien 17290075Sobrien /* A pointer to a variable list of the arguments necessary for the 17390075Sobrien purpose of message formatting. */ 17490075Sobrien va_list *args_ptr; 17590075Sobrien 17690075Sobrien /* The name of the source file involved in the diiagnostic. */ 17790075Sobrien const char *file; 17890075Sobrien 17990075Sobrien /* The line-location in the source file. */ 18090075Sobrien int line; 18190075Sobrien 18290075Sobrien /* Is this message a warning? */ 18390075Sobrien int warn; 18490075Sobrien 18590075Sobrien /* This function is called before any message is printed out. It is 18690075Sobrien responsible for preparing message prefix and such. For example, it 18790075Sobrien might say: 18890075Sobrien In file included from "/usr/local/include/curses.h:5: 18990075Sobrien from "/home/gdr/src/nifty_printer.h:56: 19090075Sobrien ... 19190075Sobrien */ 19290075Sobrien void (*begin_diagnostic) PARAMS ((output_buffer *, diagnostic_context *)); 19390075Sobrien 19490075Sobrien /* This function is called after the diagnostic message is printed. */ 19590075Sobrien void (*end_diagnostic) PARAMS ((output_buffer *, diagnostic_context *)); 19690075Sobrien 19790075Sobrien /* Hook for front-end extensions. */ 19890075Sobrien void *x_data; 19990075Sobrien}; 20090075Sobrien 20190075Sobrien/* The diagnostic message being formatted. */ 20290075Sobrien#define diagnostic_message(DC) (DC)->message 20390075Sobrien 20490075Sobrien/* A pointer to the variable argument list used in a call 20590075Sobrien to a diagonstic routine. */ 20690075Sobrien#define diagnostic_argument_list(DC) (DC)->args_ptr 20790075Sobrien 20890075Sobrien/* The program file to which the diagnostic is referring to. */ 20990075Sobrien#define diagnostic_file_location(DC) (DC)->file 21090075Sobrien 21190075Sobrien/* The program source line referred to in the diagnostic message. */ 21290075Sobrien#define diagnostic_line_location(DC) (DC)->line 21390075Sobrien 21490075Sobrien/* Tell whether the diagnostic message is to be treated as a warning. */ 21590075Sobrien#define diagnostic_is_warning(DC) (DC)->warn 21690075Sobrien 21790075Sobrien/* Client supplied function to announce a diagnostic. */ 21890075Sobrien#define diagnostic_starter(DC) (DC)->begin_diagnostic 21990075Sobrien 22090075Sobrien/* Client supplied function called after a diagnostic message is 22190075Sobrien displayed. */ 22290075Sobrien#define diagnostic_finalizer(DC) (DC)->end_diagnostic 22390075Sobrien 22490075Sobrien/* Extension hook for client. */ 22590075Sobrien#define diagnostic_auxiliary_data(DC) (DC)->x_data 22690075Sobrien 22790075Sobrien/* Client supplied function used to decode formats. Can operate on both 22890075Sobrien `output_buffer *' and `diagnostic_context *'. */ 22990075Sobrien#define diagnostic_format_decoder(DC) ((output_buffer *)(DC))->format_decoder 23090075Sobrien 23190075Sobrien/* Prefixing rule used in formatting a diagnostic message. Accepts both 23290075Sobrien `output_buffer *' and `diagnostic_context *'. */ 23390075Sobrien#define diagnostic_prefixing_rule(DC) \ 23490075Sobrien ((output_buffer *)(DC))->state.prefixing_rule 23590075Sobrien 23690075Sobrien/* Maximum characters per line in automatic line wrapping mode. 23790075Sobrien Zero means don't wrap lines. */ 23890075Sobrien#define diagnostic_line_cutoff(DC) \ 23990075Sobrien ((output_buffer *)(DC))->state.ideal_maximum_length 24090075Sobrien 24190075Sobrien/* This diagnostic context is used by front-ends that directly output 24290075Sobrien diagnostic messages without going through `error', `warning', 24390075Sobrien and similar functions. */ 24490075Sobrienextern diagnostic_context *global_dc; 24590075Sobrien 24690075Sobrien/* This will be removed shortly. */ 24790075Sobrienextern output_buffer *diagnostic_buffer; 24890075Sobrien 24990075Sobrien/* The total count of a KIND of diagnostics meitted so far. */ 25090075Sobrien#define diagnostic_kind_count(DC, DK) \ 25190075Sobrien ((output_buffer *)(DC))->state.diagnostic_count[(int) (DK)] 25290075Sobrien 25390075Sobrien/* The number of errors that have been issued so far. Ideally, these 25490075Sobrien would take an output_buffer as an argument. */ 25590075Sobrien#define errorcount diagnostic_kind_count (global_dc, DK_ERROR) 25690075Sobrien/* Similarly, but for warnings. */ 25790075Sobrien#define warningcount diagnostic_kind_count (global_dc, DK_WARNING) 25890075Sobrien/* Similarly, but for sorrys. */ 25990075Sobrien#define sorrycount diagnostic_kind_count (global_dc, DK_SORRY) 26090075Sobrien 26190075Sobrien/* Returns non-zero if warnings should be emitted. */ 26290075Sobrien#define diagnostic_report_warnings_p() \ 26390075Sobrien (!inhibit_warnings \ 26490075Sobrien && !(in_system_header && !warn_system_headers)) 26590075Sobrien 26690075Sobrien 26790075Sobrien/* Prototypes */ 26890075Sobrienextern void set_diagnostic_context PARAMS ((diagnostic_context *, 26990075Sobrien const char *, va_list *, 27090075Sobrien const char *, int, int)); 27190075Sobrienextern void set_internal_error_function PARAMS ((void (*) 27290075Sobrien PARAMS ((const char *, 27390075Sobrien va_list *)))); 27490075Sobrienextern void report_diagnostic PARAMS ((diagnostic_context *)); 27590075Sobrienextern void diagnostic_initialize PARAMS ((diagnostic_context *)); 27690075Sobrienextern void init_output_buffer PARAMS ((output_buffer *, 27790075Sobrien const char *, int)); 27890075Sobrienextern void flush_diagnostic_buffer PARAMS ((void)); 27990075Sobrienextern void output_clear PARAMS ((output_buffer *)); 28090075Sobrienextern const char *output_get_prefix PARAMS ((const output_buffer *)); 28190075Sobrienextern const char *output_last_position PARAMS ((const output_buffer *)); 28290075Sobrienextern void output_set_prefix PARAMS ((output_buffer *, 28390075Sobrien const char *)); 28490075Sobrienextern void output_destroy_prefix PARAMS ((output_buffer *)); 28590075Sobrienextern void output_set_maximum_length PARAMS ((output_buffer *, int)); 28690075Sobrienextern void output_emit_prefix PARAMS ((output_buffer *)); 28790075Sobrienextern void output_add_newline PARAMS ((output_buffer *)); 28890075Sobrienextern void output_add_space PARAMS ((output_buffer *)); 28990075Sobrienextern int output_space_left PARAMS ((const output_buffer *)); 29090075Sobrienextern void output_append PARAMS ((output_buffer *, const char *, 29190075Sobrien const char *)); 29290075Sobrienextern void output_add_character PARAMS ((output_buffer *, int)); 29390075Sobrienextern void output_decimal PARAMS ((output_buffer *, int)); 29490075Sobrienextern void output_add_string PARAMS ((output_buffer *, 29590075Sobrien const char *)); 29690075Sobrienextern const char *output_finalize_message PARAMS ((output_buffer *)); 29790075Sobrienextern void output_clear_message_text PARAMS ((output_buffer *)); 29890075Sobrienextern void output_printf PARAMS ((output_buffer *, const char *, 29990075Sobrien ...)) ATTRIBUTE_PRINTF_2; 30090075Sobrienextern int output_is_line_wrapping PARAMS ((output_buffer *)); 30190075Sobrienextern void output_verbatim PARAMS ((output_buffer *, const char *, 30290075Sobrien ...)) ATTRIBUTE_PRINTF_2; 30390075Sobrienextern void verbatim PARAMS ((const char *, ...)) 30490075Sobrien ATTRIBUTE_PRINTF_1; 30590075Sobrienextern char *context_as_prefix PARAMS ((const char *, int, int)); 30690075Sobrienextern char *file_name_as_prefix PARAMS ((const char *)); 30790075Sobrienextern int error_module_changed PARAMS ((void)); 30890075Sobrienextern void record_last_error_module PARAMS ((void)); 30990075Sobrienextern int error_function_changed PARAMS ((void)); 31090075Sobrienextern void record_last_error_function PARAMS ((void)); 31190075Sobrienextern void report_problematic_module PARAMS ((output_buffer *)); 31290075Sobrien 31390075Sobrien/* Called by report_error_function to print out function name. 31490075Sobrien * Default may be overridden by language front-ends. */ 31590075Sobrienextern void (*print_error_function) PARAMS ((diagnostic_context *, 31690075Sobrien const char *)); 31790075Sobrien 31890075Sobrienextern void default_print_error_function PARAMS ((diagnostic_context *, 31990075Sobrien const char *)); 32090075Sobrien 32190075Sobrien#endif /* ! GCC_DIAGNOSTIC_H */ 322