From patchwork Thu Oct 13 10:35:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 119408 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 C2EABB6F86 for ; Thu, 13 Oct 2011 21:35:27 +1100 (EST) Received: (qmail 25605 invoked by alias); 13 Oct 2011 10:35:24 -0000 Received: (qmail 25503 invoked by uid 22791); 13 Oct 2011 10:35:22 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,TW_TM X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 13 Oct 2011 10:35:09 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5BE922BAFA2; Thu, 13 Oct 2011 06:35:08 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id iWv5NWEApQ-E; Thu, 13 Oct 2011 06:35:08 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 4968D2BAF99; Thu, 13 Oct 2011 06:35:08 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 48AAA92BF6; Thu, 13 Oct 2011 06:35:08 -0400 (EDT) Date: Thu, 13 Oct 2011 06:35:08 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Qualified expressions and Code statements in Ada 2012 Message-ID: <20111013103508.GA2147@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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 In Ada 2012 a qualified expression is a valid name, and for example a function call that is disambiguated by means of a qualification can appear in the place of a constant object. On the other hand A qualified expression that appears as a statement denotes a machine code insertion. With the new rule, a qualified expression by itself is parsed as a parameterless procedure call, and must be rewritten and analyzed as a code statement. The following must compile quietly: gcc -c -gnat12 -gnatws code_statement.adb --- WITH MACHINE_CODE; -- N/A => ERROR. USE MACHINE_CODE; PROCEDURE code_statement IS PROCEDURE CODE IS BEGIN Asm_Insn'(Asm ("nop")); END; BEGIN CODE; END code_statement; Tested on x86_64-pc-linux-gnu, committed on trunk 2011-10-13 Ed Schonberg * sem_ch6.adb (Analyze_Procedure_Call_Statement): In Ada 2012 mode, if the prefix of the call is a qualified expression, rewrite as a code statement. * sem_ch13.adb (Analyze_Code_Statement): In Ada 2012 mode, the code statement is legal if it is a rewriting of a procedure call. Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 179894) +++ sem_ch6.adb (working copy) @@ -1340,6 +1340,15 @@ Analyze (P); Analyze_Call_And_Resolve; + -- In Ada 2012. a qualified expression is a name, but it cannot be a + -- procedure name, so the construct can only be a qualified expression. + + elsif Nkind (P) = N_Qualified_Expression + and then Ada_Version >= Ada_2012 + then + Rewrite (N, Make_Code_Statement (Loc, Expression => P)); + Analyze (N); + -- Anything else is an error else Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 179894) +++ sem_ch13.adb (working copy) @@ -3364,11 +3364,19 @@ -- No statements other than code statements, pragmas, and labels. -- Again we allow certain internally generated statements. + -- In Ada 2012, qualified expressions are names, and the code + -- statement is initially parsed as a procedure call. Stmt := First (Statements (HSS)); while Present (Stmt) loop StmtO := Original_Node (Stmt); - if Comes_From_Source (StmtO) + + if Ada_Version >= Ada_2012 + and then Nkind (StmtO) = N_Procedure_Call_Statement + then + null; + + elsif Comes_From_Source (StmtO) and then not Nkind_In (StmtO, N_Pragma, N_Label, N_Code_Statement)