Ignore non-matching regex renames when searching renames list.
Skip over %renames with non-matching %(regex)s expansion when looking for the one to apply to the given name. This allows to have multiple anonymous renames using regex as now the first _matching_ one will be used instead of always using the first one and ignoring all the rest of them. Extend unit tests to verify that applying two anonymous %renames does work as expected. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12293 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
953c4abaca
commit
f6cab0170a
6 changed files with 53 additions and 3 deletions
|
|
@ -5,6 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release.
|
|||
Version 2.0.2 (in progress)
|
||||
===========================
|
||||
|
||||
2010-11-12: vadz
|
||||
Fix handling of multiple regex-using %renames attached to the same
|
||||
declaration. For example, now
|
||||
|
||||
%rename("%(regex/^Set(.*)/put\\1/)s") "";
|
||||
%rename("%(regex/^Get(.*)/get\\1/)s") "";
|
||||
|
||||
works as expected whereas before only the last anonymous rename was
|
||||
taken into account.
|
||||
|
||||
2010-10-17: drjoe
|
||||
[R] Fix failure in overloaded functions which was breaking
|
||||
QuantLib-SWIG
|
||||
|
|
|
|||
12
Examples/test-suite/csharp/rename_pcre_encoder_runme.cs
Normal file
12
Examples/test-suite/csharp/rename_pcre_encoder_runme.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using rename_pcre_encoderNamespace;
|
||||
|
||||
public class runme {
|
||||
static void Main() {
|
||||
SomeWidget w = new SomeWidget();
|
||||
w.putBorderWidth(17);
|
||||
if ( w.getBorderWidth() != 17 )
|
||||
throw new Exception(String.Format("Border with should be 17, not {0}",
|
||||
w.getBorderWidth()));
|
||||
}
|
||||
}
|
||||
14
Examples/test-suite/java/rename_pcre_encoder_runme.java
Normal file
14
Examples/test-suite/java/rename_pcre_encoder_runme.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import rename_pcre_encoder.*;
|
||||
|
||||
public class rename_pcre_encoder_runme {
|
||||
static { System.loadLibrary("rename_pcre_encoder"); }
|
||||
|
||||
public static void main(String argv[])
|
||||
{
|
||||
SomeWidget w = new SomeWidget();
|
||||
w.putBorderWidth(17);
|
||||
if ( w.getBorderWidth() != 17 )
|
||||
throw new RuntimeException(String.format("Border with should be 17, not %d",
|
||||
w.getBorderWidth()));
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,9 @@ from rename_pcre_encoder import *
|
|||
|
||||
s = SomeWidget()
|
||||
s.putBorderWidth(3)
|
||||
if s.getBorderWidth() != 3:
|
||||
raise RuntimeError("Border should be 3, not %d" % (s.getBorderWidth(),))
|
||||
|
||||
s.putSize(4, 5)
|
||||
a = AnotherWidget()
|
||||
a.DoSomething()
|
||||
|
|
|
|||
|
|
@ -3,14 +3,19 @@
|
|||
// strip the wx prefix from all identifiers except those starting with wxEVT
|
||||
%rename("%(regex:/wx(?!EVT)(.*)/\\1/)s") "";
|
||||
|
||||
// Replace "Set" prefix with "put" in all functions
|
||||
// Replace "Set" and "Get" prefixes with "put" and "get" respectively.
|
||||
%rename("%(regex:/^Set(.*)/put\\1/)s", %$isfunction) "";
|
||||
%rename("%(regex:/^Get(.*)/get\\1/)s", %$isfunction) "";
|
||||
|
||||
%inline %{
|
||||
|
||||
struct wxSomeWidget {
|
||||
void SetBorderWidth(int) {}
|
||||
void SetBorderWidth(int width) { m_width = width; }
|
||||
int GetBorderWidth() const { return m_width; }
|
||||
|
||||
void SetSize(int, int) {}
|
||||
|
||||
int m_width;
|
||||
};
|
||||
|
||||
struct wxAnotherWidget {
|
||||
|
|
|
|||
|
|
@ -1302,7 +1302,13 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na
|
|||
: Swig_name_match_value(tname, sname);
|
||||
Delete(sname);
|
||||
} else {
|
||||
match = 1;
|
||||
/* Applying the renaming rule may fail if it contains a %(regex)s expression that doesn't match the given name. */
|
||||
String *sname = NewStringf(Getattr(rn, "name"), name);
|
||||
if (sname) {
|
||||
if (Len(sname))
|
||||
match = 1;
|
||||
Delete(sname);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue