OSDN Git Service

Delete all lines containing "$Revision:".
[pf3gnuchains/gcc-fork.git] / gcc / ada / par-ch7.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              P A R . C H 7                               --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                                                                          --
10 --          Copyright (C) 1992-2001 Free Software Foundation, Inc.          --
11 --                                                                          --
12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- GNAT was originally developed  by the GNAT team at  New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 --                                                                          --
26 ------------------------------------------------------------------------------
27
28 pragma Style_Checks (All_Checks);
29 --  Turn off subprogram body ordering check. Subprograms are in order
30 --  by RM section rather than alphabetical
31
32 separate (Par)
33 package body Ch7 is
34
35    ---------------------------------------------
36    -- 7.1  Package (also 8.5.3, 10.1.3, 12.3) --
37    ---------------------------------------------
38
39    --  This routine scans out a package declaration, package body, or a
40    --  renaming declaration or generic instantiation starting with PACKAGE
41
42    --  PACKAGE_DECLARATION ::= PACKAGE_SPECIFICATION;
43
44    --  PACKAGE_SPECIFICATION ::=
45    --    package DEFINING_PROGRAM_UNIT_NAME is
46    --      {BASIC_DECLARATIVE_ITEM}
47    --    [private
48    --      {BASIC_DECLARATIVE_ITEM}]
49    --    end [[PARENT_UNIT_NAME .] IDENTIFIER]
50
51    --  PACKAGE_BODY ::=
52    --    package body DEFINING_PROGRAM_UNIT_NAME is
53    --      DECLARATIVE_PART
54    --    [begin
55    --      HANDLED_SEQUENCE_OF_STATEMENTS]
56    --    end [[PARENT_UNIT_NAME .] IDENTIFIER]
57
58    --  PACKAGE_RENAMING_DECLARATION ::=
59    --    package DEFINING_IDENTIFIER renames package_NAME;
60
61    --  PACKAGE_BODY_STUB ::=
62    --    package body DEFINING_IDENTIFIER is separate;
63
64    --  The value in Pf_Flags indicates which of these possible declarations
65    --  is acceptable to the caller:
66
67    --    Pf_Flags.Spcn                 Set if specification OK
68    --    Pf_Flags.Decl                 Set if declaration OK
69    --    Pf_Flags.Gins                 Set if generic instantiation OK
70    --    Pf_Flags.Pbod                 Set if proper body OK
71    --    Pf_Flags.Rnam                 Set if renaming declaration OK
72    --    Pf_Flags.Stub                 Set if body stub OK
73
74    --  If an inappropriate form is encountered, it is scanned out but an
75    --  error message indicating that it is appearing in an inappropriate
76    --  context is issued. The only possible settings for Pf_Flags are those
77    --  defined as constants in package Par.
78
79    --  Note: in all contexts where a package specification is required, there
80    --  is a terminating semicolon. This semicolon is scanned out in the case
81    --  where Pf_Flags is set to Pf_Spcn, even though it is not strictly part
82    --  of the package specification (it's just too much trouble, and really
83    --  quite unnecessary, to deal with scanning out an END where the semicolon
84    --  after the END is not considered to be part of the END.
85
86    --  The caller has checked that the initial token is PACKAGE
87
88    --  Error recovery: cannot raise Error_Resync
89
90    function P_Package (Pf_Flags : Pf_Rec) return Node_Id is
91       Package_Node       : Node_Id;
92       Specification_Node : Node_Id;
93       Name_Node          : Node_Id;
94       Package_Sloc       : Source_Ptr;
95
96    begin
97       Push_Scope_Stack;
98       Scope.Table (Scope.Last).Etyp := E_Name;
99       Scope.Table (Scope.Last).Ecol := Start_Column;
100       Scope.Table (Scope.Last).Lreq := False;
101
102       Package_Sloc := Token_Ptr;
103       Scan; -- past PACKAGE
104
105       if Token = Tok_Type then
106          Error_Msg_SC ("TYPE not allowed here");
107          Scan; -- past TYPE
108       end if;
109
110       --  Case of package body. Note that we demand a package body if that
111       --  is the only possibility (even if the BODY keyword is not present)
112
113       if Token = Tok_Body or else Pf_Flags = Pf_Pbod then
114          if not Pf_Flags.Pbod then
115             Error_Msg_SC ("package body cannot appear here!");
116          end if;
117
118          T_Body;
119          Name_Node := P_Defining_Program_Unit_Name;
120          Scope.Table (Scope.Last).Labl := Name_Node;
121          TF_Is;
122
123          if Separate_Present then
124             if not Pf_Flags.Stub then
125                Error_Msg_SC ("body stub cannot appear here!");
126             end if;
127
128             Scan; -- past SEPARATE
129             TF_Semicolon;
130             Pop_Scope_Stack;
131
132             Package_Node := New_Node (N_Package_Body_Stub, Package_Sloc);
133             Set_Defining_Identifier (Package_Node, Name_Node);
134
135          else
136             Package_Node := New_Node (N_Package_Body, Package_Sloc);
137             Set_Defining_Unit_Name (Package_Node, Name_Node);
138             Parse_Decls_Begin_End (Package_Node);
139          end if;
140
141          return Package_Node;
142
143       --  Cases other than Package_Body
144
145       else
146          Name_Node := P_Defining_Program_Unit_Name;
147          Scope.Table (Scope.Last).Labl := Name_Node;
148
149          --  Case of renaming declaration
150
151          Check_Misspelling_Of (Tok_Renames);
152
153          if Token = Tok_Renames then
154             if not Pf_Flags.Rnam then
155                Error_Msg_SC ("renaming declaration cannot appear here!");
156             end if;
157
158             Scan; -- past RENAMES;
159
160             Package_Node :=
161               New_Node (N_Package_Renaming_Declaration, Package_Sloc);
162             Set_Defining_Unit_Name (Package_Node, Name_Node);
163             Set_Name (Package_Node, P_Qualified_Simple_Name);
164
165             No_Constraint;
166             TF_Semicolon;
167             Pop_Scope_Stack;
168             return Package_Node;
169
170          else
171             TF_Is;
172
173             --  Case of generic instantiation
174
175             if Token = Tok_New then
176                if not Pf_Flags.Gins then
177                   Error_Msg_SC
178                      ("generic instantiation cannot appear here!");
179                end if;
180
181                Scan; -- past NEW
182
183                Package_Node :=
184                   New_Node (N_Package_Instantiation, Package_Sloc);
185                Set_Defining_Unit_Name (Package_Node, Name_Node);
186                Set_Name (Package_Node, P_Qualified_Simple_Name);
187                Set_Generic_Associations
188                  (Package_Node, P_Generic_Actual_Part_Opt);
189                TF_Semicolon;
190                Pop_Scope_Stack;
191
192             --  Case of package declaration or package specification
193
194             else
195                Specification_Node :=
196                  New_Node (N_Package_Specification, Package_Sloc);
197
198                Set_Defining_Unit_Name (Specification_Node, Name_Node);
199                Set_Visible_Declarations
200                  (Specification_Node, P_Basic_Declarative_Items);
201
202                if Token = Tok_Private then
203                   Error_Msg_Col := Scope.Table (Scope.Last).Ecol;
204
205                   if Style.RM_Column_Check then
206                      if Token_Is_At_Start_Of_Line
207                        and then Start_Column /= Error_Msg_Col
208                      then
209                         Error_Msg_SC
210                           ("(style) PRIVATE in wrong column, should be@");
211                      end if;
212                   end if;
213
214                   Scan; -- past PRIVATE
215                   Set_Private_Declarations
216                     (Specification_Node, P_Basic_Declarative_Items);
217
218                   --  Deal gracefully with multiple PRIVATE parts
219
220                   while Token = Tok_Private loop
221                      Error_Msg_SC
222                        ("only one private part allowed per package");
223                      Scan; -- past PRIVATE
224                      Append_List (P_Basic_Declarative_Items,
225                        Private_Declarations (Specification_Node));
226                   end loop;
227                end if;
228
229                if Pf_Flags = Pf_Spcn then
230                   Package_Node := Specification_Node;
231                else
232                   Package_Node :=
233                     New_Node (N_Package_Declaration, Package_Sloc);
234                   Set_Specification (Package_Node, Specification_Node);
235                end if;
236
237                if Token = Tok_Begin then
238                   Error_Msg_SC ("begin block not allowed in package spec");
239                   Scan; -- past BEGIN
240                   Discard_Junk_List (P_Sequence_Of_Statements (SS_None));
241                end if;
242
243                End_Statements (Specification_Node);
244             end if;
245
246             return Package_Node;
247          end if;
248       end if;
249    end P_Package;
250
251    ------------------------------
252    -- 7.1  Package Declaration --
253    ------------------------------
254
255    --  Parsed by P_Package (7.1)
256
257    --------------------------------
258    -- 7.1  Package Specification --
259    --------------------------------
260
261    --  Parsed by P_Package (7.1)
262
263    -----------------------
264    -- 7.1  Package Body --
265    -----------------------
266
267    --  Parsed by P_Package (7.1)
268
269    -----------------------------------
270    -- 7.3  Private Type Declaration --
271    -----------------------------------
272
273    --  Parsed by P_Type_Declaration (3.2.1)
274
275    ----------------------------------------
276    -- 7.3  Private Extension Declaration --
277    ----------------------------------------
278
279    --  Parsed by P_Type_Declaration (3.2.1)
280
281 end Ch7;