Skip parameter names in procedure type expressions
This commit is contained in:
70
boot/ast.cc
70
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 *)
|
||||
{
|
||||
@ -151,37 +149,37 @@ namespace boot
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<std::int32_t> *)
|
||||
void empty_visitor::visit(literal<std::int32_t> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<std::uint32_t> *)
|
||||
void empty_visitor::visit(literal<std::uint32_t> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<double> *)
|
||||
void empty_visitor::visit(literal<double> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<bool> *)
|
||||
void empty_visitor::visit(literal<bool> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<unsigned char> *)
|
||||
void empty_visitor::visit(literal<unsigned char> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<std::nullptr_t> *)
|
||||
void empty_visitor::visit(literal<std::nullptr_t> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<std::string> *)
|
||||
void empty_visitor::visit(literal<std::string> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
@ -305,7 +303,7 @@ namespace boot
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
literal *expression::is_literal()
|
||||
literal_expression *expression::is_literal()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@ -336,7 +334,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 +516,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 +526,7 @@ namespace boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
literal& constant_definition::body()
|
||||
literal_expression& constant_definition::body()
|
||||
{
|
||||
return *m_body;
|
||||
}
|
||||
@ -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)
|
||||
@ -652,42 +647,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);
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,13 +119,12 @@ along with GCC; see the file COPYING3. If not see
|
||||
%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::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
|
||||
@ -293,31 +294,31 @@ 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 ")"
|
||||
@ -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