Implement case statements

This commit is contained in:
2025-04-10 23:55:56 +02:00
parent 18c4e79012
commit f68667d5e5
10 changed files with 135 additions and 94 deletions

View File

@ -321,14 +321,14 @@ namespace elna::boot
*/
class constant_definition : public definition
{
literal_expression *m_body;
expression *m_body;
public:
constant_definition(const struct position position, const std::string& identifier,
const bool exported, literal_expression *body);
const bool exported, expression *body);
void accept(parser_visitor *visitor) override;
literal_expression& body();
expression& body();
virtual ~constant_definition() override;
};
@ -451,7 +451,7 @@ namespace elna::boot
struct switch_case
{
std::vector<literal_expression *> labels;
std::vector<expression *> labels;
std::vector<statement *> statements;
};
@ -483,7 +483,7 @@ namespace elna::boot
designator_expression();
};
class variable_expression : public designator_expression
class variable_expression : public designator_expression, public literal_expression
{
public:
const std::string name;

View File

@ -155,6 +155,7 @@ namespace elna::boot
class type_info;
class procedure_info;
class constant_info;
class variable_info;
class info : public std::enable_shared_from_this<info>
{
@ -163,6 +164,8 @@ namespace elna::boot
virtual std::shared_ptr<type_info> is_type();
virtual std::shared_ptr<procedure_info> is_procedure();
virtual std::shared_ptr<constant_info> is_constant();
virtual std::shared_ptr<variable_info> is_variable();
};
class type_info : public info
@ -171,7 +174,6 @@ namespace elna::boot
const type symbol;
explicit type_info(const type symbol);
std::shared_ptr<type_info> is_type() override;
};
@ -182,7 +184,6 @@ namespace elna::boot
const std::vector<std::string> names;
procedure_info(const procedure_type symbol, const std::vector<std::string> names);
std::shared_ptr<procedure_info> is_procedure() override;
};
@ -195,6 +196,17 @@ namespace elna::boot
const variant symbol;
explicit constant_info(const variant& symbol);
std::shared_ptr<constant_info> is_constant() override;
};
class variable_info : public info
{
public:
const std::string name;
const type symbol;
variable_info(const std::string& name, const type symbol);
std::shared_ptr<variable_info> is_variable() override;
};
/**

View File

@ -70,6 +70,7 @@ namespace elna::gcc
bool expect_trait_type_only(boot::traits_expression *trait);
bool expect_trait_for_integral_type(boot::traits_expression *trait);
void visit_statements(const std::vector<boot::statement *>& statements);
bool extract_constant(location_t expression_location);
public:
generic_visitor(std::shared_ptr<symbol_table> symbol_table,

View File

@ -35,7 +35,6 @@ namespace elna::gcc
bool is_integral_type(tree type);
bool is_numeric_type(tree type);
bool is_primitive_type(tree type);
bool is_array_type(tree type);
bool is_void_type(tree type);
@ -73,7 +72,8 @@ namespace elna::gcc
void defer(tree statement_tree);
tree chain_defer();
tree do_pointer_arithmetic(boot::binary_operator binary_operator, tree left, tree right);
tree do_pointer_arithmetic(boot::binary_operator binary_operator,
tree left, tree right, location_t expression_location);
tree build_binary_operation(bool condition, boot::binary_expression *expression,
tree_code operator_code, tree left, tree right, tree target_type);
tree build_arithmetic_operation(boot::binary_expression *expression,