Set variable declaration context
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
#include "elna/gcc/elna-generic.h"
|
||||
#include "elna/gcc/elna-tree.h"
|
||||
#include "elna/gcc/elna-diagnostic.h"
|
||||
|
||||
#include "input.h"
|
||||
@ -93,18 +92,16 @@ namespace gcc
|
||||
build_int_cst_type(integer_type_node, 0));
|
||||
tree return_stmt = build1(RETURN_EXPR, void_type_node, set_result);
|
||||
|
||||
this->current_statements = alloc_stmt_list();
|
||||
|
||||
empty_visitor::visit(program);
|
||||
enter_scope();
|
||||
|
||||
empty_visitor::visit(program);
|
||||
append_to_statement_list(return_stmt, &this->current_statements);
|
||||
|
||||
tree_symbol_mapping mapping = leave_scope();
|
||||
|
||||
tree new_block = build_block(NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
|
||||
tree bind_expr = build3(BIND_EXPR, void_type_node, NULL_TREE, this->current_statements, new_block);
|
||||
|
||||
BLOCK_SUPERCONTEXT(new_block) = this->main_fndecl;
|
||||
DECL_INITIAL(this->main_fndecl) = new_block;
|
||||
DECL_SAVED_TREE(this->main_fndecl) = bind_expr;
|
||||
BLOCK_SUPERCONTEXT(mapping.block()) = this->main_fndecl;
|
||||
DECL_INITIAL(this->main_fndecl) = mapping.block();
|
||||
DECL_SAVED_TREE(this->main_fndecl) = mapping.bind_expression();
|
||||
|
||||
DECL_EXTERNAL(this->main_fndecl) = 0;
|
||||
DECL_PRESERVE_P(this->main_fndecl) = 1;
|
||||
@ -114,6 +111,22 @@ namespace gcc
|
||||
cgraph_node::finalize_function(this->main_fndecl, true);
|
||||
}
|
||||
|
||||
void generic_visitor::enter_scope()
|
||||
{
|
||||
this->current_statements = alloc_stmt_list();
|
||||
this->variable_chain = tree_chain();
|
||||
}
|
||||
|
||||
tree_symbol_mapping generic_visitor::leave_scope()
|
||||
{
|
||||
tree new_block = build_block(variable_chain.head(),
|
||||
NULL_TREE, NULL_TREE, NULL_TREE);
|
||||
tree bind_expr = build3(BIND_EXPR, void_type_node, variable_chain.head(),
|
||||
this->current_statements, new_block);
|
||||
|
||||
return tree_symbol_mapping{ bind_expr, new_block };
|
||||
}
|
||||
|
||||
void generic_visitor::visit(source::number_literal<std::int32_t> *literal)
|
||||
{
|
||||
this->current_expression = build_int_cst_type(integer_type_node, literal->number());
|
||||
@ -304,9 +317,11 @@ namespace gcc
|
||||
get_identifier(declaration->identifier().c_str()), declaration_type);
|
||||
auto result = this->symbol_map.insert({ declaration->identifier(), declaration_tree });
|
||||
|
||||
// DECL_CONTEXT(declaration_tree) = this->main_fndecl;
|
||||
if (result.second)
|
||||
{
|
||||
DECL_CONTEXT(declaration_tree) = this->main_fndecl;
|
||||
variable_chain.append(declaration_tree);
|
||||
|
||||
auto declaration_statement = build1_loc(declaration_location, DECL_EXPR,
|
||||
void_type_node, declaration_tree);
|
||||
append_to_statement_list(declaration_statement, &this->current_statements);
|
||||
|
Reference in New Issue
Block a user