Skip to content

Commit 8be7b3c

Browse files
committed
BuiltInTypeRules: Add isSameType API
1 parent 9ddf645 commit 8be7b3c

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ class CharacterType extends Type {
9595
builtInType = getBuiltInType(this)
9696
}
9797

98-
BuiltInType getRealType() { result = builtInType }
98+
private BuiltInType getBuiltInType() { result = builtInType }
99+
100+
predicate isSameType(CharacterType other) { this.getBuiltInType() = other.getBuiltInType() }
99101
}
100102

101103
/**
@@ -135,7 +137,9 @@ class NumericType extends Type {
135137
*/
136138
QlBuiltins::BigInt getIntegralLowerBound() { integralTypeBounds(builtInType, result, _) }
137139

138-
BuiltInType getRealType() { result = builtInType }
140+
private BuiltInType getBuiltInType() { result = builtInType }
141+
142+
predicate isSameType(NumericType other) { this.getBuiltInType() = other.getBuiltInType() }
139143
}
140144

141145
predicate isSignedType(NumericType t) { t.getSignedness() = Signed() }

cpp/misra/src/rules/RULE-7-0-3/NoCharacterNumericalValue.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ where
3535
eq.getAnOperand() = expr and
3636
leftType = eq.getLeftOperand().getType() and
3737
rightType = eq.getRightOperand().getType() and
38-
leftType.getRealType() = rightType.getRealType()
38+
leftType.isSameType(rightType)
3939
) and
4040
// Exclude unevaluated operands
4141
not expr.isUnevaluated()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class ImpliedUsualArithmeticConversion extends IntegerPromotionOrUsualArithmetic
125125
// type will be the same as the converted type of the rvalue.
126126
toType = aop.getRValue().getFullyConverted().getType() and
127127
// Only consider cases where the conversion is not a no-op, for consistency with the `Conversion` class
128-
not fromType.getRealType() = toType.getRealType()
128+
not fromType.isSameType(toType)
129129
)
130130
}
131131

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ predicate isValidAssignment(Expr source, NumericType targetType, string context)
196196
isAssignment(source, targetType, context) and
197197
exists(NumericType sourceType | sourceType = source.getType() |
198198
if shouldHaveSameType(source)
199-
then sourceType.getRealType() = targetType.getRealType()
199+
then sourceType.isSameType(targetType)
200200
else (
201201
// Valid type match
202202
isValidTypeMatch(sourceType, targetType)

0 commit comments

Comments
 (0)