Add support for friend templates, including operator overloading.

Closes #196.
This commit is contained in:
William S Fulton 2015-05-04 10:01:34 +01:00
commit 428b6176df
10 changed files with 146 additions and 3 deletions

View file

@ -6453,8 +6453,8 @@ idcolon : idtemplate idcolontail {
| NONID DCOLON idtemplate {
$$ = NewStringf("::%s",$3);
}
| OPERATOR {
$$ = NewString($1);
| OPERATOR template_decl {
$$ = NewStringf("%s%s",$1,$2);
}
| NONID DCOLON OPERATOR {
$$ = NewStringf("::%s",$3);

View file

@ -97,6 +97,15 @@ static int cparse_template_expand(Node *n, String *tname, String *rname, String
Append(cpatchlist, Getattr(n, "sym:name"));
}
}
if (checkAttribute(n, "storage", "friend")) {
String *symname = Getattr(n, "sym:name");
if (symname) {
String *stripped_name = SwigType_templateprefix(symname);
Setattr(n, "sym:name", stripped_name);
Delete(stripped_name);
}
Append(typelist, Getattr(n, "name"));
}
add_parms(Getattr(n, "parms"), cpatchlist, typelist);
add_parms(Getattr(n, "throws"), cpatchlist, typelist);

View file

@ -940,7 +940,7 @@ int Language::cDeclaration(Node *n) {
}
if (!validIdentifier(symname)) {
Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap '%s' unless renamed to a valid identifier.\n", symname);
Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap '%s' unless renamed to a valid identifier.\n", SwigType_namestr(symname));
return SWIG_NOWRAP;
}

View file

@ -1003,6 +1003,10 @@ static int nodes_are_equivalent(Node *a, Node *b, int a_inclass) {
}
return 0;
}
if (Equal(ta, "template") && Equal(tb, "template")) {
if (Cmp(a_storage, "friend") == 0 || Cmp(b_storage, "friend") == 0)
return 1;
}
}
return 0;
}