Skip to content

Commit 25ef996

Browse files
committed
Declarations2: fix shared rule DCL40-C
1 parent 282eb99 commit 25ef996

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

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

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,10 @@
1414

1515
import cpp
1616
import codingstandards.c.misra
17-
import codingstandards.cpp.Linkage
17+
import codingstandards.cpp.rules.notdistinctidentifier.NotDistinctIdentifier
1818

19-
class ExternalIdentifiers extends Declaration {
20-
ExternalIdentifiers() {
21-
this.getName().length() >= 31 and
22-
hasExternalLinkage(this) and
23-
getNamespace() instanceof GlobalNamespace and
24-
not this.isFromTemplateInstantiation(_) and
25-
not this.isFromUninstantiatedTemplate(_) and
26-
not this.hasDeclaringType() and
27-
not this instanceof UserType and
28-
not this instanceof Operator and
29-
not this.hasName("main")
19+
class ExternalIdentifiersNotDistinct extends NotDistinctIdentifierSharedQuery {
20+
ExternalIdentifiersNotDistinct() {
21+
this = Declarations1Package::externalIdentifiersNotDistinctQuery()
3022
}
31-
32-
string getSignificantName() {
33-
//C99 states the first 31 characters of external identifiers are significant
34-
//C90 states the first 6 characters of external identifiers are significant and case is not required to be significant
35-
//C90 is not currently considered by this rule
36-
result = this.getName().prefix(31)
37-
}
38-
}
39-
40-
from ExternalIdentifiers d, ExternalIdentifiers d2
41-
where
42-
not isExcluded(d, Declarations1Package::externalIdentifiersNotDistinctQuery()) and
43-
not d = d2 and
44-
d.getLocation().getStartLine() >= d2.getLocation().getStartLine() and
45-
d.getSignificantName() = d2.getSignificantName() and
46-
not d.getName() = d2.getName()
47-
select d,
48-
"External identifer " + d.getName() +
49-
" is nondistinct in characters at or over 31 limit, compared to $@.", d2, d2.getName()
23+
}

cpp/common/src/codingstandards/cpp/rules/notdistinctidentifier/NotDistinctIdentifier.qll

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,41 @@
55
import cpp
66
import codingstandards.cpp.Customizations
77
import codingstandards.cpp.Exclusions
8+
import codingstandards.cpp.Linkage
9+
10+
class ExternalIdentifiers extends Declaration {
11+
ExternalIdentifiers() {
12+
this.getName().length() >= 31 and
13+
hasExternalLinkage(this) and
14+
getNamespace() instanceof GlobalNamespace and
15+
not this.isFromTemplateInstantiation(_) and
16+
not this.isFromUninstantiatedTemplate(_) and
17+
not this.hasDeclaringType() and
18+
not this instanceof UserType and
19+
not this instanceof Operator and
20+
not this.hasName("main")
21+
}
22+
23+
string getSignificantName() {
24+
//C99 states the first 31 characters of external identifiers are significant
25+
//C90 states the first 6 characters of external identifiers are significant and case is not required to be significant
26+
//C90 is not currently considered by this rule
27+
result = this.getName().prefix(31)
28+
}
29+
}
830

931
abstract class NotDistinctIdentifierSharedQuery extends Query { }
1032

1133
Query getQuery() { result instanceof NotDistinctIdentifierSharedQuery }
1234

13-
query predicate problems(Element e, string message) {
14-
not isExcluded(e, getQuery()) and message = "<replace with problem alert message for >"
15-
}
35+
query predicate problems(ExternalIdentifiers d, ExternalIdentifiers d2, string message) {
36+
not isExcluded(d, getQuery()) and
37+
not isExcluded(d, getQuery()) and
38+
not d = d2 and
39+
d.getLocation().getStartLine() >= d2.getLocation().getStartLine() and
40+
d.getSignificantName() = d2.getSignificantName() and
41+
not d.getName() = d2.getName() and
42+
message =
43+
"External identifer " + d.getName() +
44+
" is nondistinct in characters at or over 31 limit, compared to " + d2.getName()
45+
}

0 commit comments

Comments
 (0)