1

The libclang C API has the following function for this purpose:

CXSourceLocation clang_getLocation( CXTranslationUnit tu, CXFile file, unsigned line, unsigned column )

I can't find an equivalent for the C++ API. There are many getLocation functions but none that take this set of arguments.

I am ultimately trying to get the DeclRef at a given source location, if it exists.

user2664470
  • 781
  • 1
  • 7
  • 17

1 Answers1

2

Finding a SourceLocation for a file:line:column triplet can be done somewhat awkwardly through the SourceManager as follows:

SourceManager& srcmgr = astctx.getSourceManager();
FileManager& filemgr = srcmgr.getFileManager();
const FileEntry* file_entry_ptr = filemgr.getFile(filename);
SourceLocation loc = srcmgr.translateFileLineCol(file_entry_ptr, line, column);

I still do not know how to find the Stmt at that point though.

user2664470
  • 781
  • 1
  • 7
  • 17