5
5
import cpp
6
6
import codingstandards.cpp.Customizations
7
7
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
+ }
8
30
9
31
abstract class NotDistinctIdentifierSharedQuery extends Query { }
10
32
11
33
Query getQuery ( ) { result instanceof NotDistinctIdentifierSharedQuery }
12
34
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