Parse a function decl. Two variants: function-decl ::= FuncRef(fnref) "=" ["colocated"] ["patchable"] name function-decl-sig function-decl-sig ::= SigRef(sig) | signature The first variant allocates a new signature reference. The second references an existing signature which must be declared first.
(&mut self, ctx: &mut Context)
| 1743 | // signature which must be declared first. |
| 1744 | // |
| 1745 | fn parse_function_decl(&mut self, ctx: &mut Context) -> ParseResult<(FuncRef, ExtFuncData)> { |
| 1746 | let fn_ = self.match_fn("expected function number: fn«n»")?; |
| 1747 | self.match_token(Token::Equal, "expected '=' in function decl")?; |
| 1748 | |
| 1749 | let loc = self.loc; |
| 1750 | |
| 1751 | // function-decl ::= FuncRef(fnref) "=" * ["colocated"] ["patchable"] name function-decl-sig |
| 1752 | let colocated = self.optional(Token::Identifier("colocated")); |
| 1753 | // function-decl ::= FuncRef(fnref) "=" ["colocated"] * ["patchable"] name function-decl-sig |
| 1754 | let patchable = self.optional(Token::Identifier("patchable")); |
| 1755 | |
| 1756 | // function-decl ::= FuncRef(fnref) "=" ["colocated"] ["patchable"] * name function-decl-sig |
| 1757 | let name = self.parse_external_name()?; |
| 1758 | |
| 1759 | // function-decl ::= FuncRef(fnref) "=" ["colocated"] ["patchable"] name * function-decl-sig |
| 1760 | let data = match self.token() { |
| 1761 | Some(Token::LPar) => { |
| 1762 | // function-decl ::= FuncRef(fnref) "=" ["colocated"] ["patchable"] name * signature |
| 1763 | let sig = self.parse_signature()?; |
| 1764 | let sigref = ctx.function.import_signature(sig); |
| 1765 | ctx.map |
| 1766 | .def_entity(sigref.into(), loc) |
| 1767 | .expect("duplicate SigRef entities created"); |
| 1768 | ExtFuncData { |
| 1769 | name, |
| 1770 | signature: sigref, |
| 1771 | colocated, |
| 1772 | patchable, |
| 1773 | } |
| 1774 | } |
| 1775 | Some(Token::SigRef(sig_src)) => { |
| 1776 | let sig = match SigRef::with_number(sig_src) { |
| 1777 | None => { |
| 1778 | return err!(self.loc, "attempted to use invalid signature ss{}", sig_src); |
| 1779 | } |
| 1780 | Some(sig) => sig, |
| 1781 | }; |
| 1782 | ctx.check_sig(sig, self.loc)?; |
| 1783 | self.consume(); |
| 1784 | ExtFuncData { |
| 1785 | name, |
| 1786 | signature: sig, |
| 1787 | colocated, |
| 1788 | patchable, |
| 1789 | } |
| 1790 | } |
| 1791 | _ => return err!(self.loc, "expected 'function' or sig«n» in function decl"), |
| 1792 | }; |
| 1793 | |
| 1794 | // Collect any trailing comments. |
| 1795 | self.token(); |
| 1796 | self.claim_gathered_comments(fn_); |
| 1797 | |
| 1798 | Ok((fn_, data)) |
| 1799 | } |
| 1800 | |
| 1801 | // Parse a jump table literal. |
| 1802 | // |
no test coverage detected