Add second GENERIC visitor

This commit is contained in:
2025-03-04 22:56:32 +01:00
parent c5930285bf
commit 8dc02047df
12 changed files with 572 additions and 341 deletions

View File

@ -191,6 +191,10 @@ namespace boot
{
}
node::~node()
{
}
const struct position& node::position() const
{
return this->source_position;
@ -200,10 +204,145 @@ namespace boot
{
}
statement::~statement()
{
}
assign_statement *statement::is_assign()
{
return nullptr;
}
if_statement *statement::is_if()
{
return nullptr;
}
while_statement *statement::is_while()
{
return nullptr;
}
return_statement *statement::is_return()
{
return nullptr;
}
defer_statement *statement::is_defer()
{
return nullptr;
}
procedure_call *statement::is_call_statement()
{
return nullptr;
}
void statement::accept(parser_visitor *visitor)
{
if (assign_statement *node = is_assign())
{
return node->accept(visitor);
}
else if (if_statement *node = is_if())
{
return node->accept(visitor);
}
else if (while_statement *node = is_while())
{
return node->accept(visitor);
}
else if (return_statement *node = is_return())
{
return node->accept(visitor);
}
else if (defer_statement *node = is_defer())
{
return node->accept(visitor);
}
else if (procedure_call *node = is_call_statement())
{
return node->accept(visitor);
}
__builtin_unreachable();
}
expression::expression()
{
}
expression::~expression()
{
}
cast_expression *expression::is_cast()
{
return nullptr;
}
traits_expression *expression::is_traits()
{
return nullptr;
}
binary_expression *expression::is_binary()
{
return nullptr;
}
unary_expression *expression::is_unary()
{
return nullptr;
}
designator_expression *expression::is_designator()
{
return nullptr;
}
procedure_call *expression::is_call_expression()
{
return nullptr;
}
literal *expression::is_literal()
{
return nullptr;
}
void expression::accept(parser_visitor *visitor)
{
if (cast_expression *node = is_cast())
{
return node->accept(visitor);
}
else if (traits_expression *node = is_traits())
{
return node->accept(visitor);
}
else if (binary_expression *node = is_binary())
{
return node->accept(visitor);
}
else if (unary_expression *node = is_unary())
{
return node->accept(visitor);
}
else if (designator_expression *node = is_designator())
{
return node->accept(visitor);
}
else if (procedure_call *node = is_call_expression())
{
return node->accept(visitor);
}
else if (literal *node = is_literal())
{
return node->accept(visitor);
}
__builtin_unreachable();
}
type_expression::type_expression(const struct position position)
: node(position)
{
@ -239,6 +378,35 @@ namespace boot
return nullptr;
}
void type_expression::accept(parser_visitor *visitor)
{
if (std::shared_ptr<primitive_type_expression> node = is_primitive())
{
return node->accept(visitor);
}
else if (std::shared_ptr<array_type_expression> node = is_array())
{
return node->accept(visitor);
}
else if (std::shared_ptr<pointer_type_expression> node = is_pointer())
{
return node->accept(visitor);
}
else if (std::shared_ptr<record_type_expression> node = is_record())
{
return node->accept(visitor);
}
else if (std::shared_ptr<union_type_expression> node = is_union())
{
return node->accept(visitor);
}
else if (std::shared_ptr<procedure_type_expression> node = is_procedure())
{
return node->accept(visitor);
}
__builtin_unreachable();
}
primitive_type_expression::primitive_type_expression(const struct position position, const std::string& name)
: type_expression(position), name(name)
{
@ -486,6 +654,47 @@ namespace boot
{
}
literal *literal::is_literal()
{
return this;
}
void literal::accept(parser_visitor *visitor)
{
if (number_literal<std::int32_t> *node = is_int())
{
return node->accept(visitor);
}
else if (number_literal<std::uint32_t> *node = is_word())
{
return node->accept(visitor);
}
else if (number_literal<double> *node = is_float())
{
return node->accept(visitor);
}
else if (number_literal<bool> *node = is_bool())
{
return node->accept(visitor);
}
else if (number_literal<unsigned char> *node = is_char())
{
return node->accept(visitor);
}
else if (number_literal<std::nullptr_t> *node = is_nil())
{
return node->accept(visitor);
}
else if (number_literal<std::string> *node = is_string())
{
return node->accept(visitor);
}
else
{
__builtin_unreachable();
}
}
defer_statement::defer_statement(const struct position position)
: node(position)
{
@ -496,6 +705,11 @@ namespace boot
visitor->visit(this);
}
defer_statement *defer_statement::is_defer()
{
return this;
}
defer_statement::~defer_statement()
{
for (statement *body_statement : statements)
@ -508,6 +722,36 @@ namespace boot
{
}
designator_expression::~designator_expression()
{
}
designator_expression *designator_expression::is_designator()
{
return this;
}
void designator_expression::accept(parser_visitor *visitor)
{
if (variable_expression *node = is_variable())
{
return visitor->visit(node);
}
else if (array_access_expression *node = is_array_access())
{
return visitor->visit(node);
}
else if (field_access_expression *node = is_field_access())
{
return visitor->visit(node);
}
else if (dereference_expression *node = is_dereference())
{
return visitor->visit(node);
}
__builtin_unreachable();
}
variable_expression::variable_expression(const struct position position, const std::string& name)
: node(position), name(name)
{
@ -623,6 +867,11 @@ namespace boot
visitor->visit(this);
}
binary_expression *binary_expression::is_binary()
{
return this;
}
expression& binary_expression::lhs()
{
return *m_lhs;
@ -655,6 +904,11 @@ namespace boot
visitor->visit(this);
}
unary_expression *unary_expression::is_unary()
{
return this;
}
expression& unary_expression::operand()
{
return *m_operand;
@ -680,6 +934,16 @@ namespace boot
visitor->visit(this);
}
procedure_call *procedure_call::is_call_statement()
{
return this;
}
procedure_call *procedure_call::is_call_expression()
{
return this;
}
designator_expression& procedure_call::callable()
{
return *m_callable;
@ -705,6 +969,11 @@ namespace boot
visitor->visit(this);
}
cast_expression *cast_expression::is_cast()
{
return this;
}
type_expression& cast_expression::target()
{
return *m_target;
@ -731,6 +1000,11 @@ namespace boot
visitor->visit(this);
}
traits_expression *traits_expression::is_traits()
{
return this;
}
type_expression& traits_expression::type()
{
return *m_type;
@ -765,6 +1039,11 @@ namespace boot
visitor->visit(this);
}
return_statement *return_statement::is_return()
{
return this;
}
expression *return_statement::return_expression()
{
return m_return_expression;
@ -775,15 +1054,20 @@ namespace boot
delete m_return_expression;
}
assign_statement::assign_statement(const struct position position, designator_expression *lvalue,
expression *rvalue)
: node(position), m_lvalue(lvalue), m_rvalue(rvalue)
{
}
void assign_statement::accept(parser_visitor *visitor)
{
visitor->visit(this);
}
assign_statement::assign_statement(const struct position position, designator_expression *lvalue,
expression *rvalue)
: node(position), m_lvalue(lvalue), m_rvalue(rvalue)
assign_statement *assign_statement::is_assign()
{
return this;
}
variable_expression *designator_expression::is_variable()
@ -832,6 +1116,11 @@ namespace boot
visitor->visit(this);
}
if_statement *if_statement::is_if()
{
return this;
}
conditional_statements& if_statement::body()
{
return *m_body;
@ -862,6 +1151,11 @@ namespace boot
visitor->visit(this);
}
while_statement *while_statement::is_while()
{
return this;
}
conditional_statements& while_statement::body()
{
return *m_body;

View File

@ -1,33 +0,0 @@
/* Semantic analysis visitors.
Copyright (C) 2025 Free Software Foundation, Inc.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "elna/boot/semantic.h"
namespace elna
{
namespace boot
{
declaration_visitor::declaration_visitor(std::shared_ptr<symbol_table> table)
: table(table)
{
}
void declaration_visitor::visit(program *program)
{
}
}
}

View File

@ -1,37 +0,0 @@
/* Symbol definitions.
Copyright (C) 2025 Free Software Foundation, Inc.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "elna/boot/symbol.h"
namespace elna
{
namespace boot
{
type::~type()
{
}
info::~info()
{
}
type_info::type_info(const std::string& name)
: name(name)
{
}
}
}