[rtems-tools commit] Remove AllExplanations global variable

Joel Sherrill joel at rtems.org
Tue Aug 3 21:00:44 UTC 2021


Module:    rtems-tools
Branch:    master
Commit:    0c6f57a25abdff1d75362cb28be2796a333c56aa
Changeset: http://git.rtems.org/rtems-tools/commit/?id=0c6f57a25abdff1d75362cb28be2796a333c56aa

Author:    Ryan Long <ryan.long at oarcorp.com>
Date:      Tue Jul 27 15:49:02 2021 -0400

Remove AllExplanations global variable

- Replaced AllExplanations in app_common with a local variable in covoar()
- Added the allExplanations_m member variable to ReportsBase
- Added a parameter to ReportsBase and its derived classes' constructors
  to initialize allExplanations_m
- Added parameter to GenerateReports() to pass the variable from
  covoar() to the constructors for Reports*

---

 tester/covoar/ReportsBase.cc | 21 ++++++++++++++-------
 tester/covoar/ReportsBase.h  | 18 ++++++++++++++++--
 tester/covoar/ReportsHtml.cc | 11 ++++++-----
 tester/covoar/ReportsHtml.h  |  6 +++++-
 tester/covoar/ReportsText.cc | 11 +++++++----
 tester/covoar/ReportsText.h  |  6 +++++-
 tester/covoar/app_common.cc  |  1 -
 tester/covoar/app_common.h   |  1 -
 tester/covoar/covoar.cc      |  8 ++++----
 9 files changed, 57 insertions(+), 26 deletions(-)

diff --git a/tester/covoar/ReportsBase.cc b/tester/covoar/ReportsBase.cc
index cd65c53..62229c0 100644
--- a/tester/covoar/ReportsBase.cc
+++ b/tester/covoar/ReportsBase.cc
@@ -23,10 +23,14 @@
 
 namespace Coverage {
 
-ReportsBase::ReportsBase( time_t timestamp, const std::string& symbolSetName ):
-  reportExtension_m( "" ),
-  symbolSetName_m( symbolSetName ),
-  timestamp_m( timestamp )
+ReportsBase::ReportsBase(
+  time_t                  timestamp,
+  const std::string&      symbolSetName,
+  Coverage::Explanations& allExplanations
+): reportExtension_m( "" ),
+   symbolSetName_m( symbolSetName ),
+   timestamp_m( timestamp ),
+   allExplanations_m( allExplanations )
 {
 }
 
@@ -558,7 +562,10 @@ void  ReportsBase::WriteSummaryReport(
   CloseFile( report );
 }
 
-void GenerateReports( const std::string& symbolSetName )
+void GenerateReports(
+  const std::string&      symbolSetName,
+  Coverage::Explanations& allExplanations
+)
 {
   typedef std::list<ReportsBase *> reportList_t;
 
@@ -570,9 +577,9 @@ void GenerateReports( const std::string& symbolSetName )
 
 
   timestamp = time( NULL ); /* get current cal time */
-  reports = new ReportsText( timestamp, symbolSetName );
+  reports = new ReportsText( timestamp, symbolSetName, allExplanations );
   reportList.push_back( reports );
-  reports = new ReportsHtml( timestamp, symbolSetName );
+  reports = new ReportsHtml( timestamp, symbolSetName, allExplanations );
   reportList.push_back( reports );
 
   for ( ritr = reportList.begin(); ritr != reportList.end(); ritr++ ) {
diff --git a/tester/covoar/ReportsBase.h b/tester/covoar/ReportsBase.h
index 41add8e..a2856e3 100644
--- a/tester/covoar/ReportsBase.h
+++ b/tester/covoar/ReportsBase.h
@@ -15,6 +15,7 @@
 #include <fstream>
 #include <time.h>
 #include "DesiredSymbols.h"
+#include "Explanations.h"
 
 namespace Coverage {
 
@@ -26,7 +27,11 @@ namespace Coverage {
 class ReportsBase {
 
   public:
-    ReportsBase( time_t timestamp, const std::string& symbolSetName );
+    ReportsBase(
+      time_t                  timestamp,
+      const std::string&      symbolSetName,
+      Coverage::Explanations& allExplanations
+    );
     virtual ~ReportsBase();
 
     /*!
@@ -120,6 +125,11 @@ class ReportsBase {
     time_t timestamp_m;
 
     /*!
+     *  This member variable contains the explanations to report on.
+     */
+    Coverage::Explanations& allExplanations_m;
+
+    /*!
      *  This method Opens a report file and verifies that it opened
      *  correctly.  Upon failure NULL is returned.
      *
@@ -389,8 +399,12 @@ class ReportsBase {
  *  all reports.
  *
  *  @param[in] symbolSetName is the name of the symbol set to report on.
+ *  @param[in] allExplanations is the explanations to report on.
  */
-void GenerateReports( const std::string& symbolSetName );
+void GenerateReports(
+  const std::string& symbolSetName,
+  Coverage::Explanations& allExplanations
+);
 
 }
 
diff --git a/tester/covoar/ReportsHtml.cc b/tester/covoar/ReportsHtml.cc
index e276732..88ea25b 100644
--- a/tester/covoar/ReportsHtml.cc
+++ b/tester/covoar/ReportsHtml.cc
@@ -38,9 +38,10 @@ typedef rtems::utils::ostream_guard ostream_guard;
 namespace Coverage {
 
   ReportsHtml::ReportsHtml(
-   time_t              timestamp,
-    const std::string& symbolSetName
-  ): ReportsBase( timestamp, symbolSetName )
+    time_t                  timestamp,
+    const std::string&      symbolSetName,
+    Coverage::Explanations& allExplanations
+  ): ReportsBase( timestamp, symbolSetName, allExplanations )
   {
     reportExtension_m = ".html";
   }
@@ -506,7 +507,7 @@ namespace Coverage {
 
     // See if an explanation is available and write the Classification and
     // the Explination Columns.
-    explanation = AllExplanations->lookupExplanation( range.lowSourceLine );
+    explanation = allExplanations_m.lookupExplanation( range.lowSourceLine );
     if ( !explanation ) {
       // Write Classificationditr->second.baseAddress
       report << "<td class=\"covoar-td\" align=\"center\">NONE</td>"
@@ -654,7 +655,7 @@ namespace Coverage {
            << range.instructionCount << "</td>" << std::endl;
 
     // See if an explanation is available
-    explanation = AllExplanations->lookupExplanation( range.lowSourceLine );
+    explanation = allExplanations_m.lookupExplanation( range.lowSourceLine );
     if ( !explanation ) {
       report << "<td class=\"covoar-td\" align=\"center\">NONE</td>"
              << std::endl
diff --git a/tester/covoar/ReportsHtml.h b/tester/covoar/ReportsHtml.h
index a7ed0af..711c48b 100644
--- a/tester/covoar/ReportsHtml.h
+++ b/tester/covoar/ReportsHtml.h
@@ -25,7 +25,11 @@ namespace Coverage {
 class ReportsHtml: public ReportsBase {
 
   public:
-    ReportsHtml( time_t timestamp, const std::string& symbolSetName );
+    ReportsHtml(
+      time_t                  timestamp,
+      const std::string&      symbolSetName,
+      Coverage::Explanations& allExplanations
+    );
    ~ReportsHtml();
 
    /*!
diff --git a/tester/covoar/ReportsText.cc b/tester/covoar/ReportsText.cc
index c4a5dbc..0b0d9df 100644
--- a/tester/covoar/ReportsText.cc
+++ b/tester/covoar/ReportsText.cc
@@ -16,8 +16,11 @@ typedef rtems::utils::ostream_guard ostream_guard;
 
 namespace Coverage {
 
-ReportsText::ReportsText( time_t timestamp, const std::string& symbolSetName ):
-  ReportsBase( timestamp, symbolSetName )
+ReportsText::ReportsText(
+  time_t                  timestamp,
+  const std::string&      symbolSetName,
+  Coverage::Explanations& allExplanations
+): ReportsBase( timestamp, symbolSetName, allExplanations )
 {
   reportExtension_m = ".txt";
 }
@@ -95,7 +98,7 @@ bool ReportsText::PutBranchEntry(
   }
 
   // See if an explanation is available
-  explanation = AllExplanations->lookupExplanation( range.lowSourceLine );
+  explanation = allExplanations_m.lookupExplanation( range.lowSourceLine );
 
   if ( !explanation ) {
     report << "Classification: NONE" << std::endl << std::endl
@@ -164,7 +167,7 @@ bool ReportsText::PutCoverageLine(
          << "Size in Instructions : " << range.instructionCount
          << std::endl << std::endl;
 
-  explanation = AllExplanations->lookupExplanation( range.lowSourceLine );
+  explanation = allExplanations_m.lookupExplanation( range.lowSourceLine );
 
   if ( !explanation ) {
     report << "Classification: NONE" << std::endl << std::endl
diff --git a/tester/covoar/ReportsText.h b/tester/covoar/ReportsText.h
index 9ad80ef..48528b0 100644
--- a/tester/covoar/ReportsText.h
+++ b/tester/covoar/ReportsText.h
@@ -21,7 +21,11 @@ namespace Coverage {
 class ReportsText: public ReportsBase {
 
   public:
-    ReportsText( time_t timestamp, const std::string& symbolSetName );
+    ReportsText(
+      time_t                  timestamp,
+      const std::string&      symbolSetName,
+      Coverage::Explanations& allExplanations
+    );
     virtual ~ReportsText();
 
   /*!
diff --git a/tester/covoar/app_common.cc b/tester/covoar/app_common.cc
index 8b490ed..f878fb6 100644
--- a/tester/covoar/app_common.cc
+++ b/tester/covoar/app_common.cc
@@ -56,7 +56,6 @@
 /*
  *  Global variables for the program
  */
-Coverage::Explanations*     AllExplanations     = NULL;
 Coverage::ObjdumpProcessor* objdumpProcessor    = NULL;
 Coverage::DesiredSymbols*   SymbolsToAnalyze    = NULL;
 bool                        Verbose             = false;
diff --git a/tester/covoar/app_common.h b/tester/covoar/app_common.h
index ac32bbd..921bb71 100644
--- a/tester/covoar/app_common.h
+++ b/tester/covoar/app_common.h
@@ -12,7 +12,6 @@
 #include "Explanations.h"
 #include "TargetBase.h"
 
-extern Coverage::Explanations*      AllExplanations;
 extern Coverage::ObjdumpProcessor*  objdumpProcessor;
 extern Coverage::DesiredSymbols*    SymbolsToAnalyze;
 extern bool                         Verbose;
diff --git a/tester/covoar/covoar.cc b/tester/covoar/covoar.cc
index 8d63132..9295519 100644
--- a/tester/covoar/covoar.cc
+++ b/tester/covoar/covoar.cc
@@ -174,6 +174,7 @@ int covoar(
   std::string                   symbolSet;
   std::string                   option;
   int                           opt;
+  Coverage::Explanations        allExplanations;
 
   //
   // Process command line options.
@@ -354,9 +355,8 @@ int covoar(
               << " symbols" << std::endl;
 
   // Create explanations.
-  AllExplanations = new Coverage::Explanations();
   if ( explanations )
-    AllExplanations->load( explanations );
+    allExplanations.load( explanations );
 
   // Create coverage map reader.
   coverageFormat = Coverage::CoverageFormatToEnum(format);
@@ -474,7 +474,7 @@ int covoar(
     std::cerr << "Generate Reports" << std::endl;
 
   for (const auto& setName : SymbolsToAnalyze->getSetNames()) {
-    Coverage::GenerateReports(setName);
+    Coverage::GenerateReports( setName, allExplanations );
   }
 
   // Write explanations that were not found.
@@ -488,7 +488,7 @@ int covoar(
     if (Verbose)
       std::cerr << "Writing Not Found Report (" << notFound<< ')' << std::endl;
 
-    AllExplanations->writeNotFound( notFound.c_str() );
+    allExplanations.writeNotFound( notFound.c_str() );
   }
 
   //Leave tempfiles around if debug flag (-d) is enabled.



More information about the vc mailing list