MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / parse_signature

Method parse_signature

cranelift/reader/src/parser.rs:1380–1407  ·  view source on GitHub ↗

Parse a function signature. signature ::= * "(" [paramlist] ")" ["->" retlist] [callconv]

(&mut self)

Source from the content-addressed store, hash-verified

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 //

Callers 4

parse_functionMethod · 0.45
parse_signature_declMethod · 0.45
parse_function_declMethod · 0.45
signatureFunction · 0.45

Calls 8

OkFunction · 0.85
match_tokenMethod · 0.80
tokenMethod · 0.80
parse_abi_param_listMethod · 0.80
optionalMethod · 0.80
newFunction · 0.50
parseMethod · 0.45
consumeMethod · 0.45

Tested by 1

signatureFunction · 0.36