Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / ada / par-ch7.adb
blob14fedc93a730e71e897d9943a75fa6410d98f182
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P A R . C H 7 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2010, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 pragma Style_Checks (All_Checks);
27 -- Turn off subprogram body ordering check. Subprograms are in order
28 -- by RM section rather than alphabetical
30 separate (Par)
31 package body Ch7 is
33 ---------------------------------------------
34 -- 7.1 Package (also 8.5.3, 10.1.3, 12.3) --
35 ---------------------------------------------
37 -- This routine scans out a package declaration, package body, or a
38 -- renaming declaration or generic instantiation starting with PACKAGE
40 -- PACKAGE_DECLARATION ::=
41 -- PACKAGE_SPECIFICATION
42 -- [ASPECT_SPECIFICATIONS];
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]
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]
58 -- PACKAGE_RENAMING_DECLARATION ::=
59 -- package DEFINING_IDENTIFIER renames package_NAME;
61 -- PACKAGE_BODY_STUB ::=
62 -- package body DEFINING_IDENTIFIER is separate;
64 -- PACKAGE_INSTANTIATION ::=
65 -- package DEFINING_PROGRAM_UNIT_NAME is
66 -- new generic_package_NAME [GENERIC_ACTUAL_PART]
67 -- [ASPECT_SPECIFICATIONS];
69 -- The value in Pf_Flags indicates which of these possible declarations
70 -- is acceptable to the caller:
72 -- Pf_Flags.Spcn Set if specification OK
73 -- Pf_Flags.Decl Set if declaration OK
74 -- Pf_Flags.Gins Set if generic instantiation OK
75 -- Pf_Flags.Pbod Set if proper body OK
76 -- Pf_Flags.Rnam Set if renaming declaration OK
77 -- Pf_Flags.Stub Set if body stub OK
79 -- If an inappropriate form is encountered, it is scanned out but an error
80 -- message indicating that it is appearing in an inappropriate context is
81 -- issued. The only possible settings for Pf_Flags are those defined as
82 -- constants in package Par.
84 -- Note: in all contexts where a package specification is required, there
85 -- is a terminating semicolon. This semicolon is scanned out in the case
86 -- where Pf_Flags is set to Pf_Spcn, even though it is not strictly part
87 -- of the package specification (it's just too much trouble, and really
88 -- quite unnecessary, to deal with scanning out an END where the semicolon
89 -- after the END is not considered to be part of the END.
91 -- The caller has checked that the initial token is PACKAGE
93 -- Error recovery: cannot raise Error_Resync
95 function P_Package
96 (Pf_Flags : Pf_Rec;
97 Decl : Node_Id := Empty) return Node_Id
99 Package_Node : Node_Id;
100 Specification_Node : Node_Id;
101 Name_Node : Node_Id;
102 Package_Sloc : Source_Ptr;
104 begin
105 Push_Scope_Stack;
106 Scope.Table (Scope.Last).Etyp := E_Name;
107 Scope.Table (Scope.Last).Ecol := Start_Column;
108 Scope.Table (Scope.Last).Lreq := False;
110 Package_Sloc := Token_Ptr;
111 Scan; -- past PACKAGE
113 if Token = Tok_Type then
114 Error_Msg_SC -- CODEFIX
115 ("TYPE not allowed here");
116 Scan; -- past TYPE
117 end if;
119 -- Case of package body. Note that we demand a package body if that
120 -- is the only possibility (even if the BODY keyword is not present)
122 if Token = Tok_Body or else Pf_Flags = Pf_Pbod_Pexp then
123 if not Pf_Flags.Pbod then
124 Error_Msg_SC ("package body cannot appear here!");
125 end if;
127 T_Body;
128 Name_Node := P_Defining_Program_Unit_Name;
129 Scope.Table (Scope.Last).Labl := Name_Node;
130 TF_Is;
132 if Separate_Present then
133 if not Pf_Flags.Stub then
134 Error_Msg_SC ("body stub cannot appear here!");
135 end if;
137 Scan; -- past SEPARATE
138 TF_Semicolon;
139 Pop_Scope_Stack;
141 Package_Node := New_Node (N_Package_Body_Stub, Package_Sloc);
142 Set_Defining_Identifier (Package_Node, Name_Node);
144 else
145 Package_Node := New_Node (N_Package_Body, Package_Sloc);
146 Set_Defining_Unit_Name (Package_Node, Name_Node);
147 Parse_Decls_Begin_End (Package_Node);
148 end if;
150 return Package_Node;
152 -- Cases other than Package_Body
154 else
155 Name_Node := P_Defining_Program_Unit_Name;
156 Scope.Table (Scope.Last).Labl := Name_Node;
158 -- Case of renaming declaration
160 Check_Misspelling_Of (Tok_Renames);
162 if Token = Tok_Renames then
163 if not Pf_Flags.Rnam then
164 Error_Msg_SC ("renaming declaration cannot appear here!");
165 end if;
167 Scan; -- past RENAMES;
169 Package_Node :=
170 New_Node (N_Package_Renaming_Declaration, Package_Sloc);
171 Set_Defining_Unit_Name (Package_Node, Name_Node);
172 Set_Name (Package_Node, P_Qualified_Simple_Name);
174 No_Constraint;
175 TF_Semicolon;
176 Pop_Scope_Stack;
177 return Package_Node;
179 else
180 TF_Is;
182 -- Case of generic instantiation
184 if Token = Tok_New then
185 if not Pf_Flags.Gins then
186 Error_Msg_SC
187 ("generic instantiation cannot appear here!");
188 end if;
190 Scan; -- past NEW
192 Package_Node :=
193 New_Node (N_Package_Instantiation, Package_Sloc);
194 Set_Defining_Unit_Name (Package_Node, Name_Node);
195 Set_Name (Package_Node, P_Qualified_Simple_Name);
196 Set_Generic_Associations
197 (Package_Node, P_Generic_Actual_Part_Opt);
198 P_Aspect_Specifications (Package_Node);
199 Pop_Scope_Stack;
201 -- Case of package declaration or package specification
203 else
204 Specification_Node :=
205 New_Node (N_Package_Specification, Package_Sloc);
207 Set_Defining_Unit_Name (Specification_Node, Name_Node);
208 Set_Visible_Declarations
209 (Specification_Node, P_Basic_Declarative_Items);
211 if Token = Tok_Private then
212 Error_Msg_Col := Scope.Table (Scope.Last).Ecol;
214 if RM_Column_Check then
215 if Token_Is_At_Start_Of_Line
216 and then Start_Column /= Error_Msg_Col
217 then
218 Error_Msg_SC
219 ("(style) PRIVATE in wrong column, should be@");
220 end if;
221 end if;
223 Scan; -- past PRIVATE
224 Set_Private_Declarations
225 (Specification_Node, P_Basic_Declarative_Items);
227 -- Deal gracefully with multiple PRIVATE parts
229 while Token = Tok_Private loop
230 Error_Msg_SC
231 ("only one private part allowed per package");
232 Scan; -- past PRIVATE
233 Append_List (P_Basic_Declarative_Items,
234 Private_Declarations (Specification_Node));
235 end loop;
236 end if;
238 if Pf_Flags = Pf_Spcn then
239 Package_Node := Specification_Node;
240 else
241 Package_Node :=
242 New_Node (N_Package_Declaration, Package_Sloc);
243 Set_Specification (Package_Node, Specification_Node);
244 end if;
246 if Token = Tok_Begin then
247 Error_Msg_SC ("begin block not allowed in package spec");
248 Scan; -- past BEGIN
249 Discard_Junk_List (P_Sequence_Of_Statements (SS_None));
250 end if;
252 if Nkind (Package_Node) = N_Package_Declaration then
253 End_Statements (Specification_Node, Package_Node);
254 else
255 End_Statements (Specification_Node, Decl);
256 end if;
257 end if;
259 return Package_Node;
260 end if;
261 end if;
262 end P_Package;
264 ------------------------------
265 -- 7.1 Package Declaration --
266 ------------------------------
268 -- Parsed by P_Package (7.1)
270 --------------------------------
271 -- 7.1 Package Specification --
272 --------------------------------
274 -- Parsed by P_Package (7.1)
276 -----------------------
277 -- 7.1 Package Body --
278 -----------------------
280 -- Parsed by P_Package (7.1)
282 -----------------------------------
283 -- 7.3 Private Type Declaration --
284 -----------------------------------
286 -- Parsed by P_Type_Declaration (3.2.1)
288 ----------------------------------------
289 -- 7.3 Private Extension Declaration --
290 ----------------------------------------
292 -- Parsed by P_Type_Declaration (3.2.1)
294 end Ch7;