P4C
The P4 Compiler
Loading...
Searching...
No Matches
cyclomaticComplexity.h
1/*
2Determines the cyclomatic complexity values of parsers and
3controls. It applies the ccCalculator to each parser and control
4instance found during traversal. The ccCalculator determines the
5CC value by counting decision point nodes (like if statements).
6*/
7
8#ifndef FRONTENDS_P4_METRICS_CYCLOMATICCOMPLEXITY_H_
9#define FRONTENDS_P4_METRICS_CYCLOMATICCOMPLEXITY_H_
10
11#include "frontends/p4/metrics/metricsStructure.h"
12#include "ir/ir.h"
13
14using namespace P4::literals;
15
16namespace P4 {
17
18class CyclomaticComplexityCalculator : public Inspector {
19 int cc;
20
21 public:
22 CyclomaticComplexityCalculator() : cc(1) { setName("CyclomaticComplexityCalculator"); }
23 int getComplexity() const { return cc; }
24
25 void postorder(const IR::IfStatement * /*stmt*/) override;
26 void postorder(const IR::SwitchStatement *stmt) override;
27 void postorder(const IR::ForStatement * /*stmt*/) override;
28 void postorder(const IR::ForInStatement * /*stmt*/) override;
29 void postorder(const IR::SelectExpression *selectExpr) override;
30 void postorder(const IR::MethodCallExpression *mce) override;
31 bool preorder(const IR::P4Table *table) override;
32};
33
34class CyclomaticComplexityPass : public Inspector {
35 Metrics &metrics;
36
37 public:
38 explicit CyclomaticComplexityPass(Metrics &metricsRef) : metrics(metricsRef) {
39 setName("CyclomaticComplexityPass");
40 }
41
42 bool preorder(const IR::P4Control *control) override;
43 bool preorder(const IR::P4Parser *parser) override;
44};
45
46} // namespace P4
47
48#endif /* FRONTENDS_P4_METRICS_CYCLOMATICCOMPLEXITY_H_ */
Definition visitor.h:413
Definition cstring.h:80
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition metricsStructure.h:119