From patchwork Tue Nov 27 19:57:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1003991 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-491028-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=golang.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="dy3ypaPJ"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=golang-org.20150623.gappssmtp.com header.i=@golang-org.20150623.gappssmtp.com header.b="kwFzEwOV"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 434F2b5T3cz9rxp for ; Wed, 28 Nov 2018 06:58:14 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=mMR0Kquhjl4JymIfrUIkX81e7UigzXZFuMk3pJGA1+aIKT 1z8K7JUnavPnHHSjfVbpAvsyrNJ0xqnFQzdWgQmqQnsRQhiR+nYDJ5JKFrk3ynWa WhJjqoasY9kh5e2zuusJ2Me7yEP/hIea5ghKf+LqdVIqBI+XL3BwD2KpkpeTg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=4VY7Ko+EGZ2gRLz5hdJqaT3oq0o=; b=dy3ypaPJwbUDCNKC8fmt VJw9bZLD2eM1HT/mRqAzOZamgqdcekQzq/kNcGVh66d195TYQTzOM3a9S9geRka0 LSv1E0ebis/gntMi38yIAuF55Lgc5tZYfVaeRhyfF+dHkqS4DfugpMA5RTejtGua KrTfZYK3kTfheJhYVyBiScA= Received: (qmail 25941 invoked by alias); 27 Nov 2018 19:58:07 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 24499 invoked by uid 89); 27 Nov 2018 19:58:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-lj1-f174.google.com Received: from mail-lj1-f174.google.com (HELO mail-lj1-f174.google.com) (209.85.208.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 Nov 2018 19:58:01 +0000 Received: by mail-lj1-f174.google.com with SMTP id t9-v6so21204766ljh.6 for ; Tue, 27 Nov 2018 11:58:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golang-org.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=NpoD/R5M4jd+H/roWvPtjeP1fyniWV3p544x7pcBZF0=; b=kwFzEwOVSYR780I6CRku+ILKBprlb3eYLkhDvPmpcplb/lNUZoc+QgPebSmrp48KE6 wPhuiGnWx2tpsO8NH9PjtUlOQRotTCsRZfb11q6x28aTLugiFN5/kXPCc2dVTt5ufXiI vUquCejBdDb8Q7wwS/XMWxQtjXKegOh0fuVyvDeqALAbB7Ic4Hx+LB/fwDsejcL+weRp 8/VAnRp3BkGdkEt5MEGtZ1wBsUkdDcw4IXLrRH7MqrSBU3DOqiLIjo74sOL9qUd8NkUI U0QZNh2Ce3H1flzcJukaB32C3fN7WQLfxpBID2iE/gewed/RJwCjOG4RVOn0/Lzst4Tx KCXQ== MIME-Version: 1.0 From: Ian Lance Taylor Date: Tue, 27 Nov 2018 11:57:46 -0800 Message-ID: Subject: Go patch committed: Pass a Location to import_expression To: gcc-patches , gofrontend-dev@googlegroups.com This patch changes the Go frontend to pass a Location to import_expression. This separates the Location that import_expression uses when creating a new Expression from the Location used to report an error. This is a step toward importing expressions for inlined functions. This is a pure refactoring that does not affect compiler behavior. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 266523) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -db5240278b3b62a919dd88f857e718a66be50346 +75d48ff977a2865d12b03857362ea48016a4b885 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/expressions.cc =================================================================== --- gcc/go/gofrontend/expressions.cc (revision 266523) +++ gcc/go/gofrontend/expressions.cc (working copy) @@ -1583,7 +1583,7 @@ class Boolean_expression : public Expres { } static Expression* - do_import(Import*); + do_import(Import*, Location); protected: bool @@ -1649,17 +1649,17 @@ Boolean_expression::do_determine_type(co // Import a boolean constant. Expression* -Boolean_expression::do_import(Import* imp) +Boolean_expression::do_import(Import* imp, Location loc) { if (imp->peek_char() == 't') { imp->require_c_string("true"); - return Expression::make_boolean(true, imp->location()); + return Expression::make_boolean(true, loc); } else { imp->require_c_string("false"); - return Expression::make_boolean(false, imp->location()); + return Expression::make_boolean(false, loc); } } @@ -1768,7 +1768,7 @@ String_expression::do_export(Export_func // Import a string expression. Expression* -String_expression::do_import(Import* imp) +String_expression::do_import(Import* imp, Location loc) { imp->require_c_string("\""); std::string val; @@ -1800,11 +1800,11 @@ String_expression::do_import(Import* imp else { go_error_at(imp->location(), "bad string constant"); - return Expression::make_error(imp->location()); + return Expression::make_error(loc); } } } - return Expression::make_string(val, imp->location()); + return Expression::make_string(val, loc); } // Ast dump for string expression. @@ -1944,7 +1944,7 @@ class Integer_expression : public Expres { mpz_init_set(this->val_, *val); } static Expression* - do_import(Import*); + do_import(Import*, Location); // Write VAL to string dump. static void @@ -2151,7 +2151,7 @@ Integer_expression::do_export(Export_fun // all these types because they all start with digits. Expression* -Integer_expression::do_import(Import* imp) +Integer_expression::do_import(Import* imp, Location loc) { std::string num = imp->read_identifier(); imp->require_c_string(" "); @@ -2169,7 +2169,7 @@ Integer_expression::do_import(Import* im { go_error_at(imp->location(), "bad number in import data: %qs", num.c_str()); - return Expression::make_error(imp->location()); + return Expression::make_error(loc); } if (pos == std::string::npos) mpfr_set_ui(real, 0, GMP_RNDN); @@ -2180,7 +2180,7 @@ Integer_expression::do_import(Import* im { go_error_at(imp->location(), "bad number in import data: %qs", real_str.c_str()); - return Expression::make_error(imp->location()); + return Expression::make_error(loc); } } @@ -2195,14 +2195,14 @@ Integer_expression::do_import(Import* im { go_error_at(imp->location(), "bad number in import data: %qs", imag_str.c_str()); - return Expression::make_error(imp->location()); + return Expression::make_error(loc); } mpc_t cval; mpc_init2(cval, mpc_precision); mpc_set_fr_fr(cval, real, imag, MPC_RNDNN); mpfr_clear(real); mpfr_clear(imag); - Expression* ret = Expression::make_complex(&cval, NULL, imp->location()); + Expression* ret = Expression::make_complex(&cval, NULL, loc); mpc_clear(cval); return ret; } @@ -2218,13 +2218,13 @@ Integer_expression::do_import(Import* im { go_error_at(imp->location(), "bad number in import data: %qs", num.c_str()); - return Expression::make_error(imp->location()); + return Expression::make_error(loc); } Expression* ret; if (is_character_constant) - ret = Expression::make_character(&val, NULL, imp->location()); + ret = Expression::make_character(&val, NULL, loc); else - ret = Expression::make_integer_z(&val, NULL, imp->location()); + ret = Expression::make_integer_z(&val, NULL, loc); mpz_clear(val); return ret; } @@ -2235,9 +2235,9 @@ Integer_expression::do_import(Import* im { go_error_at(imp->location(), "bad number in import data: %qs", num.c_str()); - return Expression::make_error(imp->location()); + return Expression::make_error(loc); } - Expression* ret = Expression::make_float(&val, NULL, imp->location()); + Expression* ret = Expression::make_float(&val, NULL, loc); mpfr_clear(val); return ret; } @@ -3133,7 +3133,7 @@ class Nil_expression : public Expression { } static Expression* - do_import(Import*); + do_import(Import*, Location); protected: bool @@ -3172,10 +3172,10 @@ class Nil_expression : public Expression // Import a nil expression. Expression* -Nil_expression::do_import(Import* imp) +Nil_expression::do_import(Import* imp, Location loc) { imp->require_c_string("nil"); - return Expression::make_nil(imp->location()); + return Expression::make_nil(loc); } // Make a nil expression. @@ -3623,14 +3623,14 @@ Type_conversion_expression::do_export(Ex // Import a type conversion or a struct construction. Expression* -Type_conversion_expression::do_import(Import* imp) +Type_conversion_expression::do_import(Import* imp, Location loc) { imp->require_c_string("convert("); Type* type = imp->read_type(); imp->require_c_string(", "); - Expression* val = Expression::import_expression(imp); + Expression* val = Expression::import_expression(imp, loc); imp->require_c_string(")"); - return Expression::make_cast(type, val, imp->location()); + return Expression::make_cast(type, val, loc); } // Dump ast representation for a type conversion expression. @@ -4634,7 +4634,7 @@ Unary_expression::do_export(Export_funct // Import a unary expression. Expression* -Unary_expression::do_import(Import* imp) +Unary_expression::do_import(Import* imp, Location loc) { Operator op; switch (imp->get_char()) @@ -4655,8 +4655,8 @@ Unary_expression::do_import(Import* imp) go_unreachable(); } imp->require_c_string(" "); - Expression* expr = Expression::import_expression(imp); - return Expression::make_unary(op, expr, imp->location()); + Expression* expr = Expression::import_expression(imp, loc); + return Expression::make_unary(op, expr, loc); } // Dump ast representation of an unary expression. @@ -6403,11 +6403,11 @@ Binary_expression::do_export(Export_func // Import a binary expression. Expression* -Binary_expression::do_import(Import* imp) +Binary_expression::do_import(Import* imp, Location loc) { imp->require_c_string("("); - Expression* left = Expression::import_expression(imp); + Expression* left = Expression::import_expression(imp, loc); Operator op; if (imp->match_c_string(" || ")) @@ -6508,14 +6508,14 @@ Binary_expression::do_import(Import* imp else { go_error_at(imp->location(), "unrecognized binary operator"); - return Expression::make_error(imp->location()); + return Expression::make_error(loc); } - Expression* right = Expression::import_expression(imp); + Expression* right = Expression::import_expression(imp, loc); imp->require_c_string(")"); - return Expression::make_binary(op, left, right, imp->location()); + return Expression::make_binary(op, left, right, loc); } // Dump ast representation of a binary expression. @@ -16138,33 +16138,33 @@ Expression::make_backend(Bexpression* be // various class definitions. Expression* -Expression::import_expression(Import* imp) +Expression::import_expression(Import* imp, Location loc) { int c = imp->peek_char(); if (imp->match_c_string("- ") || imp->match_c_string("! ") || imp->match_c_string("^ ")) - return Unary_expression::do_import(imp); + return Unary_expression::do_import(imp, loc); else if (c == '(') - return Binary_expression::do_import(imp); + return Binary_expression::do_import(imp, loc); else if (imp->match_c_string("true") || imp->match_c_string("false")) - return Boolean_expression::do_import(imp); + return Boolean_expression::do_import(imp, loc); else if (c == '"') - return String_expression::do_import(imp); + return String_expression::do_import(imp, loc); else if (c == '-' || (c >= '0' && c <= '9')) { // This handles integers, floats and complex constants. - return Integer_expression::do_import(imp); + return Integer_expression::do_import(imp, loc); } else if (imp->match_c_string("nil")) - return Nil_expression::do_import(imp); + return Nil_expression::do_import(imp, loc); else if (imp->match_c_string("convert")) - return Type_conversion_expression::do_import(imp); + return Type_conversion_expression::do_import(imp, loc); else { go_error_at(imp->location(), "import error: expected expression"); - return Expression::make_error(imp->location()); + return Expression::make_error(loc); } } Index: gcc/go/gofrontend/expressions.h =================================================================== --- gcc/go/gofrontend/expressions.h (revision 266523) +++ gcc/go/gofrontend/expressions.h (working copy) @@ -1014,9 +1014,11 @@ class Expression export_expression(Export_function_body* efb) const { this->do_export(efb); } - // Import an expression. + // Import an expression. The location should be used for the + // returned expression. Errors should be reported using the + // Import's location method. static Expression* - import_expression(Import*); + import_expression(Import*, Location); // Return an expression which checks that VAL, of arbitrary integer type, // is non-negative and is not more than the maximum integer value. @@ -1565,7 +1567,7 @@ class String_expression : public Express { return this->val_; } static Expression* - do_import(Import*); + do_import(Import*, Location); protected: bool @@ -1644,7 +1646,7 @@ class Type_conversion_expression : publi // Import a type conversion expression. static Expression* - do_import(Import*); + do_import(Import*, Location); protected: int @@ -1815,7 +1817,7 @@ class Unary_expression : public Expressi Location, Numeric_constant* nc, bool *issued_error); static Expression* - do_import(Import*); + do_import(Import*, Location); // Declare that this deref does or does not require an explicit nil check. void @@ -1964,7 +1966,7 @@ class Binary_expression : public Express bool* result); static Expression* - do_import(Import*); + do_import(Import*, Location); // Report an error if OP can not be applied to TYPE. Return whether // it can. OTYPE is the type of the other operand. Index: gcc/go/gofrontend/gogo.cc =================================================================== --- gcc/go/gofrontend/gogo.cc (revision 266523) +++ gcc/go/gofrontend/gogo.cc (working copy) @@ -7631,7 +7631,7 @@ Named_constant::import_const(Import* imp imp->require_c_string(" "); } imp->require_c_string("= "); - *pexpr = Expression::import_expression(imp); + *pexpr = Expression::import_expression(imp, imp->location()); imp->require_semicolon_if_old_version(); imp->require_c_string("\n"); } Index: gcc/go/gofrontend/statements.h =================================================================== --- gcc/go/gofrontend/statements.h (revision 266517) +++ gcc/go/gofrontend/statements.h (working copy) @@ -338,7 +338,9 @@ class Statement export_statement(Export_function_body* efb) { this->do_export_statement(efb); } - // Read a statement from export data. + // Read a statement from export data. The location should be used + // for the returned statement. Errors should be reported using the + // Import_function_body's location method. static Statement* import_statement(Import_function_body*, Location); Index: gcc/go/gofrontend/types.cc =================================================================== --- gcc/go/gofrontend/types.cc (revision 266523) +++ gcc/go/gofrontend/types.cc (working copy) @@ -6606,7 +6606,8 @@ Struct_type::do_import(Import* imp) if (imp->peek_char() == ' ') { imp->advance(1); - Expression* expr = Expression::import_expression(imp); + Expression* expr = Expression::import_expression(imp, + imp->location()); String_expression* sexpr = expr->string_expression(); go_assert(sexpr != NULL); sf.set_tag(sexpr->val()); @@ -7568,7 +7569,7 @@ Array_type::do_import(Import* imp) if (imp->peek_char() == ']') length = NULL; else - length = Expression::import_expression(imp); + length = Expression::import_expression(imp, imp->location()); imp->require_c_string("] "); Type* element_type = imp->read_type(); return Type::make_array_type(element_type, length);