diff --git a/Examples/test-suite/java/preproc_line_file_runme.java b/Examples/test-suite/java/preproc_line_file_runme.java index 6550e4a78..e390b0c19 100644 --- a/Examples/test-suite/java/preproc_line_file_runme.java +++ b/Examples/test-suite/java/preproc_line_file_runme.java @@ -34,8 +34,16 @@ public class preproc_line_file_runme { if (!preproc_line_file.MY_STRINGNUM_B.equals("my16")) throw new RuntimeException("preproc failed MY_STRINGNUM_B"); - int myline2 = preproc_line_file.MYLINE2; - if (myline2 != 23) + if (preproc_line_file.getThing27() != -1) + throw new RuntimeException("preproc failure"); + + if (preproc_line_file.getThing28() != -2) + throw new RuntimeException("preproc failure"); + + if (preproc_line_file.MYLINE2 != 30) + throw new RuntimeException("preproc failure"); + + if (SillyStruct.LINE_NUMBER != 41) throw new RuntimeException("preproc failure"); } } diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i index 9da137e94..1a75be83a 100644 --- a/Examples/test-suite/preproc_line_file.i +++ b/Examples/test-suite/preproc_line_file.i @@ -1,6 +1,6 @@ %module preproc_line_file -// Test __LINE__ and __FILE__ (don't change line numbers in here else runtime tests will need modifying) +// Test __LINE__ and __FILE__ (don't change line numbering in here else runtime tests will need modifying) #define MYLINE __LINE__ #define MYLINE_ADJUSTED __LINE__ + 100 @@ -20,14 +20,23 @@ #define NUMBER(a,b) NUMBER_HELP(a,b) #define NUMBER_UNIQUE(a) NUMBER(a,__LINE__) +%{ +const int thing27 = -1; +const int thing28 = -2; +%} +const int NUMBER_UNIQUE(thing) = -1; /* resolves to thing27 */ +const int NUMBER_UNIQUE(thing) = -2; /* resolves to thing28 */ + #define MYLINE2 __LINE__ -/* -TODO: __LINE__ is wrong -struct Struct { - static const int line_num = __LINE__; +%javaconst(1); +%{ +struct SillyStruct { + int num; + /* static const int line_num = __LINE__; */ +}; +%} +struct SillyStruct { + int num; + static const int LINE_NUMBER = __LINE__; /* This is a C test case, but we can still use a C++ feature to wrap a constant to test __LINE__ here */ }; -const int NUMBER_UNIQUE(thing) = 0; -const int NUMBER_UNIQUE(thingamebob) = 0; -#define MYLINE3 __LINE__ -*/ diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 63e6ab547..32f3a3bd4 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -353,8 +353,6 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) { break; } } else { - /*Swig_error(Getfile(str),Getline(str),"Illegal character in macro name\n"); - goto macro_error; */ Ungetc(c, str); break; } @@ -1287,8 +1285,8 @@ String *Preprocessor_parse(String *s) { case 0: /* Initial state - in first column */ /* Look for C preprocessor directives. Otherwise, go directly to state 1 */ if (c == '#') { - add_chunk(ns, chunk, allow); copy_location(s, chunk); + add_chunk(ns, chunk, allow); cpp_lines = 1; state = 40; } else if (isspace(c)) { @@ -1682,8 +1680,8 @@ String *Preprocessor_parse(String *s) { /* %{,%} block */ if (c == '{') { start_line = Getline(s); - add_chunk(ns, chunk, allow); copy_location(s, chunk); + add_chunk(ns, chunk, allow); Putc('%', chunk); Putc(c, chunk); state = 105; @@ -1759,8 +1757,8 @@ String *Preprocessor_parse(String *s) { s1 = cpp_include(fn, sysfile); if (s1) { char *dirname; - add_chunk(ns, chunk, allow); copy_location(s, chunk); + add_chunk(ns, chunk, allow); Printf(ns, "%sfile%s \"%s\" [\n", decl, opt, Swig_filename_escape(Swig_last_file())); if (Equal(decl, kpp_dimport)) { push_imported(); @@ -1793,8 +1791,8 @@ String *Preprocessor_parse(String *s) { } else if (Equal(decl, kpp_ddefine)) { /* Got a define directive */ dlevel++; - add_chunk(ns, chunk, allow); copy_location(s, chunk); + add_chunk(ns, chunk, allow); Clear(value); copy_location(s, value); state = 150; @@ -1868,8 +1866,8 @@ String *Preprocessor_parse(String *s) { if ((state >= 30) && (state < 40)) { Swig_error(Getfile(s), -1, "Unterminated comment starting on line %d\n", start_line); } - add_chunk(ns, chunk, allow); copy_location(s, chunk); + add_chunk(ns, chunk, allow); /* DelScope(scp); */ Delete(decl);