diff options
Diffstat (limited to 'boot/ast.cc')
| -rw-r--r-- | boot/ast.cc | 137 |
1 files changed, 68 insertions, 69 deletions
diff --git a/boot/ast.cc b/boot/ast.cc index 0931a2c..9b3fbe4 100644 --- a/boot/ast.cc +++ b/boot/ast.cc @@ -17,6 +17,8 @@ along with GCC; see the file COPYING3. If not see #include "elna/boot/ast.h" +#include <utility> + namespace elna::boot { void empty_visitor::visit(array_type_expression *) @@ -210,11 +212,11 @@ namespace elna::boot } if (declaration->body.has_value()) { - for (variable_declaration *const variable : declaration->body.value().variables) + for (variable_declaration *variable : declaration->body.value().variables) { variable->accept(this); } - for (statement *const statement : declaration->body.value().entry_point) + for (auto *statement : declaration->body.value().entry_point) { statement->accept(this); } @@ -234,22 +236,22 @@ namespace elna::boot void walking_visitor::visit(if_statement *statement) { statement->branch().prerequisite().accept(this); - for (struct statement *const branch_statement : statement->branch().statements) + for (auto *branch_statement : statement->branch().statements) { branch_statement->accept(this); } - for (conditional_statements *const branch : statement->branches) + for (conditional_statements *branch : statement->branches) { branch->prerequisite().accept(this); - for (struct statement *const branch_statement : branch->statements) + for (auto *branch_statement : branch->statements) { branch_statement->accept(this); } } if (statement->alternative != nullptr) { - for (struct statement *const branch_statement : *statement->alternative) + for (auto *branch_statement : *statement->alternative) { branch_statement->accept(this); } @@ -259,15 +261,15 @@ namespace elna::boot void walking_visitor::visit(while_statement *statement) { statement->branch().prerequisite().accept(this); - for (struct statement *const branch_statement : statement->branch().statements) + for (auto *branch_statement : statement->branch().statements) { branch_statement->accept(this); } - for (conditional_statements *const branch : statement->branches) + for (conditional_statements *branch : statement->branches) { branch->prerequisite().accept(this); - for (struct statement *const branch_statement : branch->statements) + for (auto *branch_statement : branch->statements) { branch_statement->accept(this); } @@ -276,7 +278,7 @@ namespace elna::boot void walking_visitor::visit(defer_statement *statement) { - for (struct statement *const block_statement : statement->statements) + for (auto *block_statement : statement->statements) { block_statement->accept(this); } @@ -291,18 +293,18 @@ namespace elna::boot statement->condition().accept(this); for (const switch_case& case_block : statement->cases) { - for (expression *const case_label : case_block.labels) + for (expression *case_label : case_block.labels) { case_label->accept(this); } - for (struct statement *const block_statement : case_block.statements) + for (auto *block_statement : case_block.statements) { block_statement->accept(this); } } if (statement->alternative != nullptr) { - for (struct statement *const block_statement : *statement->alternative) + for (auto *block_statement : *statement->alternative) { block_statement->accept(this); } @@ -312,7 +314,7 @@ namespace elna::boot void walking_visitor::visit(procedure_call *call) { call->callable().accept(this); - for (expression *const argument : call->arguments) + for (expression *argument : call->arguments) { argument->accept(this); } @@ -320,23 +322,23 @@ namespace elna::boot void walking_visitor::visit(unit *unit) { - for (import_declaration *const _import : unit->imports) + for (import_declaration *_import : unit->imports) { _import->accept(this); } - for (type_declaration *const type : unit->types) + for (type_declaration *type : unit->types) { type->accept(this); } - for (variable_declaration *const variable : unit->variables) + for (variable_declaration *variable : unit->variables) { variable->accept(this); } - for (procedure_declaration *const procedure : unit->procedures) + for (procedure_declaration *procedure : unit->procedures) { procedure->accept(this); } - for (statement *const entry_statement : unit->entry_point) + for (auto *entry_statement : unit->entry_point) { entry_statement->accept(this); } @@ -412,7 +414,7 @@ namespace elna::boot void walking_visitor::visit(array_constructor_expression *expression) { expression->m_element_type->accept(this); - for (auto element : expression->elements) + for (auto *element : expression->elements) { element->accept(this); } @@ -490,9 +492,7 @@ namespace elna::boot { } - node::~node() - { - } + node::~node() = default; const source_position& node::position() const { @@ -756,7 +756,7 @@ namespace elna::boot array_constructor_expression::~array_constructor_expression() { delete m_element_type; - for (expression *const element : elements) + for (const expression *element : elements) { delete element; } @@ -765,14 +765,14 @@ namespace elna::boot variable_declaration::variable_declaration(const source_position position, std::vector<identifier_definition>&& identifier, std::shared_ptr<type_expression> variable_type, expression *initializer) - : node(position), m_variable_type(variable_type), identifiers(std::move(identifier)), initializer(initializer) + : node(position), m_variable_type(std::move(variable_type)), identifiers(std::move(identifier)), initializer(initializer) { } variable_declaration::variable_declaration(const source_position position, std::vector<identifier_definition>&& identifier, std::shared_ptr<type_expression> variable_type, std::monostate) - : node(position), m_variable_type(variable_type), identifiers(std::move(identifier)), is_extern(true) + : node(position), m_variable_type(std::move(variable_type)), identifiers(std::move(identifier)), is_extern(true) { } @@ -792,7 +792,7 @@ namespace elna::boot } declaration::declaration(const source_position position, identifier_definition identifier) - : node(position), identifier(identifier) + : node(position), identifier(std::move(identifier)) { } @@ -804,10 +804,7 @@ namespace elna::boot procedure_type_expression::~procedure_type_expression() { - if (return_type.proper_type != nullptr) - { - delete return_type.proper_type; - } + delete return_type.proper_type; } void procedure_type_expression::accept(parser_visitor *visitor) @@ -838,14 +835,14 @@ namespace elna::boot procedure_declaration::procedure_declaration(const source_position position, identifier_definition identifier, procedure_type_expression *heading, procedure_body&& body) - : declaration(position, identifier), m_heading(heading), + : declaration(position, std::move(identifier)), m_heading(heading), body(std::make_optional<procedure_body>(std::move(body))) { } procedure_declaration::procedure_declaration(const source_position position, identifier_definition identifier, procedure_type_expression *heading) - : declaration(position, identifier), m_heading(heading) + : declaration(position, std::move(identifier)), m_heading(heading) { } @@ -866,7 +863,7 @@ namespace elna::boot type_declaration::type_declaration(const source_position position, identifier_definition identifier, type_expression *underlying_type) - : declaration(position, identifier), m_underlying_type(underlying_type) + : declaration(position, std::move(identifier)), m_underlying_type(underlying_type) { } @@ -901,11 +898,11 @@ namespace elna::boot procedure_body::~procedure_body() { - for (statement *body_statement : this->entry_point) + for (const statement *body_statement : this->entry_point) { delete body_statement; } - for (variable_declaration *variable : this->variables) + for (const variable_declaration *variable : this->variables) { delete variable; } @@ -941,15 +938,15 @@ namespace elna::boot unit::~unit() { - for (procedure_declaration *procedure : this->procedures) + for (const procedure_declaration *procedure : this->procedures) { delete procedure; } - for (type_declaration *type : this->types) + for (const type_declaration *type : this->types) { delete type; } - for (import_declaration *declaration : this->imports) + for (const import_declaration *declaration : this->imports) { delete declaration; } @@ -972,7 +969,7 @@ namespace elna::boot defer_statement::~defer_statement() { - for (statement *body_statement : statements) + for (const statement *body_statement : statements) { delete body_statement; } @@ -988,9 +985,7 @@ namespace elna::boot { } - designator_expression::~designator_expression() - { - } + designator_expression::~designator_expression() = default; designator_expression *designator_expression::is_designator() { @@ -1001,21 +996,24 @@ namespace elna::boot { if (named_expression *node = is_named()) { - return visitor->visit(node); + visitor->visit(node); } else if (array_access_expression *node = is_array_access()) { - return visitor->visit(node); + visitor->visit(node); } else if (field_access_expression *node = is_field_access()) { - return visitor->visit(node); + visitor->visit(node); } else if (dereference_expression *node = is_dereference()) { - return visitor->visit(node); + visitor->visit(node); + } + else + { + __builtin_unreachable(); } - __builtin_unreachable(); } named_expression::named_expression(const source_position position, const std::string& name) @@ -1161,7 +1159,7 @@ namespace elna::boot unary_expression::unary_expression(const source_position position, expression *operand, const unary_operator operation) - : node(position), m_operand(std::move(operand)), m_operator(operation) + : node(position), m_operand(operand), m_operator(operation) { } @@ -1213,7 +1211,7 @@ namespace elna::boot procedure_call::~procedure_call() { - for (expression *const argument : arguments) + for (const expression *argument : arguments) { delete argument; } @@ -1288,7 +1286,7 @@ namespace elna::boot conditional_statements::~conditional_statements() { delete m_prerequisite; - for (auto statement : statements) + for (auto *statement : statements) { delete statement; } @@ -1376,7 +1374,7 @@ namespace elna::boot if_statement::~if_statement() { delete m_branch; - for (conditional_statements *const branch : branches) + for (const conditional_statements *branch : branches) { delete branch; } @@ -1412,7 +1410,7 @@ namespace elna::boot while_statement::~while_statement() { delete m_branch; - for (conditional_statements *const branch : branches) + for (const conditional_statements *branch : branches) { delete branch; } @@ -1422,37 +1420,38 @@ namespace elna::boot { switch (operation) { - case binary_operator::sum: + using enum binary_operator; + case sum: return "+"; - case binary_operator::subtraction: + case subtraction: return "-"; - case binary_operator::multiplication: + case multiplication: return "*"; - case binary_operator::division: + case division: return "/"; - case binary_operator::remainder: + case remainder: return "%"; - case binary_operator::equals: + case equals: return "="; - case binary_operator::not_equals: + case not_equals: return "<>"; - case binary_operator::less: + case less: return "<"; - case binary_operator::less_equal: + case less_equal: return "<="; - case binary_operator::greater: + case greater: return ">"; - case binary_operator::greater_equal: + case greater_equal: return ">="; - case binary_operator::conjunction: + case conjunction: return "and"; - case binary_operator::disjunction: + case disjunction: return "or"; - case binary_operator::exclusive_disjunction: + case exclusive_disjunction: return "xor"; - case binary_operator::shift_left: + case shift_left: return "<<"; - case binary_operator::shift_right: + case shift_right: return ">>"; } __builtin_unreachable(); |
