mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-06-29 00:30:47 +00:00
llvm-cov: Return unique_ptrs instead of filling objects (NFC)
Having create* functions return the object they create is more readable than using an in-out parameter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218139 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
dcd8562eb7
commit
297149bafc
|
@ -103,23 +103,22 @@ public:
|
||||||
|
|
||||||
/// \brief Create a source view which shows coverage for an expansion
|
/// \brief Create a source view which shows coverage for an expansion
|
||||||
/// of a file.
|
/// of a file.
|
||||||
void createExpansionSubView(const CountedRegion &ExpandedRegion,
|
std::unique_ptr<SourceCoverageView>
|
||||||
const FunctionCoverageMapping &Function,
|
createExpansionSubView(const CountedRegion &ExpandedRegion,
|
||||||
SourceCoverageView &Parent);
|
const FunctionCoverageMapping &Function);
|
||||||
|
|
||||||
void createExpansionSubViews(SourceCoverageView &View, unsigned ViewFileID,
|
void attachExpansionSubViews(SourceCoverageView &View, unsigned ViewFileID,
|
||||||
const FunctionCoverageMapping &Function);
|
const FunctionCoverageMapping &Function);
|
||||||
|
|
||||||
/// \brief Create a source view which shows coverage for an instantiation
|
/// \brief Create a source view which shows coverage for an instantiation
|
||||||
/// of a funciton.
|
/// of a funciton.
|
||||||
void createInstantiationSubView(StringRef SourceFile,
|
std::unique_ptr<SourceCoverageView>
|
||||||
const FunctionCoverageMapping &Function,
|
createInstantiationSubView(StringRef SourceFile,
|
||||||
SourceCoverageView &View);
|
const FunctionCoverageMapping &Function);
|
||||||
|
|
||||||
/// \brief Create the main source view of a particular source file.
|
/// \brief Create the main source view of a particular source file.
|
||||||
/// Return true if this particular source file is not covered.
|
std::unique_ptr<SourceCoverageView>
|
||||||
bool
|
createSourceFileView(StringRef SourceFile,
|
||||||
createSourceFileView(StringRef SourceFile, SourceCoverageView &View,
|
|
||||||
ArrayRef<FunctionCoverageMapping> FunctionMappingRecords,
|
ArrayRef<FunctionCoverageMapping> FunctionMappingRecords,
|
||||||
bool UseOnlyRegionsInMainFile = false);
|
bool UseOnlyRegionsInMainFile = false);
|
||||||
|
|
||||||
|
@ -244,26 +243,26 @@ CodeCoverageTool::findMainViewFileID(const FunctionCoverageMapping &Function,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeCoverageTool::createExpansionSubView(
|
std::unique_ptr<SourceCoverageView> CodeCoverageTool::createExpansionSubView(
|
||||||
const CountedRegion &ExpandedRegion,
|
const CountedRegion &ExpandedRegion,
|
||||||
const FunctionCoverageMapping &Function, SourceCoverageView &Parent) {
|
const FunctionCoverageMapping &Function) {
|
||||||
auto SourceBuffer =
|
auto SourceBuffer =
|
||||||
getSourceFile(Function.Filenames[ExpandedRegion.ExpandedFileID]);
|
getSourceFile(Function.Filenames[ExpandedRegion.ExpandedFileID]);
|
||||||
if (!SourceBuffer)
|
if (!SourceBuffer)
|
||||||
return;
|
return nullptr;
|
||||||
auto SubView = llvm::make_unique<SourceCoverageView>(SourceBuffer.get(),
|
|
||||||
Parent.getOptions());
|
|
||||||
auto RegionManager = llvm::make_unique<SourceCoverageDataManager>();
|
auto RegionManager = llvm::make_unique<SourceCoverageDataManager>();
|
||||||
for (const auto &CR : Function.CountedRegions) {
|
for (const auto &CR : Function.CountedRegions) {
|
||||||
if (CR.FileID == ExpandedRegion.ExpandedFileID)
|
if (CR.FileID == ExpandedRegion.ExpandedFileID)
|
||||||
RegionManager->insert(CR);
|
RegionManager->insert(CR);
|
||||||
}
|
}
|
||||||
|
auto SubView = llvm::make_unique<SourceCoverageView>(SourceBuffer.get(),
|
||||||
|
ViewOpts);
|
||||||
SubView->load(std::move(RegionManager));
|
SubView->load(std::move(RegionManager));
|
||||||
createExpansionSubViews(*SubView, ExpandedRegion.ExpandedFileID, Function);
|
attachExpansionSubViews(*SubView, ExpandedRegion.ExpandedFileID, Function);
|
||||||
Parent.addExpansion(ExpandedRegion, std::move(SubView));
|
return SubView;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeCoverageTool::createExpansionSubViews(
|
void CodeCoverageTool::attachExpansionSubViews(
|
||||||
SourceCoverageView &View, unsigned ViewFileID,
|
SourceCoverageView &View, unsigned ViewFileID,
|
||||||
const FunctionCoverageMapping &Function) {
|
const FunctionCoverageMapping &Function) {
|
||||||
if (!ViewOpts.ShowExpandedRegions)
|
if (!ViewOpts.ShowExpandedRegions)
|
||||||
|
@ -273,36 +272,50 @@ void CodeCoverageTool::createExpansionSubViews(
|
||||||
continue;
|
continue;
|
||||||
if (CR.FileID != ViewFileID)
|
if (CR.FileID != ViewFileID)
|
||||||
continue;
|
continue;
|
||||||
createExpansionSubView(CR, Function, View);
|
auto SubView = createExpansionSubView(CR, Function);
|
||||||
|
if (SubView)
|
||||||
|
View.addExpansion(CR, std::move(SubView));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeCoverageTool::createInstantiationSubView(
|
std::unique_ptr<SourceCoverageView>
|
||||||
StringRef SourceFile, const FunctionCoverageMapping &Function,
|
CodeCoverageTool::createInstantiationSubView(
|
||||||
SourceCoverageView &View) {
|
StringRef SourceFile, const FunctionCoverageMapping &Function) {
|
||||||
auto RegionManager = llvm::make_unique<SourceCoverageDataManager>();
|
auto RegionManager = llvm::make_unique<SourceCoverageDataManager>();
|
||||||
SmallSet<unsigned, 8> InterestingFileIDs;
|
SmallSet<unsigned, 8> InterestingFileIDs;
|
||||||
if (!gatherInterestingFileIDs(SourceFile, Function, InterestingFileIDs))
|
if (!gatherInterestingFileIDs(SourceFile, Function, InterestingFileIDs))
|
||||||
return;
|
return nullptr;
|
||||||
// Get the interesting regions
|
// Get the interesting regions
|
||||||
for (const auto &CR : Function.CountedRegions) {
|
for (const auto &CR : Function.CountedRegions) {
|
||||||
if (InterestingFileIDs.count(CR.FileID))
|
if (InterestingFileIDs.count(CR.FileID))
|
||||||
RegionManager->insert(CR);
|
RegionManager->insert(CR);
|
||||||
}
|
}
|
||||||
View.load(std::move(RegionManager));
|
|
||||||
|
auto SourceBuffer = getSourceFile(SourceFile);
|
||||||
|
if (!SourceBuffer)
|
||||||
|
return nullptr;
|
||||||
|
auto SubView = llvm::make_unique<SourceCoverageView>(SourceBuffer.get(),
|
||||||
|
ViewOpts);
|
||||||
|
SubView->load(std::move(RegionManager));
|
||||||
unsigned MainFileID;
|
unsigned MainFileID;
|
||||||
if (findMainViewFileID(SourceFile, Function, MainFileID))
|
if (!findMainViewFileID(SourceFile, Function, MainFileID))
|
||||||
return;
|
attachExpansionSubViews(*SubView, MainFileID, Function);
|
||||||
createExpansionSubViews(View, MainFileID, Function);
|
return SubView;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CodeCoverageTool::createSourceFileView(
|
std::unique_ptr<SourceCoverageView> CodeCoverageTool::createSourceFileView(
|
||||||
StringRef SourceFile, SourceCoverageView &View,
|
StringRef SourceFile,
|
||||||
ArrayRef<FunctionCoverageMapping> FunctionMappingRecords,
|
ArrayRef<FunctionCoverageMapping> FunctionMappingRecords,
|
||||||
bool UseOnlyRegionsInMainFile) {
|
bool UseOnlyRegionsInMainFile) {
|
||||||
auto RegionManager = llvm::make_unique<SourceCoverageDataManager>();
|
auto RegionManager = llvm::make_unique<SourceCoverageDataManager>();
|
||||||
FunctionInstantiationSetCollector InstantiationSetCollector;
|
FunctionInstantiationSetCollector InstantiationSetCollector;
|
||||||
|
|
||||||
|
auto SourceBuffer = getSourceFile(SourceFile);
|
||||||
|
if (!SourceBuffer)
|
||||||
|
return nullptr;
|
||||||
|
auto View =
|
||||||
|
llvm::make_unique<SourceCoverageView>(SourceBuffer.get(), ViewOpts);
|
||||||
|
|
||||||
for (const auto &Function : FunctionMappingRecords) {
|
for (const auto &Function : FunctionMappingRecords) {
|
||||||
unsigned MainFileID;
|
unsigned MainFileID;
|
||||||
if (findMainViewFileID(SourceFile, Function, MainFileID))
|
if (findMainViewFileID(SourceFile, Function, MainFileID))
|
||||||
|
@ -319,14 +332,14 @@ bool CodeCoverageTool::createSourceFileView(
|
||||||
RegionManager->insert(CR);
|
RegionManager->insert(CR);
|
||||||
}
|
}
|
||||||
InstantiationSetCollector.insert(Function, MainFileID);
|
InstantiationSetCollector.insert(Function, MainFileID);
|
||||||
createExpansionSubViews(View, MainFileID, Function);
|
attachExpansionSubViews(*View, MainFileID, Function);
|
||||||
}
|
}
|
||||||
if (RegionManager->getCoverageSegments().empty())
|
if (RegionManager->getCoverageSegments().empty())
|
||||||
return true;
|
return nullptr;
|
||||||
View.load(std::move(RegionManager));
|
View->load(std::move(RegionManager));
|
||||||
// Show instantiations
|
// Show instantiations
|
||||||
if (!ViewOpts.ShowFunctionInstantiations)
|
if (!ViewOpts.ShowFunctionInstantiations)
|
||||||
return false;
|
return View;
|
||||||
for (const auto &InstantiationSet : InstantiationSetCollector) {
|
for (const auto &InstantiationSet : InstantiationSetCollector) {
|
||||||
if (InstantiationSet.second.size() < 2)
|
if (InstantiationSet.second.size() < 2)
|
||||||
continue;
|
continue;
|
||||||
|
@ -336,16 +349,12 @@ bool CodeCoverageTool::createSourceFileView(
|
||||||
for (const auto &CR : Function->CountedRegions)
|
for (const auto &CR : Function->CountedRegions)
|
||||||
if (CR.FileID == FileID)
|
if (CR.FileID == FileID)
|
||||||
Line = std::max(CR.LineEnd, Line);
|
Line = std::max(CR.LineEnd, Line);
|
||||||
auto SourceBuffer = getSourceFile(Function->Filenames[FileID]);
|
auto SubView = createInstantiationSubView(SourceFile, *Function);
|
||||||
if (!SourceBuffer)
|
if (SubView)
|
||||||
continue;
|
View->addInstantiation(Function->Name, Line, std::move(SubView));
|
||||||
auto SubView = llvm::make_unique<SourceCoverageView>(SourceBuffer.get(),
|
|
||||||
View.getOptions());
|
|
||||||
createInstantiationSubView(SourceFile, *Function, *SubView);
|
|
||||||
View.addInstantiation(Function->Name, Line, std::move(SubView));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return View;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CodeCoverageTool::load() {
|
bool CodeCoverageTool::load() {
|
||||||
|
@ -609,15 +618,18 @@ int CodeCoverageTool::show(int argc, const char **argv,
|
||||||
if (findMainViewFileID(Function, MainFileID))
|
if (findMainViewFileID(Function, MainFileID))
|
||||||
continue;
|
continue;
|
||||||
StringRef SourceFile = Function.Filenames[MainFileID];
|
StringRef SourceFile = Function.Filenames[MainFileID];
|
||||||
auto SourceBuffer = getSourceFile(SourceFile);
|
auto mainView = createSourceFileView(SourceFile, Function, true);
|
||||||
if (!SourceBuffer)
|
if (!mainView) {
|
||||||
return 1;
|
ViewOpts.colored_ostream(outs(), raw_ostream::RED)
|
||||||
SourceCoverageView mainView(SourceBuffer.get(), ViewOpts);
|
<< "warning: Could not read coverage for '" << Function.Name
|
||||||
createSourceFileView(SourceFile, mainView, Function, true);
|
<< " from " << SourceFile;
|
||||||
|
outs() << "\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ViewOpts.colored_ostream(outs(), raw_ostream::CYAN)
|
ViewOpts.colored_ostream(outs(), raw_ostream::CYAN)
|
||||||
<< Function.Name << " from " << SourceFile << ":";
|
<< Function.Name << " from " << SourceFile << ":";
|
||||||
outs() << "\n";
|
outs() << "\n";
|
||||||
mainView.render(outs(), /*WholeFile=*/false);
|
mainView->render(outs(), /*WholeFile=*/false);
|
||||||
if (FunctionMappingRecords.size() > 1)
|
if (FunctionMappingRecords.size() > 1)
|
||||||
outs() << "\n";
|
outs() << "\n";
|
||||||
}
|
}
|
||||||
|
@ -633,11 +645,8 @@ int CodeCoverageTool::show(int argc, const char **argv,
|
||||||
SourceFiles.push_back(Filename);
|
SourceFiles.push_back(Filename);
|
||||||
|
|
||||||
for (const auto &SourceFile : SourceFiles) {
|
for (const auto &SourceFile : SourceFiles) {
|
||||||
auto SourceBuffer = getSourceFile(SourceFile);
|
auto mainView = createSourceFileView(SourceFile, FunctionMappingRecords);
|
||||||
if (!SourceBuffer)
|
if (!mainView) {
|
||||||
return 1;
|
|
||||||
SourceCoverageView mainView(SourceBuffer.get(), ViewOpts);
|
|
||||||
if (createSourceFileView(SourceFile, mainView, FunctionMappingRecords)) {
|
|
||||||
ViewOpts.colored_ostream(outs(), raw_ostream::RED)
|
ViewOpts.colored_ostream(outs(), raw_ostream::RED)
|
||||||
<< "warning: The file '" << SourceFile << "' isn't covered.";
|
<< "warning: The file '" << SourceFile << "' isn't covered.";
|
||||||
outs() << "\n";
|
outs() << "\n";
|
||||||
|
@ -648,7 +657,7 @@ int CodeCoverageTool::show(int argc, const char **argv,
|
||||||
ViewOpts.colored_ostream(outs(), raw_ostream::CYAN) << SourceFile << ":";
|
ViewOpts.colored_ostream(outs(), raw_ostream::CYAN) << SourceFile << ":";
|
||||||
outs() << "\n";
|
outs() << "\n";
|
||||||
}
|
}
|
||||||
mainView.render(outs(), /*Wholefile=*/true);
|
mainView->render(outs(), /*Wholefile=*/true);
|
||||||
if (SourceFiles.size() > 1)
|
if (SourceFiles.size() > 1)
|
||||||
outs() << "\n";
|
outs() << "\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user