Skip to content

Commit

Permalink
Add %$isextendmember for %rename of members added via %extend
Browse files Browse the repository at this point in the history
  • Loading branch information
wsfulton committed Feb 18, 2014
1 parent 9cbd742 commit c5911cc
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGES.current
Expand Up @@ -8,6 +8,12 @@ Version 3.0.0 (in progress)
2014-02-15: wsfulton
Fix the %$ismember %rename predicates to also apply to members added via %extend.

Add %$isextendmember for %rename of members added via %extend. This can be used to
distinguish between normal class/struct members and %extend members. For example
'%$ismember, %$not %$isextendmember' will now identify just class/struct members.

*** POTENTIAL INCOMPATIBILITY ***

2014-02-16: hfalcic
[Python] Patch #133 - fix crashes/exceptions in exception handling in Python 3.3

Expand Down
7 changes: 7 additions & 0 deletions Examples/test-suite/python/rename_predicates_runme.py
Expand Up @@ -33,3 +33,10 @@
CA_CamelCase()
LC_lowerCamelCase()
UC_under_case_it()

ex = ExtendCheck()
ex.MF_real_member1()
ex.MF_real_member2()
ex.EX_EXTENDMETHOD1()
ex.EX_EXTENDMETHOD2()
ex.EX_EXTENDMETHOD3()
23 changes: 22 additions & 1 deletion Examples/test-suite/rename_predicates.i
@@ -1,12 +1,12 @@
%module rename_predicates

// Test a few of the predicates - %$isfunction etc
%rename("AF_%(utitle)s", %$isfunction) "";
%rename("MF_%(utitle)s", %$isfunction, %$ismember) "";
%rename("GF_%(utitle)s", %$isfunction, %$not %$ismember) "";
%rename("MV_%(utitle)s", %$isvariable) "";
%rename("GV_%(utitle)s", %$isvariable, %$isglobal) "";


%extend RenamePredicates {
void extend_function_before() {}
}
Expand All @@ -28,6 +28,7 @@ void global_function() {}
void extend_function_after() {}
}

// Test the various %rename functions - %(upper) etc
%rename("UC_%(upper)s") "uppercase";
%rename("LC_%(lower)s") "LOWERcase";
%rename("TI_%(title)s") "title";
Expand All @@ -48,3 +49,23 @@ void Lower_camel_Case() {}
void UnderCaseIt() {}
%}

// Test renaming only member functions in %extend
%rename("EX_%(upper)s", %$isfunction, %$isextendmember) "";
%extend ExtendCheck {
void ExtendMethod1() {}
}
%inline %{
struct ExtendCheck {
void RealMember1() {}
#ifdef SWIG
%extend {
void ExtendMethod2() {}
}
#endif
void RealMember2() {}
};
%}
%extend ExtendCheck {
void ExtendMethod3() {}
}

1 change: 1 addition & 0 deletions Lib/swig.swg
Expand Up @@ -297,6 +297,7 @@ static int NAME(TYPE x) {

%define %$ismember "match$ismember"="1" %enddef
%define %$isglobal %$not %$ismember %enddef
%define %$isextendmember "match$isextendmember"="1" %enddef
%define %$innamespace "match$parentNode$nodeType"="namespace" %enddef

%define %$ispublic "match$access"="public" %enddef
Expand Down
18 changes: 13 additions & 5 deletions Source/CParse/parser.y
Expand Up @@ -363,6 +363,10 @@ static void add_symbols(Node *n) {
Setattr(n,"ismember","1");
}

if (extendmode) {
Setattr(n,"isextendmember","1");
}

if (!isfriend && inclass) {
if ((cplus_mode != CPLUS_PUBLIC)) {
only_csymbol = 1;
Expand Down Expand Up @@ -1392,6 +1396,7 @@ static void mark_nodes_as_extend(Node *n) {
for (; n; n = nextSibling(n)) {
if (Getattr(n, "template") && Strcmp(nodeType(n), "class") == 0)
continue;
/* Fix me: extend is not a feature. Replace with isextendmember? */
Setattr(n, "feature:extend", "1");
mark_nodes_as_extend(firstChild(n));
}
Expand Down Expand Up @@ -4350,14 +4355,17 @@ cpp_members : cpp_member cpp_members {
}
}
| EXTEND LBRACE {
if (cplus_mode != CPLUS_PUBLIC) {
Swig_error(cparse_file,cparse_line,"%%extend can only be used in a public section\n");
}
} cpp_members RBRACE cpp_members {
extendmode = 1;
if (cplus_mode != CPLUS_PUBLIC) {
Swig_error(cparse_file,cparse_line,"%%extend can only be used in a public section\n");
}
} cpp_members RBRACE {
extendmode = 0;
} cpp_members {
$$ = new_node("extend");
mark_nodes_as_extend($4);
appendChild($$,$4);
set_nextSibling($$,$6);
set_nextSibling($$,$7);
}
| include_directive { $$ = $1; }
| empty { $$ = 0;}
Expand Down

0 comments on commit c5911cc

Please sign in to comment.