Add array_type

This commit is contained in:
2025-03-08 13:55:42 +01:00
parent dc5760394b
commit 868db6e0bf
2 changed files with 198 additions and 41 deletions

View File

@ -18,6 +18,7 @@ along with GCC; see the file COPYING3. If not see
#include <string>
#include <vector>
#include <unordered_map>
#include <memory>
#include "elna/boot/ast.h"
@ -30,6 +31,7 @@ namespace boot
class record_type;
class union_type;
class pointer_type;
class array_type;
class type
{
@ -41,29 +43,41 @@ namespace boot
record,
_union,
pointer,
array
};
type_tag tag{ type_tag::empty };
union
{
nullptr_t empty;
alias_type *alias;
primitive_type *primitive;
record_type *record;
union_type *_union;
pointer_type *pointer;
} payload{ .empty = nullptr };
std::weak_ptr<alias_type> alias;
std::weak_ptr<primitive_type> primitive;
std::shared_ptr<record_type> record;
std::shared_ptr<union_type> _union;
std::shared_ptr<pointer_type> pointer;
std::shared_ptr<array_type> array;
};
type_tag tag{ type_tag::empty };
void copy(const type& other);
void move(type&& other);
public:
type() = default;
explicit type(alias_type *alias);
explicit type(primitive_type *primitive);
explicit type(record_type *record);
explicit type(union_type *_union);
explicit type(pointer_type *pointer);
type();
explicit type(std::shared_ptr<alias_type> alias);
explicit type(std::shared_ptr<primitive_type> primitive);
explicit type(std::shared_ptr<record_type> record);
explicit type(std::shared_ptr<union_type> _union);
explicit type(std::shared_ptr<pointer_type> pointer);
explicit type(std::shared_ptr<array_type> array);
type(const type& other);
type& operator=(const type& other);
type(type&& other);
type& operator=(type&& other);
~type();
template<typename T>
T *const get() const;
std::shared_ptr<T> get() const;
bool empty() const;
};
@ -80,6 +94,14 @@ namespace boot
explicit pointer_type(type base);
};
struct array_type
{
const type base;
const std::uint64_t size;
array_type(type base, std::uint64_t size);
};
struct primitive_type
{
const std::string identifier;
@ -104,7 +126,7 @@ namespace boot
type current_type;
public:
std::unordered_map<std::string, alias_type *> unresolved;
std::unordered_map<std::string, std::shared_ptr<alias_type>> unresolved;
declaration_visitor() = default;