|
12 | 12 |
|
13 | 13 | import cpp
|
14 | 14 | import codingstandards.c.misra
|
| 15 | +import codingstandards.cpp.Compiler |
15 | 16 |
|
16 |
| -predicate isAppropriatePrimitive(Type type) { |
17 |
| - /* An appropriate primitive types to which a bit-field can be declared. */ |
18 |
| - type instanceof IntType and |
| 17 | +Type getSupportedBitFieldType(Compiler compiler) { |
| 18 | + compiler instanceof UnsupportedCompiler and |
19 | 19 | (
|
20 |
| - type.(IntegralType).isExplicitlySigned() or |
21 |
| - type.(IntegralType).isExplicitlyUnsigned() |
| 20 | + result instanceof IntType and |
| 21 | + ( |
| 22 | + result.(IntegralType).isExplicitlySigned() or |
| 23 | + result.(IntegralType).isExplicitlyUnsigned() |
| 24 | + ) |
| 25 | + or |
| 26 | + result instanceof BoolType |
22 | 27 | )
|
23 | 28 | or
|
24 |
| - type instanceof BoolType |
| 29 | + (compiler instanceof Gcc or compiler instanceof Clang) and |
| 30 | + ( |
| 31 | + result instanceof IntegralOrEnumType |
| 32 | + or |
| 33 | + result instanceof BoolType |
| 34 | + ) |
25 | 35 | }
|
26 | 36 |
|
27 | 37 | from BitField bitField
|
28 | 38 | where
|
29 | 39 | not isExcluded(bitField,
|
30 | 40 | BitfieldTypesPackage::bitFieldsShallOnlyBeDeclaredWithAnAppropriateTypeQuery()) and
|
31 | 41 | /* A violation would neither be an appropriate primitive type nor an appropriate typedef. */
|
32 |
| - not isAppropriatePrimitive(bitField.getType().resolveTypedefs()) |
33 |
| -select bitField, "Bit-field " + bitField + " is declared on type " + bitField.getType() + "." |
| 42 | + not getSupportedBitFieldType(getCompiler(bitField.getFile())) = |
| 43 | + bitField.getType().resolveTypedefs() |
| 44 | +select bitField, "Bit-field '" + bitField + "' is declared on type '" + bitField.getType() + "'." |
0 commit comments