[PATCH] covoar: Use range-based for loops in ReportsBase
Alex White
alex.white at oarcorp.com
Tue Apr 6 22:37:10 UTC 2021
Some of the loops in the ReportsBase::Write* methods contained both
regular and range-based for loops. This changes them to use only range-
based for loops.
Closes #4374
---
tester/covoar/Explanations.cc | 2 +-
tester/covoar/Explanations.h | 2 +-
tester/covoar/ReportsBase.cc | 87 ++++++++++++++---------------------
tester/covoar/ReportsBase.h | 12 ++---
tester/covoar/ReportsHtml.cc | 54 +++++++++++-----------
tester/covoar/ReportsHtml.h | 6 +--
tester/covoar/ReportsText.cc | 38 +++++++--------
tester/covoar/ReportsText.h | 6 +--
8 files changed, 95 insertions(+), 112 deletions(-)
diff --git a/tester/covoar/Explanations.cc b/tester/covoar/Explanations.cc
index 2050b84..7b0f95a 100644
--- a/tester/covoar/Explanations.cc
+++ b/tester/covoar/Explanations.cc
@@ -115,7 +115,7 @@ done:
}
const Explanation *Explanations::lookupExplanation(
- std::string& start
+ const std::string& start
)
{
if (set.find( start ) == set.end()) {
diff --git a/tester/covoar/Explanations.h b/tester/covoar/Explanations.h
index ce0e4d4..de0c051 100644
--- a/tester/covoar/Explanations.h
+++ b/tester/covoar/Explanations.h
@@ -99,7 +99,7 @@ namespace Coverage {
* which to search
*/
const Explanation *lookupExplanation(
- std::string& start
+ const std::string& start
);
/*!
diff --git a/tester/covoar/ReportsBase.cc b/tester/covoar/ReportsBase.cc
index fea776c..d904f8d 100644
--- a/tester/covoar/ReportsBase.cc
+++ b/tester/covoar/ReportsBase.cc
@@ -197,15 +197,12 @@ std::string expand_tabs(const std::string& in) {
void ReportsBase::WriteAnnotatedReport(
const char* const fileName
) {
- FILE* aFile = NULL;
- Coverage::CoverageRanges* theBranches;
- Coverage::CoverageRanges* theRanges;
- Coverage::CoverageMapBase* theCoverageMap = NULL;
- uint32_t bAddress = 0;
- AnnotatedLineState_t state;
- const std::list<Coverage::ObjdumpProcessor::objdumpLine_t>* theInstructions;
- std::list<
- Coverage::ObjdumpProcessor::objdumpLine_t>::const_iterator itr;
+ FILE* aFile = NULL;
+ Coverage::CoverageRanges* theBranches;
+ Coverage::CoverageRanges* theRanges;
+ Coverage::CoverageMapBase* theCoverageMap = NULL;
+ uint32_t bAddress = 0;
+ AnnotatedLineState_t state;
aFile = OpenAnnotatedFile(fileName);
if (!aFile)
@@ -231,16 +228,12 @@ void ReportsBase::WriteAnnotatedReport(
theCoverageMap = info.unifiedCoverageMap;
bAddress = info.baseAddress;
- theInstructions = &(info.instructions);
theRanges = info.uncoveredRanges;
theBranches = info.uncoveredBranches;
// Add annotations to each line where necessary
AnnotatedStart( aFile );
- for (itr = theInstructions->begin();
- itr != theInstructions->end();
- itr++ ) {
-
+ for (const auto& instruction : info.instructions) {
uint32_t id = 0;
std::string annotation = "";
std::string line;
@@ -249,17 +242,19 @@ void ReportsBase::WriteAnnotatedReport(
state = A_SOURCE;
- if ( itr->isInstruction ) {
- if (!theCoverageMap->wasExecuted( itr->address - bAddress )){
+ if ( instruction.isInstruction ) {
+ if (!theCoverageMap->wasExecuted( instruction.address - bAddress )){
annotation = "<== NOT EXECUTED";
state = A_NEVER_EXECUTED;
- id = theRanges->getId( itr->address );
- } else if (theCoverageMap->isBranch( itr->address - bAddress )) {
- id = theBranches->getId( itr->address );
- if (theCoverageMap->wasAlwaysTaken( itr->address - bAddress )){
+ id = theRanges->getId( instruction.address );
+ } else if (theCoverageMap->isBranch( instruction.address - bAddress )) {
+ id = theBranches->getId( instruction.address );
+ if (theCoverageMap->wasAlwaysTaken( instruction.address - bAddress )){
annotation = "<== ALWAYS TAKEN";
state = A_BRANCH_TAKEN;
- } else if (theCoverageMap->wasNeverTaken( itr->address - bAddress )){
+ } else if (
+ theCoverageMap->wasNeverTaken( instruction.address - bAddress )
+ ) {
annotation = "<== NEVER TAKEN";
state = A_BRANCH_NOT_TAKEN;
}
@@ -268,7 +263,7 @@ void ReportsBase::WriteAnnotatedReport(
}
}
- std::string textLineWithoutTabs = expand_tabs(itr->line);
+ std::string textLineWithoutTabs = expand_tabs(instruction.line);
snprintf( textLine, LINE_LENGTH, "%-90s", textLineWithoutTabs.c_str() );
line = textLine + annotation;
@@ -287,11 +282,10 @@ void ReportsBase::WriteAnnotatedReport(
void ReportsBase::WriteBranchReport(
const char* const fileName
) {
- FILE* report = NULL;
- Coverage::CoverageRanges::ranges_t::iterator ritr;
- Coverage::CoverageRanges* theBranches;
- unsigned int count;
- bool hasBranches = true;
+ FILE* report = NULL;
+ Coverage::CoverageRanges* theBranches;
+ unsigned int count;
+ bool hasBranches = true;
if ((SymbolsToAnalyze->getNumberBranchesFound(symbolSetName_m) == 0) ||
(BranchInfoAvailable == false) )
@@ -315,12 +309,9 @@ void ReportsBase::WriteBranchReport(
theBranches = info.uncoveredBranches;
if (theBranches && !theBranches->set.empty()) {
-
- for (ritr = theBranches->set.begin() ;
- ritr != theBranches->set.end() ;
- ritr++ ) {
+ for (const auto& range : theBranches->set) {
count++;
- PutBranchEntry( report, count, symbol, info, ritr );
+ PutBranchEntry( report, count, symbol, info, range );
}
}
}
@@ -336,12 +327,11 @@ void ReportsBase::WriteCoverageReport(
const char* const fileName
)
{
- FILE* report;
- Coverage::CoverageRanges::ranges_t::iterator ritr;
- Coverage::CoverageRanges* theRanges;
- unsigned int count;
- FILE* NoRangeFile;
- std::string NoRangeName;
+ FILE* report;
+ Coverage::CoverageRanges* theRanges;
+ unsigned int count;
+ FILE* NoRangeFile;
+ std::string NoRangeName;
// Open special file that captures NoRange informaiton
NoRangeName = "no_range_";
@@ -374,11 +364,8 @@ void ReportsBase::WriteCoverageReport(
putCoverageNoRange( report, NoRangeFile, count, symbol );
count++;
} else if (!theRanges->set.empty()) {
-
- for (ritr = theRanges->set.begin() ;
- ritr != theRanges->set.end() ;
- ritr++ ) {
- PutCoverageLine( report, count, symbol, info, ritr );
+ for (const auto& range : theRanges->set) {
+ PutCoverageLine( report, count, symbol, info, range );
count++;
}
}
@@ -396,10 +383,9 @@ void ReportsBase::WriteSizeReport(
const char* const fileName
)
{
- FILE* report;
- Coverage::CoverageRanges::ranges_t::iterator ritr;
- Coverage::CoverageRanges* theRanges;
- unsigned int count;
+ FILE* report;
+ Coverage::CoverageRanges* theRanges;
+ unsigned int count;
// Open the report file.
report = OpenSizeFile( fileName );
@@ -417,11 +403,8 @@ void ReportsBase::WriteSizeReport(
theRanges = info.uncoveredRanges;
if (theRanges && !theRanges->set.empty()) {
-
- for (ritr = theRanges->set.begin() ;
- ritr != theRanges->set.end() ;
- ritr++ ) {
- PutSizeLine( report, count, symbol, ritr );
+ for (const auto& range : theRanges->set) {
+ PutSizeLine( report, count, symbol, range );
count++;
}
}
diff --git a/tester/covoar/ReportsBase.h b/tester/covoar/ReportsBase.h
index 5eff76c..ab8f8dd 100644
--- a/tester/covoar/ReportsBase.h
+++ b/tester/covoar/ReportsBase.h
@@ -328,14 +328,14 @@ class ReportsBase {
* @param[in] number identifies the line number.
* @param[in] symbolName is the symbol's name.
* @param[in] symbolInfo is the symbol's information.
- * @param[in] rangePtr is a pointer to the range information.
+ * @param[in] range is the range information.
*/
virtual bool PutBranchEntry(
FILE* report,
unsigned int number,
const std::string& symbolName,
const SymbolInformation& symbolInfo,
- Coverage::CoverageRanges::ranges_t::iterator rangePtr
+ const CoverageRanges::coverageRange_t& range
)=0;
/*!
@@ -360,14 +360,14 @@ class ReportsBase {
* @param[in] number identifies the line number.
* @param[in] symbolName is the symbol's name.
* @param[in] symbolInfo is the symbol's information.
- * @param[in] ritr is a iterator to the range information.
+ * @param[in] range is the range information.
*/
virtual bool PutCoverageLine(
FILE* report,
unsigned int number,
const std::string& symbolName,
const SymbolInformation& symbolInfo,
- Coverage::CoverageRanges::ranges_t::iterator ritr
+ const CoverageRanges::coverageRange_t& range
)=0;
/*!
@@ -376,13 +376,13 @@ class ReportsBase {
* @param[in] report identifies the size report file name
* @param[in] number identifies the line number.
* @param[in] symbolName is the symbol's name.
- * @param[in] range is a iterator to the range information.
+ * @param[in] range is the range information.
*/
virtual bool PutSizeLine(
FILE* report,
unsigned int number,
const std::string& symbolName,
- Coverage::CoverageRanges::ranges_t::iterator range
+ const CoverageRanges::coverageRange_t& range
)=0;
/*!
diff --git a/tester/covoar/ReportsHtml.cc b/tester/covoar/ReportsHtml.cc
index fa1ebf6..fe75cdd 100644
--- a/tester/covoar/ReportsHtml.cc
+++ b/tester/covoar/ReportsHtml.cc
@@ -501,7 +501,7 @@ namespace Coverage {
unsigned int count,
const std::string& symbolName,
const SymbolInformation& symbolInfo,
- Coverage::CoverageRanges::ranges_t::iterator rangePtr
+ const CoverageRanges::coverageRange_t& range
)
{
const Coverage::Explanation* explanation;
@@ -528,13 +528,13 @@ namespace Coverage {
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\"><a href =\"annotated.html#range%d\">%s</td>\n",
- rangePtr->id,
- rangePtr->lowSourceLine.c_str()
+ range.id,
+ range.lowSourceLine.c_str()
);
// File
- i = rangePtr->lowSourceLine.find(":");
- temp = rangePtr->lowSourceLine.substr (0, i);
+ i = range.lowSourceLine.find(":");
+ temp = range.lowSourceLine.substr (0, i);
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\">%s</td>\n",
@@ -545,17 +545,17 @@ namespace Coverage {
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\">%d</td>\n",
- rangePtr->highAddress - rangePtr->lowAddress + 1
+ range.highAddress - range.lowAddress + 1
);
// Reason Branch was uncovered
- if (rangePtr->reason ==
+ if (range.reason ==
Coverage::CoverageRanges::UNCOVERED_REASON_BRANCH_ALWAYS_TAKEN)
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\">Always Taken</td>\n"
);
- else if (rangePtr->reason ==
+ else if (range.reason ==
Coverage::CoverageRanges::UNCOVERED_REASON_BRANCH_NEVER_TAKEN)
fprintf(
report,
@@ -563,7 +563,7 @@ namespace Coverage {
);
// Taken / Not taken counts
- lowAddress = rangePtr->lowAddress;
+ lowAddress = range.lowAddress;
bAddress = symbolInfo.baseAddress;
theCoverageMap = symbolInfo.unifiedCoverageMap;
fprintf(
@@ -579,7 +579,7 @@ namespace Coverage {
// See if an explanation is available and write the Classification and
// the Explination Columns.
- explanation = AllExplanations->lookupExplanation( rangePtr->lowSourceLine );
+ explanation = AllExplanations->lookupExplanation( range.lowSourceLine );
if ( !explanation ) {
// Write Classificationditr->second.baseAddress
fprintf(
@@ -589,7 +589,7 @@ namespace Coverage {
);
} else {
char explanationFile[48];
- sprintf( explanationFile, "explanation%d.html", rangePtr->id );
+ sprintf( explanationFile, "explanation%d.html", range.id );
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\">%s</td>\n"
@@ -707,7 +707,7 @@ namespace Coverage {
unsigned int count,
const std::string& symbolName,
const SymbolInformation& symbolInfo,
- Coverage::CoverageRanges::ranges_t::iterator rangePtr
+ const CoverageRanges::coverageRange_t& range
)
{
const Coverage::Explanation* explanation;
@@ -731,14 +731,14 @@ namespace Coverage {
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\"><a href =\"annotated.html#range%d\">%s <br>%s</td>\n",
- rangePtr->id,
- rangePtr->lowSourceLine.c_str(),
- rangePtr->highSourceLine.c_str()
+ range.id,
+ range.lowSourceLine.c_str(),
+ range.highSourceLine.c_str()
);
// File
- i = rangePtr->lowSourceLine.find(":");
- temp = rangePtr->lowSourceLine.substr (0, i);
+ i = range.lowSourceLine.find(":");
+ temp = range.lowSourceLine.substr (0, i);
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\">%s</td>\n",
@@ -749,18 +749,18 @@ namespace Coverage {
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\">%d</td>\n",
- rangePtr->highAddress - rangePtr->lowAddress + 1
+ range.highAddress - range.lowAddress + 1
);
// Size in instructions
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\">%d</td>\n",
- rangePtr->instructionCount
+ range.instructionCount
);
// See if an explanation is available
- explanation = AllExplanations->lookupExplanation( rangePtr->lowSourceLine );
+ explanation = AllExplanations->lookupExplanation( range.lowSourceLine );
if ( !explanation ) {
fprintf(
report,
@@ -773,7 +773,7 @@ namespace Coverage {
} else {
char explanationFile[48];
- sprintf( explanationFile, "explanation%d.html", rangePtr->id );
+ sprintf( explanationFile, "explanation%d.html", range.id );
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\">%s</td>\n"
@@ -794,7 +794,7 @@ namespace Coverage {
FILE* report,
unsigned int count,
const std::string& symbolName,
- Coverage::CoverageRanges::ranges_t::iterator range
+ const CoverageRanges::coverageRange_t& range
)
{
std::string temp;
@@ -810,7 +810,7 @@ namespace Coverage {
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\">%d</td>\n",
- range->highAddress - range->lowAddress + 1
+ range.highAddress - range.lowAddress + 1
);
// symbol
@@ -824,13 +824,13 @@ namespace Coverage {
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\"><a href =\"annotated.html#range%d\">%s</td>\n",
- range->id,
- range->lowSourceLine.c_str()
+ range.id,
+ range.lowSourceLine.c_str()
);
// File
- i = range->lowSourceLine.find(":");
- temp = range->lowSourceLine.substr (0, i);
+ i = range.lowSourceLine.find(":");
+ temp = range.lowSourceLine.substr (0, i);
fprintf(
report,
"<td class=\"covoar-td\" align=\"center\">%s</td>\n",
diff --git a/tester/covoar/ReportsHtml.h b/tester/covoar/ReportsHtml.h
index 60c5dc8..8d209ae 100644
--- a/tester/covoar/ReportsHtml.h
+++ b/tester/covoar/ReportsHtml.h
@@ -165,7 +165,7 @@ class ReportsHtml: public ReportsBase {
unsigned int number,
const std::string& symbolName,
const SymbolInformation& symbolInfo,
- Coverage::CoverageRanges::ranges_t::iterator rangePtr
+ const CoverageRanges::coverageRange_t& range
);
/* Inherit documentation from base class. */
@@ -182,7 +182,7 @@ class ReportsHtml: public ReportsBase {
unsigned int number,
const std::string& symbolName,
const SymbolInformation& symbolInfo,
- Coverage::CoverageRanges::ranges_t::iterator ritr
+ const CoverageRanges::coverageRange_t& range
);
/* Inherit documentation from base class. */
@@ -190,7 +190,7 @@ class ReportsHtml: public ReportsBase {
FILE* report,
unsigned int number,
const std::string& symbolName,
- Coverage::CoverageRanges::ranges_t::iterator range
+ const CoverageRanges::coverageRange_t& range
);
/* Inherit documentation from base class. */
diff --git a/tester/covoar/ReportsText.cc b/tester/covoar/ReportsText.cc
index f56580a..33be32f 100644
--- a/tester/covoar/ReportsText.cc
+++ b/tester/covoar/ReportsText.cc
@@ -66,7 +66,7 @@ bool ReportsText::PutBranchEntry(
unsigned int number,
const std::string& symbolName,
const SymbolInformation& symbolInfo,
- Coverage::CoverageRanges::ranges_t::iterator rangePtr
+ const CoverageRanges::coverageRange_t& range
)
{
const Coverage::Explanation* explanation;
@@ -80,22 +80,22 @@ bool ReportsText::PutBranchEntry(
"Size in Bytes : %d\n",
symbolName.c_str(),
symbolInfo.baseAddress,
- rangePtr->lowSourceLine.c_str(),
- rangePtr->lowAddress,
- rangePtr->highAddress - rangePtr->lowAddress + 1
+ range.lowSourceLine.c_str(),
+ range.lowAddress,
+ range.highAddress - range.lowAddress + 1
);
- if (rangePtr->reason ==
+ if (range.reason ==
Coverage::CoverageRanges::UNCOVERED_REASON_BRANCH_ALWAYS_TAKEN)
fprintf(
report, "Reason : %s\n\n", "ALWAYS TAKEN"
);
- else if (rangePtr->reason ==
+ else if (range.reason ==
Coverage::CoverageRanges::UNCOVERED_REASON_BRANCH_NEVER_TAKEN)
fprintf( report, "Reason : %s\n\n", "NEVER TAKEN" );
// See if an explanation is available
- explanation = AllExplanations->lookupExplanation( rangePtr->lowSourceLine );
+ explanation = AllExplanations->lookupExplanation( range.lowSourceLine );
if ( !explanation ) {
fprintf(
@@ -159,7 +159,7 @@ bool ReportsText::PutCoverageLine(
unsigned int number,
const std::string& symbolName,
const SymbolInformation& symbolInfo,
- Coverage::CoverageRanges::ranges_t::iterator ritr
+ const CoverageRanges::coverageRange_t& range
)
{
const Coverage::Explanation* explanation;
@@ -173,18 +173,18 @@ bool ReportsText::PutCoverageLine(
"Ending Line : %s (0x%x)\n"
"Size in Bytes : %d\n"
"Size in Instructions : %d\n\n",
- ritr->id,
+ range.id,
symbolName.c_str(),
symbolInfo.baseAddress,
- ritr->lowSourceLine.c_str(),
- ritr->lowAddress,
- ritr->highSourceLine.c_str(),
- ritr->highAddress,
- ritr->highAddress - ritr->lowAddress + 1,
- ritr->instructionCount
+ range.lowSourceLine.c_str(),
+ range.lowAddress,
+ range.highSourceLine.c_str(),
+ range.highAddress,
+ range.highAddress - range.lowAddress + 1,
+ range.instructionCount
);
- explanation = AllExplanations->lookupExplanation( ritr->lowSourceLine );
+ explanation = AllExplanations->lookupExplanation( range.lowSourceLine );
if ( !explanation ) {
fprintf(
@@ -216,15 +216,15 @@ bool ReportsText::PutSizeLine(
FILE* report,
unsigned int number,
const std::string& symbolName,
- Coverage::CoverageRanges::ranges_t::iterator range
+ const CoverageRanges::coverageRange_t& range
)
{
fprintf(
report,
"%d\t%s\t%s\n",
- range->highAddress - range->lowAddress + 1,
+ range.highAddress - range.lowAddress + 1,
symbolName.c_str(),
- range->lowSourceLine.c_str()
+ range.lowSourceLine.c_str()
);
return true;
}
diff --git a/tester/covoar/ReportsText.h b/tester/covoar/ReportsText.h
index 91366b5..23a1003 100644
--- a/tester/covoar/ReportsText.h
+++ b/tester/covoar/ReportsText.h
@@ -85,7 +85,7 @@ class ReportsText: public ReportsBase {
unsigned int number,
const std::string& symbolName,
const SymbolInformation& symbolInfo,
- Coverage::CoverageRanges::ranges_t::iterator rangePtr
+ const CoverageRanges::coverageRange_t& range
);
/* Inherit documentation from base class. */
@@ -102,7 +102,7 @@ class ReportsText: public ReportsBase {
unsigned int number,
const std::string& symbolName,
const SymbolInformation& symbolInfo,
- Coverage::CoverageRanges::ranges_t::iterator ritr
+ const CoverageRanges::coverageRange_t& range
);
/* Inherit documentation from base class. */
@@ -110,7 +110,7 @@ class ReportsText: public ReportsBase {
FILE* report,
unsigned int number,
const std::string& symbolName,
- Coverage::CoverageRanges::ranges_t::iterator range
+ const CoverageRanges::coverageRange_t& range
);
/* Inherit documentation from base class. */
--
2.27.0
More information about the devel
mailing list