cam.utilities.loop_utils#
Fabex ‘loop_utils.py’ © 2012 Vilem Novak
Functions#
Module Contents#
- add_loop(parentloop, start, end)[source]#
Add a loop to a parent loop structure.
This function recursively checks if the specified start and end values can be added as a new loop to the parent loop. If an existing loop encompasses the new loop, it will call itself on that loop. If no such loop exists, it appends the new loop defined by the start and end values to the parent loop’s list of loops.
- Parameters:
parentloop (list) – A list representing the parent loop, where the third element is a list of child loops.
start (int) – The starting value of the new loop to be added.
end (int) – The ending value of the new loop to be added.
- Returns:
- This function modifies the parentloop in place and does not
return a value.
- Return type:
None
- cut_loops(csource, parentloop, loops)[source]#
Cut loops from a source code segment.
This function takes a source code segment and a parent loop defined by its start and end indices, along with a list of nested loops. It creates a copy of the source code segment and removes the specified nested loops from it. The modified segment is then appended to the provided list of loops. The function also recursively processes any nested loops found within the parent loop.
- Parameters:
csource (str) – The source code from which loops will be cut.
parentloop (tuple) – A tuple containing the start index, end index, and a list of nested loops. The list of nested loops should contain tuples with start and end indices for each loop.
loops (list) – A list that will be populated with the modified source code segments after removing the specified loops.
- Returns:
- This function modifies the loops list in place and does not return a
value.
- Return type:
None