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
This commit is contained in:
William S Fulton 2010-09-03 17:47:12 +00:00
commit 45601f24b4
4 changed files with 50 additions and 4 deletions

View file

@ -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

View file

@ -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");
}
}

View file

@ -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__
%}

View file

@ -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);