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@8388 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2006-01-12 09:06:07 +00:00
commit 4f68626cf6
4 changed files with 135 additions and 42 deletions

View file

@ -1,5 +1,57 @@
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
- Partial fixed of errors under C89, bug #1356574
(converted C++ style comments to C style)

View file

@ -219,34 +219,37 @@ static int NAME(TYPE x) {
- to rename only the global functions:
%rename("g_%(utitle)s", %isfunction, %isnotmember) "";
%rename("g_%(utitle)s", %isfunction, %isglobal) "";
*/
#define %isenum match="enum"
#define %isenumitem match="enumitem"
#define %isaccess match="access"
#define %isclass match="class"
#define %isextend match="extend"
#define %isextend match="extend"
#define %isconstructor match="constructor"
#define %isdestructor match="destructor"
#define %isnamespace match="namespace"
#define %istemplate match="template"
%define %isenum match="enum" %enddef
%define %isenumitem match="enumitem" %enddef
%define %isaccess match="access" %enddef
%define %isclass match="class" %enddef
%define %isextend match="extend" %enddef
%define %isextend match="extend" %enddef
%define %isconstructor match="constructor" %enddef
%define %isdestructor match="destructor" %enddef
%define %isnamespace match="namespace" %enddef
%define %istemplate match="template" %enddef
%define %isconstant match="constant" %enddef
#define %isunion match$kind="union"
#define %isfunction match="cdecl",notmatch$decl=""
%define %isunion match$kind="union" %enddef
%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 %isfriend match$storage="friend"
#define %istypedef match$storage="typedef"
#define %isvirtual match$storage="virtual"
#define %isexplicit match$storage="explicit"
#define %isextern match$storage="extern"
%define %isstatic match$storage="static" %enddef
%define %isfriend match$storage="friend" %enddef
%define %istypedef match$storage="typedef" %enddef
%define %isvirtual match$storage="virtual" %enddef
%define %isexplicit match$storage="explicit" %enddef
%define %isextern match$storage="extern" %enddef
#define %ismember match$parentNode$nodeType="class"
#define %isnotmember notmatch$parentNode$nodeType="class"
%define %ismember match$parentNode$nodeType="class" %enddef
%define %isglobal notmatch$parentNode$nodeType="class" %enddef
/* -----------------------------------------------------------------------------
* Include all the warnings labels and macros

View file

@ -230,7 +230,6 @@ static String *add_oldname = 0;
static String *make_name(Node *n, String *name,SwigType *decl) {
int destructor = name && (*(Char(name)) == '~');
@ -244,10 +243,6 @@ static String *make_name(Node *n, String *name,SwigType *decl) {
}
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);
}
@ -282,6 +277,7 @@ static void add_symbols(Node *n) {
String *old_prefix = 0;
Symtab *old_scope = 0;
int isfriend = inclass && is_friend(n);
int iscdecl = Cmp(nodeType(n),"cdecl") == 0;
if (inclass) {
String *name = Getattr(n, k_name);
if (isfriend) {
@ -324,27 +320,34 @@ static void add_symbols(Node *n) {
}
Delete(prefix);
}
set_parentNode(n,current_class);
Setattr(n,"memberof",current_class);
}
}
if (!isfriend && inclass && (cplus_mode != CPLUS_PUBLIC)) {
int only_csymbol = 1;
if (cplus_mode == CPLUS_PROTECTED) {
Setattr(n,k_access, "protected");
only_csymbol = !Swig_need_protected(n);
} else {
/* private are needed only when they are pure virtuals */
Setattr(n,k_access, "private");
if (!isfriend && inclass) {
if ((cplus_mode != CPLUS_PUBLIC)) {
int only_csymbol = 1;
if (cplus_mode == CPLUS_PROTECTED) {
Setattr(n,k_access, "protected");
only_csymbol = !Swig_need_protected(n);
} else {
/* private are needed only when they are pure virtuals */
Setattr(n,k_access, "private");
if ((Cmp(Getattr(n,k_storage),"virtual") == 0)
&& (Cmp(Getattr(n,k_value),"0") == 0)) {
only_csymbol = !Swig_need_protected(n);
}
}
if (only_csymbol) {
/* Only add to C symbol table and continue */
Swig_symbol_add(0, n);
if (add_only_one) break;
n = nextSibling(n);
continue;
}
if (only_csymbol) {
/* Only add to C symbol table and continue */
Swig_symbol_add(0, n);
if (add_only_one) break;
n = nextSibling(n);
continue;
}
} else {
Setattr(n,k_access, "public");
}
}
if (Getattr(n,k_symname)) {
@ -354,6 +357,21 @@ static void add_symbols(Node *n) {
decl = Getattr(n,k_decl);
if (!SwigType_isfunction(decl)) {
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) {
symname = make_name(n, makename,0);
Delattr(n,"parser:makename"); /* temporary information, don't leave it hanging around */
@ -372,6 +390,9 @@ static void add_symbols(Node *n) {
} else {
SwigType *fdecl = Copy(decl);
SwigType *fun = SwigType_pop_function(fdecl);
if (iscdecl) {
Setattr(n,k_kind,"function");
}
symname = make_name(n, Getattr(n,k_name),fun);
wrn = Swig_name_warning(n, Namespaceprefix,symname,fun);

View file

@ -1086,6 +1086,23 @@ static DOH *Swig_get_lattr(Node *n, List *lattr)
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 match = 1;
List *matchlist = HashGetAttr(rn,k_matchlist);
@ -1103,7 +1120,7 @@ int Swig_name_match_nameobj(Hash *rn, Node *n) {
match = 0;
if (nval) {
String *kwval = Getattr(kw,k_value);
match = Equal(nval, kwval);
match = Swig_name_match_value(kwval, nval);
#ifdef SWIG_DEBUG
Printf(stderr,"val %s %s %d %d \n",nval, kwval,match, ilen);
#endif