This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Diagnostic cleanup, #3



This patch documents various macros as well as making them
polymorphic.

Bootstrapped and tested on i686-pc-linux.

-- Gaby

2001-06-27  Gabriel Dos Reis  <gdr@codesourcery.com>

	* diagnostic.h: Add documentation. Make macros polymorphic.
	* diagnostic.c (ideal_line_wrap_cutoff): Remove
	definition. Replace with diagnostic_line_cutoff.
	(prefixing_policy): Remove. Replace with diagnostic_prefixing_rule.

Index: gcc/diagnostic.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/diagnostic.c,v
retrieving revision 1.61
diff -p -r1.61 diagnostic.c
*** diagnostic.c	2001/06/26 19:18:35	1.61
--- diagnostic.c	2001/06/27 17:57:41
*************** Boston, MA 02111-1307, USA.  */
*** 52,60 ****
  #define is_starting_newline(BUFFER) (output_text_length (BUFFER) == 0)
  #define output_prefix(BUFFER) (BUFFER)->state.prefix
  #define line_wrap_cutoff(BUFFER) (BUFFER)->state.maximum_length
- #define ideal_line_wrap_cutoff(BUFFER) (BUFFER)->state.ideal_maximum_length
  #define prefix_was_emitted_for(BUFFER) (BUFFER)->state.emitted_prefix_p
- #define prefixing_policy(BUFFER) (BUFFER)->state.prefixing_rule
  #define output_buffer_ptr_to_format_args(BUFFER) (BUFFER)->state.format_args
  
  #define diagnostic_args output_buffer_ptr_to_format_args (diagnostic_buffer)
--- 52,58 ----
*************** int
*** 189,195 ****
  output_is_line_wrapping (buffer)
       output_buffer *buffer;
  {
!   return ideal_line_wrap_cutoff (buffer) > 0;
  }
  
  /* Return BUFFER's prefix.  */
--- 187,193 ----
  output_is_line_wrapping (buffer)
       output_buffer *buffer;
  {
!   return diagnostic_line_cutoff (buffer) > 0;
  }
  
  /* Return BUFFER's prefix.  */
*************** set_real_maximum_length (buffer)
*** 212,230 ****
     we'll emit prefix only once per diagnostic message, it is appropriate
    not to increase unncessarily the line-length cut-off.  */
    if (! output_is_line_wrapping (buffer)
!       || prefixing_policy (buffer) == DIAGNOSTICS_SHOW_PREFIX_ONCE
!       || prefixing_policy (buffer) == DIAGNOSTICS_SHOW_PREFIX_NEVER)
!     line_wrap_cutoff (buffer) = ideal_line_wrap_cutoff (buffer);
    else
      {
        int prefix_length =
          output_prefix (buffer) ? strlen (output_prefix (buffer)) : 0;
        /* If the prefix is ridiculously too long, output at least
           32 characters.  */
!       if (ideal_line_wrap_cutoff (buffer) - prefix_length < 32)
!         line_wrap_cutoff (buffer) = ideal_line_wrap_cutoff (buffer) + 32;
        else
!         line_wrap_cutoff (buffer) = ideal_line_wrap_cutoff (buffer);
      }
  }
  
--- 210,228 ----
     we'll emit prefix only once per diagnostic message, it is appropriate
    not to increase unncessarily the line-length cut-off.  */
    if (! output_is_line_wrapping (buffer)
!       || diagnostic_prefixing_rule (buffer) == DIAGNOSTICS_SHOW_PREFIX_ONCE
!       || diagnostic_prefixing_rule (buffer) == DIAGNOSTICS_SHOW_PREFIX_NEVER)
!     line_wrap_cutoff (buffer) = diagnostic_line_cutoff (buffer);
    else
      {
        int prefix_length =
          output_prefix (buffer) ? strlen (output_prefix (buffer)) : 0;
        /* If the prefix is ridiculously too long, output at least
           32 characters.  */
!       if (diagnostic_line_cutoff (buffer) - prefix_length < 32)
!         line_wrap_cutoff (buffer) = diagnostic_line_cutoff (buffer) + 32;
        else
!         line_wrap_cutoff (buffer) = diagnostic_line_cutoff (buffer);
      }
  }
  
*************** output_set_maximum_length (buffer, lengt
*** 236,242 ****
       output_buffer *buffer;
       int length;
  {
!   ideal_line_wrap_cutoff (buffer) = length;
    set_real_maximum_length (buffer);
  }
  
--- 234,240 ----
       output_buffer *buffer;
       int length;
  {
!   diagnostic_line_cutoff (buffer) = length;
    set_real_maximum_length (buffer);
  }
  
*************** init_output_buffer (buffer, prefix, maxi
*** 313,320 ****
    memset (buffer, 0, sizeof (output_buffer));
    obstack_init (&buffer->obstack);
    output_buffer_attached_stream (buffer) = stderr;
!   ideal_line_wrap_cutoff (buffer) = maximum_length;
!   prefixing_policy (buffer) = diagnostic_prefixing_rule (global_dc);
    output_set_prefix (buffer, prefix);
    output_text_length (buffer) = 0;
    clear_diagnostic_info (buffer);  
--- 311,318 ----
    memset (buffer, 0, sizeof (output_buffer));
    obstack_init (&buffer->obstack);
    output_buffer_attached_stream (buffer) = stderr;
!   diagnostic_line_cutoff (buffer) = maximum_length;
!   diagnostic_prefixing_rule (buffer) = diagnostic_prefixing_rule (global_dc);
    output_set_prefix (buffer, prefix);
    output_text_length (buffer) = 0;
    clear_diagnostic_info (buffer);  
*************** output_emit_prefix (buffer)
*** 366,372 ****
  {
    if (output_prefix (buffer) != NULL)
      {
!       switch (prefixing_policy (buffer))
          {
          default:
          case DIAGNOSTICS_SHOW_PREFIX_NEVER:
--- 364,370 ----
  {
    if (output_prefix (buffer) != NULL)
      {
!       switch (diagnostic_prefixing_rule (buffer))
          {
          default:
          case DIAGNOSTICS_SHOW_PREFIX_NEVER:
*************** output_do_verbatim (buffer, msgid, args_
*** 1559,1565 ****
  
    os = output_buffer_state (buffer);
    output_prefix (buffer) = NULL;
!   prefixing_policy (buffer) = DIAGNOSTICS_SHOW_PREFIX_NEVER;
    output_buffer_text_cursor (buffer) = _(msgid);
    output_buffer_ptr_to_format_args (buffer) = args_ptr;
    output_set_maximum_length (buffer, 0);
--- 1557,1563 ----
  
    os = output_buffer_state (buffer);
    output_prefix (buffer) = NULL;
!   diagnostic_prefixing_rule (buffer) = DIAGNOSTICS_SHOW_PREFIX_NEVER;
    output_buffer_text_cursor (buffer) = _(msgid);
    output_buffer_ptr_to_format_args (buffer) = args_ptr;
    output_set_maximum_length (buffer, 0);
Index: gcc/diagnostic.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/diagnostic.h,v
retrieving revision 1.30
diff -p -r1.30 diagnostic.h
*** diagnostic.h	2001/06/26 19:18:35	1.30
--- diagnostic.h	2001/06/27 17:57:41
*************** typedef struct
*** 76,85 ****
    int indent_skip;
  
    /* Nonzero if current PREFIX was emitted at least once.  */
!   int emitted_prefix_p;
  
    /* Nonzero means one should emit a newline before outputing anything.  */
!   int need_newline_p;
  
    /* Current prefixing rule.  */
    diagnostic_prefixing_rule_t prefixing_rule;
--- 76,85 ----
    int indent_skip;
  
    /* Nonzero if current PREFIX was emitted at least once.  */
!   bool emitted_prefix_p;
  
    /* Nonzero means one should emit a newline before outputing anything.  */
!   bool need_newline_p;
  
    /* Current prefixing rule.  */
    diagnostic_prefixing_rule_t prefixing_rule;
*************** struct output_buffer
*** 130,142 ****
    printer_fn format_decoder;
  };
  
! #define output_buffer_state(BUFFER) (BUFFER)->state
  #define output_buffer_attached_stream(BUFFER) (BUFFER)->stream
  #define output_buffer_text_cursor(BUFFER) (BUFFER)->state.cursor
! #define output_buffer_format_args(BUFFER) *((BUFFER)->state.format_args)
  #define output_needs_newline(BUFFER) (BUFFER)->state.need_newline_p
! #define output_buffer_state(BUFFER) (BUFFER)->state
  #define output_indentation(BUFFER) (BUFFER)->state.indent_skip
  #define output_message_text(BUFFER) \
     ((const char *) obstack_base (&(BUFFER)->obstack))
  
--- 130,159 ----
    printer_fn format_decoder;
  };
  
! /* Current state of the diagnostic_context' output_buffer.  This macro
!    accepts both `diagnostic_context *' and `output_buffer *'.  */
! #define output_buffer_state(BUFFER) ((output_buffer *)BUFFER)->state
! 
! /* The stream attached to the output_buffer, where the formatted
!    diagnostics will ultimately go.  Works only on `output_buffer *'.  */
  #define output_buffer_attached_stream(BUFFER) (BUFFER)->stream
+ 
+ /* This points to the beginning of the rest of the diagnostic message
+    to be formatted.  Accepts only `output_buffer *'s.  */
  #define output_buffer_text_cursor(BUFFER) (BUFFER)->state.cursor
! 
! /* The rest of the `variable argument list' not yet processed.
!    This macro works on both `output_state *' and `output_buffer *'.  */
! #define output_buffer_format_args(BUFFER) \
!    *(((output_state *)BUFFER)->format_args)
! 
! /* In line-wrapping mode, whether we should start a new line.  */
  #define output_needs_newline(BUFFER) (BUFFER)->state.need_newline_p
! 
! /* The amount of whitespace to be emitted when starting a new line.  */
  #define output_indentation(BUFFER) (BUFFER)->state.indent_skip
+ 
+ /* A pointer to the formatted diagonstic message.  */
  #define output_message_text(BUFFER) \
     ((const char *) obstack_base (&(BUFFER)->obstack))
  
*************** struct diagnostic_context
*** 181,219 ****
    void *x_data;
  };
  
  #define diagnostic_message(DC) (DC)->message
  #define diagnostic_argument_list(DC) (DC)->args_ptr
  #define diagnostic_file_location(DC) (DC)->file
  #define diagnostic_line_location(DC) (DC)->line
  #define diagnostic_is_warning(DC) (DC)->warn
  #define diagnostic_starter(DC) (DC)->begin_diagnostic
  #define diagnostic_finalizer(DC) (DC)->end_diagnostic
  #define diagnostic_auxiliary_data(DC) (DC)->x_data
- #define diagnostic_format_decoder(DC) (DC)->buffer.format_decoder
- #define diagnostic_prefixing_rule(DC) (DC)->buffer.state.prefixing_rule
  
  /* Maximum characters per line in automatic line wrapping mode.
     Zero means don't wrap lines. */
! #define diagnostic_line_cutoff(DC) (DC)->buffer.state.ideal_maximum_length
  
! /* This output buffer is used by front-ends that directly output
     diagnostic messages without going through `error', `warning',
!    and similar functions.  In general, such usage should be
!    avoided.  This global buffer will go away, once all such usage
!    has been removed.  */
! extern output_buffer *diagnostic_buffer;
  extern diagnostic_context *global_dc;
  
! #define diagnostic_kind_count(BUFFER, DK) \
!    (BUFFER)->state.diagnostic_count[(int) DK]
  
  /* The number of errors that have been issued so far.  Ideally, these
     would take an output_buffer as an argument.  */
! #define errorcount diagnostic_kind_count (diagnostic_buffer, DK_ERROR)
  /* Similarly, but for warnings.  */
! #define warningcount diagnostic_kind_count (diagnostic_buffer, DK_WARNING)
  /* Similarly, but for sorrys.  */
! #define sorrycount diagnostic_kind_count (diagnostic_buffer, DK_SORRY)
  
  /* Returns non-zero if warnings should be emitted.  */
  #define diagnostic_report_warnings_p()			\
--- 198,262 ----
    void *x_data;
  };
  
+ /* The diagnostic message being formatted.  */
  #define diagnostic_message(DC) (DC)->message
+ 
+ /* A pointer to the variable argument list used in a call
+    to a diagonstic routine.  */   
  #define diagnostic_argument_list(DC) (DC)->args_ptr
+ 
+ /* The program file to which the diagnostic is referring to.  */
  #define diagnostic_file_location(DC) (DC)->file
+ 
+ /* The program source line referred to in the diagnostic message.  */
  #define diagnostic_line_location(DC) (DC)->line
+ 
+ /* Tell whether the diagnostic message is to be treated as a warning.  */
  #define diagnostic_is_warning(DC) (DC)->warn
+ 
+ /* Client supplied function to announce a diagnostic.  */
  #define diagnostic_starter(DC) (DC)->begin_diagnostic
+ 
+ /* Client supplied function called after a diagnostic message is
+    displayed.  */
  #define diagnostic_finalizer(DC) (DC)->end_diagnostic
+ 
+ /* Extention hook for client.  */
  #define diagnostic_auxiliary_data(DC) (DC)->x_data
  
+ /* Client supplied function used to decode formats.  Can operate on both
+  `output_buffer *' and `diagnostic_context *'.  */
+ #define diagnostic_format_decoder(DC) ((output_buffer *)DC)->format_decoder
+ 
+ /* Prefixing rule used in formatting a diagnostic message.  Accepts both
+    `output_buffer *' and `diagnostic_context *'.  */
+ #define diagnostic_prefixing_rule(DC) \
+    ((output_buffer *)DC)->state.prefixing_rule
+ 
  /* Maximum characters per line in automatic line wrapping mode.
     Zero means don't wrap lines. */
! #define diagnostic_line_cutoff(DC) \
!    ((output_buffer *)DC)->state.ideal_maximum_length
  
! /* This diagnostic context is used by front-ends that directly output
     diagnostic messages without going through `error', `warning',
!    and similar functions.  */
  extern diagnostic_context *global_dc;
+ 
+ /* This will be removed shortly.  */
+ extern output_buffer *diagnostic_buffer;
  
! /* The total count of a KIND of diagnostics meitted so far.  */
! #define diagnostic_kind_count(DC, DK) \
!    ((output_buffer *)DC)->state.diagnostic_count[(int) DK]
  
  /* The number of errors that have been issued so far.  Ideally, these
     would take an output_buffer as an argument.  */
! #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 sorrys.  */
! #define sorrycount diagnostic_kind_count (global_dc, DK_SORRY)
  
  /* Returns non-zero if warnings should be emitted.  */
  #define diagnostic_report_warnings_p()			\


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]