Skip to content

Commit fcb0aed

Browse files
committed
function arguments, return value type added
1 parent a159d60 commit fcb0aed

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

slither/analyses/data_dependency/data_dependency.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -293,33 +293,39 @@ def get_all_dependencies_ssa(
293293
return context.context[KEY_SSA]
294294

295295

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)
298304
if len(must_dependencies) > 1 or len(must_dependencies) == 0:
299305
return None
300306
return list(must_dependencies)[0]
301307

302308

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
306312
):
307-
return set([x])
313+
return set([v])
308314

309315
function_dependencies = {}
310316
function_dependencies["context"] = {}
311317
lvalues = []
312318

313-
for node in x.function.nodes:
319+
for node in v.function.nodes:
314320
for ir in node.irs_ssa:
315321
if isinstance(ir, OperationWithLValue) and ir.lvalue:
316322
if isinstance(ir.lvalue, LocalIRVariable) and ir.lvalue.is_storage:
317323
continue
318324
if isinstance(ir.lvalue, ReferenceVariable):
319325
lvalue = ir.lvalue.points_to
320326
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))
323329

324330
for lvalue_details in lvalues:
325331
lvalue = lvalue_details[0]
@@ -335,14 +341,14 @@ def compute_must_dependencies(x):
335341
read = ir.function.return_values_ssa
336342
else:
337343
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)
341347
function_dependencies["context"] = convert_to_non_ssa(function_dependencies["context"])
342348

343349
must_dependencies = set()
344350
data_dependencies = (
345-
list(function_dependencies["context"][x])
351+
list(function_dependencies["context"][v])
346352
if function_dependencies["context"] is not None
347353
else []
348354
)
@@ -354,7 +360,6 @@ def compute_must_dependencies(x):
354360
must_dependencies = must_dependencies.union(result)
355361
return must_dependencies
356362

357-
358363
# endregion
359364
###################################################################################
360365
###################################################################################

0 commit comments

Comments
 (0)