예제 #1
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;
}
예제 #2
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;
}
예제 #3
0
std::vector<const FunctionRecord *>
CoverageMapping::getInstantiations(StringRef Filename) {
  FunctionInstantiationSetCollector InstantiationSetCollector;
  for (const auto &Function : Functions) {
    auto MainFileID = findMainViewFileID(Filename, Function);
    if (!MainFileID)
      continue;
    InstantiationSetCollector.insert(Function, *MainFileID);
  }

  std::vector<const FunctionRecord *> Result;
  for (const auto &InstantiationSet : InstantiationSetCollector) {
    if (InstantiationSet.second.size() < 2)
      continue;
    for (auto Function : InstantiationSet.second)
      Result.push_back(Function);
  }
  return Result;
}