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

Mihai Draghicioiu mihai.draghicioiu at gmail.com
Wed Sep 17 17:46:46 PDT 2014


I need those locations in order to retain comments and indentation by
simply doing a text replace instead of rebuilding the text.

On Thu, Sep 18, 2014 at 2:13 AM, Eli Bendersky <eliben at google.com> wrote:

>
>
> 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/20140918/490538aa/attachment.html>


More information about the cfe-dev mailing list