Untitled
unknown
plain_text
a year ago
2.3 kB
3
Indexable
def resolve_functions_recursive(
prog_txt,
functions_list,
replacements_dict,
processed_files,
cpy_files
):
"""
Recursively resolve functions and merge them into the program text.
Args:
prog_txt: The main program text.
functions_list: List of functions to process.
replacements_dict: Replacement rules for COPY statements.
processed_files: A set of already processed files to avoid circular references.
cpy_files: List of available function files.
Returns:
The updated program text with all functions resolved.
"""
for fun in functions_list:
if fun in processed_files:
logging.warning(f"Circular reference detected for function: {fun}")
continue
logging.debug(f"Processing function: {fun}")
processed_files.add(fun)
# Locate the file for the function
function_path = next((i for i in cpy_files if f"{fun}.cpy" in i), None)
if not function_path:
logging.error(f"Function file not found for: {fun}")
continue
# Read the function file and parse its content
logging.debug(f"Reading function file: {function_path}")
sub_functions_list, sub_prog_txt = parser.get_functions(function_path)
if len(sub_functions_list) !=0 :
print("\n\n!!!!!!!!! HURRAH !!!!!!!!!!!\n\n")
print("Got sub functions :",sub_functions_list)
# Apply `func_replace` and `func_do_task` to the content
sub_prog_txt = "".join(sub_prog_txt)
sub_prog_txt = parser.combine_copy_statements(sub_prog_txt)
# Recursively resolve nested functions
sub_replacements_dict = parser.parse_cobol_replacements_sub(sub_prog_txt)
print("REPLACMENT :", sub_replacements_dict)
sub_prog_txt = resolve_functions_recursive(
sub_prog_txt, sub_functions_list, sub_replacements_dict, processed_files, cpy_files
)
# Merge the resolved function into the main program text
prog_txt = parser.merge_functions(
replacement_dict=replacements_dict.get(fun),
program_text=prog_txt,
function_name=fun,
function_path=function_path,
)
return prog_txt
Editor is loading...
Leave a Comment