]>
git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/scripts/doxymlparser.py
4 License: wxWidgets License
8 Takes the output of Doxygen XML and parses it to retrieve metadata about the classes and methods.
10 To create the Doxygen XML files, from the wxWidgets/docs/doxygen directory, do:
14 To see the results from parsing a particular class, do:
16 python doxymlparser.py --report out/xml/classwx_<whatever>.xml
26 from xml
.dom
import minidom
29 "report" : (False, "Print out the classes and methods found by this script."),
30 "verbose" : (False, "Provide status updates and other information."),
33 parser
= optparse
.OptionParser(usage
="usage: %prog [options] <doxyml files to parse>\n" + __description__
, version
="%prog 1.0")
35 for opt
in option_dict
:
36 default
= option_dict
[opt
][0]
39 if type(default
) == types
.BooleanType
:
41 parser
.add_option("--" + opt
, default
=default
, action
=action
, dest
=opt
, help=option_dict
[opt
][1])
43 options
, arguments
= parser
.parse_args()
45 def get_first_value(alist
):
51 class ClassDefinition
:
54 self
.constructors
= []
57 self
.brief_description
= ""
58 self
.detailed_description
= ""
73 """ % (self
.name
, string
.join(self
.bases
, ", "), self
.includes
, self
.brief_description
, self
.detailed_description
)
74 str_repr
+= "Methods:\n"
76 for method
in self
.methods
:
77 str_repr
+= str(method
)
81 class MethodDefinition
:
88 self
.brief_description
= ""
89 self
.detailed_description
= ""
100 Detailed Description:
102 """ % (self
.name
, self
.return_type
, self
.params
, self
.definition
+ self
.argsstring
, self
.brief_description
, self
.detailed_description
)
105 def getTextValue(node
, recursive
=False):
107 for child
in node
.childNodes
:
108 if child
.nodeType
== child
.ELEMENT_NODE
and child
.nodeName
== "ref":
109 text
+= getTextValue(child
)
110 if child
.nodeType
== child
.TEXT_NODE
:
111 # Add a space to ensure we have a space between qualifiers and parameter names
112 text
+= child
.nodeValue
.strip() + " "
116 def doxyMLToText(node
):
123 def find_class(self
, name
):
124 for aclass
in self
.classes
:
125 if aclass
.name
== name
:
130 def get_enums_and_functions(self
, filename
, aclass
):
131 file_path
= os
.path
.dirname(filename
)
132 enum_filename
= os
.path
.join(file_path
, aclass
.name
[2:] + "_8h.xml")
133 if os
.path
.exists(enum_filename
):
134 root
= minidom
.parse(enum_filename
).documentElement
135 for method
in root
.getElementsByTagName("memberdef"):
136 if method
.getAttribute("kind") == "enum":
137 self
.parse_enum(aclass
, method
, root
)
139 def is_derived_from_base(self
, aclass
, abase
):
140 base
= get_first_value(aclass
.bases
)
141 while base
and base
!= "":
146 parentclass
= self
.find_class(base
)
149 base
= get_first_value(parentclass
.bases
)
155 def parse(self
, filename
):
156 self
.xmldoc
= minidom
.parse(filename
).documentElement
157 for node
in self
.xmldoc
.getElementsByTagName("compounddef"):
158 new_class
= self
.parse_class(node
)
159 self
.classes
.append(new_class
)
160 self
.get_enums_and_functions(filename
, new_class
)
162 def parse_class(self
, class_node
):
163 new_class
= ClassDefinition()
164 new_class
.name
= getTextValue(class_node
.getElementsByTagName("compoundname")[0])
165 for node
in class_node
.childNodes
:
166 if node
.nodeName
== "basecompoundref":
167 new_class
.bases
.append(getTextValue(node
))
168 elif node
.nodeName
== "briefdescription":
169 # let the post-processor determ
170 new_class
.brief_description
= node
.toxml()
171 elif node
.nodeName
== "detaileddescription":
172 new_class
.detailed_description
= node
.toxml()
173 elif node
.nodeName
== "includes":
174 new_class
.includes
.append(getTextValue(node
))
176 self
.parse_methods(new_class
, class_node
)
180 def parse_enum(self
, new_class
, enum
, root
):
184 for node
in enum
.childNodes
:
185 if node
.nodeName
== "name":
186 enum_name
= getTextValue(node
)
187 elif node
.nodeName
== "enumvalue":
188 enum_values
.append(getTextValue(node
.getElementsByTagName("name")[0]))
190 new_class
.enums
[enum_name
] = enum_values
192 def parse_methods(self
, new_class
, root
):
193 for method
in root
.getElementsByTagName("memberdef"):
194 new_method
= MethodDefinition()
195 for node
in method
.childNodes
:
196 if node
.nodeName
== "name":
197 new_method
.name
= getTextValue(node
)
198 elif node
.nodeName
== "type":
199 new_method
.return_type
= getTextValue(node
)
200 elif node
.nodeName
== "definition":
201 new_method
.definition
= getTextValue(node
)
202 elif node
.nodeName
== "argsstring":
203 new_method
.argsstring
= getTextValue(node
)
204 elif node
.nodeName
== "param":
206 for child
in node
.childNodes
:
207 if child
.nodeType
== child
.ELEMENT_NODE
:
208 param
[child
.nodeName
] = getTextValue(child
)
209 new_method
.params
.append(param
)
212 print "Adding %s" % (new_method
.name
+ new_method
.argsstring
)
214 if new_method
.name
== new_class
.name
:
215 new_class
.constructors
.append(new_method
)
216 elif new_method
.name
== "~" + new_class
.name
:
217 new_class
.destructors
.append(new_method
)
219 new_class
.methods
.append(new_method
)
221 if __name__
== "__main__":
222 if len(arguments
) < 1:
226 doxyparse
= DoxyMLParser()
227 for arg
in arguments
:
231 for aclass
in doxyparse
.classes
: