PR c++/3637
[official-gcc.git] / gcc / ada / sem_case.ads
blobc1f172bcd52b135ae9cc1768726dddb04bc433df
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C A S E --
6 -- --
7 -- S p e c --
8 -- --
9 -- $Revision: 1.1 $ --
10 -- --
11 -- Copyright (C) 1996 Free Software Foundation, Inc. --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 -- --
27 ------------------------------------------------------------------------------
29 with Types; use Types;
31 -- Package containing all the routines to process a list of discrete choices.
32 -- Such lists can occur in 3 different constructs: case statements, array
33 -- aggregates and record variants. We have factorized what used to be 3 very
34 -- similar sets of routines here. If you didn't figure it out already Choi
35 -- in the package name stands for Choices.
37 package Sem_Case is
39 type Choice_Bounds is record
40 Lo : Node_Id;
41 Hi : Node_Id;
42 Node : Node_Id;
43 end record;
45 type Choice_Table_Type is array (Pos range <>) of Choice_Bounds;
46 -- Table type used to sort the choices present in a case statement,
47 -- array aggregate or record variant.
49 procedure No_OP (C : Node_Id);
50 -- The no-operation routine. Does absolutely nothing. Can be used
51 -- in the following generic for the parameter Proces_Empty_Choice.
53 generic
54 with function Get_Alternatives (N : Node_Id) return List_Id;
55 -- Function needed to get to the actual list of case statement
56 -- alternatives, or array aggregate component associations or
57 -- record variants from which we can then access the actual lists
58 -- of discrete choices. N is the node for the original construct
59 -- ie a case statement, an array aggregate or a record variant.
61 with function Get_Choices (A : Node_Id) return List_Id;
62 -- Given a case statement alternative, array aggregate component
63 -- association or record variant A we need different access functions
64 -- to get to the actual list of discrete choices.
66 with procedure Process_Empty_Choice (Choice : Node_Id);
67 -- Processing to carry out for an empty Choice.
69 with procedure Process_Non_Static_Choice (Choice : Node_Id);
70 -- Processing to carry out for a non static Choice.
72 with procedure Process_Associated_Node (A : Node_Id);
73 -- Associated to each case alternative, aggregate component
74 -- association or record variant A there is a node or list of nodes
75 -- that need semantic processing. This routine implements that
76 -- processing.
78 package Generic_Choices_Processing is
80 function Number_Of_Choices (N : Node_Id) return Nat;
81 -- Iterates through the choices of N, (N can be a case statement,
82 -- array aggregate or record variant), counting all the Choice nodes
83 -- except for the Others choice.
85 procedure Analyze_Choices
86 (N : Node_Id;
87 Subtyp : Entity_Id;
88 Choice_Table : in out Choice_Table_Type;
89 Last_Choice : out Nat;
90 Raises_CE : out Boolean;
91 Others_Present : out Boolean);
92 -- From a case statement, array aggregate or record variant N, this
93 -- routine analyzes the corresponding list of discrete choices.
94 -- Subtyp is the subtype of the discrete choices. The type against
95 -- which the discrete choices must be resolved is its base type.
97 -- On entry Choice_Table must be big enough to contain all the
98 -- discrete choices encountered.
100 -- On exit Choice_Table contains all the static and non empty
101 -- discrete choices in sorted order. Last_Choice gives the position
102 -- of the last valid choice in Choice_Table, Choice_Table'First
103 -- contains the first. We can have Last_Choice < Choice_Table'Last
104 -- for one (or several) of the following reasons:
106 -- (a) The list of choices contained a non static choice
108 -- (b) The list of choices contained an empty choice
109 -- (something like "1 .. 0 => ")
111 -- (c) One of the bounds of a discrete choice contains an
112 -- error or raises constraint error.
114 -- In one of the bounds of a discrete choice raises a constraint
115 -- error the flag Raise_CE is set.
117 -- Finally Others_Present is set to True if an Others choice is
118 -- present in the list of choices.
120 end Generic_Choices_Processing;
122 end Sem_Case;