Fix dreferencing function_call refs. Now need to make sure new pass method works with defer_lower, which currently does very crazy defer double stack chains

This commit is contained in:
Nathan Braswell
2017-01-20 01:31:28 -05:00
parent e2639989c9
commit 21f957195a

View File

@@ -38,7 +38,7 @@ fun remove_ref(t: *type) {
fun ref_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_syntax: *map<*ast_node, *tree<symbol>>) {
var remove_ref_type_set = set<pair<string,*type>>()
var modify_identifier_set = set<pair<*ast_node, *ast_node>>()
var modify_reference_use_set = set<pair<*ast_node, *ast_node>>()
var modify_return_set = set<*ast_node>()
var visited = set<*ast_node>()
name_ast_map->for_each(fun(name: string, syntax_ast_pair: pair<*tree<symbol>,*ast_node>) {
@@ -46,7 +46,7 @@ fun ref_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
match(*node) {
ast_node::identifier(backing) {
if (backing.type->is_ref)
modify_identifier_set.add(make_pair(node, parent_chain->top()))
modify_reference_use_set.add(make_pair(node, parent_chain->top()))
if (has_ref_inside(backing.type)) {
remove_ref_type_set.add(make_pair("identifier: " + backing.name, backing.type))
}
@@ -65,6 +65,9 @@ fun ref_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
for (var i = 0; i < func_type_params.size; i++;)
if (func_type_params[i]->is_ref)
backing.parameters[i] = make_operator_call("&", vector(backing.parameters[i]))
// add the function call to the modify_reference_use set if the function returns a ref
if (get_ast_type(backing.func)->return_type->is_ref)
modify_reference_use_set.add(make_pair(node, parent_chain->top()))
}
ast_node::return_statement(backing) {
// check to see if it's returning a ref, if so add in the &
@@ -81,15 +84,15 @@ fun ref_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
remove_ref(t)
println("after" + p.first + ": " + t->to_string())
})
modify_identifier_set.for_each(fun(p: pair<*ast_node, *ast_node>) {
modify_reference_use_set.for_each(fun(p: pair<*ast_node, *ast_node>) {
// if we haven't modified it's indirection yet
if (p.first->identifier.type->is_ref) {
if (is_identifier(p.first) && p.first->identifier.type->is_ref) {
// remove ref, add 1 to indirection
p.first->identifier.type = p.first->identifier.type->clone_with_increased_indirection(1, false);
}
// note that we definitly want to replace the type for unused parameters, but we don't want to add the * for paramters
// in function declarations or declaration statements
if (!is_function(p.second) && !is_declaration_statement(p.second))
if (!is_identifier(p.first) || (!is_function(p.second) && !is_declaration_statement(p.second)))
replace_with_in(p.first, make_operator_call("*", vector(p.first)), p.second);
})
modify_return_set.for_each(fun(r: *ast_node) {