- Normalize the 'Swig_error' calls and formats, before some

of the strings start like "Error. XXX", others like "XXX".
  The format is now defined in 'error.c:Swig_error_msg_format()'.

- Normalize the multiline error/warning messages to correctly
  use -Fformat definition.

- Centralize the error/warning format definitions in
  'error.c:Swig_error_msg_format()'.

- Fix a minor error in cpp.c, that after finding an error, still
  was emitting a redefined macro, producing duplicated error/warning
  messages in parser.y.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5635 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-01-15 08:33:12 +00:00
commit bd9aa0c7c9
8 changed files with 65 additions and 41 deletions

View file

@ -517,8 +517,12 @@ Swig_cparse_template_locate(String *name, Parm *tparms) {
n = Swig_symbol_clookup_local(s,0);
if (Len(mpartials) > 1) {
if (n) {
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG,cparse_file,cparse_line,"Instantiation of template %s is ambiguous. Using %s at %s:%d\n",
SwigType_namestr(tname), SwigType_namestr(Getattr(n,"name")), Getfile(n),Getline(n));
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG,cparse_file,cparse_line,
"Instantiation of template '%s' is ambiguous,\n",
SwigType_namestr(tname));
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG,Getfile(n),Getline(n),
" instantiation '%s' is used.\n",
SwigType_namestr(Getattr(n,"name")));
}
}
}

View file

@ -289,7 +289,7 @@ class Allocate : public Dispatcher {
if (e && is_public(e) && !Getattr(e,"feature:ignore") && (Cmp(symname, Getattr(e,"sym:name")) == 0)) {
Swig_warning(WARN_LANG_DEREF_SHADOW,Getfile(e),Getline(e),"Declaration of '%s' shadows declaration accessible via operator->(),\n",
name);
Swig_warning(WARN_LANG_DEREF_SHADOW,Getfile(c),Getline(c)," '%s' first declared here.\n", name);
Swig_warning(WARN_LANG_DEREF_SHADOW,Getfile(c),Getline(c),"previous declaration of '%s'.\n", name);
} else {
/* Make sure node with same name doesn't already exist */
int k;

View file

@ -252,7 +252,7 @@ int emit_num_required(ParmList *parms) {
p = Getattr(p,"tmap:in:next");
} else {
if (!Getattr(p,"value") && (!Getattr(p,"tmap:default"))) {
Swig_error(Getfile(p),Getline(p),"Error. Non-optional argument '%s' follows an optional argument.\n",Getattr(p,"name"));
Swig_error(Getfile(p),Getline(p),"Non-optional argument '%s' follows an optional argument.\n",Getattr(p,"name"));
}
if (Getattr(p,"tmap:in")) {
p = Getattr(p,"tmap:in:next");

View file

@ -2097,7 +2097,7 @@ int
Language::addSymbol(String *s, Node *n) {
Node *c = Getattr(symbols,s);
if (c && (c != n)) {
Swig_error(input_file, line_number, "Error. '%s' is multiply defined in the generated module.\n", s);
Swig_error(input_file, line_number, "'%s' is multiply defined in the generated module.\n", s);
Swig_error(Getfile(c),Getline(c), "Previous declaration of '%s'\n", s);
return 0;
}

View file

@ -405,8 +405,12 @@ public:
SwigType_typedef_class(fname);
scopename = Copy(fname);
} else {
Swig_warning(WARN_TYPE_REDEFINED,Getfile(n),Getline(n),"Template '%s' was already wrapped as '%s' at %s:%d.\n",
SwigType_namestr(name), SwigType_namestr(Getattr(cn,"name")), Getfile(cn), Getline(cn));
Swig_warning(WARN_TYPE_REDEFINED,Getfile(n),Getline(n),
"Template '%s' was already wrapped,\n",
SwigType_namestr(name));
Swig_warning(WARN_TYPE_REDEFINED,Getfile(cn), Getline(cn),
"previous wrap of '%s'.\n",
SwigType_namestr(Getattr(cn,"name")));
scopename = 0;
}
} else {

View file

@ -345,7 +345,6 @@ Hash *Preprocessor_define(const String_or_char *_str, int swigmacro)
/* Go create the macro */
macro = NewHash();
Setattr(macro,"name", macroname);
Delete(macroname);
if (arglist) {
Setattr(macro,"args",arglist);
Delete(arglist);
@ -362,17 +361,23 @@ Hash *Preprocessor_define(const String_or_char *_str, int swigmacro)
}
symbols = Getattr(cpp,"symbols");
if ((m1 = Getattr(symbols,macroname))) {
if (Cmp(Getattr(m1,"value"),macrovalue))
Swig_error(Getfile(str),Getline(str),"Macro '%s' redefined. Previous definition in \'%s\', Line %d\n", macroname, Getfile(m1), Getline(m1));
if (Cmp(Getattr(m1,"value"),macrovalue)) {
Swig_error(Getfile(str),Getline(str),"Macro '%s' redefined,\n",macroname);
Swig_error(Getfile(m1),Getline(m1),"previous definition of '%s'.\n",macroname);
goto macro_error;
}
}
Setattr(symbols,macroname,macro);
Delete(str);
Delete(argstr);
Delete(macroname);
return macro;
macro_error:
Delete(str);
Delete(argstr);
Delete(macroname);
return 0;
}

View file

@ -45,6 +45,12 @@ static String *filter = 0; /* Warning filter */
static int warnall = 0;
static int nwarning = 0;
static int init_fmt = 0;
static char wrn_wnum_fmt[64];
static char wrn_nnum_fmt[64];
static char err_line_fmt[64];
static char err_eof_fmt[64];
/* -----------------------------------------------------------------------------
* Swig_warning()
*
@ -58,6 +64,7 @@ Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt
int wrn = 1;
va_list ap;
if (silence) return;
if (!init_fmt) Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT);
va_start(ap,fmt);
@ -90,25 +97,9 @@ Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt
}
if (warnall || wrn) {
if (wnum) {
switch (msg_format) {
case EMF_MICROSOFT:
Printf(stderr,"%s(%d): Warning(%d): ", filename, line, wnum);
break;
case EMF_STANDARD:
default:
Printf(stderr,"%s:%d: Warning(%d): ", filename, line, wnum);
break;
}
Printf(stderr, wrn_wnum_fmt, filename, line, wnum);
} else {
switch (msg_format) {
case EMF_MICROSOFT:
Printf(stderr,"%s(%d): Warning: ", filename, line);
break;
case EMF_STANDARD:
default:
Printf(stderr,"%s:%d: Warning: ", filename, line);
break;
}
Printf(stderr, wrn_nnum_fmt, filename, line);
}
Printf(stderr,"%s",msg);
nwarning++;
@ -130,20 +121,13 @@ Swig_error(const String_or_char *filename, int line, const char *fmt, ...) {
va_list ap;
if (silence) return;
if (!init_fmt) Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT);
va_start(ap,fmt);
if (line > 0) {
switch (msg_format) {
case EMF_MICROSOFT:
Printf(stderr,"%s(%d): ", filename, line);
break;
case EMF_STANDARD:
default:
Printf(stderr,"%s:%d: ", filename, line);
break;
}
Printf(stderr, err_line_fmt, filename, line);
} else {
Printf(stderr,"%s:EOF: ", filename);
Printf(stderr, err_eof_fmt, filename);
}
vPrintf(stderr,fmt,ap);
va_end(ap);
@ -235,5 +219,28 @@ Swig_warn_count(void) {
void
Swig_error_msg_format(ErrorMessageFormat format) {
const char* error = "Error";
const char* warning = "Warning";
const char* fmt_eof = "%s:EOF";
/* here 'format' could be directly a string instead of an enum, but
by now a switch is used to translated into one. */
const char* fmt_line = 0;
switch (format) {
case EMF_MICROSOFT:
fmt_line = "%s(%d)";
break;
case EMF_STANDARD:
default:
fmt_line = "%s:%d";
}
sprintf(wrn_wnum_fmt, "%s: %s(%%d): ", fmt_line, warning);
sprintf(wrn_nnum_fmt, "%s: %s: ", fmt_line, warning);
sprintf(err_line_fmt, "%s: %s: ", fmt_line, error);
sprintf(err_eof_fmt, "%s: %s: ", fmt_eof, error);
msg_format = format;
init_fmt = 1;
}

View file

@ -383,8 +383,12 @@ Swig_symbol_cadd(String_or_char *name, Node *n) {
Setattr(ccurrent,name,n);
append = cn;
} else if (cn && (Strcmp(nodeType(cn),"templateparm") == 0)) {
Swig_error(Getfile(n),Getline(n),"Error. Declaration of '%s' shadows template parameter at %s:%d\n",
name,Getfile(cn),Getline(cn));
Swig_error(Getfile(n),Getline(n),
"Declaration of '%s' shadows template parameter,\n",
name);
Swig_error(Getfile(cn),Getline(cn),
"previous template parameter declaration '%s'.\n",
name);
return;
} else if (cn) {
append = n;