| 186 | |
| 187 | |
| 188 | class ArrayNode(ListNode): |
| 189 | def __init__(self, l: List[ASTNode]): |
| 190 | self.list: List[ASTNode] = l |
| 191 | super().__init__('array', l, ['pn_type_t']) |
| 192 | |
| 193 | def gen_emit_code(self, prefix: List[str], first_arg: int, indent: int) -> List[str]: |
| 194 | args = self.gen_args(first_arg) |
| 195 | return [ |
| 196 | f'{self.mk_indent(indent)}for (bool small_encoding = true; ; small_encoding = false) {{', |
| 197 | f'{self.mk_indent(indent+1)}pni_compound_context c = ' |
| 198 | f'{self.mk_funcall("emit_array", prefix+["small_encoding"]+args)};', |
| 199 | f'{self.mk_indent(indent+1)}pni_compound_context compound = c;', |
| 200 | *super().gen_emit_list_code(prefix, first_arg+len(args), indent + 1), |
| 201 | f'{self.mk_indent(indent+1)}{self.mk_funcall("emit_end_array", prefix+["small_encoding"])};', |
| 202 | f'{self.mk_indent(indent+1)}if (encode_succeeded({", ".join(prefix)})) break;', |
| 203 | f'{self.mk_indent(indent)}}}', |
| 204 | ] |
| 205 | |
| 206 | |
| 207 | class OptionNode(ASTNode): |