| 223 | } |
| 224 | |
| 225 | void CoverageIndex::WriteLCOV(absl::string_view path) { |
| 226 | std::ofstream file(std::string(path).c_str()); |
| 227 | if (!file.is_open()) { |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | // Maps instrumented line numbers to whether they are covered. |
| 232 | std::map<int, bool> lines; |
| 233 | const auto& positions = checked_expr_.source_info().positions(); |
| 234 | for (const auto& [node_id, stats] : node_coverage_stats_) { |
| 235 | auto it = positions.find(node_id); |
| 236 | if (it == positions.end()) continue; |
| 237 | int line_num = GetLineNumber(checked_expr_.source_info(), it->second); |
| 238 | bool& covered = lines[line_num]; |
| 239 | covered = covered || stats.covered; |
| 240 | } |
| 241 | |
| 242 | file << "SF:" << checked_expr_.source_info().location() << "\n"; |
| 243 | for (auto& [line_num, covered] : lines) { |
| 244 | file << "DA:" << line_num << "," << (covered ? 1 : 0) << "\n"; |
| 245 | } |
| 246 | file << "end_of_record\n"; |
| 247 | } |
| 248 | |
| 249 | InstrumentationFactory InstrumentationFactoryForCoverage( |
| 250 | CoverageIndex& coverage_index) { |