From eab650bbca8bcb2ee7910a3baf4a114f4da87f84 Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Thu, 15 Jun 2000 21:27:10 +0000 Subject: [PATCH] Fixed a bug with nested conditionals in the preprocessor. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@473 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Source/Preprocessor/cpp.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/SWIG/Source/Preprocessor/cpp.c b/SWIG/Source/Preprocessor/cpp.c index 752e785d7..5a1524951 100644 --- a/SWIG/Source/Preprocessor/cpp.c +++ b/SWIG/Source/Preprocessor/cpp.c @@ -981,14 +981,16 @@ Preprocessor_parse(DOH *s) mask = 1; } } else if (Cmp(id,"else") == 0) { - if (level == 0) { + if (level <= 0) { cpp_error(Getfile(s),Getline(id),"Misplaced #else.\n"); } else { cond_lines[level-1] = Getline(id); if (allow) { allow = 0; mask = 0; - } else if (level == start_level) allow = 1; + } else if (level == start_level) { + allow = 1; + } } } else if (Cmp(id,"endif") == 0) { level--; @@ -996,7 +998,10 @@ Preprocessor_parse(DOH *s) cpp_error(Getfile(id),Getline(id),"Extraneous #endif ignored.\n"); level = 0; } else { - if (level < start_level) allow = 1; + if (level < start_level) { + allow = 1; + start_level--; + } } } else if (Cmp(id,"if") == 0) { cond_lines[level] = Getline(id); @@ -1005,6 +1010,7 @@ Preprocessor_parse(DOH *s) start_level = level; sval = Preprocessor_replace(value); Seek(sval,0,SEEK_SET); + /* Printf(stdout,"Evaluating '%s'\n", sval); */ val = Preprocessor_expr(sval,&e); if (e) { Seek(value,0,SEEK_SET); @@ -1058,7 +1064,8 @@ Preprocessor_parse(DOH *s) Delete(fn); } } else if (Cmp(id,"pragma") == 0) { - } else { + } else if (Cmp(id,"level") == 0) { + cpp_error(Getfile(s),Getline(id),"cpp debug: level = %d, startlevel = %d\n", level, start_level); } for (i = 0; i < cpp_lines; i++) Putc('\n',ns);