(self)
| 2289 | return Node(NodeKind.GLUE, void_type, '', block_node, Node(NodeKind.END, void_type, 'end')) |
| 2290 | |
| 2291 | def macro_statement(self) -> None: |
| 2292 | if Def.macro_name != '': |
| 2293 | print_error('macro_declaration', |
| 2294 | 'Nested macros are not allowed', self) |
| 2295 | |
| 2296 | if Def.fun_name != '': |
| 2297 | print_error('macro_declaration', |
| 2298 | 'Local macros are not allowed', self) |
| 2299 | |
| 2300 | ret = False |
| 2301 | if self.curr_token().kind == TokenKind.KW_RET: |
| 2302 | ret = True |
| 2303 | self.next_token() |
| 2304 | |
| 2305 | full_name = full_name_of_fun(self.match_token( |
| 2306 | TokenKind.IDENT).value, exhaustive_match=False, force_global=True) |
| 2307 | |
| 2308 | has_args = not self.no_more_tokens() |
| 2309 | arg_names: list[str] = [] |
| 2310 | if has_args: |
| 2311 | self.match_token(TokenKind.LPAREN) |
| 2312 | |
| 2313 | while self.curr_token().kind != TokenKind.RPAREN: |
| 2314 | arg_name = self.match_token(TokenKind.IDENT).value |
| 2315 | arg_names.append(full_name_of_var( |
| 2316 | arg_name, exhaustive_match=False)) |
| 2317 | |
| 2318 | if not self.no_more_tokens() and self.curr_token().kind != TokenKind.RPAREN: |
| 2319 | self.match_token(TokenKind.COMMA) |
| 2320 | |
| 2321 | self.match_token(TokenKind.RPAREN) |
| 2322 | if not self.no_more_tokens(): |
| 2323 | print_error('macro_statement', |
| 2324 | 'Junk after macro declaration', self) |
| 2325 | self.next_line() |
| 2326 | |
| 2327 | signature = MacroSignature( |
| 2328 | len(arg_names), arg_names, ret, Parser(self)) |
| 2329 | if Def.ident_map.get(full_name) == VariableMetaKind.MACRO: |
| 2330 | macro = Def.macro_map.get(full_name) |
| 2331 | for idx, macro_signature in enumerate(macro.signatures): |
| 2332 | if signature.arg_cnt == macro_signature.arg_cnt: |
| 2333 | Def.macro_map[full_name].signatures[idx] = signature |
| 2334 | break |
| 2335 | else: |
| 2336 | Def.macro_map[full_name].signatures.append(signature) |
| 2337 | |
| 2338 | else: |
| 2339 | self.check_ident(full_name, VariableMetaKind.MACRO, use_mkind=True) |
| 2340 | Def.ident_map[full_name] = VariableMetaKind.MACRO |
| 2341 | Def.macro_map[full_name] = Macro( |
| 2342 | full_name, len(arg_names), [], [signature]) |
| 2343 | |
| 2344 | for name in arg_names: |
| 2345 | self.check_ident(name, use_mkind=True) |
| 2346 | Def.ident_map[name] = VariableMetaKind.ANY |
| 2347 | |
| 2348 | Def.macro_name = full_name |
no test coverage detected