Handle break statement correctly
break
statements are ignored in the current implementation (except in switch statements). This might lead to overestimate the dependencies of some variables, possible causing false positives. This is the case, for instance, if a break
statement appears in the body of an if
-branch after a series of variable assignments. The proposed solution is as follows:
- When encountering a
break
, lookup the closest scope corresponding to a loop (this requires to change theScope
class by adding ascope_type
field of a specialenum
type). Add the current dependency graph to a list of dependency graphs linked to that scope. Finally, replace the current dependency graph by an emptied one, or signify that the graph should not be combined with other graphs. - When the body of a loop has been analyzed, the new dependency graph becomes the old dependency graph union the newly computed dependency graph union all stored dependency graphs.
This should also allow to streamline the operations combining dependency graphs: loops but also if statements.
Also, return
statements should have a similar semantic. All dependency graphs, when a return
statement is encountered, should be saved into some list, tied to the function scope, and combined once the function has been entirely analyzed. However, this should be the object of another ticket, and the interaction between the return statement and, for instance, loops, should also be specified.
Todo:
-
Change the Scope
class and add two fields:scope_type
(ScopeType
subclassingenum
) andgraphs_to_combine
(List[DependencyGraph
) -
Update the behaviour of the analysis when a break
statement is encountered -
Update the code handling branches and loops, in order to simplify it by making use of the graphs_to_combine
field -
Write tests to verify that empty dependency graphs can be correctly combined with complex, non-empty ones -
Make sure all current unit tests pass -
Write tests that highlight the difference in behaviour before and after these changes were made