This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Implement use of static predicates in variants


This patch completes the implementation of statically predicated
subtypes as choices in record variants. The following should
compile quietly in both code generation and -gnatct mode:

     1. package Predicate_Variant is
     2.    type Color is
     3.      (Red, Orange, Yellow, Green, Blue, Indigo, Violet);
     4.
     5.    subtype S1 is Color with
     6.      Predicate => S1 in Orange .. Yellow;
     7.
     8.    subtype S2 is Color with
     9.      Predicate => S2 in Blue .. Blue;
    10.
    11.    subtype Other is Color with
    12.      Predicate => Other not in S1 | S2;
    13.
    14.    type R (D : Color) is record
    15.       case D is
    16.          when S1    => F : Float;
    17.          when S2    => I : Integer;
    18.          when Other => C : Character;
    19.       end case;
    20.    end record;
    21.
    22.    R1 : constant R := (Red    , 'A');
    23.    R2 : constant R := (Orange , 2.0);
    24.    R3 : constant R := (Yellow , 1.0);
    25.    R4 : constant R := (Green  , 'G');
    26.    R5 : constant R := (Blue   , 10);
    27.    R6 : constant R := (Indigo , 'I');
    28.    R7 : constant R := (Violet , 'V');
    29. end Predicate_Variant;

And the following should compile with the indicated errors in both
code generation and -gnatct mode:

     1. PROCEDURE Variant_Errors IS
     2.    SUBTYPE STATCHAR IS CHARACTER RANGE 'I' .. 'N';
     3.    TYPE REC1 (DISC : STATCHAR) IS
     4.       RECORD
     5.          CASE DISC IS
                 |
        >>> missing case value: 'K'
        >>> missing case value: 'N'

     6.             WHEN 'I' => NULL;
     7.             WHEN 'J' => NULL;
     8.             WHEN 'L' => NULL;
     9.             WHEN 'M' => NULL;
    10.          END CASE;
    11.       END RECORD;
    12. BEGIN
    13.    NULL;
    14. end Variant_Errors;

Note: there is one problem left, which will be addressed in a
separate patch, namely we have lost diagnosis of missing cases
etc in generic templates (the erors will appear when the generic
is instantiated, so it's not a major problem).

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

2013-10-10  Robert Dewar  <dewar@adacore.com>

	* freeze.adb (Freeze_Record_Type): Move choice checking to
	Analyze_Freeze_Entity (Freeze_Record_Type): Make sure all choices
	are properly frozen
	* sem_case.adb (Check_Choices): Remove misguided attempt to
	freeze choices (this is now done in Freeze_Record_Type where
	it belongs).
	(Check_Choices): Remove some analyze/resolve calls
	that are redundant since they are done in Analyze_Choices.
	* sem_ch13.adb (Analyze_Freeze_Entity): Do the error
	checking for choices in variant records here (moved here from
	Freeze.Freeze_Record_Type)

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]