diff mbox

[Ada] Qualified expressions and Code statements in Ada 2012

Message ID 20111013103508.GA2147@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 13, 2011, 10:35 a.m. UTC
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  <schonberg@adacore.com>

	* 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.
diff mbox

Patch

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)