MCPcopy Create free account
hub / github.com/SerenityOS/jakt / parse_function

Method parse_function

bootstrap/stage0/parser.cpp:6770–6862  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6768}
6769
6770Jakt::parser::ParsedFunction Jakt::parser::Parser::parse_function(Jakt::parser::FunctionLinkage const linkage,Jakt::parser::Visibility const visibility,bool const is_comptime,bool const is_destructor,bool const is_unsafe,bool const allow_missing_body) {
6771{
6772Jakt::parser::ParsedFunction parsed_function = Jakt::parser::ParsedFunction(this->next_function_id++,ByteString::from_utf8_without_validation(""sv),this->empty_span(),visibility,DynamicArray<Jakt::parser::ParsedParameter>::create_with({}),DynamicArray<Jakt::parser::ParsedGenericParameter>::create_with({}),Jakt::parser::ParsedBlock(DynamicArray<NonnullRefPtr<typename Jakt::parser::ParsedStatement>>::create_with({})),Jakt::parser::ParsedType::Empty(JaktInternal::OptionalNone()),this->span(static_cast<size_t>(0ULL),static_cast<size_t>(0ULL)),false,Jakt::parser::FunctionType::Normal(),linkage,false,is_comptime,false,is_unsafe,false,false,JaktInternal::OptionalNone(),JaktInternal::OptionalNone(),JaktInternal::OptionalNone(),Jakt::parser::InlineState::Default(),false);
6773if (is_destructor){
6774parsed_function.type = Jakt::parser::FunctionType::Destructor();
6775parsed_function.params.push(Jakt::parser::ParsedParameter(false,Jakt::parser::ParsedVariable(ByteString::from_utf8_without_validation("this"sv),Jakt::parser::ParsedType::Empty(JaktInternal::OptionalNone()),true,this->current().span()),JaktInternal::OptionalNone(),this->current().span()));
6776}
6777if (!is_destructor){
6778this->index++;
6779}
6780if (this->eof()){
6781this->error(ByteString::from_utf8_without_validation("Incomplete function definition"sv),this->current().span());
6782return parsed_function;
6783}
6784if (is_destructor){
6785parsed_function.name = ByteString::from_utf8_without_validation("~"sv);
6786parsed_function.name_span = this->previous().span();
6787}
6788else {
6789Jakt::lexer::Token __jakt_tmp26 = this->current();
6790if (__jakt_tmp26.__jakt_init_index() == 3 /* Identifier */){
6791ByteString const name = __jakt_tmp26.as.Identifier.name;
6792parsed_function.name = name;
6793parsed_function.name_span = this->current().span();
6794}
6795else {
6796this->error(ByteString::from_utf8_without_validation("Incomplete function definition"sv),this->current().span());
6797return parsed_function;
6798}
6799
6800}
6801
6802this->index++;
6803if (!is_destructor){
6804parsed_function.generic_parameters = this->parse_generic_parameters();
6805}
6806if (this->eof()){
6807this->error(ByteString::from_utf8_without_validation("Incomplete function"sv),this->current().span());
6808}
6809if (!is_destructor){
6810Jakt::parser::ParsedFunctionParameters const fn_parameters = this->parse_function_parameters(false);
6811parsed_function.params = fn_parameters.parameters;
6812parsed_function.has_varargs = fn_parameters.has_varargs;
6813}
6814parsed_function.is_jakt_main = (parsed_function.name == ByteString::from_utf8_without_validation("main"sv));
6815bool can_throw = parsed_function.is_jakt_main;
6816if (this->current().__jakt_init_index() == 102 /* Throws */){
6817if (is_destructor){
6818this->error(ByteString::from_utf8_without_validation("Destructor cannot throw"sv),this->current().span());
6819}
6820else {
6821can_throw = true;
6822}
6823
6824this->index++;
6825}
6826parsed_function.can_throw = can_throw;
6827if (this->current().__jakt_init_index() == 58 /* Arrow */){

Callers 3

parse_namespaceMethod · 0.95
parse_traitMethod · 0.95
parse_methodMethod · 0.95

Calls 15

empty_spanMethod · 0.95
currentMethod · 0.95
eofMethod · 0.95
errorMethod · 0.95
previousMethod · 0.95
parse_typenameMethod · 0.95
parse_fat_arrowMethod · 0.95
skip_newlinesMethod · 0.95
parse_blockMethod · 0.95
ParsedFunctionClass · 0.85

Tested by

no test coverage detected