check for overloads when it's a CppMethod too

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@69779 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2011-11-17 03:51:02 +00:00
parent 3e72b29f7d
commit fd0a62c1c4
2 changed files with 20 additions and 5 deletions

View File

@@ -514,6 +514,7 @@ class ClassDef(BaseDef):
self.allowNone = False # Allow the convertFrom code to handle None too. self.allowNone = False # Allow the convertFrom code to handle None too.
self.innerclasses = [] self.innerclasses = []
self.isInner = False self.isInner = False
self.cppCtorCount = 0
# Stuff that needs to be generated after the class instead of within # Stuff that needs to be generated after the class instead of within
# it. Some back-end generators need to put stuff inside the class, and # it. Some back-end generators need to put stuff inside the class, and

View File

@@ -461,6 +461,7 @@ from %s import *
def generateMethod(self, method, stream, indent): def generateMethod(self, method, stream, indent):
assert isinstance(method, extractors.MethodDef) assert isinstance(method, extractors.MethodDef)
_needDocstring = getattr(method, '_needDocstring', True) _needDocstring = getattr(method, '_needDocstring', True)
checkOverloads = True
if not method.ignored: if not method.ignored:
if method.isVirtual: if method.isVirtual:
stream.write("%svirtual\n" % indent) stream.write("%svirtual\n" % indent)
@@ -488,6 +489,7 @@ from %s import *
_needDocstring = False _needDocstring = False
if method.cppCode: if method.cppCode:
checkOverloads = False
code, codeType = method.cppCode code, codeType = method.cppCode
if codeType == 'sip': if codeType == 'sip':
stream.write('%s%%MethodCode\n' % indent) stream.write('%s%%MethodCode\n' % indent)
@@ -500,7 +502,7 @@ from %s import *
stream.write('\n') stream.write('\n')
if method.overloads: if checkOverloads and method.overloads:
for m in method.overloads: for m in method.overloads:
m._needDocstring = _needDocstring m._needDocstring = _needDocstring
self.dispatchClassItem(method.klass, m, stream, indent) self.dispatchClassItem(method.klass, m, stream, indent)
@@ -525,6 +527,7 @@ from %s import *
if method.ignored: if method.ignored:
return return
_needDocstring = getattr(method, '_needDocstring', True)
argsString = _removeIgnoredParams(method.argsString, method.items) argsString = _removeIgnoredParams(method.argsString, method.items)
lastP = argsString.rfind(')') lastP = argsString.rfind(')')
pnames = argsString[:lastP].strip('()').split(',') pnames = argsString[:lastP].strip('()').split(',')
@@ -551,7 +554,11 @@ from %s import *
(indent, typ, method.name, argsString, constMod, self.annotate(method))) (indent, typ, method.name, argsString, constMod, self.annotate(method)))
# write the docstring # write the docstring
self.generateDocstring(method, stream, indent) if _needDocstring and not (method.isCtor or method.isDtor):
self.generateDocstring(method, stream, indent)
# We only write a docstring for the first overload, otherwise
# SIP appends them all together.
_needDocstring = False
klass = method.klass klass = method.klass
if klass: if klass:
@@ -568,7 +575,8 @@ from %s import *
fargs[idx] = arg fargs[idx] = arg
fargs = ', '.join(fargs) fargs = ', '.join(fargs)
if method.isCtor: if method.isCtor:
fname = '_%s_newCtor' % klass.name klass.cppCtorCount += 1
fname = '_%s_ctor%d' % (klass.name, klass.cppCtorCount)
fargs = '(%s)' % fargs fargs = '(%s)' % fargs
fstream.write('%s%%TypeCode\n' % indent) fstream.write('%s%%TypeCode\n' % indent)
typ = klass.name typ = klass.name
@@ -619,7 +627,8 @@ from %s import *
if method.isCtor: if method.isCtor:
stream.write('sipCpp = %s(%s);\n' % (fname, pnames)) stream.write('sipCpp = %s(%s);\n' % (fname, pnames))
else: else:
stream.write('%sPyErr_Clear();\n' % indent+' '*4) stream.write('PyErr_Clear();\n')
stream.write(indent+' '*4)
if method.type != 'void': if method.type != 'void':
stream.write('sipRes = ') stream.write('sipRes = ')
if klass: if klass:
@@ -633,12 +642,17 @@ from %s import *
stream.write('%s(sipCpp%s);\n' % (fname, pnames)) stream.write('%s(sipCpp%s);\n' % (fname, pnames))
else: else:
stream.write('%s(%s);\n' % (fname, pnames)) stream.write('%s(%s);\n' % (fname, pnames))
stream.write('%sif (PyErr_Occurred()) sipIsErr = 1;\n' % indent+' '*4) stream.write('%sif (PyErr_Occurred()) sipIsErr = 1;\n' % (indent+' '*4))
stream.write('%s%%End\n' % indent) stream.write('%s%%End\n' % indent)
# and finally, add the new function itself # and finally, add the new function itself
stream.write(fstream.getvalue()) stream.write(fstream.getvalue())
stream.write('\n') stream.write('\n')
if method.overloads:
for m in method.overloads:
m._needDocstring = _needDocstring
self.dispatchClassItem(method.klass, m, stream, indent)