[Haskell-cafe] [ANN] clang-pure-0.1.0.0: Pure C++ code analysis
chpatrick at gmail.com
Tue Dec 1 12:03:12 UTC 2015
I've been working on a pure binding to libclang that lets you easily
analyze any code that the Clang compiler understands.
libclang documentation: http://clang.llvm.org/doxygen/group__CINDEX.html
A short example that prints out the type of every function in a header file
(very useful for binding generation):
main = do
idx <- createIndex
tu <- parseTranslationUnit idx "foo.h" 
root = translationUnitCursor tu
. filtered (\c -> cursorKind c == FunctionDecl)
. folding (\c -> fmap (\t -> ( cursorSpelling c, typeSpelling
t )) (cursorType c))
for_ funDecs $ \(f, t) -> putStrLn $ BS.unpack f ++ " :: " ++ BS.unpack t
Or to find the number of gotos:
gotoCount = lengthOf (cosmosOf cursorChildrenF . filtered (\c -> cursorKind
c == GotoStmt)) root
(This uses lens, but the library itself only has one optional
Please refer to libclang's good documentation for an explanation of the
functions. The only thing to keep in mind is that functions clang_foo are
renamed to just foo, functions clang_getBar are renamed to just bar, and
types CXBaz are renamed to just Baz in the Haskell bindings.
Under the hood, a reference counting system ensures that the C objects are
the right time and in the right order, which allows the public API to be
simple and pure.
The bindings are not yet complete, so if you find something missing please
make an issue or better yet send a pull request. :)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe