|
17 | 17 |
|
18 | 18 | #include <stdio.h>
|
19 | 19 |
|
| 20 | +#include <cassert> |
20 | 21 | #include <algorithm>
|
21 | 22 | #include <iostream>
|
22 | 23 | #include <string>
|
@@ -86,45 +87,51 @@ RuleWithActions::RuleWithActions(
|
86 | 87 |
|
87 | 88 | if (actions) {
|
88 | 89 | for (Action *a : *actions) {
|
89 |
| - if (a->action_kind == Action::ConfigurationKind) { |
90 |
| - a->evaluate(this, NULL); |
91 |
| - delete a; |
92 |
| - |
93 |
| - } else if (a->action_kind == Action::RunTimeOnlyIfMatchKind) { |
94 |
| - if (dynamic_cast<actions::Capture *>(a)) { |
95 |
| - m_containsCaptureAction = true; |
96 |
| - delete a; |
97 |
| - } else if (dynamic_cast<actions::MultiMatch *>(a)) { |
98 |
| - m_containsMultiMatchAction = true; |
| 90 | + switch (a->action_kind) { |
| 91 | + case Action::ConfigurationKind: |
| 92 | + a->evaluate(this, NULL); |
99 | 93 | delete a;
|
100 |
| - } else if (dynamic_cast<actions::Severity *>(a)) { |
101 |
| - m_severity = dynamic_cast<actions::Severity *>(a); |
102 |
| - } else if (dynamic_cast<actions::LogData *>(a)) { |
103 |
| - m_logData = dynamic_cast<actions::LogData*>(a); |
104 |
| - } else if (dynamic_cast<actions::Msg *>(a)) { |
105 |
| - m_msg = dynamic_cast<actions::Msg*>(a); |
106 |
| - } else if (dynamic_cast<actions::SetVar *>(a)) { |
107 |
| - m_actionsSetVar.push_back( |
108 |
| - dynamic_cast<actions::SetVar *>(a)); |
109 |
| - } else if (dynamic_cast<actions::Tag *>(a)) { |
110 |
| - m_actionsTag.push_back(dynamic_cast<actions::Tag *>(a)); |
111 |
| - } else if (dynamic_cast<actions::Block *>(a)) { |
112 |
| - m_actionsRuntimePos.push_back(a); |
113 |
| - m_containsStaticBlockAction = true; |
114 |
| - } else if (a->isDisruptive() == true) { |
115 |
| - if (m_disruptiveAction != nullptr) { |
116 |
| - delete m_disruptiveAction; |
117 |
| - m_disruptiveAction = nullptr; |
| 94 | + break; |
| 95 | + case Action::RunTimeOnlyIfMatchKind: |
| 96 | + if (dynamic_cast<actions::Capture *>(a)) { |
| 97 | + m_containsCaptureAction = true; |
| 98 | + delete a; |
| 99 | + } else if (dynamic_cast<actions::MultiMatch *>(a)) { |
| 100 | + m_containsMultiMatchAction = true; |
| 101 | + delete a; |
| 102 | + } else if (dynamic_cast<actions::Severity *>(a)) { |
| 103 | + m_severity = dynamic_cast<actions::Severity *>(a); |
| 104 | + } else if (dynamic_cast<actions::LogData *>(a)) { |
| 105 | + m_logData = dynamic_cast<actions::LogData*>(a); |
| 106 | + } else if (dynamic_cast<actions::Msg *>(a)) { |
| 107 | + m_msg = dynamic_cast<actions::Msg*>(a); |
| 108 | + } else if (dynamic_cast<actions::SetVar *>(a)) { |
| 109 | + m_actionsSetVar.push_back( |
| 110 | + dynamic_cast<actions::SetVar *>(a)); |
| 111 | + } else if (dynamic_cast<actions::Tag *>(a)) { |
| 112 | + m_actionsTag.push_back(dynamic_cast<actions::Tag *>(a)); |
| 113 | + } else if (dynamic_cast<actions::Block *>(a)) { |
| 114 | + m_actionsRuntimePos.push_back(a); |
| 115 | + m_containsStaticBlockAction = true; |
| 116 | + } else if (a->isDisruptive() == true) { |
| 117 | + if (m_disruptiveAction != nullptr) { |
| 118 | + delete m_disruptiveAction; |
| 119 | + m_disruptiveAction = nullptr; |
| 120 | + } |
| 121 | + m_disruptiveAction = a; |
| 122 | + } else { |
| 123 | + m_actionsRuntimePos.push_back(a); |
118 | 124 | }
|
119 |
| - m_disruptiveAction = a; |
120 |
| - } else { |
121 |
| - m_actionsRuntimePos.push_back(a); |
122 |
| - } |
123 |
| - } else { |
124 |
| - delete a; |
125 |
| - std::cout << "General failure, action: " << a->m_name; |
126 |
| - std::cout << " has an unknown type." << std::endl; |
127 |
| - throw; // cppcheck-suppress rethrowNoCurrentException |
| 125 | + break; |
| 126 | + default: |
| 127 | + std::cout << "General failure, action: " << a->m_name; |
| 128 | + std::cout << " has an unknown type." << std::endl; |
| 129 | + delete a; |
| 130 | + #ifdef NDEBUG |
| 131 | + break; |
| 132 | + #else |
| 133 | + assert(false); |
| 134 | + #endif |
128 | 135 | }
|
129 | 136 | }
|
130 | 137 | delete actions;
|
@@ -239,7 +246,7 @@ void RuleWithActions::executeActionsAfterFullMatch(Transaction *trans,
|
239 | 246 | bool containsBlock, std::shared_ptr<RuleMessage> ruleMessage) {
|
240 | 247 | bool disruptiveAlreadyExecuted = false;
|
241 | 248 |
|
242 |
| - for (auto &a : trans->m_rules->m_defaultActions[getPhase()]) { // cppcheck-suppress ctunullpointer |
| 249 | + for (const auto &a : trans->m_rules->m_defaultActions[getPhase()]) { // cppcheck-suppress ctunullpointer |
243 | 250 | if (a.get()->action_kind != actions::Action::RunTimeOnlyIfMatchKind) {
|
244 | 251 | continue;
|
245 | 252 | }
|
|
0 commit comments