- StringRef AllLines = Buff->getBuffer();
-
- std::string CovFilename = Filename.str() + ".gcov";
- std::string ErrorInfo;
- raw_fd_ostream OS(CovFilename.c_str(), ErrorInfo);
- if (!ErrorInfo.empty())
- errs() << ErrorInfo << "\n";
-
- OS << " -: 0:Source:" << Filename << "\n";
- OS << " -: 0:Graph:" << GCNOFile << "\n";
- OS << " -: 0:Data:" << GCDAFile << "\n";
- OS << " -: 0:Runs:" << RunCount << "\n";
- OS << " -: 0:Programs:" << ProgramCount << "\n";
-
- const LineData &Line = I->second;
- for (uint32_t LineIndex = 0; !AllLines.empty(); ++LineIndex) {
+ S = I + 1;
+ }
+
+ if (S < I)
+ Result.append(S, I);
+ return Result.str();
+}
+
+std::string FileInfo::getCoveragePath(StringRef Filename,
+ StringRef MainFilename) {
+ if (Options.NoOutput)
+ // This is probably a bug in gcov, but when -n is specified, paths aren't
+ // mangled at all, and the -l and -p options are ignored. Here, we do the
+ // same.
+ return Filename;
+
+ std::string CoveragePath;
+ if (Options.LongFileNames && !Filename.equals(MainFilename))
+ CoveragePath =
+ mangleCoveragePath(MainFilename, Options.PreservePaths) + "##";
+ CoveragePath += mangleCoveragePath(Filename, Options.PreservePaths) + ".gcov";
+ return CoveragePath;
+}
+
+std::unique_ptr<raw_ostream>
+FileInfo::openCoveragePath(StringRef CoveragePath) {
+ if (Options.NoOutput)
+ return llvm::make_unique<raw_null_ostream>();
+
+ std::error_code EC;
+ auto OS = llvm::make_unique<raw_fd_ostream>(CoveragePath, EC,
+ sys::fs::F_Text);
+ if (EC) {
+ errs() << EC.message() << "\n";
+ return llvm::make_unique<raw_null_ostream>();
+ }
+ return std::move(OS);
+}
+
+/// print - Print source files with collected line count information.
+void FileInfo::print(raw_ostream &InfoOS, StringRef MainFilename,
+ StringRef GCNOFile, StringRef GCDAFile) {
+ for (const auto &LI : LineInfo) {
+ StringRef Filename = LI.first();
+ auto AllLines = LineConsumer(Filename);
+
+ std::string CoveragePath = getCoveragePath(Filename, MainFilename);
+ std::unique_ptr<raw_ostream> CovStream = openCoveragePath(CoveragePath);
+ raw_ostream &CovOS = *CovStream;
+
+ CovOS << " -: 0:Source:" << Filename << "\n";
+ CovOS << " -: 0:Graph:" << GCNOFile << "\n";
+ CovOS << " -: 0:Data:" << GCDAFile << "\n";
+ CovOS << " -: 0:Runs:" << RunCount << "\n";
+ CovOS << " -: 0:Programs:" << ProgramCount << "\n";
+
+ const LineData &Line = LI.second;
+ GCOVCoverage FileCoverage(Filename);
+ for (uint32_t LineIndex = 0; LineIndex < Line.LastLine || !AllLines.empty();
+ ++LineIndex) {