Separate out constructors / destructors, add support for enums and include files, and add a verbose option.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60366 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -27,6 +27,7 @@ from xml.dom import minidom
|
|||||||
|
|
||||||
option_dict = {
|
option_dict = {
|
||||||
"report" : (False, "Print out the classes and methods found by this script."),
|
"report" : (False, "Print out the classes and methods found by this script."),
|
||||||
|
"verbose" : (False, "Provide status updates and other information."),
|
||||||
}
|
}
|
||||||
|
|
||||||
parser = optparse.OptionParser(usage="usage: %prog [options] <doxyml files to parse>\n" + __description__, version="%prog 1.0")
|
parser = optparse.OptionParser(usage="usage: %prog [options] <doxyml files to parse>\n" + __description__, version="%prog 1.0")
|
||||||
@@ -44,11 +45,14 @@ options, arguments = parser.parse_args()
|
|||||||
class ClassDefinition:
|
class ClassDefinition:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = ""
|
self.name = ""
|
||||||
|
self.constructors = []
|
||||||
|
self.destructors = []
|
||||||
self.methods = []
|
self.methods = []
|
||||||
self.brief_description = ""
|
self.brief_description = ""
|
||||||
self.detailed_description = ""
|
self.detailed_description = ""
|
||||||
self.includes = []
|
self.includes = []
|
||||||
self.bases = []
|
self.bases = []
|
||||||
|
self.enums = {}
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
str_repr = """
|
str_repr = """
|
||||||
@@ -113,25 +117,49 @@ class DoxyMLParser:
|
|||||||
def parse(self, filename):
|
def parse(self, filename):
|
||||||
self.xmldoc = minidom.parse(filename).documentElement
|
self.xmldoc = minidom.parse(filename).documentElement
|
||||||
for node in self.xmldoc.getElementsByTagName("compounddef"):
|
for node in self.xmldoc.getElementsByTagName("compounddef"):
|
||||||
self.classes.append(self.parse_class(node))
|
new_class = self.parse_class(node)
|
||||||
|
self.classes.append(new_class)
|
||||||
|
self.get_enums_and_functions(filename, new_class)
|
||||||
|
|
||||||
def parse_class(self, class_node):
|
def parse_class(self, class_node):
|
||||||
new_class = ClassDefinition()
|
new_class = ClassDefinition()
|
||||||
|
new_class.name = getTextValue(class_node.getElementsByTagName("compoundname")[0])
|
||||||
for node in class_node.childNodes:
|
for node in class_node.childNodes:
|
||||||
if node.nodeName == "compoundname":
|
if node.nodeName == "basecompoundref":
|
||||||
new_class.name = getTextValue(node)
|
|
||||||
print "Parsing class %s" % new_class.name
|
|
||||||
elif node.nodeName == "basecompoundref":
|
|
||||||
new_class.bases.append(getTextValue(node))
|
new_class.bases.append(getTextValue(node))
|
||||||
elif node.nodeName == "briefdescription":
|
elif node.nodeName == "briefdescription":
|
||||||
# let the post-processor determ
|
# let the post-processor determ
|
||||||
new_class.brief_description = node.toxml()
|
new_class.brief_description = node.toxml()
|
||||||
elif node.nodeName == "detaileddescription":
|
elif node.nodeName == "detaileddescription":
|
||||||
new_class.detailed_description = node.toxml()
|
new_class.detailed_description = node.toxml()
|
||||||
|
elif node.nodeName == "includes":
|
||||||
|
new_class.includes.append(getTextValue(node))
|
||||||
|
|
||||||
self.parse_methods(new_class, class_node)
|
self.parse_methods(new_class, class_node)
|
||||||
|
|
||||||
return new_class
|
return new_class
|
||||||
|
|
||||||
|
def get_enums_and_functions(self, filename, aclass):
|
||||||
|
file_path = os.path.dirname(filename)
|
||||||
|
enum_filename = os.path.join(file_path, aclass.name[2:] + "_8h.xml")
|
||||||
|
if os.path.exists(enum_filename):
|
||||||
|
root = minidom.parse(enum_filename).documentElement
|
||||||
|
for method in root.getElementsByTagName("memberdef"):
|
||||||
|
if method.getAttribute("kind") == "enum":
|
||||||
|
self.parse_enum(aclass, method, root)
|
||||||
|
|
||||||
|
def parse_enum(self, new_class, enum, root):
|
||||||
|
enum_name = ""
|
||||||
|
enum_values = []
|
||||||
|
|
||||||
|
for node in enum.childNodes:
|
||||||
|
if node.nodeName == "name":
|
||||||
|
enum_name = getTextValue(node)
|
||||||
|
elif node.nodeName == "enumvalue":
|
||||||
|
enum_values.append(getTextValue(node.getElementsByTagName("name")[0]))
|
||||||
|
|
||||||
|
new_class.enums[enum_name] = enum_values
|
||||||
|
|
||||||
def parse_methods(self, new_class, root):
|
def parse_methods(self, new_class, root):
|
||||||
for method in root.getElementsByTagName("memberdef"):
|
for method in root.getElementsByTagName("memberdef"):
|
||||||
new_method = MethodDefinition()
|
new_method = MethodDefinition()
|
||||||
@@ -150,7 +178,15 @@ class DoxyMLParser:
|
|||||||
if child.nodeType == child.ELEMENT_NODE:
|
if child.nodeType == child.ELEMENT_NODE:
|
||||||
param[child.nodeName] = getTextValue(child)
|
param[child.nodeName] = getTextValue(child)
|
||||||
new_method.params.append(param)
|
new_method.params.append(param)
|
||||||
|
|
||||||
|
if options.verbose:
|
||||||
print "Adding %s" % (new_method.name + new_method.argsstring)
|
print "Adding %s" % (new_method.name + new_method.argsstring)
|
||||||
|
|
||||||
|
if new_method.name == new_class.name:
|
||||||
|
new_class.constructors.append(new_method)
|
||||||
|
elif new_method.name == "~" + new_class.name:
|
||||||
|
new_class.destructors.append(new_method)
|
||||||
|
else:
|
||||||
new_class.methods.append(new_method)
|
new_class.methods.append(new_method)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Reference in New Issue
Block a user