Implement defer
This commit is contained in:
58
boot/ast.cc
58
boot/ast.cc
@ -90,6 +90,14 @@ namespace boot
|
||||
}
|
||||
}
|
||||
|
||||
void empty_visitor::visit(defer_statement *defer)
|
||||
{
|
||||
for (statement *const body_statement : defer->statements)
|
||||
{
|
||||
body_statement->accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
void empty_visitor::visit(block *block)
|
||||
{
|
||||
for (constant_definition *const constant : block->constants)
|
||||
@ -204,7 +212,7 @@ namespace boot
|
||||
{
|
||||
}
|
||||
|
||||
void empty_visitor::visit(string_literal *)
|
||||
void empty_visitor::visit(number_literal<std::string> *)
|
||||
{
|
||||
}
|
||||
|
||||
@ -377,8 +385,8 @@ namespace boot
|
||||
}
|
||||
|
||||
variable_declaration::variable_declaration(const struct position position, const std::string& identifier,
|
||||
type_expression *type)
|
||||
: definition(position, identifier), m_type(type)
|
||||
const bool exported, type_expression *type)
|
||||
: definition(position, identifier, exported), m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
@ -397,19 +405,14 @@ namespace boot
|
||||
return *m_type;
|
||||
}
|
||||
|
||||
definition::definition(const struct position position, const std::string& identifier)
|
||||
: node(position), m_identifier(identifier)
|
||||
definition::definition(const struct position position, const std::string& identifier, const bool exported)
|
||||
: node(position), identifier(identifier), exported(exported)
|
||||
{
|
||||
}
|
||||
|
||||
std::string& definition::identifier()
|
||||
{
|
||||
return m_identifier;
|
||||
}
|
||||
|
||||
constant_definition::constant_definition(const struct position position, const std::string& identifier,
|
||||
literal *body)
|
||||
: definition(position, identifier), m_body(body)
|
||||
const bool exported, literal *body)
|
||||
: definition(position, identifier, exported), m_body(body)
|
||||
{
|
||||
}
|
||||
|
||||
@ -429,8 +432,8 @@ namespace boot
|
||||
}
|
||||
|
||||
procedure_definition::procedure_definition(const struct position position, const std::string& identifier,
|
||||
std::vector<variable_declaration *>&& parameters, type_expression *return_type, block *body)
|
||||
: definition(position, identifier), m_return_type(return_type), m_body(body), parameters(std::move(parameters))
|
||||
const bool exported, type_expression *return_type)
|
||||
: definition(position, identifier, exported), m_return_type(return_type)
|
||||
{
|
||||
}
|
||||
|
||||
@ -444,6 +447,12 @@ namespace boot
|
||||
return m_body;
|
||||
}
|
||||
|
||||
procedure_definition *procedure_definition::add_body(block *procedure_body)
|
||||
{
|
||||
m_body = procedure_body;
|
||||
return this;
|
||||
}
|
||||
|
||||
type_expression *procedure_definition::return_type()
|
||||
{
|
||||
return m_return_type;
|
||||
@ -462,8 +471,8 @@ namespace boot
|
||||
}
|
||||
|
||||
type_definition::type_definition(const struct position position, const std::string& identifier,
|
||||
type_expression *body)
|
||||
: definition(position, identifier), m_body(body)
|
||||
const bool exported, type_expression *body)
|
||||
: definition(position, identifier, exported), m_body(body)
|
||||
{
|
||||
}
|
||||
|
||||
@ -535,19 +544,22 @@ namespace boot
|
||||
{
|
||||
}
|
||||
|
||||
string_literal::string_literal(const struct position position, const std::string& value)
|
||||
: literal(position), m_string(value)
|
||||
defer_statement::defer_statement(const struct position position)
|
||||
: statement(position)
|
||||
{
|
||||
}
|
||||
|
||||
void string_literal::accept(parser_visitor *visitor)
|
||||
void defer_statement::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
const std::string& string_literal::string() const
|
||||
defer_statement::~defer_statement()
|
||||
{
|
||||
return m_string;
|
||||
for (statement *body_statement : statements)
|
||||
{
|
||||
delete body_statement;
|
||||
}
|
||||
}
|
||||
|
||||
designator_expression::designator_expression(const struct position position)
|
||||
@ -608,7 +620,7 @@ namespace boot
|
||||
}
|
||||
|
||||
field_access_expression::field_access_expression(const struct position position,
|
||||
designator_expression *base, const std::string& field)
|
||||
expression *base, const std::string& field)
|
||||
: designator_expression(position), m_base(base), m_field(field)
|
||||
{
|
||||
}
|
||||
@ -618,7 +630,7 @@ namespace boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
designator_expression& field_access_expression::base()
|
||||
expression& field_access_expression::base()
|
||||
{
|
||||
return *m_base;
|
||||
}
|
||||
|
Reference in New Issue
Block a user