Get a VarDecl Associated with a SourceLocation

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Get a VarDecl Associated with a SourceLocation

Richard Smith via cfe-dev
Hi,

Is it possible to get the VarDecl associated with a specific SourceLocation?
For example, VarDecl is "int a;". However, I have the SourceLocation for a. I want to get the SourceLocation that indicates the beginning (and end) of this VarDecl.

Best,
Pardis

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Get a VarDecl Associated with a SourceLocation

Richard Smith via cfe-dev
Hi Pardis,

You can use some of these as a basis for your feature.

1. Use libTooling - clang::tooling::getNamedDeclAt().
2. Use libclang (C interface) - clang_getCursor().
3. Use clangd via LSP - textDocument/SymbolInfo method.
4. Use clangd - clang::clangd::getSymbolInfo().
5. Take a look at implementation of these and write your own AST visitor.

Not knowing anything about your specific use-case I’d recommend to use libTooling.

Hope this helps!

Jan

On Jan 7, 2019, at 7:37 PM, Pardis Pashakhanloo via cfe-dev <[hidden email]> wrote:

Hi,

Is it possible to get the VarDecl associated with a specific SourceLocation?
For example, VarDecl is "int a;". However, I have the SourceLocation for a. I want to get the SourceLocation that indicates the beginning (and end) of this VarDecl.

Best,
Pardis
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev