1313import cpp
1414import codingstandards.c.misra
1515
16- abstract class ForbiddenType extends Type { }
17-
18- class BuiltinNumericType extends ForbiddenType {
16+ class BuiltinNumericType extends BuiltInType {
1917 BuiltinNumericType ( ) {
2018 /* Exclude the plain char because it does not count as a numeric type */
2119 this .( CharType ) .isExplicitlySigned ( )
@@ -38,15 +36,22 @@ class BuiltinNumericType extends ForbiddenType {
3836 }
3937}
4038
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."
4648}
4749
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