本文主要是介绍GCC主要数据结构之diagnostic_context,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
GCC:gcc/diagnostic.h
这是一个用于描述对源程序进行诊断控制的结构,一般每种语言对应一个这种结构对象。
相关全局对象定义如下:
/* A diagnostic_context surrogate for stderr. */
static diagnostic_context global_diagnostic_context;
diagnostic_context *global_dc = &global_diagnostic_context;
当然,对诊断对象初始化的是函数diagnostic_initialize().
先看相关结构定义:
/* 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;
/* This data structure bundles altogether any information relevant tothe context of a diagnostic message. */ struct diagnostic_context {/* Where most of the diagnostic formatting work is done. */ pretty_printer *printer;
/* The number of times we have issued diagnostics. */ int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
/* True if it has been requested that warnings be treated as errors. */ bool warning_as_error_requested;
/* The number of option indexes that can be passed to warning() etal. */int n_opts;
/* For each option index that can be passed to warning() et al(OPT_* from options.h when using this code with the core GCCoptions), this array may contain a new kind that the diagnosticshould be changed to before reporting, or DK_UNSPECIFIED to leaveit as the reported kind, or DK_IGNORED to not report it atall. */diagnostic_t *classify_diagnostic;
/* History of all changes to the classifications above. This listis stored in location-order, so we can search it, eitherbinary-wise or end-to-front, to find the most recentclassification for a given diagnostic, given the location of thediagnostic. */diagnostic_classification_change_t *classification_history;
/* The size of the above array. */int n_classification_history;
/* For pragma push/pop. */int *push_list;int n_push;
/* True if we should print the source line with a caret indicatingthe 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::MAX_RANGES];
/* True if we should print the command line option which controlseach diagnostic, if known. */bool show_option_requested;
/* True if we should raise a SIGABRT on errors. */bool abort_on_error;
/* True if we should show the column number on diagnostics. */bool show_column;
/* True if pedwarns are errors. */bool pedantic_errors;
/* True if permerrors are warnings. */bool permissive;
/* The index of the option to associate with turning permerrors intowarnings. */int opt_permissive;
/* True if errors are fatal. */bool fatal_errors;
/* True if all warnings should be disabled. */bool dc_inhibit_warnings;
/* True if warnings should be given in system headers. */bool dc_warn_system_headers;
/* Maximum number of errors to report. */unsigned int max_errors;
/* This function is called before any message is printed out. It isresponsible for preparing message prefix and such. For example, itmight say:In file included from "/usr/local/include/curses.h:5:from "/home/gdr/src/nifty_printer.h:56:...*/diagnostic_starter_fn begin_diagnostic;
/* This function is called by diagnostic_show_locus in betweendisjoint spans of source code, so that the context can printsomething 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;
/* Client hook to report an internal error. */void (*internal_error) (diagnostic_context *, const char *, va_list *);
/* Client hook to say whether the option controlling a diagnostic isenabled. Returns nonzero if enabled, zero if disabled. */int (*option_enabled) (int, void *);
/* Client information to pass as second argument tooption_enabled. */void *option_state;
/* Client hook to return the name of an option that controls adiagnostic. Returns malloced memory. The first diagnostic_targument is the kind of diagnostic before any reclassification(of warnings as errors, etc.); the second is the kind after anyreclassification. May return NULL if no name is to be printed.May be passed 0 as well as the index of a particular option. */char *(*option_name) (diagnostic_context *, int, diagnostic_t, diagnostic_t);
/* 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 lastdescribed. */const struct line_map *last_module;
int lock;
bool inhibit_notes_p;
/* When printing source code, should the characters at carets and rangesbe 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 thesource code (to avoid e.g. colorizing just the first character ina token, which would look strange). */bool colorize_source_p; };
general_init-> diagnostic_initialize
这篇关于GCC主要数据结构之diagnostic_context的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!