[cfe-dev] Accessing some particular source locations in the AST
Richard Smith
richard at metafoo.co.uk
Wed Sep 17 18:56:47 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>*:
>
Lexer::getLocForEndOfToken(RD->getLocation(), 0, /*...*/)
> public Bar *<AND HERE>*{
>
Do you want the location of the open brace, or the location after each base
specifier? For the base specifiers, iterate over RD->bases() and grab the
source range. (Use getLocForEndOfToken on the end of the range.) We don't
directly store the location of the left brace, but you can get an
approximation of the right thing by scanning forwards through the input
buffer looking for it (you can be defeated by macros, but that's hard to
avoid without re-lexing).
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
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140917/95c64fcb/attachment.html>
More information about the cfe-dev
mailing list