void RewriterASTConsumer::InclusionDirective(clang::SourceLocation HashLoc, const clang::Token& IncludeTok, clang::StringRef FileName, bool IsAngled, clang::CharSourceRange FilenameRange, const clang::FileEntry* File, clang::StringRef SearchPath, clang::StringRef RelativePath, const clang::Module* Imported) { if ("ParallelForEach.h" == FileName) { SourceManager& SM = TheGpuRewriter.getSourceMgr(); SourceRange Range; Range.setBegin(HashLoc); Range.setEnd(SM.getSpellingLoc(FilenameRange.getEnd())); TheGpuRewriter.RemoveText(Range); } }
void PreprocessorCallback::InclusionDirective(clang::SourceLocation HashLoc, const clang::Token& IncludeTok, llvm::StringRef FileName, bool IsAngled, clang::CharSourceRange FilenameRange, const clang::FileEntry* File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const clang::Module* Imported) { if (!HashLoc.isValid() || !HashLoc.isFileID() || !File) return; clang::SourceManager &sm = annotator.getSourceMgr(); clang::FileID FID = sm.getFileID(HashLoc); if (!annotator.shouldProcess(FID)) return; std::string link = annotator.pathTo(FID, File); if (link.empty()) return; auto B = sm.getFileOffset(FilenameRange.getBegin()); auto E = sm.getFileOffset(FilenameRange.getEnd()); annotator.generator(FID).addTag("a", "href=\"" % link % "\"", B, E-B); }
// Get the raw source string of the range. llvm::StringRef PPCallbacksTracker::getSourceString(clang::CharSourceRange Range) { const char *B = PP.getSourceManager().getCharacterData(Range.getBegin()); const char *E = PP.getSourceManager().getCharacterData(Range.getEnd()); return llvm::StringRef(B, E - B); }