public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Slightly extended example for named warnings
@ 2003-01-26 23:28 Bruce Korb
  2003-01-27  1:20 ` Joseph S. Myers
  0 siblings, 1 reply; 6+ messages in thread
From: Bruce Korb @ 2003-01-26 23:28 UTC (permalink / raw)
  To: gcc; +Cc: Bruce Korb

[-- Attachment #1: Type: text/plain, Size: 1221 bytes --]


Here goes again.

The attached example output is actually highly flexible,
but extending it over the engire GCC source would enable
the fiddling with GCC error and warning handling almost any
way anyone could possibly want.  You can easily do it by
number or name.  Furthermore, you could even translate the
attached file into multiple languages and use dlopen instead
of gettext, opening the variant of choice.  Were you to want
to do that.  In any event, this incarnation has this struct
describing every "diagnostic":

> typedef struct {
>   const diagnostic_t    diag_type;
>   diagnostic_t          diag_state;
>   diag_id_t             diag_id;
>   int*                  p_state_stack;
>   int                   stack_depth;
>   const char* const     diag_name;
>   const char* const     msg_id;
>   const char*           localized_msg;
>   const char* const     doc;
> } diag_state_t;

where "doc" would be the extended warning message.
So, attached first is the generated diag-macro.h file,
followed by the diff of a couple of sample source files.
Oh, and if anyone is wondering, there's a mechanism for
keeping the diagnostic numbers static, which is how I
was able to insert an artificial hole in the sequence.

[-- Attachment #2: diag-macros.h --]
[-- Type: text/plain, Size: 10392 bytes --]

/*   -*- buffer-read-only: t -*- vi: set ro:
 *  
 *  DO NOT EDIT THIS FILE   (diag-macros.h)
 *  
 *  It has been AutoGen-ed  
 *  From the definitions    diag-macros.def
 *  and the template file   diagnostic.tpl
 *
 *  Copyright (C) 2003 Free Software Foundation, Inc.
 *
 *  GCC is free software.
 *  
 *  You may redistribute it and/or modify it under the terms of the
 *  GNU General Public License, as published by the Free Software
 *  Foundation; either version 2, or (at your option) any later version.
 *  
 *  GCC is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with GCC.  See the file "COPYING".  If not,
 *  write to:  The Free Software Foundation, Inc.,
 *             59 Temple Place - Suite 330,
 *             Boston,  MA  02111-1307, USA.
 */
#ifndef GCC_DIAG_MACROS_H_GUARD
#define GCC_DIAG_MACROS_H_GUARD
/*
 *  Enumerate the diagnostic levels
 */
typedef enum {
  DK_FATAL,
  DK_ICE,
  DK_SORRY,
  DK_ERROR,
  DK_WARNING,
  DK_ANACRONISM,
  DK_NOTE,
  DK_DEBUG,
  DK_SUPPRESSED
} diagnostic_t;
#define  DK_LAST_DIAGNOSTIC_KIND 8

/*
 *  Enumerate every diagnostic message in GCC.
 *  The value is the diagnostic number.
 */
typedef enum {
  DIAG_WARNING_UNPUSHED_POP                     = 101,
  DIAG_WARNING_UNPUSHED_POP_ID                  = 102,
  DIAG_WARNING_NO_PRAGMA_PUSH_POP               = 103,
  DIAG_WARNING_PRAGMA_PACK_SYNTAX               = 104,
  DIAG_WARNING_MALFORMED_PRAGMA                 = 105,
  DIAG_WARNING_BAD_PACK_ACTION                  = 106,
  DIAG_WARNING_PRAGMA_JUNK                      = 107,
  DIAG_WARNING_ALIGN_NOT_POWER_OF_2             = 108,
  DIAG_WARNING_WEAK_TOO_LATE                    = 109,
  DIAG_WARNING_REDEFINE_CONFLICT                = 120,
  DIAG_WARNING_RENAME_CONFLICT                  = 121,
  DIAG_DEBUG_ENTER_HANDLE_PRAGMA_PACK           = 122,
  DIAG_ICE_UNSUPPORTED_WIDE_INT                 = 123,
  DIAG_ERROR_PARAM_SIZE_DEPENDENCY              = 124
} diag_id_t;

#define MIN_DIAGNOSTIC_NUM     101
#define MAX_DIAGNOSTIC_NUM     124

/*
 *  Message Emission Macros
 */
#ifdef DEBUG
#  define ACTIVE_DIAG(n) \
 (diag_states[n].diag_state < DK_SUPPRESSED)
#else
#  define ACTIVE_DIAG(n) \
 (diag_states[n].diag_state < DK_DEBUG)
#endif

#define WARNING_UNPUSHED_POP \
	if (ACTIVE_DIAG(DIAG_WARNING_UNPUSHED_POP)) \
	  assemble_diagnostics (DIAG_WARNING_UNPUSHED_POP)

#define WARNING_UNPUSHED_POP_ID(_arg1, _arg2) \
	if (ACTIVE_DIAG(DIAG_WARNING_UNPUSHED_POP_ID)) \
	  assemble_diagnostics (DIAG_WARNING_UNPUSHED_POP_ID, \
		(_arg1), (_arg2))

#define WARNING_NO_PRAGMA_PUSH_POP(_arg1) \
	if (ACTIVE_DIAG(DIAG_WARNING_NO_PRAGMA_PUSH_POP)) \
	  assemble_diagnostics (DIAG_WARNING_NO_PRAGMA_PUSH_POP, \
		(_arg1))

#define WARNING_PRAGMA_PACK_SYNTAX \
	if (ACTIVE_DIAG(DIAG_WARNING_PRAGMA_PACK_SYNTAX)) \
	  assemble_diagnostics (DIAG_WARNING_PRAGMA_PACK_SYNTAX)

#define WARNING_MALFORMED_PRAGMA(_arg1) \
	if (ACTIVE_DIAG(DIAG_WARNING_MALFORMED_PRAGMA)) \
	  assemble_diagnostics (DIAG_WARNING_MALFORMED_PRAGMA, \
		(_arg1))

#define WARNING_BAD_PACK_ACTION(_arg1) \
	if (ACTIVE_DIAG(DIAG_WARNING_BAD_PACK_ACTION)) \
	  assemble_diagnostics (DIAG_WARNING_BAD_PACK_ACTION, \
		(_arg1))

#define WARNING_PRAGMA_JUNK(_arg1) \
	if (ACTIVE_DIAG(DIAG_WARNING_PRAGMA_JUNK)) \
	  assemble_diagnostics (DIAG_WARNING_PRAGMA_JUNK, \
		(_arg1))

#define WARNING_ALIGN_NOT_POWER_OF_2(_arg1) \
	if (ACTIVE_DIAG(DIAG_WARNING_ALIGN_NOT_POWER_OF_2)) \
	  assemble_diagnostics (DIAG_WARNING_ALIGN_NOT_POWER_OF_2, \
		(_arg1))

#define WARNING_WEAK_TOO_LATE(_arg1) \
	if (ACTIVE_DIAG(DIAG_WARNING_WEAK_TOO_LATE)) \
	  assemble_diag_with_decl (DIAG_WARNING_WEAK_TOO_LATE, \
		(_arg1))

#define WARNING_REDEFINE_CONFLICT \
	if (ACTIVE_DIAG(DIAG_WARNING_REDEFINE_CONFLICT)) \
	  assemble_diagnostics (DIAG_WARNING_REDEFINE_CONFLICT)

#define WARNING_RENAME_CONFLICT \
	if (ACTIVE_DIAG(DIAG_WARNING_RENAME_CONFLICT)) \
	  assemble_diagnostics (DIAG_WARNING_RENAME_CONFLICT)

#ifndef DEBUG
#  define DEBUG_ENTER_HANDLE_PRAGMA_PACK(_arg1)
#else
#  define DEBUG_ENTER_HANDLE_PRAGMA_PACK(_arg1) \
	if (ACTIVE_DIAG(DIAG_DEBUG_ENTER_HANDLE_PRAGMA_PACK)) \
	  assemble_diagnostics (DIAG_DEBUG_ENTER_HANDLE_PRAGMA_PACK, __FILE__, __LINE__, \
		(_arg1))
#endif /* DEBUG */

#define ICE_UNSUPPORTED_WIDE_INT \
	  assemble_diagnostics (DIAG_ICE_UNSUPPORTED_WIDE_INT)

#define ERROR_PARAM_SIZE_DEPENDENCY(_arg1) \
	if (ACTIVE_DIAG(DIAG_ERROR_PARAM_SIZE_DEPENDENCY)) \
	  assemble_diag_with_decl (DIAG_ERROR_PARAM_SIZE_DEPENDENCY, \
		(_arg1))

typedef struct {
  const diagnostic_t    diag_type;
  diagnostic_t          diag_state;
  diag_id_t             diag_id;
  int*                  p_state_stack;
  int                   stack_depth;
  const char* const     diag_name;
  const char* const     msg_id;
  const char*           localized_msg;
  const char* const     doc;
} diag_state_t;

extern diag_state_t diag_states[ 24 ];

#ifdef DEFINE_DIAGNOSTICS
diag_state_t diag_states[ 24 ] = {
  /*
   *  Warning 101 defined in c-pragma.c on line 106
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_UNPUSHED_POP,
    NULL, 0, "unpushed-pop",
    "#pragma pack (pop) encountered without matching #pragma pack (push, <n>)", NULL,
    "These must match up.  You may find unifdef(1BSD) useful." },

  /*
   *  Warning 102 defined in c-pragma.c on line 128
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_UNPUSHED_POP_ID,
    NULL, 0, "unpushed-pop-id",
    "#pragma pack(pop, %s) encountered without matching #pragma pack(push, %s, <n>)", NULL,
    "These must match up.  You may find unifdef(1BSD) useful." },

  /*
   *  Warning 103 defined in c-pragma.c on line 152
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_NO_PRAGMA_PUSH_POP,
    NULL, 0, "no-pragma-push-pop",
    "#pragma pack(%s[, id], <n>) is not supported on this target", NULL,
    "If you have a choice about the data structure, then reorder\n\
the items so they are always aligned consistently.  Otherwise,\n\
you need to study the default layout and make sure that if you\n\
move the data to another machine that it is consistent." },

  /*
   *  Warning 104 defined in c-pragma.c on line 188
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_PRAGMA_PACK_SYNTAX,
    NULL, 0, "pragma-pack-syntax",
    "missing '(' after '#pragma pack' - ignored", NULL,
    "The syntax is:  \"#pragma pack (???)\" where \"???\" is:\n\
\"N\", \"push, N\", \"push, ID, N\", \"pop\", or \"pop, ID\"." },

  /*
   *  Warning 105 defined in c-pragma.c on line 207
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_MALFORMED_PRAGMA,
    NULL, 0, "malformed-pragma",
    "malformed '#pragma %s' - ignored", NULL,
    "The syntax is:  \"#pragma pack (???)\" where \"???\" is:\n\
\"N\", \"push, N\", \"push, ID, N\", \"pop\", or \"pop, ID\"." },

  /*
   *  Warning 106 defined in c-pragma.c on line 227
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_BAD_PACK_ACTION,
    NULL, 0, "bad-pack-action",
    "unknown action '%s' for '#pragma pack' - ignored", NULL,
    "The syntax is:  \"#pragma pack (???)\" where \"???\" is:\n\
\"N\", \"push, N\", \"push, ID, N\", \"pop\", or \"pop, ID\"." },

  /*
   *  Warning 107 defined in c-pragma.c on line 271
   */
  { DK_WARNING, DK_SUPPRESSED, DIAG_WARNING_PRAGMA_JUNK,
    NULL, 0, "pragma-junk",
    "junk at end of '#pragma %s'", NULL,
    "No stray characters should appear after the pragma pack closing\n\
parenthesis." },

  /*
   *  Warning 108 defined in c-pragma.c on line 292
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_ALIGN_NOT_POWER_OF_2,
    NULL, 0, "align-not-power-of-2",
    "alignment must be a small power of two, not %d", NULL,
    "You have your choice of: 0, 1, 2, 4, 8 or 16." },

  /*
   *  Warning 109 defined in c-pragma.c on line 330
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_WEAK_TOO_LATE,
    NULL, 0, "weak-too-late",
    "applying #pragma weak `%s' after first use results in unspecified behavior", NULL,
    "We'll try to do it, but the results may not be what you expect." },
  { DK_SUPPRESSED /* no diagnostic 110 */ },
  { DK_SUPPRESSED /* no diagnostic 111 */ },
  { DK_SUPPRESSED /* no diagnostic 112 */ },
  { DK_SUPPRESSED /* no diagnostic 113 */ },
  { DK_SUPPRESSED /* no diagnostic 114 */ },
  { DK_SUPPRESSED /* no diagnostic 115 */ },
  { DK_SUPPRESSED /* no diagnostic 116 */ },
  { DK_SUPPRESSED /* no diagnostic 117 */ },
  { DK_SUPPRESSED /* no diagnostic 118 */ },
  { DK_SUPPRESSED /* no diagnostic 119 */ },

  /*
   *  Warning 120 defined in c-pragma.c on line 439
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_REDEFINE_CONFLICT,
    NULL, 0, "redefine-conflict",
    "#pragma redefine_extname conflicts with declaration", NULL,
    "You will likely have unexpected results.  Please change the\n\
name of your local declaration." },

  /*
   *  Warning 121 defined in c-pragma.c on line 513
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_RENAME_CONFLICT,
    NULL, 0, "rename-conflict",
    "asm declaration conficts with previous rename", NULL,
    "You need to disambiguate them." },

  /*
   *  Debug 122 defined in c-pragma.c on line 180
   */
  { DK_DEBUG, DK_DEBUG, DIAG_DEBUG_ENTER_HANDLE_PRAGMA_PACK,
    NULL, 0, "enter-handle-pragma-pack",
    "In file %s on line %d:  We've entered the %s procedure", NULL,
    "This is a tracing display." },

  /*
   *  Ice 123 defined in expr.c on line 6201
   */
  { DK_ICE, DK_ICE, DIAG_ICE_UNSUPPORTED_WIDE_INT,
    NULL, 0, "unsupported-wide-int",
    "unsupported wide integer operation", NULL,
    "The defined machine integer operation mode exceeds the\n\
capacity of the compiler." },

  /*
   *  Error 124 defined in expr.c on line 6599
   */
  { DK_ERROR, DK_ERROR, DIAG_ERROR_PARAM_SIZE_DEPENDENCY,
    NULL, 0, "param-size-dependency",
    "prior parameter's size depends on `%s'", NULL,
    "I'm unsure of what this means." }
};

/*
 *  Preamble strings for the kinds of diagnostics
 */
static const char *const diagnostic_kind_text[] = {
  "fatal error: ",
  "internal compiler error: ",
  "sorry, unimplemented: ",
  "error: ",
  "warning: ",
  "anacronism: ",
  "note: ",
  "debug: ",
  "must-not-happen: "
};
#endif /* DEFINE_DIAGNOSTICS */
#endif /* GCC_DIAG_MACROS_H_GUARD */

[-- Attachment #3: diag.diff --]
[-- Type: text/plain, Size: 11995 bytes --]

--- c-pragma.c.ori	Sat Jan 25 09:25:01 2003
+++ c-pragma.c	Sun Jan 26 10:48:30 2003
@@ -35,9 +35,6 @@
 #include "output.h"
 #include "tm_p.h"
 
-#define GCC_BAD(msgid) do { warning (msgid); return; } while (0)
-#define GCC_BAD2(msgid, arg) do { warning (msgid, arg); return; } while (0)
-
 typedef struct align_stack GTY(())
 {
   int                  alignment;
@@ -106,9 +103,13 @@
       
   if (alignment_stack == NULL)
     {
-      warning ("\
-#pragma pack (pop) encountered without matching #pragma pack (push, <n>)"
-	       );
+      /*=diag unpushed_pop
+       * lev: warning
+       * fmt: "#pragma pack (pop) encountered without matching "
+       *      "#pragma pack (push, <n>)"
+       * doc: These must match up.  You may find unifdef(1BSD) useful.
+      =*/
+      WARNING_UNPUSHED_POP;
       return;
     }
 
@@ -124,9 +125,14 @@
 	    break;
 	  }
       if (entry == NULL)
-	warning ("\
-#pragma pack(pop, %s) encountered without matching #pragma pack(push, %s, <n>)"
-		 , IDENTIFIER_POINTER (id), IDENTIFIER_POINTER (id));
+	/*=diag unpushed_pop_id
+	 * lev: warning
+	 * fmt: "#pragma pack(pop, %s) encountered without"
+	 *      " matching #pragma pack(push, %s, <n>)"
+	 * doc: These must match up.  You may find unifdef(1BSD) useful.
+	=*/
+	WARNING_UNPUSHED_POP_ID(IDENTIFIER_POINTER (id),
+				IDENTIFIER_POINTER (id));
     }
 
   if (-- alignment_stack->num_pushes == 0)
@@ -143,10 +149,16 @@
 }
 #else  /* not HANDLE_PRAGMA_PACK_PUSH_POP */
 #define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = (ALIGN))
-#define push_alignment(ID, N) \
-    GCC_BAD("#pragma pack(push[, id], <n>) is not supported on this target")
-#define pop_alignment(ID) \
-    GCC_BAD("#pragma pack(pop[, id], <n>) is not supported on this target")
+/*=diag no_pragma_push_pop
+ * lev: warning
+ * fmt: #pragma pack(%s[, id], <n>) is not supported on this target
+ * doc: If you have a choice about the data structure, then reorder
+ *      the items so they are always aligned consistently.  Otherwise,
+ *      you need to study the default layout and make sure that if you
+ *      move the data to another machine that it is consistent.
+=*/
+#define push_alignment(ID, N) WARNING_NO_PRAGMA_PUSH_POP("push")
+#define pop_alignment(ID) WARNING_NO_PRAGMA_PUSH_POP("pop")
 #endif /* HANDLE_PRAGMA_PACK_PUSH_POP */
 
 /* #pragma pack ()
@@ -165,8 +177,21 @@
   enum cpp_ttype token;
   enum { set, push, pop } action;
 
+  /*=diag enter_handle_pragma_pack
+   * lev: debug
+   * fmt: "We've entered the %s procedure"
+   * doc: This is a tracing display.
+  =*/
+  DEBUG_ENTER_HANDLE_PRAGMA_PACK( __FUNCTION__ );
+
   if (c_lex (&x) != CPP_OPEN_PAREN)
-    GCC_BAD ("missing '(' after '#pragma pack' - ignored");
+    /*=diag pragma_pack_syntax
+     * lev: warning
+     * fmt: missing '(' after '#pragma pack' - ignored
+     * doc: The syntax is:  "#pragma pack (???)" where "???" is:
+     *      "N", "push, N", "push, ID, N", "pop", or "pop, ID".
+    =*/
+    WARNING_PRAGMA_PACK_SYNTAX;
 
   token = c_lex (&x);
   if (token == CPP_CLOSE_PAREN)
@@ -179,15 +204,19 @@
       align = TREE_INT_CST_LOW (x);
       action = set;
       if (c_lex (&x) != CPP_CLOSE_PAREN)
-	GCC_BAD ("malformed '#pragma pack' - ignored");
+	/*=diag malformed_pragma
+	 * lev: warning
+	 * fmt: malformed '#pragma %s' - ignored
+	 * doc: The syntax is:  "#pragma pack (???)" where "???" is:
+	 *      "N", "push, N", "push, ID, N", "pop", or "pop, ID".
+	=*/
+	WARNING_MALFORMED_PRAGMA("pack");
     }
   else if (token == CPP_NAME)
     {
-#define GCC_BAD_ACTION do { if (action == push) \
-	  GCC_BAD ("malformed '#pragma pack(push[, id], <n>)' - ignored"); \
-	else \
-	  GCC_BAD ("malformed '#pragma pack(pop[, id])' - ignored"); \
-	} while (0)
+      static const char z_bad_push[] = "pack(push[, id], <n>)";
+      static const char z_bad_pop[]  = "pack(pop[, id])";
+      WARNING_MALFORMED_PRAGMA((action == push) ? z_bad_push : z_bad_pop)
 
       const char *op = IDENTIFIER_POINTER (x);
       if (!strcmp (op, "push"))
@@ -195,11 +224,17 @@
       else if (!strcmp (op, "pop"))
 	action = pop;
       else
-	GCC_BAD2 ("unknown action '%s' for '#pragma pack' - ignored", op);
+	/*=diag bad_pack_action
+	 * lev: warning
+	 * fmt: unknown action '%s' for '#pragma pack' - ignored
+	 * doc: The syntax is:  "#pragma pack (???)" where "???" is:
+	 *      "N", "push, N", "push, ID, N", "pop", or "pop, ID".
+	=*/
+	WARNING_BAD_PACK_ACTION(op);
 
       token = c_lex (&x);
       if (token != CPP_COMMA && action == push)
-	GCC_BAD_ACTION;
+	WARNING_MALFORMED_PRAGMA((action == push) ? z_bad_push : z_bad_pop);
 
       if (token == CPP_COMMA)
 	{
@@ -208,7 +243,8 @@
 	    {
 	      id = x;
 	      if (action == push && c_lex (&x) != CPP_COMMA)
-		GCC_BAD_ACTION;
+		WARNING_MALFORMED_PRAGMA((action == push) ?
+					 z_bad_push : z_bad_pop);
 	      token = c_lex (&x);
 	    }
 
@@ -220,19 +256,26 @@
 		  token = c_lex (&x);
 		}
 	      else
-		GCC_BAD_ACTION;
+		WARNING_MALFORMED_PRAGMA((action == push) ?
+					 z_bad_push : z_bad_pop);
 	    }
 	}
 
       if (token != CPP_CLOSE_PAREN)
-	GCC_BAD_ACTION;
-#undef GCC_BAD_ACTION
+	WARNING_MALFORMED_PRAGMA((action == push) ? z_bad_push : z_bad_pop);
     }
   else
-    GCC_BAD ("malformed '#pragma pack' - ignored");
+    WARNING_MALFORMED_PRAGMA("pack");
 
   if (c_lex (&x) != CPP_EOF)
-    warning ("junk at end of '#pragma pack'");
+    /*=diag pragma_junk
+     * lev: warning
+     * disable:
+     * fmt: junk at end of '#pragma %s'
+     * doc: No stray characters should appear after the pragma pack closing
+     *      parenthesis.
+    =*/
+    WARNING_PRAGMA_JUNK("pack");
 
   if (action != pop)
     switch (align)
@@ -246,7 +289,12 @@
 	align *= BITS_PER_UNIT;
 	break;
       default:
-	GCC_BAD2 ("alignment must be a small power of two, not %d", align);
+	/*=diag align_not_power_of_2
+	 * lev: warning
+	 * fmt: alignment must be a small power of two, not %d
+	 * doc: You have your choice of: 0, 1, 2, 4, 8 or 16.
+	=*/
+	WARNING_ALIGN_NOT_POWER_OF_2(align);
       }
 
   switch (action)
@@ -279,7 +327,14 @@
 
   if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
       && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
-    warning_with_decl (decl, "applying #pragma weak `%s' after first use results in unspecified behavior");
+    /*=diag weak_too_late
+     * lev: warning
+     * decl:
+     * fmt: "applying #pragma weak `%s' after first use"
+     *      " results in unspecified behavior"
+     * doc: We'll try to do it, but the results may not be what you expect.
+    =*/
+    WARNING_WEAK_TOO_LATE(decl);
 
   declare_weak (decl);
 }
@@ -320,16 +375,16 @@
   value = 0;
 
   if (c_lex (&name) != CPP_NAME)
-    GCC_BAD ("malformed #pragma weak, ignored");
+    WARNING_MALFORMED_PRAGMA("weak");
   t = c_lex (&x);
   if (t == CPP_EQ)
     {
       if (c_lex (&value) != CPP_NAME)
-	GCC_BAD ("malformed #pragma weak, ignored");
+	WARNING_MALFORMED_PRAGMA("weak");
       t = c_lex (&x);
     }
   if (t != CPP_EOF)
-    warning ("junk at end of #pragma weak");
+    WARNING_PRAGMA_JUNK("weak");
 
   decl = identifier_global_value (name);
   if (decl && TREE_CODE_CLASS (TREE_CODE (decl)) == 'd')
@@ -364,24 +419,30 @@
 
   if (c_lex (&oldname) != CPP_NAME)
     {
-      warning ("malformed #pragma redefine_extname, ignored");
+      WARNING_MALFORMED_PRAGMA("redefine_extname");
       return;
     }
   if (c_lex (&newname) != CPP_NAME)
     {
-      warning ("malformed #pragma redefine_extname, ignored");
+      WARNING_MALFORMED_PRAGMA("redefine_extname");
       return;
     }
   t = c_lex (&x);
   if (t != CPP_EOF)
-    warning ("junk at end of #pragma redefine_extname");
+    WARNING_PRAGMA_JUNK("redefine_extname");
 
   decl = identifier_global_value (oldname);
   if (decl && TREE_CODE_CLASS (TREE_CODE (decl)) == 'd')
     {
       if (DECL_ASSEMBLER_NAME_SET_P (decl)
 	  && DECL_ASSEMBLER_NAME (decl) != newname)
-        warning ("#pragma redefine_extname conflicts with declaration");
+	/*=diag redefine_conflict
+	 * lev: warning
+	 * fmt: #pragma redefine_extname conflicts with declaration
+	 * doc: You will likely have unexpected results.  Please change the
+	 *      name of your local declaration.
+	=*/
+        WARNING_REDEFINE_CONFLICT;
       SET_DECL_ASSEMBLER_NAME (decl, newname);
     }
   else
@@ -412,12 +473,12 @@
 
   if (c_lex (&prefix) != CPP_STRING)
     {
-      warning ("malformed #pragma extern_prefix, ignored");
+      WARNING_MALFORMED_PRAGMA("extern_prefix");
       return;
     }
   t = c_lex (&x);
   if (t != CPP_EOF)
-    warning ("junk at end of #pragma extern_prefix");
+    WARNING_PRAGMA_JUNK("extern_prefix");
 
   /* Note that the length includes the null terminator.  */
   pragma_extern_prefix = (TREE_STRING_LENGTH (prefix) > 1 ? prefix : NULL);
@@ -449,7 +510,12 @@
     {
       const char *oldasmname = IDENTIFIER_POINTER (oldname) + 1;
       if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldasmname) != 0)
-	warning ("asm declaration conficts with previous rename");
+	/*=diag rename_conflict
+	 * lev: warning
+	 * fmt: asm declaration conficts with previous rename
+	 * doc: You need to disambiguate them.
+	=*/
+        WARNING_RENAME_CONFLICT;
       asmname = build_string (strlen (oldasmname), oldasmname);
     }
 
@@ -462,7 +528,7 @@
 	  const char *newname = IDENTIFIER_POINTER (TREE_VALUE (t));
 
 	  if (asmname && strcmp (TREE_STRING_POINTER (asmname), newname) != 0)
-            warning ("#pragma redefine_extname conflicts with declaration");
+            WARNING_REDEFINE_CONFLICT;
 	  *p = TREE_CHAIN (t);
 
 	  return build_string (strlen (newname), newname);
--- expr.c.ori	Sun Jan 26 09:27:23 2003
+++ expr.c	Sun Jan 26 12:10:09 2003
@@ -6198,7 +6198,13 @@
       mode = TYPE_MODE (TREE_TYPE (exp));
       if (GET_MODE_CLASS (mode) == MODE_INT
 	  && mode > MAX_INTEGER_COMPUTATION_MODE)
-	internal_error ("unsupported wide integer operation");
+	/*=diag unsupported_wide_int
+	 * lev: ice
+	 * fmt: unsupported wide integer operation
+	 * doc: The defined machine integer operation mode exceeds the
+	 *      capacity of the compiler.
+	=*/
+	ICE_UNSUPPORTED_WIDE_INT;
     }
 
   /* Check operand of a unary op.  */
@@ -6207,7 +6213,7 @@
       mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
       if (GET_MODE_CLASS (mode) == MODE_INT
 	  && mode > MAX_INTEGER_COMPUTATION_MODE)
-	internal_error ("unsupported wide integer operation");
+	ICE_UNSUPPORTED_WIDE_INT;
     }
 
   /* Check operands of a binary/comparison op.  */
@@ -6216,12 +6222,12 @@
       mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
       if (GET_MODE_CLASS (mode) == MODE_INT
 	  && mode > MAX_INTEGER_COMPUTATION_MODE)
-	internal_error ("unsupported wide integer operation");
+	ICE_UNSUPPORTED_WIDE_INT;
 
       mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1)));
       if (GET_MODE_CLASS (mode) == MODE_INT
 	  && mode > MAX_INTEGER_COMPUTATION_MODE)
-	internal_error ("unsupported wide integer operation");
+	ICE_UNSUPPORTED_WIDE_INT;
     }
 }
 #endif
@@ -6523,7 +6529,7 @@
 
       if (GET_MODE_CLASS (mode) == MODE_INT
 	  && mode > MAX_INTEGER_COMPUTATION_MODE)
-	internal_error ("unsupported wide integer operation");
+	ICE_UNSUPPORTED_WIDE_INT;
     }
 
   if (tmode != mode
@@ -6539,7 +6545,7 @@
       && TREE_CODE (exp) != RTL_EXPR
       && GET_MODE_CLASS (tmode) == MODE_INT
       && tmode > MAX_INTEGER_COMPUTATION_MODE)
-    internal_error ("unsupported wide integer operation");
+    ICE_UNSUPPORTED_WIDE_INT;
 
   check_max_integer_computation_mode (exp);
 #endif
@@ -6590,7 +6596,13 @@
     case PARM_DECL:
       if (!DECL_RTL_SET_P (exp))
 	{
-	  error_with_decl (exp, "prior parameter's size depends on `%s'");
+	  /*=diag param_size_dependency
+	   * lev:  error
+	   * decl:
+	   * fmt:  prior parameter's size depends on `%s'
+	   * doc:  I'm unsure of what this means.
+	  =*/
+	  ERROR_PARAM_SIZE_DEPENDENCY(exp);
 	  return CONST0_RTX (mode);
 	}
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Slightly extended example for named warnings
  2003-01-26 23:28 Slightly extended example for named warnings Bruce Korb
@ 2003-01-27  1:20 ` Joseph S. Myers
  2003-01-27  2:05   ` Bruce Korb
  2003-01-28  5:07   ` Slightly more extended example for named diagnostics Bruce Korb
  0 siblings, 2 replies; 6+ messages in thread
From: Joseph S. Myers @ 2003-01-27  1:20 UTC (permalink / raw)
  To: Bruce Korb; +Cc: gcc

On Sun, 26 Jan 2003, Bruce Korb wrote:

> So, attached first is the generated diag-macro.h file,
> followed by the diff of a couple of sample source files.

We want to get rid of the _with_decl etc. diagnostic function variants 
(which required adding a few features present in the C++ front end - to 
specify a decl from which the location of a diagnostic is to be taken, 
etc. - to be added to the C front end) rather than carrying them over to a 
new scheme.

Of course an actual implementation would need appropriate changes to
xgettext if messages stop being visible as C strings in the source, and
functionality to extract message explanations into the main manual (and
explanations - if wanted in source rather than just using info anchors in
the manual and giving an info command that will go to the right point -
would need careful and separate review from the rest of the patch).  I
don't feel a need for this in the proof-of-concept examples, but I would
like to see an example of how this implementation method handles more
complicated cases - warnings which are enabled or disabled, and may or may
not be errors, depending on multiple flags.  For example, those in
<http://gcc.gnu.org/ml/gcc/2003-01/msg01158.html> which illustrates what
source could look like if the enabling/disabling is parsed from a string
at runtime.

-- 
Joseph S. Myers
jsm28@cam.ac.uk

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Slightly extended example for named warnings
  2003-01-27  1:20 ` Joseph S. Myers
@ 2003-01-27  2:05   ` Bruce Korb
  2003-01-28  5:07   ` Slightly more extended example for named diagnostics Bruce Korb
  1 sibling, 0 replies; 6+ messages in thread
From: Bruce Korb @ 2003-01-27  2:05 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc, bkorb

"Joseph S. Myers" wrote:

> We want to get rid of the _with_decl etc. diagnostic function variants

Being unaware of all the plans, I was just mimicing what I found.
Needless to say, with other mechanisms in place, one can emit
proc calls with different argument sequences.  What gets generated
is programmable.  What is in the source would never need to change.

> Of course an actual implementation would need appropriate changes to
> xgettext if messages stop being visible as C strings in the source,

Exactly.  Whatever it was xgettext was doing can be implemented
in a template and emitted directly.  xgettext could become historical.

> functionality to extract message explanations into the main manual

Trivial.  Along with names, formatting strings and (given a magic
processing flag) the source file and line number.  They can also be
sorted and/or segregated based on their groupings (not part of current
example, tho.)

> explanations - if wanted in source rather than just using info anchors in
> the manual and giving an info command that will go to the right point -
> would need careful and separate review from the rest of the patch).  I
> don't feel a need for this in the proof-of-concept examples,

No.  One has to keep a proof-of-concept within reasonable
complexity bounds.  I would need to add the grouping stuff
tho (marking a diagnostic as being "pedantic" or part of
"all" [a subset of everything], etc.).

> like to see an example of how this implementation method handles more
> complicated cases - warnings which are enabled or disabled, and may or may
> not be errors, depending on multiple flags.  For example, those in
> <http://gcc.gnu.org/ml/gcc/2003-01/msg01158.html> which illustrates what
> source could look like if the enabling/disabling is parsed from a string
> at runtime.

I would set up a bitmask that would mark every diagnostic with
its group memberships.  The mask would not be constrained to
32/64 bits, but it would be "convenient" if there were not more.
This list of groups would be extracted from attributes as described in:

  http://gcc.gnu.org/ml/gcc/2003-01/msg01154.html

e.g. from this description:
>   /*=diag mumble
>    * lev: warning
>    * fmt: "some sort of format string:  %d"
>    * group: pedantic all
>    * disabled:
>    * doc:  why you got this warning
>    *       and what you might do about it.
>   =*/
>   WARNING_MUMBLE(val);

the scheme would ensure that the "pedantic" and "all" groups had defined
bits in the bit mask and that -Wall and -Wpedantic would turn this diag-
nostic on and -Wno-pedantic would turn it off, but -Wno-pedantic -Wall
would leave it on.

Alternatively, one could define a recognized list and ignore groups
not from that list.  The mechanism is programmable.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Slightly more extended example for named diagnostics
  2003-01-27  1:20 ` Joseph S. Myers
  2003-01-27  2:05   ` Bruce Korb
@ 2003-01-28  5:07   ` Bruce Korb
  2003-01-28 12:30     ` Joseph S. Myers
  1 sibling, 1 reply; 6+ messages in thread
From: Bruce Korb @ 2003-01-28  5:07 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc, bkorb

[-- Attachment #1: Type: text/plain, Size: 4037 bytes --]

"Joseph S. Myers" wrote:

> Of course an actual implementation would need appropriate changes to
> xgettext if messages stop being visible as C strings in the source,

The comment extraction process produces this:

> #line 300 "c-pragma.c"
> diag[108] = {
>     name    = 'align_not_power_of_2';
>     lev = 'warning';
>     group = 'pragma';
>     fmt = 'alignment must be a small power of two, not %d';
>     doc = 'You have your choice of: 0, 1, 2, 4, 8 or 16.';
>     srcfile = 'c-pragma.c';
>     linenum = '300';
> };

Creating a .po file looks like this:

> [= (out-push-new "gcc.po") =]
> # GCC @PACKAGE-VERSION@ Messages in the default language (English)
> # Copyright (C) [=`date +%Y`=] Free Software Foundation, Inc.
> # blah, blah, blah
> # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
> #
> #, fuzzy
> msgid ""
> msgstr ""
> "Project-Id-Version: PACKAGE VERSION\n"
> "POT-Creation-Date: 2002-12-30 18:47+0000\n"
> "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
> "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
> "Language-Team: LANGUAGE <LL@li.org>\n"
> "MIME-Version: 1.0\n"
> "Content-Type: text/plain; charset=CHARSET\n"
> "Content-Transfer-Encoding: 8bit\n"
> [= FOR diag =]
> #: [=srcfile=]:[=linenum=]
> #, c-format
> msgid [=(c-string (get "fmt"))=]
> msgstr ""
> [= ENDFOR =][= (out-pop) =]

All done.  :-)

> functionality to extract message explanations into the main manual

How would you like it structured?  How about putting all the
details in a numericly ordered section and indexed by name
and sections for each named group that also have indexes
into it for each member of each group?  The groupings ought to go
into the full index, but I think I would omit individual
warnings.  Anything else?  It will be very easy, regardless of
how you want it formatted.

> explanations - if wanted in source rather than just using info anchors in
> the manual and giving an info command that will go to the right point -

The full entry would contain file and line number, with the caveat that
it is only accurate if the source and doc precisely match.  In any event,
one can grep for the diagnostic name and find all places where it is
triggered (which may happen in more and different places than where defined).

> would need careful and separate review from the rest of the patch).  I
> don't feel a need for this in the proof-of-concept examples, but I would
> like to see an example of how this implementation method handles more
> complicated cases - warnings which are enabled or disabled, and may or may
> not be errors, depending on multiple flags.  For example, those in
> <http://gcc.gnu.org/ml/gcc/2003-01/msg01158.html> which illustrates what

I looked at that.  It is trivial to add another control string argument
to the diagostic calls, but with a little trickery, I generated a bit
mask to indicate diagnostic group membership, too.  Those bits can be
used at option processing time to change the value of the "diagnostic
state" for each diagnostic:

> typedef struct {
>   const diagnostic_t    diag_type;      /* base diagnostic type    */
>   diagnostic_t          diag_state;     /* current emission type   */
>   diag_id_t             diag_id;        /* diagnostic id number    */
>   int*                  p_state_stack;  /* stacked emission types  */
>   int                   stack_depth;
>   const char* const     diag_name;      /* hyphenated diag name    */
>   const char* const     msg_id;         /* original message format */
>   const char*           localized_msg;  /* localized version       */
>   const char* const     doc;            /* detail about diagnostic */
>   member_mask_t         member_mask;    /* group membership mask   */
> } diag_state_t;

"diag_state" being the field used to determine how to handle a
diagnosed condition.  "diag_type" being how to reset the
handling type and "p_state_stack" being how to handle push/pop.

Attached is the example with a bit mask.  If we have more than
32 groupings, the code is ready to change "member_mask_t" into
an array.

Cheers - Bruce

[-- Attachment #2: diag-macros.h --]
[-- Type: text/plain, Size: 12324 bytes --]

/*   -*- buffer-read-only: t -*- vi: set ro:
 *  
 *  DO NOT EDIT THIS FILE   (diag-macros.h)
 *  
 *  It has been AutoGen-ed  
 *  From the definitions    diag-macros.def
 *  and the template file   diagnostic.tpl
 *
 *  Copyright (C) 2003 Free Software Foundation, Inc.
 *
 *  GCC is free software.
 *  
 *  You may redistribute it and/or modify it under the terms of the
 *  GNU General Public License, as published by the Free Software
 *  Foundation; either version 2, or (at your option) any later version.
 *  
 *  GCC is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with GCC.  See the file "COPYING".  If not,
 *  write to:  The Free Software Foundation, Inc.,
 *             59 Temple Place - Suite 330,
 *             Boston,  MA  02111-1307, USA.
 */
#ifndef GCC_DIAG_MACROS_H_GUARD
#define GCC_DIAG_MACROS_H_GUARD
/*
 *  Enumerate the diagnostic levels
 */
typedef enum {
  DK_FATAL,
  DK_ICE,
  DK_SORRY,
  DK_ERROR,
  DK_WARNING,
  DK_ANACRONISM,
  DK_NOTE,
  DK_DEBUG,
  DK_SUPPRESSED
} diagnostic_t;
#define  DK_LAST_DIAGNOSTIC_KIND 8

/*
 *  Enumerate every diagnostic message in GCC.
 *  The value is the diagnostic number.
 */
typedef enum {
  DIAG_WARNING_UNPUSHED_POP                     = 101,
  DIAG_WARNING_UNPUSHED_POP_ID                  = 102,
  DIAG_WARNING_NO_PRAGMA_PUSH_POP               = 103,
  DIAG_WARNING_PRAGMA_PACK_SYNTAX               = 104,
  DIAG_WARNING_MALFORMED_PRAGMA                 = 105,
  DIAG_WARNING_BAD_PACK_ACTION                  = 106,
  DIAG_WARNING_PRAGMA_JUNK                      = 107,
  DIAG_WARNING_ALIGN_NOT_POWER_OF_2             = 108,
  DIAG_WARNING_WEAK_TOO_LATE                    = 109,
  DIAG_WARNING_REDEFINE_CONFLICT                = 120,
  DIAG_WARNING_RENAME_CONFLICT                  = 121,
  DIAG_DEBUG_ENTER_HANDLE_PRAGMA_PACK           = 122,
  DIAG_ICE_UNSUPPORTED_WIDE_INT                 = 123,
  DIAG_ERROR_PARAM_SIZE_DEPENDENCY              = 124
} diag_id_t;

#define MIN_DIAGNOSTIC_NUM     101
#define MAX_DIAGNOSTIC_NUM     124

/*
 *  Message Emission Macros
 */
#ifdef DEBUG
#  define ACTIVE_DIAG(n) \
 (diag_states[n].diag_state < DK_SUPPRESSED)
#else
#  define ACTIVE_DIAG(n) \
 (diag_states[n].diag_state < DK_DEBUG)
#endif

#define WARNING_UNPUSHED_POP \
	if (ACTIVE_DIAG(DIAG_WARNING_UNPUSHED_POP)) \
	  assemble_diagnostics (DIAG_WARNING_UNPUSHED_POP)

#define WARNING_UNPUSHED_POP_ID(_arg1, _arg2) \
	if (ACTIVE_DIAG(DIAG_WARNING_UNPUSHED_POP_ID)) \
	  assemble_diagnostics (DIAG_WARNING_UNPUSHED_POP_ID, \
		(_arg1), (_arg2))

#define WARNING_NO_PRAGMA_PUSH_POP(_arg1) \
	if (ACTIVE_DIAG(DIAG_WARNING_NO_PRAGMA_PUSH_POP)) \
	  assemble_diagnostics (DIAG_WARNING_NO_PRAGMA_PUSH_POP, \
		(_arg1))

#define WARNING_PRAGMA_PACK_SYNTAX \
	if (ACTIVE_DIAG(DIAG_WARNING_PRAGMA_PACK_SYNTAX)) \
	  assemble_diagnostics (DIAG_WARNING_PRAGMA_PACK_SYNTAX)

#define WARNING_MALFORMED_PRAGMA(_arg1) \
	if (ACTIVE_DIAG(DIAG_WARNING_MALFORMED_PRAGMA)) \
	  assemble_diagnostics (DIAG_WARNING_MALFORMED_PRAGMA, \
		(_arg1))

#define WARNING_BAD_PACK_ACTION(_arg1) \
	if (ACTIVE_DIAG(DIAG_WARNING_BAD_PACK_ACTION)) \
	  assemble_diagnostics (DIAG_WARNING_BAD_PACK_ACTION, \
		(_arg1))

#define WARNING_PRAGMA_JUNK(_arg1) \
	if (ACTIVE_DIAG(DIAG_WARNING_PRAGMA_JUNK)) \
	  assemble_diagnostics (DIAG_WARNING_PRAGMA_JUNK, \
		(_arg1))

#define WARNING_ALIGN_NOT_POWER_OF_2(_arg1) \
	if (ACTIVE_DIAG(DIAG_WARNING_ALIGN_NOT_POWER_OF_2)) \
	  assemble_diagnostics (DIAG_WARNING_ALIGN_NOT_POWER_OF_2, \
		(_arg1))

#define WARNING_WEAK_TOO_LATE(_arg1) \
	if (ACTIVE_DIAG(DIAG_WARNING_WEAK_TOO_LATE)) \
	  assemble_diag_with_decl (DIAG_WARNING_WEAK_TOO_LATE, \
		(_arg1))

#define WARNING_REDEFINE_CONFLICT \
	if (ACTIVE_DIAG(DIAG_WARNING_REDEFINE_CONFLICT)) \
	  assemble_diagnostics (DIAG_WARNING_REDEFINE_CONFLICT)

#define WARNING_RENAME_CONFLICT \
	if (ACTIVE_DIAG(DIAG_WARNING_RENAME_CONFLICT)) \
	  assemble_diagnostics (DIAG_WARNING_RENAME_CONFLICT)

#ifndef DEBUG
#  define DEBUG_ENTER_HANDLE_PRAGMA_PACK(_arg1)
#else
#  define DEBUG_ENTER_HANDLE_PRAGMA_PACK(_arg1) \
	if (ACTIVE_DIAG(DIAG_DEBUG_ENTER_HANDLE_PRAGMA_PACK)) \
	  assemble_diagnostics (DIAG_DEBUG_ENTER_HANDLE_PRAGMA_PACK, __FILE__, __LINE__, \
		(_arg1))
#endif /* DEBUG */

#define ICE_UNSUPPORTED_WIDE_INT \
	  assemble_diagnostics (DIAG_ICE_UNSUPPORTED_WIDE_INT)

#define ERROR_PARAM_SIZE_DEPENDENCY(_arg1) \
	if (ACTIVE_DIAG(DIAG_ERROR_PARAM_SIZE_DEPENDENCY)) \
	  assemble_diag_with_decl (DIAG_ERROR_PARAM_SIZE_DEPENDENCY, \
		(_arg1))

/*
 *  Diagnostic Group Identifiers
 */
#define DGR_HIDDEN_NAME_ID 0
#define DGR_PRAGMA_ID 1
#define DGR_TRACING_ID 2

typedef uint32_t member_mask_t;

typedef struct {
  const diagnostic_t    diag_type;      /* base diagnostic type    */
  diagnostic_t          diag_state;     /* current emission type   */
  diag_id_t             diag_id;        /* diagnostic id number    */
  int*                  p_state_stack;  /* stacked emission types  */
  int                   stack_depth;
  const char* const     diag_name;      /* hyphenated diag name    */
  const char* const     msg_id;         /* original message format */
  const char*           localized_msg;  /* localized version       */
  const char* const     doc;            /* detail about diagnostic */
  member_mask_t         member_mask;    /* group membership mask   */
} diag_state_t;

extern diag_state_t diag_states[ 24 ];

#ifdef DEFINE_DIAGNOSTICS
diag_state_t diag_states[ 24 ] = {
  /*
   *  Warning 101 defined in c-pragma.c on line 106
   *  It is a member of the following groups:
   *    pragma
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_UNPUSHED_POP,
    NULL, 0, "unpushed-pop",
    "#pragma pack (pop) encountered without matching #pragma pack (push, <n>)", NULL,
    "These must match up.  You may find unifdef(1BSD) useful.", 0x00000002 },

  /*
   *  Warning 102 defined in c-pragma.c on line 129
   *  It is a member of the following groups:
   *    pragma
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_UNPUSHED_POP_ID,
    NULL, 0, "unpushed-pop-id",
    "#pragma pack(pop, %s) encountered without matching #pragma pack(push, %s, <n>)", NULL,
    "These must match up.  You may find unifdef(1BSD) useful.", 0x00000002 },

  /*
   *  Warning 103 defined in c-pragma.c on line 154
   *  It is a member of the following groups:
   *    pragma
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_NO_PRAGMA_PUSH_POP,
    NULL, 0, "no-pragma-push-pop",
    "#pragma pack(%s[, id], <n>) is not supported on this target", NULL,
    "If you have a choice about the data structure, then reorder\n\
the items so they are always aligned consistently.  Otherwise,\n\
you need to study the default layout and make sure that if you\n\
move the data to another machine that it is consistent.", 0x00000002 },

  /*
   *  Warning 104 defined in c-pragma.c on line 192
   *  It is a member of the following groups:
   *    pragma
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_PRAGMA_PACK_SYNTAX,
    NULL, 0, "pragma-pack-syntax",
    "missing '(' after '#pragma pack' - ignored", NULL,
    "The syntax is:  \"#pragma pack (???)\" where \"???\" is:\n\
\"N\", \"push, N\", \"push, ID, N\", \"pop\", or \"pop, ID\".", 0x00000002 },

  /*
   *  Warning 105 defined in c-pragma.c on line 212
   *  It is a member of the following groups:
   *    pragma
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_MALFORMED_PRAGMA,
    NULL, 0, "malformed-pragma",
    "malformed '#pragma %s' - ignored", NULL,
    "The syntax is:  \"#pragma pack (???)\" where \"???\" is:\n\
\"N\", \"push, N\", \"push, ID, N\", \"pop\", or \"pop, ID\".", 0x00000002 },

  /*
   *  Warning 106 defined in c-pragma.c on line 233
   *  It is a member of the following groups:
   *    pragma
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_BAD_PACK_ACTION,
    NULL, 0, "bad-pack-action",
    "unknown action '%s' for '#pragma pack' - ignored", NULL,
    "The syntax is:  \"#pragma pack (???)\" where \"???\" is:\n\
\"N\", \"push, N\", \"push, ID, N\", \"pop\", or \"pop, ID\".", 0x00000002 },

  /*
   *  Warning 107 defined in c-pragma.c on line 278
   *  It is a member of the following groups:
   *    pragma
   */
  { DK_WARNING, DK_SUPPRESSED, DIAG_WARNING_PRAGMA_JUNK,
    NULL, 0, "pragma-junk",
    "junk at end of '#pragma %s'", NULL,
    "No stray characters should appear after the pragma pack closing\n\
parenthesis.", 0x00000002 },

  /*
   *  Warning 108 defined in c-pragma.c on line 300
   *  It is a member of the following groups:
   *    pragma
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_ALIGN_NOT_POWER_OF_2,
    NULL, 0, "align-not-power-of-2",
    "alignment must be a small power of two, not %d", NULL,
    "You have your choice of: 0, 1, 2, 4, 8 or 16.", 0x00000002 },

  /*
   *  Warning 109 defined in c-pragma.c on line 339
   *  It is a member of the following groups:
   *    pragma
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_WEAK_TOO_LATE,
    NULL, 0, "weak-too-late",
    "applying #pragma weak `%s' after first use results in unspecified behavior", NULL,
    "We'll try to do it, but the results may not be what you expect.", 0x00000002 },
  { DK_SUPPRESSED, DK_SUPPRESSED /* no diagnostic 110 */ },
  { DK_SUPPRESSED, DK_SUPPRESSED /* no diagnostic 111 */ },
  { DK_SUPPRESSED, DK_SUPPRESSED /* no diagnostic 112 */ },
  { DK_SUPPRESSED, DK_SUPPRESSED /* no diagnostic 113 */ },
  { DK_SUPPRESSED, DK_SUPPRESSED /* no diagnostic 114 */ },
  { DK_SUPPRESSED, DK_SUPPRESSED /* no diagnostic 115 */ },
  { DK_SUPPRESSED, DK_SUPPRESSED /* no diagnostic 116 */ },
  { DK_SUPPRESSED, DK_SUPPRESSED /* no diagnostic 117 */ },
  { DK_SUPPRESSED, DK_SUPPRESSED /* no diagnostic 118 */ },
  { DK_SUPPRESSED, DK_SUPPRESSED /* no diagnostic 119 */ },

  /*
   *  Warning 120 defined in c-pragma.c on line 449
   *  It is a member of the following groups:
   *    pragma hidden_name
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_REDEFINE_CONFLICT,
    NULL, 0, "redefine-conflict",
    "#pragma redefine_extname conflicts with declaration", NULL,
    "You will likely have unexpected results.  Please change the\n\
name of your local declaration.", 0x00000003 },

  /*
   *  Warning 121 defined in c-pragma.c on line 524
   *  It is a member of the following groups:
   *    pragma hidden-name
   */
  { DK_WARNING, DK_WARNING, DIAG_WARNING_RENAME_CONFLICT,
    NULL, 0, "rename-conflict",
    "asm declaration conficts with previous rename", NULL,
    "You need to disambiguate them.", 0x00000002 },

  /*
   *  Debug 122 defined in c-pragma.c on line 183
   *  It is a member of the following groups:
   *    tracing
   */
  { 
#ifndef DEBUG
    DK_SUPPRESSED, DK_SUPPRESSED /* Debugging diagnostic */
#else
    DK_DEBUG, DK_DEBUG, DIAG_DEBUG_ENTER_HANDLE_PRAGMA_PACK,
    NULL, 0, "enter-handle-pragma-pack",
    "In file %s on line %d:  We've entered the %s procedure", NULL,
    "This is a tracing display.", 0x00000004
#endif /* DEBUG */
    },

  /*
   *  Ice 123 defined in expr.c on line 6201
   *  This diagnostic is not a member of any group.
   */
  { DK_ICE, DK_ICE, DIAG_ICE_UNSUPPORTED_WIDE_INT,
    NULL, 0, "unsupported-wide-int",
    "unsupported wide integer operation", NULL,
    "The defined machine integer operation mode exceeds the\n\
capacity of the compiler.", 0 },

  /*
   *  Error 124 defined in expr.c on line 6599
   *  This diagnostic is not a member of any group.
   */
  { DK_ERROR, DK_ERROR, DIAG_ERROR_PARAM_SIZE_DEPENDENCY,
    NULL, 0, "param-size-dependency",
    "prior parameter's size depends on `%s'", NULL,
    "I'm unsure of what this means.", 0 }
};

/*
 *  Name -> group number mapping (by index of entry):
 */
static const char *const diagnostic_group_name[] = {
  "hidden_name",
  "pragma",
  "tracing" };

/*
 *  Preamble strings for the kinds of diagnostics
 */
static const char *const diagnostic_kind_text[] = {
  "fatal error: ",
  "internal compiler error: ",
  "sorry, unimplemented: ",
  "error: ",
  "warning: ",
  "anacronism: ",
  "note: ",
  "debug: ",
  "must-not-happen: "
};
#endif /* DEFINE_DIAGNOSTICS */
#endif /* GCC_DIAG_MACROS_H_GUARD */

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Slightly more extended example for named diagnostics
  2003-01-28  5:07   ` Slightly more extended example for named diagnostics Bruce Korb
@ 2003-01-28 12:30     ` Joseph S. Myers
  2003-01-28 14:17       ` Bruce Korb
  0 siblings, 1 reply; 6+ messages in thread
From: Joseph S. Myers @ 2003-01-28 12:30 UTC (permalink / raw)
  To: Bruce Korb; +Cc: gcc, bkorb

On Mon, 27 Jan 2003, Bruce Korb wrote:

> All done.  :-)

Over-simplified, you haven't handled all the messages that aren't covered
by the diagnostic machinery (from miscellaneous programs outside cc1
etc.), or the various message fragments marked with N_ and _ for gettext
to extract them (which may in future need to be duplicated, preceded by
various codes, in order to handle the various ways in which they are
declined in sentences in various languages).  I don't recommend generating
a .pot file directly rather than using gettext - better to run gettext on
the generated source file and work out how to get original source
locations into the .pot file rather than references to the generated file.

> How would you like it structured?  How about putting all the
> details in a numericly ordered section and indexed by name
> and sections for each named group that also have indexes
> into it for each member of each group?  The groupings ought to go
> into the full index, but I think I would omit individual
> warnings.  Anything else?  It will be very easy, regardless of
> how you want it formatted.

Ordered in some vaguely logical conceptual way.  The arrangement of
sections in the standard isn't bad, but complicated by messages shared by
C and C++.  Where front ends have their own manuals, messages get
documented in those manuals.  And a properly aesthetic printed manual
requires that the documentation is in Texinfo format.  You avoid needing
to duplicate makeinfo within gcc if you just say "see info gcc whatever
for details" and put the documentation in the manual rather than the
source, then the source just needs to reference the manual and you can
arrange for the node (or the anchor within the node) to be named after the
message identifier.

-- 
Joseph S. Myers
jsm28@cam.ac.uk

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Slightly more extended example for named diagnostics
  2003-01-28 12:30     ` Joseph S. Myers
@ 2003-01-28 14:17       ` Bruce Korb
  0 siblings, 0 replies; 6+ messages in thread
From: Bruce Korb @ 2003-01-28 14:17 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc, bkorb

"Joseph S. Myers" wrote:
> > All done.  :-)
> 
> Over-simplified,

Of course it is.  It is an abbreviated example of a proof-of-concept.
From approximately here, someone getting paid to work on GCC
needs to take over.  I already have a day job.  I figure at least
100 hours (as much as 200, depending on who) to do a properly polished job.
My wife wouldn't like me giving away that much time.

> you haven't handled all the messages that aren't covered
> by the diagnostic machinery

True.  You'd either have to append to the real xgettext output
or, as you suggest, emit some c code that doesn't get compiled,
but gets processed by xgettext.  Does xgettext honor #line directives?
My info doc for it only gives invocation information.

> > How would you like it structured?

> Ordered in some vaguely logical conceptual way.  The arrangement of
> sections in the standard isn't bad,

To order them automatically it would have to be based on
information in the comment.  That means someone would have
to go in and insert the C standard section name/number.
It can be done, but is likely less fun than an original
conversion.

> but complicated by messages shared by
> C and C++.  Where front ends have their own manuals, messages get
> documented in those manuals.  And a properly aesthetic printed manual
> requires that the documentation is in Texinfo format.

Large chunks of my manual are generated:

  http://Autogen.SourceForge.Net/doc/autogen.html

(Large chunks are written directly, too.)
It's much harder to emit that header file than it is texinfo.

> ... and put the documentation in the manual rather than the
> source, then the source just needs to reference the manual and you can
> arrange for the node (or the anchor within the node) to be named after the
> message identifier.

The "doc" piece was to accommodate "extended" messages.  For example,
printing them at the end for the triggered diagnostics.  If it were
necessary or useful to expand beyond that in the texinfo doc, one can
trivially add to it with an auxiliary file that, maybe, had stuff like:

> ==>stumble-mumble
> @enumerate
> @item
> This is more elaboration for the stumble-mumble
> diagnostic.

get added to the generated doc at the right place.  Or, just not include
any of the source code text in the doc, either.  I think this is better
though if nothing else because you can then be completely certain that
not even one diagnostic gets left out. :-)

Cheers, Bruce

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-01-28 13:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-26 23:28 Slightly extended example for named warnings Bruce Korb
2003-01-27  1:20 ` Joseph S. Myers
2003-01-27  2:05   ` Bruce Korb
2003-01-28  5:07   ` Slightly more extended example for named diagnostics Bruce Korb
2003-01-28 12:30     ` Joseph S. Myers
2003-01-28 14:17       ` Bruce Korb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).