Skip to content

Commit 0d43de5

Browse files
committed
M14-6-1: Push dependent base type context
Push the dependent type context into the individual determination of contravening cases to work towards addressing performance issues.
1 parent 7b6cc90 commit 0d43de5

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

cpp/autosar/src/rules/M14-6-1/NameInDependentBase.qll

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,47 @@ TemplateClass getADependentBaseType(TemplateClass t) {
1818
}
1919

2020
/**
21-
* There is a `MemberFunction` in parent class with same name
22-
* as a `FunctionCall` that exists in a child `MemberFunction`
21+
* Gets a function call in `TemplateClass` `t` where the target function name exists in a dependent
22+
* base type and the function does not call that function.
2323
*/
24-
FunctionCall parentMemberFunctionCall(Class child, Class parent) {
25-
exists(MemberFunction parentFunction, Function other |
24+
FunctionCall parentMemberFunctionCall(TemplateClass t) {
25+
exists(TemplateClass dependentBaseType, MemberFunction parentFunction, Function other |
26+
dependentBaseType = getADependentBaseType(t) and
2627
not other = parentFunction and
27-
parent.getAMember() = parentFunction and
28+
dependentBaseType.getAMember() = parentFunction and
2829
other.getName() = parentFunction.getName() and
2930
result = other.getACallToThisFunction() and
30-
result.getEnclosingFunction() = child.getAMemberFunction()
31+
result.getEnclosingFunction() = t.getAMemberFunction()
3132
)
3233
}
3334

3435
/**
3536
* There is a `MemberFunction` in parent class with same name
3637
* as a `FunctionAccess` that exists in a child `MemberFunction`
3738
*/
38-
FunctionAccess parentMemberFunctionAccess(Class child, Class parent) {
39-
exists(MemberFunction parentFunction, Function other |
39+
FunctionAccess parentMemberFunctionAccess(TemplateClass t) {
40+
exists(TemplateClass dependentBaseType, MemberFunction parentFunction, Function other |
41+
dependentBaseType = getADependentBaseType(t) and
4042
not other = parentFunction and
41-
parent.getAMember() = parentFunction and
43+
dependentBaseType.getAMember() = parentFunction and
4244
other.getName() = parentFunction.getName() and
4345
result = other.getAnAccess() and
44-
result.getEnclosingFunction() = child.getAMemberFunction()
46+
result.getEnclosingFunction() = t.getAMemberFunction()
4547
)
4648
}
4749

4850
/**
4951
* There is a `MemberVariable` in parent class with same name
5052
* as a `VariableAccess` that exists in a child `MemberFunction`
5153
*/
52-
Access parentMemberAccess(Class child, Class parent) {
53-
exists(MemberVariable parentMember, Variable other |
54+
Access parentMemberAccess(TemplateClass t) {
55+
exists(TemplateClass dependentBaseType, MemberVariable parentMember, Variable other |
56+
dependentBaseType = getADependentBaseType(t) and
5457
not other = parentMember and
55-
parent.getAMemberVariable() = parentMember and
58+
dependentBaseType.getAMemberVariable() = parentMember and
5659
other.getName() = parentMember.getName() and
5760
result = other.getAnAccess() and
58-
result.getEnclosingFunction() = child.getAMemberFunction()
61+
result.getEnclosingFunction() = t.getAMemberFunction()
5962
)
6063
}
6164

cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.ql

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@ import cpp
1818
import codingstandards.cpp.autosar
1919
import NameInDependentBase
2020

21-
from TemplateClass c, TemplateClass dependentBaseType, NameQualifiableElement fn
21+
from TemplateClass c, NameQualifiableElement fn
2222
where
2323
not isExcluded(fn, TemplatesPackage::nameNotReferredUsingAQualifiedIdOrThisQuery()) and
2424
not isCustomExcluded(fn) and
25-
dependentBaseType = getADependentBaseType(c) and
2625
missingNameQualifier(fn) and
2726
(
2827
fn instanceof FunctionAccess and
29-
fn = parentMemberFunctionAccess(c, dependentBaseType)
28+
fn = parentMemberFunctionAccess(c)
3029
or
3130
fn instanceof FunctionCall and
32-
fn = parentMemberFunctionCall(c, dependentBaseType) and
31+
fn = parentMemberFunctionCall(c) and
3332
not exists(Expr e | e = fn.(FunctionCall).getQualifier())
3433
or
3534
fn instanceof VariableAccess and
3635
not fn.(VariableAccess).getTarget() instanceof Parameter and
37-
fn = parentMemberAccess(c, dependentBaseType) and
36+
fn = parentMemberAccess(c) and
3837
not exists(Expr e | e = fn.(VariableAccess).getQualifier())
3938
) and
4039
not fn.isAffectedByMacro()

cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.ql

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@ import cpp
1818
import codingstandards.cpp.autosar
1919
import NameInDependentBase
2020

21-
from TemplateClass c, TemplateClass dependentBaseType, NameQualifiableElement fn
21+
from TemplateClass c, NameQualifiableElement fn
2222
where
2323
not isExcluded(fn, TemplatesPackage::nameNotReferredUsingAQualifiedIdOrThisAuditQuery()) and
2424
not isCustomExcluded(fn) and
25-
dependentBaseType = getADependentBaseType(c) and
2625
missingNameQualifier(fn) and
2726
(
2827
fn instanceof FunctionAccess and
29-
fn = parentMemberFunctionAccess(c, dependentBaseType)
28+
fn = parentMemberFunctionAccess(c)
3029
or
3130
fn instanceof FunctionCall and
32-
fn = parentMemberFunctionCall(c, dependentBaseType) and
31+
fn = parentMemberFunctionCall(c) and
3332
not exists(Expr e | e = fn.(FunctionCall).getQualifier())
3433
or
3534
fn instanceof VariableAccess and
3635
not fn.(VariableAccess).getTarget() instanceof Parameter and
37-
fn = parentMemberAccess(c, dependentBaseType) and
36+
fn = parentMemberAccess(c) and
3837
not exists(Expr e | e = fn.(VariableAccess).getQualifier())
3938
)
4039
select fn, "Use of identifier that also exists in a base class that is not fully qualified."

0 commit comments

Comments
 (0)