Skip parameter names in procedure type expressions
This commit is contained in:
28
boot/ast.cc
28
boot/ast.cc
@ -17,9 +17,7 @@ along with GCC; see the file COPYING3. If not see
|
||||
|
||||
#include "elna/boot/ast.h"
|
||||
|
||||
namespace elna
|
||||
{
|
||||
namespace boot
|
||||
namespace elna::boot
|
||||
{
|
||||
void empty_visitor::visit(variable_declaration *)
|
||||
{
|
||||
@ -538,14 +536,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 +557,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)
|
||||
@ -1212,4 +1207,3 @@ namespace boot
|
||||
__builtin_unreachable();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,10 +122,9 @@ along with GCC; see the file COPYING3. If not see
|
||||
%type <elna::boot::literal *> 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::unary_expression *> unary_expression;
|
||||
@ -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
|
||||
@ -438,7 +439,14 @@ 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 "]"
|
||||
{
|
||||
@ -500,9 +508,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 +570,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); }
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
@ -122,4 +120,3 @@ namespace boot
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user