@@ -17,35 +17,49 @@ import cpp
17
17
import codingstandards.cpp.misra
18
18
import codingstandards.cpp.misra.BuiltInTypeRules
19
19
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
+
20
30
/**
21
31
* A `Conversion` that is relevant for the rule.
22
32
*/
23
- abstract class RelevantConversion extends Conversion {
33
+ abstract class RelevantRealConversion extends RelevantConversion , Conversion {
24
34
NumericType fromType ;
25
35
NumericType toType ;
26
36
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
30
40
this .isImplicit ( )
31
41
}
32
42
33
- Type getFromType ( ) { result = fromType }
43
+ override Type getFromType ( ) { result = fromType }
44
+
45
+ override Type getToType ( ) { result = toType }
34
46
35
- Type getToType ( ) { result = toType }
47
+ override Expr getConvertedExpr ( ) { result = this . getExpr ( ) }
36
48
}
37
49
38
- class UsualArithmeticConversion extends RelevantConversion {
50
+ class UsualArithmeticConversion extends RelevantRealConversion {
39
51
UsualArithmeticConversion ( ) {
40
52
(
41
53
exists ( BinaryOperation op | op .getAnOperand ( ) .getFullyConverted ( ) = this ) or
42
54
exists ( UnaryOperation uao | uao .getOperand ( ) .getFullyConverted ( ) = this ) or
43
55
exists ( AssignArithmeticOperation ao | ao .getAnOperand ( ) .getFullyConverted ( ) = this )
44
56
)
45
57
}
58
+
59
+ override string getKindOfConversion ( ) { result = "Usual arithmetic conversion" }
46
60
}
47
61
48
- class IntegerPromotion extends RelevantConversion {
62
+ class IntegerPromotion extends RelevantRealConversion {
49
63
IntegerPromotion ( ) {
50
64
// Only consider cases where the integer promotion is the last conversion applied
51
65
exists ( Expr e | e .getFullyConverted ( ) = this ) and
@@ -61,7 +75,7 @@ class IntegerPromotion extends RelevantConversion {
61
75
from Expr e , RelevantConversion c , NumericType fromType , NumericType toType , string changeType
62
76
where
63
77
not isExcluded ( e , ConversionsPackage:: noSignednessChangeFromPromotionQuery ( ) ) and
64
- c = e . getConversion ( ) and
78
+ c . getConvertedExpr ( ) = e and
65
79
fromType = c .getFromType ( ) and
66
80
toType = c .getToType ( ) and
67
81
(
84
98
toType .getTypeCategory ( ) = FloatingPoint ( )
85
99
)
86
100
select 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