Simple patch to allow fragments to include other fragments:

%fragment("Hello","header") "..."

%fragment("Hi","header",fragment="Hello") "..."

the latter fragment will include the first one if is invoked.

more than one fragment can be included at the time, just
keep adding fragment="f1",fragment="f2", etc.

this is used to emulate typemaps reuse, where all the
reusable typemap code is put in a fragment static method,
and then it can be included from another fragment typemap
as needed.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5690 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-01-27 23:39:35 +00:00
commit 6dceec6fdb
5 changed files with 64 additions and 16 deletions

View file

@ -23,17 +23,21 @@ static Hash *fragments = 0;
/* -----------------------------------------------------------------------------
* Swig_fragment_register()
*
* Add a fragment.
* Add a fragment. Use the original Node*, so, if something needs to be
* changed, lang.cxx doesn't nedd to be touched again.
* ----------------------------------------------------------------------------- */
void
Swig_fragment_register(String *name, String *section, String *code) {
String *ccode;
Swig_fragment_register(Node* fragment) {
String *name = Getattr(fragment,"name");
String *section = Getattr(fragment,"section");
String *ccode = Copy(Getattr(fragment,"code"));
Hash *kwargs = Getattr(fragment,"kwargs");
if (!fragments) {
fragments = NewHash();
}
ccode = Copy(code);
Setmeta(ccode,"section",Copy(section));
if (kwargs) Setmeta(ccode,"kwargs",Copy(kwargs));
Setattr(fragments,Copy(name),ccode);
}
@ -51,6 +55,13 @@ Swig_fragment_emit(String *name) {
code = Getattr(fragments,name);
if (code) {
String *section = Getmeta(code,"section");
Hash *n = Getmeta(code,"kwargs");
while (n) {
if (Cmp(Getattr(n,"name"),"fragment") == 0) {
Swig_fragment_emit(Getattr(n,"value"));
}
n = nextSibling(n);
}
if (section) {
File *f = Swig_filebyname(section);
if (!f) {

View file

@ -499,7 +499,7 @@ extern void Swig_typemap_attach_parms(const String_or_char *op, ParmList *parm
/* --- Code fragment support --- */
extern void Swig_fragment_register(String *name, String *section, String *code);
extern void Swig_fragment_register(Node* fragment);
extern void Swig_fragment_emit(String *name);
/* hacks defined in C++ ! */