From patchwork Wed Dec 15 22:08:46 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 75685 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 9C1601007D6 for ; Thu, 16 Dec 2010 09:09:03 +1100 (EST) Received: (qmail 27894 invoked by alias); 15 Dec 2010 22:08:58 -0000 Received: (qmail 27685 invoked by uid 22791); 15 Dec 2010 22:08:57 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 15 Dec 2010 22:08:52 +0000 Received: from wpaz21.hot.corp.google.com (wpaz21.hot.corp.google.com [172.24.198.85]) by smtp-out.google.com with ESMTP id oBFM8obH002187 for ; Wed, 15 Dec 2010 14:08:50 -0800 Received: from ywe10 (ywe10.prod.google.com [10.192.5.10]) by wpaz21.hot.corp.google.com with ESMTP id oBFM8QoM028193 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT) for ; Wed, 15 Dec 2010 14:08:49 -0800 Received: by ywe10 with SMTP id 10so1510748ywe.38 for ; Wed, 15 Dec 2010 14:08:49 -0800 (PST) Received: by 10.150.225.4 with SMTP id x4mr11158186ybg.104.1292450929152; Wed, 15 Dec 2010 14:08:49 -0800 (PST) Received: from coign.google.com (dhcp-172-22-127-241.mtv.corp.google.com [172.22.127.241]) by mx.google.com with ESMTPS id f73sm999085yhc.4.2010.12.15.14.08.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 15 Dec 2010 14:08:48 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Permit _ as a result variable name Date: Wed, 15 Dec 2010 14:08:46 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true X-IsSubscribed: yes 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 This patch to the Go frontend permits _ as a result variable name. The name _ is special in Go: it means that the object has no name and can not be referenced. This is still meaningful for a result variable, as the return statement will still work. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 912813039662 go/gogo.cc --- a/go/gogo.cc Wed Dec 15 13:48:02 2010 -0800 +++ b/go/gogo.cc Wed Dec 15 14:00:37 2010 -0800 @@ -640,7 +640,7 @@ } } - function->create_named_result_variables(); + function->create_named_result_variables(this); const std::string* pname; std::string nested_name; @@ -2473,7 +2473,7 @@ // Create the named result variables. void -Function::create_named_result_variables() +Function::create_named_result_variables(Gogo* gogo) { const Typed_identifier_list* results = this->type_->results(); if (results == NULL @@ -2490,10 +2490,17 @@ p != results->end(); ++p, ++index) { - Result_variable* result = new Result_variable(p->type(), this, - index); - Named_object* no = block->bindings()->add_result_variable(p->name(), - result); + std::string name = p->name(); + if (Gogo::is_sink_name(name)) + { + static int unnamed_result_counter; + char buf[100]; + snprintf(buf, sizeof buf, "_$%d", unnamed_result_counter); + ++unnamed_result_counter; + name = gogo->pack_hidden_name(buf, false); + } + Result_variable* result = new Result_variable(p->type(), this, index); + Named_object* no = block->bindings()->add_result_variable(name, result); this->named_results_->push_back(no); } } diff -r 912813039662 go/gogo.h --- a/go/gogo.h Wed Dec 15 13:48:02 2010 -0800 +++ b/go/gogo.h Wed Dec 15 14:00:37 2010 -0800 @@ -785,7 +785,7 @@ // Create the named result variables in the outer block. void - create_named_result_variables(); + create_named_result_variables(Gogo*); // Add a new field to the closure variable. void