@@ -17,35 +17,49 @@ import cpp
1717import codingstandards.cpp.misra
1818import codingstandards.cpp.misra.BuiltInTypeRules
1919
20+ abstract class RelevantConversion extends Expr {
21+ abstract Type getFromType ( ) ;
22+
23+ abstract Type getToType ( ) ;
24+
25+ abstract Expr getConvertedExpr ( ) ;
26+
27+ abstract string getKindOfConversion ( ) ;
28+ }
29+
2030/**
2131 * A `Conversion` that is relevant for the rule.
2232 */
23- abstract class RelevantConversion extends Conversion {
33+ abstract class RelevantRealConversion extends RelevantConversion , Conversion {
2434 NumericType fromType ;
2535 NumericType toType ;
2636
27- RelevantConversion ( ) {
28- fromType = this .getExpr ( ) .getType ( ) . getUnspecifiedType ( ) and
29- toType = this .getType ( ) . getUnspecifiedType ( ) and
37+ RelevantRealConversion ( ) {
38+ fromType = this .getExpr ( ) .getType ( ) and
39+ toType = this .getType ( ) and
3040 this .isImplicit ( )
3141 }
3242
33- Type getFromType ( ) { result = fromType }
43+ override Type getFromType ( ) { result = fromType }
44+
45+ override Type getToType ( ) { result = toType }
3446
35- Type getToType ( ) { result = toType }
47+ override Expr getConvertedExpr ( ) { result = this . getExpr ( ) }
3648}
3749
38- class UsualArithmeticConversion extends RelevantConversion {
50+ class UsualArithmeticConversion extends RelevantRealConversion {
3951 UsualArithmeticConversion ( ) {
4052 (
4153 exists ( BinaryOperation op | op .getAnOperand ( ) .getFullyConverted ( ) = this ) or
4254 exists ( UnaryOperation uao | uao .getOperand ( ) .getFullyConverted ( ) = this ) or
4355 exists ( AssignArithmeticOperation ao | ao .getAnOperand ( ) .getFullyConverted ( ) = this )
4456 )
4557 }
58+
59+ override string getKindOfConversion ( ) { result = "Usual arithmetic conversion" }
4660}
4761
48- class IntegerPromotion extends RelevantConversion {
62+ class IntegerPromotion extends RelevantRealConversion {
4963 IntegerPromotion ( ) {
5064 // Only consider cases where the integer promotion is the last conversion applied
5165 exists ( Expr e | e .getFullyConverted ( ) = this ) and
@@ -61,7 +75,7 @@ class IntegerPromotion extends RelevantConversion {
6175from Expr e , RelevantConversion c , NumericType fromType , NumericType toType , string changeType
6276where
6377 not isExcluded ( e , ConversionsPackage:: noSignednessChangeFromPromotionQuery ( ) ) and
64- c = e . getConversion ( ) and
78+ c . getConvertedExpr ( ) = e and
6579 fromType = c .getFromType ( ) and
6680 toType = c .getToType ( ) and
6781 (
8498 toType .getTypeCategory ( ) = FloatingPoint ( )
8599 )
86100select e ,
87- "Conversion from '" + fromType .getName ( ) + "' to '" + toType .getName ( ) + "' changes " + changeType
88- + "."
101+ c . getKindOfConversion ( ) + " from '" + fromType .getName ( ) + "' to '" + toType .getName ( ) +
102+ "' changes " + changeType + "."
0 commit comments