@@ -1091,34 +1091,24 @@ private import GetConvertedResultExpression
1091
1091
predicate exprNodeShouldBeOperand ( OperandNode node , Expr e ) {
1092
1092
exists ( Instruction def |
1093
1093
unique( | | getAUse ( def ) ) = node .getOperand ( ) and
1094
- e = def . getConvertedResultExpression ( )
1094
+ e = getConvertedResultExpression ( def )
1095
1095
)
1096
1096
}
1097
1097
1098
- private predicate indirectExprNodeShouldBeIndirectOperand0 (
1099
- VariableAddressInstruction instr , RawIndirectOperand node , Expr e
1100
- ) {
1101
- instr = node .getOperand ( ) .getDef ( ) and
1102
- e = instr .getAst ( ) .( Expr ) .getUnconverted ( )
1103
- }
1104
-
1105
1098
/** Holds if `node` should be an `IndirectOperand` that maps `node.asIndirectExpr()` to `e`. */
1106
- private predicate indirectExprNodeShouldBeIndirectOperand ( RawIndirectOperand node , Expr e ) {
1107
- exists ( Instruction instr | instr = node .getOperand ( ) .getDef ( ) |
1108
- exists ( Expr e0 |
1109
- indirectExprNodeShouldBeIndirectOperand0 ( instr , node , e0 ) and
1110
- e = e0 .getFullyConverted ( )
1111
- )
1112
- or
1113
- not indirectExprNodeShouldBeIndirectOperand0 ( _, node , _) and
1114
- e = instr .getConvertedResultExpression ( )
1099
+ private predicate indirectExprNodeShouldBeIndirectOperand (
1100
+ IndirectOperand node , Expr e , int indirectionIndex
1101
+ ) {
1102
+ exists ( Instruction def |
1103
+ node .hasOperandAndIndirectionIndex ( unique( | | getAUse ( def ) ) , indirectionIndex ) and
1104
+ e = getConvertedResultExpression ( def )
1115
1105
)
1116
1106
}
1117
1107
1118
1108
private predicate exprNodeShouldBeIndirectOutNode ( IndirectArgumentOutNode node , Expr e ) {
1119
1109
exists ( CallInstruction call |
1120
1110
call .getStaticCallTarget ( ) instanceof Constructor and
1121
- e = call . getConvertedResultExpression ( ) and
1111
+ e = getConvertedResultExpression ( call ) and
1122
1112
call .getThisArgumentOperand ( ) = node .getAddressOperand ( )
1123
1113
)
1124
1114
}
@@ -1127,37 +1117,17 @@ private predicate exprNodeShouldBeIndirectOutNode(IndirectArgumentOutNode node,
1127
1117
predicate exprNodeShouldBeInstruction ( Node node , Expr e ) {
1128
1118
not exprNodeShouldBeOperand ( _, e ) and
1129
1119
not exprNodeShouldBeIndirectOutNode ( _, e ) and
1130
- (
1131
- e = node .asInstruction ( ) .getConvertedResultExpression ( )
1132
- or
1133
- // The instruction that contains the result of an `AssignOperation` is
1134
- // the unloaded left operand (see the comments in `TranslatedAssignOperation`).
1135
- // That means that for cases like
1136
- // ```cpp
1137
- // int x = ...;
1138
- // x += 1;
1139
- // ```
1140
- // the result of `x += 1` is the `VariableAddressInstruction` that represents `x`. But
1141
- // that instruction doesn't receive the flow from this `AssignOperation`. So instead we
1142
- // map the operation to the `AddInstruction`.
1143
- node .asInstruction ( ) .getAst ( ) = e .( AssignOperation )
1144
- or
1145
- // Same story for `CrementOperation`s (cf. the comments in the subclasses
1146
- // of `TranslatedCrementOperation`).
1147
- node .asInstruction ( ) .getAst ( ) = e .( CrementOperation )
1148
- )
1120
+ e = getConvertedResultExpression ( node .asInstruction ( ) )
1149
1121
}
1150
1122
1151
1123
/** Holds if `node` should be an `IndirectInstruction` that maps `node.asIndirectExpr()` to `e`. */
1152
- predicate indirectExprNodeShouldBeIndirectInstruction ( IndirectInstruction node , Expr e ) {
1124
+ predicate indirectExprNodeShouldBeIndirectInstruction (
1125
+ IndirectInstruction node , Expr e , int indirectionIndex
1126
+ ) {
1127
+ not indirectExprNodeShouldBeIndirectOperand ( _, e , indirectionIndex ) and
1153
1128
exists ( Instruction instr |
1154
- node .hasInstructionAndIndirectionIndex ( instr , _) and
1155
- not indirectExprNodeShouldBeIndirectOperand ( _, e )
1156
- |
1157
- e = instr .( VariableAddressInstruction ) .getAst ( ) .( Expr ) .getFullyConverted ( )
1158
- or
1159
- not instr instanceof VariableAddressInstruction and
1160
- e = instr .getConvertedResultExpression ( )
1129
+ node .hasInstructionAndIndirectionIndex ( instr , indirectionIndex ) and
1130
+ e = getConvertedResultExpression ( instr )
1161
1131
)
1162
1132
}
1163
1133
@@ -1169,27 +1139,19 @@ abstract private class ExprNodeBase extends Node {
1169
1139
abstract Expr getConvertedExpr ( ) ;
1170
1140
1171
1141
/** Gets the non-conversion expression corresponding to this node, if any. */
1172
- abstract Expr getExpr ( ) ;
1142
+ final Expr getExpr ( ) { result = this . getConvertedExpr ( ) . getUnconverted ( ) }
1173
1143
}
1174
1144
1175
1145
private class InstructionExprNode extends ExprNodeBase , InstructionNode {
1176
1146
InstructionExprNode ( ) { exprNodeShouldBeInstruction ( this , _) }
1177
1147
1178
1148
final override Expr getConvertedExpr ( ) { exprNodeShouldBeInstruction ( this , result ) }
1179
-
1180
- final override Expr getExpr ( ) { result = this .getConvertedExpr ( ) .getUnconverted ( ) }
1181
-
1182
- final override string toStringImpl ( ) { result = this .getConvertedExpr ( ) .toString ( ) }
1183
1149
}
1184
1150
1185
1151
private class OperandExprNode extends ExprNodeBase , OperandNode {
1186
1152
OperandExprNode ( ) { exprNodeShouldBeOperand ( this , _) }
1187
1153
1188
1154
final override Expr getConvertedExpr ( ) { exprNodeShouldBeOperand ( this , result ) }
1189
-
1190
- final override Expr getExpr ( ) { result = this .getConvertedExpr ( ) .getUnconverted ( ) }
1191
-
1192
- final override string toStringImpl ( ) { result = this .getConvertedExpr ( ) .toString ( ) }
1193
1155
}
1194
1156
1195
1157
abstract private class IndirectExprNodeBase extends Node {
@@ -1200,45 +1162,33 @@ abstract private class IndirectExprNodeBase extends Node {
1200
1162
abstract Expr getConvertedExpr ( int indirectionIndex ) ;
1201
1163
1202
1164
/** Gets the non-conversion expression corresponding to this node, if any. */
1203
- abstract Expr getExpr ( int indirectionIndex ) ;
1165
+ final Expr getExpr ( int indirectionIndex ) {
1166
+ result = this .getConvertedExpr ( indirectionIndex ) .getUnconverted ( )
1167
+ }
1204
1168
}
1205
1169
1206
- private class IndirectOperandIndirectExprNode extends IndirectExprNodeBase , RawIndirectOperand {
1207
- IndirectOperandIndirectExprNode ( ) { indirectExprNodeShouldBeIndirectOperand ( this , _) }
1170
+ private class IndirectOperandIndirectExprNode extends IndirectExprNodeBase instanceof IndirectOperand
1171
+ {
1172
+ IndirectOperandIndirectExprNode ( ) { indirectExprNodeShouldBeIndirectOperand ( this , _, _) }
1208
1173
1209
1174
final override Expr getConvertedExpr ( int index ) {
1210
- this .getIndirectionIndex ( ) = index and
1211
- indirectExprNodeShouldBeIndirectOperand ( this , result )
1212
- }
1213
-
1214
- final override Expr getExpr ( int index ) {
1215
- this .getIndirectionIndex ( ) = index and
1216
- result = this .getConvertedExpr ( index ) .getUnconverted ( )
1175
+ indirectExprNodeShouldBeIndirectOperand ( this , result , index )
1217
1176
}
1218
1177
}
1219
1178
1220
- private class IndirectInstructionIndirectExprNode extends IndirectExprNodeBase ,
1221
- RawIndirectInstruction
1179
+ private class IndirectInstructionIndirectExprNode extends IndirectExprNodeBase instanceof IndirectInstruction
1222
1180
{
1223
- IndirectInstructionIndirectExprNode ( ) { indirectExprNodeShouldBeIndirectInstruction ( this , _) }
1181
+ IndirectInstructionIndirectExprNode ( ) { indirectExprNodeShouldBeIndirectInstruction ( this , _, _ ) }
1224
1182
1225
1183
final override Expr getConvertedExpr ( int index ) {
1226
- this .getIndirectionIndex ( ) = index and
1227
- indirectExprNodeShouldBeIndirectInstruction ( this , result )
1228
- }
1229
-
1230
- final override Expr getExpr ( int index ) {
1231
- this .getIndirectionIndex ( ) = index and
1232
- result = this .getConvertedExpr ( index ) .getUnconverted ( )
1184
+ indirectExprNodeShouldBeIndirectInstruction ( this , result , index )
1233
1185
}
1234
1186
}
1235
1187
1236
1188
private class IndirectArgumentOutExprNode extends ExprNodeBase , IndirectArgumentOutNode {
1237
1189
IndirectArgumentOutExprNode ( ) { exprNodeShouldBeIndirectOutNode ( this , _) }
1238
1190
1239
1191
final override Expr getConvertedExpr ( ) { exprNodeShouldBeIndirectOutNode ( this , result ) }
1240
-
1241
- final override Expr getExpr ( ) { result = this .getConvertedExpr ( ) }
1242
1192
}
1243
1193
1244
1194
/**
0 commit comments