#include// ... void Example::processTranslationUnit(clang::ASTUnit *unit) { clang::SourceManager &sourceManager = unit->getSourceManager(); // Use the source manager to retrieve information about the translation unit. }
#includeIn this example, we are using the getSourceManager method to retrieve a reference to the source manager associated with the context of an AST. We then use the source manager to retrieve the file ID associated with the starting location of a statement node in the AST. The file ID can then be used to retrieve information about the source file, such as its contents and its location on disk. Package/Library: Clang C++ library// ... void Example::processASTNode(clang::ASTContext &context, clang::Stmt *node) { clang::SourceManager &sourceManager = context.getSourceManager(); clang::SourceLocation startLocation = node->getLocStart(); clang::FileID fileID = sourceManager.getFileID(startLocation); // Use the filID to retrieve information about the source file. }