aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_case.ads
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2013-10-10 14:17:35 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2013-10-10 14:17:35 +0200
commit15918371923d3e31a9f74c46fbe94e7e1e6d76e6 (patch)
treecd80a5317c5228f3994e9670042a976f5b3fa86b /gcc/ada/sem_case.ads
parentb184c8f13820b011a119ce9c900b73986f3c5351 (diff)
downloadgcc-15918371923d3e31a9f74c46fbe94e7e1e6d76e6.zip
gcc-15918371923d3e31a9f74c46fbe94e7e1e6d76e6.tar.gz
gcc-15918371923d3e31a9f74c46fbe94e7e1e6d76e6.tar.bz2
[multiple changes]
2013-10-10 Robert Dewar <dewar@adacore.com> * lib-xref-spark_specific.adb, par-ch13.adb, sem_prag.adb, sem_prag.ads, sem_ch12.adb, sem_attr.adb, sem_ch6.adb, sem_ch13.adb, a-sequio.adb, s-atocou-builtin.adb: Minor reformatting. 2013-10-10 Thomas Quinot <quinot@adacore.com> * s-oscons-tmplt.c (NEED_PTHREAD_CONDATTR_SETCLOCK): This constant needs to be output to s-oscons.h, as it is tested by init.c. 2013-10-10 Robert Dewar <dewar@adacore.com> * exp_ch3.adb (Expand_N_Variant_Part): Don't expand choices, too early * exp_ch5.adb (Expand_N_Case_Statement): Use new Has_SP_Choice flag to avoid expanding choices when not necessary. * exp_util.adb: Minor reformatting * freeze.adb (Freeze_Record_Type): Redo expansion of variants * sem_aggr.adb: Minor reformatting * sem_case.ads, sem_case.adb: Major rewrite, separating Analysis and Checking of choices. * sem_ch3.adb (Analyze_Variant_Part): Rewrite to call new Analyze_Choices. * sem_ch4.adb (Analyze_Case_Expression): Call Analyze_Choices and Check_Choices * sem_ch5.adb (Analyze_Case_Statement): Call Analyze_Choices and Check_Choices * sem_util.adb: Minor reformatting * sinfo.ads, sinfo.adb (Has_SP_Choice): New flag. 2013-10-10 Vincent Celier <celier@adacore.com> * mlib-prj.adb (Build_Library): Do not issue link dynamic libraries with an Rpath, if switch -R was used. 2013-10-10 Tristan Gingold <gingold@adacore.com> * s-stalib.ads (Image_Index_Table_8, Image_Index_Table_16, Image_Index_Table_32): Remove as not used. * s-imgint.adb (Image_Integer): Call Set_Image_Integer and remove duplicated code. From-SVN: r203358
Diffstat (limited to 'gcc/ada/sem_case.ads')
-rw-r--r--gcc/ada/sem_case.ads118
1 files changed, 95 insertions, 23 deletions
diff --git a/gcc/ada/sem_case.ads b/gcc/ada/sem_case.ads
index d788afe..c6917f0 100644
--- a/gcc/ada/sem_case.ads
+++ b/gcc/ada/sem_case.ads
@@ -30,52 +30,124 @@
-- aggregate case, since issues with nested aggregates make that case
-- substantially different.
+-- The following processing is required for such cases:
+
+-- 1. Analysis of names of subtypes, constants, expressions appearing within
+-- the choices. This must be done when the construct is encountered to get
+-- proper visibility of names.
+
+-- 2. Checking for semantic correctness of the choices. A lot of this could
+-- be done at the time when the construct is encountered, but not all, since
+-- in the case of variants, statically predicated subtypes won't be frozen
+-- (and the choice sets known) till the enclosing record type is frozen. So
+-- at least the check for no overlaps and covering the range must be delayed
+-- till the freeze point in this case.
+
+-- 3. Set the Others_Discrete_Choices list for an others choice. This is
+-- used in various ways, e.g. to construct the disriminant checking function
+-- for the case of a variant with an others choice.
+
+-- 4. In the case of static predicates, we need to expand out choices that
+-- correspond to the predicate for the back end. This expansion destroys
+-- the list of choices, so it should be delayed to expansion time. We do
+-- not want to mess up the -gnatct ASIS tree, which needs to be able to
+
+-- Step 1 is performed by the generic procedure Analyze_Choices, which is
+-- called when the variant record or case statement/expression is first
+-- encountered.
+
+-- Step 2 is performed by the generic procedure Check_Choices. We decide to
+-- do all semantic checking in that step, since as noted above some of this
+-- has to be deferred to the freeze point in any case for variants. For case
+-- statements and expressions, this procedure can be called at the time the
+-- case construct is encountered (after calling Analyze_Choices).
+
+-- Step 3 is also performed by Check_Choices, since we need the static ranges
+-- for predicated subtypes to accurately construct this.
+
+-- Step 4 is performed by the procedure Expand_Static_Predicates_In_Choices.
+-- For case statements, this call only happens during expansion, so the tree
+-- generated for ASIS does not have this expansion. For the Variant case, the
+-- expansion is done in the ASIS -gnatct case, but with a proper Rewrite call
+-- on the N_Variant node, so ASIS can retrieve the original. The reason we do
+-- the expansion unconditionally for variants is that other processing, for
+-- example for aggregates, relies on having a complete list of choices.
+
+-- Historical note: We used to perform all four of these functions at once in
+-- a single procedure called Analyze_Choices. This routine was called at the
+-- time the construct was first encountered. That seemed to work OK up to Ada
+-- 2005, but the introduction of statically predicated subtypes with delayed
+-- evaluation of the static ranges made this completely wrong, both because
+-- the ASIS tree got destroyed by step 4, and steps 2 and 3 were too early
+-- in the variant record case.
+
with Types; use Types;
package Sem_Case is
procedure No_OP (C : Node_Id);
-- The no-operation routine. Does absolutely nothing. Can be used
- -- in the following generic for the parameter Process_Empty_Choice.
+ -- in the following generics for the parameters Process_Empty_Choice,
+ -- or Process_Associated_Node.
generic
- with function Get_Alternatives (N : Node_Id) return List_Id;
- -- Function used to get the list of case statement alternatives or
- -- record variants, from which we can then access the actual lists of
- -- discrete choices. N is the node for the original construct (case
- -- statement or a record variant).
+ with procedure Process_Associated_Node (A : Node_Id);
+ -- Associated with each case alternative or record variant A there is
+ -- a node or list of nodes that need additional processing. This routine
+ -- implements that processing.
+
+ package Generic_Analyze_Choices is
+
+ procedure Analyze_Choices
+ (Alternatives : List_Id;
+ Subtyp : Entity_Id);
+ -- From a case expression, case statement, or record variant, this
+ -- routine analyzes the corresponding list of discrete choices which
+ -- appear in each element of the list Alternatives (for the variant
+ -- part case, this is the variants, for a case expression or statement,
+ -- this is the Alternatives).
+ --
+ -- Subtyp is the subtype of the discrete choices. The type against which
+ -- the discrete choices must be resolved is its base type.
+ end Generic_Analyze_Choices;
+
+ generic
with procedure Process_Empty_Choice (Choice : Node_Id);
-- Processing to carry out for an empty Choice. Set to No_Op (declared
-- above) if no such processing is required.
with procedure Process_Non_Static_Choice (Choice : Node_Id);
- -- Processing to carry out for a non static Choice
+ -- Processing to carry out for a non static Choice (gives an error msg)
with procedure Process_Associated_Node (A : Node_Id);
-- Associated with each case alternative or record variant A there is
-- a node or list of nodes that need semantic processing. This routine
-- implements that processing.
- package Generic_Choices_Processing is
+ package Generic_Check_Choices is
- procedure Analyze_Choices
- (N : Node_Id;
- Subtyp : Entity_Id;
- Raises_CE : out Boolean;
- Others_Present : out Boolean);
+ procedure Check_Choices
+ (N : Node_Id;
+ Alternatives : List_Id;
+ Subtyp : Entity_Id;
+ Others_Present : out Boolean);
-- From a case expression, case statement, or record variant N, this
- -- routine analyzes the corresponding list of discrete choices. Subtyp
- -- is the subtype of the discrete choices. The type against which the
- -- discrete choices must be resolved is its base type.
+ -- routine analyzes the corresponding list of discrete choices which
+ -- appear in each element of the list Alternatives (for the variant
+ -- part case, this is the variants, for a case expression or statement,
+ -- this is the Alternatives).
--
- -- If one of the bounds of a discrete choice raises a constraint
- -- error the flag Raise_CE is set.
+ -- Subtyp is the subtype of the discrete choices. The type against which
+ -- the discrete choices must be resolved is its base type.
--
- -- Finally Others_Present is set to True if an Others choice is present
- -- in the list of choices, and in this case the call also sets
- -- Others_Discrete_Choices in the N_Others_Choice node.
-
- end Generic_Choices_Processing;
+ -- Others_Present is set to True if an Others choice is present in the
+ -- list of choices, and in this case Others_Discrete_Choices is set in
+ -- the N_Others_Choice node.
+ --
+ -- If a Discrete_Choice list contains at least one instance of a subtype
+ -- with a static predicate, then the Has_SP_Choice flag is set true in
+ -- the parent node (N_Variant, N_Case_Expression/Statement_Alternative).
+ end Generic_Check_Choices;
end Sem_Case;