@@ -85,19 +85,36 @@ newtype Signedness =
8585 Signed ( ) or
8686 Unsigned ( )
8787
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
9099 BuiltInType builtInType ;
91100
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 ) }
97102
98103 private BuiltInType getBuiltInType ( ) { result = builtInType }
99104
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+ }
101118}
102119
103120/**
@@ -108,25 +125,16 @@ class CharacterType extends Type {
108125 * - Typedef'd types that are numeric types.
109126 * - Numeric types with specifiers (e.g., `const`, `volatile`, `restrict`).
110127 */
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 {
115129 NumericType ( ) {
116130 // 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 ( ) ]
119132 }
120133
121134 Signedness getSignedness ( ) {
122135 if builtInType .( IntegralType ) .isUnsigned ( ) then result = Unsigned ( ) else result = Signed ( )
123136 }
124137
125- /** Gets the size of the actual numeric type. */
126- int getRealSize ( ) { result = builtInType .getSize ( ) }
127-
128- TypeCategory getTypeCategory ( ) { result = getBuiltInTypeCategory ( builtInType ) }
129-
130138 /**
131139 * Gets the integeral upper bound of the numeric type, if it represents an integer type.
132140 */
@@ -136,10 +144,6 @@ class NumericType extends Type {
136144 * Gets the integeral lower bound of the numeric type, if it represents an integer type.
137145 */
138146 QlBuiltins:: BigInt getIntegralLowerBound ( ) { integralTypeBounds ( builtInType , result , _) }
139-
140- private BuiltInType getBuiltInType ( ) { result = builtInType }
141-
142- predicate isSameType ( NumericType other ) { this .getBuiltInType ( ) = other .getBuiltInType ( ) }
143147}
144148
145149predicate isSignedType ( NumericType t ) { t .getSignedness ( ) = Signed ( ) }
@@ -300,7 +304,7 @@ CanonicalIntegerNumericType getBitFieldType(BitField bf) {
300304 other .getSize ( ) * 8 >= bf .getNumBits ( ) and
301305 other .getSignedness ( ) = result .getSignedness ( )
302306 |
303- other .getSize ( ) < result .getRealSize ( )
307+ other .getSize ( ) < result .getBuiltInSize ( )
304308 )
305309 )
306310}
0 commit comments