After the extremely positive experiences I've had with clang and since the IDE tools I tried failed for our projectI'd like to utilize the clang infrastructure for this task. However, in the very beginning I already face the problem of where I should start:.
On the other hand libclang seems to be easier to use, has Python bindings, and from the outset looks like it could be already sufficient for the task at hand. Karl Eugen Huthmacher Geschaeftsfuehrung : Prof. Achim Bachem VorsitzenderKarsten Beneke stellv.
VorsitzenderProf. Harald Bolt, Prof. Sebastian M. Schmidt From your description I infer that clang-fixit is a tool for enforcing a certain naming convention, rather than changing specific names, or did I misunderstand you?
However, maybe it could be a place for me to start looking for ideas Could you tell me where I can find more information on it? I would guess clang-migrate would be the next best tool to look at.
It does various code changes and deals with reformatting the resulting code, etc. Tooling, specifically the clang-fixit till is one place sheet efforts are being made to apply these kinds of refractoriness specifically clang-fixit would apply predefined naming convention rules, rather than user specified renaming.
Clang Developers. Search everywhere only in this topic. Advanced Search. Classic List Threaded. Schlottke, Michael. LibTooling vs. Regards, Michael -- Michael Schlottke. David Blaikie.GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together. If nothing happens, download GitHub Desktop and try again. If nothing happens, download Xcode and try again. If nothing happens, download the GitHub extension for Visual Studio and try again.
For a high-level description of how it works, please check out our technical overview or our FAQ for some more details. We have a small website pyston. We have two mailing lists: pyston-dev for development-related discussions, and pyston-announce which is for wider announcements new releases, major project changes. We also have a gitter chat room where most discussion takes place. Pyston should be considered in alpha: it "works" in that it can successfully run Python code, but it is still quite far from being useful for end-users.
Currently, Pyston targets Python 2. Support for more platforms -- along with Python 3 compatibility -- is desired but deferred until we feel successful on our initial platform. Pyston does not currently work on Mac OSX, and it is not clear when it will. This means that the "pip" and "python" commands correspond to Pyston, so you can directly start doing pip install mypackage to get started.
As mentioned though, the docker images are experimental, so please give us feedback on gitter. You can also download the latest release from GitHub. It should for the most part just extract and run. One thing to note is that current virtualenv versions do not support Pyston, so you will need to use our version that we ship in the releases.
See our Dockerfile for how to do this. You can also build Pyston directly from source. If you have any issues, please feel free to file an issue in the issue tracker, or mention it via email or gitter. To install it yourself, one needs a modified Cython, as well as to install numpy from source in order to invoke our modified Cython.
We have some documentation for those interested in contributing: see our Development Guide and development tips. All pull requests are built and tested by travis-ci. See travis-ci. If you are interested in seeing how fast Pyston can go, you should try the release configuration, but there is a good chance that it will crash, in which case you can run the debug configuration to see what is happening. You can get a simple REPL by simply typing make run ; it is not very robust right now, and only supports single-line statements, but can give you an interactive view into how Pyston works.
To get more functionality, you can do. Skip to content. An open-source Python implementation using JIT techniques. View license. Dismiss Join GitHub today GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together. Sign up.LibTooling is a library to support writing standalone tools based on Clang. This document will provide a basic walkthrough of how to write a tool using LibTooling. Let me give you an example:. For a standalone tool to run clang, it first needs to figure out what command line arguments to use for a specified file.
To that end we create a CompilationDatabase. There are different ways to create a compilation database, and we need to support all of them depending on command-line options.
CompilationDatabase can be read from a build directory or the command line. Using CommonOptionsParser allows for explicit specification of a compile command line, specification of build path using the -p command-line option, and automatic location of the compilation database using source files paths. Now we combine the two previous steps into our first real tool.
As an alternative, you can also configure cmake to output a compile command database into its build directory:. Now you can run clang-check over files in the project by specifying the build path as first argument and some source files as further positional arguments:. Clang tools need their builtin headers and search for them the same way Clang does.
Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I have a header header. The required method is SourceManager's getFileLoc SourceLocation locwhich "returns the expansion location" if loc "is a macro location".
My code to get source location for both normal class definitions and definitions as macro expansions:. Learn more. Clang libtooling: determine macro expansion location Ask Question. Asked 4 years, 9 months ago. Active 4 years, 9 months ago. Viewed 1k times. Thanks in advance.
Top 10 Python Libraries You Must Know In 2020
Active Oldest Votes. Found solution. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Tales from documentation: Write for your clueless users. Podcast a conversation on diversity and representation.
Upcoming Events. Featured on Meta. Feedback post: New moderator reinstatement and appeal process revisions. The new moderator agreement is now live for moderators to accept across the…. Allow bountied questions to be closed by regular users.
Along with its parent project - the LLVM compiler backend, Clang starts to become a formidable alternative to gcc itself these days. There's a slight problem with that, however. Enter libclang. In fact, Apple's own Xcode development tools use Clang as a library under the hood for code completion, cross-referencing, and so on. The component through which Clang enables such usage is called libclang.
It's a C API  that the Clang team vows to keep relatively stable, allowing the user to examine parsed code at the level of an abstract syntax tree AST . This module relies on ctypes to load the dynamic libclang library and tries to wrap as much of libclang as possible with a Pythonic API. Unfortunately, the state of documentation for libclang and its Python bindings is dire. In addition, all I could find online is a presentation and a couple of outdated email messages from the Clang dev mailing list.
On the bright side, if you just skim the Index. For the Python bindings, there is absolutely no documentation as well, except the source plus a couple of examples that are distributed alongside it.
So I hope this article will be helpful! That arranged, you're ready to import clang. Let's start with a simple example. The following script uses the Python bindings of libclang to find all references to some type in a given file:. An "index" represents a set of translation units compiled and linked together.
We need some way of grouping several translation units if we want to reason across them. For example, we may want to find references to some type defined in a header file, in a set of other source files.
Next, we use Index 's parse method to parse a single translation unit from a file. Its comment says:. This is a powerful function - it can optionally accept the full set of flags normally passed to the command-line compiler. This TranslationUnit can be queried, for example the name of the translation unit is available in the spelling property:. Its most important property is, however, cursor. A cursor is a key abstraction in libclangit represents some node in the AST of a parsed translation unit.
The cursor unifies the different kinds of entities in a program under a single abstraction, providing a common set of operations, such as getting its location and children cursors.
I will use the terms cursor and node interchangeably from this point on. The Python bindings encapsulate the libclang cursor in the Cursor object. It has many attributes, the most interesting of which are:.Clang provides infrastructure to write tools that need syntactic and semantic information about a program. This document will give a short introduction of the different ways to write clang tools, and their pros and cons.CppCon 2018: Arvid Gerstmann “Building a C++ Reflection System in One Weekend Using Clang and LLVM”
LibClang is a stable high level C interface to clang. When in doubt LibClang is probably the interface you want to use. Consider the other interfaces only when you have a good reason not to use LibClang. Clang Plugins allow you to run additional actions on the AST as part of a compilation.
Canonical examples of when to use LibTooling:. Clang tools are a collection of specific developer tools built on top of the LibTooling infrastructure as part of the Clang project.
Canonical examples of when to use Clang Plugins: special lint-style warnings or errors for your project creating additional build artifacts from a single compile step Use Clang Plugins when you…: need your tool to rerun if any of the dependencies change want your tool to make or break a build need full control over the Clang AST Do not use Clang Plugins when you…: want to run tools outside of your build environment want full control on how Clang is set up, including mapping of in-memory virtual files need to run over a specific subset of files in your project which is not necessarily related to any changes which would trigger rebuilds.
Examples of tools we are building or planning as part of the Clang project: Syntax checking clang-check Automatic fixing of compile errors clang-fixit Automatic code formatting clang-format Migration tools for new features in new language standards Core refactoring tools.
Created using Sphinx 1.In order to work on the compiler, you need some basic knowledge of the abstract syntax tree AST. For further information, see the getting started guide. The second command will bring up a GUI for configuring Clang. Press 't' to turn on advanced mode.
As this is not going to be a core clang tool, it will live in the clang-tools-extra repository. With that done, Ninja will be able to compile our tool. A detailed explanation of why the different parts are needed can be found in the LibTooling documentation. You can compile our new tool by running ninja from the build directory. Try it! Note the two dashes after we specify the source file. Clang recently introduced the ASTMatcher library to provide a simple, powerful, and concise way to describe specific patterns in the AST.
For example, suppose you wanted to examine only binary operators. There is a matcher to do exactly that, conveniently named binaryOperator. Shockingly, it will match against addition expressions whose left hand side is exactly the literal 0. All matcher that are nouns describe entities in the AST and can be bound, so that they can be referred to whenever a match is found. To do so, simply call the method bind on these matchers, e. Okay, on to using matchers for real.
Next, we want to specify that a single variable is declared in the first portion of the loop, so we can extend the matcher to. The last step is giving the matcher a name and binding the ForStmt as we will want to do something with it:.
Once you have defined your matchers, you will need to add a little more scaffolding in order to run them. More code! Add the following to LoopConvert. Now, you should be able to recompile and run the code to discover for loops. Create a new file with a few examples, and test out our new handiwork:. Our simple matcher is capable of discovering for loops, but we would still need to filter out many more ourselves. We can do a good portion of the remaining work with some cleverly chosen matchers, but first we need to decide exactly which properties we want to allow.
How can we characterize for loops over arrays which would be eligible for translation to range-based syntax? Range based loops over arrays of size N that:. The matcher for 2 is straightforward: require a pre- or post-increment of the same variable declared in the init portion.
Unfortunately, such a matcher is impossible to write. Matchers contain no logic for comparing two arbitrary AST nodes and determining whether or not they are equal, so the best we can do is matching more than we would like to allow, and punting extra comparisons to the callback.
Subscribe to RSS
In any case, we can start building this sub-matcher. We can require that the increment step be a unary increment like this:. To find a unaryOperator that refers to a specific declaration, we can simply add a second condition to it:. Furthermore, we can restrict our matcher to only match if the incremented variable is an integer:.
And the last step will be to attach an identifier to this variable, so that we can retrieve it in the callback:.