Skip to content

Commit 5ca11e9

Browse files
committed
Add TypeCategory suffix
1 parent 2c97905 commit 5ca11e9

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

cpp/misra/src/codingstandards/cpp/misra/BuiltInTypeRules.qll

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ module MisraCpp23BuiltInTypes {
1313
* A MISRA C++ 2023 type category.
1414
*/
1515
newtype TypeCategory =
16-
Integral() or
17-
FloatingPoint() or
18-
Character() or
19-
Other()
16+
IntegralTypeCategory() or
17+
FloatingPointTypeCategory() or
18+
CharacterTypeCategory() or
19+
OtherTypeCategory()
2020

2121
/**
2222
* Gets the type category of a built-in type.
@@ -31,7 +31,7 @@ module MisraCpp23BuiltInTypes {
3131
t instanceof Char32Type or
3232
t instanceof Char8Type
3333
) and
34-
result = Character()
34+
result = CharacterTypeCategory()
3535
or
3636
(
3737
// The 5 standard integral types, covering both signed/unsigned variants
@@ -43,21 +43,21 @@ module MisraCpp23BuiltInTypes {
4343
t instanceof LongType or
4444
t instanceof LongLongType
4545
) and
46-
result = Integral()
46+
result = IntegralTypeCategory()
4747
or
4848
(
4949
t instanceof FloatType or
5050
t instanceof DoubleType or
5151
t instanceof LongDoubleType
5252
) and
53-
result = FloatingPoint()
53+
result = FloatingPointTypeCategory()
5454
or
5555
(
5656
t instanceof BoolType or
5757
t instanceof VoidType or
5858
t instanceof NullPointerType
5959
) and
60-
result = Other()
60+
result = OtherTypeCategory()
6161
}
6262

6363
/**
@@ -119,7 +119,7 @@ module MisraCpp23BuiltInTypes {
119119
class CharacterType extends MisraBuiltInType {
120120
CharacterType() {
121121
// A type whose type category is character
122-
getBuiltInTypeCategory(builtInType) = Character()
122+
getBuiltInTypeCategory(builtInType) = CharacterTypeCategory()
123123
}
124124
}
125125

@@ -134,7 +134,8 @@ module MisraCpp23BuiltInTypes {
134134
class NumericType extends MisraBuiltInType {
135135
NumericType() {
136136
// A type whose type category is either integral or a floating-point
137-
getBuiltInTypeCategory(builtInType) = [Integral().(TypeCategory), FloatingPoint()]
137+
getBuiltInTypeCategory(builtInType) =
138+
[IntegralTypeCategory().(TypeCategory), FloatingPointTypeCategory()]
138139
}
139140

140141
Signedness getSignedness() {

cpp/misra/src/rules/RULE-7-0-5/NoSignednessChangeFromPromotion.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ class IntegerPromotion extends IntegerPromotionOrUsualArithmeticConversionAsCast
9797
// This deliberately excludes integer promotions from `bool` and unscoped enums which do not
9898
// have a fixed underlying type, because neither of these are considered integral types in the
9999
// MISRA C++ rules.
100-
fromType.getTypeCategory() = MisraCpp23BuiltInTypes::Integral() and
101-
toType.getTypeCategory() = MisraCpp23BuiltInTypes::Integral()
100+
fromType.getTypeCategory() = MisraCpp23BuiltInTypes::IntegralTypeCategory() and
101+
toType.getTypeCategory() = MisraCpp23BuiltInTypes::IntegralTypeCategory()
102102
}
103103

104104
override string getKindOfConversion() { result = "Integer promotion" }
@@ -150,7 +150,7 @@ class ImpliedIntegerPromotion extends IntegerPromotionOrUsualArithmeticConversio
150150
// However, you cannot have an integer promotion on a float, so we restrict
151151
// this to integral types only
152152
fromType = this.getType() and
153-
fromType.getTypeCategory() = MisraCpp23BuiltInTypes::Integral() and
153+
fromType.getTypeCategory() = MisraCpp23BuiltInTypes::IntegralTypeCategory() and
154154
// If the size is less than int, then it is an implied integer promotion
155155
fromType.getBuiltInSize() < sizeOfInt()
156156
}
@@ -223,8 +223,8 @@ where
223223
// Exception 2: allow safe conversions from integral to floating-point types
224224
not (
225225
e.isConstant() and
226-
fromType.getTypeCategory() = MisraCpp23BuiltInTypes::Integral() and
227-
toType.getTypeCategory() = MisraCpp23BuiltInTypes::FloatingPoint()
226+
fromType.getTypeCategory() = MisraCpp23BuiltInTypes::IntegralTypeCategory() and
227+
toType.getTypeCategory() = MisraCpp23BuiltInTypes::FloatingPointTypeCategory()
228228
)
229229
select e,
230230
c.getKindOfConversion() + " from '" + fromType.getName() + "' to '" + toType.getName() +

cpp/misra/src/rules/RULE-7-0-6/NumericAssignmentTypeMismatch.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ predicate isValidConstantAssignment(
4848
val <= targetType.getIntegralUpperBound()
4949
or
5050
// All floating point types can represent all integer values
51-
targetType.getTypeCategory() = MisraCpp23BuiltInTypes::FloatingPoint()
51+
targetType.getTypeCategory() = MisraCpp23BuiltInTypes::FloatingPointTypeCategory()
5252
)
5353
)
5454
}

0 commit comments

Comments
 (0)