[pypy-commit] pypy reflex-support: improved "const" removal
wlav
noreply at buildbot.pypy.org
Wed Mar 20 23:51:53 CET 2013
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r62585:94948aa3cb9c
Date: 2013-03-20 14:39 -0700
http://bitbucket.org/pypy/pypy/changeset/94948aa3cb9c/
Log: improved "const" removal
diff --git a/pypy/module/cppyy/helper.py b/pypy/module/cppyy/helper.py
--- a/pypy/module/cppyy/helper.py
+++ b/pypy/module/cppyy/helper.py
@@ -2,26 +2,26 @@
#- type name manipulations --------------------------------------------------
-def _remove_const(name):
+def remove_const(name):
tmplt_start = name.find("<")
- if 0 <= tmplt_start:
- # only replace const within the class name, not in the template parameters
- return "".join(rstring.split(name[:tmplt_start], "const"))+name[tmplt_start:]
+ tmplt_stop = name.rfind(">")
+ if 0 <= tmplt_start and 0 <= tmplt_stop:
+ # only replace const qualifying the class name, not in the template parameters
+ return "".join([x.strip(" ") for x in rstring.split(name[:tmplt_start], "const")])+\
+ name[tmplt_start:tmplt_stop]+\
+ "".join([x.strip(" ") for x in rstring.split(name[tmplt_stop:], "const")])
else:
- return "".join(rstring.split(name, "const"))
-
-def remove_const(name):
- return _remove_const(name).strip(' ')
+ return "".join([x.strip(" ") for x in rstring.split(name, "const")])
def compound(name):
- name = _remove_const(name)
+ name = remove_const(name)
if name.endswith("]"): # array type?
return "[]"
i = _find_qualifier_index(name)
return "".join(name[i:].split(" "))
def array_size(name):
- name = _remove_const(name)
+ name = remove_const(name)
if name.endswith("]"): # array type?
idx = name.rfind("[")
if 0 < idx:
@@ -42,7 +42,7 @@
def clean_type(name):
# can't strip const early b/c name could be a template ...
i = _find_qualifier_index(name)
- name = name[:i].strip(' ')
+ name = name[:i].strip(" ")
idx = -1
if name.endswith("]"): # array type?
@@ -52,10 +52,10 @@
elif name.endswith(">"): # template type?
idx = name.find("<")
if 0 < idx: # always true, but just so that the translater knows
- n1 = _remove_const(name[:idx])
+ n1 = remove_const(name[:idx])
name = "".join([n1, name[idx:]])
else:
- name = _remove_const(name)
+ name = remove_const(name)
name = name[:_find_qualifier_index(name)]
return name.strip(' ')
diff --git a/pypy/module/cppyy/test/test_helper.py b/pypy/module/cppyy/test/test_helper.py
--- a/pypy/module/cppyy/test/test_helper.py
+++ b/pypy/module/cppyy/test/test_helper.py
@@ -3,6 +3,14 @@
def test_remove_const():
assert helper.remove_const("const int") == "int"
+ assert helper.remove_const("const some_class*") == "some_class*"
+ assert helper.remove_const("const some_class const*") == "some_class*"
+ assert helper.remove_const("some_class const*const") == "some_class*"
+
+ assert helper.remove_const("const some_class<const aap>*") == "some_class<const aap>*"
+ assert helper.remove_const("const some_class<const aap> const*") == "some_class<const aap>*"
+ assert helper.remove_const("some_class const<const aap*const>*const") == "some_class<const aap*const>*"
+
def test_compound():
assert helper.compound("int*") == "*"
assert helper.compound("int* const *&") == "**&"
More information about the pypy-commit
mailing list