Add procedure type expression
This commit is contained in:
@ -75,6 +75,7 @@ namespace boot
|
||||
class pointer_type;
|
||||
class record_type;
|
||||
class union_type;
|
||||
class procedure_type;
|
||||
class variable_expression;
|
||||
class array_access_expression;
|
||||
class field_access_expression;
|
||||
@ -110,6 +111,7 @@ namespace boot
|
||||
virtual void visit(pointer_type *) = 0;
|
||||
virtual void visit(record_type *) = 0;
|
||||
virtual void visit(union_type *) = 0;
|
||||
virtual void visit(procedure_type *) = 0;
|
||||
virtual void visit(variable_expression *) = 0;
|
||||
virtual void visit(array_access_expression *) = 0;
|
||||
virtual void visit(field_access_expression *is_field_access) = 0;
|
||||
@ -150,6 +152,7 @@ namespace boot
|
||||
virtual void visit(pointer_type *) override;
|
||||
virtual void visit(record_type *expression) override;
|
||||
virtual void visit(union_type *expression) override;
|
||||
virtual void visit(procedure_type *expression) override;
|
||||
virtual void visit(variable_expression *) override;
|
||||
virtual void visit(array_access_expression *expression) override;
|
||||
virtual void visit(field_access_expression *expression) override;
|
||||
@ -220,14 +223,15 @@ namespace boot
|
||||
/**
|
||||
* Some type expression.
|
||||
*/
|
||||
class top_type : public node
|
||||
class top_type : public node, public std::enable_shared_from_this<top_type>
|
||||
{
|
||||
public:
|
||||
virtual basic_type *is_basic();
|
||||
virtual array_type *is_array();
|
||||
virtual pointer_type *is_pointer();
|
||||
virtual record_type *is_record();
|
||||
virtual union_type *is_union();
|
||||
virtual std::shared_ptr<basic_type> is_basic();
|
||||
virtual std::shared_ptr<array_type> is_array();
|
||||
virtual std::shared_ptr<pointer_type> is_pointer();
|
||||
virtual std::shared_ptr<record_type> is_record();
|
||||
virtual std::shared_ptr<union_type> is_union();
|
||||
virtual std::shared_ptr<procedure_type> is_procedure();
|
||||
|
||||
protected:
|
||||
top_type(const struct position position);
|
||||
@ -250,7 +254,7 @@ namespace boot
|
||||
|
||||
const std::string& base_name();
|
||||
|
||||
basic_type *is_basic() override;
|
||||
std::shared_ptr<basic_type> is_basic() override;
|
||||
};
|
||||
|
||||
class array_type : public top_type
|
||||
@ -265,7 +269,7 @@ namespace boot
|
||||
|
||||
top_type& base();
|
||||
|
||||
array_type *is_array() override;
|
||||
std::shared_ptr<array_type> is_array() override;
|
||||
};
|
||||
|
||||
class pointer_type : public top_type
|
||||
@ -278,37 +282,32 @@ namespace boot
|
||||
|
||||
top_type& base();
|
||||
|
||||
pointer_type *is_pointer() override;
|
||||
std::shared_ptr<pointer_type> is_pointer() override;
|
||||
};
|
||||
|
||||
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
|
||||
class record_type : public top_type
|
||||
{
|
||||
protected:
|
||||
composite_type(const struct position position, fields_t&& fields);
|
||||
|
||||
public:
|
||||
fields_t fields;
|
||||
};
|
||||
|
||||
class record_type : public composite_type
|
||||
{
|
||||
public:
|
||||
record_type(const struct position position, fields_t&& fields);
|
||||
|
||||
virtual void accept(parser_visitor *visitor) override;
|
||||
record_type *is_record() override;
|
||||
std::shared_ptr<record_type> is_record() override;
|
||||
};
|
||||
|
||||
class union_type : public composite_type
|
||||
class union_type : public top_type
|
||||
{
|
||||
public:
|
||||
fields_t fields;
|
||||
|
||||
union_type(const struct position position, fields_t&& fields);
|
||||
|
||||
virtual void accept(parser_visitor *visitor) override;
|
||||
union_type *is_union() override;
|
||||
std::shared_ptr<union_type> is_union() override;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -357,31 +356,48 @@ namespace boot
|
||||
virtual ~constant_definition() override;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tags a procedure type as never returning.
|
||||
*/
|
||||
struct no_return_t
|
||||
{
|
||||
};
|
||||
constexpr no_return_t no_return{};
|
||||
|
||||
/**
|
||||
* Procedure type.
|
||||
*/
|
||||
class procedure_type : public top_type
|
||||
{
|
||||
public:
|
||||
const std::shared_ptr<top_type> return_type;
|
||||
const bool no_return;
|
||||
std::vector<variable_declaration *> parameters;
|
||||
|
||||
procedure_type(const struct position position, std::shared_ptr<top_type> return_type = nullptr);
|
||||
procedure_type(const struct position position, no_return_t);
|
||||
|
||||
virtual void accept(parser_visitor *visitor) override;
|
||||
std::shared_ptr<procedure_type> is_procedure() override;
|
||||
|
||||
virtual ~procedure_type() override;
|
||||
};
|
||||
|
||||
/**
|
||||
* Procedure definition.
|
||||
*/
|
||||
class procedure_definition : public definition
|
||||
{
|
||||
std::shared_ptr<top_type> m_return_type{ nullptr };
|
||||
block *m_body{ nullptr };
|
||||
std::shared_ptr<procedure_type> m_heading;
|
||||
|
||||
public:
|
||||
struct no_return_t
|
||||
{
|
||||
};
|
||||
const bool no_return{ false };
|
||||
std::vector<variable_declaration *> parameters;
|
||||
block *const body;
|
||||
|
||||
procedure_definition(const struct position position, const std::string& identifier,
|
||||
const bool exported, std::shared_ptr<top_type> return_type = nullptr);
|
||||
procedure_definition(const struct position position, const std::string& identifier,
|
||||
const bool exported, no_return_t);
|
||||
const bool exported, std::shared_ptr<procedure_type> heading, block *body = nullptr);
|
||||
virtual void accept(parser_visitor *visitor) override;
|
||||
|
||||
std::shared_ptr<top_type> return_type();
|
||||
|
||||
block *body();
|
||||
procedure_definition *add_body(block *procedure_body);
|
||||
procedure_type& heading();
|
||||
|
||||
virtual ~procedure_definition() override;
|
||||
};
|
||||
|
Reference in New Issue
Block a user