Skip to content

Commit ab02217

Browse files
committed
gcc-parser: deduplicate code of GccPostProcessor
No changes in behavior intended by this commit.
1 parent e25d700 commit ab02217

File tree

1 file changed

+16
-36
lines changed

1 file changed

+16
-36
lines changed

src/gcc-parser.cc

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -561,20 +561,13 @@ struct GccPostProcessor::Private {
561561
const LangDetector langDetector;
562562

563563
void transGccAnal(Defect *pDef) const;
564-
void transGccSuffix(Defect *pDef) const;
564+
void transSuffixGeneric(Defect *pDef, const std::string, const RE &) const;
565565
void transShellCheckId(Defect *pDef) const;
566566

567-
const RE reGccAnalCoreEvt =
568-
RE("^(.*) (\\[-Wanalyzer-[^ \\]]+\\])$");
569-
570-
const RE reGccAnalCwe =
571-
RE("^(.*) \\[CWE-([0-9]+)\\]$");
572-
573-
const RE reGccWarningEvt =
574-
RE("^(.*) (\\[-W[^ \\]]+\\])$");
575-
576-
const RE reShellCheckId =
577-
RE("(^.*) (\\[SC([0-9]+)\\])$");
567+
const RE reGccAnalCoreEvt = RE("^(.*) (\\[-Wanalyzer-[^ \\]]+\\])$");
568+
const RE reGccAnalCwe = RE("^(.*) \\[CWE-([0-9]+)\\]$");
569+
const RE reGccWarningEvt = RE("^(.*) (\\[-W[^ \\]]+\\])$");
570+
const RE reShellCheckId = RE("(^.*) (\\[SC([0-9]+)\\])$");
578571
};
579572

580573
GccPostProcessor::GccPostProcessor():
@@ -613,35 +606,22 @@ void GccPostProcessor::Private::transGccAnal(Defect *pDef) const
613606
keyEvt.msg = sm[/* msg */ 1];
614607
}
615608

616-
void GccPostProcessor::Private::transGccSuffix(Defect *pDef) const
617-
{
618-
if ("COMPILER_WARNING" != pDef->checker)
619-
return;
620-
621-
// check for [-W...] suffix in message of the key event
622-
DefEvent &keyEvt = pDef->events[pDef->keyEventIdx];
623-
boost::smatch sm;
624-
if (!boost::regex_match(keyEvt.msg, sm, this->reGccWarningEvt))
625-
return;
626-
627-
// append [-W...] to key event ID and remove it from event msg
628-
keyEvt.event += sm[/* id */ 2];
629-
// this invalidates sm
630-
keyEvt.msg = sm[/* msg */ 1];
631-
}
632-
633-
void GccPostProcessor::Private::transShellCheckId(Defect *pDef) const
609+
void GccPostProcessor::Private::transSuffixGeneric(
610+
Defect *pDef,
611+
const std::string checker,
612+
const RE &reEvt)
613+
const
634614
{
635-
if ("SHELLCHECK_WARNING" != pDef->checker)
615+
if (checker != pDef->checker)
636616
return;
637617

638-
// check for [SC1234] suffix in message of the key event
618+
// check for [...] suffix in message of the key event
639619
DefEvent &keyEvt = pDef->events[pDef->keyEventIdx];
640620
boost::smatch sm;
641-
if (!boost::regex_match(keyEvt.msg, sm, this->reShellCheckId))
621+
if (!boost::regex_match(keyEvt.msg, sm, reEvt))
642622
return;
643623

644-
// append [SC1234] to key event ID and remove it from event msg
624+
// append [...] to key event ID and remove it from event msg
645625
keyEvt.event += sm[/* id */ 2];
646626
// this invalidates sm
647627
keyEvt.msg = sm[/* msg */ 1];
@@ -650,8 +630,8 @@ void GccPostProcessor::Private::transShellCheckId(Defect *pDef) const
650630
void GccPostProcessor::apply(Defect *pDef) const
651631
{
652632
d->transGccAnal(pDef);
653-
d->transGccSuffix(pDef);
654-
d->transShellCheckId(pDef);
633+
d->transSuffixGeneric(pDef, "COMPILER_WARNING", d->reGccWarningEvt);
634+
d->transSuffixGeneric(pDef, "SHELLCHECK_WARNING", d->reShellCheckId);
655635
d->langDetector.inferLangFromChecker(pDef);
656636
}
657637

0 commit comments

Comments
 (0)