Add forward type declaration representation

This commit is contained in:
2025-03-06 03:46:10 +01:00
parent 8dc02047df
commit dbeaca7cbf
5 changed files with 215 additions and 26 deletions

View File

@ -0,0 +1,75 @@
/* Name analysis.
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 <string>
#include <vector>
namespace elna
{
namespace boot
{
class alias_type;
class record_type;
class union_type;
class primitive_type;
class type
{
public:
virtual alias_type *is_alias();
virtual primitive_type *is_primitive();
virtual record_type *is_record();
virtual union_type *is_union();
virtual ~type() = 0;
};
class alias_type : public type
{
public:
alias_type *is_alias() override;
type *reference{ nullptr };
};
class primitive_type : public type
{
public:
std::string identifier;
primitive_type(const std::string& identifier);
primitive_type *is_primitive() override;
};
class record_type : public type
{
public:
std::vector<std::pair<std::string, type *>> fields;
record_type *is_record() override;
};
class union_type : public type
{
public:
std::vector<std::pair<std::string, type *>> fields;
union_type *is_union() override;
};
}
}

View File

@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/ast.h"
#include "elna/boot/symbol.h"
#include "elna/boot/semantic.h"
#include "elna/gcc/elna-tree.h"
#include "config.h"
@ -34,20 +35,15 @@ namespace elna
{
namespace gcc
{
struct type
{
type() {}
type(tree resolved): resolved(resolved) {}
type(std::shared_ptr<type> reference): reference(reference) {}
tree resolved{ NULL_TREE };
std::shared_ptr<type> reference;
};
class declaration_visitor final : public boot::empty_visitor
{
std::shared_ptr<symbol_table> symbols;
std::unordered_map<std::string, std::shared_ptr<type>> unresolved;
std::unordered_map<std::string, boot::alias_type *> unresolved;
boot::type *build_type(boot::type_expression *type_expression);
boot::record_type *build_record(boot::record_type_expression *type_expression);
boot::union_type *build_union(boot::union_type_expression *type_expression);
tree get_inner_alias(const boot::alias_type& t);
public:
declaration_visitor(std::shared_ptr<symbol_table> symbol_table);