Fix line number and file name reporting for some macro preprocessor warnings.

The line number of the macro argument has been corrected and the line number
of the start of the macro instead of one past the end is used. Some examples:
  file.h:11: Error: Illegal macro argument name '..'
  file.h:19: Error: Macro 'DUPLICATE' redefined,
  file.h:15: Error: previous definition of 'DUPLICATE'.
  file.h:25: Error: Variable-length macro argument must be last parameter
  file.h:32: Error: Illegal character in macro argument name
  file.i:37: Error: Macro 'SIT' expects 2 arguments

Code used for testing:
// file.h
%define SIT(ax,b)
abc(
%enddef

%define MISSING_DOT1(a,
b,
..)
xxx
%enddef

%define MISSING_DOT2(..)
xxx
%enddef

%define DUPLICATE(a,b)
abc
%enddef

%define DUPLICATE(b)
xxx
%enddef

%define VARARGS_WRONG(a,
x,
...,
 b)
xxx
%enddef

%define BAD_ARGNAME(
a,
b{c
)
xxx
%enddef

SIT(1)


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12195 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-08-29 23:32:49 +00:00
commit 31b5f36b74

View file

@ -337,7 +337,7 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) {
Putc(c, argstr);
}
if (c != ')') {
Swig_error(Getfile(str), Getline(str), "Missing \')\' in macro parameters\n");
Swig_error(Getfile(argstr), Getline(argstr), "Missing \')\' in macro parameters\n");
goto macro_error;
}
break;
@ -372,10 +372,10 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) {
argname = NewStringEmpty();
while ((c = Getc(argstr)) != EOF) {
if (c == ',') {
varargname = Macro_vararg_name(argname, str);
varargname = Macro_vararg_name(argname, argstr);
if (varargname) {
Delete(varargname);
Swig_error(Getfile(str), Getline(str), "Variable-length macro argument must be last parameter\n");
Swig_error(Getfile(argstr), Getline(argstr), "Variable length macro argument must be last parameter\n");
} else {
Append(arglist, argname);
}
@ -385,13 +385,13 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) {
Putc(c, argname);
} else if (!(isspace(c) || (c == '\\'))) {
Delete(argname);
Swig_error(Getfile(str), Getline(str), "Illegal character in macro argument name\n");
Swig_error(Getfile(argstr), Getline(argstr), "Illegal character in macro argument name\n");
goto macro_error;
}
}
if (Len(argname)) {
/* Check for varargs */
varargname = Macro_vararg_name(argname, str);
varargname = Macro_vararg_name(argname, argstr);
if (varargname) {
Append(arglist, varargname);
Delete(varargname);
@ -513,7 +513,7 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) {
symbols = Getattr(cpp, kpp_symbols);
if ((m1 = Getattr(symbols, macroname))) {
if (!Checkattr(m1, kpp_value, macrovalue)) {
Swig_error(Getfile(str), Getline(str), "Macro '%s' redefined,\n", macroname);
Swig_error(Getfile(macroname), Getline(macroname), "Macro '%s' redefined,\n", macroname);
Swig_error(Getfile(m1), Getline(m1), "previous definition of '%s'.\n", macroname);
goto macro_error;
}