diff --git a/CHANGES.current b/CHANGES.current index 770187d5e..0ac740062 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -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 diff --git a/Examples/test-suite/python/rename_predicates_runme.py b/Examples/test-suite/python/rename_predicates_runme.py index f21f32348..2ce097737 100644 --- a/Examples/test-suite/python/rename_predicates_runme.py +++ b/Examples/test-suite/python/rename_predicates_runme.py @@ -33,3 +33,10 @@ FL_firstLowerCase() 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() diff --git a/Examples/test-suite/rename_predicates.i b/Examples/test-suite/rename_predicates.i index a80f3c565..13fb3e1e4 100644 --- a/Examples/test-suite/rename_predicates.i +++ b/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() {} } @@ -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"; @@ -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() {} +} + diff --git a/Lib/swig.swg b/Lib/swig.swg index edadf036d..3ddbb85a0 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -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 diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 467f78587..dd8de45ff 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -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; @@ -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)); } @@ -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;}