13
13
import cpp
14
14
import codingstandards.c.misra
15
15
16
- abstract class ForbiddenType extends Type { }
17
-
18
- class BuiltinNumericType extends ForbiddenType {
16
+ class BuiltinNumericType extends BuiltInType {
19
17
BuiltinNumericType ( ) {
20
18
/* Exclude the plain char because it does not count as a numeric type */
21
19
this .( CharType ) .isExplicitlySigned ( )
@@ -38,15 +36,22 @@ class BuiltinNumericType extends ForbiddenType {
38
36
}
39
37
}
40
38
41
- class ForbiddenTypedefType extends ForbiddenType , TypedefType {
42
- ForbiddenTypedefType ( ) {
43
- this .( TypedefType ) .getBaseType ( ) instanceof BuiltinNumericType and
44
- not this .getName ( ) .regexpMatch ( "u?(int|float)(4|8|16|32|64|128)_t" )
45
- }
39
+ predicate forbiddenBuiltinNumericUsedInDecl ( Variable var , string message ) {
40
+ var .getType ( ) instanceof BuiltinNumericType and
41
+ message = "The type " + var .getType ( ) + " is not a fixed-width numeric type."
42
+ }
43
+
44
+ predicate forbiddenTypedef ( TypedefType typedef , string message ) {
45
+ typedef .getBaseType ( ) instanceof BuiltinNumericType and
46
+ not typedef .getName ( ) .regexpMatch ( "u?(int|float)(4|8|16|32|64|128)_t" ) and
47
+ message = "The type " + typedef .getName ( ) + " is not an alias to a fixed-width numeric type."
46
48
}
47
49
48
- /* TODO: BuiltinNumericType not being flagged */
49
- from ForbiddenType forbiddenType
50
- where not isExcluded ( forbiddenType , TypesPackage:: plainNumericalTypeUsedOverExplicitTypedefQuery ( ) )
51
- select forbiddenType ,
52
- "The type " + forbiddenType + " is not a fixed-width numeric type nor an alias to one."
50
+ from Element elem , string message
51
+ where
52
+ not isExcluded ( elem , TypesPackage:: plainNumericalTypeUsedOverExplicitTypedefQuery ( ) ) and
53
+ (
54
+ forbiddenBuiltinNumericUsedInDecl ( elem , message ) or
55
+ forbiddenTypedef ( elem , message )
56
+ )
57
+ select elem , message
0 commit comments