Make type_expression abstract

This commit is contained in:
2025-01-05 00:06:51 +01:00
parent 98c13f0be3
commit bbd38a5d26
6 changed files with 56 additions and 33 deletions

View File

@ -46,7 +46,7 @@ namespace source
class program;
class binary_expression;
class unary_expression;
class type_expression;
class basic_type_expression;
class variable_expression;
template<typename T>
class number_literal;
@ -70,7 +70,7 @@ namespace source
virtual void visit(program *) = 0;
virtual void visit(binary_expression *) = 0;
virtual void visit(unary_expression *) = 0;
virtual void visit(type_expression *) = 0;
virtual void visit(basic_type_expression *) = 0;
virtual void visit(variable_expression *) = 0;
virtual void visit(number_literal<std::int32_t> *) = 0;
virtual void visit(number_literal<double> *) = 0;
@ -96,7 +96,7 @@ namespace source
virtual void visit(program *program) override;
virtual void visit(binary_expression *expression) override;
virtual void visit(unary_expression *expression) override;
virtual void visit(type_expression *) override;
virtual void visit(basic_type_expression *) override;
virtual void visit(variable_expression *) override;
virtual void visit(number_literal<std::int32_t> *) override;
virtual void visit(number_literal<double> *) override;
@ -223,20 +223,30 @@ namespace source
};
/**
* Expression defining a composed type like pointer or an array.
* Some type expression.
*/
class type_expression : public node
{
public:
virtual basic_type_expression *is_basic();
protected:
type_expression(const struct position position);
};
/**
* Expression defining a basic type.
*/
class basic_type_expression : public type_expression
{
std::string m_base;
bool m_pointer{ false };
public:
/**
* \param position Source code position.
* \param name Type name.
* \param is_pointer Whether it is a pointer type.
*/
type_expression(const struct position position, const std::string& name, const bool is_pointer = false);
basic_type_expression(const struct position position, const std::string& name);
virtual void accept(parser_visitor *visitor) override;
/**
@ -244,10 +254,7 @@ namespace source
*/
const std::string& base() const noexcept;
/**
* \return Whether the type is a pointer.
*/
bool is_pointer() const noexcept;
basic_type_expression *is_basic() override;
};
/**