pygccxml package

Introduction

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.

What can you do with it?

Using pygccxml you can:

  • parse C++ source code
  • create a powerful code generator
    • Py++ is heavily based on pygccxml
    • generate WSDL file from sources
    • ...
  • generate UML diagrams
  • build code analyzer
  • ...

Features

Query interface

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

Type traits

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

Declaration dependencies

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.

Caching

Consider the following situation: you have to parse the same set of files every day. There are 2 possible ways to complete the task:

  • create a header file that includes all files you need to parse
  • parse each file separately and then join the results

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.

Binary files parser

pygccxml contains functionality which allows to extract different information from binary files ( .map, .dll, .so ) and integrate it with the existing declarations tree.

Test environment

pygccxml comes with comprehensive unit tests. They are executed on Windows XP and Ubuntu Linux operating systems. All in all, pygccxml has more than 230 tests. I am using Python 2.6 to run tests against.

Support for Python 2.4 was dropped.

Table Of Contents

Previous topic

pydsc introduction

Next topic

Download & Install

This Page

Table Of Contents

Previous topic

pydsc introduction

Next topic

Download & Install

This Page