Add the unreachable builtin function

This commit is contained in:
2025-04-02 21:08:15 +02:00
parent a7b5e32d09
commit 50970f3289
6 changed files with 136 additions and 73 deletions

View File

@ -127,8 +127,8 @@ along with GCC; see the file COPYING3. If not see
%type <elna::boot::constant_definition *> constant_definition;
%type <std::vector<elna::boot::constant_definition *>> constant_part constant_definitions;
%type <std::vector<elna::boot::variable_declaration *>> variable_declarations variable_part variable_declaration;
%type <std::shared_ptr<elna::boot::type_expression>> type_expression;
%type <std::vector<std::shared_ptr<elna::boot::type_expression>>> type_expressions;
%type <elna::boot::type_expression *> type_expression;
%type <std::vector<elna::boot::type_expression *>> type_expressions;
%type <elna::boot::traits_expression *> traits_expression;
%type <elna::boot::expression *> expression operand qualident;
%type <elna::boot::unary_expression *> unary_expression;
@ -143,14 +143,14 @@ along with GCC; see the file COPYING3. If not see
%type <elna::boot::statement *> statement;
%type <std::vector<elna::boot::statement *>> statements;
%type <elna::boot::procedure_definition *> procedure_definition;
%type <std::pair<std::vector<std::string>, std::shared_ptr<elna::boot::procedure_type_expression>>> procedure_heading;
%type <std::pair<std::vector<std::string>, elna::boot::procedure_type_expression *>> procedure_heading;
%type <elna::boot::procedure_type_expression::return_t> return_declaration;
%type <std::vector<elna::boot::procedure_definition *>> procedure_definitions procedure_part;
%type <elna::boot::type_definition *> type_definition;
%type <std::vector<elna::boot::type_definition *>> type_definitions type_part;
%type <elna::boot::block *> block;
%type <elna::boot::field_declaration> field_declaration formal_parameter;
%type <std::vector<std::pair<std::string, std::shared_ptr<elna::boot::type_expression>>>>
%type <std::vector<std::pair<std::string, elna::boot::type_expression *>>>
optional_fields required_fields formal_parameters;
%type <std::vector<elna::boot::conditional_statements *>> elsif_then_statements elsif_do_statements;
%type <elna::boot::cast_expression *> cast_expression;
@ -202,8 +202,7 @@ return_declaration:
procedure_heading:
"(" formal_parameters ")" return_declaration
{
$$.second = std::make_shared<boot::procedure_type_expression>(boot::make_position(@1),
std::move($4));
$$.second = new boot::procedure_type_expression(boot::make_position(@1), std::move($4));
for (auto& [name, type] : $2)
{
$$.first.emplace_back(std::move(name));
@ -213,8 +212,7 @@ procedure_heading:
procedure_definition:
"proc" identifier_definition procedure_heading ";" block
{
$$ = new boot::procedure_definition(boot::make_position(@1),
$2.first, $2.second, $3.second, $5);
$$ = new boot::procedure_definition(boot::make_position(@1), $2.first, $2.second, $3.second, $5);
std::swap($3.first, $$->parameter_names);
}
| "proc" identifier_definition procedure_heading ";" "extern"
@ -489,37 +487,38 @@ optional_fields:
type_expression:
"[" INTEGER "]" type_expression
{
$$ = std::make_shared<boot::array_type_expression>(boot::make_position(@1), $4, $2);
$$ = new boot::array_type_expression(boot::make_position(@1), $4, $2);
}
| "^" type_expression
{
$$ = std::make_shared<boot::pointer_type_expression>(boot::make_position(@1), $2);
$$ = new boot::pointer_type_expression(boot::make_position(@1), $2);
}
| "record" optional_fields "end"
{
$$ = std::make_shared<boot::record_type_expression>(boot::make_position(@1), std::move($2));
$$ = new boot::record_type_expression(boot::make_position(@1), std::move($2));
}
| "union" required_fields "end"
{
$$ = std::make_shared<boot::union_type_expression>(boot::make_position(@1), std::move($2));
$$ = new boot::union_type_expression(boot::make_position(@1), std::move($2));
}
| "proc" "(" type_expressions ")" return_declaration
{
auto result = std::make_shared<boot::procedure_type_expression>(boot::make_position(@1),
std::move($5));
auto result = new boot::procedure_type_expression(boot::make_position(@1), std::move($5));
std::swap(result->parameters, $3);
$$ = result;
}
| IDENTIFIER
{
$$ = std::make_shared<boot::primitive_type_expression>(boot::make_position(@1), $1);
$$ = new boot::primitive_type_expression(boot::make_position(@1), $1);
}
variable_declaration: identifier_definitions ":" type_expression
{
std::shared_ptr<boot::type_expression> shared_type{ $3 };
for (const std::pair<std::string, bool>& identifier : $1)
{
boot::variable_declaration *declaration = new boot::variable_declaration(
boot::make_position(@2), identifier.first, $3, identifier.second);
boot::make_position(@2), identifier.first, shared_type, identifier.second);
$$.push_back(declaration);
}
}