add predicates to %rename, new kind attribute to cdecl and the '|' operator in %rename's match
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8388 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
27da47b56c
commit
2208b55215
4 changed files with 135 additions and 42 deletions
|
|
@ -1,5 +1,57 @@
|
||||||
Version 1.3.28 (unreleased).
|
Version 1.3.28 (unreleased).
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
01/12/2006: mmatus
|
||||||
|
- Add predicates to %rename, so, you don't need to
|
||||||
|
remember, for example, how to match a member function.
|
||||||
|
|
||||||
|
Now it is easy, for example to use the 'utitle' encoder
|
||||||
|
in all the member methods, you type:
|
||||||
|
|
||||||
|
%rename("%(utitle)s",%isfunction,%ismember) "";
|
||||||
|
|
||||||
|
Available predicates are (see swig.swg):
|
||||||
|
|
||||||
|
%isenum
|
||||||
|
%isenumitem
|
||||||
|
%isaccess
|
||||||
|
%isclass
|
||||||
|
%isextend
|
||||||
|
%isextend
|
||||||
|
%isconstructor
|
||||||
|
%isdestructor
|
||||||
|
%isnamespace
|
||||||
|
%istemplate
|
||||||
|
%isconstant
|
||||||
|
|
||||||
|
%isunion
|
||||||
|
%isfunction
|
||||||
|
%isvariable
|
||||||
|
%isimmutable
|
||||||
|
|
||||||
|
%isstatic
|
||||||
|
%isfriend
|
||||||
|
%istypedef
|
||||||
|
%isvirtual
|
||||||
|
%isexplicit
|
||||||
|
%isextern
|
||||||
|
|
||||||
|
%ismember
|
||||||
|
%isglobal
|
||||||
|
|
||||||
|
These predicates correspond to specific 'match'
|
||||||
|
declarations, which sometimes are not as evident as the
|
||||||
|
predicates names.
|
||||||
|
|
||||||
|
|
||||||
|
- Add the or '|' operation in %rename match, for
|
||||||
|
example to capitalize all the constants (%constant or
|
||||||
|
const cdecl):
|
||||||
|
|
||||||
|
%rename("%(upper)s",match="cdecl|constant",%isimmutable) "";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
01/12/2006: mgossage
|
01/12/2006: mgossage
|
||||||
- Partial fixed of errors under C89, bug #1356574
|
- Partial fixed of errors under C89, bug #1356574
|
||||||
(converted C++ style comments to C style)
|
(converted C++ style comments to C style)
|
||||||
|
|
|
||||||
45
Lib/swig.swg
45
Lib/swig.swg
|
|
@ -219,34 +219,37 @@ static int NAME(TYPE x) {
|
||||||
|
|
||||||
- to rename only the global functions:
|
- to rename only the global functions:
|
||||||
|
|
||||||
%rename("g_%(utitle)s", %isfunction, %isnotmember) "";
|
%rename("g_%(utitle)s", %isfunction, %isglobal) "";
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define %isenum match="enum"
|
%define %isenum match="enum" %enddef
|
||||||
#define %isenumitem match="enumitem"
|
%define %isenumitem match="enumitem" %enddef
|
||||||
#define %isaccess match="access"
|
%define %isaccess match="access" %enddef
|
||||||
#define %isclass match="class"
|
%define %isclass match="class" %enddef
|
||||||
#define %isextend match="extend"
|
%define %isextend match="extend" %enddef
|
||||||
#define %isextend match="extend"
|
%define %isextend match="extend" %enddef
|
||||||
#define %isconstructor match="constructor"
|
%define %isconstructor match="constructor" %enddef
|
||||||
#define %isdestructor match="destructor"
|
%define %isdestructor match="destructor" %enddef
|
||||||
#define %isnamespace match="namespace"
|
%define %isnamespace match="namespace" %enddef
|
||||||
#define %istemplate match="template"
|
%define %istemplate match="template" %enddef
|
||||||
|
%define %isconstant match="constant" %enddef
|
||||||
|
|
||||||
#define %isunion match$kind="union"
|
%define %isunion match$kind="union" %enddef
|
||||||
#define %isfunction match="cdecl",notmatch$decl=""
|
%define %isfunction match$kind="function" %enddef
|
||||||
|
%define %isvariable match$kind="variable" %enddef
|
||||||
|
%define %isimmutable "match$feature:immutable"="1" %enddef
|
||||||
|
|
||||||
#define %isstatic match$storage="static"
|
%define %isstatic match$storage="static" %enddef
|
||||||
#define %isfriend match$storage="friend"
|
%define %isfriend match$storage="friend" %enddef
|
||||||
#define %istypedef match$storage="typedef"
|
%define %istypedef match$storage="typedef" %enddef
|
||||||
#define %isvirtual match$storage="virtual"
|
%define %isvirtual match$storage="virtual" %enddef
|
||||||
#define %isexplicit match$storage="explicit"
|
%define %isexplicit match$storage="explicit" %enddef
|
||||||
#define %isextern match$storage="extern"
|
%define %isextern match$storage="extern" %enddef
|
||||||
|
|
||||||
#define %ismember match$parentNode$nodeType="class"
|
%define %ismember match$parentNode$nodeType="class" %enddef
|
||||||
#define %isnotmember notmatch$parentNode$nodeType="class"
|
%define %isglobal notmatch$parentNode$nodeType="class" %enddef
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Include all the warnings labels and macros
|
* Include all the warnings labels and macros
|
||||||
|
|
|
||||||
|
|
@ -230,7 +230,6 @@ static String *add_oldname = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static String *make_name(Node *n, String *name,SwigType *decl) {
|
static String *make_name(Node *n, String *name,SwigType *decl) {
|
||||||
int destructor = name && (*(Char(name)) == '~');
|
int destructor = name && (*(Char(name)) == '~');
|
||||||
|
|
||||||
|
|
@ -244,10 +243,6 @@ static String *make_name(Node *n, String *name,SwigType *decl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!name) return 0;
|
if (!name) return 0;
|
||||||
/* Check to see if the name is in the hash */
|
|
||||||
if (inclass) {
|
|
||||||
set_parentNode(n,current_class);
|
|
||||||
}
|
|
||||||
return Swig_name_make(n,Namespaceprefix,name,decl,add_oldname);
|
return Swig_name_make(n,Namespaceprefix,name,decl,add_oldname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -282,6 +277,7 @@ static void add_symbols(Node *n) {
|
||||||
String *old_prefix = 0;
|
String *old_prefix = 0;
|
||||||
Symtab *old_scope = 0;
|
Symtab *old_scope = 0;
|
||||||
int isfriend = inclass && is_friend(n);
|
int isfriend = inclass && is_friend(n);
|
||||||
|
int iscdecl = Cmp(nodeType(n),"cdecl") == 0;
|
||||||
if (inclass) {
|
if (inclass) {
|
||||||
String *name = Getattr(n, k_name);
|
String *name = Getattr(n, k_name);
|
||||||
if (isfriend) {
|
if (isfriend) {
|
||||||
|
|
@ -324,27 +320,34 @@ static void add_symbols(Node *n) {
|
||||||
}
|
}
|
||||||
Delete(prefix);
|
Delete(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_parentNode(n,current_class);
|
||||||
|
Setattr(n,"memberof",current_class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isfriend && inclass && (cplus_mode != CPLUS_PUBLIC)) {
|
if (!isfriend && inclass) {
|
||||||
int only_csymbol = 1;
|
if ((cplus_mode != CPLUS_PUBLIC)) {
|
||||||
if (cplus_mode == CPLUS_PROTECTED) {
|
int only_csymbol = 1;
|
||||||
Setattr(n,k_access, "protected");
|
if (cplus_mode == CPLUS_PROTECTED) {
|
||||||
only_csymbol = !Swig_need_protected(n);
|
Setattr(n,k_access, "protected");
|
||||||
} else {
|
only_csymbol = !Swig_need_protected(n);
|
||||||
/* private are needed only when they are pure virtuals */
|
} else {
|
||||||
Setattr(n,k_access, "private");
|
/* private are needed only when they are pure virtuals */
|
||||||
|
Setattr(n,k_access, "private");
|
||||||
if ((Cmp(Getattr(n,k_storage),"virtual") == 0)
|
if ((Cmp(Getattr(n,k_storage),"virtual") == 0)
|
||||||
&& (Cmp(Getattr(n,k_value),"0") == 0)) {
|
&& (Cmp(Getattr(n,k_value),"0") == 0)) {
|
||||||
only_csymbol = !Swig_need_protected(n);
|
only_csymbol = !Swig_need_protected(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (only_csymbol) {
|
if (only_csymbol) {
|
||||||
/* Only add to C symbol table and continue */
|
/* Only add to C symbol table and continue */
|
||||||
Swig_symbol_add(0, n);
|
Swig_symbol_add(0, n);
|
||||||
if (add_only_one) break;
|
if (add_only_one) break;
|
||||||
n = nextSibling(n);
|
n = nextSibling(n);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Setattr(n,k_access, "public");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Getattr(n,k_symname)) {
|
if (Getattr(n,k_symname)) {
|
||||||
|
|
@ -354,6 +357,21 @@ static void add_symbols(Node *n) {
|
||||||
decl = Getattr(n,k_decl);
|
decl = Getattr(n,k_decl);
|
||||||
if (!SwigType_isfunction(decl)) {
|
if (!SwigType_isfunction(decl)) {
|
||||||
String *makename = Getattr(n,"parser:makename");
|
String *makename = Getattr(n,"parser:makename");
|
||||||
|
if (iscdecl) {
|
||||||
|
String *storage = Getattr(n, k_storage);
|
||||||
|
if (Cmp(storage,"typedef") == 0) {
|
||||||
|
Setattr(n,k_kind,"typedef");
|
||||||
|
} else {
|
||||||
|
SwigType *type = Getattr(n, k_type);
|
||||||
|
Setattr(n,k_kind,"variable");
|
||||||
|
if (type && !SwigType_ismutable(type)) {
|
||||||
|
SetFlag(n,"feature:immutable");
|
||||||
|
}
|
||||||
|
if (!type) {
|
||||||
|
Printf(stderr,"notype name %s\n", Getattr(n,"name"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (makename) {
|
if (makename) {
|
||||||
symname = make_name(n, makename,0);
|
symname = make_name(n, makename,0);
|
||||||
Delattr(n,"parser:makename"); /* temporary information, don't leave it hanging around */
|
Delattr(n,"parser:makename"); /* temporary information, don't leave it hanging around */
|
||||||
|
|
@ -372,6 +390,9 @@ static void add_symbols(Node *n) {
|
||||||
} else {
|
} else {
|
||||||
SwigType *fdecl = Copy(decl);
|
SwigType *fdecl = Copy(decl);
|
||||||
SwigType *fun = SwigType_pop_function(fdecl);
|
SwigType *fun = SwigType_pop_function(fdecl);
|
||||||
|
if (iscdecl) {
|
||||||
|
Setattr(n,k_kind,"function");
|
||||||
|
}
|
||||||
|
|
||||||
symname = make_name(n, Getattr(n,k_name),fun);
|
symname = make_name(n, Getattr(n,k_name),fun);
|
||||||
wrn = Swig_name_warning(n, Namespaceprefix,symname,fun);
|
wrn = Swig_name_warning(n, Namespaceprefix,symname,fun);
|
||||||
|
|
|
||||||
|
|
@ -1086,6 +1086,23 @@ static DOH *Swig_get_lattr(Node *n, List *lattr)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Swig_name_match_value(String *mvalue, String *value)
|
||||||
|
{
|
||||||
|
int match = 0;
|
||||||
|
char *cvalue = Char(value);
|
||||||
|
char *cmvalue = Char(mvalue);
|
||||||
|
char *sep = strstr(cmvalue,"|");
|
||||||
|
while (sep && !match) {
|
||||||
|
match = strncmp(cvalue,cmvalue, sep - cmvalue) == 0;
|
||||||
|
cmvalue = sep + 1;
|
||||||
|
sep = strstr(cmvalue,"|");
|
||||||
|
}
|
||||||
|
if (!match) {
|
||||||
|
match = strcmp(cvalue,cmvalue) == 0;
|
||||||
|
}
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
int Swig_name_match_nameobj(Hash *rn, Node *n) {
|
int Swig_name_match_nameobj(Hash *rn, Node *n) {
|
||||||
int match = 1;
|
int match = 1;
|
||||||
List *matchlist = HashGetAttr(rn,k_matchlist);
|
List *matchlist = HashGetAttr(rn,k_matchlist);
|
||||||
|
|
@ -1103,7 +1120,7 @@ int Swig_name_match_nameobj(Hash *rn, Node *n) {
|
||||||
match = 0;
|
match = 0;
|
||||||
if (nval) {
|
if (nval) {
|
||||||
String *kwval = Getattr(kw,k_value);
|
String *kwval = Getattr(kw,k_value);
|
||||||
match = Equal(nval, kwval);
|
match = Swig_name_match_value(kwval, nval);
|
||||||
#ifdef SWIG_DEBUG
|
#ifdef SWIG_DEBUG
|
||||||
Printf(stderr,"val %s %s %d %d \n",nval, kwval,match, ilen);
|
Printf(stderr,"val %s %s %d %d \n",nval, kwval,match, ilen);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue