Support procedures returning values
This commit is contained in:
@ -39,7 +39,7 @@ namespace gcc
|
||||
|
||||
void visit(source::program *program) override;
|
||||
void visit(source::procedure_definition *definition) override;
|
||||
void visit(source::call_statement *statement) override;
|
||||
void visit(source::call_expression *statement) override;
|
||||
void visit(source::number_literal<std::int32_t> *literal) override;
|
||||
void visit(source::number_literal<double> *literal) override;
|
||||
void visit(source::number_literal<bool> *boolean) override;
|
||||
@ -57,6 +57,8 @@ namespace gcc
|
||||
void visit(source::assign_statement *statement) override;
|
||||
void visit(source::if_statement *statement) override;
|
||||
void visit(source::while_statement *statement) override;
|
||||
void visit(source::expression_statement *statement) override;
|
||||
void visit(source::return_statement *statement) override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "tree.h"
|
||||
#include "tree.h"
|
||||
|
||||
#include "elna/source/symbol.h"
|
||||
|
||||
enum elna_tree_index
|
||||
{
|
||||
ELNA_TI_CHAR_TYPE,
|
||||
@ -25,7 +27,6 @@ namespace gcc
|
||||
void init_ttree();
|
||||
bool is_pointer_type(tree type);
|
||||
bool is_string_type(tree type);
|
||||
bool is_array_type(tree type);
|
||||
|
||||
class tree_chain_base
|
||||
{
|
||||
@ -58,6 +59,6 @@ namespace gcc
|
||||
tree block();
|
||||
};
|
||||
|
||||
std::shared_ptr<elna::source::symbol_table<tree>> builtin_symbol_table();
|
||||
std::shared_ptr<source::symbol_table<tree>> builtin_symbol_table();
|
||||
}
|
||||
}
|
||||
|
@ -39,11 +39,13 @@ namespace source
|
||||
class constant_definition;
|
||||
class procedure_definition;
|
||||
class type_definition;
|
||||
class call_statement;
|
||||
class call_expression;
|
||||
class compound_statement;
|
||||
class assign_statement;
|
||||
class if_statement;
|
||||
class while_statement;
|
||||
class return_statement;
|
||||
class expression_statement;
|
||||
class block;
|
||||
class program;
|
||||
class binary_expression;
|
||||
@ -71,11 +73,13 @@ namespace source
|
||||
virtual void visit(constant_definition *) = 0;
|
||||
virtual void visit(procedure_definition *) = 0;
|
||||
virtual void visit(type_definition *) = 0;
|
||||
virtual void visit(call_statement *) = 0;
|
||||
virtual void visit(call_expression *) = 0;
|
||||
virtual void visit(expression_statement *) = 0;
|
||||
virtual void visit(compound_statement *) = 0;
|
||||
virtual void visit(assign_statement *) = 0;
|
||||
virtual void visit(if_statement *) = 0;
|
||||
virtual void visit(while_statement *) = 0;
|
||||
virtual void visit(return_statement *) = 0;
|
||||
virtual void visit(block *) = 0;
|
||||
virtual void visit(program *) = 0;
|
||||
virtual void visit(binary_expression *) = 0;
|
||||
@ -105,11 +109,13 @@ namespace source
|
||||
virtual void visit(constant_definition *definition) override;
|
||||
virtual void visit(procedure_definition *definition) override;
|
||||
virtual void visit(type_definition *definition) override;
|
||||
virtual void visit(call_statement *statement) override;
|
||||
virtual void visit(call_expression *statement) override;
|
||||
virtual void visit(expression_statement *statement) override;
|
||||
virtual void visit(compound_statement *statement) override;
|
||||
virtual void visit(assign_statement *statement) override;
|
||||
virtual void visit(if_statement *) override;
|
||||
virtual void visit(while_statement *) override;
|
||||
virtual void visit(return_statement *) override;
|
||||
virtual void visit(block *block) override;
|
||||
virtual void visit(program *program) override;
|
||||
virtual void visit(binary_expression *expression) override;
|
||||
@ -403,6 +409,7 @@ namespace source
|
||||
*/
|
||||
class procedure_definition : public definition
|
||||
{
|
||||
type_expression *m_return_type{ nullptr };
|
||||
block *m_body{ nullptr };
|
||||
|
||||
public:
|
||||
@ -411,12 +418,16 @@ namespace source
|
||||
/**
|
||||
* \param position Source code position.
|
||||
* \param identifier Procedure name.
|
||||
* \param parameters Procedure formal parameters.
|
||||
* \param return_type Return type if any.
|
||||
* \param body Procedure body.
|
||||
*/
|
||||
procedure_definition(const struct position position, const std::string& identifier,
|
||||
block *body = nullptr);
|
||||
std::vector<variable_declaration *>&& parameters,
|
||||
type_expression *return_type = nullptr, block *body = nullptr);
|
||||
virtual void accept(parser_visitor *visitor) override;
|
||||
|
||||
type_expression *return_type();
|
||||
block *body();
|
||||
|
||||
virtual ~procedure_definition() override;
|
||||
@ -439,7 +450,7 @@ namespace source
|
||||
/**
|
||||
* Call statement.
|
||||
*/
|
||||
class call_statement : public statement
|
||||
class call_expression : public expression
|
||||
{
|
||||
std::string m_name;
|
||||
std::vector<expression *> m_arguments;
|
||||
@ -449,16 +460,29 @@ namespace source
|
||||
* \param position Source code position.
|
||||
* \param name Callable's name.
|
||||
*/
|
||||
call_statement(const struct position position, const std::string& name);
|
||||
call_expression(const struct position position, const std::string& name);
|
||||
virtual void accept(parser_visitor *visitor) override;
|
||||
|
||||
std::string& name();
|
||||
std::vector<expression *>& arguments();
|
||||
|
||||
virtual ~call_statement() override;
|
||||
virtual ~call_expression() override;
|
||||
};
|
||||
|
||||
class compound_statement : public statement
|
||||
class expression_statement : public statement
|
||||
{
|
||||
expression *m_body;
|
||||
|
||||
public:
|
||||
expression_statement(const struct position position, expression *body);
|
||||
virtual void accept(parser_visitor *visitor) override;
|
||||
|
||||
expression& body();
|
||||
|
||||
virtual ~expression_statement() override;
|
||||
};
|
||||
|
||||
class compound_statement : public node
|
||||
{
|
||||
public:
|
||||
std::vector<statement *> statements;
|
||||
@ -469,6 +493,19 @@ namespace source
|
||||
virtual ~compound_statement() override;
|
||||
};
|
||||
|
||||
class return_statement : public statement
|
||||
{
|
||||
expression *m_return_expression{ nullptr };
|
||||
|
||||
public:
|
||||
return_statement(const struct position position, expression *return_expression);
|
||||
virtual void accept(parser_visitor *visitor) override;
|
||||
|
||||
expression *return_expression();
|
||||
|
||||
virtual ~return_statement() override;
|
||||
};
|
||||
|
||||
class designator_expression : public expression
|
||||
{
|
||||
public:
|
||||
|
Reference in New Issue
Block a user