Fragments can now be "type especialized", as the typemaps. The

syntax is as follows

 %fragment("name","header") { /* an old fragment */ }
 %fragment("name" {Type}, "header") { /* the fragment is type dependent */}

Now fragments can also be used inside templates:

 template <class T>
 struct A {
   %fragment("incode"{A<T>},"header") {
     /* 'incode' especialized fragment */
   }

   %typemap(in,fragment="incode"{A<T>}) {
     /*
       here we use the 'type especialized' fragment
       "incode"{A<T> }
      */
   }
 };

Also, there is a minor templ.c fix when expanding '#T'.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5749 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-03-17 08:01:06 +00:00
commit 22d2c01b50
2 changed files with 55 additions and 14 deletions

View file

@ -125,7 +125,8 @@ static Node *copy_node(Node *n) {
if (Strcmp(key,"node") == 0) { if (Strcmp(key,"node") == 0) {
continue; continue;
} }
if ((Strcmp(key,"parms") == 0) || (Strcmp(key,"pattern") == 0) || (Strcmp(key,"throws") == 0)) { if ((Strcmp(key,"parms") == 0) || (Strcmp(key,"pattern") == 0) || (Strcmp(key,"throws") == 0)
|| (Strcmp(key,"kwargs") == 0)) {
Setattr(nn,key,CopyParmList(k.item)); Setattr(nn,key,CopyParmList(k.item));
continue; continue;
} }
@ -952,6 +953,7 @@ Node *Swig_cparse(File *f) {
%type <dtype> cpp_vend; %type <dtype> cpp_vend;
%type <ivalue> rename_namewarn; %type <ivalue> rename_namewarn;
%type <ptype> type_specifier primitive_type_list ; %type <ptype> type_specifier primitive_type_list ;
%type <node> fname stringtype;
%% %%
@ -1266,24 +1268,49 @@ except_directive : EXCEPT LPAREN ID RPAREN LBRACE {
%fragment(name,location) { ... } %fragment(name,location) { ... }
------------------------------------------------------------ */ ------------------------------------------------------------ */
fragment_directive: FRAGMENT LPAREN kwargs RPAREN HBLOCK { /* fragment keyword arguments */
Hash *p = nextSibling($3); stringtype : string LBRACE type RBRACE {
$$ = new_node("fragment"); $$ = NewHash();
Setattr($$,"section", Getattr(p,"name")); Setattr($$,"value",$1);
Setattr($$,"name",Getattr($3,"name")); Setattr($$,"type",$3);
Setattr($$,"kwargs",nextSibling(p)); }
Setattr($$,"code",$5); ;
fname : string {
$$ = NewHash();
Setattr($$,"value",$1);
}
| stringtype {
$$ = $1;
}
;
fragment_directive: FRAGMENT LPAREN fname COMMA kwargs RPAREN HBLOCK {
Hash *p = $5;
$$ = new_node("fragment");
Setattr($$,"value",Getattr($3,"value"));
Setattr($$,"type",Getattr($3,"type"));
Setattr($$,"section",Getattr(p,"name"));
Setattr($$,"kwargs",nextSibling(p));
Setattr($$,"code",$7);
} }
| FRAGMENT LPAREN kwargs RPAREN LBRACE { | FRAGMENT LPAREN fname COMMA kwargs RPAREN LBRACE {
Hash *p = nextSibling($3); Hash *p = $5;
skip_balanced('{','}'); skip_balanced('{','}');
$$ = new_node("fragment"); $$ = new_node("fragment");
Setattr($$,"section", Getattr(p,"name")); Setattr($$,"value",Getattr($3,"value"));
Setattr($$,"name",Getattr($3,"name")); Setattr($$,"type",Getattr($3,"type"));
Setattr($$,"section",Getattr(p,"name"));
Setattr($$,"kwargs",nextSibling(p)); Setattr($$,"kwargs",nextSibling(p));
Delitem(scanner_ccode,0); Delitem(scanner_ccode,0);
Delitem(scanner_ccode,DOH_END); Delitem(scanner_ccode,DOH_END);
Setattr($$,"code",Copy(scanner_ccode)); Setattr($$,"code",Copy(scanner_ccode));
}
| FRAGMENT LPAREN fname RPAREN SEMI {
$$ = new_node("fragment");
Setattr($$,"value",Getattr($3,"value"));
Setattr($$,"type",Getattr($3,"type"));
Setattr($$,"emitonly","1");
} }
; ;
@ -2035,7 +2062,9 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
String *nname = NewStringf("__dummy_%d__", cnt++); String *nname = NewStringf("__dummy_%d__", cnt++);
Swig_cparse_template_expand($$,nname,temparms); Swig_cparse_template_expand($$,nname,temparms);
Setattr($$,"sym:name",nname); Setattr($$,"sym:name",nname);
Setattr($$,"feature:ignore","1"); /* Setattr($$,"feature:ignore","1"); */
Setattr($$,"feature:onlychildren",
"typemap,typemapitem,typemapcopy,typedef,types,fragment");
} }
Delattr($$,"templatetype"); Delattr($$,"templatetype");
Setattr($$,"template",n); Setattr($$,"template",n);
@ -3094,6 +3123,8 @@ cpp_member : c_declaration { $$ = $1; }
| template_directive { $$ = $1; } | template_directive { $$ = $1; }
| warn_directive { $$ = $1; } | warn_directive { $$ = $1; }
| anonymous_bitfield { $$ = 0; } | anonymous_bitfield { $$ = 0; }
| fragment_directive {$$ = $1; }
| types_directive {$$ = $1; }
| SEMI { $$ = 0; } | SEMI { $$ = 0; }
; ;
@ -4787,6 +4818,15 @@ kwargs : idstring EQUAL stringnum {
Setattr($$,"name",$1); Setattr($$,"name",$1);
set_nextSibling($$,$3); set_nextSibling($$,$3);
} }
| idstring EQUAL stringtype {
$$ = $3;
Setattr($$,"name",$1);
}
| idstring EQUAL stringtype COMMA kwargs {
$$ = $3;
Setattr($$,"name",$1);
set_nextSibling($$,$5);
}
; ;
stringnum : string { stringnum : string {

View file

@ -177,6 +177,7 @@ cparse_template_expand(Node *n, String *tname, String *rname, String *templatear
Append(typelist, Getattr(n,"type")); Append(typelist, Getattr(n,"type"));
Append(typelist, Getattr(n,"decl")); Append(typelist, Getattr(n,"decl"));
add_parms(Getattr(n,"parms"), cpatchlist, typelist); add_parms(Getattr(n,"parms"), cpatchlist, typelist);
add_parms(Getattr(n,"kwargs"), cpatchlist, typelist);
add_parms(Getattr(n,"pattern"), cpatchlist, typelist); add_parms(Getattr(n,"pattern"), cpatchlist, typelist);
add_parms(Getattr(n,"throws"), cpatchlist, typelist); add_parms(Getattr(n,"throws"), cpatchlist, typelist);
cn = firstChild(n); cn = firstChild(n);
@ -329,7 +330,7 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms) {
tydef = value; tydef = value;
} }
tmp = NewStringf("#%s",name); tmp = NewStringf("#%s",name);
tmpr = NewStringf("\"%s\"", value); tmpr = NewStringf("\"%s\"", valuestr);
sz = Len(cpatchlist); sz = Len(cpatchlist);
for (i = 0; i < sz; i++) { for (i = 0; i < sz; i++) {