diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-10-08 01:46:45 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-10-08 01:46:45 +0200 |
| commit | d392f0c54a7748b816ab327758ae835f73cd1c0a (patch) | |
| tree | a7c029dffab842acbd4f5f0cab5685a93e9b9747 /boot/ast.cc | |
| parent | d4b7f5e52a33f2d15aafca7f1b040f3f2821fd0c (diff) | |
| download | elna-d392f0c54a7748b816ab327758ae835f73cd1c0a.tar.gz | |
Allow initialized declarations without an explicit type
Diffstat (limited to 'boot/ast.cc')
| -rw-r--r-- | boot/ast.cc | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/boot/ast.cc b/boot/ast.cc index d698cd4..69b15d3 100644 --- a/boot/ast.cc +++ b/boot/ast.cc @@ -352,7 +352,10 @@ namespace elna::boot void walking_visitor::visit(variable_declaration *declaration) { - declaration->variable_type().accept(this); + if (declaration->variable_type != nullptr) + { + declaration->variable_type->accept(this); + } if (declaration->initializer != nullptr) { declaration->initializer->accept(this); @@ -895,17 +898,24 @@ 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(std::move(variable_type)), identifiers(std::move(identifier)), initializer(initializer) + std::vector<identifier_definition>&& identifier, type_expression *variable_type, + expression *initializer, const bool is_const) + : node(position), identifiers(std::move(identifier)), variable_type(variable_type), + initializer(initializer), is_const(is_const) { } variable_declaration::variable_declaration(const source_position position, - std::vector<identifier_definition>&& identifier, std::shared_ptr<type_expression> variable_type, + std::vector<identifier_definition>&& identifier, type_expression *variable_type, std::monostate) - : node(position), m_variable_type(std::move(variable_type)), identifiers(std::move(identifier)), is_extern(true) + : node(position), identifiers(std::move(identifier)), variable_type(variable_type), + is_extern(true) + { + } + + variable_declaration::~variable_declaration() { + delete this->variable_type; } void variable_declaration::accept(parser_visitor *visitor) @@ -918,11 +928,6 @@ namespace elna::boot return this->is_extern || this->initializer != nullptr; } - type_expression& variable_declaration::variable_type() - { - return *m_variable_type; - } - procedure_type_expression::procedure_type_expression(const source_position position, std::vector<field_declaration>&& parameters, type_expression *return_type) : node(position), return_type(return_type), parameters(std::move(parameters)) |
