libTooling Questions

Hi Clang-devs,

just started to play around with libTooling, a few (C++ related) Questions...

As far as I understand, I can access the AST with LibTooling, retrieving f.e. all Function Names and beeing able to make changes to the ast.
This works over the Visitor and FrontendAction classes.

So, I understand how to implement tools which do transformations or rename things in the code, or generate statistics.

What I have yet not found, is kind of a Document Model for C++ files, which I'm actually looking for:
I'd like to be able to display the whole ast (or more precise, namespaces, classes, members of them), so I would need to have access to the ast nodes, instead of visiting selected ones.

Where to look for this, is libAst the right place?
http://clang.llvm.org/docs/InternalsManual.html#libast

As far as I understand, in LibTooling ASTContext provides information about the current location in the ast to the visitor.

So, where to start, if you need an document like interface for a C++ File in clang?

kind regards,

Jens Weller

Hi Clang-devs,

just started to play around with libTooling, a few (C++ related) Questions...

As far as I understand, I can access the AST with LibTooling, retrieving f.e. all Function Names and beeing able to make changes to the ast.
This works over the Visitor and FrontendAction classes.

So, I understand how to implement tools which do transformations or rename things in the code, or generate statistics.

What I have yet not found, is kind of a Document Model for C++ files, which I'm actually looking for:
I'd like to be able to display the whole ast (or more precise, namespaces, classes, members of them), so I would need to have access to the ast nodes, instead of visiting selected ones.

The AST visitor gives you that access. I'm not exactly sure what
you're looking for.

Where to look for this, is libAst the right place?
http://clang.llvm.org/docs/InternalsManual.html#libast

With high probability this is not what you're looking for ...

As far as I understand, in LibTooling ASTContext provides information about the current location in the ast to the visitor.

So, where to start, if you need an document like interface for a C++ File in clang?

Again, I'm not sure what you're asking. Can you tell me more about
what you're trying to do in the end?

Cheers,
/Manuel

> Hi Clang-devs,
>
> just started to play around with libTooling, a few (C++ related)
Questions...
>
> As far as I understand, I can access the AST with LibTooling, retrieving
f.e. all Function Names and beeing able to make changes to the ast.
> This works over the Visitor and FrontendAction classes.
>
> So, I understand how to implement tools which do transformations or
rename things in the code, or generate statistics.
>
> What I have yet not found, is kind of a Document Model for C++ files,
which I'm actually looking for:
> I'd like to be able to display the whole ast (or more precise,
namespaces, classes, members of them), so I would need to have access to the ast
nodes, instead of visiting selected ones.

The AST visitor gives you that access. I'm not exactly sure what
you're looking for.

I doubt that.
One of my goals is, to fill a treeview, for that case I need to know, what class a method belongs to.
Ofc. I can match both, and add methods to the last matched class type.
But what to do with a nested class then? I'd need to check with ASTContext the position with in the AST of the Method/function/class I guess, just want to know, if I'm looking at the right end of the clang APIs for doing something like that.

>
> Where to look for this, is libAst the right place?
> http://clang.llvm.org/docs/InternalsManual.html#libast

With high probability this is not what you're looking for ...

Well, yes, its very basic, there is probably already a better API Build on top of that for this purpose.

> As far as I understand, in LibTooling ASTContext provides information
about the current location in the ast to the visitor.
>
> So, where to start, if you need an document like interface for a C++
File in clang?

Again, I'm not sure what you're asking. Can you tell me more about
what you're trying to do in the end?

Referring to the example:
http://clang.llvm.org/docs/RAVFrontendAction.html

Lets say I add a nother visiting method, for methoddeclaration.
How to match in the invocation of the methodhandler, which class this one belongs to?
Do I get a fully qualified name (e.g. myclass::foo) or just foo.

regards,

Jens Weller

For the following code, only the second declaration of foo will have
the 'A::' NestedNameSpecifier.

class A {
  void foo();
};

void A::foo() {}

But you can still get the class using CXXMethodDecl::getParent().

+cfe-dev :slight_smile:

Referring to the example:
http://clang.llvm.org/docs/RAVFrontendAction.html

Lets say I add a nother visiting method, for methoddeclaration.
How to match in the invocation of the methodhandler, which class this one belongs to?
Do I get a fully qualified name (e.g. myclass::foo) or just foo.

For the following code, only the second declaration of foo will have
the 'A::' NestedNameSpecifier.

I'm not sure what you're referring to here...

Cheers,
/Manuel

I was referring to getQualifier(), but your other reply is a better
answer to the question.