From f82811dbcd135f37544d20d75354efe70f5d548d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 10 Sep 2010 23:44:27 +0000 Subject: [PATCH] Fix incorrect line number reporting in errors/warnings after parsing macro invocations with parameters given over more than one line. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12214 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 +++ Examples/test-suite/errors/expected.log | 6 ++++ Examples/test-suite/errors/make.sh | 1 + .../errors/pp_macro_expansion_multiline.i | 32 +++++++++++++++++++ Source/Preprocessor/cpp.c | 7 ++++ 5 files changed, 50 insertions(+) create mode 100644 Examples/test-suite/errors/pp_macro_expansion_multiline.i diff --git a/CHANGES.current b/CHANGES.current index 227f5218c..20c0a6b0a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-11: wsfulton + Fix incorrect line number reporting in errors/warnings after parsing + macro invocations with parameters given over more than one line. + 2010-09-10: wsfulton Remove extraneous extra line in preprocessed output after including files which would sometimes lead to error/warning messages two lines after the diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index fa8114aad..56e10a066 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -106,6 +106,12 @@ pp_macro_defined_unterminated.i:4: Error: Unterminated call to 'defined' :::::::::::::::::::::::::::::::: pp_macro_expansion.i ::::::::::::::::::::::::::::::::::: pp_macro_expansion.i:9: Error: Macro 'MACRO2' expects 2 arguments +:::::::::::::::::::::::::::::::: pp_macro_expansion_multiline.i ::::::::::::::::::::::::::::::::::: +pp_macro_expansion_multiline.i:13: Warning 509: Overloaded method foo(int const *) effectively ignored, +pp_macro_expansion_multiline.i:12: Warning 509: as it is shadowed by foo(int *). +pp_macro_expansion_multiline.i:31: Warning 509: Overloaded method bar(int const *) effectively ignored, +pp_macro_expansion_multiline.i:30: Warning 509: as it is shadowed by bar(int *). + :::::::::::::::::::::::::::::::: pp_macro_inline_unterminated.i ::::::::::::::::::::::::::::::::::: pp_macro_inline_unterminated.i:9: Error: Unterminated call invoking macro 'foo' pp_macro_inline_unterminated.i:12: Error: Syntax error in input(3). diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index 45c5c1733..0fb3e14a4 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -34,6 +34,7 @@ pp_macro_args pp_macro_badchar pp_macro_defined_unterminated pp_macro_expansion +pp_macro_expansion_multiline pp_macro_inline_unterminated pp_macro_nargs pp_macro_redef diff --git a/Examples/test-suite/errors/pp_macro_expansion_multiline.i b/Examples/test-suite/errors/pp_macro_expansion_multiline.i new file mode 100644 index 000000000..b0777de60 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_expansion_multiline.i @@ -0,0 +1,32 @@ +%module xxx +// Testing macros split over multiple lines - ensure the warning message for the ignored functions contain the correct line numbering + +#define MYMACRO(NAME, A, B, C) void NAME(int A, int B, int C); + +MYMACRO(funk, x, +y, + +z +) + +void foo(int *); +void foo(const int *); + +%define MYSWIGMACRO(A, B, C) +MYMACRO(funk1, + AA, + BB, + CC) +MYMACRO(funk2, + AA, + BB, + CC) +%enddef + +MYSWIGMACRO(xx, + yy, + zz) + +void bar(int *); +void bar(const int *); + diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index bb56c21d2..23896fc50 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1075,10 +1075,14 @@ static DOH *Preprocessor_replace(DOH *s) { /* See if the macro is defined in the preprocessor symbol table */ DOH *args = 0; DOH *e; + int macro_additional_lines = 0; /* See if the macro expects arguments */ if (Getattr(m, kpp_args)) { /* Yep. We need to go find the arguments and do a substitution */ + int line = Getline(s); args = find_args(s, 1, id); + macro_additional_lines = Getline(s) - line; + assert(macro_additional_lines >= 0); if (!Len(args)) { Delete(args); args = 0; @@ -1090,6 +1094,9 @@ static DOH *Preprocessor_replace(DOH *s) { if (e) { Append(ns, e); } + while (macro_additional_lines--) { + Putc('\n', ns); + } Delete(e); Delete(args); } else {