diff options
Diffstat (limited to 'boot')
| -rw-r--r-- | boot/ast.cc | 11 | ||||
| -rw-r--r-- | boot/name_analysis.cc | 5 | ||||
| -rw-r--r-- | boot/parser.yy | 16 | ||||
| -rw-r--r-- | boot/type_check.cc | 7 |
4 files changed, 14 insertions, 25 deletions
diff --git a/boot/ast.cc b/boot/ast.cc index 1f2b884..d4f015b 100644 --- a/boot/ast.cc +++ b/boot/ast.cc @@ -461,7 +461,6 @@ namespace elna::boot void walking_visitor::visit(array_constructor_expression *expression) { - expression->array_type().accept(this); for (auto *element : expression->elements) { element->accept(this); @@ -844,8 +843,8 @@ namespace elna::boot } array_constructor_expression::array_constructor_expression(const source_position position, - array_type_expression *element_type, std::vector<expression *>&& elements) - : node(position), m_element_type(element_type), elements(std::move(elements)) + std::vector<expression *>&& elements) + : node(position), elements(std::move(elements)) { } @@ -859,14 +858,8 @@ namespace elna::boot return this; } - array_type_expression& array_constructor_expression::array_type() const - { - return *this->m_element_type; - } - array_constructor_expression::~array_constructor_expression() { - delete this->m_element_type; for (const expression *element : elements) { delete element; diff --git a/boot/name_analysis.cc b/boot/name_analysis.cc index d4b8643..30d3cda 100644 --- a/boot/name_analysis.cc +++ b/boot/name_analysis.cc @@ -470,12 +470,13 @@ namespace elna::boot void name_analysis_visitor::visit(array_constructor_expression *expression) { - expression->array_type().accept(this); - expression->type_decoration = this->current_type; for (auto *element : expression->elements) { element->accept(this); } + const type element_type = expression->elements.front()->type_decoration; + expression->type_decoration = type(std::make_shared<array_type>(element_type, + expression->elements.size())); this->current_type = type(); } diff --git a/boot/parser.yy b/boot/parser.yy index 0c32610..669115b 100644 --- a/boot/parser.yy +++ b/boot/parser.yy @@ -135,7 +135,7 @@ along with GCC; see the file COPYING3. If not see %type <std::vector<elna::boot::type_expression *>> type_expressions; %type <elna::boot::expression *> expression operand simple_expression procedure_return unary_expression; %type <elna::boot::binary_expression *> binary_expression; -%type <std::vector<elna::boot::expression *>> expressions actual_parameter_list; +%type <std::vector<elna::boot::expression *>> optional_expressions required_expressions actual_parameter_list; %type <elna::boot::designator_expression *> designator_expression; %type <std::unique_ptr<elna::boot::procedure_call>> call_expression; %type <elna::boot::statement *> statement; @@ -343,9 +343,9 @@ simple_expression: { $$ = new boot::record_constructor_expression(boot::make_position(@$), std::move(*$1), $3); } - | array_type_expression "{" expressions "}" + | "[" required_expressions "]" { - $$ = new boot::array_constructor_expression(boot::make_position(@$), $1.release(), $3); + $$ = new boot::array_constructor_expression(boot::make_position(@$), $2); } operand: unary_expression { $$ = $1; } @@ -453,14 +453,16 @@ unary_expression: { $$ = new boot::unary_expression(boot::make_position(@$), $2, boot::unary_operator::plus); } -expressions: - expression "," expressions +optional_expressions: + required_expressions { $$ = $1; } + | %empty { $$ = std::vector<elna::boot::expression *>(); } +required_expressions: + expression "," required_expressions { $$ = $3; $$.emplace($$.cbegin(), $1); } | expression { $$.push_back($1); } - | %empty { $$ = std::vector<elna::boot::expression *>(); } type_expressions: type_expression "," type_expressions { @@ -659,7 +661,7 @@ type_part: %empty {} | "type" type_declarations { $$ = $2; } actual_parameter_list: - "(" expressions ")" { $$ = $2; } + "(" optional_expressions ")" { $$ = $2; } %% void yy::parser::error(const location_type& loc, const std::string& message) diff --git a/boot/type_check.cc b/boot/type_check.cc index e810e30..ad27337 100644 --- a/boot/type_check.cc +++ b/boot/type_check.cc @@ -984,13 +984,6 @@ namespace elna::boot type_mismatch_error::expected_type{ type(std::make_shared<array_type>(type(), 0)) }); return; } - if (expression->elements.size() > array->size) - { - add_error<argument_count_error>(expression->position(), - argument_count_error::kind::array, expression->type_decoration.to_string(), - array->size, expression->elements.size()); - return; - } for (auto *element : expression->elements) { if (!is_assignable_from(array->base, element->type_decoration)) |
