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 to    the 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() et      al.  */   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 GCC      options), this array may contain a new kind that the diagnostic      should be changed to before reporting, or DK_UNSPECIFIED to leave      it as the reported kind, or DK_IGNORED to not report it at      all.  */   diagnostic_t *classify_diagnostic;

  /* History of all changes to the classifications above.  This list      is stored in location-order, so we can search it, either      binary-wise or end-to-front, to find the most recent      classification for a given diagnostic, given the location of the      diagnostic.  */   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 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::MAX_RANGES];

  /* True if we should print the command line option which controls      each 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 into      warnings.  */   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 is      responsible for preparing message prefix and such.  For example, it      might 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 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;

  /* 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 is      enabled.  Returns nonzero if enabled, zero if disabled.  */   int (*option_enabled) (int, void *);

  /* Client information to pass as second argument to      option_enabled.  */   void *option_state;

  /* Client hook to return the name of an option that controls a      diagnostic.  Returns malloced memory.  The first diagnostic_t      argument is the kind of diagnostic before any reclassification      (of warnings as errors, etc.); the second is the kind after any      reclassification.  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 last      described.  */   const struct line_map *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; };

general_init-> diagnostic_initialize

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值