MCPcopy Create free account
hub / github.com/NICUP14/MiniLang / ref

Method ref

src/Parser.py:795–822  ·  view source on GitHub ↗
(self, node: Node)

Source from the content-addressed store, hash-verified

793 return node_stack
794
795 def ref(self, node: Node) -> tuple[Node, Node]:
796 # Macro fix
797 if Def.macro_name != '':
798 return None, ref_node(node)
799
800 # Fix for passing non-funs to Parser.ref
801 if node.value not in Def.fun_map:
802 return (None, ref_node(node))
803
804 small_name = f'{node.value}_tmp_ref_{get_counter()}'
805 tmp_name = full_name_of_var(small_name, force_local=True)
806
807 def get_type(node: Node):
808 return node.ntype
809
810 fun = Def.fun_map.get(node.value)
811 sig = _find_signature(
812 fun, list(map(get_type, args_to_list(node.left))))
813 if not sig:
814 print_error('ref',
815 f'No signature of {fun.name} matches {list(map(Def.rev_type_of, map(get_type, args_to_list(node.left))))} out of {[list(map(Def.rev_type_of, sig.arg_types)) for sig in fun.signatures]}')
816
817 # Def.context_map[tmp_name] = Context(small_name, curr_scope())
818 # Def.ident_map[tmp_name] = sig.ret_type.meta_kind()
819 tmp_decl = self.declare(
820 tmp_name, sig.ret_type, sig.ret_type.elem_ckind, init_node=node)
821
822 return (tmp_decl, ref_node(Node(NodeKind.IDENT, sig.ret_type, tmp_name)))
823
824 def to_tree(self, tokens: list[Token]) -> Node:
825 node_stack: list[Node] = []

Callers 6

try_cast_refMethod · 0.95
inject_copy_argMethod · 0.95
to_treeMethod · 0.95
for_statementMethod · 0.95
ret_statementMethod · 0.95
inject_declMethod · 0.95

Calls 8

declareMethod · 0.95
ref_nodeFunction · 0.90
get_counterFunction · 0.90
full_name_of_varFunction · 0.90
_find_signatureFunction · 0.90
args_to_listFunction · 0.90
print_errorFunction · 0.90
NodeClass · 0.90

Tested by

no test coverage detected