190075Sobrien/* Various declarations for language-independent diagnostics subroutines. 2169689Skan Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 3169689Skan Free Software Foundation, Inc. 490075Sobrien Contributed by Gabriel Dos Reis <gdr@codesourcery.com> 590075Sobrien 690075SobrienThis file is part of GCC. 790075Sobrien 890075SobrienGCC is free software; you can redistribute it and/or modify it under 990075Sobrienthe terms of the GNU General Public License as published by the Free 1090075SobrienSoftware Foundation; either version 2, or (at your option) any later 1190075Sobrienversion. 1290075Sobrien 1390075SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY 1490075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or 1590075SobrienFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1690075Sobrienfor more details. 1790075Sobrien 1890075SobrienYou should have received a copy of the GNU General Public License 1990075Sobrienalong with GCC; see the file COPYING. If not, write to the Free 20169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 21169689Skan02110-1301, USA. */ 2290075Sobrien 2390075Sobrien#ifndef GCC_DIAGNOSTIC_H 2490075Sobrien#define GCC_DIAGNOSTIC_H 2590075Sobrien 26132718Skan#include "pretty-print.h" 27169689Skan#include "options.h" 2890075Sobrien 29132718Skan/* Constants used to discriminate diagnostics. */ 3090075Sobrientypedef enum 3190075Sobrien{ 32132718Skan#define DEFINE_DIAGNOSTIC_KIND(K, msgid) K, 3390075Sobrien#include "diagnostic.def" 3490075Sobrien#undef DEFINE_DIAGNOSTIC_KIND 3590075Sobrien DK_LAST_DIAGNOSTIC_KIND 3690075Sobrien} diagnostic_t; 3790075Sobrien 38117395Skan/* A diagnostic is described by the MESSAGE to send, the FILE and LINE of 39117395Skan its context and its KIND (ice, error, warning, note, ...) See complete 40117395Skan list in diagnostic.def. */ 41117395Skantypedef struct 42117395Skan{ 43117395Skan text_info message; 44117395Skan location_t location; 45117395Skan /* The kind of diagnostic it is about. */ 46117395Skan diagnostic_t kind; 47169689Skan /* Which OPT_* directly controls this diagnostic. */ 48169689Skan int option_index; 49117395Skan} diagnostic_info; 50117395Skan 5190075Sobrien#define pedantic_error_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING) 5290075Sobrien 5390075Sobrien 54117395Skan/* Forward declarations. */ 55117395Skantypedef struct diagnostic_context diagnostic_context; 56132718Skantypedef void (*diagnostic_starter_fn) (diagnostic_context *, 57132718Skan diagnostic_info *); 58117395Skantypedef diagnostic_starter_fn diagnostic_finalizer_fn; 59117395Skan 6090075Sobrien/* This data structure bundles altogether any information relevant to 6190075Sobrien the context of a diagnostic message. */ 6290075Sobrienstruct diagnostic_context 6390075Sobrien{ 64132718Skan /* Where most of the diagnostic formatting work is done. */ 65132718Skan pretty_printer *printer; 6690075Sobrien 67117395Skan /* The number of times we have issued diagnostics. */ 68117395Skan int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND]; 6990075Sobrien 70117395Skan /* True if we should display the "warnings are being tread as error" 71117395Skan message, usually displayed once per compiler run. */ 72169689Skan bool issue_warnings_are_errors_message; 73169689Skan 74169689Skan /* True if it has been requested that warnings be treated as errors. */ 75169689Skan bool warning_as_error_requested; 7690075Sobrien 77169689Skan /* For each option index that can be passed to warning() et all 78169689Skan (OPT_* from options.h), this array may contain a new kind that 79169689Skan the diagnostic should be changed to before reporting, or 80169689Skan DK_UNSPECIFIED to leave it as the reported kind, or DK_IGNORED to 81169689Skan not report it at all. N_OPTS is from <options.h>. */ 82169689Skan char classify_diagnostic[N_OPTS]; 83169689Skan 84169689Skan /* True if we should print the command line option which controls 85169689Skan each diagnostic, if known. */ 86169689Skan bool show_option_requested; 87169689Skan 88132718Skan /* True if we should raise a SIGABRT on errors. */ 89132718Skan bool abort_on_error; 90132718Skan 9190075Sobrien /* This function is called before any message is printed out. It is 9290075Sobrien responsible for preparing message prefix and such. For example, it 9390075Sobrien might say: 9490075Sobrien In file included from "/usr/local/include/curses.h:5: 9590075Sobrien from "/home/gdr/src/nifty_printer.h:56: 9690075Sobrien ... 9790075Sobrien */ 98117395Skan diagnostic_starter_fn begin_diagnostic; 9990075Sobrien 10090075Sobrien /* This function is called after the diagnostic message is printed. */ 101117395Skan diagnostic_finalizer_fn end_diagnostic; 10290075Sobrien 103117395Skan /* Client hook to report an internal error. */ 104132718Skan void (*internal_error) (const char *, va_list *); 105117395Skan 106117395Skan /* Function of last diagnostic message; more generally, function such that 107117395Skan if next diagnostic message is in it then we don't have to mention the 108117395Skan function name. */ 109117395Skan tree last_function; 110117395Skan 111117395Skan /* Used to detect when input_file_stack has changed since last described. */ 112117395Skan int last_module; 113117395Skan 114117395Skan int lock; 11590075Sobrien}; 11690075Sobrien 11790075Sobrien/* Client supplied function to announce a diagnostic. */ 11890075Sobrien#define diagnostic_starter(DC) (DC)->begin_diagnostic 11990075Sobrien 12090075Sobrien/* Client supplied function called after a diagnostic message is 12190075Sobrien displayed. */ 12290075Sobrien#define diagnostic_finalizer(DC) (DC)->end_diagnostic 12390075Sobrien 12490075Sobrien/* Extension hook for client. */ 12590075Sobrien#define diagnostic_auxiliary_data(DC) (DC)->x_data 12690075Sobrien 127132718Skan/* Same as pp_format_decoder. Works on 'diagnostic_context *'. */ 128132718Skan#define diagnostic_format_decoder(DC) ((DC)->printer->format_decoder) 12990075Sobrien 130117395Skan/* Same as output_prefixing_rule. Works on 'diagnostic_context *'. */ 131169689Skan#define diagnostic_prefixing_rule(DC) ((DC)->printer->wrapping.rule) 13290075Sobrien 13390075Sobrien/* Maximum characters per line in automatic line wrapping mode. 13490075Sobrien Zero means don't wrap lines. */ 135169689Skan#define diagnostic_line_cutoff(DC) ((DC)->printer->wrapping.line_cutoff) 13690075Sobrien 137132718Skan#define diagnostic_flush_buffer(DC) pp_base_flush ((DC)->printer) 138132718Skan 139117395Skan/* True if the last function in which a diagnostic was reported is 140117395Skan different from the current one. */ 141117395Skan#define diagnostic_last_function_changed(DC) \ 142117395Skan ((DC)->last_function != current_function_decl) 143117395Skan 144117395Skan/* Remember the current function as being the last one in which we report 145117395Skan a diagnostic. */ 146117395Skan#define diagnostic_set_last_function(DC) \ 147117395Skan (DC)->last_function = current_function_decl 148117395Skan 149117395Skan/* True if the last module or file in which a diagnostic was reported is 150117395Skan different from the current one. */ 151117395Skan#define diagnostic_last_module_changed(DC) \ 152117395Skan ((DC)->last_module != input_file_stack_tick) 153117395Skan 154117395Skan/* Remember the current module or file as being the last one in which we 155117395Skan report a diagnostic. */ 156117395Skan#define diagnostic_set_last_module(DC) \ 157117395Skan (DC)->last_module = input_file_stack_tick 158117395Skan 159132718Skan/* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */ 160132718Skan#define diagnostic_abort_on_error(DC) \ 161132718Skan (DC)->abort_on_error = true 162132718Skan 163117395Skan/* This diagnostic_context is used by front-ends that directly output 16490075Sobrien diagnostic messages without going through `error', `warning', 16590075Sobrien and similar functions. */ 16690075Sobrienextern diagnostic_context *global_dc; 16790075Sobrien 168132718Skan/* The total count of a KIND of diagnostics emitted so far. */ 169117395Skan#define diagnostic_kind_count(DC, DK) (DC)->diagnostic_count[(int) (DK)] 17090075Sobrien 17190075Sobrien/* The number of errors that have been issued so far. Ideally, these 172117395Skan would take a diagnostic_context as an argument. */ 17390075Sobrien#define errorcount diagnostic_kind_count (global_dc, DK_ERROR) 17490075Sobrien/* Similarly, but for warnings. */ 17590075Sobrien#define warningcount diagnostic_kind_count (global_dc, DK_WARNING) 17690075Sobrien/* Similarly, but for sorrys. */ 17790075Sobrien#define sorrycount diagnostic_kind_count (global_dc, DK_SORRY) 17890075Sobrien 179117395Skan/* Returns nonzero if warnings should be emitted. */ 18090075Sobrien#define diagnostic_report_warnings_p() \ 18190075Sobrien (!inhibit_warnings \ 18290075Sobrien && !(in_system_header && !warn_system_headers)) 18390075Sobrien 184117395Skan#define report_diagnostic(D) diagnostic_report_diagnostic (global_dc, D) 18590075Sobrien 186132718Skan/* Diagnostic related functions. */ 187132718Skanextern void diagnostic_initialize (diagnostic_context *); 188132718Skanextern void diagnostic_report_current_module (diagnostic_context *); 189132718Skanextern void diagnostic_report_current_function (diagnostic_context *); 190169689Skan 191169689Skan/* Force diagnostics controlled by OPTIDX to be kind KIND. */ 192169689Skanextern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *, 193169689Skan int /* optidx */, 194169689Skan diagnostic_t /* kind */); 195132718Skanextern void diagnostic_report_diagnostic (diagnostic_context *, 196132718Skan diagnostic_info *); 197169689Skan#ifdef ATTRIBUTE_GCC_DIAG 198132718Skanextern void diagnostic_set_info (diagnostic_info *, const char *, va_list *, 199169689Skan location_t, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0); 200169689Skanextern void diagnostic_set_info_translated (diagnostic_info *, const char *, 201169689Skan va_list *, location_t, 202169689Skan diagnostic_t) 203169689Skan ATTRIBUTE_GCC_DIAG(2,0); 204169689Skan#endif 205132718Skanextern char *diagnostic_build_prefix (diagnostic_info *); 206117395Skan 207117395Skan/* Pure text formatting support functions. */ 208132718Skanextern char *file_name_as_prefix (const char *); 20990075Sobrien 210169689Skan/* In tree-pretty-print.c */ 211169689Skanextern int dump_generic_node (pretty_printer *, tree, int, int, bool); 212169689Skanextern void print_generic_stmt (FILE *, tree, int); 213169689Skanextern void print_generic_stmt_indented (FILE *, tree, int, int); 214169689Skanextern void print_generic_expr (FILE *, tree, int); 215169689Skanextern void print_generic_decl (FILE *, tree, int); 216169689Skan 217169689Skanextern void debug_generic_expr (tree); 218169689Skanextern void debug_generic_stmt (tree); 219169689Skanextern void debug_tree_chain (tree); 220169689Skanextern void debug_c_tree (tree); 22190075Sobrien#endif /* ! GCC_DIAGNOSTIC_H */ 222