Skip to content

Commit

Permalink
Fix #13029 (Update checkers report: Misra C directives) (#6712)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar authored Aug 19, 2024
1 parent 8349fe2 commit 55adeb4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
25 changes: 25 additions & 0 deletions lib/checkers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,31 @@ namespace checkers {
const char Man[] = "Mandatory";
const char Doc[] = "Document";

const std::vector<MisraInfo> misraC2012Directives =
{
{1,1,Req,0},
{2,1,Req,0},
{3,1,Req,0},
{4,1,Req,0},
{4,2,Adv,0},
{4,3,Req,0},
{4,4,Adv,0},
{4,5,Adv,0},
{4,6,Adv,3},
{4,7,Req,0},
{4,8,Adv,0},
{4,9,Adv,3},
{4,10,Req,0},
{4,11,Req,3},
{4,12,Req,0},
{4,13,Adv,0},
{4,14,Req,2},
{4,15,Req,3},
{5,1,Req,4},
{5,2,Req,4},
{5,3,Req,4},
};

const std::vector<MisraInfo> misraC2012Rules =
{
{1,1,Req,0},
Expand Down
1 change: 1 addition & 0 deletions lib/checkers.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace checkers {
extern CPPCHECKLIB const char Man[]; // = "Mandatory";
extern CPPCHECKLIB const char Doc[]; // = "Document";

extern CPPCHECKLIB const std::vector<MisraInfo> misraC2012Directives;
extern CPPCHECKLIB const std::vector<MisraInfo> misraC2012Rules;
extern CPPCHECKLIB const std::vector<MisraCppInfo> misraCpp2008Rules;
extern CPPCHECKLIB const std::vector<MisraCppInfo> misraCpp2023Rules;
Expand Down
13 changes: 12 additions & 1 deletion lib/checkersreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,17 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
fout << std::endl << std::endl;
fout << "Misra C " << misra << std::endl;
fout << "------------" << std::endl;
for (const checkers::MisraInfo& info: checkers::misraC2012Directives) {
const std::string directive = "Dir " + std::to_string(info.a) + "." + std::to_string(info.b);
const bool active = isMisraRuleActive(mActiveCheckers, directive);
fout << (active ? "Yes " : "No ") << "Misra C " << misra << ": " << directive;
std::string extra;
if (misra == 2012 && info.amendment >= 1)
extra = " amendment:" + std::to_string(info.amendment);
if (!extra.empty())
fout << std::string(10 - directive.size(), ' ') << extra;
fout << '\n';
}
for (const checkers::MisraInfo& info: checkers::misraC2012Rules) {
const std::string rule = std::to_string(info.a) + "." + std::to_string(info.b);
const bool active = isMisraRuleActive(mActiveCheckers, rule);
Expand All @@ -254,7 +265,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
if (!active && !reqs.empty())
extra += " require:" + reqs.substr(1);
if (!extra.empty())
fout << std::string(7 - rule.size(), ' ') << extra;
fout << std::string(10 - rule.size(), ' ') << extra;
fout << '\n';
}
}
Expand Down

0 comments on commit 55adeb4

Please sign in to comment.