[cfe-dev] libTooling Questions
Manuel Klimek
klimek at google.com
Wed Aug 15 13:25:49 PDT 2012
+cfe-dev :)
On Wed, Aug 15, 2012 at 10:25 PM, Manuel Klimek <klimek at google.com> wrote:
> On Sun, Aug 12, 2012 at 10:38 PM, Jens Weller <JensWeller at gmx.de> wrote:
>>
>>> On Sun, Aug 12, 2012 at 5:54 PM, Jens Weller <JensWeller at gmx.de> wrote:
>>> > 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.
>
> When you overwrite the various Traverse* methods of the RAV, you have
> full control over the traversal, and you can thus build up the full
> tree of declarations.
>
> You can get the fully qualified name or just the unqualified names
> from the various AST nodes, depending on which methods you call. For
> example, you can call getQualifiedNameAsString() to get the fully
> qualified name of any NamedDecl (which CXXMethodDecls are).
>
>>
>> regards,
>>
>> Jens Weller
More information about the cfe-dev
mailing list