Skip to main content

Functional tools for matching nodes in the clang AST

Project description

Overview

Glud is an abstraction on the libclang library that make matching fragments of the Clang AST simple and Pythonic, in the same way that libclangastmatchers does for the C++ Clang API.

MIT License Continuous Integration Coverage Testing Results

Examples

On the code snippet

// input.cpp
namespace X {
    class Y {};
}
class Y {};

You could match a class named X in the namespace Y with the matcher:

from glud import *
m = cxxRecordDecl(
         hasName('Y'),
         hasAncestor(namespaceDecl(hasName('X'))))
tu = parse('input.cpp')
matches = walk(m, tu.cursor)

Prerequisites

Install a recent version of Clang and the python libclang bindings. On Ubuntu Trusty, you can install pre-built binaries from the LLVM apt repositories:

wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.8 main" | sudo tee -a /etc/apt/sources.list
sudo apt-get update -qq
sudo apt-get install -y python-clang-3.8 libclang1-3.8

To run glud, you’ll need to make sure that libclang.so is on your loader path.

export LD_LIBRARY_PATH=/usr/lib/llvm-3.8/lib

Installing

You can install the latest stable version from PyPI

$ pip install glud

Or, you can install the latest development version from GitHub

$ pip install git+git://github.com/AndrewWalker/glud.git

Acknowledgements

This project is in no way affiliated with the LLVM Team or the University of Illinois at Urbana-Champaign.

Contributing

If you experience problems with glud, log them on GitHub. If you want to contribute code, please fork the code and submit a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glud-0.3.3.tar.gz (8.0 kB view details)

Uploaded Source

File details

Details for the file glud-0.3.3.tar.gz.

File metadata

  • Download URL: glud-0.3.3.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for glud-0.3.3.tar.gz
Algorithm Hash digest
SHA256 7e6a7ab7a328d2c90c7b87ad5076b44df7affd38ca2a6667a5cf7f89b22c7915
MD5 69050dd7b6209f0c3b2d34581a1b7a3d
BLAKE2b-256 27903d98276c41c0f8101ecab2c514b8b2ff5234bb0e639bf2d0d8f13534fb01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page