@@ -293,33 +293,39 @@ def get_all_dependencies_ssa(
293
293
return context .context [KEY_SSA ]
294
294
295
295
296
- def get_must_depends_on (x ):
297
- must_dependencies = compute_must_dependencies (x )
296
+ def get_must_depends_on (variable : SUPPORTED_TYPES ) -> SUPPORTED_TYPES | None :
297
+ """
298
+ Return must dependency of a variable if exist otherwise return None.
299
+
300
+ :param variable: target variable whose must dependency needs to be computed
301
+ :return: Variable | None
302
+ """
303
+ must_dependencies = compute_must_dependencies (variable )
298
304
if len (must_dependencies ) > 1 or len (must_dependencies ) == 0 :
299
305
return None
300
306
return list (must_dependencies )[0 ]
301
307
302
308
303
- def compute_must_dependencies (x ) :
304
- if isinstance (x , (SolidityVariableComposed , Constant )) or (
305
- x .function .visibility in ["public" , "external" ] and x in x .function .parameters
309
+ def compute_must_dependencies (v : SUPPORTED_TYPES ) -> Set [ Variable ] :
310
+ if isinstance (v , (SolidityVariableComposed , Constant )) or (
311
+ v .function .visibility in ["public" , "external" ] and v in v .function .parameters
306
312
):
307
- return set ([x ])
313
+ return set ([v ])
308
314
309
315
function_dependencies = {}
310
316
function_dependencies ["context" ] = {}
311
317
lvalues = []
312
318
313
- for node in x .function .nodes :
319
+ for node in v .function .nodes :
314
320
for ir in node .irs_ssa :
315
321
if isinstance (ir , OperationWithLValue ) and ir .lvalue :
316
322
if isinstance (ir .lvalue , LocalIRVariable ) and ir .lvalue .is_storage :
317
323
continue
318
324
if isinstance (ir .lvalue , ReferenceVariable ):
319
325
lvalue = ir .lvalue .points_to
320
326
if lvalue :
321
- lvalues .append ((lvalue , x .function , ir ))
322
- lvalues .append ((ir .lvalue , x .function , ir ))
327
+ lvalues .append ((lvalue , v .function , ir ))
328
+ lvalues .append ((ir .lvalue , v .function , ir ))
323
329
324
330
for lvalue_details in lvalues :
325
331
lvalue = lvalue_details [0 ]
@@ -335,14 +341,14 @@ def compute_must_dependencies(x):
335
341
read = ir .function .return_values_ssa
336
342
else :
337
343
read = ir .read
338
- for v in read :
339
- # if not isinstance(v , Constant):
340
- function_dependencies ["context" ][lvalue ].add (v )
344
+ for variable in read :
345
+ # if not isinstance(variable , Constant):
346
+ function_dependencies ["context" ][lvalue ].add (variable )
341
347
function_dependencies ["context" ] = convert_to_non_ssa (function_dependencies ["context" ])
342
348
343
349
must_dependencies = set ()
344
350
data_dependencies = (
345
- list (function_dependencies ["context" ][x ])
351
+ list (function_dependencies ["context" ][v ])
346
352
if function_dependencies ["context" ] is not None
347
353
else []
348
354
)
@@ -354,7 +360,6 @@ def compute_must_dependencies(x):
354
360
must_dependencies = must_dependencies .union (result )
355
361
return must_dependencies
356
362
357
-
358
363
# endregion
359
364
###################################################################################
360
365
###################################################################################
0 commit comments