Parse a function signature. signature ::= * "(" [paramlist] ")" ["->" retlist] [callconv]
(&mut self)
| 1378 | // signature ::= * "(" [paramlist] ")" ["->" retlist] [callconv] |
| 1379 | // |
| 1380 | fn parse_signature(&mut self) -> ParseResult<Signature> { |
| 1381 | // Calling convention defaults to `fast`, but can be changed. |
| 1382 | let mut sig = Signature::new(self.default_calling_convention); |
| 1383 | |
| 1384 | self.match_token(Token::LPar, "expected function signature: ( args... )")?; |
| 1385 | // signature ::= "(" * [abi-param-list] ")" ["->" retlist] [callconv] |
| 1386 | if self.token() != Some(Token::RPar) { |
| 1387 | sig.params = self.parse_abi_param_list()?; |
| 1388 | } |
| 1389 | self.match_token(Token::RPar, "expected ')' after function arguments")?; |
| 1390 | if self.optional(Token::Arrow) { |
| 1391 | sig.returns = self.parse_abi_param_list()?; |
| 1392 | } |
| 1393 | |
| 1394 | // The calling convention is optional. |
| 1395 | match self.token() { |
| 1396 | Some(Token::Identifier(text)) => match text.parse() { |
| 1397 | Ok(cc) => { |
| 1398 | self.consume(); |
| 1399 | sig.call_conv = cc; |
| 1400 | } |
| 1401 | _ => return err!(self.loc, "unknown calling convention: {}", text), |
| 1402 | }, |
| 1403 | _ => {} |
| 1404 | } |
| 1405 | |
| 1406 | Ok(sig) |
| 1407 | } |
| 1408 | |
| 1409 | // Parse list of function parameter / return value types. |
| 1410 | // |