/* Visitor generating a GENERIC tree.
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
. */
#pragma once
#include "elna/boot/ast.h"
#include "elna/boot/symbol.h"
#include "elna/gcc/elna-tree.h"
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tree.h"
#include "tree-iterator.h"
#include
#include
namespace elna
{
namespace gcc
{
class generic_visitor final : public boot::empty_visitor
{
tree current_expression{ NULL_TREE };
std::shared_ptr> symbol_map;
tree build_label_decl(const char *name, location_t loc);
tree build_type(boot::type_expression& type);
void enter_scope();
tree leave_scope();
tree lookup(const std::string& name);
void make_if_branch(boot::conditional_statements& branch, tree goto_endif);
tree build_arithmetic_operation(boot::binary_expression *expression,
tree_code operator_code, tree left, tree right);
tree build_comparison_operation(boot::binary_expression *expression,
tree_code operator_code, tree left, tree right);
tree build_logic_operation(boot::binary_expression *expression,
tree_code operator_code, tree left, tree right);
tree build_equality_operation(boot::binary_expression *expression, tree left, tree right);
void build_procedure_call(location_t call_location,
tree symbol, const std::vector& arguments);
void build_record_call(location_t call_location,
tree symbol, const std::vector& arguments);
public:
generic_visitor(std::shared_ptr> symbol_table);
void visit(boot::program *program) override;
void visit(boot::procedure_definition *definition) override;
void visit(boot::call_expression *expression) override;
void visit(boot::cast_expression *expression) override;
void visit(boot::size_of_expression *expression) override;
void visit(boot::number_literal *literal) override;
void visit(boot::number_literal *literal) override;
void visit(boot::number_literal *literal) override;
void visit(boot::number_literal *boolean) override;
void visit(boot::number_literal *character) override;
void visit(boot::number_literal *) override;
void visit(boot::number_literal *string) override;
void visit(boot::binary_expression *expression) override;
void visit(boot::unary_expression *expression) override;
void visit(boot::constant_definition *definition) override;
void visit(boot::type_definition *definition) override;
void visit(boot::variable_declaration *declaration) override;
void visit(boot::variable_expression *expression) override;
void visit(boot::array_access_expression *expression) override;
void visit(boot::field_access_expression *expression) override;
void visit(boot::dereference_expression *expression) override;
void visit(boot::assign_statement *statement) override;
void visit(boot::if_statement *statement) override;
void visit(boot::while_statement *statement) override;
void visit(boot::call_statement *statement) override;
void visit(boot::return_statement *statement) override;
void visit(boot::defer_statement *statement) override;
};
}
}