Skip to content

Instantly share code, notes, and snippets.

@kwk
Last active March 28, 2017 20:56
Show Gist options
  • Select an option

  • Save kwk/9326647 to your computer and use it in GitHub Desktop.

Select an option

Save kwk/9326647 to your computer and use it in GitHub Desktop.
Get filename/path of clang::Decl
static const clang::FileEntry * getFileEntryForDecl(const clang::Decl * decl, clang::SourceManager * sourceManager)
{
if (!decl || !sourceManager) {
return 0;
}
clang::SourceLocation sLoc = decl->getLocation();
clang::FileID fileID = sourceManager->getFileID(sLoc);
return sourceManager->getFileEntryForID(fileID);
}
static const char * getFileNameForDecl(const clang::Decl * decl, clang::SourceManager * sourceManager)
{
const clang::FileEntry * fileEntry = getFileEntryForDecl(decl, sourceManager);
if (!fileEntry) {
return 0;
}
return fileEntry->getName();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment