Skip to content

Commit 103b866

Browse files
committed
move query implementations to Query.qll files to avoid isPOD deprecation warning in test output
1 parent 367576f commit 103b866

8 files changed

+65
-49
lines changed

cpp/autosar/src/rules/A11-0-1/NonPodTypeShouldBeDefinedAsClass.ql

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@
1515
* external/autosar/obligation/advisory
1616
*/
1717

18-
import cpp
19-
import codingstandards.cpp.autosar
20-
import codingstandards.cpp.Typehelpers
18+
import NonPodTypeShouldBeDefinedAsClassQuery
2119

2220
from Struct s
23-
where
24-
not isExcluded(s, ClassesPackage::nonPodTypeShouldBeDefinedAsClassQuery()) and
25-
not s.isPOD()
21+
where problem(s)
2622
select s, "Non-POD type defined as struct instead of class."
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import cpp
2+
import codingstandards.cpp.autosar
3+
import codingstandards.cpp.Typehelpers
4+
5+
predicate problem(Struct s) {
6+
not isExcluded(s, ClassesPackage::nonPodTypeShouldBeDefinedAsClassQuery()) and
7+
not s.isPOD()
8+
}

cpp/autosar/src/rules/A12-0-2/OperationsAssumingMemoryLayoutPerformedOnObjects.ql

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,8 @@
1515
* external/autosar/obligation/required
1616
*/
1717

18-
import cpp
19-
import codingstandards.cpp.autosar
20-
21-
class Object extends Class {
22-
Object() { not this.(Struct).isPOD() }
23-
}
24-
25-
predicate isPointerToObject(Expr e) {
26-
e.(VariableAccess).getType().(PointerType).getBaseType() instanceof Object
27-
or
28-
e.(AddressOfExpr).getOperand().getType() instanceof Object
29-
}
18+
import OperationsAssumingMemoryLayoutPerformedOnObjectsQuery
3019

3120
from FunctionCall fc, string functionName
32-
where
33-
not isExcluded(fc, ExpressionsPackage::operationsAssumingMemoryLayoutPerformedOnObjectsQuery()) and
34-
/*
35-
* Note: this list was arbitrarily chosen, based on <https://en.cppreference.com/w/c/string/byte>,
36-
* and may be incomplete.
37-
*/
38-
39-
functionName in [
40-
"memcmp", "memset", "memset_s", "memcpy", "memcpy_s", "memmove", "memmove_s", "free"
41-
] and
42-
fc.getTarget().hasGlobalOrStdName(functionName) and
43-
isPointerToObject(fc.getAnArgument())
21+
where problem(fc, functionName)
4422
select fc, "Use of an object as argument to 'std::" + functionName + "'."
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import cpp
2+
import codingstandards.cpp.autosar
3+
4+
class Object extends Class {
5+
Object() { not this.(Struct).isPOD() }
6+
}
7+
8+
predicate isPointerToObject(Expr e) {
9+
e.(VariableAccess).getType().(PointerType).getBaseType() instanceof Object
10+
or
11+
e.(AddressOfExpr).getOperand().getType() instanceof Object
12+
}
13+
14+
predicate problem(FunctionCall fc, string functionName) {
15+
not isExcluded(fc, ExpressionsPackage::operationsAssumingMemoryLayoutPerformedOnObjectsQuery()) and
16+
/*
17+
* Note: this list was arbitrarily chosen, based on <https://en.cppreference.com/w/c/string/byte>,
18+
* and may be incomplete.
19+
*/
20+
21+
functionName in [
22+
"memcmp", "memset", "memset_s", "memcpy", "memcpy_s", "memmove", "memmove_s", "free"
23+
] and
24+
fc.getTarget().hasGlobalOrStdName(functionName) and
25+
isPointerToObject(fc.getAnArgument())
26+
}

cpp/autosar/src/rules/A9-6-1/DataTypesUsedForInterfacingWithHardwareOrProtocolsMustBeTrivialAndStandardLayout.ql

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,9 @@
1414
* external/autosar/obligation/required
1515
*/
1616

17-
import cpp
18-
import codingstandards.cpp.autosar
19-
import codingstandards.cpp.HardwareOrProtocolInterface
20-
import codingstandards.cpp.ImplicitHardwareOrProtocolInterfaceClass
17+
import DataTypesUsedForInterfacingWithHardwareOrProtocolsMustBeTrivialAndStandardLayoutQuery
2118

2219
from HardwareOrProtocolInterfaceClass c
23-
where
24-
not isExcluded(c,
25-
ClassesPackage::dataTypesUsedForInterfacingWithHardwareOrProtocolsMustBeTrivialAndStandardLayoutQuery()) and
26-
not c.isPOD()
20+
where problem(c)
2721
select c,
2822
"Data type used for hardware interface or communication protocol is not standard layout and trivial."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import cpp
2+
import codingstandards.cpp.autosar
3+
import codingstandards.cpp.HardwareOrProtocolInterface
4+
import codingstandards.cpp.ImplicitHardwareOrProtocolInterfaceClass
5+
6+
predicate problem(HardwareOrProtocolInterfaceClass c) {
7+
not isExcluded(c,
8+
ClassesPackage::dataTypesUsedForInterfacingWithHardwareOrProtocolsMustBeTrivialAndStandardLayoutQuery()) and
9+
not c.isPOD()
10+
}

cpp/autosar/src/rules/M11-0-1/MemberDataInNonPodClassTypesNotPrivate.ql

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,8 @@
1313
* external/autosar/obligation/required
1414
*/
1515

16-
import cpp
17-
import codingstandards.cpp.autosar
18-
19-
class NonPODType extends Class {
20-
NonPODType() { not this.isPOD() }
21-
}
16+
import MemberDataInNonPodClassTypesNotPrivateQuery
2217

2318
from NonPODType p, Field f
24-
where
25-
not isExcluded(p, ClassesPackage::memberDataInNonPodClassTypesNotPrivateQuery()) and
26-
f = p.getAField() and
27-
not f.isCompilerGenerated() and
28-
(f.isProtected() or f.isPublic())
19+
where problem(p, f)
2920
select f, "Member data in a non-POD class is not private."
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import cpp
2+
import codingstandards.cpp.autosar
3+
4+
class NonPODType extends Class {
5+
NonPODType() { not this.isPOD() }
6+
}
7+
8+
predicate problem(NonPODType p, Field f) {
9+
not isExcluded(p, ClassesPackage::memberDataInNonPodClassTypesNotPrivateQuery()) and
10+
f = p.getAField() and
11+
not f.isCompilerGenerated() and
12+
(f.isProtected() or f.isPublic())
13+
}

0 commit comments

Comments
 (0)