(self, is_struct: bool = False)
| 2589 | f'Unknown meta kind {meta_kind}', self) |
| 2590 | |
| 2591 | def declaration(self, is_struct: bool = False) -> Optional[Node]: |
| 2592 | name = self.match_token(TokenKind.IDENT).value |
| 2593 | var_name = full_name_of_var( |
| 2594 | name, force_local=True, exhaustive_match=False) |
| 2595 | |
| 2596 | is_local = Def.fun_name != '' |
| 2597 | full_name = var_name if is_local else full_name_of_var(name, True) |
| 2598 | is_implicit = self.curr_token().kind != TokenKind.COLON |
| 2599 | |
| 2600 | if Def.macro_name != '': |
| 2601 | Def.ident_map[full_name] = VariableMetaKind.ANY |
| 2602 | macro = Def.macro_map.get(Def.macro_name) |
| 2603 | macro.local_names.append(full_name) |
| 2604 | return None |
| 2605 | # print_error('declaration', |
| 2606 | # f'Variable declarations within macro ({Def.macro_name}) are not allowed', self) |
| 2607 | |
| 2608 | elem_cnt = 0 |
| 2609 | var_type = default_type |
| 2610 | meta_kind = VariableMetaKind.PRIM |
| 2611 | if not is_implicit: |
| 2612 | self.match_token(TokenKind.COLON) |
| 2613 | |
| 2614 | if self.curr_token().kind == TokenKind.KW_FUN: |
| 2615 | self.match_token(TokenKind.KW_FUN) |
| 2616 | sig = self.fun_declaration(is_sig=True) |
| 2617 | Def.sig_map[full_name] = sig |
| 2618 | |
| 2619 | var_type = VariableType(sig_ckind, name=full_name) |
| 2620 | meta_kind = var_type.meta_kind() |
| 2621 | elem_cnt = 0 |
| 2622 | else: |
| 2623 | parsed_type = self.parse_type() |
| 2624 | var_type = parsed_type.var_type |
| 2625 | elem_cnt = parsed_type.elem_cnt |
| 2626 | meta_kind = var_type.meta_kind() |
| 2627 | |
| 2628 | if not self.no_more_tokens(): |
| 2629 | self.match_token(TokenKind.ASSIGN) |
| 2630 | |
| 2631 | if is_implicit: |
| 2632 | if self.curr_token().kind == TokenKind.LBRACE: |
| 2633 | print_error( |
| 2634 | 'declaration', |
| 2635 | 'Implicit array declaration is not permitted.', self) |
| 2636 | |
| 2637 | node = self.token_list_to_tree() |
| 2638 | var_type = node.ntype |
| 2639 | meta_kind = var_type.meta_kind() |
| 2640 | |
| 2641 | if var_type.ckind == sig_ckind: |
| 2642 | print_error( |
| 2643 | 'declaration', |
| 2644 | 'Implicit signature declaration is not permitted.', self) |
| 2645 | |
| 2646 | if var_type.ckind == void_ckind: |
| 2647 | print_error('declaration', |
| 2648 | 'Declaration of implicit void primitive is not allowed.', self) |
no test coverage detected