Rename AST types to type expressions
This commit is contained in:
292
boot/ast.cc
292
boot/ast.cc
@ -23,215 +23,167 @@ namespace boot
|
||||
{
|
||||
void empty_visitor::visit(variable_declaration *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(constant_definition *definition)
|
||||
void empty_visitor::visit(constant_definition *)
|
||||
{
|
||||
definition->body().accept(this);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(procedure_definition *definition)
|
||||
void empty_visitor::visit(procedure_definition *)
|
||||
{
|
||||
definition->heading().accept(this);
|
||||
if (definition->body != nullptr)
|
||||
{
|
||||
definition->body->accept(this);
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(type_definition *definition)
|
||||
void empty_visitor::visit(type_definition *)
|
||||
{
|
||||
definition->body().accept(this);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(procedure_call *call)
|
||||
void empty_visitor::visit(procedure_call *)
|
||||
{
|
||||
for (expression *const argument : call->arguments)
|
||||
{
|
||||
argument->accept(this);
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(traits_expression *trait)
|
||||
void empty_visitor::visit(traits_expression *)
|
||||
{
|
||||
trait->type().accept(this);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(cast_expression *expression)
|
||||
void empty_visitor::visit(cast_expression *)
|
||||
{
|
||||
expression->target().accept(this);
|
||||
expression->value().accept(this);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(assign_statement *statement)
|
||||
void empty_visitor::visit(assign_statement *)
|
||||
{
|
||||
statement->rvalue().accept(this);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(if_statement *statement)
|
||||
void empty_visitor::visit(if_statement *)
|
||||
{
|
||||
statement->body().prerequisite().accept(this);
|
||||
for (const auto body_statement : statement->body().statements)
|
||||
{
|
||||
body_statement->accept(this);
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(while_statement *statement)
|
||||
void empty_visitor::visit(while_statement *)
|
||||
{
|
||||
statement->body().prerequisite().accept(this);
|
||||
for (const auto body_statement : statement->body().statements)
|
||||
{
|
||||
body_statement->accept(this);
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(return_statement *statement)
|
||||
void empty_visitor::visit(return_statement *)
|
||||
{
|
||||
expression *return_expression = statement->return_expression();
|
||||
|
||||
if (return_expression != nullptr)
|
||||
{
|
||||
return_expression->accept(this);
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(defer_statement *defer)
|
||||
void empty_visitor::visit(defer_statement *)
|
||||
{
|
||||
for (statement *const body_statement : defer->statements)
|
||||
{
|
||||
body_statement->accept(this);
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(block *block)
|
||||
void empty_visitor::visit(block *)
|
||||
{
|
||||
for (constant_definition *const constant : block->constants)
|
||||
{
|
||||
constant->accept(this);
|
||||
}
|
||||
for (variable_declaration *const variable : block->variables)
|
||||
{
|
||||
variable->accept(this);
|
||||
}
|
||||
for (statement *const body_statement : block->body)
|
||||
{
|
||||
body_statement->accept(this);
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(program *program)
|
||||
void empty_visitor::visit(program *)
|
||||
{
|
||||
visit(reinterpret_cast<block *>(program));
|
||||
for (type_definition *const type : program->types)
|
||||
{
|
||||
type->accept(this);
|
||||
}
|
||||
for (procedure_definition *const procedure : program->procedures)
|
||||
{
|
||||
procedure->accept(this);
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(binary_expression *expression)
|
||||
void empty_visitor::visit(binary_expression *)
|
||||
{
|
||||
expression->lhs().accept(this);
|
||||
expression->rhs().accept(this);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(unary_expression *expression)
|
||||
void empty_visitor::visit(unary_expression *)
|
||||
{
|
||||
expression->operand().accept(this);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(basic_type *)
|
||||
void empty_visitor::visit(primitive_type_expression *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(array_type *expression)
|
||||
void empty_visitor::visit(array_type_expression *)
|
||||
{
|
||||
expression->base().accept(this);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(pointer_type *expression)
|
||||
void empty_visitor::visit(pointer_type_expression *)
|
||||
{
|
||||
expression->base().accept(this);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(record_type *expression)
|
||||
void empty_visitor::visit(record_type_expression *)
|
||||
{
|
||||
for (auto& field : expression->fields)
|
||||
{
|
||||
field.second->accept(this);
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(union_type *expression)
|
||||
void empty_visitor::visit(union_type_expression *)
|
||||
{
|
||||
for (auto& field : expression->fields)
|
||||
{
|
||||
field.second->accept(this);
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(procedure_type *expression)
|
||||
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);
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(variable_expression *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(array_access_expression *expression)
|
||||
void empty_visitor::visit(array_access_expression *)
|
||||
{
|
||||
expression->base().accept(this);
|
||||
expression->index().accept(this);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(field_access_expression *expression)
|
||||
void empty_visitor::visit(field_access_expression *)
|
||||
{
|
||||
expression->base().accept(this);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(dereference_expression *expression)
|
||||
void empty_visitor::visit(dereference_expression *)
|
||||
{
|
||||
expression->base().accept(this);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<std::int32_t> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<std::uint32_t> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<double> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<bool> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<unsigned char> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<std::nullptr_t> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(number_literal<std::string> *)
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
node::node(const struct position position)
|
||||
@ -252,78 +204,130 @@ namespace boot
|
||||
{
|
||||
}
|
||||
|
||||
top_type::top_type(const struct position position)
|
||||
type_expression::type_expression(const struct position position)
|
||||
: node(position)
|
||||
{
|
||||
}
|
||||
|
||||
basic_type::basic_type(const struct position position, const std::string& name)
|
||||
: top_type(position), m_name(name)
|
||||
std::shared_ptr<primitive_type_expression> type_expression::is_primitive()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<array_type_expression> type_expression::is_array()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<pointer_type_expression> type_expression::is_pointer()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<record_type_expression> type_expression::is_record()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<union_type_expression> type_expression::is_union()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<procedure_type_expression> type_expression::is_procedure()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
primitive_type_expression::primitive_type_expression(const struct position position, const std::string& name)
|
||||
: type_expression(position), name(name)
|
||||
{
|
||||
}
|
||||
|
||||
void basic_type::accept(parser_visitor *visitor)
|
||||
void primitive_type_expression::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
const std::string& basic_type::base_name()
|
||||
std::shared_ptr<primitive_type_expression> primitive_type_expression::is_primitive()
|
||||
{
|
||||
return m_name;
|
||||
return std::static_pointer_cast<primitive_type_expression>(shared_from_this());
|
||||
}
|
||||
|
||||
array_type::array_type(const struct position position, std::shared_ptr<top_type> base, const std::uint32_t size)
|
||||
: top_type(position), m_base(base), size(size)
|
||||
array_type_expression::array_type_expression(const struct position position,
|
||||
std::shared_ptr<type_expression> base, const std::uint32_t size)
|
||||
: type_expression(position), m_base(base), size(size)
|
||||
{
|
||||
}
|
||||
|
||||
void array_type::accept(parser_visitor *visitor)
|
||||
void array_type_expression::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
top_type& array_type::base()
|
||||
std::shared_ptr<array_type_expression> array_type_expression::is_array()
|
||||
{
|
||||
return std::static_pointer_cast<array_type_expression>(shared_from_this());
|
||||
}
|
||||
|
||||
type_expression& array_type_expression::base()
|
||||
{
|
||||
return *m_base;
|
||||
}
|
||||
|
||||
pointer_type::pointer_type(const struct position position, std::shared_ptr<top_type> base)
|
||||
: top_type(position), m_base(base)
|
||||
pointer_type_expression::pointer_type_expression(const struct position position,
|
||||
std::shared_ptr<type_expression> base)
|
||||
: type_expression(position), m_base(base)
|
||||
{
|
||||
}
|
||||
|
||||
void pointer_type::accept(parser_visitor *visitor)
|
||||
void pointer_type_expression::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
top_type& pointer_type::base()
|
||||
std::shared_ptr<pointer_type_expression> pointer_type_expression::is_pointer()
|
||||
{
|
||||
return std::static_pointer_cast<pointer_type_expression>(shared_from_this());
|
||||
}
|
||||
|
||||
type_expression& pointer_type_expression::base()
|
||||
{
|
||||
return *m_base;
|
||||
}
|
||||
|
||||
record_type::record_type(const struct position position, fields_t&& fields)
|
||||
: top_type(position), fields(std::move(fields))
|
||||
record_type_expression::record_type_expression(const struct position position, fields_t&& fields)
|
||||
: type_expression(position), fields(std::move(fields))
|
||||
{
|
||||
}
|
||||
|
||||
void record_type::accept(parser_visitor *visitor)
|
||||
void record_type_expression::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
union_type::union_type(const struct position position, fields_t&& fields)
|
||||
: top_type(position), fields(std::move(fields))
|
||||
std::shared_ptr<record_type_expression> record_type_expression::is_record()
|
||||
{
|
||||
return std::static_pointer_cast<record_type_expression>(shared_from_this());
|
||||
}
|
||||
|
||||
union_type_expression::union_type_expression(const struct position position, fields_t&& fields)
|
||||
: type_expression(position), fields(std::move(fields))
|
||||
{
|
||||
}
|
||||
|
||||
void union_type::accept(parser_visitor *visitor)
|
||||
void union_type_expression::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<union_type_expression> union_type_expression::is_union()
|
||||
{
|
||||
return std::static_pointer_cast<union_type_expression>(shared_from_this());
|
||||
}
|
||||
|
||||
variable_declaration::variable_declaration(const struct position position, const std::string& identifier,
|
||||
std::shared_ptr<top_type> type, const bool exported)
|
||||
std::shared_ptr<type_expression> type, const bool exported)
|
||||
: definition(position, identifier, exported), m_type(type)
|
||||
{
|
||||
}
|
||||
@ -333,7 +337,7 @@ namespace boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
top_type& variable_declaration::variable_type()
|
||||
type_expression& variable_declaration::variable_type()
|
||||
{
|
||||
return *m_type;
|
||||
}
|
||||
@ -364,22 +368,23 @@ namespace boot
|
||||
delete m_body;
|
||||
}
|
||||
|
||||
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_expression::procedure_type_expression(const struct position position,
|
||||
std::shared_ptr<type_expression> return_type)
|
||||
: type_expression(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)
|
||||
procedure_type_expression::procedure_type_expression(const struct position position, no_return_t)
|
||||
: type_expression(position), return_type(nullptr), no_return(true)
|
||||
{
|
||||
}
|
||||
|
||||
void procedure_type::accept(parser_visitor *visitor)
|
||||
void procedure_type_expression::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
procedure_type::~procedure_type()
|
||||
procedure_type_expression::~procedure_type_expression()
|
||||
{
|
||||
for (auto parameter : this->parameters)
|
||||
{
|
||||
@ -388,7 +393,7 @@ namespace boot
|
||||
}
|
||||
|
||||
procedure_definition::procedure_definition(const struct position position, const std::string& identifier,
|
||||
const bool exported, std::shared_ptr<procedure_type> heading, block *body)
|
||||
const bool exported, std::shared_ptr<procedure_type_expression> heading, block *body)
|
||||
: definition(position, identifier, exported), m_heading(heading), body(body)
|
||||
{
|
||||
}
|
||||
@ -398,7 +403,12 @@ namespace boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
procedure_type& procedure_definition::heading()
|
||||
std::shared_ptr<procedure_type_expression> procedure_type_expression::is_procedure()
|
||||
{
|
||||
return std::static_pointer_cast<procedure_type_expression>(shared_from_this());
|
||||
}
|
||||
|
||||
procedure_type_expression& procedure_definition::heading()
|
||||
{
|
||||
return *m_heading;
|
||||
}
|
||||
@ -409,7 +419,7 @@ namespace boot
|
||||
}
|
||||
|
||||
type_definition::type_definition(const struct position position, const std::string& identifier,
|
||||
const bool exported, std::shared_ptr<top_type> body)
|
||||
const bool exported, std::shared_ptr<type_expression> body)
|
||||
: definition(position, identifier, exported), m_body(body)
|
||||
{
|
||||
}
|
||||
@ -419,7 +429,7 @@ namespace boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
top_type& type_definition::body()
|
||||
type_expression& type_definition::body()
|
||||
{
|
||||
return *m_body;
|
||||
}
|
||||
@ -685,7 +695,7 @@ namespace boot
|
||||
}
|
||||
|
||||
cast_expression::cast_expression(const struct position position,
|
||||
std::shared_ptr<top_type> target, expression *value)
|
||||
std::shared_ptr<type_expression> target, expression *value)
|
||||
: node(position), m_target(target), m_value(value)
|
||||
{
|
||||
}
|
||||
@ -695,7 +705,7 @@ namespace boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
top_type& cast_expression::target()
|
||||
type_expression& cast_expression::target()
|
||||
{
|
||||
return *m_target;
|
||||
}
|
||||
@ -711,7 +721,7 @@ namespace boot
|
||||
}
|
||||
|
||||
traits_expression::traits_expression(const struct position position,
|
||||
const std::string& name, std::shared_ptr<top_type> type)
|
||||
const std::string& name, std::shared_ptr<type_expression> type)
|
||||
: node(position), m_type(type), name(name)
|
||||
{
|
||||
}
|
||||
@ -721,7 +731,7 @@ namespace boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
top_type& traits_expression::type()
|
||||
type_expression& traits_expression::type()
|
||||
{
|
||||
return *m_type;
|
||||
}
|
||||
|
Reference in New Issue
Block a user