55import cpp
66import codingstandards.cpp.Customizations
77import 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
931abstract class NotDistinctIdentifierSharedQuery extends Query { }
1032
1133Query 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