void ClangInternalState::printIncludedFiles(llvm::raw_ostream& Out, SourceManager& SM) { Out << "Legend: [p] parsed; [P] parsed and open; [r] from AST file\n\n"; for (clang::SourceManager::fileinfo_iterator I = SM.fileinfo_begin(), E = SM.fileinfo_end(); I != E; ++I) { const clang::FileEntry *FE = I->first; // Our error recovery purges the cache of the FileEntry, but keeps // the FileEntry's pointer so that if it was used by smb (like the // SourceManager) it wouldn't be dangling. In that case we shouldn't // print the FileName, because semantically it is not there. if (!I->second) continue; std::string fileName(FE->getName()); if (!(fileName.compare(0, 5, "/usr/") == 0 && fileName.find("/bits/") != std::string::npos) && fileName.compare("-")) { if (I->second->getRawBuffer()) { // There is content - a memory buffer or a file. // We know it's a file because we started off the FileEntry. if (FE->isOpen()) Out << "[P] "; else Out << "[p] "; } else Out << "[r] "; Out << fileName << '\n'; } } }
void ClangInternalState::printIncludedFiles(llvm::raw_ostream& Out, const SourceManager& SM) { // FileInfos are stored as a mapping, and invalidating the cache // can change iteration order. std::vector<std::string> ParsedOpen, Parsed, AST; for (clang::SourceManager::fileinfo_iterator I = SM.fileinfo_begin(), E = SM.fileinfo_end(); I != E; ++I) { const clang::FileEntry *FE = I->first; // Our error recovery purges the cache of the FileEntry, but keeps // the FileEntry's pointer so that if it was used by smb (like the // SourceManager) it wouldn't be dangling. In that case we shouldn't // print the FileName, because semantically it is not there. if (!I->second) continue; std::string fileName(FE->getName()); // We create a virtual file for each input line in the format input_line_N if (fileName.size() > 11 && fileName.find("input_line_") == 0 && std::find_if(fileName.begin() + 11, fileName.end(), [](char c) { return !std::isdigit(c); }) == fileName.end()) { continue; } if (!(fileName.compare(0, 5, "/usr/") == 0 && fileName.find("/bits/") != std::string::npos) && fileName.compare("-")) { if (I->second->getRawBuffer()) { // There is content - a memory buffer or a file. // We know it's a file because we started off the FileEntry. if (FE->isOpen()) ParsedOpen.emplace_back(std::move(fileName)); else Parsed.emplace_back(std::move(fileName)); } else AST.emplace_back(std::move(fileName)); } } auto DumpFiles = [&Out](const char* What, std::vector<std::string>& Files) { if (Files.empty()) return; Out << What << ":\n"; std::sort(Files.begin(), Files.end()); for (auto&& FileName : Files) Out << " " << FileName << '\n'; }; DumpFiles("Parsed and open", ParsedOpen); DumpFiles("Parsed", Parsed); DumpFiles("From AST file", AST); }
void ClangInternalState::printIncludedFiles(llvm::raw_ostream& Out, SourceManager& SM) { for (clang::SourceManager::fileinfo_iterator I = SM.fileinfo_begin(), E = SM.fileinfo_end(); I != E; ++I) { const clang::SrcMgr::ContentCache &C = *I->second; const clang::FileEntry *FE = C.OrigEntry; // Our error recovery purges the cache of the FileEntry, but keeps // the FileEntry's pointer so that if it was used by smb (like the // SourceManager) it wouldn't be dangling. In that case we shouldn't // print the FileName, because semantically it is not there. if (!FE->getSize() && !FE->getModificationTime()) continue; std::string fileName(FE->getName()); if (!(fileName.compare(0, 5, "/usr/") == 0 && fileName.find("/bits/") != std::string::npos)) { Out << fileName << '\n'; } } }