From 30cf3657c6f7428ae99cc57cede46e7c8ff18372 Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Fri, 30 Sep 2005 15:27:20 +0000 Subject: [PATCH] recover the %import(module=name) option,lost in previous fix git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7558 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/test-suite/imports_b.i | 27 ++++++++++++++++++++++++++- SWIG/Source/CParse/parser.y | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/SWIG/Examples/test-suite/imports_b.i b/SWIG/Examples/test-suite/imports_b.i index 070dea447..afc573a39 100644 --- a/SWIG/Examples/test-suite/imports_b.i +++ b/SWIG/Examples/test-suite/imports_b.i @@ -12,6 +12,31 @@ #include "imports_b.h" %} -%import(module="imports_a") "imports_a.i" + +/* + To import, you can use either + + %import "imports_a.i" + + or + + %import(module="imports_a") "imports_a.h" + + + In the first case, imports_a.i should declare the module name using + the %module directive. + + In the second case, the file could be either a .h file, where no + %module directive will be found, or a swig interface file, where + the module option will take priority over any %module directive + inside the imported file. + +*/ + +#if 0 +%import "imports_a.i" +#else +%import(module="imports_a") "imports_a.h" +#endif %include "imports_b.h" diff --git a/SWIG/Source/CParse/parser.y b/SWIG/Source/CParse/parser.y index d5133959d..efaa6a1e7 100644 --- a/SWIG/Source/CParse/parser.y +++ b/SWIG/Source/CParse/parser.y @@ -1748,11 +1748,13 @@ include_directive: includetype options string LBRACKET { cparse_file = Swig_copy_string($3); cparse_line = 0; } interface RBRACKET { + String *mname = 0; $$ = $6; cparse_file = $1.filename; cparse_line = $1.line; if (strcmp($1.type,"include") == 0) set_nodeType($$,"include"); if (strcmp($1.type,"import") == 0) { + mname = $2 ? Getattr($2,"module") : 0; set_nodeType($$,"import"); if (import_mode) --import_mode; } @@ -1763,11 +1765,29 @@ include_directive: includetype options string LBRACKET { Node *n = firstChild($$); while (n) { if (Strcmp(nodeType(n),"module") == 0) { + if (mname) { + Setattr(n,"name", mname); + mname = 0; + } Setattr($$,"module",Getattr(n,"name")); break; } n = nextSibling(n); } + if (mname) { + /* There is no module node in the import + node, ie, you imported a .h file + directly. We are forced then to create + a new import node with a module node. + */ + Node *nint = new_node("import"); + Node *mnode = new_node("module"); + Setattr(mnode,"name", mname); + appendChild(nint,mnode); + appendChild(nint,firstChild($$)); + $$ = nint; + Setattr($$,"module",mname); + } } Setattr($$,"options",$2); }