In common IDEs (pick one) you often have an outline view showing you the list of methods for a specific class.
Suppose I have a C++ interface class in IFoo.h
that looks like this:
#ifndef IFOO_H_
#define IFOO_H_
class IFoo {
public:
virtual ~IFoo() {}
virtual void bar() = 0;
};
#endif
How (programmatically) can I get such an IDE outliner list for my IFoo.h
file above using maybe the clang libraries? For a first start, it would help if I can get a list of names of functions.
I specifically intend to use clang, so any help on how to analyze the my header file with clang would be really appreciated.
Meanwhile I will have a look at the clang tutorial here: https://github.com/loarabia/Clang-tutorial
Thanks in advance for your help.
I went through this tutorial http://clang.llvm.org/docs/LibASTMatchersTutorial.html and found some pretty helpful stuff there, this is what I came up with:
I had to rename my file fromIFoo.h
toIFoo.hpp
to be detected as Cxx and not C code.I had to call my program with
-x c++
to have myIFoo.h
file being recognized as C++ code rather than C code (clang interprets*.h
files as C by default:This is my code to dump all virtual functions from the provided class:
The output looks like this, when passed the
IFoo.h
file: