PR c++/29733
[official-gcc.git] / gcc / ada / sem_case.ads
blobe07e229c8f1c77c22dfd03e60a2825ae2d475f2a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C A S E --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1996-2005, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 -- Package containing the routines to process a list of discrete choices.
28 -- Such lists can occur in two different constructs: case statements and
29 -- record variants. We have factorized what used to be two very similar
30 -- sets of routines in one place. These are not currently used for the
31 -- aggregate case, since issues with nested aggregates make that case
32 -- substantially different.
34 with Types; use Types;
36 package Sem_Case is
38 type Choice_Bounds is record
39 Lo : Node_Id;
40 Hi : Node_Id;
41 Node : Node_Id;
42 end record;
44 type Choice_Table_Type is array (Pos range <>) of Choice_Bounds;
45 -- Table type used to sort the choices present in a case statement,
46 -- array aggregate or record variant.
48 procedure No_OP (C : Node_Id);
49 -- The no-operation routine. Does absolutely nothing. Can be used
50 -- in the following generic for the parameter Proces_Empty_Choice.
52 generic
53 with function Get_Alternatives (N : Node_Id) return List_Id;
54 -- Function needed to get to the actual list of case statement
55 -- alternatives, or array aggregate component associations or
56 -- record variants from which we can then access the actual lists
57 -- of discrete choices. N is the node for the original construct
58 -- ie a case statement, an array aggregate or a record variant.
60 with function Get_Choices (A : Node_Id) return List_Id;
61 -- Given a case statement alternative, array aggregate component
62 -- association or record variant A we need different access functions
63 -- to get to the actual list of discrete choices.
65 with procedure Process_Empty_Choice (Choice : Node_Id);
66 -- Processing to carry out for an empty Choice
68 with procedure Process_Non_Static_Choice (Choice : Node_Id);
69 -- Processing to carry out for a non static Choice
71 with procedure Process_Associated_Node (A : Node_Id);
72 -- Associated to each case alternative, aggregate component
73 -- association or record variant A there is a node or list of nodes
74 -- that need semantic processing. This routine implements that
75 -- processing.
77 package Generic_Choices_Processing is
79 function Number_Of_Choices (N : Node_Id) return Nat;
80 -- Iterates through the choices of N, (N can be a case statement,
81 -- array aggregate or record variant), counting all the Choice nodes
82 -- except for the Others choice.
84 procedure Analyze_Choices
85 (N : Node_Id;
86 Subtyp : Entity_Id;
87 Choice_Table : out Choice_Table_Type;
88 Last_Choice : out Nat;
89 Raises_CE : out Boolean;
90 Others_Present : out Boolean);
91 -- From a case statement, array aggregate or record variant N, this
92 -- routine analyzes the corresponding list of discrete choices.
93 -- Subtyp is the subtype of the discrete choices. The type against
94 -- which the discrete choices must be resolved is its base type.
96 -- On entry Choice_Table must be big enough to contain all the
97 -- discrete choices encountered.
99 -- On exit Choice_Table contains all the static and non empty discrete
100 -- choices in sorted order. Last_Choice gives the position of the last
101 -- valid choice in Choice_Table, Choice_Table'First contains the first.
102 -- We can have Last_Choice < Choice_Table'Last for one (or several) of
103 -- the following reasons:
105 -- (a) The list of choices contained a non static choice
107 -- (b) The list of choices contained an empty choice
108 -- (something like "1 .. 0 => ")
110 -- (c) One of the bounds of a discrete choice contains an
111 -- error or raises constraint error.
113 -- In one of the bounds of a discrete choice raises a constraint
114 -- error the flag Raise_CE is set.
116 -- Finally Others_Present is set to True if an Others choice is present
117 -- in the list of choices, and in this case the call also sets
118 -- Others_Discrete_Choices in the N_Others_Choice node.
120 end Generic_Choices_Processing;
122 end Sem_Case;