@@ -225,56 +225,52 @@ module SemanticExprConfig {
225225 )
226226 }
227227
228- predicate unaryExpr ( Expr expr , Opcode opcode , SemType type , Expr operand ) {
229- exists ( J:: Expr javaExpr | expr = TPrimaryExpr ( javaExpr ) |
230- type = getSemanticType ( javaExpr . getType ( ) ) and
228+ private predicate primaryUnaryExpr ( J :: Expr javaExpr , Opcode opcode , Expr operand ) {
229+ exists ( J:: UnaryExpr unary | unary = javaExpr |
230+ operand = getResultExpr ( unary . getExpr ( ) ) and
231231 (
232- exists ( J:: UnaryExpr unary | unary = javaExpr |
233- operand = getResultExpr ( unary .getExpr ( ) ) and
234- (
235- unary instanceof J:: MinusExpr and opcode instanceof Opcode:: Negate
236- or
237- unary instanceof J:: PlusExpr and opcode instanceof Opcode:: CopyValue
238- or
239- unary instanceof J:: BitNotExpr and opcode instanceof Opcode:: BitComplement
240- or
241- unary instanceof J:: LogNotExpr and opcode instanceof Opcode:: LogicalNot
242- or
243- unary instanceof J:: PreIncExpr and opcode instanceof Opcode:: AddOne
244- or
245- unary instanceof J:: PreDecExpr and opcode instanceof Opcode:: SubOne
246- or
247- // Post-increment/decrement returns the original value. The actual increment/decrement part
248- // is a separate `Expr`.
249- unary instanceof J:: PostIncExpr and opcode instanceof Opcode:: CopyValue
250- or
251- unary instanceof J:: PostDecExpr and opcode instanceof Opcode:: CopyValue
252- )
253- )
232+ unary instanceof J:: MinusExpr and opcode instanceof Opcode:: Negate
254233 or
255- exists ( J:: CastExpr cast | cast = javaExpr |
256- // TODO: Boolean? Null? Boxing?
257- type instanceof SemNumericType and
258- getSemanticType ( cast .getExpr ( ) .getType ( ) ) instanceof SemNumericType and
259- opcode instanceof Opcode:: Convert and
260- operand = getResultExpr ( cast .getExpr ( ) )
261- )
234+ unary instanceof J:: PlusExpr and opcode instanceof Opcode:: CopyValue
262235 or
263- exists ( J:: AssignExpr assign | assign = javaExpr |
264- opcode instanceof Opcode:: CopyValue and
265- operand = getResultExpr ( assign .getSource ( ) )
266- )
236+ unary instanceof J:: BitNotExpr and opcode instanceof Opcode:: BitComplement
267237 or
268- exists ( J:: LocalVariableDeclExpr decl | decl = javaExpr |
269- opcode instanceof Opcode:: CopyValue and
270- operand = getResultExpr ( decl .getInit ( ) )
271- )
238+ unary instanceof J:: LogNotExpr and opcode instanceof Opcode:: LogicalNot
239+ or
240+ unary instanceof J:: PreIncExpr and opcode instanceof Opcode:: AddOne
241+ or
242+ unary instanceof J:: PreDecExpr and opcode instanceof Opcode:: SubOne
243+ or
244+ // Post-increment/decrement returns the original value. The actual increment/decrement part
245+ // is a separate `Expr`.
246+ unary instanceof J:: PostIncExpr and opcode instanceof Opcode:: CopyValue
247+ or
248+ unary instanceof J:: PostDecExpr and opcode instanceof Opcode:: CopyValue
272249 )
273250 )
274251 or
275- exists ( J:: UnaryAssignExpr javaExpr | javaExpr = expr .( PostUpdateExpr ) .getExpr ( ) |
276- type = getSemanticType ( javaExpr .getType ( ) ) and
277- operand = getResultExpr ( javaExpr .getExpr ( ) ) and
252+ exists ( J:: CastExpr cast | cast = javaExpr |
253+ // TODO: Boolean? Null? Boxing?
254+ getSemanticType ( cast .getType ( ) ) instanceof SemNumericType and
255+ getSemanticType ( cast .getExpr ( ) .getType ( ) ) instanceof SemNumericType and
256+ opcode instanceof Opcode:: Convert and
257+ operand = getResultExpr ( cast .getExpr ( ) )
258+ )
259+ or
260+ exists ( J:: AssignExpr assign | assign = javaExpr |
261+ opcode instanceof Opcode:: CopyValue and
262+ operand = getResultExpr ( assign .getSource ( ) )
263+ )
264+ or
265+ exists ( J:: LocalVariableDeclExpr decl | decl = javaExpr |
266+ opcode instanceof Opcode:: CopyValue and
267+ operand = getResultExpr ( decl .getInit ( ) )
268+ )
269+ }
270+
271+ private predicate postUpdateUnaryExpr ( J:: UnaryAssignExpr javaExpr , Opcode opcode , Expr operand ) {
272+ exists ( J:: UnaryAssignExpr unaryAssign | unaryAssign = javaExpr |
273+ operand = getResultExpr ( unaryAssign .getExpr ( ) ) and
278274 (
279275 javaExpr instanceof J:: PostIncExpr and opcode instanceof Opcode:: AddOne
280276 or
@@ -283,6 +279,22 @@ module SemanticExprConfig {
283279 )
284280 }
285281
282+ private predicate unaryExprWithoutType ( Expr expr , Opcode opcode , Expr operand , J:: Expr javaExpr ) {
283+ primaryUnaryExpr ( javaExpr , opcode , operand ) and
284+ expr = TPrimaryExpr ( javaExpr )
285+ or
286+ postUpdateUnaryExpr ( javaExpr , opcode , operand ) and
287+ expr = TPostUpdateExpr ( javaExpr )
288+ }
289+
290+ predicate unaryExpr ( Expr expr , Opcode opcode , SemType type , Expr operand ) {
291+ exists ( J:: Expr javaExpr , J:: Type javaType |
292+ unaryExprWithoutType ( expr , opcode , operand , javaExpr ) and
293+ javaType = javaExpr .getType ( ) and
294+ type = getSemanticType ( javaType )
295+ )
296+ }
297+
286298 predicate nullaryExpr ( Expr expr , Opcode opcode , SemType type ) {
287299 exists ( ParameterInitExpr paramInit | paramInit = expr |
288300 opcode instanceof Opcode:: InitializeParameter and
0 commit comments