public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Internal error on iterator for limited private discriminated type
@ 2019-07-22 14:03 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-07-22 14:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: Eric Botcazou

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

This patch further extends the short-circuit, aka optimization, present
in the Check_Constrained_Object procedure used for renaming declarations
to all limited types, so as to prevent type mismatches downstream in
more cases.

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

2019-07-22  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* sem_ch8.adb (Check_Constrained_Object): Further extend the
	special optimization to all limited types.

gcc/testsuite/

	* gnat.dg/iter5.adb, gnat.dg/iter5_pkg.ads: New testcase.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 5371 bytes --]

--- gcc/ada/sem_ch8.adb
+++ gcc/ada/sem_ch8.adb
@@ -809,18 +809,12 @@ package body Sem_Ch8 is
             --  in particular with record types with an access discriminant
             --  that are used in iterators. This is an optimization, but it
             --  also prevents typing anomalies when the prefix is further
-            --  expanded. This also applies to limited types with access
-            --  discriminants.
+            --  expanded.
             --  Note that we cannot just use the Is_Limited_Record flag because
             --  it does not apply to records with limited components, for which
             --  this syntactic flag is not set, but whose size is also fixed.
 
-            elsif (Is_Record_Type (Typ) and then Is_Limited_Type (Typ))
-              or else
-                (Ekind (Typ) = E_Limited_Private_Type
-                  and then Has_Discriminants (Typ)
-                  and then Is_Access_Type (Etype (First_Discriminant (Typ))))
-            then
+            elsif Is_Limited_Type (Typ) then
                null;
 
             else

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/iter5.adb
@@ -0,0 +1,10 @@
+--  { dg-do compile }
+
+with Iter5_Pkg;
+
+procedure Iter5 is
+begin
+   for The_Filename of Iter5_Pkg.Iterator_For ("C:\Program_Files") loop
+      null;
+   end loop;
+end Iter5;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/iter5_pkg.ads
@@ -0,0 +1,127 @@
+with Ada.Calendar;
+with Ada.Directories;
+
+with Ada.Iterator_Interfaces;
+
+package Iter5_Pkg is
+
+  subtype Size is Ada.Directories.File_Size;
+
+  type Folder is new String;
+
+  function Folder_Separator return Character;
+
+  function "+" (Directory : String) return Folder;
+
+  function "+" (Left, Right : String) return Folder;
+
+  function "+" (Left  : Folder;
+                Right : String) return Folder;
+
+  function Composure (Directory : Folder;
+                      Filename  : String;
+                      Extension : String) return String;
+
+  function Composure (Directory : String;
+                      Filename  : String;
+                      Extension : String) return String;
+  -- no exception
+
+  function Base_Name_Of (Name : String) return String
+    renames Ada.Directories.Base_Name;
+
+  function Extension_Of (Name : String) return String
+    renames Ada.Directories.Extension;
+
+  function Containing_Directory_Of (Name : String) return String
+    renames Ada.Directories.Containing_Directory;
+
+  function Exists (Name : String) return Boolean;
+  -- no exception
+
+  function Size_Of (Name : String) return Size renames Ada.Directories.Size;
+
+  function Directory_Exists (Name : String) return Boolean;
+  -- no exception
+
+  function Modification_Time_Of (Name : String) return Ada.Calendar.Time
+    renames Ada.Directories.Modification_Time;
+
+  function Is_Newer (The_Name  : String;
+                     Than_Name : String) return Boolean;
+
+  procedure Delete (Name : String);
+  -- no exception if no existance
+
+  procedure Create_Directory (Path : String);
+  -- creates the whole directory path
+
+  procedure Delete_Directory (Name : String); -- including contents
+  -- no exception if no existance
+
+  procedure Rename (Old_Name : String;
+                    New_Name : String) renames Ada.Directories.Rename;
+
+  procedure Copy (Source_Name   : String;
+                  Target_Name   : String;
+                  Form          : String := "")
+    renames Ada.Directories.Copy_File;
+
+  function Is_Leaf_Directory (Directory : String) return Boolean;
+
+  procedure Iterate_Over_Leaf_Directories (From_Directory : String;
+                                           Iterator : access procedure
+                                             (Leaf_Directory : String));
+
+  function Found_Directory (Simple_Name  : String;
+                            In_Directory : String) return String;
+
+  Not_Found : exception;
+
+  Name_Error : exception renames Ada.Directories.Name_Error;
+  Use_Error  : exception renames Ada.Directories.Use_Error;
+
+  ------------------------
+  -- File Iterator Loop --
+  ------------------------
+  -- Example:
+  --          for The_Filename of Iter5_Pkg.Iterator_For ("C:\Program_Files") loop
+  --            Log.Write (The_Filename);
+  --          end loop;
+
+  type Item (Name_Length : Natural) is limited private;
+
+  function Iterator_For (Name : String) return Item;
+
+private
+  type Cursor;
+
+  function Has_More (Data : Cursor) return Boolean;
+
+  package List_Iterator_Interfaces is
+    new Ada.Iterator_Interfaces (Cursor, Has_More);
+
+  function Iterate (The_Item : Item)
+    return List_Iterator_Interfaces.Forward_Iterator'class;
+
+  type Cursor_Data is record
+    Has_More : Boolean := False;
+    Position : Ada.Directories.Search_Type;
+  end record;
+
+  type Cursor is access all Cursor_Data;
+
+  function Constant_Reference (The_Item     : aliased Item;
+                               Unused_Index : Cursor) return String;
+
+  type Item (Name_Length : Natural) is tagged limited record
+    Name   : String(1..Name_Length);
+    Actual : Ada.Directories.Directory_Entry_Type;
+    Data   : aliased Cursor_Data;
+  end record
+  with
+    Constant_Indexing => Constant_Reference,
+    Default_Iterator  => Iterate,
+    Iterator_Element  => String;
+
+end Iter5_Pkg;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-22 14:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22 14:03 [Ada] Internal error on iterator for limited private discriminated type Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).