The purpose of the GCC-XML extension is to generate an XML description of a C++ program from GCC’s internal representation.
– Introduction to GCC-XML
The purpose of pygccxml is to read a generated file and provide a simple framework to navigate C++ declarations, using Python classes.
Using pygccxml you can:
pygccxml provides simple and powerful API to query declarations tree.
How many lines is needed to write the following query?
select all free functions from the project
where
name equal to "do_smth"
return type is void
function has two arguments
second argument type is int
Only single line of code is needed:
#global_ns is the reference to declarations, which describes global( :: ) namespace
global_ns.free_functions( "do_smth", return_type='void', arg_types=[None,'int'] )
None means “any type”. In my opinion, the code is pretty clear and readable.
If you want to know more about provided API read query interface document or API documentation
pygccxml provides a lot of functionality to analyze C++ types and relationship between them. For more information please refer to design document or API documentation. Just a few names of algorithms:
is_convertible( from, to )
returns True if there is a conversion from type from to type to, otherwise False
is_unary_operator( oper )
returns True if oper describes unary operator
You can query a declaration, about it dependencies - declarations it depends on. This is very powerful and useful feature. Py++, for example, uses this functionality to check that user creates Python bindings for all relevant declarations.
Consider the following situation: you have to parse the same set of files every day. There are 2 possible ways to complete the task:
The difference between these approaches is the caching algorithm used in the second case. pygccxml supports both of them. Actually pygccxml supports more caching strategies, read the API documentation for more information.
pygccxml contains functionality which allows to extract different information from binary files ( .map, .dll, .so ) and integrate it with the existing declarations tree.