Reputation: 537
I want to write a refactor tool, where I want to move the function at the cursor(cursor is in the function name) to the source file.
I found the FunctionMover.cc in https://github.com/lanl/CoARCT which is a good starting point to move the function. However, I cannot find anything how to get the symbol (i.e. in my case function) from a file:line:column (or file:offset) combination. I imagine this should be quite easy with the AST, SourceManager and libtooling of clang, but I cannot find anything about it.
Thanks for any help in advance!
Upvotes: 0
Views: 451
Reputation: 503
I would try LibTooling, clang::SourceManager has a member function translateFileLineCol():
SourceManager& SM = ctx.getSourceManager();
const FileEntry* FE = SM.getFileManager().getFile(filename);
SourceLocation loc = SM.translateFileLineCol(FE, line, column);
after obtaining the loc, you can maybe use SM.getCharacterData() or do other maneuvers.
This post has a very similar purpose, I believe. Seems like there is also a solution with libClang.
Upvotes: 1