@@ -85,19 +85,36 @@ newtype Signedness =
85
85
Signed ( ) or
86
86
Unsigned ( )
87
87
88
- class CharacterType extends Type {
89
- // The actual character type, which is either a plain char or a wide char
88
+ /**
89
+ * A `Type` which is considered to be a built-in type by MISRA.
90
+ *
91
+ * It differs from `BuiltInType` in that includes:
92
+ * - Built in types with specifiers (e.g., `const`, `volatile`, `restrict`).
93
+ * - Typedefs to built in types
94
+ * - References to built in types
95
+ * - Enum types with an explicit underlying type that is a built-in type.
96
+ */
97
+ class MisraBuiltInType extends Type {
98
+ // The built in type underlying this MISRA built in type
90
99
BuiltInType builtInType ;
91
100
92
- CharacterType ( ) {
93
- // A type whose type category is character
94
- getBuiltInTypeCategory ( builtInType ) = Character ( ) and
95
- builtInType = getBuiltInType ( this )
96
- }
101
+ MisraBuiltInType ( ) { builtInType = getBuiltInType ( this ) }
97
102
98
103
private BuiltInType getBuiltInType ( ) { result = builtInType }
99
104
100
- predicate isSameType ( CharacterType other ) { this .getBuiltInType ( ) = other .getBuiltInType ( ) }
105
+ /** Gets the size of the underlying built in type. */
106
+ int getBuiltInSize ( ) { result = builtInType .getSize ( ) }
107
+
108
+ TypeCategory getTypeCategory ( ) { result = getBuiltInTypeCategory ( builtInType ) }
109
+
110
+ predicate isSameType ( MisraBuiltInType other ) { this .getBuiltInType ( ) = other .getBuiltInType ( ) }
111
+ }
112
+
113
+ class CharacterType extends MisraBuiltInType {
114
+ CharacterType ( ) {
115
+ // A type whose type category is character
116
+ getBuiltInTypeCategory ( builtInType ) = Character ( )
117
+ }
101
118
}
102
119
103
120
/**
@@ -108,25 +125,16 @@ class CharacterType extends Type {
108
125
* - Typedef'd types that are numeric types.
109
126
* - Numeric types with specifiers (e.g., `const`, `volatile`, `restrict`).
110
127
*/
111
- class NumericType extends Type {
112
- // The actual numeric type, which is either an integral or a floating-point type.
113
- BuiltInType builtInType ;
114
-
128
+ class NumericType extends MisraBuiltInType {
115
129
NumericType ( ) {
116
130
// A type whose type category is either integral or a floating-point
117
- getBuiltInTypeCategory ( builtInType ) = [ Integral ( ) .( TypeCategory ) , FloatingPoint ( ) ] and
118
- builtInType = getBuiltInType ( this )
131
+ getBuiltInTypeCategory ( builtInType ) = [ Integral ( ) .( TypeCategory ) , FloatingPoint ( ) ]
119
132
}
120
133
121
134
Signedness getSignedness ( ) {
122
135
if builtInType .( IntegralType ) .isUnsigned ( ) then result = Unsigned ( ) else result = Signed ( )
123
136
}
124
137
125
- /** Gets the size of the actual numeric type. */
126
- int getRealSize ( ) { result = builtInType .getSize ( ) }
127
-
128
- TypeCategory getTypeCategory ( ) { result = getBuiltInTypeCategory ( builtInType ) }
129
-
130
138
/**
131
139
* Gets the integeral upper bound of the numeric type, if it represents an integer type.
132
140
*/
@@ -136,10 +144,6 @@ class NumericType extends Type {
136
144
* Gets the integeral lower bound of the numeric type, if it represents an integer type.
137
145
*/
138
146
QlBuiltins:: BigInt getIntegralLowerBound ( ) { integralTypeBounds ( builtInType , result , _) }
139
-
140
- private BuiltInType getBuiltInType ( ) { result = builtInType }
141
-
142
- predicate isSameType ( NumericType other ) { this .getBuiltInType ( ) = other .getBuiltInType ( ) }
143
147
}
144
148
145
149
predicate isSignedType ( NumericType t ) { t .getSignedness ( ) = Signed ( ) }
@@ -300,7 +304,7 @@ CanonicalIntegerNumericType getBitFieldType(BitField bf) {
300
304
other .getSize ( ) * 8 >= bf .getNumBits ( ) and
301
305
other .getSignedness ( ) = result .getSignedness ( )
302
306
|
303
- other .getSize ( ) < result .getRealSize ( )
307
+ other .getSize ( ) < result .getBuiltInSize ( )
304
308
)
305
309
)
306
310
}