From bddf02154ea39ec9721952b922a1cb71d347fa64 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 27 Sep 2004 19:35:05 +0000 Subject: [PATCH] Bill Clarke patch: fix to ensure SWIGIMPORT always defined for %import and new warning when using -importall and -includeall together git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6273 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Source/Include/swigwarn.h | 1 + SWIG/Source/Preprocessor/cpp.c | 42 ++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/SWIG/Source/Include/swigwarn.h b/SWIG/Source/Include/swigwarn.h index 915ba8b32..d29fe0435 100644 --- a/SWIG/Source/Include/swigwarn.h +++ b/SWIG/Source/Include/swigwarn.h @@ -47,6 +47,7 @@ #define WARN_PP_MISSING_FILE 201 #define WARN_PP_EVALUATION 202 +#define WARN_PP_INCLUDEALL_IMPORTALL 203 /* -- C/C++ Parser -- */ diff --git a/SWIG/Source/Preprocessor/cpp.c b/SWIG/Source/Preprocessor/cpp.c index faf525102..11595ea77 100644 --- a/SWIG/Source/Preprocessor/cpp.c +++ b/SWIG/Source/Preprocessor/cpp.c @@ -25,6 +25,7 @@ static Hash *cpp = 0; /* C preprocessor data */ static int include_all = 0; /* Follow all includes */ static int ignore_missing = 0; static int import_all = 0; /* Follow all includes, but as %import statements */ +static int imported_depth = 0; /* Depth of %imported files */ static int single_include = 1; /* Only include each file once */ static Hash *included_files = 0; static List *dependencies = 0; @@ -1025,6 +1026,26 @@ static void add_chunk(DOH *ns, DOH *chunk, int allow) { Clear(chunk); } +/* + push/pop_imported(): helper functions for defining and undefining + SWIGIMPORT (when %importing a file). + */ +static void +push_imported() { + if (imported_depth == 0) { + Preprocessor_define("SWIGIMPORT 1", 0); + } + ++imported_depth; +} + +static void +pop_imported() { + --imported_depth; + if (imported_depth == 0) { + Preprocessor_undef("SWIGIMPORT"); + } +} + /* ----------------------------------------------------------------------------- * Preprocessor_parse() * @@ -1366,14 +1387,20 @@ Preprocessor_parse(String *s) if (((include_all) || (import_all)) && (allow)) { String *s1, *s2, *fn; char *dirname; int sysfile = 0; + if (include_all && import_all) { + Swig_warning(WARN_PP_INCLUDEALL_IMPORTALL,Getfile(s),Getline(id),"Both includeall and importall are defined: using includeall"); + import_all = 0; + } Seek(value,0,SEEK_SET); fn = get_filename(value, &sysfile); s1 = cpp_include(fn, sysfile); if (s1) { if (include_all) Printf(ns,"%%includefile \"%s\" [\n", Swig_last_file()); - else if (import_all) + else if (import_all) { Printf(ns,"%%importfile \"%s\" [\n", Swig_last_file()); + push_imported(); + } /* See if the filename has a directory component */ dirname = Swig_file_dirname(Swig_last_file()); @@ -1388,6 +1415,9 @@ Preprocessor_parse(String *s) if (dirname) { Swig_pop_directory(); } + if (import_all) { + pop_imported(); + } Delete(s2); } Delete(s1); @@ -1495,9 +1525,8 @@ Preprocessor_parse(String *s) add_chunk(ns,chunk,allow); copy_location(s,chunk); Printf(ns,"%sfile%s \"%s\" [\n", decl, opt, Swig_last_file()); - if ((Cmp(decl,"%import") == 0) || (Cmp(decl,"%extern") == 0)) { - Preprocessor_define("WRAPEXTERN 1", 0); - Preprocessor_define("SWIGIMPORT 1", 0); + if (Cmp(decl,"%import") == 0) { + push_imported(); } dirname = Swig_file_dirname(Swig_last_file()); if (sysfile || !strlen(dirname)) dirname = 0; @@ -1509,9 +1538,8 @@ Preprocessor_parse(String *s) if (dirname) { Swig_pop_directory(); } - if ((Cmp(decl,"%import") == 0) || (Cmp(decl,"%extern") == 0)) { - Preprocessor_undef("SWIGIMPORT"); - Preprocessor_undef("WRAPEXTERN"); + if (Cmp(decl,"%import") == 0) { + pop_imported(); } addline(ns,s2,allow); Printf(ns,"\n]");