CompilerInstance and C++

Hi,

I try to parse c++ code, for now just very simple code like this:

class Testing {
public:
    Testing(){}
};



My Code is based on a CompilerInstance but I always get the following 

error: unknown type name 'class'

I tried to somehow set the LangOptions but still didn't get it to work...

My code is here [https://github.com/lukedirtwalker/Envision/blob/cppimport/CppImport/src/cppimportmanager.cpp](https://github.com/lukedirtwalker/Envision/blob/cppimport/CppImport/src/cppimportmanager.cpp) 

Thanks for any help :)


Using CompilerInstance is non-trivial. To make your life easier, there’s LibTooling:
http://clang.llvm.org/docs/LibTooling.html

If you want a more stable interface I’d suggest you also take a look at LibClang.

Cheers,
/Manuel

Okay I will look into this thank you.

Can you please tell me if I will be able to have control over all Preprocessor directives and over the full C++ AST using either Libclang or Libtooling?

The aim of my project is to import C++ code (including included files) into a Visual Environment.
Meaning i need to know in which file something was declared/defined is there a way to see this in just the AST?

I just have the fear that LibClang and LibTooling will not be enough for the whole task…?

I appreciate any comment/help on this.

Cheers,
Lukas

Okay I will look into this thank you.

Can you please tell me if I will be able to have control over all
Preprocessor directives and over the full C++ AST using either Libclang or
Libtooling?

See http://clang.llvm.org/docs/Tooling.html

With libclang you have less constrol than with libtooling, but libclang is
a higher abstraction and more stable interface.

The aim of my project is to import C++ code (including included files)
into a Visual Environment.
Meaning i need to know in which file something was declared/defined is
there a way to see this in just the AST?

Yes. I think both libclang and libtooling should be fine for this (although
I don't have a lot of experience with libclang).

I just have the fear that LibClang and LibTooling will not be enough for

Faced the same error, was quite surprised...

With libclang you have less control than with libtooling, but libclang is
a higher abstraction and more stable interface.

And is there any way to get current ASTContext and LangOptions inside the
tool?

Thank you,
Vadim

Faced the same error, was quite surprised...

> With libclang you have less control than with libtooling, but libclang is
> a higher abstraction and more stable interface.

And is there any way to get current ASTContext and LangOptions inside the
tool?

Yes: if you have a compilation database, the language options will be
provided by the clang arguments used there; otherwise you can specify the
options yourself. The idea is to use command line options, though.

Cheers,
/Manuel

the language options will be provided by the clang arguments used there;

Ok, I am more concerned here about having ASTContext. Grep'ing the Index.h
haven't gave me a clue on building CFG for code. I guess I will have to use
LibTooling as I want to walk CFG built for given code.

In this case, any advice?
Anyway, thanks in advance,
Vadim Brodskiy

> the language options will be provided by the clang arguments used there;

Ok, I am more concerned here about having ASTContext. Grep'ing the Index.h
haven't gave me a clue on building CFG for code. I guess I will have to use
LibTooling as I want to walk CFG built for given code.

I personally haven't implemented CFG walking from libtooling, but you
definitely have the ASTContext available if that's what you need...

Cheers,
/Manuel

Thank you Manuel for your responses!

you definitely have the ASTContext available if that's what you need...

I was trying to find origin of ASTContext in consumer to use it. By trial
and error I found in the error stack that tool is also using ParseAST to run
action

So now I'm a bit confused if I can use both ASTContext(from
HandleTranslationUnit) and DeclGroupRef(from HandleTopLevelDecl) with
Tool/ClangTool.
While using CompilerInstance I've done that through giving YAASTConsumer
link to the ASTContext that is used in CompilerInstance and just using
ParseAST.

Regards,
Vadim

I'm a bit confused if I can use both ASTContext and DeclGroupRef with

Tool/ClangTool

Actually works fine. Just get ASTContext for Decl