[cfe-dev] Accessing some particular source locations in the AST

Eli Bendersky eliben at google.com
Wed Sep 17 16:13:23 PDT 2014


On Wed, Sep 17, 2014 at 3:55 PM, Mihai Draghicioiu <
mihai.draghicioiu at gmail.com> wrote:

> Hi guys. I'm trying to get a SourceLocation for a couple of points in the
> source. So for:
>
> class Foo*<HERE>*: public Bar *<AND HERE>*{
>
> Starting from a CXXRecordDecl (which I get from
> RecursiveASTVisitor::VisitCXXRecordDecl()), currently I am only able to get
> the location before the *class* keyword (with
> TagDecl::getInnerLocStart()) and after it (TagDecl::getOuterLocStart()).
>
> I've been struggling with this for a while now, and the documentation
> really isn't helping. There are many missing enums and member functions in
> the docs. Am I supposed to use the lexer somehow? How? Am I supposed to use
> VisitTypeLoc()? I dunno, help!
>
> This is for a source translation tool that translates a small subset of
> C++ to JS. So:
>
> class Foo: public Bar {
>     Foo(int x, float y) {
>
> Becomes:
>
> function Foo(x, y) {
> ...
> }
> // Do some inheritance stuff for Bar
>

Why do you need those particular source locations to perform this task,
though? Sounds like all you need is find the class name, its base(s) and
constructor(s) - all that is readily available in the AST.

Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140917/ab3c8c43/attachment.html>


More information about the cfe-dev mailing list