From 480bc21a84e2836f146351e43fcc238cdd7886f6 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 8 Jun 2013 23:31:44 +0000 Subject: [PATCH] Add a tool function that ignores one overloaded method if another overload only differs in constness. Use it in richtextbuffer. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@74137 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- TODO.txt | 5 +-- etg/richtextbuffer.py | 80 ++++++++------------------------------- etgtools/tweaker_tools.py | 30 +++++++++++++++ 3 files changed, 46 insertions(+), 69 deletions(-) diff --git a/TODO.txt b/TODO.txt index 5ae2ffb4..e7a08a3d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -138,10 +138,7 @@ other dev stuff * Reimplement the classes in the valgen, valnum and valtext headers as Python code, and make them visible in the core wx namespace? - * It would be nice to have a way to automatically ignore one overload if it - only differs from another overload by constness. See etg/richtextbuffer.py - for why. - + diff --git a/etg/richtextbuffer.py b/etg/richtextbuffer.py index 119d3d08..97af3acc 100644 --- a/etg/richtextbuffer.py +++ b/etg/richtextbuffer.py @@ -103,7 +103,6 @@ def run(): class wxRichTextStyleDefinition; class wxRichTextListStyleDefinition; class wxRichTextXMLHandler; - class wxRichTextCtrl; class wxRichTextStyleSheet; class wxRichTextFloatCollector; """)) @@ -116,109 +115,60 @@ def run(): #------------------------------------------------------- c = module.find('wxTextAttrDimensions') - # There are const and non-const versions of each of these, get rid of one - # of each pair. - c.find('GetLeft').ignore() - c.find('GetRight').ignore() - c.find('GetTop').ignore() - c.find('GetBottom').ignore() - + tools.ignoreConstOverloads(c) #------------------------------------------------------- c = module.find('wxTextAttrSize') - c.find('GetWidth').ignore() - c.find('GetHeight').ignore() + tools.ignoreConstOverloads(c) c.find('SetWidth').findOverload('units').ignore() c.find('SetHeight').findOverload('units').ignore() #------------------------------------------------------- c = module.find('wxTextAttrBorder') - c.find('GetWidth').ignore() + tools.ignoreConstOverloads(c) #------------------------------------------------------- c = module.find('wxTextAttrBorders') - c.find('GetLeft').ignore() - c.find('GetRight').ignore() - c.find('GetTop').ignore() - c.find('GetBottom').ignore() + tools.ignoreConstOverloads(c) #------------------------------------------------------- c = module.find('wxTextBoxAttr') - c.find('GetMargins').ignore() - c.find('GetLeftMargin').ignore() - c.find('GetRightMargin').ignore() - c.find('GetTopMargin').ignore() - c.find('GetBottomMargin').ignore() - - c.find('GetPosition').ignore() - - c.find('GetLeft').ignore() - c.find('GetRight').ignore() - c.find('GetTop').ignore() - c.find('GetBottom').ignore() - - c.find('GetPadding').ignore() - c.find('GetLeftPadding').ignore() - c.find('GetRightPadding').ignore() - c.find('GetTopPadding').ignore() - c.find('GetBottomPadding').ignore() - - c.find('GetBorder').ignore() - c.find('GetLeftBorder').ignore() - c.find('GetRightBorder').ignore() - c.find('GetTopBorder').ignore() - c.find('GetBottomBorder').ignore() - - c.find('GetOutline').ignore() - c.find('GetLeftOutline').ignore() - c.find('GetRightOutline').ignore() - c.find('GetTopOutline').ignore() - c.find('GetBottomOutline').ignore() - - c.find('GetSize').ignore() - c.find('GetMinSize').ignore() - c.find('GetMaxSize').ignore() - c.find('GetWidth').ignore() - c.find('GetHeight').ignore() + tools.ignoreConstOverloads(c) #------------------------------------------------------- c = module.find('wxRichTextAttr') - c.find('GetTextBoxAttr').ignore() + tools.ignoreConstOverloads(c) #------------------------------------------------------- c = module.find('wxRichTextProperties') - c.find('operator[]').ignore() - c.find('GetProperties').ignore() + tools.ignoreConstOverloads(c) c.find('SetProperty').findOverload('bool').ignore() #------------------------------------------------------- c = module.find('wxRichTextSelection') - c.find('GetRanges').ignore() + tools.ignoreConstOverloads(c) #------------------------------------------------------- c = module.find('wxRichTextObject') #c.find('ImportFromXML').ignore() - c.find('GetRange').ignore() - c.find('GetOwnRange').ignore() - c.find('GetAttributes').ignore() - c.find('GetProperties').ignore() + tools.ignoreConstOverloads(c) #------------------------------------------------------- c = module.find('wxRichTextCompositeObject') - c.find('GetChildren').ignore() + tools.ignoreConstOverloads(c) #------------------------------------------------------- c = module.find('wxRichTextLine') - c.find('GetRange').ignore() + tools.ignoreConstOverloads(c) #------------------------------------------------------- @@ -236,7 +186,7 @@ def run(): #------------------------------------------------------- c = module.find('wxRichTextBuffer') - c.find('GetFontTable').ignore() + tools.ignoreConstOverloads(c) # More untyped wxLists module.addItem( @@ -257,12 +207,12 @@ def run(): #------------------------------------------------------- c = module.find('wxRichTextTable') - c.find('GetCells').ignore() + tools.ignoreConstOverloads(c) #------------------------------------------------------- c = module.find('wxRichTextObjectAddress') - c.find('GetAddress').ignore() + tools.ignoreConstOverloads(c) #------------------------------------------------------- @@ -277,7 +227,7 @@ def run(): #------------------------------------------------------- c = module.find('wxRichTextAction') - c.find('GetContainerAddress').ignore() + tools.ignoreConstOverloads(c) #------------------------------------------------------- diff --git a/etgtools/tweaker_tools.py b/etgtools/tweaker_tools.py index fc57f011..ae0f62ca 100644 --- a/etgtools/tweaker_tools.py +++ b/etgtools/tweaker_tools.py @@ -149,6 +149,36 @@ def ignoreAllOperators(node): if isinstance(item, extractors.MethodDef) and item.name.startswith('operator'): item.ignore() + +def ignoreConstOverloads(node): + """ + If a method is overloaded and one of them only differs by const-ness, + then ignore it. + """ + def _checkOverloads(item): + overloads = item.all() + for i in range(len(overloads)): + for j in range(len(overloads)): + if i == j: + continue + item1 = overloads[i] + item2 = overloads[j] + if item1.ignored or item2.ignored: + continue + if (item1.argsString.replace(' const', '').strip() == + item2.argsString.replace(' const', '').strip()): + if item1.isConst: + item1.ignore() + return + elif item2.isConst: + item2.ignore() + return + + for item in node.items: + if isinstance(item, extractors.MethodDef) and item.overloads: + _checkOverloads(item) + + def addAutoProperties(node): """