This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: Named Warnings (example code)
- From: Bruce Korb <bkorb at veritas dot com>
- To: gcc <gcc at gcc dot gnu dot org>, Stan Shebs <shebs at apple dot com>
- Cc: bkorb at veritas dot com
- Date: Sat, 25 Jan 2003 12:24:14 -0800
- Subject: Re: RFC: Named Warnings (example code)
- Organization: Home
Hi Stan,
Just to see what it would look like, I made an example of c-pragma.c.
Attached are the diffs for that file + the generated header.
I didn't generate anything else on the grounds that such tables
ought to be "obvious"
Index: c-pragma.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pragma.c,v
retrieving revision 1.57
diff -u -p -r1.57 c-pragma.c
--- c-pragma.c 18 Jan 2003 02:26:41 -0000 1.57
+++ c-pragma.c 25 Jan 2003 19:59:54 -0000
@@ -35,9 +35,6 @@ Software Foundation, 59 Temple Place - S
#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 @@ pop_alignment (id)
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 @@ pop_alignment (id)
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,12 @@ pop_alignment (id)
}
#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
+=*/
+#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 ()
@@ -166,7 +174,11 @@ handle_pragma_pack (dummy)
enum { set, push, pop } action;
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
+ =*/
+ WARNING_PRAGMA_PACK_SYNTAX;
token = c_lex (&x);
if (token == CPP_CLOSE_PAREN)
@@ -179,15 +191,17 @@ handle_pragma_pack (dummy)
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
+ =*/
+ 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 +209,15 @@ handle_pragma_pack (dummy)
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
+ =*/
+ 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 +226,8 @@ handle_pragma_pack (dummy)
{
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 +239,23 @@ handle_pragma_pack (dummy)
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
+ * fmt: junk at end of '#pragma %s'
+ =*/
+ WARNING_PRAGMA_JUNK("pack");
if (action != pop)
switch (align)
@@ -246,7 +269,11 @@ handle_pragma_pack (dummy)
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
+ =*/
+ WARNING_ALIGN_NOT_POWER_OF_2(align);
}
switch (action)
@@ -279,7 +306,13 @@ apply_pragma_weak (decl, value)
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"
+ =*/
+ WARNING_WEAK_TOO_LATE(decl);
declare_weak (decl);
}
@@ -320,16 +353,16 @@ handle_pragma_weak (dummy)
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 +397,28 @@ handle_pragma_redefine_extname (dummy)
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
+ =*/
+ WARNING_REDEFINE_CONFLICT;
SET_DECL_ASSEMBLER_NAME (decl, newname);
}
else
@@ -412,12 +449,12 @@ handle_pragma_extern_prefix (dummy)
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 +486,11 @@ maybe_apply_renaming_pragma (decl, asmna
{
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
+ =*/
+ WARNING_RENAME_CONFLICT;
asmname = build_string (strlen (oldasmname), oldasmname);
}
@@ -462,7 +503,7 @@ maybe_apply_renaming_pragma (decl, asmna
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);
/* -*- 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
typedef enum {
DIAG_WARNING_ALIGN_NOT_POWER_OF_2,
DIAG_WARNING_BAD_PACK_ACTION,
DIAG_WARNING_MALFORMED_PRAGMA,
DIAG_WARNING_NO_PRAGMA_PUSH_POP,
DIAG_WARNING_PRAGMA_JUNK,
DIAG_WARNING_PRAGMA_PACK_SYNTAX,
DIAG_WARNING_REDEFINE_CONFLICT,
DIAG_WARNING_RENAME_CONFLICT,
DIAG_WARNING_UNPUSHED_POP,
DIAG_WARNING_UNPUSHED_POP_ID,
DIAG_WARNING_WEAK_TOO_LATE
/*
* Message Emission Macros
*/
#define WARNING_ALIGN_NOT_POWER_OF_2( A0 ) \
assemble_diagnostics (_("alignment must be a small power of two, not %d"), \
(A0))
#define WARNING_BAD_PACK_ACTION( A0 ) \
assemble_diagnostics (_("unknown action '%s' for '#pragma pack' - ignored"), \
(A0))
#define WARNING_MALFORMED_PRAGMA( A0 ) \
assemble_diagnostics (_("malformed '#pragma %s' - ignored"), \
(A0))
#define WARNING_NO_PRAGMA_PUSH_POP( A0 ) \
assemble_diagnostics (_("#pragma pack(%s[, id], <n>) is not supported on this target"), \
(A0))
#define WARNING_PRAGMA_JUNK( A0 ) \
assemble_diagnostics (_("junk at end of '#pragma %s'"), \
(A0))
#define WARNING_PRAGMA_PACK_SYNTAX \
assemble_diagnostics (_("missing '(' after '#pragma pack' - ignored"))
#define WARNING_REDEFINE_CONFLICT \
assemble_diagnostics (_("#pragma redefine_extname conflicts with declaration"))
#define WARNING_RENAME_CONFLICT \
assemble_diagnostics (_("asm declaration conficts with previous rename"))
#define WARNING_UNPUSHED_POP \
assemble_diagnostics (_("#pragma pack (pop) encountered without matching #pragma pack (push, <n>)"))
#define WARNING_UNPUSHED_POP_ID( A0, A1 ) \
assemble_diagnostics (_("#pragma pack(pop, %s) encountered without matching #pragma pack(push, %s, <n>)"), \
(A0), (A1))
#define WARNING_WEAK_TOO_LATE( A0 ) \
assemble_diag_with_decl ((A0), _("applying #pragma weak `%s' after first use results in unspecified behavior"))
typedef struct {
int state;
int* p_state_stack;
int stack_depth;
} diag_state_t;
extern diag_state_t diag_states[ 11 ];
#endif /* GCC_DIAG_MACROS_H_GUARD */