Skip to content

Commit 161479e

Browse files
authored
Merge pull request #3 from github/michaelrfairhurst/rule-6-8-4-performance-fix
Performance fix that preserves test results.
2 parents 81375fa + e8d60bc commit 161479e

2 files changed

Lines changed: 37 additions & 19 deletions

File tree

cpp/common/src/codingstandards/cpp/types/Compatible.qll

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,45 +486,70 @@ signature predicate interestedInFunctionDeclarations(
486486
);
487487

488488
module FunctionDeclarationTypeEquivalence<
489-
TypeEquivalenceSig Config, interestedInFunctionDeclarations/2 interestedInFunctions>
489+
TypeEquivalenceSig Config, interestedInFunctionDeclarations/2 interestedInFunDecls>
490490
{
491491
private predicate interestedInReturnTypes(Type a, Type b) {
492492
exists(FunctionDeclarationEntry aFun, FunctionDeclarationEntry bFun |
493-
interestedInFunctions(pragma[only_bind_into](aFun), pragma[only_bind_into](bFun)) and
493+
interestedInFunDecls(pragma[only_bind_into](aFun), pragma[only_bind_into](bFun)) and
494494
a = aFun.getType() and
495495
b = bFun.getType()
496496
)
497497
}
498498

499499
private predicate interestedInParameterTypes(Type a, Type b) {
500500
exists(FunctionDeclarationEntry aFun, FunctionDeclarationEntry bFun, int i |
501-
interestedInFunctions(pragma[only_bind_into](aFun), pragma[only_bind_into](bFun)) and
501+
interestedInFunDecls(pragma[only_bind_into](aFun), pragma[only_bind_into](bFun)) and
502502
a = aFun.getParameterDeclarationEntry(i).getType() and
503503
b = bFun.getParameterDeclarationEntry(i).getType()
504504
)
505505
}
506506

507507
predicate equalReturnTypes(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2) {
508-
interestedInFunctions(f1, f2) and
508+
interestedInFunDecls(f1, f2) and
509509
TypeEquivalence<Config, interestedInReturnTypes/2>::equalTypes(f1.getType(), f2.getType())
510510
}
511511

512512
predicate equalParameterTypes(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2) {
513-
interestedInFunctions(f1, f2) and
513+
interestedInFunDecls(f1, f2) and
514514
f1.getDeclaration() = f2.getDeclaration() and
515515
forall(int i | exists([f1, f2].getParameterDeclarationEntry(i)) |
516516
equalParameterTypesAt(f1, f2, pragma[only_bind_into](i))
517517
)
518518
}
519519

520520
predicate equalParameterTypesAt(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2, int i) {
521-
interestedInFunctions(f1, f2) and
521+
interestedInFunDecls(f1, f2) and
522522
f1.getDeclaration() = f2.getDeclaration() and
523523
TypeEquivalence<Config, interestedInParameterTypes/2>::equalTypes(f1.getParameterDeclarationEntry(pragma[only_bind_into](i))
524524
.getType(), f2.getParameterDeclarationEntry(pragma[only_bind_into](i)).getType())
525525
}
526526
}
527527

528+
signature predicate interestedInFunctions(Function f1, Function f2);
529+
530+
module FunctionEquivalence<TypeEquivalenceSig Config, interestedInFunctions/2 interestedInFuncs> {
531+
private predicate interestedInParameterTypes(Type a, Type b) {
532+
exists(Function aFun, Function bFun, int i |
533+
interestedInFuncs(pragma[only_bind_into](aFun), pragma[only_bind_into](bFun)) and
534+
a = aFun.getParameter(i).getType() and
535+
b = bFun.getParameter(i).getType()
536+
)
537+
}
538+
539+
predicate equalParameterTypes(Function f1, Function f2) {
540+
interestedInFuncs(f1, f2) and
541+
forall(int i | exists([f1, f2].getParameter(i)) |
542+
equalParameterTypesAt(f1, f2, pragma[only_bind_into](i))
543+
)
544+
}
545+
546+
predicate equalParameterTypesAt(Function f1, Function f2, int i) {
547+
interestedInFuncs(f1, f2) and
548+
TypeEquivalence<Config, interestedInParameterTypes/2>::equalTypes(f1.getParameter(pragma[only_bind_into](i))
549+
.getType(), f2.getParameter(pragma[only_bind_into](i)).getType())
550+
}
551+
}
552+
528553
private class LeafType extends Type {
529554
LeafType() {
530555
not this instanceof DerivedType and

cpp/misra/src/rules/RULE-6-8-4/MemberFunctionsRefqualified.ql

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,12 @@ class MembersReturningSubObject extends MembersReturningObjectOrSubobject {
6868
}
6969
}
7070

71-
predicate relevantTypes(Type a, Type b) {
72-
exists(MembersReturningObjectOrSubobject f, MemberFunction overload |
73-
f.getAnOverload() = overload and
74-
exists(int i |
75-
f.getParameter(i).getType() = a and
76-
overload.getParameter(i).getType() = b
77-
)
78-
)
71+
predicate relevantFunctions(Function a, Function b) {
72+
a instanceof MembersReturningObjectOrSubobject and
73+
a.getAnOverload() = b
7974
}
8075

81-
class AppropriatelyQualified extends MembersReturningObjectOrSubobject {
76+
class AppropriatelyQualified extends MemberFunction {
8277
AppropriatelyQualified() {
8378
//non-const-lvalue-ref-qualified
8479
this.isLValueRefQualified() and
@@ -92,10 +87,8 @@ class AppropriatelyQualified extends MembersReturningObjectOrSubobject {
9287
this.getAnOverload() = overload and
9388
overload.isRValueRefQualified() and
9489
//and has same param list
95-
forall(int i | exists([this, overload].getParameter(i)) |
96-
TypeEquivalence<TypesCompatibleConfig, relevantTypes/2>::equalTypes(this.getParameter(i)
97-
.getType(), overload.getParameter(i).getType())
98-
)
90+
FunctionEquivalence<TypesCompatibleConfig, relevantFunctions/2>::equalParameterTypes(this,
91+
overload)
9992
)
10093
}
10194
}

0 commit comments

Comments
 (0)