diff --git a/Source/CParse/templ.c b/Source/CParse/templ.c index c978a2044..c38f9a9bf 100644 --- a/Source/CParse/templ.c +++ b/Source/CParse/templ.c @@ -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"))); } } } diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index e913003be..2f9e7a5dc 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -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; diff --git a/Source/Modules/emit.cxx b/Source/Modules/emit.cxx index e8e3abdc8..2cebe8c27 100644 --- a/Source/Modules/emit.cxx +++ b/Source/Modules/emit.cxx @@ -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"); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index afc19143a..31afb1bd8 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -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; } diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 12e09c4ea..ff864e273 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -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 { diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 3890d039a..be35d5124 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -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; } diff --git a/Source/Swig/error.c b/Source/Swig/error.c index ebf42d9b2..eb5ca3e1a 100644 --- a/Source/Swig/error.c +++ b/Source/Swig/error.c @@ -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; } diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index ddf2d72e7..beecbc00c 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -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;