Add the unreachable builtin function

This commit is contained in:
2025-04-02 21:08:15 +02:00
parent a7b5e32d09
commit 50970f3289
6 changed files with 136 additions and 73 deletions

View File

@ -185,15 +185,15 @@ namespace elna::boot
/**
* Some type expression.
*/
class type_expression : public node, public std::enable_shared_from_this<type_expression>
class type_expression : public node
{
public:
virtual std::shared_ptr<primitive_type_expression> is_primitive();
virtual std::shared_ptr<array_type_expression> is_array();
virtual std::shared_ptr<pointer_type_expression> is_pointer();
virtual std::shared_ptr<record_type_expression> is_record();
virtual std::shared_ptr<union_type_expression> is_union();
virtual std::shared_ptr<procedure_type_expression> is_procedure();
virtual primitive_type_expression *is_primitive();
virtual array_type_expression *is_array();
virtual pointer_type_expression *is_pointer();
virtual record_type_expression *is_record();
virtual union_type_expression *is_union();
virtual procedure_type_expression *is_procedure();
protected:
type_expression(const struct position position);
@ -209,37 +209,41 @@ namespace elna::boot
primitive_type_expression(const struct position position, const std::string& name);
void accept(parser_visitor *visitor) override;
std::shared_ptr<primitive_type_expression> is_primitive() override;
primitive_type_expression *is_primitive() override;
};
class array_type_expression : public type_expression
{
std::shared_ptr<type_expression> m_base;
type_expression *m_base;
public:
const std::uint32_t size;
array_type_expression(const struct position position,
std::shared_ptr<type_expression> base, const std::uint32_t size);
type_expression *base, const std::uint32_t size);
~array_type_expression();
void accept(parser_visitor *visitor) override;
std::shared_ptr<array_type_expression> is_array() override;
array_type_expression *is_array() override;
type_expression& base();
};
class pointer_type_expression : public type_expression
{
std::shared_ptr<type_expression> m_base;
type_expression *m_base;
public:
pointer_type_expression(const struct position position, std::shared_ptr<type_expression> base);
pointer_type_expression(const struct position position, type_expression *base);
~pointer_type_expression();
void accept(parser_visitor *visitor) override;
std::shared_ptr<pointer_type_expression> is_pointer() override;
pointer_type_expression *is_pointer() override;
type_expression& base();
};
using field_declaration = std::pair<std::string, std::shared_ptr<type_expression>>;
using field_declaration = std::pair<std::string, type_expression *>;
class record_type_expression : public type_expression
{
@ -247,9 +251,10 @@ namespace elna::boot
const std::vector<field_declaration> fields;
record_type_expression(const struct position position, std::vector<field_declaration>&& fields);
~record_type_expression();
void accept(parser_visitor *visitor) override;
std::shared_ptr<record_type_expression> is_record() override;
record_type_expression *is_record() override;
};
class union_type_expression : public type_expression
@ -258,9 +263,10 @@ namespace elna::boot
std::vector<field_declaration> fields;
union_type_expression(const struct position position, std::vector<field_declaration>&& fields);
~union_type_expression();
void accept(parser_visitor *visitor) override;
std::shared_ptr<union_type_expression> is_union() override;
union_type_expression *is_union() override;
};
/**
@ -273,6 +279,7 @@ namespace elna::boot
public:
variable_declaration(const struct position position, const std::string& identifier,
std::shared_ptr<type_expression> variable_type, const bool exported = false);
void accept(parser_visitor *visitor) override;
type_expression& variable_type();
@ -321,16 +328,16 @@ namespace elna::boot
class procedure_type_expression : public type_expression
{
public:
using return_t = return_declaration<std::shared_ptr<type_expression>>;
using return_t = return_declaration<type_expression *>;
const return_t return_type;
std::vector<std::shared_ptr<type_expression>> parameters;
std::vector<type_expression *> parameters;
procedure_type_expression(const struct position position,
return_t return_type = return_t());
procedure_type_expression(const struct position position, return_t return_type = return_t());
~procedure_type_expression();
void accept(parser_visitor *visitor) override;
std::shared_ptr<procedure_type_expression> is_procedure() override;
procedure_type_expression *is_procedure() override;
};
/**
@ -338,14 +345,14 @@ namespace elna::boot
*/
class procedure_definition : public definition
{
std::shared_ptr<procedure_type_expression> m_heading;
procedure_type_expression *m_heading;
public:
block *const body;
std::vector<std::string> parameter_names;
procedure_definition(const struct position position, const std::string& identifier,
const bool exported, std::shared_ptr<procedure_type_expression> heading, block *body = nullptr);
const bool exported, procedure_type_expression *heading, block *body = nullptr);
void accept(parser_visitor *visitor) override;
procedure_type_expression& heading();
@ -358,11 +365,13 @@ namespace elna::boot
*/
class type_definition : public definition
{
std::shared_ptr<type_expression> m_body;
type_expression *m_body;
public:
type_definition(const struct position position, const std::string& identifier,
const bool exported, std::shared_ptr<type_expression> expression);
const bool exported, type_expression *expression);
~type_definition();
void accept(parser_visitor *visitor) override;
type_expression& body();
@ -373,11 +382,11 @@ namespace elna::boot
*/
class cast_expression : public expression
{
std::shared_ptr<type_expression> m_target;
type_expression *m_target;
expression *m_value;
public:
cast_expression(const struct position position, std::shared_ptr<type_expression> target, expression *value);
cast_expression(const struct position position, type_expression *target, expression *value);
void accept(parser_visitor *visitor) override;
cast_expression *is_cast() override;
@ -390,10 +399,12 @@ namespace elna::boot
class traits_expression : public expression
{
public:
std::vector<std::shared_ptr<type_expression>> parameters;
std::vector<type_expression *> parameters;
const std::string name;
traits_expression(const struct position position, const std::string& name);
~traits_expression();
void accept(parser_visitor *visitor) override;
traits_expression *is_traits() override;
};