Discussion:
%rename for namespaces?
Marvin Greenberg
2012-06-20 19:23:56 UTC
Permalink
For swig 2.0 the documentation for %rename says
" The renaming applies to functions, variables, class and structure names,
member functions, and member data"

Later it recommends examining swig.swg for a list of renaming predicates, and
there we find (for 2.0.5, as of around revision 12900):

%define %$isnamespace "match"="namespace" %enddef

Trying some renames like this:

foo.i:
%module myspam

%rename("Utility",%$isnamespace) std;
%nspace std::Spam;

namespace std {
class Spam {
public:
void foo(int);
};
}


and running:
swig -c++ -java -o cppsrc/foo.cpp -outdir javasrc/ foo.i

still generates std/Spam.java not Utility/Spam.java. Trying variations on the
rename and nspace don;t seem to have any effect. Is %renaming namespaces (and
corresponding support in %nspace) some work in progress? Or is the predicate in
swig.swg just some "wouldn't it be nice" placeholder...
William S Fulton
2012-07-17 06:30:52 UTC
Permalink
Post by Marvin Greenberg
For swig 2.0 the documentation for %rename says
" The renaming applies to functions, variables, class and structure names,
member functions, and member data"
Later it recommends examining swig.swg for a list of renaming predicates, and
%define %$isnamespace "match"="namespace" %enddef
%module myspam
%rename("Utility",%$isnamespace) std;
%nspace std::Spam;
namespace std {
class Spam {
void foo(int);
};
}
swig -c++ -java -o cppsrc/foo.cpp -outdir javasrc/ foo.i
still generates std/Spam.java not Utility/Spam.java. Trying variations on the
rename and nspace don;t seem to have any effect. Is %renaming namespaces (and
corresponding support in %nspace) some work in progress? Or is the predicate in
swig.swg just some "wouldn't it be nice" placeholder...
Hi Marvin

SWIG's historic approach has been to ignore the namespaces and %nspace
is a relatively new feature to improve this situation. Consider it
incomplete and fairly experimental. For example, most language modules
do not have it implemented. Your observations of %rename not working for
it is interesting. Probably it can be made to work as you describe, but
I have higher priority tasks to work on for the foreseeable future. If
you want to get involved in fixing this I can give you some pointers. It
don't think it will be too hard.

William
marvin persona
2012-07-19 14:40:18 UTC
Permalink
OK. I'll file a bug/new feature report if you think it makes sense.
We might have cycles to try to fix this one bit, but not right away.
I was just trying to understand if renaming namespaces was "supposed"
to work at this point.
Post by William S Fulton
Hi Marvin
SWIG's historic approach has been to ignore the namespaces and %nspace is a
relatively new feature to improve this situation. Consider it incomplete and
fairly experimental. For example, most language modules do not have it
implemented. Your observations of %rename not working for it is interesting.
Probably it can be made to work as you describe, but I have higher priority
tasks to work on for the foreseeable future. If you want to get involved in
fixing this I can give you some pointers. It don't think it will be too
hard.
William
Loading...