annotate gcc/ada/sem_case.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S E M _ C A S E --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1996-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- Package containing the routines to process a list of discrete choices.
kono
parents:
diff changeset
27 -- Such lists can occur in two different constructs: case statements and
kono
parents:
diff changeset
28 -- record variants. We have factorized what used to be two very similar
kono
parents:
diff changeset
29 -- sets of routines in one place. These are not currently used for the
kono
parents:
diff changeset
30 -- aggregate case, since issues with nested aggregates make that case
kono
parents:
diff changeset
31 -- substantially different.
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 -- The following processing is required for such cases:
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 -- 1. Analysis of names of subtypes, constants, expressions appearing within
kono
parents:
diff changeset
36 -- the choices. This must be done when the construct is encountered to get
kono
parents:
diff changeset
37 -- proper visibility of names.
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 -- 2. Checking for semantic correctness of the choices. A lot of this could
kono
parents:
diff changeset
40 -- be done at the time when the construct is encountered, but not all, since
kono
parents:
diff changeset
41 -- in the case of variants, statically predicated subtypes won't be frozen
kono
parents:
diff changeset
42 -- (and the choice sets known) till the enclosing record type is frozen. So
kono
parents:
diff changeset
43 -- at least the check for no overlaps and covering the range must be delayed
kono
parents:
diff changeset
44 -- till the freeze point in this case.
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 -- 3. Set the Others_Discrete_Choices list for an others choice. This is
kono
parents:
diff changeset
47 -- used in various ways, e.g. to construct the disriminant checking function
kono
parents:
diff changeset
48 -- for the case of a variant with an others choice.
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 -- 4. In the case of static predicates, we need to expand out choices that
kono
parents:
diff changeset
51 -- correspond to the predicate for the back end. This expansion destroys
kono
parents:
diff changeset
52 -- the list of choices, so it should be delayed to expansion time. We do
kono
parents:
diff changeset
53 -- not want to mess up the -gnatct ASIS tree, which needs to be able to
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 -- Step 1 is performed by the generic procedure Analyze_Choices, which is
kono
parents:
diff changeset
56 -- called when the variant record or case statement/expression is first
kono
parents:
diff changeset
57 -- encountered.
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 -- Step 2 is performed by the generic procedure Check_Choices. We decide to
kono
parents:
diff changeset
60 -- do all semantic checking in that step, since as noted above some of this
kono
parents:
diff changeset
61 -- has to be deferred to the freeze point in any case for variants. For case
kono
parents:
diff changeset
62 -- statements and expressions, this procedure can be called at the time the
kono
parents:
diff changeset
63 -- case construct is encountered (after calling Analyze_Choices).
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 -- Step 3 is also performed by Check_Choices, since we need the static ranges
kono
parents:
diff changeset
66 -- for predicated subtypes to accurately construct this.
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 -- Step 4 is performed by the procedure Expand_Static_Predicates_In_Choices.
kono
parents:
diff changeset
69 -- For case statements, this call only happens during expansion, so the tree
kono
parents:
diff changeset
70 -- generated for ASIS does not have this expansion. For the Variant case, the
kono
parents:
diff changeset
71 -- expansion is done in the ASIS -gnatct case, but with a proper Rewrite call
kono
parents:
diff changeset
72 -- on the N_Variant node, so ASIS can retrieve the original. The reason we do
kono
parents:
diff changeset
73 -- the expansion unconditionally for variants is that other processing, for
kono
parents:
diff changeset
74 -- example for aggregates, relies on having a complete list of choices.
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 -- Historical note: We used to perform all four of these functions at once in
kono
parents:
diff changeset
77 -- a single procedure called Analyze_Choices. This routine was called at the
kono
parents:
diff changeset
78 -- time the construct was first encountered. That seemed to work OK up to Ada
kono
parents:
diff changeset
79 -- 2005, but the introduction of statically predicated subtypes with delayed
kono
parents:
diff changeset
80 -- evaluation of the static ranges made this completely wrong, both because
kono
parents:
diff changeset
81 -- the ASIS tree got destroyed by step 4, and steps 2 and 3 were too early
kono
parents:
diff changeset
82 -- in the variant record case.
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 with Types; use Types;
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 package Sem_Case is
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 procedure No_OP (C : Node_Id);
kono
parents:
diff changeset
89 -- The no-operation routine. Does mostly nothing. Can be used
kono
parents:
diff changeset
90 -- in the following generics for the parameters Process_Empty_Choice,
kono
parents:
diff changeset
91 -- or Process_Associated_Node. In the case of an empty range choice,
kono
parents:
diff changeset
92 -- routine emits a warning when Warn_On_Redundant_Constructs is enabled.
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 generic
kono
parents:
diff changeset
95 with procedure Process_Associated_Node (A : Node_Id);
kono
parents:
diff changeset
96 -- Associated with each case alternative or record variant A there is
kono
parents:
diff changeset
97 -- a node or list of nodes that need additional processing. This routine
kono
parents:
diff changeset
98 -- implements that processing.
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 package Generic_Analyze_Choices is
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 procedure Analyze_Choices
kono
parents:
diff changeset
103 (Alternatives : List_Id;
kono
parents:
diff changeset
104 Subtyp : Entity_Id);
kono
parents:
diff changeset
105 -- From a case expression, case statement, or record variant, this
kono
parents:
diff changeset
106 -- routine analyzes the corresponding list of discrete choices which
kono
parents:
diff changeset
107 -- appear in each element of the list Alternatives (for the variant
kono
parents:
diff changeset
108 -- part case, this is the variants, for a case expression or statement,
kono
parents:
diff changeset
109 -- this is the Alternatives).
kono
parents:
diff changeset
110 --
kono
parents:
diff changeset
111 -- Subtyp is the subtype of the discrete choices. The type against which
kono
parents:
diff changeset
112 -- the discrete choices must be resolved is its base type.
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 end Generic_Analyze_Choices;
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 generic
kono
parents:
diff changeset
117 with procedure Process_Empty_Choice (Choice : Node_Id);
kono
parents:
diff changeset
118 -- Processing to carry out for an empty Choice. Set to No_Op (declared
kono
parents:
diff changeset
119 -- above) if no such processing is required.
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 with procedure Process_Non_Static_Choice (Choice : Node_Id);
kono
parents:
diff changeset
122 -- Processing to carry out for a non static Choice (gives an error msg)
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 with procedure Process_Associated_Node (A : Node_Id);
kono
parents:
diff changeset
125 -- Associated with each case alternative or record variant A there is
kono
parents:
diff changeset
126 -- a node or list of nodes that need semantic processing. This routine
kono
parents:
diff changeset
127 -- implements that processing.
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 package Generic_Check_Choices is
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 procedure Check_Choices
kono
parents:
diff changeset
132 (N : Node_Id;
kono
parents:
diff changeset
133 Alternatives : List_Id;
kono
parents:
diff changeset
134 Subtyp : Entity_Id;
kono
parents:
diff changeset
135 Others_Present : out Boolean);
kono
parents:
diff changeset
136 -- From a case expression, case statement, or record variant N, this
kono
parents:
diff changeset
137 -- routine analyzes the corresponding list of discrete choices which
kono
parents:
diff changeset
138 -- appear in each element of the list Alternatives (for the variant
kono
parents:
diff changeset
139 -- part case, this is the variants, for a case expression or statement,
kono
parents:
diff changeset
140 -- this is the Alternatives).
kono
parents:
diff changeset
141 --
kono
parents:
diff changeset
142 -- Subtyp is the subtype of the discrete choices. The type against which
kono
parents:
diff changeset
143 -- the discrete choices must be resolved is its base type.
kono
parents:
diff changeset
144 --
kono
parents:
diff changeset
145 -- Others_Present is set to True if an Others choice is present in the
kono
parents:
diff changeset
146 -- list of choices, and in this case Others_Discrete_Choices is set in
kono
parents:
diff changeset
147 -- the N_Others_Choice node.
kono
parents:
diff changeset
148 --
kono
parents:
diff changeset
149 -- If a Discrete_Choice list contains at least one instance of a subtype
kono
parents:
diff changeset
150 -- with a static predicate, then the Has_SP_Choice flag is set true in
kono
parents:
diff changeset
151 -- the parent node (N_Variant, N_Case_Expression/Statement_Alternative).
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 end Generic_Check_Choices;
kono
parents:
diff changeset
154 end Sem_Case;