Source code for delphi.GrFN.linking

import networkx as nx





[docs]def get_argument_lists(GrFN): # Make a dict of the argument lists for each container in the GrFN indexed # by the container basename return { c["name"].split("::")[-1]: c["arguments"] for c in GrFN["containers"] }
[docs]def get_call_conventions(GrFN): # Make a dict of all of the calls in every container in the GrFN. Index them # by basename of the callee. Include the caller basename and input list in # the value field return { stmt["function"]["name"].split("::")[-1]: { "caller": container["name"].split("::")[-1], "inputs": stmt["input"] } for container in GrFN["containers"] for stmt in container["body"] if stmt["function"]["type"] == "function_name" }
[docs]def merge_similar_vars(vars): unique_vars = dict() for (_, scope, name, idx) in vars: if (scope, name) in unique_vars: unique_vars[(scope, name)].append(int(idx)) else: unique_vars[(scope, name)] = [int(idx)] return unique_vars
[docs]def format_long_text(text): new_text = list() while len(text) > 8: new_text.extend(text[:4]) new_text.append("\n") text = text[4:] new_text.extend(text) return new_text
[docs]def get_id(el_data): el_type = el_data["type"] if el_type == "identifier": var_name = el_data["content"].split("::")[-3:] return tuple(["<VAR>"] + var_name) elif el_type == "comment_span": tokens = el_data["content"].split() name = tokens[0] desc = " ".join(format_long_text(tokens[1:])) return ("<CMS>", f"{name}: {desc}") return ("<CMS>", name, desc) elif el_type == "text_span": desc = " ".join(format_long_text(el_data["content"].split())) desc = el_data["content"] return ("<TXT>", desc) elif el_type == "equation_span": desc = " ".join(format_long_text(el_data["content"].split())) desc = el_data["content"] return ("<EQN>", desc) else: raise ValueError(f"Unrecognized link type: {el_type}")