Move type definitions to the program node
This commit is contained in:
		@@ -100,7 +100,7 @@ namespace gcc
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    void generic_visitor::visit(source::program *program)
 | 
					    void generic_visitor::visit(source::program *program)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        for (const auto& constant : program->definitions())
 | 
					        for (const auto& constant : program->type_definitions)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            constant->accept(this);
 | 
					            constant->accept(this);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -596,19 +596,16 @@ namespace source
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    class block : public node
 | 
					    class block : public node
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::vector<definition *> m_definitions;
 | 
					 | 
				
			||||||
        statement *m_body;
 | 
					        statement *m_body;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
        std::vector<definition *> value_definitions;
 | 
					        std::vector<definition *> value_definitions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        block(const struct position position, std::vector<definition *>&& definitions,
 | 
					        block(const struct position position, std::vector<definition *>&& value_definitions,
 | 
				
			||||||
                std::vector<definition *>&& value_definitions,
 | 
					 | 
				
			||||||
                statement *body);
 | 
					                statement *body);
 | 
				
			||||||
        virtual void accept(parser_visitor *visitor) override;
 | 
					        virtual void accept(parser_visitor *visitor) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        statement& body();
 | 
					        statement& body();
 | 
				
			||||||
        std::vector<definition *>& definitions();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        virtual ~block() override;
 | 
					        virtual ~block() override;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
@@ -616,9 +613,13 @@ namespace source
 | 
				
			|||||||
    class program : public block
 | 
					    class program : public block
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
        program(const struct position position, std::vector<definition *>&& definitions,
 | 
					        std::vector<definition *> type_definitions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        program(const struct position position, std::vector<definition *>&& type_definitions,
 | 
				
			||||||
                std::vector<definition *>&& value_definitions, statement *body);
 | 
					                std::vector<definition *>&& value_definitions, statement *body);
 | 
				
			||||||
        virtual void accept(parser_visitor *visitor) override;
 | 
					        virtual void accept(parser_visitor *visitor) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        virtual ~program() override;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    template<typename T>
 | 
					    template<typename T>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -65,10 +65,6 @@ namespace source
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    void empty_visitor::visit(block *block)
 | 
					    void empty_visitor::visit(block *block)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        for (const auto& constant : block->definitions())
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            constant->accept(this);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        for (const auto& definition : block->value_definitions)
 | 
					        for (const auto& definition : block->value_definitions)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            definition->accept(this);
 | 
					            definition->accept(this);
 | 
				
			||||||
@@ -78,6 +74,10 @@ namespace source
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    void empty_visitor::visit(program *program)
 | 
					    void empty_visitor::visit(program *program)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        for (auto definition : program->type_definitions)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            definition->accept(this);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        visit(reinterpret_cast<block *>(program));
 | 
					        visit(reinterpret_cast<block *>(program));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -447,11 +447,9 @@ namespace source
 | 
				
			|||||||
        delete m_body;
 | 
					        delete m_body;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    block::block(const struct position position, std::vector<definition *>&& definitions,
 | 
					    block::block(const struct position position, std::vector<definition *>&& value_definitions,
 | 
				
			||||||
            std::vector<definition *>&& value_definitions,
 | 
					 | 
				
			||||||
            statement *body)
 | 
					            statement *body)
 | 
				
			||||||
        : node(position), m_definitions(std::move(definitions)),
 | 
					        : node(position), m_body(std::move(body)), value_definitions(std::move(value_definitions))
 | 
				
			||||||
        m_body(std::move(body)), value_definitions(std::move(value_definitions))
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -460,11 +458,6 @@ namespace source
 | 
				
			|||||||
        visitor->visit(this);
 | 
					        visitor->visit(this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::vector<definition *>& block::definitions()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return m_definitions;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    statement& block::body()
 | 
					    statement& block::body()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return *m_body;
 | 
					        return *m_body;
 | 
				
			||||||
@@ -472,10 +465,6 @@ namespace source
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    block::~block()
 | 
					    block::~block()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        for (auto definition : m_definitions)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            delete definition;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        for (auto definition : value_definitions)
 | 
					        for (auto definition : value_definitions)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            delete definition;
 | 
					            delete definition;
 | 
				
			||||||
@@ -483,9 +472,11 @@ namespace source
 | 
				
			|||||||
        delete m_body;
 | 
					        delete m_body;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    program::program(const struct position position, std::vector<definition *>&& definitions,
 | 
					    program::program(const struct position position,
 | 
				
			||||||
 | 
					            std::vector<definition *>&& type_definitions,
 | 
				
			||||||
            std::vector<definition *>&& value_definitions, statement *body)
 | 
					            std::vector<definition *>&& value_definitions, statement *body)
 | 
				
			||||||
        : block(position, std::move(definitions), std::move(value_definitions), body)
 | 
					        : block(position, std::move(value_definitions), body),
 | 
				
			||||||
 | 
					        type_definitions(std::move(type_definitions))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -494,6 +485,14 @@ namespace source
 | 
				
			|||||||
        visitor->visit(this);
 | 
					        visitor->visit(this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    program::~program()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        for (auto definition : type_definitions)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            delete definition;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    char_literal::char_literal(const struct position position, const unsigned char value)
 | 
					    char_literal::char_literal(const struct position position, const unsigned char value)
 | 
				
			||||||
        : expression(position), m_character(value)
 | 
					        : expression(position), m_character(value)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -143,7 +143,7 @@ block: constant_part variable_part statement
 | 
				
			|||||||
                *definition++ = variable;
 | 
					                *definition++ = variable;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            $$ = new elna::source::block(elna::source::position{},
 | 
					            $$ = new elna::source::block(elna::source::position{},
 | 
				
			||||||
                 {}, std::move(definitions), std::move($3));
 | 
					                 std::move(definitions), std::move($3));
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
procedure_definition:
 | 
					procedure_definition:
 | 
				
			||||||
    PROCEDURE IDENTIFIER formal_parameter_list SEMICOLON block SEMICOLON
 | 
					    PROCEDURE IDENTIFIER formal_parameter_list SEMICOLON block SEMICOLON
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user