diff options
Diffstat (limited to 'gcc/go/gofrontend/gogo-tree.cc')
-rw-r--r-- | gcc/go/gofrontend/gogo-tree.cc | 121 |
1 files changed, 69 insertions, 52 deletions
diff --git a/gcc/go/gofrontend/gogo-tree.cc b/gcc/go/gofrontend/gogo-tree.cc index 349ee25..0e77f5d 100644 --- a/gcc/go/gofrontend/gogo-tree.cc +++ b/gcc/go/gofrontend/gogo-tree.cc @@ -336,8 +336,9 @@ Gogo::register_gc_vars(const std::vector<Named_object*>& var_gc, rest_of_decl_compilation(decl, 1, 0); static tree register_gc_fndecl; - tree call = Gogo::call_builtin(®ister_gc_fndecl, BUILTINS_LOCATION, - "__go_register_gc_roots", + tree call = Gogo::call_builtin(®ister_gc_fndecl, + Linemap::predeclared_location(), + "__go_register_gc_roots", 1, void_type_node, build_pointer_type(root_list_type), @@ -746,8 +747,9 @@ Gogo::write_globals() else if (is_sink) var_init_tree = init; else - var_init_tree = fold_build2_loc(no->location(), MODIFY_EXPR, - void_type_node, vec[i], init); + var_init_tree = fold_build2_loc(no->location().gcc_location(), + MODIFY_EXPR, void_type_node, + vec[i], init); } else { @@ -843,7 +845,7 @@ Named_object::get_id(Gogo* gogo) && !this->func_declaration_value()->asm_name().empty()) decl_name = this->func_declaration_value()->asm_name(); else if (this->is_type() - && this->type_value()->location() == BUILTINS_LOCATION) + && Linemap::is_predeclared_location(this->type_value()->location())) { // We don't need the package name for builtin types. decl_name = Gogo::unpack_hidden_name(this->name_); @@ -920,8 +922,8 @@ Named_object::get_tree(Gogo* gogo, Named_object* function) decl = error_mark_node; else if (INTEGRAL_TYPE_P(TREE_TYPE(expr_tree))) { - decl = build_decl(named_constant->location(), CONST_DECL, - name, TREE_TYPE(expr_tree)); + decl = build_decl(named_constant->location().gcc_location(), + CONST_DECL, name, TREE_TYPE(expr_tree)); DECL_INITIAL(decl) = expr_tree; TREE_CONSTANT(decl) = 1; TREE_READONLY(decl) = 1; @@ -958,9 +960,12 @@ Named_object::get_tree(Gogo* gogo, Named_object* function) // descriptor, even though we don't do anything with it. if (this->package_ == NULL) { - named_type->type_descriptor_pointer(gogo, BUILTINS_LOCATION); + named_type-> + type_descriptor_pointer(gogo, + Linemap::predeclared_location()); Type* pn = Type::make_pointer_type(named_type); - pn->type_descriptor_pointer(gogo, BUILTINS_LOCATION); + pn->type_descriptor_pointer(gogo, + Linemap::predeclared_location()); } } } @@ -989,7 +994,8 @@ Named_object::get_tree(Gogo* gogo, Named_object* function) else push_cfun(DECL_STRUCT_FUNCTION(decl)); - cfun->function_end_locus = func->block()->end_location(); + cfun->function_end_locus = + func->block()->end_location().gcc_location(); current_function_decl = decl; @@ -1091,8 +1097,9 @@ Variable::get_init_block(Gogo* gogo, Named_object* function, tree var_decl) this->location()); if (val == error_mark_node) return error_mark_node; - tree set = fold_build2_loc(this->location(), MODIFY_EXPR, - void_type_node, var_decl, val); + tree set = fold_build2_loc(this->location().gcc_location(), + MODIFY_EXPR, void_type_node, var_decl, + val); append_to_statement_list(set, &statements); } } @@ -1116,7 +1123,8 @@ Function::get_or_make_decl(Gogo* gogo, Named_object* no, tree id) // want the real function type for a function declaration. go_assert(POINTER_TYPE_P(functype)); functype = TREE_TYPE(functype); - tree decl = build_decl(this->location(), FUNCTION_DECL, id, functype); + tree decl = build_decl(this->location().gcc_location(), FUNCTION_DECL, + id, functype); this->fndecl_ = decl; @@ -1146,8 +1154,9 @@ Function::get_or_make_decl(Gogo* gogo, Named_object* no, tree id) // Why do we have to do this in the frontend? tree restype = TREE_TYPE(functype); - tree resdecl = build_decl(this->location(), RESULT_DECL, NULL_TREE, - restype); + tree resdecl = + build_decl(this->location().gcc_location(), RESULT_DECL, NULL_TREE, + restype); DECL_ARTIFICIAL(resdecl) = 1; DECL_IGNORED_P(resdecl) = 1; DECL_CONTEXT(resdecl) = decl; @@ -1233,7 +1242,8 @@ Function_declaration::get_or_make_decl(Gogo* gogo, Named_object* no, tree id) // want the real function type for a function declaration. go_assert(POINTER_TYPE_P(functype)); functype = TREE_TYPE(functype); - decl = build_decl(this->location(), FUNCTION_DECL, id, functype); + decl = build_decl(this->location().gcc_location(), FUNCTION_DECL, id, + functype); TREE_PUBLIC(decl) = 1; DECL_EXTERNAL(decl) = 1; @@ -1292,7 +1302,8 @@ Function::make_receiver_parm_decl(Gogo* gogo, Named_object* no, tree var_decl) no->location()); space = save_expr(space); space = fold_convert(build_pointer_type(val_type), space); - tree spaceref = build_fold_indirect_ref_loc(no->location(), space); + tree spaceref = build_fold_indirect_ref_loc(no->location().gcc_location(), + space); TREE_THIS_NOTRAP(spaceref) = 1; tree set = fold_build2_loc(loc, MODIFY_EXPR, void_type_node, spaceref, init); @@ -1314,7 +1325,7 @@ Function::copy_parm_to_heap(Gogo* gogo, Named_object* no, tree var_decl) if (var_decl == error_mark_node) return error_mark_node; go_assert(TREE_CODE(var_decl) == VAR_DECL); - source_location loc = DECL_SOURCE_LOCATION(var_decl); + Location loc(DECL_SOURCE_LOCATION(var_decl)); std::string name = IDENTIFIER_POINTER(DECL_NAME(var_decl)); name += ".param"; @@ -1324,7 +1335,7 @@ Function::copy_parm_to_heap(Gogo* gogo, Named_object* no, tree var_decl) go_assert(POINTER_TYPE_P(type)); type = TREE_TYPE(type); - tree parm_decl = build_decl(loc, PARM_DECL, id, type); + tree parm_decl = build_decl(loc.gcc_location(), PARM_DECL, id, type); DECL_CONTEXT(parm_decl) = current_function_decl; DECL_ARG_TYPE(parm_decl) = type; @@ -1332,7 +1343,7 @@ Function::copy_parm_to_heap(Gogo* gogo, Named_object* no, tree var_decl) tree space = gogo->allocate_memory(no->var_value()->type(), size, loc); space = save_expr(space); space = fold_convert(TREE_TYPE(var_decl), space); - tree spaceref = build_fold_indirect_ref_loc(loc, space); + tree spaceref = build_fold_indirect_ref_loc(loc.gcc_location(), space); TREE_THIS_NOTRAP(spaceref) = 1; tree init = build2(COMPOUND_EXPR, TREE_TYPE(space), build2(MODIFY_EXPR, void_type_node, spaceref, parm_decl), @@ -1415,13 +1426,13 @@ Function::build_tree(Gogo* gogo, Named_object* named_function) } else { - source_location loc = (*p)->location(); + Location loc = (*p)->location(); tree type_tree = type_to_tree(type->get_backend(gogo)); tree space = gogo->allocate_memory(type, TYPE_SIZE_UNIT(type_tree), loc); tree ptr_type_tree = build_pointer_type(type_tree); - init = fold_convert_loc(loc, ptr_type_tree, space); + init = fold_convert_loc(loc.gcc_location(), ptr_type_tree, space); } if (var_decl != error_mark_node) @@ -1486,7 +1497,8 @@ Function::build_tree(Gogo* gogo, Named_object* named_function) // function. if (defer_init != NULL_TREE && defer_init != error_mark_node) { - SET_EXPR_LOCATION(defer_init, this->block_->start_location()); + SET_EXPR_LOCATION(defer_init, + this->block_->start_location().gcc_location()); append_to_statement_list(defer_init, &init); // Clean up the defer stack when we leave the function. @@ -1524,7 +1536,7 @@ void Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function, tree *except, tree *fini) { - source_location end_loc = this->block_->end_location(); + Location end_loc = this->block_->end_location(); // Add an exception handler. This is used if a panic occurs. Its // purpose is to stop the stack unwinding if a deferred function @@ -1545,9 +1557,10 @@ Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function, if (retval == NULL_TREE) set = NULL_TREE; else - set = fold_build2_loc(end_loc, MODIFY_EXPR, void_type_node, + set = fold_build2_loc(end_loc.gcc_location(), MODIFY_EXPR, void_type_node, DECL_RESULT(this->fndecl_), retval); - tree ret_stmt = fold_build1_loc(end_loc, RETURN_EXPR, void_type_node, set); + tree ret_stmt = fold_build1_loc(end_loc.gcc_location(), RETURN_EXPR, + void_type_node, set); append_to_statement_list(ret_stmt, &stmt_list); go_assert(*except == NULL_TREE); @@ -1564,9 +1577,9 @@ Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function, stmt_list = NULL; - tree label = create_artificial_label(end_loc); - tree define_label = fold_build1_loc(end_loc, LABEL_EXPR, void_type_node, - label); + tree label = create_artificial_label(end_loc.gcc_location()); + tree define_label = fold_build1_loc(end_loc.gcc_location(), LABEL_EXPR, + void_type_node, label); append_to_statement_list(define_label, &stmt_list); call = Runtime::make_call(Runtime::UNDEFER, end_loc, 1, @@ -1580,7 +1593,8 @@ Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function, if (undefer == error_mark_node || defer == error_mark_node) return; - tree jump = fold_build1_loc(end_loc, GOTO_EXPR, void_type_node, label); + tree jump = fold_build1_loc(end_loc.gcc_location(), GOTO_EXPR, void_type_node, + label); tree catch_body = build2(COMPOUND_EXPR, void_type_node, defer, jump); catch_body = build2(CATCH_EXPR, void_type_node, NULL, catch_body); tree try_catch = build2(TRY_CATCH_EXPR, void_type_node, undefer, catch_body); @@ -1598,15 +1612,16 @@ Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function, // variable to true if we are returning from this function. retval = this->return_value(gogo, named_function, end_loc, &stmt_list); - set = fold_build2_loc(end_loc, MODIFY_EXPR, void_type_node, + set = fold_build2_loc(end_loc.gcc_location(), MODIFY_EXPR, void_type_node, DECL_RESULT(this->fndecl_), retval); - ret_stmt = fold_build1_loc(end_loc, RETURN_EXPR, void_type_node, set); + ret_stmt = fold_build1_loc(end_loc.gcc_location(), RETURN_EXPR, + void_type_node, set); Expression* ref = Expression::make_temporary_reference(this->defer_stack_, end_loc); tree tref = ref->get_tree(&context); - tree s = build3_loc(end_loc, COND_EXPR, void_type_node, tref, - ret_stmt, NULL_TREE); + tree s = build3_loc(end_loc.gcc_location(), COND_EXPR, void_type_node, + tref, ret_stmt, NULL_TREE); append_to_statement_list(s, &stmt_list); @@ -1623,7 +1638,7 @@ Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function, tree Function::return_value(Gogo* gogo, Named_object* named_function, - source_location location, tree* stmt_list) const + Location location, tree* stmt_list) const { const Typed_identifier_list* results = this->type_->results(); if (results == NULL || results->empty()) @@ -1644,7 +1659,7 @@ Function::return_value(Gogo* gogo, Named_object* named_function, named_function); tree ret = var_to_tree(bvar); if (this->results_->front()->result_var_value()->is_in_heap()) - ret = build_fold_indirect_ref_loc(location, ret); + ret = build_fold_indirect_ref_loc(location.gcc_location(), ret); return ret; } else @@ -1662,8 +1677,9 @@ Function::return_value(Gogo* gogo, Named_object* named_function, Bvariable* bvar = no->get_backend_variable(gogo, named_function); tree val = var_to_tree(bvar); if (no->result_var_value()->is_in_heap()) - val = build_fold_indirect_ref_loc(location, val); - tree set = fold_build2_loc(location, MODIFY_EXPR, void_type_node, + val = build_fold_indirect_ref_loc(location.gcc_location(), val); + tree set = fold_build2_loc(location.gcc_location(), MODIFY_EXPR, + void_type_node, build3(COMPONENT_REF, TREE_TYPE(field), retval, field, NULL_TREE), val); @@ -1762,7 +1778,7 @@ go_type_for_mode(enum machine_mode mode, int unsignedp) // type TYPE. tree -Gogo::allocate_memory(Type* type, tree size, source_location location) +Gogo::allocate_memory(Type* type, tree size, Location location) { // If the package imports unsafe, then it may play games with // pointers that look like integers. @@ -2028,7 +2044,8 @@ Gogo::interface_method_table_for_type(const Interface_type* interface, td_type = type; else td_type = Type::make_pointer_type(type); - tree tdp = td_type->type_descriptor_pointer(this, BUILTINS_LOCATION); + tree tdp = td_type->type_descriptor_pointer(this, + Linemap::predeclared_location()); elt->value = fold_convert(const_ptr_type_node, tdp); size_t i = 1; @@ -2105,7 +2122,7 @@ Gogo::mark_fndecl_as_builtin_library(tree fndecl) // Build a call to a builtin function. tree -Gogo::call_builtin(tree* pdecl, source_location location, const char* name, +Gogo::call_builtin(tree* pdecl, Location location, const char* name, int nargs, tree rettype, ...) { if (rettype == error_mark_node) @@ -2151,10 +2168,10 @@ Gogo::call_builtin(tree* pdecl, source_location location, const char* name, tree fnptr = build_fold_addr_expr(*pdecl); if (CAN_HAVE_LOCATION_P(fnptr)) - SET_EXPR_LOCATION(fnptr, location); + SET_EXPR_LOCATION(fnptr, location.gcc_location()); tree ret = build_call_array(rettype, fnptr, nargs, args); - SET_EXPR_LOCATION(ret, location); + SET_EXPR_LOCATION(ret, location.gcc_location()); delete[] types; delete[] args; @@ -2165,7 +2182,7 @@ Gogo::call_builtin(tree* pdecl, source_location location, const char* name, // Build a call to the runtime error function. tree -Gogo::runtime_error(int code, source_location location) +Gogo::runtime_error(int code, Location location) { static tree runtime_error_fndecl; tree ret = Gogo::call_builtin(&runtime_error_fndecl, @@ -2190,7 +2207,7 @@ Gogo::runtime_error(int code, source_location location) tree Gogo::receive_from_channel(tree type_tree, tree channel, bool for_select, - source_location location) + Location location) { if (type_tree == error_mark_node || channel == error_mark_node) return error_mark_node; @@ -2218,9 +2235,9 @@ Gogo::receive_from_channel(tree type_tree, tree channel, bool for_select, TREE_NOTHROW(receive_small_fndecl) = 0; int bitsize = GET_MODE_BITSIZE(TYPE_MODE(type_tree)); tree int_type_tree = go_type_for_size(bitsize, 1); - return fold_convert_loc(location, type_tree, - fold_convert_loc(location, int_type_tree, - call)); + return fold_convert_loc(location.gcc_location(), type_tree, + fold_convert_loc(location.gcc_location(), + int_type_tree, call)); } else { @@ -2228,7 +2245,7 @@ Gogo::receive_from_channel(tree type_tree, tree channel, bool for_select, DECL_IGNORED_P(tmp) = 0; TREE_ADDRESSABLE(tmp) = 1; tree make_tmp = build1(DECL_EXPR, void_type_node, tmp); - SET_EXPR_LOCATION(make_tmp, location); + SET_EXPR_LOCATION(make_tmp, location.gcc_location()); tree tmpaddr = build_fold_addr_expr(tmp); tmpaddr = fold_convert(ptr_type_node, tmpaddr); static tree receive_big_fndecl; @@ -2284,7 +2301,7 @@ Gogo::trampoline_type_tree() // Make a trampoline which calls FNADDR passing CLOSURE. tree -Gogo::make_trampoline(tree fnaddr, tree closure, source_location location) +Gogo::make_trampoline(tree fnaddr, tree closure, Location location) { tree trampoline_type = Gogo::trampoline_type_tree(); tree trampoline_size = TYPE_SIZE_UNIT(trampoline_type); @@ -2302,8 +2319,8 @@ Gogo::make_trampoline(tree fnaddr, tree closure, source_location location) size_type_node, trampoline_size, ptr_type_node, - fold_convert_loc(location, ptr_type_node, - closure)); + fold_convert_loc(location.gcc_location(), + ptr_type_node, closure)); if (x == error_mark_node) return error_mark_node; |