Skip to content

Commit 4acfba8

Browse files
committed
Declarations1: refactor RULE-5-1
1 parent a3891e2 commit 4acfba8

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

c/misra/src/rules/RULE-5-1/ExternalIdentifiersNotDistinct.ql

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,21 @@ import codingstandards.cpp.Linkage
1818

1919
class ExternalIdentifiers extends Declaration {
2020
ExternalIdentifiers() { hasExternalLinkage(this) }
21-
}
2221

23-
class ExternalIdentifiersLong extends ExternalIdentifiers {
24-
ExternalIdentifiersLong() { this.getName().length() >= 32 }
25-
}
26-
27-
predicate notSame(ExternalIdentifiers d, ExternalIdentifiers d2) {
28-
not d = d2 and
29-
d.getLocation().getStartLine() >= d2.getLocation().getStartLine()
22+
string getSignificantName() {
23+
//C99 states the first 31 characters of external identifiers are significant
24+
//C90 states the first 6 characters of external identifiers are significant and case is not required to be significant
25+
//C90 is not currently considered by this rule
26+
result = this.getName().prefix(31)
27+
}
3028
}
3129

3230
from ExternalIdentifiers d, ExternalIdentifiers d2
3331
where
3432
not isExcluded(d, Declarations1Package::externalIdentifiersNotDistinctQuery()) and
35-
notSame(d, d2) and
36-
//C99 states the first 31 characters of external identifiers are significant
37-
//C90 states the first 6 characters of external identifiers are significant and case is not required to be significant
38-
//C90 is not currently considered by this rule
39-
if d instanceof ExternalIdentifiersLong and d2 instanceof ExternalIdentifiersLong
40-
then d.getName().prefix(31) = d2.getName().prefix(31)
41-
else d.getName() = d2.getName()
33+
not d = d2 and
34+
d.getLocation().getStartLine() >= d2.getLocation().getStartLine() and
35+
d.getSignificantName() = d2.getSignificantName()
4236
select d,
4337
"External identifer " + d.getName() + " is nondistinct in first 31 characters, compared to $@.",
4438
d2, d2.getName()

0 commit comments

Comments
 (0)