119 lines
5.6 KiB
C++
119 lines
5.6 KiB
C++
/* 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
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#pragma once
|
|
|
|
#include "elna/boot/ast.h"
|
|
#include "elna/boot/symbol.h"
|
|
#include "elna/boot/semantic.h"
|
|
#include "elna/gcc/elna-tree.h"
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "coretypes.h"
|
|
#include "tree.h"
|
|
#include "tree-iterator.h"
|
|
|
|
#include <string>
|
|
#include <forward_list>
|
|
|
|
namespace elna::gcc
|
|
{
|
|
std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path,
|
|
std::unique_ptr<boot::program>& ast, std::shared_ptr<boot::symbol_table> info_table,
|
|
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved);
|
|
tree handle_symbol(const std::string& symbol_name, std::shared_ptr<boot::alias_type> reference,
|
|
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved,
|
|
std::vector<std::string>& path);
|
|
|
|
|
|
class generic_visitor final : public boot::parser_visitor
|
|
{
|
|
tree current_expression{ NULL_TREE };
|
|
std::shared_ptr<symbol_table> symbols;
|
|
std::unordered_map<std::string, tree> unresolved;
|
|
std::forward_list<std::pair<tree, tree>> loops;
|
|
|
|
void declare_procedure(boot::procedure_definition *const definition);
|
|
tree build_procedure_type(boot::procedure_type_expression& type);
|
|
void build_composite_type(const std::vector<boot::field_declaration>& fields,
|
|
tree composite_type_node);
|
|
|
|
void enter_scope();
|
|
tree leave_scope();
|
|
|
|
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_bit_logic_operation(boot::binary_expression *expression, 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 procedure_address, const std::vector<boot::expression *>& arguments);
|
|
void build_record_call(location_t call_location,
|
|
tree symbol, const std::vector<boot::expression *>& arguments);
|
|
|
|
bool expect_trait_type_only(boot::traits_expression *trait);
|
|
bool expect_trait_for_integral_type(boot::traits_expression *trait);
|
|
void visit_statements(const std::vector<boot::statement *>& statements);
|
|
bool extract_constant(location_t expression_location);
|
|
|
|
public:
|
|
generic_visitor(std::shared_ptr<symbol_table> symbol_table,
|
|
std::unordered_map<std::string, tree>&& unresolved);
|
|
|
|
void visit(boot::program *program) override;
|
|
void visit(boot::procedure_definition *definition) override;
|
|
void visit(boot::procedure_call *call) override;
|
|
void visit(boot::cast_expression *expression) override;
|
|
void visit(boot::traits_expression *trait) override;
|
|
void visit(boot::literal<std::int32_t> *literal) override;
|
|
void visit(boot::literal<std::uint32_t> *literal) override;
|
|
void visit(boot::literal<double> *literal) override;
|
|
void visit(boot::literal<bool> *boolean) override;
|
|
void visit(boot::literal<unsigned char> *character) override;
|
|
void visit(boot::literal<std::nullptr_t> *) override;
|
|
void visit(boot::literal<std::string> *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::block *block) override;
|
|
void visit(boot::assign_statement *statement) override;
|
|
void visit(boot::if_statement *statement) override;
|
|
void visit(boot::escape_statement *statement) override;
|
|
void visit(boot::while_statement *statement) override;
|
|
void visit(boot::named_type_expression *type) override;
|
|
void visit(boot::array_type_expression *type) override;
|
|
void visit(boot::pointer_type_expression *type) override;
|
|
void visit(boot::record_type_expression *type) override;
|
|
void visit(boot::union_type_expression *type) override;
|
|
void visit(boot::procedure_type_expression *type) override;
|
|
void visit(boot::enumeration_type_expression *type) override;
|
|
void visit(boot::return_statement *statement) override;
|
|
void visit(boot::defer_statement *statement) override;
|
|
void visit(boot::case_statement *statement) override;
|
|
};
|
|
}
|