Skip to content

Commit c308956

Browse files
committed
M14-6-1: Add improved alert message
Improve the alert message to include: - The name of the identifier - A link to the target of the use of the identifier - A link to the dependent base type member with the same name.
1 parent 3f564a3 commit c308956

5 files changed

+40
-31
lines changed

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ private FunctionCall helper_functioncall(
3737
* Gets a function call in `TemplateClass` `t` where the target function name exists in a dependent
3838
* base type and the call is to a function that is not declared in the dependent base type.
3939
*/
40-
FunctionCall getConfusingFunctionCall(TemplateClass t) {
41-
exists(
42-
string name, TemplateClass dependentBaseType, MemberFunction dependentTypeFunction,
43-
Function target
44-
|
40+
FunctionCall getConfusingFunctionCall(
41+
TemplateClass t, string name, Function target, MemberFunction dependentTypeFunction
42+
) {
43+
exists(TemplateClass dependentBaseType |
4544
result = helper_functioncall(t, dependentBaseType, target, name) and
4645
// The dependentTypeFunction is declared on the dependent base type
4746
dependentBaseType.getAMember() = dependentTypeFunction and
@@ -70,11 +69,10 @@ private FunctionAccess helper_functionaccess(
7069
* Gets a function access in `TemplateClass` `t` where the target function name exists in a dependent
7170
* base type and the access is to a function declared outside the dependent base type.
7271
*/
73-
FunctionAccess getConfusingFunctionAccess(TemplateClass t) {
74-
exists(
75-
string name, TemplateClass dependentBaseType, MemberFunction dependentTypeFunction,
76-
Function target
77-
|
72+
FunctionAccess getConfusingFunctionAccess(
73+
TemplateClass t, string name, Function target, MemberFunction dependentTypeFunction
74+
) {
75+
exists(TemplateClass dependentBaseType |
7876
result = helper_functionaccess(t, dependentBaseType, target, name) and
7977
dependentBaseType.getAMember() = dependentTypeFunction and
8078
name = dependentTypeFunction.getName()
@@ -101,11 +99,10 @@ private VariableAccess helper_memberaccess(
10199
* Gets a memmber access in `TemplateClass` `t` where the target member name exists in a dependent
102100
* base type and the access is to a variable declared outside the dependent base type.
103101
*/
104-
VariableAccess getConfusingMemberVariableAccess(TemplateClass t) {
105-
exists(
106-
string name, TemplateClass dependentBaseType, MemberVariable dependentTypeMemberVariable,
107-
Variable target
108-
|
102+
VariableAccess getConfusingMemberVariableAccess(
103+
TemplateClass t, string name, Variable target, MemberVariable dependentTypeMemberVariable
104+
) {
105+
exists(TemplateClass dependentBaseType |
109106
result = helper_memberaccess(t, dependentBaseType, target, name) and
110107
dependentBaseType.getAMemberVariable() = dependentTypeMemberVariable and
111108
name = dependentTypeMemberVariable.getName()

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

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

21-
from TemplateClass c, NameQualifiableElement fn
21+
from
22+
TemplateClass c, NameQualifiableElement fn, string targetName, Element actualTarget,
23+
Element dependentTypeMemberWithSameName
2224
where
2325
not isExcluded(fn, TemplatesPackage::nameNotReferredUsingAQualifiedIdOrThisQuery()) and
2426
not isCustomExcluded(fn) and
2527
missingNameQualifier(fn) and
2628
(
27-
fn = getConfusingFunctionAccess(c)
29+
fn = getConfusingFunctionAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName)
2830
or
29-
fn = getConfusingFunctionCall(c) and
31+
fn = getConfusingFunctionCall(c, targetName, actualTarget, dependentTypeMemberWithSameName) and
3032
not exists(Expr e | e = fn.(FunctionCall).getQualifier())
3133
or
3234
not fn.(VariableAccess).getTarget() instanceof Parameter and
33-
fn = getConfusingMemberVariableAccess(c) and
35+
fn =
36+
getConfusingMemberVariableAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) and
3437
not exists(Expr e | e = fn.(VariableAccess).getQualifier())
3538
) and
3639
not fn.isAffectedByMacro()
37-
select fn, "Use of identifier that also exists in a base class that is not fully qualified."
40+
select fn,
41+
"Use of unqualified identifier " + targetName +
42+
" targets $@ but a member with the name also exists $@.", actualTarget, targetName,
43+
dependentTypeMemberWithSameName, "in the dependent base class"

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

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

21-
from TemplateClass c, NameQualifiableElement fn
21+
from
22+
TemplateClass c, NameQualifiableElement fn, string targetName, Element actualTarget,
23+
Element dependentTypeMemberWithSameName
2224
where
2325
not isExcluded(fn, TemplatesPackage::nameNotReferredUsingAQualifiedIdOrThisAuditQuery()) and
2426
not isCustomExcluded(fn) and
2527
missingNameQualifier(fn) and
2628
(
27-
fn = getConfusingFunctionAccess(c)
29+
fn = getConfusingFunctionAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName)
2830
or
29-
fn = getConfusingFunctionCall(c) and
31+
fn = getConfusingFunctionCall(c, targetName, actualTarget, dependentTypeMemberWithSameName) and
3032
not exists(Expr e | e = fn.(FunctionCall).getQualifier())
3133
or
3234
not fn.(VariableAccess).getTarget() instanceof Parameter and
33-
fn = getConfusingMemberVariableAccess(c) and
35+
fn =
36+
getConfusingMemberVariableAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) and
3437
not exists(Expr e | e = fn.(VariableAccess).getQualifier())
3538
)
36-
select fn, "Use of identifier that also exists in a base class that is not fully qualified."
39+
select fn,
40+
"Use of unqualified identifier " + targetName +
41+
" targets $@ but a member with the name also exists $@.", actualTarget, targetName,
42+
dependentTypeMemberWithSameName, "in the dependent base class"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.cpp:16:5:16:5 | m | Use of identifier that also exists in a base class that is not fully qualified. |
2-
| test.cpp:17:5:17:5 | call to g | Use of identifier that also exists in a base class that is not fully qualified. |
3-
| test.cpp:19:20:19:20 | g | Use of identifier that also exists in a base class that is not fully qualified. |
1+
| test.cpp:16:5:16:5 | m | Use of unqualified identifier m targets $@ but a member with the name also exists $@. | test.cpp:4:5:4:5 | m | m | test.cpp:10:7:10:7 | m | in the dependent base class |
2+
| test.cpp:17:5:17:5 | call to g | Use of unqualified identifier g targets $@ but a member with the name also exists $@. | test.cpp:2:6:2:6 | g | g | test.cpp:9:8:9:8 | g | in the dependent base class |
3+
| test.cpp:19:20:19:20 | g | Use of unqualified identifier g targets $@ but a member with the name also exists $@. | test.cpp:2:6:2:6 | g | g | test.cpp:9:8:9:8 | g | in the dependent base class |
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.cpp:16:5:16:5 | m | Use of identifier that also exists in a base class that is not fully qualified. |
2-
| test.cpp:17:5:17:5 | call to g | Use of identifier that also exists in a base class that is not fully qualified. |
3-
| test.cpp:19:20:19:20 | g | Use of identifier that also exists in a base class that is not fully qualified. |
1+
| test.cpp:16:5:16:5 | m | Use of unqualified identifier m targets $@ but a member with the name also exists $@. | test.cpp:4:5:4:5 | m | m | test.cpp:10:7:10:7 | m | in the dependent base class |
2+
| test.cpp:17:5:17:5 | call to g | Use of unqualified identifier g targets $@ but a member with the name also exists $@. | test.cpp:2:6:2:6 | g | g | test.cpp:9:8:9:8 | g | in the dependent base class |
3+
| test.cpp:19:20:19:20 | g | Use of unqualified identifier g targets $@ but a member with the name also exists $@. | test.cpp:2:6:2:6 | g | g | test.cpp:9:8:9:8 | g | in the dependent base class |

0 commit comments

Comments
 (0)