Skip parameter names in procedure type expressions

This commit is contained in:
2025-03-18 11:37:10 +01:00
parent 6eb4e91b2c
commit 5e8555b4f4
20 changed files with 469 additions and 490 deletions

View File

@ -17,175 +17,8 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/ast.h"
namespace elna
namespace elna::boot
{
namespace boot
{
void empty_visitor::visit(variable_declaration *)
{
__builtin_unreachable();
}
void empty_visitor::visit(constant_definition *)
{
__builtin_unreachable();
}
void empty_visitor::visit(procedure_definition *)
{
__builtin_unreachable();
}
void empty_visitor::visit(type_definition *)
{
__builtin_unreachable();
}
void empty_visitor::visit(procedure_call *)
{
__builtin_unreachable();
}
void empty_visitor::visit(traits_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(cast_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(assign_statement *)
{
__builtin_unreachable();
}
void empty_visitor::visit(if_statement *)
{
__builtin_unreachable();
}
void empty_visitor::visit(while_statement *)
{
__builtin_unreachable();
}
void empty_visitor::visit(return_statement *)
{
__builtin_unreachable();
}
void empty_visitor::visit(defer_statement *)
{
__builtin_unreachable();
}
void empty_visitor::visit(block *)
{
__builtin_unreachable();
}
void empty_visitor::visit(program *)
{
__builtin_unreachable();
}
void empty_visitor::visit(binary_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(unary_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(primitive_type_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(array_type_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(pointer_type_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(record_type_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(union_type_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(procedure_type_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(variable_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(array_access_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(field_access_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(dereference_expression *)
{
__builtin_unreachable();
}
void empty_visitor::visit(number_literal<std::int32_t> *)
{
__builtin_unreachable();
}
void empty_visitor::visit(number_literal<std::uint32_t> *)
{
__builtin_unreachable();
}
void empty_visitor::visit(number_literal<double> *)
{
__builtin_unreachable();
}
void empty_visitor::visit(number_literal<bool> *)
{
__builtin_unreachable();
}
void empty_visitor::visit(number_literal<unsigned char> *)
{
__builtin_unreachable();
}
void empty_visitor::visit(number_literal<std::nullptr_t> *)
{
__builtin_unreachable();
}
void empty_visitor::visit(number_literal<std::string> *)
{
__builtin_unreachable();
}
node::node(const struct position position)
: source_position(position)
{
@ -305,7 +138,7 @@ namespace boot
return nullptr;
}
literal *expression::is_literal()
literal_expression *expression::is_literal()
{
return nullptr;
}
@ -336,7 +169,7 @@ namespace boot
{
return node->accept(visitor);
}
else if (literal *node = is_literal())
else if (literal_expression *node = is_literal())
{
return node->accept(visitor);
}
@ -518,7 +351,7 @@ namespace boot
}
constant_definition::constant_definition(const struct position position, const std::string& identifier,
const bool exported, literal *body)
const bool exported, literal_expression *body)
: definition(position, identifier, exported), m_body(body)
{
}
@ -528,7 +361,7 @@ namespace boot
visitor->visit(this);
}
literal& constant_definition::body()
literal_expression& constant_definition::body()
{
return *m_body;
}
@ -538,14 +371,19 @@ namespace boot
delete m_body;
}
procedure_type_expression::procedure_type_expression(const struct position position,
std::shared_ptr<type_expression> return_type)
: type_expression(position), return_type(return_type), no_return(false)
return_declaration::return_declaration(std::shared_ptr<type_expression> type)
: type(type)
{
}
procedure_type_expression::procedure_type_expression(const struct position position, no_return_t)
: type_expression(position), return_type(nullptr), no_return(true)
return_declaration::return_declaration(std::monostate)
: no_return(true)
{
}
procedure_type_expression::procedure_type_expression(const struct position position,
return_declaration return_type)
: type_expression(position), return_type(return_type)
{
}
@ -554,14 +392,6 @@ namespace boot
visitor->visit(this);
}
procedure_type_expression::~procedure_type_expression()
{
for (auto parameter : this->parameters)
{
delete parameter;
}
}
procedure_definition::procedure_definition(const struct position position, const std::string& identifier,
const bool exported, std::shared_ptr<procedure_type_expression> heading, block *body)
: definition(position, identifier, exported), m_heading(heading), body(body)
@ -652,42 +482,42 @@ namespace boot
}
}
literal::literal()
literal_expression::literal_expression()
{
}
literal *literal::is_literal()
literal_expression *literal_expression::is_literal()
{
return this;
}
void literal::accept(parser_visitor *visitor)
void literal_expression::accept(parser_visitor *visitor)
{
if (number_literal<std::int32_t> *node = is_int())
if (literal<std::int32_t> *node = is_int())
{
return node->accept(visitor);
}
else if (number_literal<std::uint32_t> *node = is_word())
else if (literal<std::uint32_t> *node = is_word())
{
return node->accept(visitor);
}
else if (number_literal<double> *node = is_float())
else if (literal<double> *node = is_float())
{
return node->accept(visitor);
}
else if (number_literal<bool> *node = is_bool())
else if (literal<bool> *node = is_bool())
{
return node->accept(visitor);
}
else if (number_literal<unsigned char> *node = is_char())
else if (literal<unsigned char> *node = is_char())
{
return node->accept(visitor);
}
else if (number_literal<std::nullptr_t> *node = is_nil())
else if (literal<std::nullptr_t> *node = is_nil())
{
return node->accept(visitor);
}
else if (number_literal<std::string> *node = is_string())
else if (literal<std::string> *node = is_string())
{
return node->accept(visitor);
}
@ -991,9 +821,8 @@ namespace boot
delete m_value;
}
traits_expression::traits_expression(const struct position position,
const std::string& name, std::shared_ptr<type_expression> type)
: node(position), m_type(type), name(name)
traits_expression::traits_expression(const struct position position, const std::string& name)
: node(position), name(name)
{
}
@ -1007,11 +836,6 @@ namespace boot
return this;
}
type_expression& traits_expression::type()
{
return *m_type;
}
conditional_statements::conditional_statements(expression *prerequisite)
: m_prerequisite(prerequisite)
{
@ -1212,4 +1036,3 @@ namespace boot
__builtin_unreachable();
};
}
}

View File

@ -17,9 +17,7 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/driver.h"
namespace elna
{
namespace boot
namespace elna::boot
{
position make_position(const yy::location& location)
{
@ -79,4 +77,3 @@ namespace boot
}
}
}
}

View File

@ -87,7 +87,7 @@ along with GCC; see the file COPYING3. If not see
ARROW "->" EXCLAMATION "!"
AT "@" HAT "^"
COLON ":" SEMICOLON ";" DOT "." COMMA ","
%token NOT "not"
%token NOT "~"
CAST "cast"
NIL "nil"
CONST "const"
@ -107,27 +107,26 @@ along with GCC; see the file COPYING3. If not see
BEGIN_BLOCK "begin"
END_BLOCK "end"
DEFER "defer"
%token OR "or" AND "and" XOR "xor"
%token OR "|" AND "&" XOR "xor"
EQUALS "=" NOT_EQUAL "<>" LESS_THAN "<" GREATER_THAN ">" LESS_EQUAL "<=" GREATER_EQUAL ">="
SHIFT_LEFT "<<" SHIFT_RIGHT ">>"
PLUS "+" MINUS "-"
MULTIPLICATION "*" DIVISION "/" REMAINDER "%"
%left "or" "and" "xor"
%left "|" "&" "xor"
%left "=" "<>" "<" ">" "<=" ">="
%left "<<" ">>"
%left "+" "-"
%left "*" "/" "%"
%type <elna::boot::literal *> literal;
%type <elna::boot::literal_expression *> literal;
%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
formal_parameters formal_parameter_list;
%type <elna::boot::variable_declaration *> formal_parameter
%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::traits_expression *> traits_expression;
%type <elna::boot::expression *> expression operand;
%type <elna::boot::expression *> expression operand qualident;
%type <elna::boot::unary_expression *> unary_expression;
%type <elna::boot::binary_expression *> binary_expression;
%type <std::vector<elna::boot::expression *>> expressions actual_parameter_list;
@ -140,14 +139,15 @@ 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::shared_ptr<elna::boot::procedure_type_expression>> procedure_heading;
%type <std::pair<std::vector<std::string>, std::shared_ptr<elna::boot::procedure_type_expression>>> procedure_heading;
%type <elna::boot::return_declaration> 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;
%type <elna::boot::field_declaration> field_declaration formal_parameter;
%type <std::vector<std::pair<std::string, std::shared_ptr<elna::boot::type_expression>>>>
optional_fields required_fields;
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;
%type <elna::boot::defer_statement *> defer_statement;
@ -191,31 +191,32 @@ identifier_definitions:
$$.emplace($$.cbegin(), $1);
}
| identifier_definition { $$.emplace_back(std::move($1)); }
return_declaration:
/* proper procedure */ {}
| "->" "!" { $$ = elna::boot::return_declaration(std::monostate{}); }
| "->" type_expression { $$ = elna::boot::return_declaration($2); }
procedure_heading:
formal_parameter_list
"(" formal_parameters ")" return_declaration
{
$$ = std::make_shared<elna::boot::procedure_type_expression>(elna::boot::make_position(@1));
std::swap($1, $$->parameters);
}
| formal_parameter_list "->" "!"
{
$$ = std::make_shared<elna::boot::procedure_type_expression>(elna::boot::make_position(@1),
elna::boot::no_return);
std::swap($1, $$->parameters);
}
| formal_parameter_list "->" type_expression
{
$$ = std::make_shared<elna::boot::procedure_type_expression>(elna::boot::make_position(@1), $3);
std::swap($1, $$->parameters);
$$.second = std::make_shared<elna::boot::procedure_type_expression>(elna::boot::make_position(@1),
std::move($4));
for (auto& [name, type] : $2)
{
$$.first.emplace_back(std::move(name));
$$.second->parameters.push_back(type);
}
}
procedure_definition:
"proc" identifier_definition procedure_heading ";" block
{
$$ = new elna::boot::procedure_definition(elna::boot::make_position(@1), $2.first, $2.second, $3, $5);
$$ = new elna::boot::procedure_definition(elna::boot::make_position(@1),
$2.first, $2.second, $3.second, $5);
std::swap($3.first, $$->parameter_names);
}
| "proc" identifier_definition procedure_heading ";" "extern"
{
$$ = new elna::boot::procedure_definition(elna::boot::make_position(@1), $2.first, $2.second, $3);
$$ = new elna::boot::procedure_definition(elna::boot::make_position(@1), $2.first, $2.second, $3.second);
std::swap($3.first, $$->parameter_names);
}
procedure_definitions:
procedure_definition procedure_definitions
@ -293,47 +294,50 @@ defer_statement: DEFER statements "end"
literal:
INTEGER
{
$$ = new elna::boot::number_literal<std::int32_t>(elna::boot::make_position(@1), $1);
$$ = new elna::boot::literal<std::int32_t>(elna::boot::make_position(@1), $1);
}
| WORD
{
$$ = new elna::boot::number_literal<std::uint32_t>(elna::boot::make_position(@1), $1);
$$ = new elna::boot::literal<std::uint32_t>(elna::boot::make_position(@1), $1);
}
| FLOAT
{
$$ = new elna::boot::number_literal<double>(elna::boot::make_position(@1), $1);
$$ = new elna::boot::literal<double>(elna::boot::make_position(@1), $1);
}
| BOOLEAN
{
$$ = new elna::boot::number_literal<bool>(elna::boot::make_position(@1), $1);
$$ = new elna::boot::literal<bool>(elna::boot::make_position(@1), $1);
}
| CHARACTER
{
$$ = new elna::boot::number_literal<unsigned char>(elna::boot::make_position(@1), $1.at(0));
$$ = new elna::boot::literal<unsigned char>(elna::boot::make_position(@1), $1.at(0));
}
| "nil"
{
$$ = new elna::boot::number_literal<std::nullptr_t>(elna::boot::make_position(@1), nullptr);
$$ = new elna::boot::literal<std::nullptr_t>(elna::boot::make_position(@1), nullptr);
}
| STRING
{
$$ = new elna::boot::number_literal<std::string>(elna::boot::make_position(@1), $1);
$$ = new elna::boot::literal<std::string>(elna::boot::make_position(@1), $1);
}
traits_expression:
TRAIT "(" type_expression ")"
TRAIT "(" type_expressions ")"
{
$$ = new elna::boot::traits_expression(elna::boot::make_position(@1), $1, $3);
$$ = new elna::boot::traits_expression(elna::boot::make_position(@1), $1);
std::swap($3, $$->parameters);
}
operand:
qualident:
literal { $$ = $1; }
| designator_expression { $$ = $1; }
| traits_expression { $$ = $1; }
| cast_expression { $$ = $1; }
| call_expression { $$ = $1; }
| "(" expression ")" { $$ = $2; }
expression:
operand:
unary_expression { $$ = $1; }
| binary_expression { $$ = $1; }
| qualident { $$ = $1; }
expression:
binary_expression { $$ = $1; }
| operand { $$ = $1; }
binary_expression:
expression "*" expression
@ -391,12 +395,12 @@ binary_expression:
$$ = new elna::boot::binary_expression(elna::boot::make_position(@2), $1, $3,
elna::boot::binary_operator::greater_equal);
}
| expression "and" expression
| expression "&" expression
{
$$ = new elna::boot::binary_expression(elna::boot::make_position(@2), $1, $3,
elna::boot::binary_operator::conjunction);
}
| expression "or" expression
| expression "|" expression
{
$$ = new elna::boot::binary_expression(elna::boot::make_position(@2), $1, $3,
elna::boot::binary_operator::disjunction);
@ -422,7 +426,7 @@ unary_expression:
$$ = new elna::boot::unary_expression(elna::boot::make_position(@1), $2,
elna::boot::unary_operator::reference);
}
| "not" operand
| "~" operand
{
$$ = new elna::boot::unary_expression(elna::boot::make_position(@1), $2,
elna::boot::unary_operator::negation);
@ -438,17 +442,24 @@ expressions:
std::swap($$, $3);
$$.emplace($$.cbegin(), $1);
}
| expression { $$.emplace_back(std::move($1)); }
| expression { $$.push_back($1); }
type_expressions:
type_expression "," type_expressions
{
std::swap($$, $3);
$$.emplace($$.cbegin(), $1);
}
| type_expression { $$.push_back($1); }
designator_expression:
operand "[" expression "]"
qualident "[" expression "]"
{
$$ = new elna::boot::array_access_expression(elna::boot::make_position(@2), $1, $3);
}
| operand "." IDENTIFIER
| qualident "." IDENTIFIER
{
$$ = new elna::boot::field_access_expression(elna::boot::make_position(@2), $1, $3);
}
| operand "^"
| qualident "^"
{
$$ = new elna::boot::dereference_expression(elna::boot::make_position(@1), $1);
}
@ -500,9 +511,12 @@ type_expression:
{
$$ = std::make_shared<elna::boot::union_type_expression>(elna::boot::make_position(@1), std::move($2));
}
| "proc" procedure_heading
| "proc" "(" type_expressions ")" return_declaration
{
$$ = $2;
auto result = std::make_shared<elna::boot::procedure_type_expression>(elna::boot::make_position(@1),
std::move($5));
std::swap(result->parameters, $3);
$$ = result;
}
| IDENTIFIER
{
@ -559,18 +573,16 @@ type_part:
| "type" type_definitions { std::swap($$, $2); }
formal_parameter: IDENTIFIER ":" type_expression
{
$$ = new elna::boot::variable_declaration(elna::boot::make_position(@2), $1, $3);
$$ = std::make_pair($1, $3);
}
formal_parameters:
formal_parameter "," formal_parameters
/* no formal parameters */ {}
| formal_parameter "," formal_parameters
{
std::swap($$, $3);
$$.emplace($$.cbegin(), $1);
}
| formal_parameter { $$.emplace_back(std::move($1)); }
formal_parameter_list:
"(" ")" {}
| "(" formal_parameters ")" { std::swap($$, $2); }
actual_parameter_list:
"(" ")" {}
| "(" expressions ")" { std::swap($$, $2); }

View File

@ -17,9 +17,7 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/result.h"
namespace elna
{
namespace boot
namespace elna::boot
{
error::error(const char *path, const struct position position)
: position(position), path(path)
@ -46,4 +44,3 @@ namespace boot
return m_errors;
}
}
}

View File

@ -17,9 +17,7 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/semantic.h"
namespace elna
{
namespace boot
namespace elna::boot
{
undeclared_error::undeclared_error(const std::string& identifier, const char *path, const struct position position)
: error(path, position), identifier(identifier)
@ -121,5 +119,129 @@ namespace boot
void declaration_visitor::visit(procedure_type_expression *)
{
}
}
void declaration_visitor::visit(variable_declaration *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(constant_definition *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(procedure_definition *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(assign_statement *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(if_statement *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(while_statement *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(return_statement *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(defer_statement *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(procedure_call *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(block *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(traits_expression *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(cast_expression *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(binary_expression *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(unary_expression *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(variable_expression *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(array_access_expression *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(field_access_expression *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(dereference_expression *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(literal<std::int32_t> *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(literal<std::uint32_t> *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(literal<double> *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(literal<bool> *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(literal<unsigned char> *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(literal<std::nullptr_t> *)
{
__builtin_unreachable();
}
void declaration_visitor::visit(literal<std::string> *)
{
__builtin_unreachable();
}
}

View File

@ -17,9 +17,7 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/symbol.h"
namespace elna
{
namespace boot
namespace elna::boot
{
type::type()
{
@ -301,4 +299,3 @@ namespace boot
return result;
}
}
}