Giter VIP home page Giter VIP logo

clanalyze's Introduction

Clanalyze

Clanalyze is a C language analyzer. The goal of Clanalyze is to provide a framework by which people can easily consume parsed C language files, including C, C++, and Objective-C.

Using Clanalyze, it is possible to easily write tools that:

  • Check C/C++ style conventions
  • Perform compiler-like warnings
  • Build documentation from C/C++ source files
  • Perform static analysis

Clanalyze is built on top of Clang, the C language compiler that is part of the LLVM project. Clanalyze supplements the low-level Python bindings provided by Clang with higher-level, easier-to-consume APIs for tool writers.

Clanalyze was originally authored by Gregory Szorc <[email protected]>.

Requirements

Clanalyze requires Clang and the Clang Python bindings.

As part of developing Clanalyze, the author of Clanalyze needed to add functionality to the Clang Python bindings. The state of those changes is as follows:

  • Support for C++ access specifiers - Patch not yet submitted.
  • Support for token access - Patch not yet submitted.

Until all the above changes are merged into Clang's source tree and released, you probably don't have them available on your machine. Fortunately, the Clang Python bindings are located in a self-contained .py file. So, all you need to do is fetch an updated copy of that file and make it available in your PYTHONPATH.

The author of Clanalyze maintains a branch with all pending Clang Python binding changes at https://github.com/indygreg/clang/tree/python_features. The Python file you want can be downloaded directly from:

https://raw.github.com/indygreg/clang/python_features/bindings/python/clang/cindex.py

Technical Overview

Clanalyze provides a basic observer framework for entities (i.e. Python classes) wishing to react to events/entities in parsed C-family source code.

The general usage looks something like the following:

# Create a clanalyze.parser.Parser() instance # Register observers with the parser # Parse source code using Parser.parse() # (Observers get called for observed events, perform side-effects) # Profit

Writing Observers

To do something useful with Clanalyze, you'll want to write an observer. Writing an observer is as simple as creating a Python class that uses one of the built-in abstract observer base classes as its parent.

You have the following choices for observers:

  • DefinitionObserver - Consumes high-level entity definitions, such as classes, structs, and functions which are derived from the AST. Basically, Clanalyze takes the low-level AST cursor stream and converts it into friendly Python objects. This is a real value-add of Clanalyze, as it saves you from having to reimplement low-level logic interacting with the Clang parser.
  • CursorObserver - Consumes raw Clang AST cursor stream. This is very low-level and very close to the Clang API. If you are using this API, Clanalyze doesn't really provide much incremental benefit over consuming the Python Clang API directly.

When writing observers, it is important to conform to the API they have provided. See the documentation in the base classes for details.

Licensing

Clanalyze is currently licensed under version 2.0 of the Mozilla Public License. The full license can be seen at https://www.mozilla.org/MPL/2.0/. If this license is not satisfactory, please contact the author for consideration on issuing a version with a different license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.