MCPcopy Index your code
hub / github.com/python/cpython / handle_alt_loop

Method handle_alt_loop

Tools/peg_generator/pegen/c_generator.py:804–833  ·  view source on GitHub ↗
(self, node: Alt, is_gather: bool, rulename: str | None)

Source from the content-addressed store, hash-verified

802 self.print("}")
803
804 def handle_alt_loop(self, node: Alt, is_gather: bool, rulename: str | None) -> None:
805 # Condition of the main body of the alternative
806 self.join_conditions(keyword="while", node=node)
807 self.print("{")
808 # We have parsed successfully one item!
809 with self.indent():
810 # Prepare to emit the rule action and do so
811 if node.action and "EXTRA" in node.action:
812 self._set_up_token_end_metadata_extraction()
813 if self.skip_actions:
814 self.emit_dummy_action()
815 elif node.action:
816 self.emit_action(node, cleanup_code="PyMem_Free(_children);")
817 else:
818 self.emit_default_action(is_gather, node)
819
820 # Add the result of rule to the temporary buffer of children. This buffer
821 # will populate later an asdl_seq with all elements to return.
822 self.print("if (_n == _children_capacity) {")
823 with self.indent():
824 self.print("_children_capacity *= 2;")
825 self.print(
826 "void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *));"
827 )
828 self.out_of_memory_return("!_new_children", cleanup_code="PyMem_Free(_children);")
829 self.print("_children = _new_children;")
830 self.print("}")
831 self.print("_children[_n++] = _res;")
832 self.print("_mark = p->mark;")
833 self.print("}")
834
835 def visit_Alt(
836 self, node: Alt, is_loop: bool, is_gather: bool, rulename: str | None

Callers 1

visit_AltMethod · 0.95

Calls 8

join_conditionsMethod · 0.95
emit_dummy_actionMethod · 0.95
emit_actionMethod · 0.95
emit_default_actionMethod · 0.95
out_of_memory_returnMethod · 0.95
printMethod · 0.45
indentMethod · 0.45

Tested by

no test coverage detected