From patchwork Mon Jun 21 14:53:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 56323 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 20C68B6F07 for ; Tue, 22 Jun 2010 00:53:20 +1000 (EST) Received: (qmail 24727 invoked by alias); 21 Jun 2010 14:53:19 -0000 Received: (qmail 24710 invoked by uid 22791); 21 Jun 2010 14:53:17 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, TW_TX, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 21 Jun 2010 14:53:08 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5LEr6iB006156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 21 Jun 2010 10:53:07 -0400 Received: from redhat.com (vpn-9-210.rdu.redhat.com [10.11.9.210]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5LEr3Lv009112 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 21 Jun 2010 10:53:06 -0400 Date: Mon, 21 Jun 2010 10:53:03 -0400 From: Aldy Hernandez To: rth@redhat.com, gcc-patches@gcc.gnu.org Subject: [trans-mem] add support for C++ transaction expressions Message-ID: <20100621145301.GA10641@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) 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 Hi. This patch adds transaction expression support for C++. No test, because there's already a common one here: testsuite/c-c++-common/tm/trxn-expr.c OK for branch? * cp/parser.c (cp_parser_unary_expression): Handle RID_TRANSACTION. (cp_parser_transaction_expression): New. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 160538) +++ cp/parser.c (working copy) @@ -1893,6 +1893,8 @@ static void cp_parser_label_declaration static tree cp_parser_transaction (cp_parser *); +static tree cp_parser_transaction_expression + (cp_parser *); static bool cp_parser_function_transaction (cp_parser *); static tree cp_parser_transaction_cancel @@ -5582,6 +5584,9 @@ cp_parser_unary_expression (cp_parser *p } break; + case RID_TRANSACTION: + return cp_parser_transaction_expression (parser); + default: break; } @@ -23058,6 +23063,55 @@ cp_parser_transaction (cp_parser *parser return stmt; } +/* Parse a __transaction expression. + + transaction-expression: + __transaction txn-attribute[opt] txn-exception-spec[opt] + compound-statement + + ??? The exception specification is not yet implemented. +*/ + +static tree +cp_parser_transaction_expression (cp_parser *parser) +{ + unsigned char old_in = parser->in_transaction; + unsigned char this_in = 1; + cp_token *token; + tree ret, attrs; + + token = cp_parser_require_keyword (parser, RID_TRANSACTION, + "%<__transaction%>"); + gcc_assert (token != NULL); + + attrs = cp_parser_txn_attribute_opt (parser); + if (attrs) + { + this_in |= parse_tm_stmt_attr (attrs, (TM_STMT_ATTR_ATOMIC + | TM_STMT_ATTR_RELAXED)); + /* The [[ atomic ]] attribute is the same as no attribute. */ + this_in &= ~TM_STMT_ATTR_ATOMIC; + } + + parser->in_transaction = this_in; + if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN)) + { + tree expr = cp_parser_expression (parser, /*cast_p=*/false, NULL); + ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr); + if (this_in & TM_STMT_ATTR_RELAXED) + TRANSACTION_EXPR_RELAXED (ret) = 1; + SET_EXPR_LOCATION (ret, token->location); + } + else + { + cp_parser_error (parser, "expected %<(%>"); + ret = error_mark_node; + } + parser->in_transaction = old_in; + + return ret; +} + /* Parse a function-transaction-block. function-transaction-block: