Mercurial > hg > CbC > GCC_original
diff gcc/diagnostic.h @ 16:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | f6334be47118 |
children | 84e7813d76e9 |
line wrap: on
line diff
--- a/gcc/diagnostic.h Sun Aug 21 07:07:55 2011 +0900 +++ b/gcc/diagnostic.h Fri Oct 27 22:46:09 2017 +0900 @@ -1,6 +1,5 @@ /* Various declarations for language-independent diagnostics subroutines. - Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 - 2010, Free Software Foundation, Inc. + Copyright (C) 2000-2017 Free Software Foundation, Inc. Contributed by Gabriel Dos Reis <gdr@codesourcery.com> This file is part of GCC. @@ -28,34 +27,43 @@ /* A diagnostic is described by the MESSAGE to send, the FILE and LINE of its context and its KIND (ice, error, warning, note, ...) See complete list in diagnostic.def. */ -typedef struct diagnostic_info +struct diagnostic_info { + /* Text to be formatted. */ text_info message; - location_t location; - unsigned int override_column; + + /* The location at which the diagnostic is to be reported. */ + rich_location *richloc; + /* Auxiliary data for client. */ void *x_data; /* The kind of diagnostic it is about. */ diagnostic_t kind; /* Which OPT_* directly controls this diagnostic. */ int option_index; -} diagnostic_info; +}; /* Each time a diagnostic's classification is changed with a pragma, we record the change and the location of the change in an array of these structs. */ -typedef struct diagnostic_classification_change_t +struct diagnostic_classification_change_t { location_t location; int option; diagnostic_t kind; -} diagnostic_classification_change_t; +}; /* Forward declarations. */ typedef void (*diagnostic_starter_fn) (diagnostic_context *, diagnostic_info *); + +typedef void (*diagnostic_start_span_fn) (diagnostic_context *, + expanded_location); + typedef diagnostic_starter_fn diagnostic_finalizer_fn; +class edit_context; + /* This data structure bundles altogether any information relevant to the context of a diagnostic message. */ struct diagnostic_context @@ -66,10 +74,6 @@ /* The number of times we have issued diagnostics. */ int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND]; - /* True if we should display the "warnings are being tread as error" - message, usually displayed once per compiler run. */ - bool some_warnings_are_errors; - /* True if it has been requested that warnings be treated as errors. */ bool warning_as_error_requested; @@ -99,6 +103,16 @@ int *push_list; int n_push; + /* True if we should print the source line with a caret indicating + the location. */ + bool show_caret; + + /* Maximum width of the source line printed. */ + int caret_max_width; + + /* Character used for caret diagnostics. */ + char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES]; + /* True if we should print the command line option which controls each diagnostic, if known. */ bool show_option_requested; @@ -129,7 +143,7 @@ bool dc_warn_system_headers; /* Maximum number of errors to report. */ - unsigned int max_errors; + int max_errors; /* This function is called before any message is printed out. It is responsible for preparing message prefix and such. For example, it @@ -140,6 +154,11 @@ */ diagnostic_starter_fn begin_diagnostic; + /* This function is called by diagnostic_show_locus in between + disjoint spans of source code, so that the context can print + something to indicate that a new span of source code has begun. */ + diagnostic_start_span_fn start_span; + /* This function is called after the diagnostic message is printed. */ diagnostic_finalizer_fn end_diagnostic; @@ -165,13 +184,37 @@ /* Auxiliary data for client. */ void *x_data; + /* Used to detect that the last caret was printed at the same location. */ + location_t last_location; + /* Used to detect when the input file stack has changed since last described. */ - const struct line_map *last_module; + const line_map_ordinary *last_module; int lock; bool inhibit_notes_p; + + /* When printing source code, should the characters at carets and ranges + be colorized? (assuming colorization is on at all). + This should be true for frontends that generate range information + (so that the ranges of code are colorized), + and false for frontends that merely specify points within the + source code (to avoid e.g. colorizing just the first character in + a token, which would look strange). */ + bool colorize_source_p; + + /* Usable by plugins; if true, print a debugging ruler above the + source output. */ + bool show_ruler_p; + + /* If true, print fixits in machine-parseable form after the + rest of the diagnostic. */ + bool parseable_fixits_p; + + /* If non-NULL, an edit_context to which fix-it hints should be + applied, for generating patches. */ + edit_context *edit_context_ptr; }; static inline void @@ -198,22 +241,6 @@ /* Same as output_prefixing_rule. Works on 'diagnostic_context *'. */ #define diagnostic_prefixing_rule(DC) ((DC)->printer->wrapping.rule) -/* Maximum characters per line in automatic line wrapping mode. - Zero means don't wrap lines. */ -#define diagnostic_line_cutoff(DC) ((DC)->printer->wrapping.line_cutoff) - -#define diagnostic_flush_buffer(DC) pp_base_flush ((DC)->printer) - -/* True if the last module or file in which a diagnostic was reported is - different from the current one. */ -#define diagnostic_last_module_changed(DC, MAP) \ - ((DC)->last_module != MAP) - -/* Remember the current module or file as being the last one in which we - report a diagnostic. */ -#define diagnostic_set_last_module(DC, MAP) \ - (DC)->last_module = MAP - /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */ #define diagnostic_abort_on_error(DC) \ (DC)->abort_on_error = true @@ -231,6 +258,8 @@ #define errorcount diagnostic_kind_count (global_dc, DK_ERROR) /* Similarly, but for warnings. */ #define warningcount diagnostic_kind_count (global_dc, DK_WARNING) +/* Similarly, but for warnings promoted to errors. */ +#define werrorcount diagnostic_kind_count (global_dc, DK_WERROR) /* Similarly, but for sorrys. */ #define sorrycount diagnostic_kind_count (global_dc, DK_SORRY) @@ -239,21 +268,23 @@ (!(DC)->dc_inhibit_warnings \ && !(in_system_header_at (LOC) && !(DC)->dc_warn_system_headers)) -#define report_diagnostic(D) diagnostic_report_diagnostic (global_dc, D) - -/* Override the column number to be used for reporting a - diagnostic. */ -#define diagnostic_override_column(DI, COL) (DI)->override_column = (COL) - /* Override the option index to be used for reporting a diagnostic. */ -#define diagnostic_override_option_index(DI, OPTIDX) \ - ((DI)->option_index = (OPTIDX)) + +static inline void +diagnostic_override_option_index (diagnostic_info *info, int optidx) +{ + info->option_index = optidx; +} /* Diagnostic related functions. */ extern void diagnostic_initialize (diagnostic_context *, int); +extern void diagnostic_color_init (diagnostic_context *, int value = -1); extern void diagnostic_finish (diagnostic_context *); -extern void diagnostic_report_current_module (diagnostic_context *); +extern void diagnostic_report_current_module (diagnostic_context *, location_t); +extern void diagnostic_show_locus (diagnostic_context *, + rich_location *richloc, + diagnostic_t diagnostic_kind); /* Force diagnostics controlled by OPTIDX to be kind KIND. */ extern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *, @@ -266,17 +297,77 @@ diagnostic_info *); #ifdef ATTRIBUTE_GCC_DIAG extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *, - location_t, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0); + rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0); extern void diagnostic_set_info_translated (diagnostic_info *, const char *, - va_list *, location_t, + va_list *, rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0); +extern void diagnostic_append_note (diagnostic_context *, location_t, + const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); #endif -extern char *diagnostic_build_prefix (diagnostic_context *, diagnostic_info *); +extern char *diagnostic_build_prefix (diagnostic_context *, const diagnostic_info *); void default_diagnostic_starter (diagnostic_context *, diagnostic_info *); +void default_diagnostic_start_span_fn (diagnostic_context *, + expanded_location); void default_diagnostic_finalizer (diagnostic_context *, diagnostic_info *); +void diagnostic_set_caret_max_width (diagnostic_context *context, int value); +void diagnostic_action_after_output (diagnostic_context *, diagnostic_t); +void diagnostic_check_max_errors (diagnostic_context *, bool flush = false); + +void diagnostic_file_cache_fini (void); + +int get_terminal_width (void); + +/* Return the location associated to this diagnostic. Parameter WHICH + specifies which location. By default, expand the first one. */ + +static inline location_t +diagnostic_location (const diagnostic_info * diagnostic, int which = 0) +{ + return diagnostic->message.get_location (which); +} + +/* Return the number of locations to be printed in DIAGNOSTIC. */ + +static inline unsigned int +diagnostic_num_locations (const diagnostic_info * diagnostic) +{ + return diagnostic->message.m_richloc->get_num_locations (); +} + +/* Expand the location of this diagnostic. Use this function for + consistency. Parameter WHICH specifies which location. By default, + expand the first one. */ + +static inline expanded_location +diagnostic_expand_location (const diagnostic_info * diagnostic, int which = 0) +{ + return diagnostic->richloc->get_expanded_location (which); +} + +/* This is somehow the right-side margin of a caret line, that is, we + print at least these many characters after the position pointed at + by the caret. */ +const int CARET_LINE_MARGIN = 10; + +/* Return true if the two locations can be represented within the same + caret line. This is used to build a prefix and also to determine + whether to print one or two caret lines. */ + +static inline bool +diagnostic_same_line (const diagnostic_context *context, + expanded_location s1, expanded_location s2) +{ + return s2.column && s1.line == s2.line + && context->caret_max_width - CARET_LINE_MARGIN > abs (s1.column - s2.column); +} + +extern const char *diagnostic_get_color_for_kind (diagnostic_t kind); /* Pure text formatting support functions. */ -extern char *file_name_as_prefix (const char *); +extern char *file_name_as_prefix (diagnostic_context *, const char *); + +extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1; + #endif /* ! GCC_DIAGNOSTIC_H */