Add procedure type expression
This commit is contained in:
131
boot/ast.cc
131
boot/ast.cc
@ -32,13 +32,10 @@ namespace boot
|
||||
|
||||
void empty_visitor::visit(procedure_definition *definition)
|
||||
{
|
||||
for (auto parameter : definition->parameters)
|
||||
definition->heading().accept(this);
|
||||
if (definition->body != nullptr)
|
||||
{
|
||||
parameter->accept(this);
|
||||
}
|
||||
if (definition->body() != nullptr)
|
||||
{
|
||||
definition->body()->accept(this);
|
||||
definition->body->accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,6 +179,18 @@ namespace boot
|
||||
}
|
||||
}
|
||||
|
||||
void empty_visitor::visit(procedure_type *expression)
|
||||
{
|
||||
for (auto parameter : expression->parameters)
|
||||
{
|
||||
parameter->accept(this);
|
||||
}
|
||||
if (expression->return_type != nullptr)
|
||||
{
|
||||
expression->return_type->accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
void empty_visitor::visit(variable_expression *)
|
||||
{
|
||||
}
|
||||
@ -255,27 +264,32 @@ namespace boot
|
||||
{
|
||||
}
|
||||
|
||||
basic_type *top_type::is_basic()
|
||||
std::shared_ptr<basic_type> top_type::is_basic()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
array_type *top_type::is_array()
|
||||
std::shared_ptr<array_type> top_type::is_array()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
record_type *top_type::is_record()
|
||||
std::shared_ptr<record_type> top_type::is_record()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
union_type *top_type::is_union()
|
||||
std::shared_ptr<union_type> top_type::is_union()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pointer_type *top_type::is_pointer()
|
||||
std::shared_ptr<pointer_type> top_type::is_pointer()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<procedure_type> top_type::is_procedure()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@ -295,9 +309,9 @@ namespace boot
|
||||
return m_name;
|
||||
}
|
||||
|
||||
basic_type *basic_type::is_basic()
|
||||
std::shared_ptr<basic_type> basic_type::is_basic()
|
||||
{
|
||||
return this;
|
||||
return std::static_pointer_cast<basic_type>(shared_from_this());
|
||||
}
|
||||
|
||||
array_type::array_type(const struct position position, std::shared_ptr<top_type> base, const std::uint32_t size)
|
||||
@ -315,9 +329,9 @@ namespace boot
|
||||
return *m_base;
|
||||
}
|
||||
|
||||
array_type*array_type::is_array()
|
||||
std::shared_ptr<array_type> array_type::is_array()
|
||||
{
|
||||
return this;
|
||||
return std::static_pointer_cast<array_type>(shared_from_this());
|
||||
}
|
||||
|
||||
pointer_type::pointer_type(const struct position position, std::shared_ptr<top_type> base)
|
||||
@ -335,18 +349,13 @@ namespace boot
|
||||
return *m_base;
|
||||
}
|
||||
|
||||
pointer_type *pointer_type::is_pointer()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
composite_type::composite_type(const struct position position, fields_t&& fields)
|
||||
: top_type(position), fields(std::move(fields))
|
||||
std::shared_ptr<pointer_type> pointer_type::is_pointer()
|
||||
{
|
||||
return std::static_pointer_cast<pointer_type>(shared_from_this());
|
||||
}
|
||||
|
||||
record_type::record_type(const struct position position, fields_t&& fields)
|
||||
: composite_type(position, std::move(fields))
|
||||
: top_type(position), fields(std::move(fields))
|
||||
{
|
||||
}
|
||||
|
||||
@ -355,19 +364,19 @@ namespace boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
record_type *record_type::is_record()
|
||||
std::shared_ptr<record_type> record_type::is_record()
|
||||
{
|
||||
return this;
|
||||
return std::static_pointer_cast<record_type>(shared_from_this());
|
||||
}
|
||||
|
||||
union_type::union_type(const struct position position, fields_t&& fields)
|
||||
: composite_type(position, std::move(fields))
|
||||
: top_type(position), fields(std::move(fields))
|
||||
{
|
||||
}
|
||||
|
||||
union_type *union_type::is_union()
|
||||
std::shared_ptr<union_type> union_type::is_union()
|
||||
{
|
||||
return this;
|
||||
return std::static_pointer_cast<union_type>(shared_from_this());
|
||||
}
|
||||
|
||||
void union_type::accept(parser_visitor *visitor)
|
||||
@ -417,15 +426,37 @@ namespace boot
|
||||
delete m_body;
|
||||
}
|
||||
|
||||
procedure_definition::procedure_definition(const struct position position, const std::string& identifier,
|
||||
const bool exported, std::shared_ptr<top_type> return_type)
|
||||
: definition(position, identifier, exported), m_return_type(return_type), no_return{ false }
|
||||
procedure_type::procedure_type(const struct position position, std::shared_ptr<top_type> return_type)
|
||||
: top_type(position), return_type(return_type), no_return(false)
|
||||
{
|
||||
}
|
||||
|
||||
procedure_type::procedure_type(const struct position position, no_return_t)
|
||||
: top_type(position), return_type(nullptr), no_return(true)
|
||||
{
|
||||
}
|
||||
|
||||
void procedure_type::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<procedure_type> procedure_type::is_procedure()
|
||||
{
|
||||
return std::static_pointer_cast<procedure_type>(shared_from_this());
|
||||
}
|
||||
|
||||
procedure_type::~procedure_type()
|
||||
{
|
||||
for (auto parameter : this->parameters)
|
||||
{
|
||||
delete parameter;
|
||||
}
|
||||
}
|
||||
|
||||
procedure_definition::procedure_definition(const struct position position, const std::string& identifier,
|
||||
const bool exported, no_return_t)
|
||||
: definition(position, identifier, exported), m_return_type(nullptr), no_return{ true }
|
||||
const bool exported, std::shared_ptr<procedure_type> heading, block *body)
|
||||
: definition(position, identifier, exported), m_heading(heading), body(body)
|
||||
{
|
||||
}
|
||||
|
||||
@ -434,32 +465,14 @@ namespace boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
block *procedure_definition::body()
|
||||
procedure_type& procedure_definition::heading()
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
procedure_definition *procedure_definition::add_body(block *procedure_body)
|
||||
{
|
||||
m_body = procedure_body;
|
||||
return this;
|
||||
}
|
||||
|
||||
std::shared_ptr<top_type> procedure_definition::return_type()
|
||||
{
|
||||
return m_return_type;
|
||||
return *m_heading;
|
||||
}
|
||||
|
||||
procedure_definition::~procedure_definition()
|
||||
{
|
||||
if (m_body != nullptr)
|
||||
{
|
||||
delete m_body;
|
||||
}
|
||||
for (auto parameter : parameters)
|
||||
{
|
||||
delete parameter;
|
||||
}
|
||||
delete body;
|
||||
}
|
||||
|
||||
type_definition::type_definition(const struct position position, const std::string& identifier,
|
||||
@ -846,10 +859,7 @@ namespace boot
|
||||
|
||||
return_statement::~return_statement()
|
||||
{
|
||||
if (m_return_expression != nullptr)
|
||||
{
|
||||
delete m_return_expression;
|
||||
}
|
||||
delete m_return_expression;
|
||||
}
|
||||
|
||||
void assign_statement::accept(parser_visitor *visitor)
|
||||
@ -926,10 +936,7 @@ namespace boot
|
||||
{
|
||||
delete branch;
|
||||
}
|
||||
if (m_alternative != nullptr)
|
||||
{
|
||||
delete m_alternative;
|
||||
}
|
||||
delete m_alternative;
|
||||
}
|
||||
|
||||
while_statement::while_statement(const struct position position, conditional_statements *body)
|
||||
|
Reference in New Issue
Block a user