From 0fd503d6af132467669b9a9f598391513744ee31 Mon Sep 17 00:00:00 2001 From: Bruno da Silva de Oliveira Date: Fri, 28 Mar 2003 21:02:24 +0000 Subject: [PATCH] - Bug where the full name of the operator wasn't used in the declaration - Now converter operators that return char* or string are automatically named __str__ in Python - Update documentation with info about Psyco [SVN r18127] --- pyste/doc/pyste.txt | 4 ++++ pyste/doc/running_pyste.html | 9 +++++++++ pyste/example/operators.h | 3 ++- pyste/src/ClassExporter.py | 27 +++++++++++++++++---------- pyste/src/declarations.py | 2 +- pyste/src/pyste.py | 2 +- pyste/tests/example_operatorsUT.py | 1 + 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/pyste/doc/pyste.txt b/pyste/doc/pyste.txt index 585df472..e5527709 100644 --- a/pyste/doc/pyste.txt +++ b/pyste/doc/pyste.txt @@ -123,6 +123,10 @@ which for Visual C++ 6 is normally located at: with that, you should have little trouble setting up the flags. +[blurb [$theme/note.gif][*A note about Psyco][br][br] +Although you don't have to install [@http://psyco.sourceforge.net/ Psyco] to use Pyste, if you do, Pyste will make use of it to speed up the wrapper generation. Speed ups of 30% can be achieved, so it's highly recommended. +] + [page The Interface Files] The interface files are the heart of Pyste. The user creates one or more diff --git a/pyste/doc/running_pyste.html b/pyste/doc/running_pyste.html index ceea231e..b0bbdf2e 100644 --- a/pyste/doc/running_pyste.html +++ b/pyste/doc/running_pyste.html @@ -95,6 +95,15 @@ which for Visual C++ 6 is normally located at:

with that, you should have little trouble setting up the flags.

+ + + + +
+A note about Psyco

+Although you don't have to install +Psyco to use Pyste, if you do, Pyste will make use of it to speed up the wrapper generation. Speed ups of 30% can be achieved, so it's highly recommended. +
diff --git a/pyste/example/operators.h b/pyste/example/operators.h index 65ea68e1..6d92c4ea 100644 --- a/pyste/example/operators.h +++ b/pyste/example/operators.h @@ -28,7 +28,7 @@ struct C return C::x + other; } - + operator const char*() { return "C"; } }; double C::x = 10; @@ -40,4 +40,5 @@ const C operator*(const C& lhs, const C& rhs) return c; } + } diff --git a/pyste/src/ClassExporter.py b/pyste/src/ClassExporter.py index 18a74fc6..0e554eba 100644 --- a/pyste/src/ClassExporter.py +++ b/pyste/src/ClassExporter.py @@ -8,6 +8,7 @@ from EnumExporter import EnumExporter from makeid import makeid from copy import deepcopy import exporterutils +import re #============================================================================== # ClassExporter @@ -357,12 +358,16 @@ class ClassExporter(Exporter): '()' : '__call__', } - # converters which has a special name in python + # converters which have a special name in python + # it's a map of a regular expression of the converter's result to the + # appropriate python name SPECIAL_CONVERTERS = { - 'double' : '__float__', - 'float' : '__float__', - 'int' : '__int__', - 'long' : '__long__', + re.compile(r'(const)?\s*double$') : '__float__', + re.compile(r'(const)?\s*float$') : '__float__', + re.compile(r'(const)?\s*int$') : '__int__', + re.compile(r'(const)?\s*long$') : '__long__', + re.compile(r'(const)?\s*char\s*\*?$') : '__str__', + re.compile(r'(const)?.*::basic_string<.*>\s*(\*|\&)?$') : '__str__', } @@ -475,16 +480,18 @@ class ClassExporter(Exporter): converters = [x for x in self.public_members if type(x) == ConverterOperator] def ConverterMethodName(converter): - result_fullname = converter.result.name - if result_fullname in self.SPECIAL_CONVERTERS: - return self.SPECIAL_CONVERTERS[result_fullname] + result_fullname = converter.result.FullName() + result_name = converter.result.name + for regex, method_name in self.SPECIAL_CONVERTERS.items(): + if regex.match(result_fullname): + return method_name else: # extract the last name from the full name - result_name = makeid(result_fullname.split('::')[-1]) + result_name = makeid(result_name) return 'to_' + result_name for converter in converters: - info = self.info['operator'][converter.result.name] + info = self.info['operator'][converter.result.FullName()] # check if this operator should be excluded if info.exclude: continue diff --git a/pyste/src/declarations.py b/pyste/src/declarations.py index 73e69d5f..22ee2df4 100644 --- a/pyste/src/declarations.py +++ b/pyste/src/declarations.py @@ -258,7 +258,7 @@ class ConverterOperator(ClassOperator): 'An operator in the form "operator OtherClass()".' def FullName(self): - return self.class_ + '::operator ' + self.result.name + return self.class_ + '::operator ' + self.result.FullName() diff --git a/pyste/src/pyste.py b/pyste/src/pyste.py index 6cea954c..33f014ae 100644 --- a/pyste/src/pyste.py +++ b/pyste/src/pyste.py @@ -27,7 +27,7 @@ from policies import * from CppParser import CppParser, CppParserError import time -__VERSION__ = '0.6.3' +__VERSION__ = '0.6.4' def GetDefaultIncludes(): if 'INCLUDE' in os.environ: diff --git a/pyste/tests/example_operatorsUT.py b/pyste/tests/example_operatorsUT.py index 345a3a17..06585d05 100644 --- a/pyste/tests/example_operatorsUT.py +++ b/pyste/tests/example_operatorsUT.py @@ -19,6 +19,7 @@ class OperatorTest(unittest.TestCase): self.assertEqual(d(), 10) self.assertEqual(c(3.0), 13.0) self.assertEqual(d(6.0), 16.0) + self.assertEqual(str(c), "C") if __name__ == '__main__':