mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-06 03:50:06 +01:00
* Include inner classes in a ClassDef's allItems
* Enable finding an overload based on its constness * Add FunctionDef.renameOverload * Write nested enums before inner classes and ctors in the sip generator. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@70775 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -136,6 +136,10 @@ class BaseDef(object):
|
||||
if hasattr(item, 'overloads'):
|
||||
for o in item.overloads:
|
||||
items.extend(o.allItems())
|
||||
if hasattr(item, 'innerclasses'):
|
||||
for o in item.innerclasses:
|
||||
items.extend(o.allItems())
|
||||
|
||||
return items
|
||||
|
||||
|
||||
@@ -311,13 +315,17 @@ class FunctionDef(BaseDef):
|
||||
return [self] + self.overloads
|
||||
|
||||
|
||||
def findOverload(self, matchText):
|
||||
def findOverload(self, matchText, isConst=None):
|
||||
"""
|
||||
Search for an overloaded method that has matchText in its C++ argsString.
|
||||
"""
|
||||
for o in self.all():
|
||||
if matchText in o.argsString and not o.ignored:
|
||||
return o
|
||||
if isConst is None:
|
||||
return o
|
||||
else:
|
||||
if o.isConst == isConst:
|
||||
return o
|
||||
return None
|
||||
|
||||
|
||||
@@ -327,6 +335,42 @@ class FunctionDef(BaseDef):
|
||||
"""
|
||||
return bool([x for x in self.overloads if not x.ignored])
|
||||
|
||||
|
||||
def renameOverload(self, matchText, newName, **kw):
|
||||
"""
|
||||
Rename the overload with matching matchText in the argsString to
|
||||
newName. The overload is moved out of this function's overload list
|
||||
and directly into the parent module or class so it can appear to be a
|
||||
separate function.
|
||||
"""
|
||||
if hasattr(self, 'module'):
|
||||
parent = self.module
|
||||
else:
|
||||
parent = self.klass
|
||||
item = self.findOverload(matchText)
|
||||
item.pyName = newName
|
||||
item.__dict__.update(kw)
|
||||
|
||||
if item is self and not self.hasOverloads():
|
||||
# We're done, there actually is only one instance of this method
|
||||
pass
|
||||
elif item is self:
|
||||
# Make the first overload take the place of this node in the
|
||||
# parent, and then insert this item into the parent's list again
|
||||
overloads = self.overloads
|
||||
overloads.sort(key=lambda o: o.ignored)
|
||||
self.overloads = []
|
||||
first = overloads[0]
|
||||
first.overloads = overloads[1:]
|
||||
idx = parent.items.index(self)
|
||||
parent.items[idx] = first
|
||||
parent.insertItemAfter(first, self)
|
||||
|
||||
else:
|
||||
# Just remove from the overloads list and insert it into the parent.
|
||||
self.overloads.remove(item)
|
||||
parent.insertItemAfter(self, item)
|
||||
|
||||
|
||||
def ignore(self, val=True):
|
||||
# If the item being ignored has overloads then try to reorder the
|
||||
|
||||
@@ -435,23 +435,32 @@ from %s import *
|
||||
# is the generator currently inside the class or after it?
|
||||
klass.generatingInClass = True
|
||||
|
||||
# Split the items into public and protected groups
|
||||
ctors = [i for i in klass if
|
||||
isinstance(i, extractors.MethodDef) and
|
||||
i.protection == 'public' and (i.isCtor or i.isDtor)]
|
||||
enums = [i for i in klass if
|
||||
isinstance(i, extractors.EnumDef) and
|
||||
i.protection == 'public']
|
||||
public = [i for i in klass if i.protection == 'public' and i not in ctors+enums]
|
||||
protected = [i for i in klass if i.protection == 'protected']
|
||||
|
||||
if klass.kind == 'class':
|
||||
stream.write('%spublic:\n' % indent)
|
||||
|
||||
# Write enums first since they may be used as default values in
|
||||
# methods or in nested classes
|
||||
for item in enums:
|
||||
self.dispatchClassItem(klass, item, stream, indent2)
|
||||
|
||||
# Next do inner classes
|
||||
for item in klass.innerclasses:
|
||||
if klass.kind == 'class':
|
||||
stream.write('%s%s:\n' % (indent, item.protection))
|
||||
item.klass = klass
|
||||
self.generateClass(item, stream, indent2)
|
||||
|
||||
if klass.kind == 'class':
|
||||
stream.write('%spublic:\n' % indent)
|
||||
|
||||
# Split the items into public and protected groups
|
||||
ctors = [i for i in klass if
|
||||
isinstance(i, extractors.MethodDef) and
|
||||
i.protection == 'public' and (i.isCtor or i.isDtor)]
|
||||
public = [i for i in klass if i.protection == 'public' and i not in ctors]
|
||||
protected = [i for i in klass if i.protection == 'protected']
|
||||
|
||||
|
||||
|
||||
# and then the ctors and the rest of the items in the class
|
||||
for item in ctors:
|
||||
self.dispatchClassItem(klass, item, stream, indent2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user