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

Method parse_function

cranelift/reader/src/parser.rs:1219–1273  ·  view source on GitHub ↗

Parse a whole function definition. function ::= * "function" name signature "{" preamble function-body "}"

(&mut self)

Source from the content-addressed store, hash-verified

1217 // function ::= * "function" name signature "{" preamble function-body "}"
1218 //
1219 fn parse_function(&mut self) -> ParseResult<(Function, Details<'a>)> {
1220 // Begin gathering comments.
1221 // Make sure we don't include any comments before the `function` keyword.
1222 self.token();
1223 debug_assert!(self.comments.is_empty());
1224 self.start_gathering_comments();
1225
1226 self.match_identifier("function", "expected 'function'")?;
1227
1228 let location = self.loc;
1229
1230 // function ::= "function" * name signature "{" preamble function-body "}"
1231 let name = self.parse_user_func_name()?;
1232
1233 // function ::= "function" name * signature "{" preamble function-body "}"
1234 let sig = self.parse_signature()?;
1235
1236 let mut ctx = Context::new(Function::with_name_signature(name, sig));
1237
1238 // function ::= "function" name signature * "{" preamble function-body "}"
1239 self.match_token(Token::LBrace, "expected '{' before function body")?;
1240
1241 self.token();
1242 self.claim_gathered_comments(AnyEntity::Function);
1243
1244 // function ::= "function" name signature "{" * preamble function-body "}"
1245 self.parse_preamble(&mut ctx)?;
1246 // function ::= "function" name signature "{" preamble * function-body "}"
1247 self.parse_function_body(&mut ctx)?;
1248 // function ::= "function" name signature "{" preamble function-body * "}"
1249 self.match_token(Token::RBrace, "expected '}' after function body")?;
1250
1251 // Collect any comments following the end of the function, then stop gathering comments.
1252 self.start_gathering_comments();
1253 self.token();
1254 self.claim_gathered_comments(AnyEntity::Function);
1255
1256 // Claim all the declared user-defined function names.
1257 for (user_func_ref, user_external_name) in
1258 std::mem::take(&mut self.predeclared_external_names)
1259 {
1260 let actual_ref = ctx
1261 .function
1262 .declare_imported_user_function(user_external_name);
1263 assert_eq!(user_func_ref, actual_ref);
1264 }
1265
1266 let details = Details {
1267 location,
1268 comments: self.take_comments(),
1269 map: ctx.map,
1270 };
1271
1272 Ok((ctx.function, details))
1273 }
1274
1275 // Parse a user-defined function name
1276 //

Callers 13

parse_function_listMethod · 0.80
aliasesFunction · 0.80
stack_slot_declFunction · 0.80
block_headerFunction · 0.80
duplicate_blockFunction · 0.80
number_of_blocksFunction · 0.80
duplicate_ssFunction · 0.80
duplicate_gvFunction · 0.80
duplicate_sigFunction · 0.80
duplicate_fnFunction · 0.80
commentsFunction · 0.80
user_function_nameFunction · 0.80

Calls 13

OkFunction · 0.85
tokenMethod · 0.80
match_identifierMethod · 0.80
parse_user_func_nameMethod · 0.80
match_tokenMethod · 0.80
parse_preambleMethod · 0.80
parse_function_bodyMethod · 0.80
take_commentsMethod · 0.80
newFunction · 0.50

Tested by 12

aliasesFunction · 0.64
stack_slot_declFunction · 0.64
block_headerFunction · 0.64
duplicate_blockFunction · 0.64
number_of_blocksFunction · 0.64
duplicate_ssFunction · 0.64
duplicate_gvFunction · 0.64
duplicate_sigFunction · 0.64
duplicate_fnFunction · 0.64
commentsFunction · 0.64
user_function_nameFunction · 0.64
parse_cold_blocksFunction · 0.64