Esempio n. 1
0
void CodeCoverageTool::createExpansionSubView(
    const CountedRegion &ExpandedRegion,
    const FunctionCoverageMapping &Function, SourceCoverageView &Parent) {
  auto ExpandedLines = findExpandedFileInterestingLineRange(
      ExpandedRegion.ExpandedFileID, Function);
  if (ViewOpts.Debug)
    llvm::errs() << "Expansion of " << ExpandedRegion.ExpandedFileID << ":"
                 << ExpandedLines.first << " -> " << ExpandedLines.second
                 << " @ " << ExpandedRegion.FileID << ", "
                 << ExpandedRegion.LineStart << ":"
                 << ExpandedRegion.ColumnStart << "\n";
  auto SourceBuffer =
      getSourceFile(Function.Filenames[ExpandedRegion.ExpandedFileID]);
  if (!SourceBuffer)
    return;
  auto SubView = llvm::make_unique<SourceCoverageView>(SourceBuffer.get(),
                                                       Parent.getOptions());
  auto RegionManager = llvm::make_unique<SourceCoverageDataManager>();
  for (const auto &CR : Function.CountedRegions) {
    if (CR.FileID == ExpandedRegion.ExpandedFileID)
      RegionManager->insert(CR);
  }
  SubView->load(std::move(RegionManager));
  createExpansionSubViews(*SubView, ExpandedRegion.ExpandedFileID, Function);
  Parent.addExpansion(ExpandedRegion, std::move(SubView));
}
Esempio n. 2
0
bool CodeCoverageTool::createSourceFileView(
    StringRef SourceFile, SourceCoverageView &View,
    ArrayRef<FunctionCoverageMapping> FunctionMappingRecords,
    bool UseOnlyRegionsInMainFile) {
  auto RegionManager = llvm::make_unique<SourceCoverageDataManager>();
  FunctionInstantiationSetCollector InstantiationSetCollector;

  for (const auto &Function : FunctionMappingRecords) {
    unsigned MainFileID;
    if (findMainViewFileID(SourceFile, Function, MainFileID))
      continue;
    SmallSet<unsigned, 8> InterestingFileIDs;
    if (UseOnlyRegionsInMainFile) {
      InterestingFileIDs.insert(MainFileID);
    } else if (!gatherInterestingFileIDs(SourceFile, Function,
                                         InterestingFileIDs))
      continue;
    // Get the interesting regions
    for (const auto &CR : Function.CountedRegions) {
      if (InterestingFileIDs.count(CR.FileID))
        RegionManager->insert(CR);
    }
    InstantiationSetCollector.insert(Function, MainFileID);
    createExpansionSubViews(View, MainFileID, Function);
  }
  if (RegionManager->getCoverageSegments().empty())
    return true;
  View.load(std::move(RegionManager));
  // Show instantiations
  if (!ViewOpts.ShowFunctionInstantiations)
    return false;
  for (const auto &InstantiationSet : InstantiationSetCollector) {
    if (InstantiationSet.second.size() < 2)
      continue;
    for (auto Function : InstantiationSet.second) {
      unsigned FileID = Function->CountedRegions.front().FileID;
      unsigned Line = 0;
      for (const auto &CR : Function->CountedRegions)
        if (CR.FileID == FileID)
          Line = std::max(CR.LineEnd, Line);
      auto SourceBuffer = getSourceFile(Function->Filenames[FileID]);
      if (!SourceBuffer)
        continue;
      auto SubView = llvm::make_unique<SourceCoverageView>(SourceBuffer.get(),
                                                           View.getOptions());
      createInstantiationSubView(SourceFile, *Function, *SubView);
      View.addInstantiation(Function->Name, Line, std::move(SubView));
    }
  }
  return false;
}
Esempio n. 3
0
bool CodeCoverageTool::createSourceFileView(
    StringRef SourceFile, SourceCoverageView &View,
    ArrayRef<FunctionCoverageMapping> FunctionMappingRecords,
    bool UseOnlyRegionsInMainFile) {
  SourceCoverageDataManager RegionManager;
  FunctionInstantiationSetCollector InstantiationSetCollector;

  for (const auto &Function : FunctionMappingRecords) {
    unsigned MainFileID;
    if (findMainViewFileID(SourceFile, Function, MainFileID))
      continue;
    SmallSet<unsigned, 8> InterestingFileIDs;
    if (UseOnlyRegionsInMainFile) {
      InterestingFileIDs.insert(MainFileID);
    } else if (!gatherInterestingFileIDs(SourceFile, Function,
                                         InterestingFileIDs))
      continue;
    // Get the interesting regions
    for (const auto &Region : Function.MappingRegions) {
      if (InterestingFileIDs.count(Region.FileID))
        RegionManager.insert(Region);
    }
    InstantiationSetCollector.insert(Function, MainFileID);
    createExpansionSubViews(View, MainFileID, Function);
  }
  if (RegionManager.getSourceRegions().empty())
    return true;
  View.load(RegionManager);
  // Show instantiations
  if (!ViewOpts.ShowFunctionInstantiations)
    return false;
  for (const auto &InstantiationSet : InstantiationSetCollector) {
    if (InstantiationSet.second.size() < 2)
      continue;
    auto InterestingRange = findExpandedFileInterestingLineRange(
        InstantiationSet.second.front()->MappingRegions.front().FileID,
        *InstantiationSet.second.front());
    for (auto Function : InstantiationSet.second) {
      auto SubView = llvm::make_unique<SourceCoverageView>(
          View, InterestingRange.first, InterestingRange.second,
          Function->PrettyName);
      createInstantiationSubView(SourceFile, *Function, *SubView);
      View.addChild(std::move(SubView));
    }
  }
  return false;
}
Esempio n. 4
0
void CodeCoverageTool::createInstantiationSubView(
    StringRef SourceFile, const FunctionCoverageMapping &Function,
    SourceCoverageView &View) {
  auto RegionManager = llvm::make_unique<SourceCoverageDataManager>();
  SmallSet<unsigned, 8> InterestingFileIDs;
  if (!gatherInterestingFileIDs(SourceFile, Function, InterestingFileIDs))
    return;
  // Get the interesting regions
  for (const auto &CR : Function.CountedRegions) {
    if (InterestingFileIDs.count(CR.FileID))
      RegionManager->insert(CR);
  }
  View.load(std::move(RegionManager));
  unsigned MainFileID;
  if (findMainViewFileID(SourceFile, Function, MainFileID))
    return;
  createExpansionSubViews(View, MainFileID, Function);
}
Esempio n. 5
0
void CodeCoverageTool::createInstantiationSubView(
    StringRef SourceFile, const FunctionCoverageMapping &Function,
    SourceCoverageView &View) {
  SourceCoverageDataManager RegionManager;
  SmallSet<unsigned, 8> InterestingFileIDs;
  if (!gatherInterestingFileIDs(SourceFile, Function, InterestingFileIDs))
    return;
  // Get the interesting regions
  for (const auto &Region : Function.MappingRegions) {
    if (InterestingFileIDs.count(Region.FileID))
      RegionManager.insert(Region);
  }
  View.load(RegionManager);
  unsigned MainFileID;
  if (findMainViewFileID(SourceFile, Function, MainFileID))
    return;
  createExpansionSubViews(View, MainFileID, Function);
}
Esempio n. 6
0
void CodeCoverageTool::attachExpansionSubViews(
    SourceCoverageView &View, ArrayRef<ExpansionRecord> Expansions,
    const CoverageMapping &Coverage) {
  if (!ViewOpts.ShowExpandedRegions)
    return;
  for (const auto &Expansion : Expansions) {
    auto ExpansionCoverage = Coverage.getCoverageForExpansion(Expansion);
    if (ExpansionCoverage.empty())
      continue;
    auto SourceBuffer = getSourceFile(ExpansionCoverage.getFilename());
    if (!SourceBuffer)
      continue;

    auto SubViewExpansions = ExpansionCoverage.getExpansions();
    auto SubView =
        SourceCoverageView::create(Expansion.Function.Name, SourceBuffer.get(),
                                   ViewOpts, std::move(ExpansionCoverage));
    attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
    View.addExpansion(Expansion.Region, std::move(SubView));
  }
}