Skip to content

Commit aac2dc2

Browse files
committed
Refactor to use NumericType
1 parent 9aed463 commit aac2dc2

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import codingstandards.cpp.misra
1818
import codingstandards.cpp.misra.BuiltInTypeRules
1919

2020
abstract class RelevantConversion extends Expr {
21-
abstract Type getFromType();
21+
abstract NumericType getFromType();
2222

23-
abstract Type getToType();
23+
abstract NumericType getToType();
2424

2525
abstract Expr getConvertedExpr();
2626

@@ -40,9 +40,9 @@ abstract class RelevantRealConversion extends RelevantConversion, Conversion {
4040
this.isImplicit()
4141
}
4242

43-
override Type getFromType() { result = fromType }
43+
override NumericType getFromType() { result = fromType }
4444

45-
override Type getToType() { result = toType }
45+
override NumericType getToType() { result = toType }
4646

4747
override Expr getConvertedExpr() { result = this.getExpr() }
4848
}
@@ -119,9 +119,9 @@ class ImpliedUsualArithmeticConversion extends RelevantConversion {
119119
)
120120
}
121121

122-
override Type getFromType() { result = fromType }
122+
override NumericType getFromType() { result = fromType }
123123

124-
override Type getToType() { result = toType }
124+
override NumericType getToType() { result = toType }
125125

126126
override Expr getConvertedExpr() { result = this }
127127

@@ -143,11 +143,11 @@ class ImpliedIntegerPromotion extends RelevantConversion {
143143
fromType.getRealSize() < sizeOfInt()
144144
}
145145

146-
override Type getFromType() { result = fromType }
146+
override NumericType getFromType() { result = fromType }
147147

148-
override IntegralType getToType() {
148+
override NumericType getToType() {
149149
// Only report the canonical type - e.g. `int` not `signed int`
150-
result = result.getCanonicalArithmeticType() and
150+
result = result.(IntegralType).getCanonicalArithmeticType() and
151151
if result instanceof Char16Type or result instanceof Char32Type or result instanceof Wchar_t
152152
then
153153
// Smallest type that can hold the value of the `fromType`
@@ -163,8 +163,6 @@ class ImpliedIntegerPromotion extends RelevantConversion {
163163
candidateType order by candidateType.getIntegralUpperBound()
164164
)
165165
else (
166-
// The result is always `int` or `unsigned int`
167-
result instanceof IntType and
168166
if
169167
// If the `fromType` is signed, the result must be signed
170168
fromType.getSignedness() = Signed()
@@ -173,10 +171,12 @@ class ImpliedIntegerPromotion extends RelevantConversion {
173171
// result must be signed as well.
174172
fromType.getIntegralUpperBound() <=
175173
any(IntType t | t.isSigned()).(NumericType).getIntegralUpperBound()
176-
then result.isSigned()
174+
then
175+
// `int` is returned
176+
result.(IntType).isSigned()
177177
else
178-
// Otherwise an unsigned type is returned
179-
result.isUnsigned()
178+
// Otherwise `unsigned int` is returned
179+
result.(IntType).isUnsigned()
180180
)
181181
}
182182

0 commit comments

Comments
 (0)