@@ -10,6 +10,10 @@ private module Impl {
1010 TPrimaryExpr ( J:: Expr e ) or
1111 TPostUpdateExpr ( J:: UnaryAssignExpr e ) {
1212 e instanceof J:: PostIncExpr or e instanceof J:: PostDecExpr
13+ } or
14+ TEnhancedForInit ( J:: EnhancedForStmt for ) or
15+ TParameterInit ( SSA:: SsaImplicitInit init , J:: Parameter param ) {
16+ init .isParameterDefinition ( param )
1317 }
1418
1519 TExpr getResultExpr ( J:: Expr e ) { result = TPrimaryExpr ( e ) }
@@ -22,6 +26,8 @@ module SemanticExprConfig {
2226 string toString ( ) { none ( ) }
2327
2428 J:: Location getLocation ( ) { none ( ) }
29+
30+ J:: BasicBlock getBasicBlock ( ) { none ( ) }
2531 }
2632
2733 private class PrimaryExpr extends Expr , TPrimaryExpr {
@@ -33,6 +39,8 @@ module SemanticExprConfig {
3339
3440 override J:: Location getLocation ( ) { result = e .getLocation ( ) }
3541
42+ override J:: BasicBlock getBasicBlock ( ) { result = e .getBasicBlock ( ) }
43+
3644 J:: Expr getExpr ( ) { result = e }
3745 }
3846
@@ -45,14 +53,43 @@ module SemanticExprConfig {
4553
4654 override J:: Location getLocation ( ) { result = e .getLocation ( ) }
4755
56+ override J:: BasicBlock getBasicBlock ( ) { result = e .getBasicBlock ( ) }
57+
4858 J:: UnaryAssignExpr getExpr ( ) { result = e }
4959 }
5060
61+ private class EnhancedForInitExpr extends Expr , TEnhancedForInit {
62+ J:: EnhancedForStmt for ;
63+
64+ EnhancedForInitExpr ( ) { this = TEnhancedForInit ( for ) }
65+
66+ override string toString ( ) { result = "init of " + for .getVariable ( ) .toString ( ) }
67+
68+ override J:: Location getLocation ( ) { result = for .getVariable ( ) .getLocation ( ) }
69+
70+ override J:: BasicBlock getBasicBlock ( ) { result = for .getVariable ( ) .getBasicBlock ( ) }
71+ }
72+
73+ private class ParameterInitExpr extends Expr , TParameterInit {
74+ SSA:: SsaImplicitInit init ;
75+ J:: Parameter param ;
76+
77+ ParameterInitExpr ( ) { this = TParameterInit ( init , param ) }
78+
79+ override string toString ( ) { result = "param init: " + init .toString ( ) }
80+
81+ override J:: Location getLocation ( ) { result = init .getLocation ( ) }
82+
83+ override J:: BasicBlock getBasicBlock ( ) { result = init .getBasicBlock ( ) }
84+
85+ final J:: Parameter getParameter ( ) { result = param }
86+ }
87+
5188 string exprToString ( Expr e ) { result = e .toString ( ) }
5289
5390 J:: Location getExprLocation ( Expr e ) { result = e .getLocation ( ) }
5491
55- SemBasicBlock getExprBasicBlock ( Expr e ) { result . getAnExpr ( ) = e }
92+ SemBasicBlock getExprBasicBlock ( Expr e ) { result = getSemanticBasicBlock ( e . getBasicBlock ( ) ) }
5693
5794 predicate integerLiteral ( Expr expr , SemIntegerType type , int value ) {
5895 exists ( J:: Expr javaExpr | javaExpr = expr .( PrimaryExpr ) .getExpr ( ) |
@@ -172,7 +209,8 @@ module SemanticExprConfig {
172209 assignOp instanceof J:: AssignRShiftExpr and opcode instanceof Opcode:: ShiftRight
173210 or
174211 // TODO: Add new opcode or add an implicit conversion
175- assignOp instanceof J:: AssignURShiftExpr and opcode instanceof Opcode:: ShiftRightUnsigned
212+ assignOp instanceof J:: AssignURShiftExpr and
213+ opcode instanceof Opcode:: ShiftRightUnsigned
176214 )
177215 )
178216 )
@@ -237,13 +275,15 @@ module SemanticExprConfig {
237275 )
238276 }
239277
240- predicate loadExpr ( Expr expr , SemType type ) {
241- type = getSemanticType ( expr .( PrimaryExpr ) .getExpr ( ) .( J:: RValue ) .getType ( ) )
242- }
243-
244- SemSsaVariable getLoadDef ( Expr expr ) {
245- exists ( SSA:: SsaVariable var | expr .( PrimaryExpr ) .getExpr ( ) = var .getAUse ( ) |
246- result = getSemanticSsaVariable ( var )
278+ predicate nullaryExpr ( Expr expr , Opcode opcode , SemType type ) {
279+ exists ( ParameterInitExpr paramInit | paramInit = expr |
280+ opcode instanceof Opcode:: InitializeParameter and
281+ type = getSemanticType ( paramInit .getParameter ( ) .getType ( ) )
282+ )
283+ or
284+ exists ( J:: RValue rval | rval = expr .( PrimaryExpr ) .getExpr ( ) |
285+ type = getSemanticType ( rval .getType ( ) ) and
286+ opcode instanceof Opcode:: Load
247287 )
248288 }
249289
@@ -260,6 +300,10 @@ module SemanticExprConfig {
260300
261301 SemType getUnknownExprType ( Expr expr ) {
262302 result = getSemanticType ( expr .( PrimaryExpr ) .getExpr ( ) .getType ( ) )
303+ or
304+ exists ( J:: EnhancedForStmt for | expr = TEnhancedForInit ( for ) |
305+ result = getSemanticType ( for .getVariable ( ) .getType ( ) )
306+ )
263307 }
264308}
265309
@@ -282,5 +326,12 @@ SemExpr getUpdateExpr(SSA::SsaExplicitUpdate update) {
282326 or
283327 ( expr instanceof J:: PostIncExpr or expr instanceof J:: PostDecExpr ) and
284328 result = TPostUpdateExpr ( expr )
329+ or
330+ exists ( J:: EnhancedForStmt for |
331+ for .getVariable ( ) = expr and
332+ result = TEnhancedForInit ( for )
333+ )
285334 )
286335}
336+
337+ SemExpr getEnhancedForInitExpr ( J:: EnhancedForStmt for ) { result = TEnhancedForInit ( for ) }
0 commit comments