Allow multiple variable declarations with a single type

This commit is contained in:
2025-02-15 10:26:04 +01:00
parent 82b3806fd2
commit b358f8ba27
7 changed files with 117 additions and 138 deletions

View File

@ -255,37 +255,33 @@ namespace boot
class array_type : public top_type
{
top_type *m_base;
std::shared_ptr<top_type> m_base;
public:
const std::uint32_t size;
array_type(const struct position position, top_type*base, const std::uint32_t size);
array_type(const struct position position, std::shared_ptr<top_type> base, const std::uint32_t size);
virtual void accept(parser_visitor *visitor) override;
top_type& base();
array_type *is_array() override;
virtual ~array_type() override;
};
class pointer_type : public top_type
{
top_type *m_base;
std::shared_ptr<top_type> m_base;
public:
pointer_type(const struct position position, top_type *base);
pointer_type(const struct position position, std::shared_ptr<top_type> base);
virtual void accept(parser_visitor *visitor) override;
top_type& base();
pointer_type *is_pointer() override;
virtual ~pointer_type() override;
};
using field_t = std::pair<std::string, top_type *>;
using field_t = std::pair<std::string, std::shared_ptr<top_type>>;
using fields_t = std::vector<field_t>;
class composite_type : public top_type
@ -295,8 +291,6 @@ namespace boot
public:
fields_t fields;
virtual ~composite_type() override;
};
class record_type : public composite_type
@ -322,16 +316,14 @@ namespace boot
*/
class variable_declaration : public definition
{
top_type *m_type;
std::shared_ptr<top_type> m_type;
public:
variable_declaration(const struct position position, const std::string& identifier,
const bool exported, top_type *type);
std::shared_ptr<top_type> type, const bool exported = false);
virtual void accept(parser_visitor *visitor) override;
top_type& variable_type();
virtual ~variable_declaration() override;
};
/**
@ -370,17 +362,17 @@ namespace boot
*/
class procedure_definition : public definition
{
top_type *m_return_type{ nullptr };
std::shared_ptr<top_type> m_return_type{ nullptr };
block *m_body{ nullptr };
public:
std::vector<variable_declaration *> parameters;
procedure_definition(const struct position position, const std::string& identifier,
const bool exported, top_type *return_type = nullptr);
const bool exported, std::shared_ptr<top_type> return_type = nullptr);
virtual void accept(parser_visitor *visitor) override;
top_type *return_type();
std::shared_ptr<top_type> return_type();
block *body();
procedure_definition *add_body(block *procedure_body);
@ -393,16 +385,14 @@ namespace boot
*/
class type_definition : public definition
{
top_type *m_body;
std::shared_ptr<top_type> m_body;
public:
type_definition(const struct position position, const std::string& identifier,
const bool exported, top_type *expression);
const bool exported, std::shared_ptr<top_type> expression);
virtual void accept(parser_visitor *visitor) override;
top_type& body();
virtual ~type_definition() override;
};
/**
@ -432,11 +422,11 @@ namespace boot
*/
class cast_expression : public expression
{
top_type *m_target;
std::shared_ptr<top_type> m_target;
expression *m_value;
public:
cast_expression(const struct position position, top_type *target, expression *value);
cast_expression(const struct position position, std::shared_ptr<top_type> target, expression *value);
virtual void accept(parser_visitor *visitor) override;
top_type& target();
@ -450,15 +440,13 @@ namespace boot
*/
class type_expression : public expression
{
top_type *m_body;
std::shared_ptr<top_type> m_body;
public:
type_expression(const struct position position, top_type *body);
type_expression(const struct position position, std::shared_ptr<top_type> body);
virtual void accept(parser_visitor *visitor) override;
top_type& body();
virtual ~type_expression() override;
};
class call_statement : public statement