From 45601f24b4209b1f00b6897a01afc3ecfcf07b40 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 3 Sep 2010 17:47:12 +0000 Subject: [PATCH] Fix line numbers in error and warning messages for preprocessor messages within %inline. Also fixes __LINE__ within %inline git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12200 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 9 +++++++ .../java/preproc_line_file_runme.java | 16 ++++++++++-- Examples/test-suite/preproc_line_file.i | 26 +++++++++++++++++++ Source/CParse/parser.y | 3 +-- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 7213a66c0..6d5cc9327 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-02: wsfulton + Fix line numbers in error and warning messages for preprocessor messages within + %inline, for example: + + %inline %{ + #define FOOBAR 1 + #define FOOBAR "hi" + %} + 2010-09-02: wsfulton Fix line numbers in error and warning messages which were accumulately one less than they should have been after parsing each %include/%import - bug diff --git a/Examples/test-suite/java/preproc_line_file_runme.java b/Examples/test-suite/java/preproc_line_file_runme.java index 7200e4a53..8119824e9 100644 --- a/Examples/test-suite/java/preproc_line_file_runme.java +++ b/Examples/test-suite/java/preproc_line_file_runme.java @@ -11,6 +11,8 @@ public class preproc_line_file_runme { } } + public static String FILENAME_WINDOWS = "..\\..\\..\\..\\Examples\\test-suite\\preproc_line_file.i"; + public static String FILENAME_UNIX = "../../../../Examples/test-suite/preproc_line_file.i"; public static void main(String argv[]) throws Throwable { int myline = preproc_line_file.MYLINE; @@ -22,10 +24,10 @@ public class preproc_line_file_runme { String myfile = preproc_line_file.MYFILE; String myfile_adjusted = preproc_line_file.MYFILE_ADJUSTED; - if (!(myfile.equals("../../../../Examples/test-suite/preproc_line_file.i") || myfile.equals("..\\..\\..\\..\\Examples\\test-suite\\preproc_line_file.i"))) + if (!(myfile.equals(FILENAME_UNIX) || myfile.equals(FILENAME_WINDOWS))) throw new RuntimeException("preproc failure"); - if (!(myfile_adjusted.equals("../../../../Examples/test-suite/preproc_line_file.i.bak") || myfile_adjusted.equals("..\\..\\..\\..\\Examples\\test-suite\\preproc_line_file.i.bak"))) + if (!(myfile_adjusted.equals(FILENAME_UNIX + ".bak") || myfile_adjusted.equals(FILENAME_WINDOWS + ".bak"))) throw new RuntimeException("preproc failure"); if (!preproc_line_file.MY_STRINGNUM_A.equals("my15")) @@ -48,5 +50,15 @@ public class preproc_line_file_runme { if (SillyMacroClass.LINE_NUM != 45) throw new RuntimeException("preproc failure"); + + if (SillyMultipleMacroStruct.LINE_NUM != 70) + throw new RuntimeException("preproc failure"); + + if (preproc_line_file.INLINE_LINE != 76) + throw new RuntimeException("preproc failure"); + + String inlineFile = preproc_line_file.INLINE_FILE; + if (!(inlineFile.equals(FILENAME_UNIX) || inlineFile.equals(FILENAME_WINDOWS))) + throw new RuntimeException("preproc failure"); } } diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i index 2ef43b017..5b75d0a20 100644 --- a/Examples/test-suite/preproc_line_file.i +++ b/Examples/test-suite/preproc_line_file.i @@ -50,3 +50,29 @@ SILLY_CLASS %} +%inline %{ +#ifdef SWIG +%define BODY + int num; + static const int LINE_NUM = __LINE__; +%enddef +%define KLASS(NAME) +struct NAME { + BODY +}; +%enddef +#else +#define KLASS(NAME) \ +struct NAME { \ + int num; \ +}; +#endif +KLASS(SillyMultipleMacroStruct) +%} + +%inline %{ + +#define INLINE_FILE __FILE__ +#define INLINE_LINE __LINE__ +%} + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index f0df6684d..09ed9bcf2 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2176,15 +2176,14 @@ inline_directive : INLINE HBLOCK { String *cpps; if (Namespaceprefix) { Swig_error(cparse_file, cparse_start_line, "%%inline directive inside a namespace is disallowed.\n"); - $$ = 0; } else { $$ = new_node("insert"); Setattr($$,"code",$2); /* Need to run through the preprocessor */ + Seek($2,0,SEEK_SET); Setline($2,cparse_start_line); Setfile($2,cparse_file); - Seek($2,0,SEEK_SET); cpps = Preprocessor_parse($2); start_inline(Char(cpps), cparse_start_line); Delete($2);