1// Check violations for rule 5.7
2// https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_02.c
3//
4// Confidence: Moderate
5// Copyright: (C) 2020 Intel Corporation
6//
7// SPDX-License-Identifier: Apache-2.0
8
9virtual report
10
11@initialize:python@
12@@
13
14@common_case@
15position p;
16identifier t, v;
17expression E;
18type T;
19@@
20(
21struct t *v@p;
22|
23struct t v@p;
24|
25union t v@p;
26|
27T v@p;
28|
29T *v@p;
30|
31struct t *v@p = E;
32|
33struct t v@p = E;
34|
35union t v@p = E;
36|
37T v@p = E;
38|
39T *v@p = E;
40)
41
42@ script:python @
43v << common_case.v;
44p << common_case.p;
45@@
46
47msg = "WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - {}".format(v)
48with open("scripts/coccinelle/symbols.txt", "r") as fp:
49       symbols = fp.read().splitlines()
50       if v in symbols:
51               coccilib.report.print_report(p[0], msg)
52
53@function_match@
54type T;
55identifier f;
56position p;
57@@
58T f@p(...) {
59...
60}
61
62@ script:python @
63v << function_match.f;
64@@
65
66msg = "WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - {}".format(v)
67with open("scripts/coccinelle/symbols.txt", "r") as fp:
68       symbols = fp.read().splitlines()
69       if v in symbols:
70               coccilib.report.print_report(p[0], msg)
71
72@function_parameter@
73type T1, T2;
74identifier function, v;
75position p;
76parameter list[n] P1;
77parameter list[n1] P2;
78@@
79T1 function(P1, T2 *v@p, P2) {
80...
81}
82
83@ script:python @
84v << function_parameter.v;
85p << function_parameter.p;
86@@
87
88msg = "WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - {}".format(v)
89with open("scripts/coccinelle/symbols.txt", "r") as fp:
90       symbols = fp.read().splitlines()
91       if v in symbols:
92               coccilib.report.print_report(p[0], msg)
93