Previously all rep clauses were ignored in -gnatI mode, but in two
cases (enumeration rep clauses and record rep clauses), they were
not removed from the tree, causing trouble with ASIS tools. These
two cases are now consistent, and ASIS tools will see none of the
ignored rep clauses (e.g. gnatpp will not list ignored rep clauses).

The following test generates no output if compiled with

gcc -c ignorei.ads -gnatI -gnatG >log
grep 35 log

     1. package IgnoreI is
     2.    type R is record
     3.       X : Integer;
     4.    end record;
     5.    for R use record
     6.       X at 0 range 0 .. 35;
     7.    end record;
     8.    type E is (a,b,c);
     9.    for E use (0,1,35);
    10. end IgnoreI;

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-07-18  Robert Dewar  <de...@adacore.com>

        * freeze.adb (Check_Address_Clause): Use Kill_Rep_Clause (no
        functional change).
        * gnat_ugn.texi: Document that -gnatI removes rep clauses from
        ASIS trees.
        * sem_ch13.adb (Kill_Rep_Clause): New procedure
        (Analyze_Attribute_Definition_Clause): Use
        Kill_Rep_Clause. This is just a cleanup, no functional effect.
        (Analyze_Enumeration_Representation_Clause):
        Use Kill_Rep_Clause. This means that enum rep
        clauses are now properly removed from -gnatct trees.
        (Analyze_Record_Representation_Clause): Same change.
        * sem_ch13.ads (Kill_Rep_Clause): New procedure.

Index: gnat_ugn.texi
===================================================================
--- gnat_ugn.texi       (revision 212782)
+++ gnat_ugn.texi       (working copy)
@@ -4091,6 +4091,12 @@
 Note that this option should be used only for compiling -- the
 code is likely to malfunction at run time.
 
+Note that when @code{-gnatct} is used to generate trees for input
+into @code{ASIS} tools, these representation clauses are removed
+from the tree. This means that the tool will not see them. For
+example, if you use @command{gnatpp} with @code{-gnatI}, the pretty printed
+output will not include the ignored representation clauses.
+
 @item -gnatjnn
 @cindex @option{-gnatjnn} (@command{gcc})
 Reformat error messages to fit on nn character lines
Index: freeze.adb
===================================================================
--- freeze.adb  (revision 212737)
+++ freeze.adb  (working copy)
@@ -604,8 +604,10 @@
                end if;
             end;
 
-            Rewrite (Addr, Make_Null_Statement (Sloc (E)));
+            --  And now remove the address clause
 
+            Kill_Rep_Clause (Addr);
+
          elsif not Error_Posted (Expr)
            and then not Needs_Finalization (Typ)
          then
Index: sem_ch13.adb
===================================================================
--- sem_ch13.adb        (revision 212782)
+++ sem_ch13.adb        (working copy)
@@ -3647,19 +3647,12 @@
                  Attribute_Machine_Radix  |
                  Attribute_Object_Size    |
                  Attribute_Size           |
+                 Attribute_Small          |
                  Attribute_Stream_Size    |
                  Attribute_Value_Size     =>
-               Rewrite (N, Make_Null_Statement (Sloc (N)));
+               Kill_Rep_Clause (N);
                return;
 
-            --  Perhaps 'Small should not be ignored by Ignore_Rep_Clauses ???
-
-            when Attribute_Small =>
-               if Ignore_Rep_Clauses then
-                  Rewrite (N, Make_Null_Statement (Sloc (N)));
-                  return;
-               end if;
-
             --  The following should not be ignored, because in the first place
             --  they are reasonably portable, and should not cause problems in
             --  compiling code from another target, and also they do affect
@@ -3676,6 +3669,13 @@
                  Attribute_Write               =>
                null;
 
+            --  We do not do anything here with address clauses, they will be
+            --  removed by Freeze later on, but for now, it works better to
+            --  keep then in the tree.
+
+            when Attribute_Address =>
+               null;
+
             --  Other cases are errors ("attribute& cannot be set with
             --  definition clause"), which will be caught below.
 
@@ -3830,7 +3830,7 @@
 
             --  Even when ignoring rep clauses we need to indicate that the
             --  entity has an address clause and thus it is legal to declare
-            --  it imported.
+            --  it imported. Freeze will get rid of the address clause later.
 
             if Ignore_Rep_Clauses then
                if Ekind_In (U_Ent, E_Variable, E_Constant) then
@@ -5365,6 +5365,7 @@
 
    begin
       if Ignore_Rep_Clauses then
+         Kill_Rep_Clause (N);
          return;
       end if;
 
@@ -5740,6 +5741,7 @@
 
    begin
       if Ignore_Rep_Clauses then
+         Kill_Rep_Clause (N);
          return;
       end if;
 
@@ -10286,6 +10288,16 @@
       end if;
    end Is_Operational_Item;
 
+   ---------------------
+   -- Kill_Rep_Clause --
+   ---------------------
+
+   procedure Kill_Rep_Clause (N : Node_Id) is
+   begin
+      pragma Assert (Ignore_Rep_Clauses);
+      Rewrite (N, Make_Null_Statement (Sloc (N)));
+   end Kill_Rep_Clause;
+
    ------------------
    -- Minimum_Size --
    ------------------
Index: sem_ch13.ads
===================================================================
--- sem_ch13.ads        (revision 212640)
+++ sem_ch13.ads        (working copy)
@@ -79,6 +79,11 @@
    procedure Initialize;
    --  Initialize internal tables for new compilation
 
+   procedure Kill_Rep_Clause (N : Node_Id);
+   --  This procedure is called for a rep clause N when we are in -gnatI mode
+   --  (Ignore_Rep_Clauses). It rewrites the node N to a null statement. This
+   --  is only called if Ignore_Rep_Clauses is True.
+
    procedure Set_Enum_Esize (T : Entity_Id);
    --  This routine sets the Esize field for an enumeration type T, based
    --  on the current representation information available for T. Note that

Reply via email to