]>
git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/scripts/doxymlparser.py
a880524fc834ce420d3886d8f94c93227bcee482
4 Licence: wxWindows licence
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
28 from xml
.dom
import minidom
30 class ClassDefinition
:
33 self
.constructors
= []
36 self
.brief_description
= ""
37 self
.detailed_description
= ""
52 """ % (self
.name
, string
.join(self
.bases
, ", "), self
.includes
, self
.brief_description
, self
.detailed_description
)
53 str_repr
+= "Methods:\n"
55 for method
in self
.methods
:
56 str_repr
+= str(method
)
60 class MethodDefinition
:
67 self
.brief_description
= ""
68 self
.detailed_description
= ""
81 """ % (self
.name
, self
.return_type
, self
.params
, self
.definition
+ self
.argsstring
, self
.brief_description
, self
.detailed_description
)
84 def getTextValue(node
, recursive
=False):
86 for child
in node
.childNodes
:
87 if child
.nodeType
== child
.ELEMENT_NODE
and child
.nodeName
== "ref":
88 text
+= getTextValue(child
)
89 if child
.nodeType
== child
.TEXT_NODE
:
90 # Add a space to ensure we have a space between qualifiers and parameter names
91 text
+= child
.nodeValue
.strip() + " "
95 def doxyMLToText(node
):
99 def __init__(self
, verbose
= False):
101 self
.verbose
= verbose
103 def find_class(self
, name
):
104 for aclass
in self
.classes
:
105 if aclass
.name
== name
:
110 def get_enums_and_functions(self
, filename
, aclass
):
111 file_path
= os
.path
.dirname(filename
)
112 enum_filename
= os
.path
.join(file_path
, aclass
.name
[2:] + "_8h.xml")
113 if os
.path
.exists(enum_filename
):
114 root
= minidom
.parse(enum_filename
).documentElement
115 for method
in root
.getElementsByTagName("memberdef"):
116 if method
.getAttribute("kind") == "enum":
117 self
.parse_enum(aclass
, method
, root
)
119 def is_derived_from_base(self
, aclass
, abase
):
120 base
= get_first_value(aclass
.bases
)
121 while base
and base
!= "":
126 parentclass
= self
.find_class(base
)
129 base
= get_first_value(parentclass
.bases
)
135 def parse(self
, filename
):
136 self
.xmldoc
= minidom
.parse(filename
).documentElement
137 for node
in self
.xmldoc
.getElementsByTagName("compounddef"):
138 new_class
= self
.parse_class(node
)
139 self
.classes
.append(new_class
)
140 self
.get_enums_and_functions(filename
, new_class
)
142 def parse_class(self
, class_node
):
143 new_class
= ClassDefinition()
144 new_class
.name
= getTextValue(class_node
.getElementsByTagName("compoundname")[0])
145 for node
in class_node
.childNodes
:
146 if node
.nodeName
== "basecompoundref":
147 new_class
.bases
.append(getTextValue(node
))
148 elif node
.nodeName
== "briefdescription":
149 # let the post-processor determ
150 new_class
.brief_description
= node
.toxml()
151 elif node
.nodeName
== "detaileddescription":
152 new_class
.detailed_description
= node
.toxml()
153 elif node
.nodeName
== "includes":
154 new_class
.includes
.append(getTextValue(node
))
156 self
.parse_methods(new_class
, class_node
)
160 def parse_enum(self
, new_class
, enum
, root
):
164 for node
in enum
.childNodes
:
165 if node
.nodeName
== "name":
166 enum_name
= getTextValue(node
)
167 elif node
.nodeName
== "enumvalue":
168 enum_values
.append(getTextValue(node
.getElementsByTagName("name")[0]))
170 new_class
.enums
[enum_name
] = enum_values
172 def parse_methods(self
, new_class
, root
):
173 for method
in root
.getElementsByTagName("memberdef"):
174 new_method
= MethodDefinition()
175 for node
in method
.childNodes
:
176 if node
.nodeName
== "name":
177 new_method
.name
= getTextValue(node
)
178 elif node
.nodeName
== "type":
179 new_method
.return_type
= getTextValue(node
)
180 elif node
.nodeName
== "definition":
181 new_method
.definition
= getTextValue(node
)
182 elif node
.nodeName
== "argsstring":
183 new_method
.argsstring
= getTextValue(node
)
184 elif node
.nodeName
== "param":
186 for child
in node
.childNodes
:
187 if child
.nodeType
== child
.ELEMENT_NODE
:
188 param
[child
.nodeName
] = getTextValue(child
)
189 new_method
.params
.append(param
)
192 print "Adding %s" % (new_method
.name
+ new_method
.argsstring
)
194 if new_method
.name
== new_class
.name
:
195 new_class
.constructors
.append(new_method
)
196 elif new_method
.name
== "~" + new_class
.name
:
197 new_class
.destructors
.append(new_method
)
199 new_class
.methods
.append(new_method
)
201 if __name__
== "__main__":
203 "report" : (False, "Print out the classes and methods found by this script."),
204 "verbose" : (False, "Provide status updates and other information."),
207 parser
= optparse
.OptionParser(usage
="usage: %prog [options] <doxyml files to parse>\n" + __description__
, version
="%prog 1.0")
209 for opt
in option_dict
:
210 default
= option_dict
[opt
][0]
213 if type(default
) == types
.BooleanType
:
214 action
= "store_true"
215 parser
.add_option("--" + opt
, default
=default
, action
=action
, dest
=opt
, help=option_dict
[opt
][1])
217 options
, arguments
= parser
.parse_args()
219 if len(arguments
) < 1:
223 doxyparse
= DoxyMLParser(verbose
= options
.verbose
)
224 for arg
in arguments
:
228 for aclass
in doxyparse
.classes
: