]>
git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/doxymlparser.py
ab6bcd27228f0e621e015743c1d0d92096d8d33c
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 class ClassDefinition
:
48 self
.constructors
= []
51 self
.brief_description
= ""
52 self
.detailed_description
= ""
67 """ % (self
.name
, string
.join(self
.bases
, ", "), self
.includes
, self
.brief_description
, self
.detailed_description
)
68 str_repr
+= "Methods:\n"
70 for method
in self
.methods
:
71 str_repr
+= str(method
)
75 class MethodDefinition
:
82 self
.brief_description
= ""
83 self
.detailed_description
= ""
96 """ % (self
.name
, self
.return_type
, self
.params
, self
.definition
+ self
.argsstring
, self
.brief_description
, self
.detailed_description
)
99 def getTextValue(node
, recursive
=False):
101 for child
in node
.childNodes
:
102 if child
.nodeType
== child
.ELEMENT_NODE
and child
.nodeName
== "ref":
103 text
+= getTextValue(child
)
104 if child
.nodeType
== child
.TEXT_NODE
:
105 # Add a space to ensure we have a space between qualifiers and parameter names
106 text
+= child
.nodeValue
.strip() + " "
110 def doxyMLToText(node
):
117 def parse(self
, filename
):
118 self
.xmldoc
= minidom
.parse(filename
).documentElement
119 for node
in self
.xmldoc
.getElementsByTagName("compounddef"):
120 new_class
= self
.parse_class(node
)
121 self
.classes
.append(new_class
)
122 self
.get_enums_and_functions(filename
, new_class
)
124 def parse_class(self
, class_node
):
125 new_class
= ClassDefinition()
126 new_class
.name
= getTextValue(class_node
.getElementsByTagName("compoundname")[0])
127 for node
in class_node
.childNodes
:
128 if node
.nodeName
== "basecompoundref":
129 new_class
.bases
.append(getTextValue(node
))
130 elif node
.nodeName
== "briefdescription":
131 # let the post-processor determ
132 new_class
.brief_description
= node
.toxml()
133 elif node
.nodeName
== "detaileddescription":
134 new_class
.detailed_description
= node
.toxml()
135 elif node
.nodeName
== "includes":
136 new_class
.includes
.append(getTextValue(node
))
138 self
.parse_methods(new_class
, class_node
)
142 def get_enums_and_functions(self
, filename
, aclass
):
143 file_path
= os
.path
.dirname(filename
)
144 enum_filename
= os
.path
.join(file_path
, aclass
.name
[2:] + "_8h.xml")
145 if os
.path
.exists(enum_filename
):
146 root
= minidom
.parse(enum_filename
).documentElement
147 for method
in root
.getElementsByTagName("memberdef"):
148 if method
.getAttribute("kind") == "enum":
149 self
.parse_enum(aclass
, method
, root
)
151 def parse_enum(self
, new_class
, enum
, root
):
155 for node
in enum
.childNodes
:
156 if node
.nodeName
== "name":
157 enum_name
= getTextValue(node
)
158 elif node
.nodeName
== "enumvalue":
159 enum_values
.append(getTextValue(node
.getElementsByTagName("name")[0]))
161 new_class
.enums
[enum_name
] = enum_values
163 def parse_methods(self
, new_class
, root
):
164 for method
in root
.getElementsByTagName("memberdef"):
165 new_method
= MethodDefinition()
166 for node
in method
.childNodes
:
167 if node
.nodeName
== "name":
168 new_method
.name
= getTextValue(node
)
169 elif node
.nodeName
== "type":
170 new_method
.return_type
= getTextValue(node
)
171 elif node
.nodeName
== "definition":
172 new_method
.definition
= getTextValue(node
)
173 elif node
.nodeName
== "argsstring":
174 new_method
.argsstring
= getTextValue(node
)
175 elif node
.nodeName
== "param":
177 for child
in node
.childNodes
:
178 if child
.nodeType
== child
.ELEMENT_NODE
:
179 param
[child
.nodeName
] = getTextValue(child
)
180 new_method
.params
.append(param
)
183 print "Adding %s" % (new_method
.name
+ new_method
.argsstring
)
185 if new_method
.name
== new_class
.name
:
186 new_class
.constructors
.append(new_method
)
187 elif new_method
.name
== "~" + new_class
.name
:
188 new_class
.destructors
.append(new_method
)
190 new_class
.methods
.append(new_method
)
192 if __name__
== "__main__":
193 if len(arguments
) < 1:
197 doxyparse
= DoxyMLParser()
198 for arg
in arguments
:
202 for aclass
in doxyparse
.classes
: