Added the warning code

WARN_PARSE_REDUNDANT          322

similar to the g++ -Wredundant-decls flag.

This recovers the warnings that now are not been reported by
the original code

   WARN_PARSE_REDEFINED          302

Redundant example:

   int foo(int);
   int foo(int);

Redefined example:

   int foo(int);
   double foo(int);


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5634 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-01-15 08:16:53 +00:00
commit 74d6f1eb43
6 changed files with 63 additions and 25 deletions

View file

@ -281,7 +281,7 @@ example.i(4): Syntax error in input.
<ul>
<li>301. <tt>class</tt> keyword used, but not in C++ mode.
<li>302. Identifier '<em>name</em>' redeclared (ignored).
<li>302. Identifier '<em>name</em>' redefined (ignored).
<li>303. <tt>%extend</tt> defined for an undeclared class '<em>name</em>'.
<li>304. Unsupported constant value (ignored).
<li>305. Bad constant value (ignored).
@ -301,6 +301,7 @@ example.i(4): Syntax error in input.
<li>319. No access specifier given for base class <em>name</em> (ignored).
<li>320. Explicit template instantiation ignored.
<li>321. <em>identifier</em> conflicts with a built-in name.
<li>322. Redundant redeclaration of '<em>name</em>'.
<li>350. operator new ignored.
<li>351. operator delete ignored.
<li>352. operator+ ignored.

View file

@ -1,5 +1,8 @@
%module redefined
/* no redundant warnings */
#pragma SWIG nowarn=-322
#if 1
//
// All these repeated declarations are not redefinitions,
@ -19,31 +22,38 @@
%inline %{
#define REPEATED 1
#define REPEATED 1
#define REDUNDANT 1
#define REDUNDANT 1
#define MACROREP(x) x
#define MACROREP(x) x
class Hello;
class Hello;
typedef int Int;
typedef int Int;
int hello(int);
inline int hello(int) { return 0; };
inline int hello(int);
struct Hello
class B;
struct A
{
typedef int Int;
typedef int Int;
friend int hello(int);
friend int foo(A*, B*);
};
struct Hello2
struct B
{
typedef int Int;
typedef int Int;
friend int hello(int);
friend int foo(A*, B*);
};
inline int foo(A*, B*) { return 0; };
%}
@ -51,13 +61,15 @@
#else
//
// the %extend directive ALWAYS emits redefined warnings,
// since it is not only introducing a declaration, but a redefinition.
// the %extend and %rename directive ALWAYS emit redefined warnings,
// since they are not C/C++/CPP standard.
//
%extend Hello {
int hi(int) { return 0; };
}
%rename(chao) hi(int);
//
// All these repeated declarations are really redefinitions,
// therefore, swig must produce a redefined warning
@ -69,8 +81,8 @@
%inline %{
#define REPEATED 1
#define REPEATED 2
#define REDEFINED 1
#define REDEFINED 2
#define MACROREP(x) x
#define MACROREP(x) x*2
@ -78,6 +90,8 @@
typedef int Int;
typedef double Int;
int hi(int);
int chao(int);
int hello(int);
inline double hello(int) { return 0; };

View file

@ -376,21 +376,30 @@ static void add_symbols(Node *n) {
String *e = NewString("");
String *en = NewString("");
String *ec = NewString("");
Printf(en,"Identifier '%s' redeclared (ignored)", symname);
int redefined = need_redefined_warn(n,c,inclass);
if (redefined) {
Printf(en,"Identifier '%s' redefined (ignored)",symname);
Printf(ec,"previous definition of '%s'",symname);
} else {
Printf(en,"Redundant redeclaration of '%s'",symname);
Printf(ec,"previous declaration of '%s'",symname);
}
if (Cmp(symname,Getattr(n,"name"))) {
Printf(en," (Renamed from '%s')", SwigType_namestr(Getattr(n,"name")));
}
Printf(en,",");
Printf(ec," previous declaration of '%s'", symname);
if (Cmp(symname,Getattr(c,"name"))) {
Printf(ec," (Renamed from '%s')", SwigType_namestr(Getattr(c,"name")));
}
Printf(ec,".");
if (need_redefined_warn(n, c, inclass)) {
if (redefined) {
Swig_warning(WARN_PARSE_REDEFINED,Getfile(n),Getline(n),"%s\n",en);
Swig_warning(WARN_PARSE_REDEFINED,Getfile(c),Getline(c),"%s\n",ec);
} else if (!is_friend(n) && !is_friend(c)) {
Swig_warning(WARN_PARSE_REDUNDANT,Getfile(n),Getline(n),"%s\n",en);
Swig_warning(WARN_PARSE_REDUNDANT,Getfile(c),Getline(c),"%s\n",ec);
}
Printf(e,"%s\n%s:%d:%s\n", en, Getfile(c), Getline(c), ec);
Printf(e,"%s\n%s:%d:%s\n",en,Getfile(c),Getline(c),ec);
Setattr(n,"error",e);
Delete(en);
Delete(ec);
@ -535,8 +544,8 @@ static void merge_extensions(Node *cls, Node *am) {
String *e = NewString("");
String *en = NewString("");
String *ec = NewString("");
Printf(ec,"Identifier '%s' redeclared (ignored),\n", symname);
Printf(en," %%extend definition of '%s'.", symname);
Printf(ec,"Identifier '%s' redefined by %extend (ignored),\n", symname);
Printf(en,"%%extend definition of '%s'.", symname);
Swig_warning(WARN_PARSE_REDEFINED,Getfile(csym), Getline(csym), "%s\n", ec);
Swig_warning(WARN_PARSE_REDEFINED,Getfile(n), Getline(n), "%s\n", en);
Printf(e,"%s\n%s:%d:%s\n", ec, Getfile(n), Getline(n), en);
@ -1312,7 +1321,7 @@ includetype : INCLUDE { $$.type = (char *) "include"; }
inline_directive : INLINE HBLOCK {
String *cpps;
if (Namespaceprefix) {
Swig_error(cparse_file, cparse_start_line, "Error. %%inline directive inside a namespace is disallowed.\n");
Swig_error(cparse_file, cparse_start_line, "%%inline directive inside a namespace is disallowed.\n");
$$ = 0;
} else {
@ -1333,7 +1342,7 @@ inline_directive : INLINE HBLOCK {
String *cpps;
skip_balanced('{','}');
if (Namespaceprefix) {
Swig_error(cparse_file, cparse_start_line, "Error. %%inline directive inside a namespace is disallowed.\n");
Swig_error(cparse_file, cparse_start_line, "%%inline directive inside a namespace is disallowed.\n");
$$ = 0;
} else {

View file

@ -170,6 +170,7 @@ int are_equivalent_nodes(Node* a, Node* b, int a_inclass)
if (!a_inclass || (Cmp(a_storage,"friend") == 0)) {
/* check declaration */
String *a_decl = (Getattr(a,"decl"));
String *b_decl = (Getattr(b,"decl"));
if (Cmp(a_decl, b_decl) == 0) {
@ -216,8 +217,12 @@ int are_equivalent_nodes(Node* a, Node* b, int a_inclass)
int need_redefined_warn(Node* a, Node* b, int InClass)
{
String *a_storage = Getattr(a,"storage");
String *b_storage = Getattr(b,"storage");
String *a_symname = Getattr(a,"sym:name");
String *b_symname = Getattr(b,"sym:name");
/* always send a warning if a 'rename' is involved */
if ((a_symname && Cmp(a_symname,Getattr(a,"name")))
|| (b_symname && Cmp(b_symname,Getattr(b,"name"))))
return 1;
return !are_equivalent_nodes(a, b, InClass);
}

View file

@ -70,6 +70,8 @@
#define WARN_PARSE_TEMPLATE_AMBIG 318
#define WARN_PARSE_NO_ACCESS 319
#define WARN_PARSE_EXPLICIT_TEMPLATE 320
#define WARN_PARSE_BUILTIN_NAME 321
#define WARN_PARSE_REDUNDANT 322
#define WARN_IGNORE_OPERATOR_NEW 350 /* new */
#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */

View file

@ -232,10 +232,17 @@ int SWIG_main(int argc, char *argv[], Language *l) {
/* Initialize the SWIG core */
Swig_init();
/* Suppress warning messages for private inheritance, preprocessor evaluation,
might be abstract, and overloaded const */
/* Suppress warning messages for private inheritance, preprocessor
evaluation, might be abstract, overloaded const, and ...
Swig_warnfilter("202,309,403,512,321",1);
WARN_PP_EVALUATION 202
WARN_PARSE_PRIVATE_INHERIT 309
WARN_TYPE_ABSTRACT 403
WARN_LANG_OVERLOAD_CONST 512
WARN_PARSE_BUILTIN_NAME 321
WARN_PARSE_REDUNDANT 322
*/
Swig_warnfilter("202,309,403,512,321,322",1);
// Initialize the preprocessor
Preprocessor_init();