Skip to content

Commit c8f559c

Browse files
committed
Generate query files for "Statements" package
1 parent 691460a commit c8f559c

12 files changed

+222
-0
lines changed

cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import SideEffects1
4747
import SideEffects2
4848
import SmartPointers1
4949
import SmartPointers2
50+
import Statements
5051
import Strings
5152
import Templates
5253
import Toolchain
@@ -102,6 +103,7 @@ newtype TCPPQuery =
102103
TSideEffects2PackageQuery(SideEffects2Query q) or
103104
TSmartPointers1PackageQuery(SmartPointers1Query q) or
104105
TSmartPointers2PackageQuery(SmartPointers2Query q) or
106+
TStatementsPackageQuery(StatementsQuery q) or
105107
TStringsPackageQuery(StringsQuery q) or
106108
TTemplatesPackageQuery(TemplatesQuery q) or
107109
TToolchainPackageQuery(ToolchainQuery q) or
@@ -157,6 +159,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
157159
isSideEffects2QueryMetadata(query, queryId, ruleId, category) or
158160
isSmartPointers1QueryMetadata(query, queryId, ruleId, category) or
159161
isSmartPointers2QueryMetadata(query, queryId, ruleId, category) or
162+
isStatementsQueryMetadata(query, queryId, ruleId, category) or
160163
isStringsQueryMetadata(query, queryId, ruleId, category) or
161164
isTemplatesQueryMetadata(query, queryId, ruleId, category) or
162165
isToolchainQueryMetadata(query, queryId, ruleId, category) or
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype StatementsQuery =
7+
TAppropriateStructureOfSwitchStatementQuery() or
8+
TLegacyForStatementsShouldBeSimpleQuery() or
9+
TForRangeInitializerAtMostOneFunctionCallQuery()
10+
11+
predicate isStatementsQueryMetadata(Query query, string queryId, string ruleId, string category) {
12+
query =
13+
// `Query` instance for the `appropriateStructureOfSwitchStatement` query
14+
StatementsPackage::appropriateStructureOfSwitchStatementQuery() and
15+
queryId =
16+
// `@id` for the `appropriateStructureOfSwitchStatement` query
17+
"cpp/misra/appropriate-structure-of-switch-statement" and
18+
ruleId = "RULE-9-4-2" and
19+
category = "required"
20+
or
21+
query =
22+
// `Query` instance for the `legacyForStatementsShouldBeSimple` query
23+
StatementsPackage::legacyForStatementsShouldBeSimpleQuery() and
24+
queryId =
25+
// `@id` for the `legacyForStatementsShouldBeSimple` query
26+
"cpp/misra/legacy-for-statements-should-be-simple" and
27+
ruleId = "RULE-9-5-1" and
28+
category = "advisory"
29+
or
30+
query =
31+
// `Query` instance for the `forRangeInitializerAtMostOneFunctionCall` query
32+
StatementsPackage::forRangeInitializerAtMostOneFunctionCallQuery() and
33+
queryId =
34+
// `@id` for the `forRangeInitializerAtMostOneFunctionCall` query
35+
"cpp/misra/for-range-initializer-at-most-one-function-call" and
36+
ruleId = "RULE-9-5-2" and
37+
category = "required"
38+
}
39+
40+
module StatementsPackage {
41+
Query appropriateStructureOfSwitchStatementQuery() {
42+
//autogenerate `Query` type
43+
result =
44+
// `Query` type for `appropriateStructureOfSwitchStatement` query
45+
TQueryCPP(TStatementsPackageQuery(TAppropriateStructureOfSwitchStatementQuery()))
46+
}
47+
48+
Query legacyForStatementsShouldBeSimpleQuery() {
49+
//autogenerate `Query` type
50+
result =
51+
// `Query` type for `legacyForStatementsShouldBeSimple` query
52+
TQueryCPP(TStatementsPackageQuery(TLegacyForStatementsShouldBeSimpleQuery()))
53+
}
54+
55+
Query forRangeInitializerAtMostOneFunctionCallQuery() {
56+
//autogenerate `Query` type
57+
result =
58+
// `Query` type for `forRangeInitializerAtMostOneFunctionCall` query
59+
TQueryCPP(TStatementsPackageQuery(TForRangeInitializerAtMostOneFunctionCallQuery()))
60+
}
61+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @id cpp/misra/appropriate-structure-of-switch-statement
3+
* @name RULE-9-4-2: The structure of a switch statement shall be appropriate
4+
* @description A switch statement should have an appropriate structure with proper cases, default
5+
* labels, and break statements to ensure clear control flow and prevent unintended
6+
* fall-through behavior.
7+
* @kind problem
8+
* @precision very-high
9+
* @problem.severity error
10+
* @tags external/misra/id/rule-9-4-2
11+
* correctness
12+
* maintainability
13+
* readability
14+
* external/misra/allocated-target/single-translation-unit
15+
* external/misra/enforcement/decidable
16+
* external/misra/obligation/required
17+
*/
18+
19+
import cpp
20+
import codingstandards.cpp.misra
21+
22+
from
23+
where
24+
not isExcluded(x, StatementsPackage::appropriateStructureOfSwitchStatementQuery()) and
25+
select
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id cpp/misra/legacy-for-statements-should-be-simple
3+
* @name RULE-9-5-1: Legacy for statements should be simple
4+
* @description Legacy for statements with complex initialization, condition, and increment
5+
* expressions can be difficult to understand and maintain. Simple for loops are more
6+
* readable.
7+
* @kind problem
8+
* @precision high
9+
* @problem.severity recommendation
10+
* @tags external/misra/id/rule-9-5-1
11+
* maintainability
12+
* readability
13+
* external/misra/allocated-target/single-translation-unit
14+
* external/misra/enforcement/decidable
15+
* external/misra/obligation/advisory
16+
*/
17+
18+
import cpp
19+
import codingstandards.cpp.misra
20+
21+
from
22+
where
23+
not isExcluded(x, StatementsPackage::legacyForStatementsShouldBeSimpleQuery()) and
24+
select
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @id cpp/misra/for-range-initializer-at-most-one-function-call
3+
* @name RULE-9-5-2: A for-range-initializer shall contain at most one function call
4+
* @description Multiple function calls in a for-range-initializer can lead to unclear iteration
5+
* behavior and potential side effects that make the code harder to understand and
6+
* debug.
7+
* @kind problem
8+
* @precision very-high
9+
* @problem.severity error
10+
* @tags external/misra/id/rule-9-5-2
11+
* correctness
12+
* maintainability
13+
* readability
14+
* external/misra/allocated-target/single-translation-unit
15+
* external/misra/enforcement/decidable
16+
* external/misra/obligation/required
17+
*/
18+
19+
import cpp
20+
import codingstandards.cpp.misra
21+
22+
from
23+
where
24+
not isExcluded(x, StatementsPackage::forRangeInitializerAtMostOneFunctionCallQuery()) and
25+
select
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-9-4-2/AppropriateStructureOfSwitchStatement.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-9-5-1/LegacyForStatementsShouldBeSimple.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified

0 commit comments

Comments
 (0)