| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- P A R . C H 3 -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, 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 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
pragma Style_Checks (All_Checks); |
| 27 |
-- Turn off subprogram body ordering check. Subprograms are in order |
| 28 |
-- by RM section rather than alphabetical. |
| 29 |
|
| 30 |
with Sinfo.CN; use Sinfo.CN; |
| 31 |
|
| 32 |
separate (Par) |
| 33 |
|
| 34 |
--------- |
| 35 |
-- Ch3 -- |
| 36 |
--------- |
| 37 |
|
| 38 |
package body Ch3 is |
| 39 |
|
| 40 |
----------------------- |
| 41 |
-- Local Subprograms -- |
| 42 |
----------------------- |
| 43 |
|
| 44 |
function P_Component_List return Node_Id; |
| 45 |
function P_Defining_Character_Literal return Node_Id; |
| 46 |
function P_Delta_Constraint return Node_Id; |
| 47 |
function P_Derived_Type_Def_Or_Private_Ext_Decl return Node_Id; |
| 48 |
function P_Digits_Constraint return Node_Id; |
| 49 |
function P_Discriminant_Association return Node_Id; |
| 50 |
function P_Enumeration_Literal_Specification return Node_Id; |
| 51 |
function P_Enumeration_Type_Definition return Node_Id; |
| 52 |
function P_Fixed_Point_Definition return Node_Id; |
| 53 |
function P_Floating_Point_Definition return Node_Id; |
| 54 |
function P_Index_Or_Discriminant_Constraint return Node_Id; |
| 55 |
function P_Real_Range_Specification_Opt return Node_Id; |
| 56 |
function P_Subtype_Declaration return Node_Id; |
| 57 |
function P_Type_Declaration return Node_Id; |
| 58 |
function P_Modular_Type_Definition return Node_Id; |
| 59 |
function P_Variant return Node_Id; |
| 60 |
function P_Variant_Part return Node_Id; |
| 61 |
|
| 62 |
procedure Check_Restricted_Expression (N : Node_Id); |
| 63 |
-- Check that the expression N meets the Restricted_Expression syntax. |
| 64 |
-- The syntax is as follows: |
| 65 |
-- |
| 66 |
-- RESTRICTED_EXPRESSION ::= |
| 67 |
-- RESTRICTED_RELATION {and RESTRICTED_RELATION} |
| 68 |
-- | RESTRICTED_RELATION {and then RESTRICTED_RELATION} |
| 69 |
-- | RESTRICTED_RELATION {or RESTRICTED_RELATION} |
| 70 |
-- | RESTRICTED_RELATION {or else RESTRICTED_RELATION} |
| 71 |
-- | RESTRICTED_RELATION {xor RESTRICTED_RELATION} |
| 72 |
-- |
| 73 |
-- RESTRICTED_RELATION ::= |
| 74 |
-- SIMPLE_EXPRESSION [RELATIONAL_OPERATOR SIMPLE_EXPRESSION] |
| 75 |
-- |
| 76 |
-- This syntax is used for choices when extensions (and set notations) |
| 77 |
-- are enabled, to remove the ambiguity of "when X in A | B". We consider |
| 78 |
-- it very unlikely that this will ever arise in practice. |
| 79 |
|
| 80 |
procedure P_Declarative_Item |
| 81 |
(Decls : List_Id; |
| 82 |
Done : out Boolean; |
| 83 |
Declare_Expression : Boolean; |
| 84 |
In_Spec : Boolean; |
| 85 |
In_Statements : Boolean); |
| 86 |
-- Parses a single declarative item. The parameters have the same meaning |
| 87 |
-- as for P_Declarative_Items. If the declarative item has multiple |
| 88 |
-- identifiers, as in "X, Y, Z : ...", then one declaration is appended to |
| 89 |
-- Decls for each of the identifiers. |
| 90 |
|
| 91 |
procedure P_Identifier_Declarations |
| 92 |
(Decls : List_Id; |
| 93 |
Done : out Boolean; |
| 94 |
In_Spec : Boolean; |
| 95 |
In_Statements : Boolean); |
| 96 |
-- Parses a sequence of declarations for an identifier or list of |
| 97 |
-- identifiers, and appends them to the given list. The parameters |
| 98 |
-- have the same meaning as for P_Declarative_Items. |
| 99 |
|
| 100 |
procedure Statement_When_Declaration_Expected |
| 101 |
(Decls : List_Id; |
| 102 |
Done : out Boolean; |
| 103 |
In_Spec : Boolean); |
| 104 |
-- Called when a statement is found at a point where a declaration was |
| 105 |
-- expected. The parameters have the same meaning as for |
| 106 |
-- P_Declarative_Items. |
| 107 |
|
| 108 |
procedure Set_Declaration_Expected; |
| 109 |
-- Posts a "declaration expected" error messages at the start of the |
| 110 |
-- current token, and if this is the first such message issued, saves |
| 111 |
-- the message id in Missing_Begin_Msg, for possible later replacement. |
| 112 |
|
| 113 |
--------------------------------- |
| 114 |
-- Check_Restricted_Expression -- |
| 115 |
--------------------------------- |
| 116 |
|
| 117 |
procedure Check_Restricted_Expression (N : Node_Id) is |
| 118 |
begin |
| 119 |
if Nkind (N) in N_Op_And | N_Op_Or | N_Op_Xor | N_And_Then | N_Or_Else |
| 120 |
then |
| 121 |
Check_Restricted_Expression (Left_Opnd (N)); |
| 122 |
Check_Restricted_Expression (Right_Opnd (N)); |
| 123 |
|
| 124 |
elsif Nkind (N) in N_In | N_Not_In |
| 125 |
and then Paren_Count (N) = 0 |
| 126 |
then |
| 127 |
Error_Msg_N ("|this expression must be parenthesized!", N); |
| 128 |
end if; |
| 129 |
end Check_Restricted_Expression; |
| 130 |
|
| 131 |
------------------- |
| 132 |
-- Init_Expr_Opt -- |
| 133 |
------------------- |
| 134 |
|
| 135 |
function Init_Expr_Opt (P : Boolean := False) return Node_Id is |
| 136 |
begin |
| 137 |
-- For colon, assume it means := unless it is at the end of |
| 138 |
-- a line, in which case guess that it means a semicolon. |
| 139 |
|
| 140 |
if Token = Tok_Colon then |
| 141 |
if Token_Is_At_End_Of_Line then |
| 142 |
T_Semicolon; |
| 143 |
return Empty; |
| 144 |
end if; |
| 145 |
|
| 146 |
-- Here if := or something that we will take as equivalent |
| 147 |
|
| 148 |
elsif Token in Tok_Colon_Equal | Tok_Equal | Tok_Is then |
| 149 |
null; |
| 150 |
|
| 151 |
-- Another possibility. If we have a literal followed by a semicolon, |
| 152 |
-- we assume that we have a missing colon-equal. |
| 153 |
|
| 154 |
elsif Token in Token_Class_Literal then |
| 155 |
declare |
| 156 |
Scan_State : Saved_Scan_State; |
| 157 |
|
| 158 |
begin |
| 159 |
Save_Scan_State (Scan_State); |
| 160 |
Scan; -- past literal or identifier |
| 161 |
|
| 162 |
if Token = Tok_Semicolon then |
| 163 |
Restore_Scan_State (Scan_State); |
| 164 |
else |
| 165 |
Restore_Scan_State (Scan_State); |
| 166 |
return Empty; |
| 167 |
end if; |
| 168 |
end; |
| 169 |
|
| 170 |
-- Otherwise we definitely have no initialization expression |
| 171 |
|
| 172 |
else |
| 173 |
return Empty; |
| 174 |
end if; |
| 175 |
|
| 176 |
-- Merge here if we have an initialization expression |
| 177 |
|
| 178 |
T_Colon_Equal; |
| 179 |
|
| 180 |
if P then |
| 181 |
return P_Expression; |
| 182 |
else |
| 183 |
return P_Expression_No_Right_Paren; |
| 184 |
end if; |
| 185 |
end Init_Expr_Opt; |
| 186 |
|
| 187 |
---------------------------- |
| 188 |
-- 3.1 Basic Declaration -- |
| 189 |
---------------------------- |
| 190 |
|
| 191 |
-- Parsed by P_Basic_Declarative_Items (3.9) |
| 192 |
|
| 193 |
------------------------------ |
| 194 |
-- 3.1 Defining Identifier -- |
| 195 |
------------------------------ |
| 196 |
|
| 197 |
-- DEFINING_IDENTIFIER ::= IDENTIFIER |
| 198 |
|
| 199 |
-- Error recovery: can raise Error_Resync |
| 200 |
|
| 201 |
function P_Defining_Identifier (C : Id_Check := None) return Node_Id is |
| 202 |
Ident_Node : Node_Id := P_Identifier (C, True); |
| 203 |
|
| 204 |
begin |
| 205 |
-- If we already have a defining identifier, clean it out and make |
| 206 |
-- a new clean identifier. This situation arises in some error cases |
| 207 |
-- and we need to fix it. |
| 208 |
|
| 209 |
if Nkind (Ident_Node) = N_Defining_Identifier then |
| 210 |
Ident_Node := Make_Identifier (Sloc (Ident_Node), Chars (Ident_Node)); |
| 211 |
end if; |
| 212 |
|
| 213 |
-- Change identifier to defining identifier if not in error |
| 214 |
|
| 215 |
if Ident_Node /= Error then |
| 216 |
Change_Identifier_To_Defining_Identifier (Ident_Node); |
| 217 |
|
| 218 |
-- Warn if standard redefinition, except that we never warn on a |
| 219 |
-- record field definition (since this is always a harmless case). |
| 220 |
|
| 221 |
if not Inside_Record_Definition then |
| 222 |
Warn_If_Standard_Redefinition (Ident_Node); |
| 223 |
end if; |
| 224 |
end if; |
| 225 |
|
| 226 |
return Ident_Node; |
| 227 |
end P_Defining_Identifier; |
| 228 |
|
| 229 |
----------------------------- |
| 230 |
-- 3.2.1 Type Declaration -- |
| 231 |
----------------------------- |
| 232 |
|
| 233 |
-- TYPE_DECLARATION ::= |
| 234 |
-- FULL_TYPE_DECLARATION |
| 235 |
-- | INCOMPLETE_TYPE_DECLARATION |
| 236 |
-- | PRIVATE_TYPE_DECLARATION |
| 237 |
-- | PRIVATE_EXTENSION_DECLARATION |
| 238 |
|
| 239 |
-- FULL_TYPE_DECLARATION ::= |
| 240 |
-- type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART] is TYPE_DEFINITION |
| 241 |
-- [ASPECT_SPECIFICATIONS]; |
| 242 |
-- | CONCURRENT_TYPE_DECLARATION |
| 243 |
|
| 244 |
-- INCOMPLETE_TYPE_DECLARATION ::= |
| 245 |
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] [is tagged]; |
| 246 |
|
| 247 |
-- PRIVATE_TYPE_DECLARATION ::= |
| 248 |
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] |
| 249 |
-- is [abstract] [tagged] [limited] private |
| 250 |
-- [ASPECT_SPECIFICATIONS]; |
| 251 |
|
| 252 |
-- PRIVATE_EXTENSION_DECLARATION ::= |
| 253 |
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is |
| 254 |
-- [abstract] [limited | synchronized] |
| 255 |
-- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST] |
| 256 |
-- with private [ASPECT_SPECIFICATIONS]; |
| 257 |
|
| 258 |
-- TYPE_DEFINITION ::= |
| 259 |
-- ENUMERATION_TYPE_DEFINITION | INTEGER_TYPE_DEFINITION |
| 260 |
-- | REAL_TYPE_DEFINITION | ARRAY_TYPE_DEFINITION |
| 261 |
-- | RECORD_TYPE_DEFINITION | ACCESS_TYPE_DEFINITION |
| 262 |
-- | DERIVED_TYPE_DEFINITION | INTERFACE_TYPE_DEFINITION |
| 263 |
|
| 264 |
-- INTEGER_TYPE_DEFINITION ::= |
| 265 |
-- SIGNED_INTEGER_TYPE_DEFINITION |
| 266 |
-- MODULAR_TYPE_DEFINITION |
| 267 |
|
| 268 |
-- INTERFACE_TYPE_DEFINITION ::= |
| 269 |
-- [limited | task | protected | synchronized ] interface |
| 270 |
-- [and INTERFACE_LIST] |
| 271 |
|
| 272 |
-- Error recovery: can raise Error_Resync |
| 273 |
|
| 274 |
-- The processing for full type declarations, incomplete type declarations, |
| 275 |
-- private type declarations and type definitions is included in this |
| 276 |
-- function. The processing for concurrent type declarations is NOT here, |
| 277 |
-- but rather in chapter 9 (this function handles only declarations |
| 278 |
-- starting with TYPE). |
| 279 |
|
| 280 |
function P_Type_Declaration return Node_Id is |
| 281 |
Abstract_Present : Boolean := False; |
| 282 |
Abstract_Loc : Source_Ptr := No_Location; |
| 283 |
Decl_Node : Node_Id; |
| 284 |
Discr_List : List_Id; |
| 285 |
Discr_Sloc : Source_Ptr; |
| 286 |
End_Labl : Node_Id; |
| 287 |
Ident_Node : Node_Id; |
| 288 |
Is_Derived_Iface : Boolean := False; |
| 289 |
Type_Loc : Source_Ptr; |
| 290 |
Type_Start_Col : Column_Number; |
| 291 |
Unknown_Dis : Boolean; |
| 292 |
|
| 293 |
Typedef_Node : Node_Id; |
| 294 |
-- Normally holds type definition, except in the case of a private |
| 295 |
-- extension declaration, in which case it holds the declaration itself |
| 296 |
|
| 297 |
begin |
| 298 |
Type_Loc := Token_Ptr; |
| 299 |
Type_Start_Col := Start_Column; |
| 300 |
|
| 301 |
-- If we have TYPE, then proceed ahead and scan identifier |
| 302 |
|
| 303 |
if Token = Tok_Type then |
| 304 |
Type_Token_Location := Type_Loc; |
| 305 |
Scan; -- past TYPE |
| 306 |
Ident_Node := P_Defining_Identifier (C_Is); |
| 307 |
|
| 308 |
-- Otherwise this is an error case |
| 309 |
|
| 310 |
else |
| 311 |
T_Type; |
| 312 |
Type_Token_Location := Type_Loc; |
| 313 |
Ident_Node := P_Defining_Identifier (C_Is); |
| 314 |
end if; |
| 315 |
|
| 316 |
Discr_Sloc := Token_Ptr; |
| 317 |
|
| 318 |
if P_Unknown_Discriminant_Part_Opt then |
| 319 |
Unknown_Dis := True; |
| 320 |
Discr_List := No_List; |
| 321 |
else |
| 322 |
Unknown_Dis := False; |
| 323 |
Discr_List := P_Known_Discriminant_Part_Opt; |
| 324 |
end if; |
| 325 |
|
| 326 |
-- Incomplete type declaration. We complete the processing for this |
| 327 |
-- case here and return the resulting incomplete type declaration node |
| 328 |
|
| 329 |
if Token = Tok_Semicolon then |
| 330 |
Scan; -- past ; |
| 331 |
Decl_Node := New_Node (N_Incomplete_Type_Declaration, Type_Loc); |
| 332 |
Set_Defining_Identifier (Decl_Node, Ident_Node); |
| 333 |
Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis); |
| 334 |
Set_Discriminant_Specifications (Decl_Node, Discr_List); |
| 335 |
return Decl_Node; |
| 336 |
|
| 337 |
else |
| 338 |
Decl_Node := Empty; |
| 339 |
end if; |
| 340 |
|
| 341 |
-- Full type declaration or private type declaration, must have IS |
| 342 |
|
| 343 |
if Token = Tok_Equal then |
| 344 |
TF_Is; |
| 345 |
Scan; -- past = used in place of IS |
| 346 |
|
| 347 |
elsif Token = Tok_Renames then |
| 348 |
Error_Msg_SC -- CODEFIX |
| 349 |
("RENAMES should be IS"); |
| 350 |
Scan; -- past RENAMES used in place of IS |
| 351 |
|
| 352 |
else |
| 353 |
TF_Is; |
| 354 |
end if; |
| 355 |
|
| 356 |
-- First an error check, if we have two identifiers in a row, a likely |
| 357 |
-- possibility is that the first of the identifiers is an incorrectly |
| 358 |
-- spelled keyword. |
| 359 |
|
| 360 |
if Token = Tok_Identifier then |
| 361 |
declare |
| 362 |
SS : Saved_Scan_State; |
| 363 |
I2 : Boolean; |
| 364 |
|
| 365 |
begin |
| 366 |
Save_Scan_State (SS); |
| 367 |
Scan; -- past initial identifier |
| 368 |
I2 := (Token = Tok_Identifier); |
| 369 |
Restore_Scan_State (SS); |
| 370 |
|
| 371 |
if I2 |
| 372 |
and then |
| 373 |
(Bad_Spelling_Of (Tok_Abstract) or else |
| 374 |
Bad_Spelling_Of (Tok_Access) or else |
| 375 |
Bad_Spelling_Of (Tok_Aliased) or else |
| 376 |
Bad_Spelling_Of (Tok_Constant)) |
| 377 |
then |
| 378 |
null; |
| 379 |
end if; |
| 380 |
end; |
| 381 |
end if; |
| 382 |
|
| 383 |
-- Check for misuse of Ada 95 keyword abstract in Ada 83 mode |
| 384 |
|
| 385 |
if Token_Name = Name_Abstract then |
| 386 |
Check_95_Keyword (Tok_Abstract, Tok_Tagged); |
| 387 |
Check_95_Keyword (Tok_Abstract, Tok_New); |
| 388 |
end if; |
| 389 |
|
| 390 |
-- Check cases of misuse of ABSTRACT |
| 391 |
|
| 392 |
if Token = Tok_Abstract then |
| 393 |
Abstract_Present := True; |
| 394 |
Abstract_Loc := Token_Ptr; |
| 395 |
Scan; -- past ABSTRACT |
| 396 |
|
| 397 |
-- Ada 2005 (AI-419): AARM 3.4 (2/2) |
| 398 |
|
| 399 |
if (Ada_Version < Ada_2005 and then Token = Tok_Limited) |
| 400 |
or else Token in Tok_Private | Tok_Record | Tok_Null |
| 401 |
then |
| 402 |
Error_Msg_AP ("TAGGED expected"); |
| 403 |
end if; |
| 404 |
end if; |
| 405 |
|
| 406 |
-- Check for misuse of Ada 95 keyword Tagged |
| 407 |
|
| 408 |
if Token_Name = Name_Tagged then |
| 409 |
Check_95_Keyword (Tok_Tagged, Tok_Private); |
| 410 |
Check_95_Keyword (Tok_Tagged, Tok_Limited); |
| 411 |
Check_95_Keyword (Tok_Tagged, Tok_Record); |
| 412 |
end if; |
| 413 |
|
| 414 |
-- Special check for misuse of Aliased |
| 415 |
|
| 416 |
if Token = Tok_Aliased or else Token_Name = Name_Aliased then |
| 417 |
Error_Msg_SC ("ALIASED not allowed in type definition"); |
| 418 |
Scan; -- past ALIASED |
| 419 |
end if; |
| 420 |
|
| 421 |
-- The following processing deals with either a private type declaration |
| 422 |
-- or a full type declaration. In the private type case, we build the |
| 423 |
-- N_Private_Type_Declaration node, setting its Tagged_Present and |
| 424 |
-- Limited_Present flags, on encountering the Private keyword, and |
| 425 |
-- leave Typedef_Node set to Empty. For the full type declaration |
| 426 |
-- case, Typedef_Node gets set to the type definition. |
| 427 |
|
| 428 |
Typedef_Node := Empty; |
| 429 |
|
| 430 |
-- Switch on token following the IS. The loop normally runs once. It |
| 431 |
-- only runs more than once if an error is detected, to try again after |
| 432 |
-- detecting and fixing up the error. |
| 433 |
|
| 434 |
loop |
| 435 |
case Token is |
| 436 |
when Tok_Access |
| 437 |
| Tok_Not -- Ada 2005 (AI-231) |
| 438 |
=> |
| 439 |
Typedef_Node := P_Access_Type_Definition; |
| 440 |
exit; |
| 441 |
|
| 442 |
when Tok_Array => |
| 443 |
Typedef_Node := P_Array_Type_Definition; |
| 444 |
exit; |
| 445 |
|
| 446 |
when Tok_Delta => |
| 447 |
Typedef_Node := P_Fixed_Point_Definition; |
| 448 |
exit; |
| 449 |
|
| 450 |
when Tok_Digits => |
| 451 |
Typedef_Node := P_Floating_Point_Definition; |
| 452 |
exit; |
| 453 |
|
| 454 |
when Tok_In => |
| 455 |
Ignore (Tok_In); |
| 456 |
|
| 457 |
when Tok_Integer_Literal => |
| 458 |
T_Range; |
| 459 |
Typedef_Node := P_Signed_Integer_Type_Definition; |
| 460 |
exit; |
| 461 |
|
| 462 |
when Tok_Null => |
| 463 |
Typedef_Node := P_Record_Definition; |
| 464 |
exit; |
| 465 |
|
| 466 |
when Tok_Left_Paren => |
| 467 |
Typedef_Node := P_Enumeration_Type_Definition; |
| 468 |
|
| 469 |
End_Labl := Make_Identifier (Token_Ptr, Chars (Ident_Node)); |
| 470 |
Set_Comes_From_Source (End_Labl, False); |
| 471 |
|
| 472 |
Set_End_Label (Typedef_Node, End_Labl); |
| 473 |
exit; |
| 474 |
|
| 475 |
when Tok_Mod => |
| 476 |
Typedef_Node := P_Modular_Type_Definition; |
| 477 |
exit; |
| 478 |
|
| 479 |
when Tok_New => |
| 480 |
Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl; |
| 481 |
|
| 482 |
if Nkind (Typedef_Node) = N_Derived_Type_Definition |
| 483 |
and then Present (Record_Extension_Part (Typedef_Node)) |
| 484 |
then |
| 485 |
End_Labl := Make_Identifier (Token_Ptr, Chars (Ident_Node)); |
| 486 |
Set_Comes_From_Source (End_Labl, False); |
| 487 |
|
| 488 |
Set_End_Label |
| 489 |
(Record_Extension_Part (Typedef_Node), End_Labl); |
| 490 |
end if; |
| 491 |
|
| 492 |
exit; |
| 493 |
|
| 494 |
when Tok_Range => |
| 495 |
Typedef_Node := P_Signed_Integer_Type_Definition; |
| 496 |
exit; |
| 497 |
|
| 498 |
when Tok_Record => |
| 499 |
Typedef_Node := P_Record_Definition; |
| 500 |
|
| 501 |
End_Labl := Make_Identifier (Token_Ptr, Chars (Ident_Node)); |
| 502 |
Set_Comes_From_Source (End_Labl, False); |
| 503 |
|
| 504 |
Set_End_Label (Typedef_Node, End_Labl); |
| 505 |
exit; |
| 506 |
|
| 507 |
when Tok_Tagged => |
| 508 |
Scan; -- past TAGGED |
| 509 |
|
| 510 |
-- Ada 2005 (AI-326): If the words IS TAGGED appear, the type |
| 511 |
-- is a tagged incomplete type. |
| 512 |
|
| 513 |
if Ada_Version >= Ada_2005 |
| 514 |
and then Token = Tok_Semicolon |
| 515 |
then |
| 516 |
Scan; -- past ; |
| 517 |
|
| 518 |
Decl_Node := |
| 519 |
New_Node (N_Incomplete_Type_Declaration, Type_Loc); |
| 520 |
Set_Defining_Identifier (Decl_Node, Ident_Node); |
| 521 |
Set_Tagged_Present (Decl_Node); |
| 522 |
Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis); |
| 523 |
Set_Discriminant_Specifications (Decl_Node, Discr_List); |
| 524 |
|
| 525 |
return Decl_Node; |
| 526 |
end if; |
| 527 |
|
| 528 |
if Token = Tok_Abstract then |
| 529 |
Error_Msg_SC -- CODEFIX |
| 530 |
("ABSTRACT must come before TAGGED"); |
| 531 |
Abstract_Present := True; |
| 532 |
Abstract_Loc := Token_Ptr; |
| 533 |
Scan; -- past ABSTRACT |
| 534 |
end if; |
| 535 |
|
| 536 |
if Token = Tok_Limited then |
| 537 |
Scan; -- past LIMITED |
| 538 |
|
| 539 |
-- TAGGED LIMITED PRIVATE case |
| 540 |
|
| 541 |
if Token = Tok_Private then |
| 542 |
Decl_Node := |
| 543 |
New_Node (N_Private_Type_Declaration, Type_Loc); |
| 544 |
Set_Tagged_Present (Decl_Node, True); |
| 545 |
Set_Limited_Present (Decl_Node, True); |
| 546 |
Scan; -- past PRIVATE |
| 547 |
|
| 548 |
-- TAGGED LIMITED RECORD |
| 549 |
|
| 550 |
else |
| 551 |
Typedef_Node := P_Record_Definition; |
| 552 |
Set_Tagged_Present (Typedef_Node, True); |
| 553 |
Set_Limited_Present (Typedef_Node, True); |
| 554 |
|
| 555 |
End_Labl := |
| 556 |
Make_Identifier (Token_Ptr, Chars (Ident_Node)); |
| 557 |
Set_Comes_From_Source (End_Labl, False); |
| 558 |
|
| 559 |
Set_End_Label (Typedef_Node, End_Labl); |
| 560 |
end if; |
| 561 |
|
| 562 |
else |
| 563 |
-- TAGGED PRIVATE |
| 564 |
|
| 565 |
if Token = Tok_Private then |
| 566 |
Decl_Node := |
| 567 |
New_Node (N_Private_Type_Declaration, Type_Loc); |
| 568 |
Set_Tagged_Present (Decl_Node, True); |
| 569 |
Scan; -- past PRIVATE |
| 570 |
|
| 571 |
-- TAGGED RECORD |
| 572 |
|
| 573 |
else |
| 574 |
Typedef_Node := P_Record_Definition; |
| 575 |
Set_Tagged_Present (Typedef_Node, True); |
| 576 |
|
| 577 |
End_Labl := |
| 578 |
Make_Identifier (Token_Ptr, Chars (Ident_Node)); |
| 579 |
Set_Comes_From_Source (End_Labl, False); |
| 580 |
|
| 581 |
Set_End_Label (Typedef_Node, End_Labl); |
| 582 |
end if; |
| 583 |
end if; |
| 584 |
|
| 585 |
exit; |
| 586 |
|
| 587 |
when Tok_Limited => |
| 588 |
Scan; -- past LIMITED |
| 589 |
|
| 590 |
loop |
| 591 |
if Token = Tok_Tagged then |
| 592 |
Error_Msg_SC -- CODEFIX |
| 593 |
("TAGGED must come before LIMITED"); |
| 594 |
Scan; -- past TAGGED |
| 595 |
|
| 596 |
elsif Token = Tok_Abstract then |
| 597 |
Error_Msg_SC -- CODEFIX |
| 598 |
("ABSTRACT must come before LIMITED"); |
| 599 |
Scan; -- past ABSTRACT |
| 600 |
|
| 601 |
else |
| 602 |
exit; |
| 603 |
end if; |
| 604 |
end loop; |
| 605 |
|
| 606 |
-- LIMITED RECORD or LIMITED NULL RECORD |
| 607 |
|
| 608 |
if Token in Tok_Record | Tok_Null then |
| 609 |
if Ada_Version = Ada_83 then |
| 610 |
Error_Msg_SP |
| 611 |
("(Ada 83) limited record declaration not allowed!"); |
| 612 |
|
| 613 |
-- In Ada 2005, "abstract limited" can appear before "new", |
| 614 |
-- but it cannot be part of an untagged record declaration. |
| 615 |
|
| 616 |
elsif Abstract_Present |
| 617 |
and then Prev_Token /= Tok_Tagged |
| 618 |
then |
| 619 |
Error_Msg_SP ("TAGGED expected"); |
| 620 |
end if; |
| 621 |
|
| 622 |
Typedef_Node := P_Record_Definition; |
| 623 |
Set_Limited_Present (Typedef_Node, True); |
| 624 |
End_Labl := Make_Identifier (Token_Ptr, Chars (Ident_Node)); |
| 625 |
Set_Comes_From_Source (End_Labl, False); |
| 626 |
|
| 627 |
Set_End_Label (Typedef_Node, End_Labl); |
| 628 |
|
| 629 |
-- Ada 2005 (AI-251): LIMITED INTERFACE |
| 630 |
|
| 631 |
-- If we are compiling in Ada 83 or Ada 95 mode, "interface" |
| 632 |
-- is not a reserved word but we force its analysis to |
| 633 |
-- generate the corresponding usage error. |
| 634 |
|
| 635 |
elsif Token = Tok_Interface |
| 636 |
or else (Token = Tok_Identifier |
| 637 |
and then Chars (Token_Node) = Name_Interface) |
| 638 |
then |
| 639 |
Typedef_Node := |
| 640 |
P_Interface_Type_Definition (Abstract_Present); |
| 641 |
Abstract_Present := True; |
| 642 |
Set_Limited_Present (Typedef_Node); |
| 643 |
|
| 644 |
if Nkind (Typedef_Node) = N_Derived_Type_Definition then |
| 645 |
Is_Derived_Iface := True; |
| 646 |
end if; |
| 647 |
|
| 648 |
-- Ada 2005 (AI-419): LIMITED NEW |
| 649 |
|
| 650 |
elsif Token = Tok_New then |
| 651 |
Error_Msg_Ada_2005_Extension ("LIMITED in derived type"); |
| 652 |
|
| 653 |
Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl; |
| 654 |
Set_Limited_Present (Typedef_Node); |
| 655 |
|
| 656 |
if Nkind (Typedef_Node) = N_Derived_Type_Definition |
| 657 |
and then Present (Record_Extension_Part (Typedef_Node)) |
| 658 |
then |
| 659 |
End_Labl := |
| 660 |
Make_Identifier (Token_Ptr, Chars (Ident_Node)); |
| 661 |
Set_Comes_From_Source (End_Labl, False); |
| 662 |
|
| 663 |
Set_End_Label |
| 664 |
(Record_Extension_Part (Typedef_Node), End_Labl); |
| 665 |
end if; |
| 666 |
|
| 667 |
-- LIMITED PRIVATE is the only remaining possibility here |
| 668 |
|
| 669 |
else |
| 670 |
Decl_Node := New_Node (N_Private_Type_Declaration, Type_Loc); |
| 671 |
Set_Limited_Present (Decl_Node, True); |
| 672 |
T_Private; -- past PRIVATE (or complain if not there) |
| 673 |
end if; |
| 674 |
|
| 675 |
exit; |
| 676 |
|
| 677 |
-- Here we have an identifier after the IS, which is certainly |
| 678 |
-- wrong and which might be one of several different mistakes. |
| 679 |
|
| 680 |
when Tok_Identifier => |
| 681 |
|
| 682 |
-- First case, if identifier is on same line, then probably we |
| 683 |
-- have something like "type X is Integer .." and the best |
| 684 |
-- diagnosis is a missing NEW. Note: the missing new message |
| 685 |
-- will be posted by P_Derived_Type_Def_Or_Private_Ext_Decl. |
| 686 |
|
| 687 |
if not Token_Is_At_Start_Of_Line then |
| 688 |
Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl; |
| 689 |
|
| 690 |
-- If the identifier is at the start of the line, and is in the |
| 691 |
-- same column as the type declaration itself then we consider |
| 692 |
-- that we had a missing type definition on the previous line |
| 693 |
|
| 694 |
elsif Start_Column <= Type_Start_Col then |
| 695 |
Error_Msg_AP ("type definition expected"); |
| 696 |
Typedef_Node := Error; |
| 697 |
|
| 698 |
-- If the identifier is at the start of the line, and is in |
| 699 |
-- a column to the right of the type declaration line, then we |
| 700 |
-- may have something like: |
| 701 |
|
| 702 |
-- type x is |
| 703 |
-- r : integer |
| 704 |
|
| 705 |
-- and the best diagnosis is a missing record keyword |
| 706 |
|
| 707 |
else |
| 708 |
Typedef_Node := P_Record_Definition; |
| 709 |
end if; |
| 710 |
|
| 711 |
exit; |
| 712 |
|
| 713 |
-- Ada 2005 (AI-251): INTERFACE |
| 714 |
|
| 715 |
when Tok_Interface => |
| 716 |
Typedef_Node := P_Interface_Type_Definition (Abstract_Present); |
| 717 |
Abstract_Present := True; |
| 718 |
exit; |
| 719 |
|
| 720 |
when Tok_Private => |
| 721 |
Decl_Node := New_Node (N_Private_Type_Declaration, Type_Loc); |
| 722 |
Scan; -- past PRIVATE |
| 723 |
|
| 724 |
-- Check error cases of private [abstract] tagged |
| 725 |
|
| 726 |
if Token = Tok_Abstract then |
| 727 |
Error_Msg_SC ("`ABSTRACT TAGGED` must come before PRIVATE"); |
| 728 |
Scan; -- past ABSTRACT |
| 729 |
|
| 730 |
if Token = Tok_Tagged then |
| 731 |
Scan; -- past TAGGED |
| 732 |
end if; |
| 733 |
|
| 734 |
elsif Token = Tok_Tagged then |
| 735 |
Error_Msg_SC ("TAGGED must come before PRIVATE"); |
| 736 |
Scan; -- past TAGGED |
| 737 |
end if; |
| 738 |
|
| 739 |
exit; |
| 740 |
|
| 741 |
-- Ada 2005 (AI-345): Protected, synchronized or task interface |
| 742 |
-- or Ada 2005 (AI-443): Synchronized private extension. |
| 743 |
|
| 744 |
when Tok_Protected |
| 745 |
| Tok_Synchronized |
| 746 |
| Tok_Task |
| 747 |
=> |
| 748 |
declare |
| 749 |
Saved_Token : constant Token_Type := Token; |
| 750 |
|
| 751 |
begin |
| 752 |
Scan; -- past TASK, PROTECTED or SYNCHRONIZED |
| 753 |
|
| 754 |
-- Synchronized private extension |
| 755 |
|
| 756 |
if Token = Tok_New then |
| 757 |
Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl; |
| 758 |
|
| 759 |
if Saved_Token = Tok_Synchronized then |
| 760 |
if Nkind (Typedef_Node) = |
| 761 |
N_Derived_Type_Definition |
| 762 |
then |
| 763 |
Error_Msg_N |
| 764 |
("SYNCHRONIZED not allowed for record extension", |
| 765 |
Typedef_Node); |
| 766 |
else |
| 767 |
Set_Synchronized_Present (Typedef_Node); |
| 768 |
end if; |
| 769 |
|
| 770 |
else |
| 771 |
Error_Msg_SC ("invalid kind of private extension"); |
| 772 |
end if; |
| 773 |
|
| 774 |
-- Interface |
| 775 |
|
| 776 |
else |
| 777 |
if Token /= Tok_Interface then |
| 778 |
Error_Msg_SC ("NEW or INTERFACE expected"); |
| 779 |
end if; |
| 780 |
|
| 781 |
Typedef_Node := |
| 782 |
P_Interface_Type_Definition (Abstract_Present); |
| 783 |
Abstract_Present := True; |
| 784 |
|
| 785 |
case Saved_Token is |
| 786 |
when Tok_Task => |
| 787 |
Set_Task_Present (Typedef_Node); |
| 788 |
|
| 789 |
when Tok_Protected => |
| 790 |
Set_Protected_Present (Typedef_Node); |
| 791 |
|
| 792 |
when Tok_Synchronized => |
| 793 |
Set_Synchronized_Present (Typedef_Node); |
| 794 |
|
| 795 |
when others => |
| 796 |
pragma Assert (False); |
| 797 |
null; |
| 798 |
end case; |
| 799 |
end if; |
| 800 |
end; |
| 801 |
|
| 802 |
exit; |
| 803 |
|
| 804 |
-- Anything else is an error |
| 805 |
|
| 806 |
when others => |
| 807 |
if Bad_Spelling_Of (Tok_Access) |
| 808 |
or else |
| 809 |
Bad_Spelling_Of (Tok_Array) |
| 810 |
or else |
| 811 |
Bad_Spelling_Of (Tok_Delta) |
| 812 |
or else |
| 813 |
Bad_Spelling_Of (Tok_Digits) |
| 814 |
or else |
| 815 |
Bad_Spelling_Of (Tok_Limited) |
| 816 |
or else |
| 817 |
Bad_Spelling_Of (Tok_Private) |
| 818 |
or else |
| 819 |
Bad_Spelling_Of (Tok_Range) |
| 820 |
or else |
| 821 |
Bad_Spelling_Of (Tok_Record) |
| 822 |
or else |
| 823 |
Bad_Spelling_Of (Tok_Tagged) |
| 824 |
then |
| 825 |
null; |
| 826 |
|
| 827 |
else |
| 828 |
Error_Msg_AP ("type definition expected"); |
| 829 |
raise Error_Resync; |
| 830 |
end if; |
| 831 |
end case; |
| 832 |
end loop; |
| 833 |
|
| 834 |
-- For the private type declaration case, the private type declaration |
| 835 |
-- node has been built, with the Tagged_Present and Limited_Present |
| 836 |
-- flags set as needed, and Typedef_Node is left set to Empty. |
| 837 |
|
| 838 |
if No (Typedef_Node) then |
| 839 |
Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis); |
| 840 |
Set_Abstract_Present (Decl_Node, Abstract_Present); |
| 841 |
|
| 842 |
-- For a private extension declaration, Typedef_Node contains the |
| 843 |
-- N_Private_Extension_Declaration node, which we now complete. Note |
| 844 |
-- that the private extension declaration, unlike a full type |
| 845 |
-- declaration, does permit unknown discriminants. |
| 846 |
|
| 847 |
elsif Nkind (Typedef_Node) = N_Private_Extension_Declaration then |
| 848 |
Decl_Node := Typedef_Node; |
| 849 |
Set_Sloc (Decl_Node, Type_Loc); |
| 850 |
Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis); |
| 851 |
Set_Abstract_Present (Typedef_Node, Abstract_Present); |
| 852 |
|
| 853 |
-- In the full type declaration case, Typedef_Node has the type |
| 854 |
-- definition and here is where we build the full type declaration |
| 855 |
-- node. This is also where we check for improper use of an unknown |
| 856 |
-- discriminant part (not allowed for full type declaration). |
| 857 |
|
| 858 |
else |
| 859 |
if Nkind (Typedef_Node) = N_Record_Definition |
| 860 |
or else (Nkind (Typedef_Node) = N_Derived_Type_Definition |
| 861 |
and then Present (Record_Extension_Part (Typedef_Node))) |
| 862 |
or else Is_Derived_Iface |
| 863 |
then |
| 864 |
Set_Abstract_Present (Typedef_Node, Abstract_Present); |
| 865 |
|
| 866 |
elsif Abstract_Present then |
| 867 |
Error_Msg ("ABSTRACT not allowed here, ignored", Abstract_Loc); |
| 868 |
end if; |
| 869 |
|
| 870 |
Decl_Node := New_Node (N_Full_Type_Declaration, Type_Loc); |
| 871 |
Set_Type_Definition (Decl_Node, Typedef_Node); |
| 872 |
|
| 873 |
if Unknown_Dis then |
| 874 |
Error_Msg |
| 875 |
("full type declaration cannot have unknown discriminants", |
| 876 |
Discr_Sloc); |
| 877 |
end if; |
| 878 |
end if; |
| 879 |
|
| 880 |
-- Remaining processing is common for all three cases |
| 881 |
|
| 882 |
Set_Defining_Identifier (Decl_Node, Ident_Node); |
| 883 |
Set_Discriminant_Specifications (Decl_Node, Discr_List); |
| 884 |
P_Aspect_Specifications (Decl_Node, Semicolon => True); |
| 885 |
return Decl_Node; |
| 886 |
end P_Type_Declaration; |
| 887 |
|
| 888 |
---------------------------------- |
| 889 |
-- 3.2.1 Full Type Declaration -- |
| 890 |
---------------------------------- |
| 891 |
|
| 892 |
-- Parsed by P_Type_Declaration (3.2.1) |
| 893 |
|
| 894 |
---------------------------- |
| 895 |
-- 3.2.1 Type Definition -- |
| 896 |
---------------------------- |
| 897 |
|
| 898 |
-- Parsed by P_Type_Declaration (3.2.1) |
| 899 |
|
| 900 |
-------------------------------- |
| 901 |
-- 3.2.2 Subtype Declaration -- |
| 902 |
-------------------------------- |
| 903 |
|
| 904 |
-- SUBTYPE_DECLARATION ::= |
| 905 |
-- subtype DEFINING_IDENTIFIER is [NULL_EXCLUSION] SUBTYPE_INDICATION |
| 906 |
-- [ASPECT_SPECIFICATIONS]; |
| 907 |
|
| 908 |
-- The caller has checked that the initial token is SUBTYPE |
| 909 |
|
| 910 |
-- Error recovery: can raise Error_Resync |
| 911 |
|
| 912 |
function P_Subtype_Declaration return Node_Id is |
| 913 |
Decl_Node : Node_Id; |
| 914 |
Not_Null_Present : Boolean := False; |
| 915 |
|
| 916 |
begin |
| 917 |
Decl_Node := New_Node (N_Subtype_Declaration, Token_Ptr); |
| 918 |
Scan; -- past SUBTYPE |
| 919 |
Set_Defining_Identifier (Decl_Node, P_Defining_Identifier (C_Is)); |
| 920 |
TF_Is; |
| 921 |
|
| 922 |
if Token = Tok_New then |
| 923 |
Error_Msg_SC -- CODEFIX |
| 924 |
("NEW ignored (only allowed in type declaration)"); |
| 925 |
Scan; -- past NEW |
| 926 |
end if; |
| 927 |
|
| 928 |
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231) |
| 929 |
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present); |
| 930 |
|
| 931 |
Set_Subtype_Indication |
| 932 |
(Decl_Node, P_Subtype_Indication (Not_Null_Present)); |
| 933 |
P_Aspect_Specifications (Decl_Node, Semicolon => True); |
| 934 |
return Decl_Node; |
| 935 |
end P_Subtype_Declaration; |
| 936 |
|
| 937 |
------------------------------- |
| 938 |
-- 3.2.2 Subtype Indication -- |
| 939 |
------------------------------- |
| 940 |
|
| 941 |
-- SUBTYPE_INDICATION ::= |
| 942 |
-- [not null] SUBTYPE_MARK [CONSTRAINT] |
| 943 |
|
| 944 |
-- Error recovery: can raise Error_Resync |
| 945 |
|
| 946 |
function P_Null_Exclusion |
| 947 |
(Allow_Anonymous_In_95 : Boolean := False) return Boolean |
| 948 |
is |
| 949 |
Not_Loc : constant Source_Ptr := Token_Ptr; |
| 950 |
-- Source position of "not", if present |
| 951 |
|
| 952 |
begin |
| 953 |
if Token /= Tok_Not then |
| 954 |
return False; |
| 955 |
|
| 956 |
else |
| 957 |
Scan; -- past NOT |
| 958 |
|
| 959 |
if Token = Tok_Null then |
| 960 |
Scan; -- past NULL |
| 961 |
|
| 962 |
-- Ada 2005 (AI-441, AI-447): null_exclusion is illegal in Ada 95, |
| 963 |
-- except in the case of anonymous access types. |
| 964 |
|
| 965 |
-- Allow_Anonymous_In_95 will be True if we're parsing a formal |
| 966 |
-- parameter or discriminant, which are the only places where |
| 967 |
-- anonymous access types occur in Ada 95. "Formal : not null |
| 968 |
-- access ..." is legal in Ada 95, whereas "Formal : not null |
| 969 |
-- Named_Access_Type" is not. |
| 970 |
|
| 971 |
if Ada_Version >= Ada_2005 |
| 972 |
or else (Ada_Version >= Ada_95 |
| 973 |
and then Allow_Anonymous_In_95 |
| 974 |
and then Token = Tok_Access) |
| 975 |
then |
| 976 |
null; -- OK |
| 977 |
|
| 978 |
else |
| 979 |
Error_Msg |
| 980 |
("`NOT NULL` access type is an Ada 2005 extension", Not_Loc); |
| 981 |
Error_Msg |
| 982 |
("\unit should be compiled with -gnat05 switch", Not_Loc); |
| 983 |
end if; |
| 984 |
|
| 985 |
else |
| 986 |
Error_Msg_SP ("NULL expected"); |
| 987 |
end if; |
| 988 |
|
| 989 |
if Token = Tok_New then |
| 990 |
Error_Msg ("`NOT NULL` comes after NEW, not before", Not_Loc); |
| 991 |
end if; |
| 992 |
|
| 993 |
return True; |
| 994 |
end if; |
| 995 |
end P_Null_Exclusion; |
| 996 |
|
| 997 |
function P_Subtype_Indication |
| 998 |
(Not_Null_Present : Boolean := False) return Node_Id |
| 999 |
is |
| 1000 |
Type_Node : Node_Id; |
| 1001 |
|
| 1002 |
begin |
| 1003 |
if Token in Tok_Identifier | Tok_Operator_Symbol then |
| 1004 |
Type_Node := P_Subtype_Mark; |
| 1005 |
return P_Subtype_Indication (Type_Node, Not_Null_Present); |
| 1006 |
|
| 1007 |
else |
| 1008 |
-- Check for error of using record definition and treat it nicely, |
| 1009 |
-- otherwise things are really messed up, so resynchronize. |
| 1010 |
|
| 1011 |
if Token = Tok_Record then |
| 1012 |
Error_Msg_SC ("anonymous record definition not permitted"); |
| 1013 |
Discard_Junk_Node (P_Record_Definition); |
| 1014 |
return Error; |
| 1015 |
|
| 1016 |
else |
| 1017 |
Error_Msg_AP ("subtype indication expected"); |
| 1018 |
raise Error_Resync; |
| 1019 |
end if; |
| 1020 |
end if; |
| 1021 |
end P_Subtype_Indication; |
| 1022 |
|
| 1023 |
-- The following function is identical except that it is called with |
| 1024 |
-- the subtype mark already scanned out, and it scans out the constraint |
| 1025 |
|
| 1026 |
-- Error recovery: can raise Error_Resync |
| 1027 |
|
| 1028 |
function P_Subtype_Indication |
| 1029 |
(Subtype_Mark : Node_Id; |
| 1030 |
Not_Null_Present : Boolean := False) return Node_Id |
| 1031 |
is |
| 1032 |
Indic_Node : Node_Id; |
| 1033 |
Constr_Node : Node_Id; |
| 1034 |
|
| 1035 |
begin |
| 1036 |
Constr_Node := P_Constraint_Opt; |
| 1037 |
|
| 1038 |
if No (Constr_Node) |
| 1039 |
or else |
| 1040 |
(Nkind (Constr_Node) = N_Range_Constraint |
| 1041 |
and then Nkind (Range_Expression (Constr_Node)) = N_Error) |
| 1042 |
then |
| 1043 |
return Subtype_Mark; |
| 1044 |
else |
| 1045 |
if Not_Null_Present then |
| 1046 |
Error_Msg_SP ("`NOT NULL` not allowed if constraint given"); |
| 1047 |
end if; |
| 1048 |
|
| 1049 |
Indic_Node := New_Node (N_Subtype_Indication, Sloc (Subtype_Mark)); |
| 1050 |
Set_Subtype_Mark (Indic_Node, Check_Subtype_Mark (Subtype_Mark)); |
| 1051 |
Set_Constraint (Indic_Node, Constr_Node); |
| 1052 |
return Indic_Node; |
| 1053 |
end if; |
| 1054 |
end P_Subtype_Indication; |
| 1055 |
|
| 1056 |
------------------------- |
| 1057 |
-- 3.2.2 Subtype Mark -- |
| 1058 |
------------------------- |
| 1059 |
|
| 1060 |
-- SUBTYPE_MARK ::= subtype_NAME; |
| 1061 |
|
| 1062 |
-- Note: The subtype mark which appears after an IN or NOT IN |
| 1063 |
-- operator is parsed by P_Range_Or_Subtype_Mark (3.5) |
| 1064 |
|
| 1065 |
-- Error recovery: cannot raise Error_Resync |
| 1066 |
|
| 1067 |
function P_Subtype_Mark return Node_Id is |
| 1068 |
begin |
| 1069 |
return P_Subtype_Mark_Resync; |
| 1070 |
exception |
| 1071 |
when Error_Resync => |
| 1072 |
return Error; |
| 1073 |
end P_Subtype_Mark; |
| 1074 |
|
| 1075 |
-- This routine differs from P_Subtype_Mark in that it insists that an |
| 1076 |
-- identifier be present, and if it is not, it raises Error_Resync. |
| 1077 |
|
| 1078 |
-- Error recovery: can raise Error_Resync |
| 1079 |
|
| 1080 |
function P_Subtype_Mark_Resync return Node_Id is |
| 1081 |
Type_Node : Node_Id; |
| 1082 |
|
| 1083 |
begin |
| 1084 |
if Token = Tok_Access then |
| 1085 |
Error_Msg_SC ("anonymous access type definition not allowed here"); |
| 1086 |
Scan; -- past ACCESS |
| 1087 |
end if; |
| 1088 |
|
| 1089 |
if Token = Tok_Array then |
| 1090 |
Error_Msg_SC ("anonymous array definition not allowed here"); |
| 1091 |
Discard_Junk_Node (P_Array_Type_Definition); |
| 1092 |
return Error; |
| 1093 |
|
| 1094 |
else |
| 1095 |
Type_Node := P_Qualified_Simple_Name_Resync; |
| 1096 |
|
| 1097 |
-- Check for a subtype mark attribute. The only valid possibilities |
| 1098 |
-- are 'CLASS and 'BASE. Anything else is a definite error. We may |
| 1099 |
-- as well catch it here. |
| 1100 |
|
| 1101 |
if Token = Tok_Apostrophe then |
| 1102 |
return P_Subtype_Mark_Attribute (Type_Node); |
| 1103 |
else |
| 1104 |
return Type_Node; |
| 1105 |
end if; |
| 1106 |
end if; |
| 1107 |
end P_Subtype_Mark_Resync; |
| 1108 |
|
| 1109 |
-- The following function is called to scan out a subtype mark attribute. |
| 1110 |
-- The caller has already scanned out the subtype mark, which is passed in |
| 1111 |
-- as the argument, and has checked that the current token is apostrophe. |
| 1112 |
|
| 1113 |
-- Only a special subclass of attributes, called type attributes |
| 1114 |
-- (see Snames package) are allowed in this syntactic position. |
| 1115 |
|
| 1116 |
-- Note: if the apostrophe is followed by other than an identifier, then |
| 1117 |
-- the input expression is returned unchanged, and the scan pointer is |
| 1118 |
-- left pointing to the apostrophe. |
| 1119 |
|
| 1120 |
-- Error recovery: can raise Error_Resync |
| 1121 |
|
| 1122 |
function P_Subtype_Mark_Attribute (Type_Node : Node_Id) return Node_Id is |
| 1123 |
Attr_Node : Node_Id := Empty; |
| 1124 |
Scan_State : Saved_Scan_State; |
| 1125 |
Prefix : Node_Id; |
| 1126 |
|
| 1127 |
begin |
| 1128 |
Prefix := Check_Subtype_Mark (Type_Node); |
| 1129 |
|
| 1130 |
if Prefix = Error then |
| 1131 |
raise Error_Resync; |
| 1132 |
end if; |
| 1133 |
|
| 1134 |
-- Loop through attributes appearing (more than one can appear as for |
| 1135 |
-- for example in X'Base'Class). We are at an apostrophe on entry to |
| 1136 |
-- this loop, and it runs once for each attribute parsed, with |
| 1137 |
-- Prefix being the current possible prefix if it is an attribute. |
| 1138 |
|
| 1139 |
loop |
| 1140 |
Save_Scan_State (Scan_State); -- at Apostrophe |
| 1141 |
Scan; -- past apostrophe |
| 1142 |
|
| 1143 |
if Token /= Tok_Identifier then |
| 1144 |
Restore_Scan_State (Scan_State); -- to apostrophe |
| 1145 |
return Prefix; -- no attribute after all |
| 1146 |
|
| 1147 |
elsif not Is_Type_Attribute_Name (Token_Name) then |
| 1148 |
Error_Msg_N |
| 1149 |
("attribute & may not be used in a subtype mark", Token_Node); |
| 1150 |
raise Error_Resync; |
| 1151 |
|
| 1152 |
else |
| 1153 |
Attr_Node := |
| 1154 |
Make_Attribute_Reference (Prev_Token_Ptr, |
| 1155 |
Prefix => Prefix, |
| 1156 |
Attribute_Name => Token_Name); |
| 1157 |
Scan; -- past type attribute identifier |
| 1158 |
end if; |
| 1159 |
|
| 1160 |
exit when Token /= Tok_Apostrophe; |
| 1161 |
Prefix := Attr_Node; |
| 1162 |
end loop; |
| 1163 |
|
| 1164 |
-- Fall through here after scanning type attribute |
| 1165 |
|
| 1166 |
return Attr_Node; |
| 1167 |
end P_Subtype_Mark_Attribute; |
| 1168 |
|
| 1169 |
----------------------- |
| 1170 |
-- 3.2.2 Constraint -- |
| 1171 |
----------------------- |
| 1172 |
|
| 1173 |
-- CONSTRAINT ::= SCALAR_CONSTRAINT | COMPOSITE_CONSTRAINT |
| 1174 |
|
| 1175 |
-- SCALAR_CONSTRAINT ::= |
| 1176 |
-- RANGE_CONSTRAINT | DIGITS_CONSTRAINT | DELTA_CONSTRAINT |
| 1177 |
|
| 1178 |
-- COMPOSITE_CONSTRAINT ::= |
| 1179 |
-- INDEX_CONSTRAINT | DISCRIMINANT_CONSTRAINT |
| 1180 |
|
| 1181 |
-- If no constraint is present, this function returns Empty |
| 1182 |
|
| 1183 |
-- Error recovery: can raise Error_Resync |
| 1184 |
|
| 1185 |
function P_Constraint_Opt return Node_Id is |
| 1186 |
begin |
| 1187 |
if Token = Tok_Range or else Bad_Spelling_Of (Tok_Range) then |
| 1188 |
return P_Range_Constraint; |
| 1189 |
|
| 1190 |
elsif Token = Tok_Digits or else Bad_Spelling_Of (Tok_Digits) then |
| 1191 |
return P_Digits_Constraint; |
| 1192 |
|
| 1193 |
elsif Token = Tok_Delta or else Bad_Spelling_Of (Tok_Delta) then |
| 1194 |
return P_Delta_Constraint; |
| 1195 |
|
| 1196 |
elsif Token = Tok_Left_Paren then |
| 1197 |
return P_Index_Or_Discriminant_Constraint; |
| 1198 |
|
| 1199 |
-- One more possibility is e.g. 1 .. 10 (i.e. missing RANGE keyword) |
| 1200 |
|
| 1201 |
elsif Token = Tok_Identifier or else |
| 1202 |
Token = Tok_Integer_Literal or else |
| 1203 |
Token = Tok_Real_Literal |
| 1204 |
then |
| 1205 |
declare |
| 1206 |
Scan_State : Saved_Scan_State; |
| 1207 |
|
| 1208 |
begin |
| 1209 |
Save_Scan_State (Scan_State); -- at identifier or literal |
| 1210 |
Scan; -- past identifier or literal |
| 1211 |
|
| 1212 |
if Token = Tok_Dot_Dot then |
| 1213 |
Restore_Scan_State (Scan_State); |
| 1214 |
Error_Msg_BC ("missing RANGE keyword"); |
| 1215 |
return P_Range_Constraint; |
| 1216 |
else |
| 1217 |
Restore_Scan_State (Scan_State); |
| 1218 |
return Empty; |
| 1219 |
end if; |
| 1220 |
end; |
| 1221 |
|
| 1222 |
-- Nothing worked, no constraint there |
| 1223 |
|
| 1224 |
else |
| 1225 |
return Empty; |
| 1226 |
end if; |
| 1227 |
end P_Constraint_Opt; |
| 1228 |
|
| 1229 |
------------------------------ |
| 1230 |
-- 3.2.2 Scalar Constraint -- |
| 1231 |
------------------------------ |
| 1232 |
|
| 1233 |
-- Parsed by P_Constraint_Opt (3.2.2) |
| 1234 |
|
| 1235 |
--------------------------------- |
| 1236 |
-- 3.2.2 Composite Constraint -- |
| 1237 |
--------------------------------- |
| 1238 |
|
| 1239 |
-- Parsed by P_Constraint_Opt (3.2.2) |
| 1240 |
|
| 1241 |
-------------------------------------------------------- |
| 1242 |
-- 3.3 Identifier Declarations (Also 7.4, 8.5, 11.1) -- |
| 1243 |
-------------------------------------------------------- |
| 1244 |
|
| 1245 |
-- This routine scans out a declaration starting with an identifier: |
| 1246 |
|
| 1247 |
-- OBJECT_DECLARATION ::= |
| 1248 |
-- DEFINING_IDENTIFIER_LIST : [aliased] [constant] |
| 1249 |
-- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION] |
| 1250 |
-- [ASPECT_SPECIFICATIONS]; |
| 1251 |
-- | DEFINING_IDENTIFIER_LIST : [aliased] [constant] |
| 1252 |
-- ACCESS_DEFINITION [:= EXPRESSION] |
| 1253 |
-- [ASPECT_SPECIFICATIONS]; |
| 1254 |
-- | DEFINING_IDENTIFIER_LIST : [aliased] [constant] |
| 1255 |
-- ARRAY_TYPE_DEFINITION [:= EXPRESSION] |
| 1256 |
-- [ASPECT_SPECIFICATIONS]; |
| 1257 |
|
| 1258 |
-- NUMBER_DECLARATION ::= |
| 1259 |
-- DEFINING_IDENTIFIER_LIST : constant ::= static_EXPRESSION; |
| 1260 |
|
| 1261 |
-- OBJECT_RENAMING_DECLARATION ::= |
| 1262 |
-- DEFINING_IDENTIFIER : |
| 1263 |
-- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME |
| 1264 |
-- [ASPECT_SPECIFICATIONS]; |
| 1265 |
-- | DEFINING_IDENTIFIER : |
| 1266 |
-- ACCESS_DEFINITION renames object_NAME |
| 1267 |
-- [ASPECT_SPECIFICATIONS]; |
| 1268 |
|
| 1269 |
-- EXCEPTION_RENAMING_DECLARATION ::= |
| 1270 |
-- DEFINING_IDENTIFIER : exception renames exception_NAME |
| 1271 |
-- [ASPECT_SPECIFICATIONS]; |
| 1272 |
|
| 1273 |
-- EXCEPTION_DECLARATION ::= |
| 1274 |
-- DEFINING_IDENTIFIER_LIST : exception |
| 1275 |
-- [ASPECT_SPECIFICATIONS]; |
| 1276 |
|
| 1277 |
-- Note that the ALIASED indication in an object declaration is |
| 1278 |
-- marked by a flag in the parent node. |
| 1279 |
|
| 1280 |
-- The caller has checked that the initial token is an identifier |
| 1281 |
|
| 1282 |
-- The value returned is a list of declarations, one for each identifier |
| 1283 |
-- in the list (as described in Sinfo, we always split up multiple |
| 1284 |
-- declarations into the equivalent sequence of single declarations |
| 1285 |
-- using the More_Ids and Prev_Ids flags to preserve the source). |
| 1286 |
|
| 1287 |
-- If the identifier turns out to be a probable statement rather than |
| 1288 |
-- an identifier, then the scan is left pointing to the identifier and |
| 1289 |
-- No_List is returned. |
| 1290 |
|
| 1291 |
-- Error recovery: can raise Error_Resync |
| 1292 |
|
| 1293 |
procedure P_Identifier_Declarations |
| 1294 |
(Decls : List_Id; |
| 1295 |
Done : out Boolean; |
| 1296 |
In_Spec : Boolean; |
| 1297 |
In_Statements : Boolean) |
| 1298 |
is |
| 1299 |
Acc_Node : Node_Id; |
| 1300 |
Decl_Node : Node_Id; |
| 1301 |
Type_Node : Node_Id; |
| 1302 |
Ident_Sloc : Source_Ptr; |
| 1303 |
Scan_State : Saved_Scan_State; |
| 1304 |
List_OK : Boolean := True; |
| 1305 |
Ident : Nat; |
| 1306 |
Init_Expr : Node_Id; |
| 1307 |
Init_Loc : Source_Ptr; |
| 1308 |
Con_Loc : Source_Ptr; |
| 1309 |
Not_Null_Present : Boolean := False; |
| 1310 |
|
| 1311 |
Idents : array (Int range 1 .. 4096) of Entity_Id; |
| 1312 |
-- Used to save identifiers in the identifier list. The upper bound |
| 1313 |
-- of 4096 is expected to be infinite in practice, and we do not even |
| 1314 |
-- bother to check if this upper bound is exceeded. |
| 1315 |
|
| 1316 |
Num_Idents : Nat := 1; |
| 1317 |
-- Number of identifiers stored in Idents |
| 1318 |
|
| 1319 |
function Identifier_Starts_Statement return Boolean; |
| 1320 |
-- Called with Token being an identifier that might start a declaration |
| 1321 |
-- or a statement. True if we are parsing declarations in a sequence of |
| 1322 |
-- statements, and this identifier is the start of a statement. If this |
| 1323 |
-- is true, we quit parsing declarations, and return Done = True so the |
| 1324 |
-- caller will switch to parsing statements. |
| 1325 |
|
| 1326 |
procedure No_List; |
| 1327 |
-- This procedure is called in renames cases to make sure that we do |
| 1328 |
-- not have more than one identifier. If we do have more than one |
| 1329 |
-- then an error message is issued (and the declaration is split into |
| 1330 |
-- multiple declarations) |
| 1331 |
|
| 1332 |
function Token_Is_Renames return Boolean; |
| 1333 |
-- Checks if current token is RENAMES, and if so, scans past it and |
| 1334 |
-- returns True, otherwise returns False. Includes checking for some |
| 1335 |
-- common error cases. |
| 1336 |
|
| 1337 |
--------------------------------- |
| 1338 |
-- Identifier_Starts_Statement -- |
| 1339 |
--------------------------------- |
| 1340 |
|
| 1341 |
function Identifier_Starts_Statement return Boolean is |
| 1342 |
pragma Assert (Token = Tok_Identifier); |
| 1343 |
Scan_State : Saved_Scan_State; |
| 1344 |
Result : Boolean := False; |
| 1345 |
begin |
| 1346 |
if not In_Statements then |
| 1347 |
return False; |
| 1348 |
end if; |
| 1349 |
|
| 1350 |
Save_Scan_State (Scan_State); |
| 1351 |
Scan; |
| 1352 |
|
| 1353 |
case Token is |
| 1354 |
when Tok_Comma => -- "X, ..." is a declaration |
| 1355 |
null; |
| 1356 |
|
| 1357 |
when Tok_Colon => |
| 1358 |
-- "X : ..." is usually a declaration, but "X : begin..." is |
| 1359 |
-- not. We return true for things like "X : Y : begin...", |
| 1360 |
-- which is a syntax error, because that gives better error |
| 1361 |
-- recovery for some ACATS. |
| 1362 |
|
| 1363 |
Scan; |
| 1364 |
|
| 1365 |
if Token in Token_Class_Labeled_Stmt then |
| 1366 |
Result := True; |
| 1367 |
|
| 1368 |
elsif Token = Tok_Identifier then |
| 1369 |
Scan; |
| 1370 |
if Token = Tok_Colon then |
| 1371 |
Scan; |
| 1372 |
if Token in Token_Class_Labeled_Stmt then |
| 1373 |
Result := True; |
| 1374 |
end if; |
| 1375 |
end if; |
| 1376 |
end if; |
| 1377 |
|
| 1378 |
when others => |
| 1379 |
Result := True; |
| 1380 |
end case; |
| 1381 |
|
| 1382 |
Restore_Scan_State (Scan_State); |
| 1383 |
return Result; |
| 1384 |
end Identifier_Starts_Statement; |
| 1385 |
|
| 1386 |
------------- |
| 1387 |
-- No_List -- |
| 1388 |
------------- |
| 1389 |
|
| 1390 |
procedure No_List is |
| 1391 |
begin |
| 1392 |
if Num_Idents > 1 then |
| 1393 |
Error_Msg_N |
| 1394 |
("identifier list not allowed for RENAMES", |
| 1395 |
Idents (2)); |
| 1396 |
end if; |
| 1397 |
|
| 1398 |
List_OK := False; |
| 1399 |
end No_List; |
| 1400 |
|
| 1401 |
---------------------- |
| 1402 |
-- Token_Is_Renames -- |
| 1403 |
---------------------- |
| 1404 |
|
| 1405 |
function Token_Is_Renames return Boolean is |
| 1406 |
At_Colon : Saved_Scan_State; |
| 1407 |
|
| 1408 |
begin |
| 1409 |
if Token = Tok_Colon then |
| 1410 |
Save_Scan_State (At_Colon); |
| 1411 |
Scan; -- past colon |
| 1412 |
Check_Misspelling_Of (Tok_Renames); |
| 1413 |
|
| 1414 |
if Token = Tok_Renames then |
| 1415 |
Error_Msg_SP -- CODEFIX |
| 1416 |
("|extra "":"" ignored"); |
| 1417 |
Scan; -- past RENAMES |
| 1418 |
return True; |
| 1419 |
else |
| 1420 |
Restore_Scan_State (At_Colon); |
| 1421 |
return False; |
| 1422 |
end if; |
| 1423 |
|
| 1424 |
else |
| 1425 |
Check_Misspelling_Of (Tok_Renames); |
| 1426 |
|
| 1427 |
if Token = Tok_Renames then |
| 1428 |
Scan; -- past RENAMES |
| 1429 |
return True; |
| 1430 |
else |
| 1431 |
return False; |
| 1432 |
end if; |
| 1433 |
end if; |
| 1434 |
end Token_Is_Renames; |
| 1435 |
|
| 1436 |
-- Start of processing for P_Identifier_Declarations |
| 1437 |
|
| 1438 |
begin |
| 1439 |
if Identifier_Starts_Statement then |
| 1440 |
Done := True; |
| 1441 |
return; |
| 1442 |
end if; |
| 1443 |
|
| 1444 |
Ident_Sloc := Token_Ptr; |
| 1445 |
Save_Scan_State (Scan_State); -- at first identifier |
| 1446 |
Idents (1) := P_Defining_Identifier (C_Comma_Colon); |
| 1447 |
|
| 1448 |
-- If we have a colon after the identifier, then we can assume that |
| 1449 |
-- this is in fact a valid identifier declaration and can steam ahead. |
| 1450 |
|
| 1451 |
if Token = Tok_Colon then |
| 1452 |
Scan; -- past colon |
| 1453 |
|
| 1454 |
-- If we have a comma, then scan out the list of identifiers |
| 1455 |
|
| 1456 |
elsif Token = Tok_Comma then |
| 1457 |
while Comma_Present loop |
| 1458 |
Num_Idents := Num_Idents + 1; |
| 1459 |
Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon); |
| 1460 |
end loop; |
| 1461 |
|
| 1462 |
Save_Scan_State (Scan_State); -- at colon |
| 1463 |
T_Colon; |
| 1464 |
|
| 1465 |
-- If we have an identifier followed by := then we assume that what is |
| 1466 |
-- really meant is an assignment statement. The assignment statement |
| 1467 |
-- is scanned out and added to the list of declarations. An exception |
| 1468 |
-- occurs if the := is followed by the keyword constant, in which case |
| 1469 |
-- we assume it was meant to be a colon. |
| 1470 |
|
| 1471 |
elsif Token = Tok_Colon_Equal then |
| 1472 |
Scan; -- past := |
| 1473 |
|
| 1474 |
if Token = Tok_Constant then |
| 1475 |
Error_Msg_SP ("colon expected"); |
| 1476 |
|
| 1477 |
else |
| 1478 |
Restore_Scan_State (Scan_State); |
| 1479 |
|
| 1480 |
-- Reset Token_Node, because it already got changed from an |
| 1481 |
-- Identifier to a Defining_Identifier, and we don't want that |
| 1482 |
-- for a statement! |
| 1483 |
|
| 1484 |
Token_Node := |
| 1485 |
Make_Identifier (Sloc (Token_Node), Chars (Token_Node)); |
| 1486 |
|
| 1487 |
-- And now scan out one or more statements |
| 1488 |
|
| 1489 |
Statement_When_Declaration_Expected (Decls, Done, In_Spec); |
| 1490 |
return; |
| 1491 |
end if; |
| 1492 |
|
| 1493 |
-- If we have an IS keyword, then assume the TYPE keyword was missing |
| 1494 |
|
| 1495 |
elsif Token = Tok_Is then |
| 1496 |
Restore_Scan_State (Scan_State); |
| 1497 |
Append_To (Decls, P_Type_Declaration); |
| 1498 |
Done := False; |
| 1499 |
return; |
| 1500 |
|
| 1501 |
-- AI12-0275: Object renaming declaration without subtype_mark or |
| 1502 |
-- access_definition |
| 1503 |
|
| 1504 |
elsif Token = Tok_Renames then |
| 1505 |
Error_Msg_Ada_2022_Feature |
| 1506 |
("object renaming without subtype", Token_Ptr); |
| 1507 |
|
| 1508 |
Scan; -- past renames |
| 1509 |
|
| 1510 |
Decl_Node := |
| 1511 |
New_Node (N_Object_Renaming_Declaration, Ident_Sloc); |
| 1512 |
Set_Name (Decl_Node, P_Name); |
| 1513 |
Set_Defining_Identifier (Decl_Node, Idents (1)); |
| 1514 |
|
| 1515 |
P_Aspect_Specifications (Decl_Node, Semicolon => False); |
| 1516 |
|
| 1517 |
T_Semicolon; |
| 1518 |
|
| 1519 |
Append (Decl_Node, Decls); |
| 1520 |
Done := False; |
| 1521 |
|
| 1522 |
return; |
| 1523 |
|
| 1524 |
-- Otherwise we have an error situation |
| 1525 |
|
| 1526 |
else |
| 1527 |
Restore_Scan_State (Scan_State); |
| 1528 |
|
| 1529 |
-- First case is possible misuse of PROTECTED in Ada 83 mode. If |
| 1530 |
-- so, fix the keyword and return to scan the protected declaration. |
| 1531 |
|
| 1532 |
if Token_Name = Name_Protected then |
| 1533 |
Check_95_Keyword (Tok_Protected, Tok_Identifier); |
| 1534 |
Check_95_Keyword (Tok_Protected, Tok_Type); |
| 1535 |
Check_95_Keyword (Tok_Protected, Tok_Body); |
| 1536 |
|
| 1537 |
if Token = Tok_Protected then |
| 1538 |
Done := False; |
| 1539 |
return; |
| 1540 |
end if; |
| 1541 |
|
| 1542 |
-- Check misspelling possibilities. If so, correct the misspelling |
| 1543 |
-- and return to scan out the resulting declaration. |
| 1544 |
|
| 1545 |
elsif Bad_Spelling_Of (Tok_Function) |
| 1546 |
or else Bad_Spelling_Of (Tok_Procedure) |
| 1547 |
or else Bad_Spelling_Of (Tok_Package) |
| 1548 |
or else Bad_Spelling_Of (Tok_Pragma) |
| 1549 |
or else Bad_Spelling_Of (Tok_Protected) |
| 1550 |
or else Bad_Spelling_Of (Tok_Generic) |
| 1551 |
or else Bad_Spelling_Of (Tok_Subtype) |
| 1552 |
or else Bad_Spelling_Of (Tok_Type) |
| 1553 |
or else Bad_Spelling_Of (Tok_Task) |
| 1554 |
or else Bad_Spelling_Of (Tok_Use) |
| 1555 |
or else Bad_Spelling_Of (Tok_For) |
| 1556 |
then |
| 1557 |
Done := False; |
| 1558 |
return; |
| 1559 |
|
| 1560 |
-- Otherwise we definitely have an ordinary identifier with a junk |
| 1561 |
-- token after it. |
| 1562 |
|
| 1563 |
elsif In_Statements then |
| 1564 |
Done := True; |
| 1565 |
return; |
| 1566 |
|
| 1567 |
else |
| 1568 |
-- If in -gnatd.2 mode, try for statements |
| 1569 |
|
| 1570 |
if Debug_Flag_Dot_2 then |
| 1571 |
Restore_Scan_State (Scan_State); |
| 1572 |
|
| 1573 |
-- Reset Token_Node, because it already got changed from an |
| 1574 |
-- Identifier to a Defining_Identifier, and we don't want that |
| 1575 |
-- for a statement! |
| 1576 |
|
| 1577 |
Token_Node := |
| 1578 |
Make_Identifier (Sloc (Token_Node), Chars (Token_Node)); |
| 1579 |
|
| 1580 |
-- And now scan out one or more statements |
| 1581 |
|
| 1582 |
Statement_When_Declaration_Expected (Decls, Done, In_Spec); |
| 1583 |
return; |
| 1584 |
|
| 1585 |
-- Normal case, just complain and skip to semicolon |
| 1586 |
|
| 1587 |
else |
| 1588 |
Set_Declaration_Expected; |
| 1589 |
Resync_Past_Semicolon; |
| 1590 |
Done := False; |
| 1591 |
return; |
| 1592 |
end if; |
| 1593 |
end if; |
| 1594 |
end if; |
| 1595 |
|
| 1596 |
-- Come here with an identifier list and colon scanned out. We now |
| 1597 |
-- build the nodes for the declarative items. One node is built for |
| 1598 |
-- each identifier in the list, with the type information being |
| 1599 |
-- repeated by rescanning the appropriate section of source. |
| 1600 |
|
| 1601 |
-- First an error check, if we have two identifiers in a row, a likely |
| 1602 |
-- possibility is that the first of the identifiers is an incorrectly |
| 1603 |
-- spelled keyword. |
| 1604 |
|
| 1605 |
if Token = Tok_Identifier then |
| 1606 |
declare |
| 1607 |
SS : Saved_Scan_State; |
| 1608 |
I2 : Boolean; |
| 1609 |
|
| 1610 |
begin |
| 1611 |
Save_Scan_State (SS); |
| 1612 |
Scan; -- past initial identifier |
| 1613 |
I2 := (Token = Tok_Identifier); |
| 1614 |
Restore_Scan_State (SS); |
| 1615 |
|
| 1616 |
if I2 |
| 1617 |
and then |
| 1618 |
(Bad_Spelling_Of (Tok_Access) or else |
| 1619 |
Bad_Spelling_Of (Tok_Aliased) or else |
| 1620 |
Bad_Spelling_Of (Tok_Constant)) |
| 1621 |
then |
| 1622 |
null; |
| 1623 |
end if; |
| 1624 |
end; |
| 1625 |
end if; |
| 1626 |
|
| 1627 |
-- Loop through identifiers |
| 1628 |
|
| 1629 |
Ident := 1; |
| 1630 |
Ident_Loop : loop |
| 1631 |
|
| 1632 |
-- Check for some cases of misused Ada 95 keywords |
| 1633 |
|
| 1634 |
if Token_Name = Name_Aliased then |
| 1635 |
Check_95_Keyword (Tok_Aliased, Tok_Array); |
| 1636 |
Check_95_Keyword (Tok_Aliased, Tok_Identifier); |
| 1637 |
Check_95_Keyword (Tok_Aliased, Tok_Constant); |
| 1638 |
end if; |
| 1639 |
|
| 1640 |
-- Constant cases |
| 1641 |
|
| 1642 |
if Token = Tok_Constant then |
| 1643 |
Con_Loc := Token_Ptr; |
| 1644 |
Scan; -- past CONSTANT |
| 1645 |
|
| 1646 |
-- Number declaration, initialization required |
| 1647 |
|
| 1648 |
Init_Expr := Init_Expr_Opt; |
| 1649 |
|
| 1650 |
if Present (Init_Expr) then |
| 1651 |
if Not_Null_Present then |
| 1652 |
Error_Msg_SP |
| 1653 |
("`NOT NULL` not allowed in numeric expression"); |
| 1654 |
end if; |
| 1655 |
|
| 1656 |
Decl_Node := New_Node (N_Number_Declaration, Ident_Sloc); |
| 1657 |
Set_Expression (Decl_Node, Init_Expr); |
| 1658 |
|
| 1659 |
-- Constant object declaration |
| 1660 |
|
| 1661 |
else |
| 1662 |
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc); |
| 1663 |
Set_Constant_Present (Decl_Node, True); |
| 1664 |
|
| 1665 |
if Token_Name = Name_Aliased then |
| 1666 |
Check_95_Keyword (Tok_Aliased, Tok_Array); |
| 1667 |
Check_95_Keyword (Tok_Aliased, Tok_Identifier); |
| 1668 |
end if; |
| 1669 |
|
| 1670 |
if Token = Tok_Aliased then |
| 1671 |
Error_Msg_SC -- CODEFIX |
| 1672 |
("ALIASED should be before CONSTANT"); |
| 1673 |
Scan; -- past ALIASED |
| 1674 |
Set_Aliased_Present (Decl_Node, True); |
| 1675 |
end if; |
| 1676 |
|
| 1677 |
if Token = Tok_Array then |
| 1678 |
Set_Object_Definition |
| 1679 |
(Decl_Node, P_Array_Type_Definition); |
| 1680 |
|
| 1681 |
else |
| 1682 |
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231) |
| 1683 |
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present); |
| 1684 |
|
| 1685 |
if Token = Tok_Access then |
| 1686 |
Error_Msg_Ada_2005_Extension |
| 1687 |
("generalized use of anonymous access types"); |
| 1688 |
|
| 1689 |
Set_Object_Definition |
| 1690 |
(Decl_Node, P_Access_Definition (Not_Null_Present)); |
| 1691 |
else |
| 1692 |
Set_Object_Definition |
| 1693 |
(Decl_Node, P_Subtype_Indication (Not_Null_Present)); |
| 1694 |
end if; |
| 1695 |
end if; |
| 1696 |
|
| 1697 |
if Token = Tok_Renames then |
| 1698 |
Error_Msg |
| 1699 |
("CONSTANT not permitted in renaming declaration", |
| 1700 |
Con_Loc); |
| 1701 |
Scan; -- Past renames |
| 1702 |
Discard_Junk_Node (P_Name); |
| 1703 |
end if; |
| 1704 |
end if; |
| 1705 |
|
| 1706 |
-- Exception cases |
| 1707 |
|
| 1708 |
elsif Token = Tok_Exception then |
| 1709 |
Scan; -- past EXCEPTION |
| 1710 |
|
| 1711 |
if Token_Is_Renames then |
| 1712 |
No_List; |
| 1713 |
Decl_Node := |
| 1714 |
New_Node (N_Exception_Renaming_Declaration, Ident_Sloc); |
| 1715 |
Set_Name (Decl_Node, P_Qualified_Simple_Name_Resync); |
| 1716 |
No_Constraint; |
| 1717 |
else |
| 1718 |
Decl_Node := New_Node (N_Exception_Declaration, Prev_Token_Ptr); |
| 1719 |
end if; |
| 1720 |
|
| 1721 |
-- Aliased case (note that an object definition is required) |
| 1722 |
|
| 1723 |
elsif Token = Tok_Aliased then |
| 1724 |
Scan; -- past ALIASED |
| 1725 |
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc); |
| 1726 |
Set_Aliased_Present (Decl_Node, True); |
| 1727 |
|
| 1728 |
if Token = Tok_Constant then |
| 1729 |
Scan; -- past CONSTANT |
| 1730 |
Set_Constant_Present (Decl_Node, True); |
| 1731 |
end if; |
| 1732 |
|
| 1733 |
if Token = Tok_Array then |
| 1734 |
Set_Object_Definition |
| 1735 |
(Decl_Node, P_Array_Type_Definition); |
| 1736 |
|
| 1737 |
else |
| 1738 |
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231) |
| 1739 |
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present); |
| 1740 |
|
| 1741 |
-- Access definition (AI-406) or subtype indication |
| 1742 |
|
| 1743 |
if Token = Tok_Access then |
| 1744 |
Error_Msg_Ada_2005_Extension |
| 1745 |
("generalized use of anonymous access types"); |
| 1746 |
|
| 1747 |
Set_Object_Definition |
| 1748 |
(Decl_Node, P_Access_Definition (Not_Null_Present)); |
| 1749 |
else |
| 1750 |
Set_Object_Definition |
| 1751 |
(Decl_Node, P_Subtype_Indication (Not_Null_Present)); |
| 1752 |
end if; |
| 1753 |
end if; |
| 1754 |
|
| 1755 |
-- Array case |
| 1756 |
|
| 1757 |
elsif Token = Tok_Array then |
| 1758 |
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc); |
| 1759 |
Set_Object_Definition (Decl_Node, P_Array_Type_Definition); |
| 1760 |
|
| 1761 |
-- Ada 2005 (AI-254, AI-406) |
| 1762 |
|
| 1763 |
elsif Token = Tok_Not then |
| 1764 |
|
| 1765 |
-- OBJECT_DECLARATION ::= |
| 1766 |
-- DEFINING_IDENTIFIER_LIST : [aliased] [constant] |
| 1767 |
-- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION] |
| 1768 |
-- [ASPECT_SPECIFICATIONS]; |
| 1769 |
-- | DEFINING_IDENTIFIER_LIST : [aliased] [constant] |
| 1770 |
-- ACCESS_DEFINITION [:= EXPRESSION] |
| 1771 |
-- [ASPECT_SPECIFICATIONS]; |
| 1772 |
|
| 1773 |
-- OBJECT_RENAMING_DECLARATION ::= |
| 1774 |
-- DEFINING_IDENTIFIER : |
| 1775 |
-- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME |
| 1776 |
-- [ASPECT_SPECIFICATIONS]; |
| 1777 |
-- | DEFINING_IDENTIFIER : |
| 1778 |
-- ACCESS_DEFINITION renames object_NAME |
| 1779 |
-- [ASPECT_SPECIFICATIONS]; |
| 1780 |
|
| 1781 |
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231/423) |
| 1782 |
|
| 1783 |
if Token = Tok_Access then |
| 1784 |
Error_Msg_Ada_2005_Extension |
| 1785 |
("generalized use of anonymous access types"); |
| 1786 |
|
| 1787 |
Acc_Node := P_Access_Definition (Not_Null_Present); |
| 1788 |
|
| 1789 |
if Token /= Tok_Renames then |
| 1790 |
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc); |
| 1791 |
Set_Object_Definition (Decl_Node, Acc_Node); |
| 1792 |
|
| 1793 |
else |
| 1794 |
Scan; -- past renames |
| 1795 |
No_List; |
| 1796 |
Decl_Node := |
| 1797 |
New_Node (N_Object_Renaming_Declaration, Ident_Sloc); |
| 1798 |
Set_Access_Definition (Decl_Node, Acc_Node); |
| 1799 |
Set_Name (Decl_Node, P_Name); |
| 1800 |
end if; |
| 1801 |
|
| 1802 |
else |
| 1803 |
Type_Node := P_Subtype_Mark; |
| 1804 |
|
| 1805 |
-- Object renaming declaration |
| 1806 |
|
| 1807 |
if Token_Is_Renames then |
| 1808 |
if Ada_Version < Ada_2005 then |
| 1809 |
Error_Msg_SP |
| 1810 |
("`NOT NULL` not allowed in object renaming"); |
| 1811 |
raise Error_Resync; |
| 1812 |
|
| 1813 |
-- Ada 2005 (AI-423): Object renaming declaration with |
| 1814 |
-- a null exclusion. |
| 1815 |
|
| 1816 |
else |
| 1817 |
No_List; |
| 1818 |
Decl_Node := |
| 1819 |
New_Node (N_Object_Renaming_Declaration, Ident_Sloc); |
| 1820 |
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present); |
| 1821 |
Set_Subtype_Mark (Decl_Node, Type_Node); |
| 1822 |
Set_Name (Decl_Node, P_Name); |
| 1823 |
end if; |
| 1824 |
|
| 1825 |
-- Object declaration |
| 1826 |
|
| 1827 |
else |
| 1828 |
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc); |
| 1829 |
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present); |
| 1830 |
Set_Object_Definition |
| 1831 |
(Decl_Node, |
| 1832 |
P_Subtype_Indication (Type_Node, Not_Null_Present)); |
| 1833 |
|
| 1834 |
-- RENAMES at this point means that we had the combination |
| 1835 |
-- of a constraint on the Type_Node and renames, which is |
| 1836 |
-- illegal |
| 1837 |
|
| 1838 |
if Token_Is_Renames then |
| 1839 |
Error_Msg_N |
| 1840 |
("constraint not allowed in object renaming " |
| 1841 |
& "declaration", |
| 1842 |
Constraint (Object_Definition (Decl_Node))); |
| 1843 |
raise Error_Resync; |
| 1844 |
end if; |
| 1845 |
end if; |
| 1846 |
end if; |
| 1847 |
|
| 1848 |
-- Ada 2005 (AI-230): Access Definition case |
| 1849 |
|
| 1850 |
elsif Token = Tok_Access then |
| 1851 |
Error_Msg_Ada_2005_Extension |
| 1852 |
("generalized use of anonymous access types"); |
| 1853 |
|
| 1854 |
Acc_Node := P_Access_Definition (Null_Exclusion_Present => False); |
| 1855 |
|
| 1856 |
-- Object declaration with access definition, or renaming |
| 1857 |
|
| 1858 |
if Token /= Tok_Renames then |
| 1859 |
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc); |
| 1860 |
Set_Object_Definition (Decl_Node, Acc_Node); |
| 1861 |
|
| 1862 |
else |
| 1863 |
Scan; -- past renames |
| 1864 |
No_List; |
| 1865 |
Decl_Node := |
| 1866 |
New_Node (N_Object_Renaming_Declaration, Ident_Sloc); |
| 1867 |
Set_Access_Definition (Decl_Node, Acc_Node); |
| 1868 |
Set_Name (Decl_Node, P_Name); |
| 1869 |
end if; |
| 1870 |
|
| 1871 |
-- Subtype indication case |
| 1872 |
|
| 1873 |
else |
| 1874 |
Type_Node := P_Subtype_Mark; |
| 1875 |
|
| 1876 |
-- Object renaming declaration |
| 1877 |
|
| 1878 |
if Token_Is_Renames then |
| 1879 |
No_List; |
| 1880 |
Decl_Node := |
| 1881 |
New_Node (N_Object_Renaming_Declaration, Ident_Sloc); |
| 1882 |
Set_Subtype_Mark (Decl_Node, Type_Node); |
| 1883 |
Set_Name (Decl_Node, P_Name); |
| 1884 |
|
| 1885 |
-- Object declaration |
| 1886 |
|
| 1887 |
else |
| 1888 |
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc); |
| 1889 |
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present); |
| 1890 |
Set_Object_Definition |
| 1891 |
(Decl_Node, |
| 1892 |
P_Subtype_Indication (Type_Node, Not_Null_Present)); |
| 1893 |
|
| 1894 |
-- RENAMES at this point means that we had the combination of |
| 1895 |
-- a constraint on the Type_Node and renames, which is illegal |
| 1896 |
|
| 1897 |
if Token_Is_Renames then |
| 1898 |
Error_Msg_N |
| 1899 |
("constraint not allowed in object renaming declaration", |
| 1900 |
Constraint (Object_Definition (Decl_Node))); |
| 1901 |
raise Error_Resync; |
| 1902 |
end if; |
| 1903 |
end if; |
| 1904 |
end if; |
| 1905 |
|
| 1906 |
-- Scan out initialization, allowed only for object declaration |
| 1907 |
|
| 1908 |
Init_Loc := Token_Ptr; |
| 1909 |
Init_Expr := Init_Expr_Opt; |
| 1910 |
|
| 1911 |
if Present (Init_Expr) then |
| 1912 |
if Nkind (Decl_Node) = N_Object_Declaration then |
| 1913 |
Set_Expression (Decl_Node, Init_Expr); |
| 1914 |
Set_Has_Init_Expression (Decl_Node); |
| 1915 |
else |
| 1916 |
Error_Msg ("initialization not allowed here", Init_Loc); |
| 1917 |
end if; |
| 1918 |
end if; |
| 1919 |
|
| 1920 |
Set_Defining_Identifier (Decl_Node, Idents (Ident)); |
| 1921 |
P_Aspect_Specifications (Decl_Node, Semicolon => False); |
| 1922 |
|
| 1923 |
-- Allow initialization expression to follow aspects (note that in |
| 1924 |
-- this case P_Aspect_Specifications already issued an error msg). |
| 1925 |
|
| 1926 |
if Token = Tok_Colon_Equal then |
| 1927 |
if Is_Non_Empty_List (Aspect_Specifications (Decl_Node)) then |
| 1928 |
Error_Msg |
| 1929 |
("aspect specifications must come after initialization " |
| 1930 |
& "expression", |
| 1931 |
Sloc (First (Aspect_Specifications (Decl_Node)))); |
| 1932 |
|
| 1933 |
else |
| 1934 |
-- In any case, the assignment symbol doesn't belong. |
| 1935 |
|
| 1936 |
Error_Msg ("misplaced assignment symbol", Scan_Ptr); |
| 1937 |
end if; |
| 1938 |
|
| 1939 |
Set_Expression (Decl_Node, Init_Expr_Opt); |
| 1940 |
Set_Has_Init_Expression (Decl_Node); |
| 1941 |
end if; |
| 1942 |
|
| 1943 |
-- Now scan out the semicolon, which we deferred above |
| 1944 |
|
| 1945 |
T_Semicolon; |
| 1946 |
|
| 1947 |
if List_OK then |
| 1948 |
if Ident < Num_Idents then |
| 1949 |
Set_More_Ids (Decl_Node, True); |
| 1950 |
end if; |
| 1951 |
|
| 1952 |
if Ident > 1 then |
| 1953 |
Set_Prev_Ids (Decl_Node, True); |
| 1954 |
end if; |
| 1955 |
end if; |
| 1956 |
|
| 1957 |
Append (Decl_Node, Decls); |
| 1958 |
exit Ident_Loop when Ident = Num_Idents; |
| 1959 |
Restore_Scan_State (Scan_State); |
| 1960 |
T_Colon; |
| 1961 |
Ident := Ident + 1; |
| 1962 |
end loop Ident_Loop; |
| 1963 |
|
| 1964 |
Done := False; |
| 1965 |
end P_Identifier_Declarations; |
| 1966 |
|
| 1967 |
------------------------------- |
| 1968 |
-- 3.3.1 Object Declaration -- |
| 1969 |
------------------------------- |
| 1970 |
|
| 1971 |
-- OBJECT DECLARATION ::= |
| 1972 |
-- DEFINING_IDENTIFIER_LIST : [aliased] [constant] |
| 1973 |
-- SUBTYPE_INDICATION [:= EXPRESSION]; |
| 1974 |
-- | DEFINING_IDENTIFIER_LIST : [aliased] [constant] |
| 1975 |
-- ARRAY_TYPE_DEFINITION [:= EXPRESSION]; |
| 1976 |
-- | SINGLE_TASK_DECLARATION |
| 1977 |
-- | SINGLE_PROTECTED_DECLARATION |
| 1978 |
|
| 1979 |
-- Cases starting with TASK are parsed by P_Task (9.1) |
| 1980 |
-- Cases starting with PROTECTED are parsed by P_Protected (9.4) |
| 1981 |
-- All other cases are parsed by P_Identifier_Declarations (3.3) |
| 1982 |
|
| 1983 |
------------------------------------- |
| 1984 |
-- 3.3.1 Defining Identifier List -- |
| 1985 |
------------------------------------- |
| 1986 |
|
| 1987 |
-- DEFINING_IDENTIFIER_LIST ::= |
| 1988 |
-- DEFINING_IDENTIFIER {, DEFINING_IDENTIFIER} |
| 1989 |
|
| 1990 |
-- Always parsed by the construct in which it appears. See special |
| 1991 |
-- section on "Handling of Defining Identifier Lists" in this unit. |
| 1992 |
|
| 1993 |
------------------------------- |
| 1994 |
-- 3.3.2 Number Declaration -- |
| 1995 |
------------------------------- |
| 1996 |
|
| 1997 |
-- Parsed by P_Identifier_Declarations (3.3) |
| 1998 |
|
| 1999 |
------------------------------------------------------------------------- |
| 2000 |
-- 3.4 Derived Type Definition or Private Extension Declaration (7.3) -- |
| 2001 |
------------------------------------------------------------------------- |
| 2002 |
|
| 2003 |
-- DERIVED_TYPE_DEFINITION ::= |
| 2004 |
-- [abstract] [limited] new [NULL_EXCLUSION] parent_SUBTYPE_INDICATION |
| 2005 |
-- [[and INTERFACE_LIST] RECORD_EXTENSION_PART] |
| 2006 |
|
| 2007 |
-- PRIVATE_EXTENSION_DECLARATION ::= |
| 2008 |
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is |
| 2009 |
-- [abstract] [limited | synchronized] |
| 2010 |
-- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST] |
| 2011 |
-- with private [ASPECT_SPECIFICATIONS]; |
| 2012 |
|
| 2013 |
-- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION |
| 2014 |
|
| 2015 |
-- The caller has already scanned out the part up to the NEW, and Token |
| 2016 |
-- either contains Tok_New (or ought to, if it doesn't this procedure |
| 2017 |
-- will post an appropriate "NEW expected" message). |
| 2018 |
|
| 2019 |
-- Note: the caller is responsible for filling in the Sloc field of |
| 2020 |
-- the returned node in the private extension declaration case as |
| 2021 |
-- well as the stuff relating to the discriminant part. |
| 2022 |
|
| 2023 |
-- Error recovery: can raise Error_Resync; |
| 2024 |
|
| 2025 |
function P_Derived_Type_Def_Or_Private_Ext_Decl return Node_Id is |
| 2026 |
Typedef_Node : Node_Id; |
| 2027 |
Typedecl_Node : Node_Id; |
| 2028 |
Not_Null_Present : Boolean := False; |
| 2029 |
|
| 2030 |
begin |
| 2031 |
Typedef_Node := New_Node (N_Derived_Type_Definition, Token_Ptr); |
| 2032 |
|
| 2033 |
if Ada_Version < Ada_2005 |
| 2034 |
and then Token = Tok_Identifier |
| 2035 |
and then Token_Name = Name_Interface |
| 2036 |
then |
| 2037 |
Error_Msg_SP |
| 2038 |
("abstract interface is an Ada 2005 extension"); |
| 2039 |
Error_Msg_SP ("\unit must be compiled with -gnat05 switch"); |
| 2040 |
else |
| 2041 |
T_New; |
| 2042 |
end if; |
| 2043 |
|
| 2044 |
if Token = Tok_Abstract then |
| 2045 |
Error_Msg_SC -- CODEFIX |
| 2046 |
("ABSTRACT must come before NEW, not after"); |
| 2047 |
Scan; |
| 2048 |
end if; |
| 2049 |
|
| 2050 |
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231) |
| 2051 |
Set_Null_Exclusion_Present (Typedef_Node, Not_Null_Present); |
| 2052 |
Set_Subtype_Indication (Typedef_Node, |
| 2053 |
P_Subtype_Indication (Not_Null_Present)); |
| 2054 |
|
| 2055 |
-- Ada 2005 (AI-251): Deal with interfaces |
| 2056 |
|
| 2057 |
if Token = Tok_And then |
| 2058 |
Scan; -- past AND |
| 2059 |
|
| 2060 |
Error_Msg_Ada_2005_Extension ("abstract interface"); |
| 2061 |
|
| 2062 |
Set_Interface_List (Typedef_Node, New_List); |
| 2063 |
|
| 2064 |
loop |
| 2065 |
Append (P_Qualified_Simple_Name, Interface_List (Typedef_Node)); |
| 2066 |
exit when Token /= Tok_And; |
| 2067 |
Scan; -- past AND |
| 2068 |
end loop; |
| 2069 |
|
| 2070 |
if Token /= Tok_With then |
| 2071 |
Error_Msg_SC ("WITH expected"); |
| 2072 |
raise Error_Resync; |
| 2073 |
end if; |
| 2074 |
end if; |
| 2075 |
|
| 2076 |
-- Deal with record extension, note that we assume that a WITH is |
| 2077 |
-- missing in the case of "type X is new Y record ..." or in the |
| 2078 |
-- case of "type X is new Y null record". |
| 2079 |
|
| 2080 |
-- First make sure we don't have an aspect specification. If we do |
| 2081 |
-- return now, so that our caller can check it (the WITH here is not |
| 2082 |
-- part of a type extension). |
| 2083 |
|
| 2084 |
if Aspect_Specifications_Present then |
| 2085 |
return Typedef_Node; |
| 2086 |
|
| 2087 |
-- OK, not an aspect specification, so continue test for extension |
| 2088 |
|
| 2089 |
elsif Token in Tok_With | Tok_Record | Tok_Null then |
| 2090 |
T_With; -- past WITH or give error message |
| 2091 |
|
| 2092 |
if Token = Tok_Limited then |
| 2093 |
Error_Msg_SC ("LIMITED keyword not allowed in private extension"); |
| 2094 |
Scan; -- ignore LIMITED |
| 2095 |
end if; |
| 2096 |
|
| 2097 |
-- Private extension declaration |
| 2098 |
|
| 2099 |
if Token = Tok_Private then |
| 2100 |
Scan; -- past PRIVATE |
| 2101 |
|
| 2102 |
-- Throw away the type definition node and build the type |
| 2103 |
-- declaration node. Note the caller must set the Sloc, |
| 2104 |
-- Discriminant_Specifications, Unknown_Discriminants_Present, |
| 2105 |
-- and Defined_Identifier fields in the returned node. |
| 2106 |
|
| 2107 |
Typedecl_Node := |
| 2108 |
Make_Private_Extension_Declaration (No_Location, |
| 2109 |
Defining_Identifier => Empty, |
| 2110 |
Subtype_Indication => Subtype_Indication (Typedef_Node), |
| 2111 |
Abstract_Present => Abstract_Present (Typedef_Node), |
| 2112 |
Interface_List => Interface_List (Typedef_Node)); |
| 2113 |
|
| 2114 |
return Typedecl_Node; |
| 2115 |
|
| 2116 |
-- Derived type definition with record extension part |
| 2117 |
|
| 2118 |
else |
| 2119 |
Set_Record_Extension_Part (Typedef_Node, P_Record_Definition); |
| 2120 |
return Typedef_Node; |
| 2121 |
end if; |
| 2122 |
|
| 2123 |
-- Derived type definition with no record extension part |
| 2124 |
|
| 2125 |
else |
| 2126 |
return Typedef_Node; |
| 2127 |
end if; |
| 2128 |
end P_Derived_Type_Def_Or_Private_Ext_Decl; |
| 2129 |
|
| 2130 |
--------------------------- |
| 2131 |
-- 3.5 Range Constraint -- |
| 2132 |
--------------------------- |
| 2133 |
|
| 2134 |
-- RANGE_CONSTRAINT ::= range RANGE |
| 2135 |
|
| 2136 |
-- The caller has checked that the initial token is RANGE or some |
| 2137 |
-- misspelling of it, or it may be absent completely (and a message |
| 2138 |
-- has already been issued). |
| 2139 |
|
| 2140 |
-- Error recovery: cannot raise Error_Resync |
| 2141 |
|
| 2142 |
function P_Range_Constraint return Node_Id is |
| 2143 |
Range_Node : Node_Id; |
| 2144 |
|
| 2145 |
begin |
| 2146 |
Range_Node := New_Node (N_Range_Constraint, Token_Ptr); |
| 2147 |
|
| 2148 |
-- Skip range keyword if present |
| 2149 |
|
| 2150 |
if Token = Tok_Range or else Bad_Spelling_Of (Tok_Range) then |
| 2151 |
Scan; -- past RANGE |
| 2152 |
end if; |
| 2153 |
|
| 2154 |
Set_Range_Expression (Range_Node, P_Range); |
| 2155 |
return Range_Node; |
| 2156 |
end P_Range_Constraint; |
| 2157 |
|
| 2158 |
---------------- |
| 2159 |
-- 3.5 Range -- |
| 2160 |
---------------- |
| 2161 |
|
| 2162 |
-- RANGE ::= |
| 2163 |
-- RANGE_ATTRIBUTE_REFERENCE | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION |
| 2164 |
|
| 2165 |
-- Note: the range that appears in a membership test is parsed by |
| 2166 |
-- P_Range_Or_Subtype_Mark (3.5). |
| 2167 |
|
| 2168 |
-- Error recovery: cannot raise Error_Resync |
| 2169 |
|
| 2170 |
function P_Range return Node_Id is |
| 2171 |
Expr_Node : Node_Id; |
| 2172 |
Range_Node : Node_Id; |
| 2173 |
|
| 2174 |
begin |
| 2175 |
Expr_Node := P_Simple_Expression_Or_Range_Attribute; |
| 2176 |
|
| 2177 |
if Expr_Form = EF_Range_Attr then |
| 2178 |
return Expr_Node; |
| 2179 |
|
| 2180 |
elsif Token = Tok_Dot_Dot then |
| 2181 |
Range_Node := New_Node (N_Range, Token_Ptr); |
| 2182 |
Set_Low_Bound (Range_Node, Expr_Node); |
| 2183 |
Scan; -- past .. |
| 2184 |
Expr_Node := P_Expression; |
| 2185 |
Check_Simple_Expression (Expr_Node); |
| 2186 |
Set_High_Bound (Range_Node, Expr_Node); |
| 2187 |
return Range_Node; |
| 2188 |
|
| 2189 |
-- Anything else is an error |
| 2190 |
|
| 2191 |
else |
| 2192 |
T_Dot_Dot; -- force missing .. message |
| 2193 |
return Error; |
| 2194 |
end if; |
| 2195 |
end P_Range; |
| 2196 |
|
| 2197 |
---------------------------------- |
| 2198 |
-- 3.5 P_Range_Or_Subtype_Mark -- |
| 2199 |
---------------------------------- |
| 2200 |
|
| 2201 |
-- RANGE ::= |
| 2202 |
-- RANGE_ATTRIBUTE_REFERENCE |
| 2203 |
-- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION |
| 2204 |
|
| 2205 |
-- This routine scans out the range or subtype mark that forms the right |
| 2206 |
-- operand of a membership test (it is not used in any other contexts, and |
| 2207 |
-- error messages are specialized with this knowledge in mind). |
| 2208 |
|
| 2209 |
-- Note: as documented in the Sinfo interface, although the syntax only |
| 2210 |
-- allows a subtype mark, we in fact allow any simple expression to be |
| 2211 |
-- returned from this routine. The semantics is responsible for issuing |
| 2212 |
-- an appropriate message complaining if the argument is not a name. |
| 2213 |
-- This simplifies the coding and error recovery processing in the |
| 2214 |
-- parser, and in any case it is preferable not to consider this a |
| 2215 |
-- syntax error and to continue with the semantic analysis. |
| 2216 |
|
| 2217 |
-- Error recovery: cannot raise Error_Resync |
| 2218 |
|
| 2219 |
function P_Range_Or_Subtype_Mark |
| 2220 |
(Allow_Simple_Expression : Boolean := False) return Node_Id |
| 2221 |
is |
| 2222 |
Expr_Node : Node_Id; |
| 2223 |
Range_Node : Node_Id; |
| 2224 |
Save_Loc : Source_Ptr; |
| 2225 |
|
| 2226 |
-- Start of processing for P_Range_Or_Subtype_Mark |
| 2227 |
|
| 2228 |
begin |
| 2229 |
-- Save location of possible junk parentheses |
| 2230 |
|
| 2231 |
Save_Loc := Token_Ptr; |
| 2232 |
|
| 2233 |
-- Scan out either a simple expression or a range (this accepts more |
| 2234 |
-- than is legal here, but as explained above, we like to allow more |
| 2235 |
-- with a proper diagnostic, and in the case of a membership operation |
| 2236 |
-- where sets are allowed, a simple expression is permissible anyway. |
| 2237 |
|
| 2238 |
Expr_Node := P_Simple_Expression_Or_Range_Attribute; |
| 2239 |
|
| 2240 |
-- Range attribute |
| 2241 |
|
| 2242 |
if Expr_Form = EF_Range_Attr then |
| 2243 |
return Expr_Node; |
| 2244 |
|
| 2245 |
-- Simple_Expression .. Simple_Expression |
| 2246 |
|
| 2247 |
elsif Token = Tok_Dot_Dot then |
| 2248 |
Check_Simple_Expression (Expr_Node); |
| 2249 |
Range_Node := New_Node (N_Range, Token_Ptr); |
| 2250 |
Set_Low_Bound (Range_Node, Expr_Node); |
| 2251 |
Scan; -- past .. |
| 2252 |
Set_High_Bound (Range_Node, P_Simple_Expression); |
| 2253 |
return Range_Node; |
| 2254 |
|
| 2255 |
-- Case of subtype mark (optionally qualified simple name or an |
| 2256 |
-- attribute whose prefix is an optionally qualified simple name) |
| 2257 |
|
| 2258 |
elsif Expr_Form = EF_Simple_Name |
| 2259 |
or else Nkind (Expr_Node) = N_Attribute_Reference |
| 2260 |
then |
| 2261 |
-- Check for error of range constraint after a subtype mark |
| 2262 |
|
| 2263 |
if Token = Tok_Range then |
| 2264 |
Error_Msg_SC ("range constraint not allowed in membership test"); |
| 2265 |
Scan; -- past RANGE |
| 2266 |
raise Error_Resync; |
| 2267 |
|
| 2268 |
-- Check for error of DIGITS or DELTA after a subtype mark |
| 2269 |
|
| 2270 |
elsif Token in Tok_Digits | Tok_Delta then |
| 2271 |
Error_Msg_SC |
| 2272 |
("accuracy definition not allowed in membership test"); |
| 2273 |
Scan; -- past DIGITS or DELTA |
| 2274 |
raise Error_Resync; |
| 2275 |
|
| 2276 |
-- Attribute reference, may or may not be OK, but in any case we |
| 2277 |
-- will scan it out |
| 2278 |
|
| 2279 |
elsif Token = Tok_Apostrophe then |
| 2280 |
return P_Subtype_Mark_Attribute (Expr_Node); |
| 2281 |
|
| 2282 |
-- OK case of simple name, just return it |
| 2283 |
|
| 2284 |
else |
| 2285 |
return Expr_Node; |
| 2286 |
end if; |
| 2287 |
|
| 2288 |
-- Simple expression case |
| 2289 |
|
| 2290 |
elsif Expr_Form = EF_Simple and then Allow_Simple_Expression then |
| 2291 |
return Expr_Node; |
| 2292 |
|
| 2293 |
-- Here we have some kind of error situation. Check for junk parens |
| 2294 |
-- then return what we have, caller will deal with other errors. |
| 2295 |
|
| 2296 |
else |
| 2297 |
if Nkind (Expr_Node) in N_Subexpr |
| 2298 |
and then Paren_Count (Expr_Node) /= 0 |
| 2299 |
then |
| 2300 |
Error_Msg ("|parentheses not allowed for subtype mark", Save_Loc); |
| 2301 |
Set_Paren_Count (Expr_Node, 0); |
| 2302 |
end if; |
| 2303 |
|
| 2304 |
return Expr_Node; |
| 2305 |
end if; |
| 2306 |
end P_Range_Or_Subtype_Mark; |
| 2307 |
|
| 2308 |
---------------------------------------- |
| 2309 |
-- 3.5.1 Enumeration Type Definition -- |
| 2310 |
---------------------------------------- |
| 2311 |
|
| 2312 |
-- ENUMERATION_TYPE_DEFINITION ::= |
| 2313 |
-- (ENUMERATION_LITERAL_SPECIFICATION |
| 2314 |
-- {, ENUMERATION_LITERAL_SPECIFICATION}) |
| 2315 |
|
| 2316 |
-- The caller has already scanned out the TYPE keyword |
| 2317 |
|
| 2318 |
-- Error recovery: can raise Error_Resync; |
| 2319 |
|
| 2320 |
function P_Enumeration_Type_Definition return Node_Id is |
| 2321 |
Typedef_Node : Node_Id; |
| 2322 |
|
| 2323 |
begin |
| 2324 |
Typedef_Node := New_Node (N_Enumeration_Type_Definition, Token_Ptr); |
| 2325 |
Set_Literals (Typedef_Node, New_List); |
| 2326 |
|
| 2327 |
T_Left_Paren; |
| 2328 |
|
| 2329 |
loop |
| 2330 |
Append (P_Enumeration_Literal_Specification, Literals (Typedef_Node)); |
| 2331 |
exit when not Comma_Present; |
| 2332 |
end loop; |
| 2333 |
|
| 2334 |
T_Right_Paren; |
| 2335 |
return Typedef_Node; |
| 2336 |
end P_Enumeration_Type_Definition; |
| 2337 |
|
| 2338 |
---------------------------------------------- |
| 2339 |
-- 3.5.1 Enumeration Literal Specification -- |
| 2340 |
---------------------------------------------- |
| 2341 |
|
| 2342 |
-- ENUMERATION_LITERAL_SPECIFICATION ::= |
| 2343 |
-- DEFINING_IDENTIFIER | DEFINING_CHARACTER_LITERAL |
| 2344 |
|
| 2345 |
-- Error recovery: can raise Error_Resync |
| 2346 |
|
| 2347 |
function P_Enumeration_Literal_Specification return Node_Id is |
| 2348 |
begin |
| 2349 |
if Token = Tok_Char_Literal then |
| 2350 |
return P_Defining_Character_Literal; |
| 2351 |
else |
| 2352 |
return P_Defining_Identifier (C_Comma_Right_Paren); |
| 2353 |
end if; |
| 2354 |
end P_Enumeration_Literal_Specification; |
| 2355 |
|
| 2356 |
--------------------------------------- |
| 2357 |
-- 3.5.1 Defining_Character_Literal -- |
| 2358 |
--------------------------------------- |
| 2359 |
|
| 2360 |
-- DEFINING_CHARACTER_LITERAL ::= CHARACTER_LITERAL |
| 2361 |
|
| 2362 |
-- Error recovery: cannot raise Error_Resync |
| 2363 |
|
| 2364 |
-- The caller has checked that the current token is a character literal |
| 2365 |
|
| 2366 |
function P_Defining_Character_Literal return Node_Id is |
| 2367 |
Literal_Node : Node_Id; |
| 2368 |
begin |
| 2369 |
Literal_Node := Token_Node; |
| 2370 |
Change_Character_Literal_To_Defining_Character_Literal (Literal_Node); |
| 2371 |
Scan; -- past character literal |
| 2372 |
return Literal_Node; |
| 2373 |
end P_Defining_Character_Literal; |
| 2374 |
|
| 2375 |
------------------------------------ |
| 2376 |
-- 3.5.4 Integer Type Definition -- |
| 2377 |
------------------------------------ |
| 2378 |
|
| 2379 |
-- Parsed by P_Type_Declaration (3.2.1) |
| 2380 |
|
| 2381 |
------------------------------------------- |
| 2382 |
-- 3.5.4 Signed Integer Type Definition -- |
| 2383 |
------------------------------------------- |
| 2384 |
|
| 2385 |
-- SIGNED_INTEGER_TYPE_DEFINITION ::= |
| 2386 |
-- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION |
| 2387 |
|
| 2388 |
-- Normally the initial token on entry is RANGE, but in some |
| 2389 |
-- error conditions, the range token was missing and control is |
| 2390 |
-- passed with Token pointing to first token of the first expression. |
| 2391 |
|
| 2392 |
-- Error recovery: cannot raise Error_Resync |
| 2393 |
|
| 2394 |
function P_Signed_Integer_Type_Definition return Node_Id is |
| 2395 |
Typedef_Node : Node_Id; |
| 2396 |
Expr_Node : Node_Id; |
| 2397 |
|
| 2398 |
begin |
| 2399 |
Typedef_Node := New_Node (N_Signed_Integer_Type_Definition, Token_Ptr); |
| 2400 |
|
| 2401 |
if Token = Tok_Range then |
| 2402 |
Scan; -- past RANGE |
| 2403 |
end if; |
| 2404 |
|
| 2405 |
Expr_Node := P_Expression_Or_Range_Attribute; |
| 2406 |
|
| 2407 |
-- Range case (not permitted by the grammar, this is surprising but |
| 2408 |
-- the grammar in the RM is as quoted above, and does not allow Range). |
| 2409 |
|
| 2410 |
if Expr_Form = EF_Range_Attr then |
| 2411 |
Error_Msg_N |
| 2412 |
("Range attribute not allowed here, use First .. Last", Expr_Node); |
| 2413 |
Set_Low_Bound (Typedef_Node, Expr_Node); |
| 2414 |
Set_Attribute_Name (Expr_Node, Name_First); |
| 2415 |
Set_High_Bound (Typedef_Node, Copy_Separate_Tree (Expr_Node)); |
| 2416 |
Set_Attribute_Name (High_Bound (Typedef_Node), Name_Last); |
| 2417 |
|
| 2418 |
-- Normal case of explicit range |
| 2419 |
|
| 2420 |
else |
| 2421 |
Check_Simple_Expression (Expr_Node); |
| 2422 |
Set_Low_Bound (Typedef_Node, Expr_Node); |
| 2423 |
T_Dot_Dot; |
| 2424 |
Expr_Node := P_Expression; |
| 2425 |
Check_Simple_Expression (Expr_Node); |
| 2426 |
Set_High_Bound (Typedef_Node, Expr_Node); |
| 2427 |
end if; |
| 2428 |
|
| 2429 |
return Typedef_Node; |
| 2430 |
end P_Signed_Integer_Type_Definition; |
| 2431 |
|
| 2432 |
------------------------------------ |
| 2433 |
-- 3.5.4 Modular Type Definition -- |
| 2434 |
------------------------------------ |
| 2435 |
|
| 2436 |
-- MODULAR_TYPE_DEFINITION ::= mod static_EXPRESSION |
| 2437 |
|
| 2438 |
-- The caller has checked that the initial token is MOD |
| 2439 |
|
| 2440 |
-- Error recovery: cannot raise Error_Resync |
| 2441 |
|
| 2442 |
function P_Modular_Type_Definition return Node_Id is |
| 2443 |
Typedef_Node : Node_Id; |
| 2444 |
|
| 2445 |
begin |
| 2446 |
if Ada_Version = Ada_83 then |
| 2447 |
Error_Msg_SC ("(Ada 83) modular types not allowed"); |
| 2448 |
end if; |
| 2449 |
|
| 2450 |
Typedef_Node := New_Node (N_Modular_Type_Definition, Token_Ptr); |
| 2451 |
Scan; -- past MOD |
| 2452 |
Set_Expression (Typedef_Node, P_Expression_No_Right_Paren); |
| 2453 |
|
| 2454 |
-- Handle mod L..R cleanly |
| 2455 |
|
| 2456 |
if Token = Tok_Dot_Dot then |
| 2457 |
Error_Msg_SC ("range not allowed for modular type"); |
| 2458 |
Scan; -- past .. |
| 2459 |
Set_Expression (Typedef_Node, P_Expression_No_Right_Paren); |
| 2460 |
end if; |
| 2461 |
|
| 2462 |
return Typedef_Node; |
| 2463 |
end P_Modular_Type_Definition; |
| 2464 |
|
| 2465 |
--------------------------------- |
| 2466 |
-- 3.5.6 Real Type Definition -- |
| 2467 |
--------------------------------- |
| 2468 |
|
| 2469 |
-- Parsed by P_Type_Declaration (3.2.1) |
| 2470 |
|
| 2471 |
-------------------------------------- |
| 2472 |
-- 3.5.7 Floating Point Definition -- |
| 2473 |
-------------------------------------- |
| 2474 |
|
| 2475 |
-- FLOATING_POINT_DEFINITION ::= |
| 2476 |
-- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION] |
| 2477 |
|
| 2478 |
-- Note: In Ada-83, the EXPRESSION must be a SIMPLE_EXPRESSION |
| 2479 |
|
| 2480 |
-- The caller has checked that the initial token is DIGITS |
| 2481 |
|
| 2482 |
-- Error recovery: cannot raise Error_Resync |
| 2483 |
|
| 2484 |
function P_Floating_Point_Definition return Node_Id is |
| 2485 |
Digits_Loc : constant Source_Ptr := Token_Ptr; |
| 2486 |
Def_Node : Node_Id; |
| 2487 |
Expr_Node : Node_Id; |
| 2488 |
|
| 2489 |
begin |
| 2490 |
Scan; -- past DIGITS |
| 2491 |
Expr_Node := P_Expression_No_Right_Paren; |
| 2492 |
Check_Simple_Expression_In_Ada_83 (Expr_Node); |
| 2493 |
|
| 2494 |
-- Handle decimal fixed-point defn with DIGITS/DELTA in wrong order |
| 2495 |
|
| 2496 |
if Token = Tok_Delta then |
| 2497 |
Error_Msg_SC -- CODEFIX |
| 2498 |
("|DELTA must come before DIGITS"); |
| 2499 |
Def_Node := New_Node (N_Decimal_Fixed_Point_Definition, Digits_Loc); |
| 2500 |
Scan; -- past DELTA |
| 2501 |
Set_Delta_Expression (Def_Node, P_Expression_No_Right_Paren); |
| 2502 |
|
| 2503 |
-- OK floating-point definition |
| 2504 |
|
| 2505 |
else |
| 2506 |
Def_Node := New_Node (N_Floating_Point_Definition, Digits_Loc); |
| 2507 |
end if; |
| 2508 |
|
| 2509 |
Set_Digits_Expression (Def_Node, Expr_Node); |
| 2510 |
Set_Real_Range_Specification (Def_Node, P_Real_Range_Specification_Opt); |
| 2511 |
return Def_Node; |
| 2512 |
end P_Floating_Point_Definition; |
| 2513 |
|
| 2514 |
------------------------------------- |
| 2515 |
-- 3.5.7 Real Range Specification -- |
| 2516 |
------------------------------------- |
| 2517 |
|
| 2518 |
-- REAL_RANGE_SPECIFICATION ::= |
| 2519 |
-- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION |
| 2520 |
|
| 2521 |
-- Error recovery: cannot raise Error_Resync |
| 2522 |
|
| 2523 |
function P_Real_Range_Specification_Opt return Node_Id is |
| 2524 |
Specification_Node : Node_Id; |
| 2525 |
Expr_Node : Node_Id; |
| 2526 |
|
| 2527 |
begin |
| 2528 |
if Token = Tok_Range then |
| 2529 |
Specification_Node := |
| 2530 |
New_Node (N_Real_Range_Specification, Token_Ptr); |
| 2531 |
Scan; -- past RANGE |
| 2532 |
Expr_Node := P_Expression_No_Right_Paren; |
| 2533 |
Check_Simple_Expression (Expr_Node); |
| 2534 |
Set_Low_Bound (Specification_Node, Expr_Node); |
| 2535 |
T_Dot_Dot; |
| 2536 |
Expr_Node := P_Expression_No_Right_Paren; |
| 2537 |
Check_Simple_Expression (Expr_Node); |
| 2538 |
Set_High_Bound (Specification_Node, Expr_Node); |
| 2539 |
return Specification_Node; |
| 2540 |
else |
| 2541 |
return Empty; |
| 2542 |
end if; |
| 2543 |
end P_Real_Range_Specification_Opt; |
| 2544 |
|
| 2545 |
----------------------------------- |
| 2546 |
-- 3.5.9 Fixed Point Definition -- |
| 2547 |
----------------------------------- |
| 2548 |
|
| 2549 |
-- FIXED_POINT_DEFINITION ::= |
| 2550 |
-- ORDINARY_FIXED_POINT_DEFINITION | DECIMAL_FIXED_POINT_DEFINITION |
| 2551 |
|
| 2552 |
-- ORDINARY_FIXED_POINT_DEFINITION ::= |
| 2553 |
-- delta static_EXPRESSION REAL_RANGE_SPECIFICATION |
| 2554 |
|
| 2555 |
-- DECIMAL_FIXED_POINT_DEFINITION ::= |
| 2556 |
-- delta static_EXPRESSION |
| 2557 |
-- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION] |
| 2558 |
|
| 2559 |
-- The caller has checked that the initial token is DELTA |
| 2560 |
|
| 2561 |
-- Error recovery: cannot raise Error_Resync |
| 2562 |
|
| 2563 |
function P_Fixed_Point_Definition return Node_Id is |
| 2564 |
Delta_Node : Node_Id; |
| 2565 |
Delta_Loc : Source_Ptr; |
| 2566 |
Def_Node : Node_Id; |
| 2567 |
Expr_Node : Node_Id; |
| 2568 |
|
| 2569 |
begin |
| 2570 |
Delta_Loc := Token_Ptr; |
| 2571 |
Scan; -- past DELTA |
| 2572 |
Delta_Node := P_Expression_No_Right_Paren; |
| 2573 |
Check_Simple_Expression_In_Ada_83 (Delta_Node); |
| 2574 |
|
| 2575 |
if Token = Tok_Digits then |
| 2576 |
if Ada_Version = Ada_83 then |
| 2577 |
Error_Msg_SC ("(Ada 83) decimal fixed type not allowed!"); |
| 2578 |
end if; |
| 2579 |
|
| 2580 |
Def_Node := New_Node (N_Decimal_Fixed_Point_Definition, Delta_Loc); |
| 2581 |
Scan; -- past DIGITS |
| 2582 |
Expr_Node := P_Expression_No_Right_Paren; |
| 2583 |
Check_Simple_Expression_In_Ada_83 (Expr_Node); |
| 2584 |
Set_Digits_Expression (Def_Node, Expr_Node); |
| 2585 |
|
| 2586 |
else |
| 2587 |
Def_Node := New_Node (N_Ordinary_Fixed_Point_Definition, Delta_Loc); |
| 2588 |
|
| 2589 |
-- Range is required in ordinary fixed point case |
| 2590 |
|
| 2591 |
if Token /= Tok_Range then |
| 2592 |
Error_Msg_AP ("range must be given for fixed-point type"); |
| 2593 |
T_Range; |
| 2594 |
end if; |
| 2595 |
end if; |
| 2596 |
|
| 2597 |
Set_Delta_Expression (Def_Node, Delta_Node); |
| 2598 |
Set_Real_Range_Specification (Def_Node, P_Real_Range_Specification_Opt); |
| 2599 |
return Def_Node; |
| 2600 |
end P_Fixed_Point_Definition; |
| 2601 |
|
| 2602 |
-------------------------------------------- |
| 2603 |
-- 3.5.9 Ordinary Fixed Point Definition -- |
| 2604 |
-------------------------------------------- |
| 2605 |
|
| 2606 |
-- Parsed by P_Fixed_Point_Definition (3.5.9) |
| 2607 |
|
| 2608 |
------------------------------------------- |
| 2609 |
-- 3.5.9 Decimal Fixed Point Definition -- |
| 2610 |
------------------------------------------- |
| 2611 |
|
| 2612 |
-- Parsed by P_Decimal_Point_Definition (3.5.9) |
| 2613 |
|
| 2614 |
------------------------------ |
| 2615 |
-- 3.5.9 Digits Constraint -- |
| 2616 |
------------------------------ |
| 2617 |
|
| 2618 |
-- DIGITS_CONSTRAINT ::= |
| 2619 |
-- digits static_EXPRESSION [RANGE_CONSTRAINT] |
| 2620 |
|
| 2621 |
-- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION |
| 2622 |
|
| 2623 |
-- The caller has checked that the initial token is DIGITS |
| 2624 |
|
| 2625 |
function P_Digits_Constraint return Node_Id is |
| 2626 |
Constraint_Node : Node_Id; |
| 2627 |
Expr_Node : Node_Id; |
| 2628 |
|
| 2629 |
begin |
| 2630 |
Constraint_Node := New_Node (N_Digits_Constraint, Token_Ptr); |
| 2631 |
Scan; -- past DIGITS |
| 2632 |
Expr_Node := P_Expression; |
| 2633 |
Check_Simple_Expression_In_Ada_83 (Expr_Node); |
| 2634 |
Set_Digits_Expression (Constraint_Node, Expr_Node); |
| 2635 |
|
| 2636 |
if Token = Tok_Range then |
| 2637 |
Set_Range_Constraint (Constraint_Node, P_Range_Constraint); |
| 2638 |
end if; |
| 2639 |
|
| 2640 |
return Constraint_Node; |
| 2641 |
end P_Digits_Constraint; |
| 2642 |
|
| 2643 |
----------------------------- |
| 2644 |
-- 3.5.9 Delta Constraint -- |
| 2645 |
----------------------------- |
| 2646 |
|
| 2647 |
-- DELTA CONSTRAINT ::= DELTA STATIC_EXPRESSION [RANGE_CONSTRAINT] |
| 2648 |
|
| 2649 |
-- Note: this is an obsolescent feature in Ada 95 (I.3) |
| 2650 |
|
| 2651 |
-- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION |
| 2652 |
-- (also true in formal modes). |
| 2653 |
|
| 2654 |
-- The caller has checked that the initial token is DELTA |
| 2655 |
|
| 2656 |
-- Error recovery: cannot raise Error_Resync |
| 2657 |
|
| 2658 |
function P_Delta_Constraint return Node_Id is |
| 2659 |
Constraint_Node : Node_Id; |
| 2660 |
Expr_Node : Node_Id; |
| 2661 |
|
| 2662 |
begin |
| 2663 |
Constraint_Node := New_Node (N_Delta_Constraint, Token_Ptr); |
| 2664 |
Scan; -- past DELTA |
| 2665 |
Expr_Node := P_Expression; |
| 2666 |
Check_Simple_Expression_In_Ada_83 (Expr_Node); |
| 2667 |
|
| 2668 |
Set_Delta_Expression (Constraint_Node, Expr_Node); |
| 2669 |
|
| 2670 |
if Token = Tok_Range then |
| 2671 |
Set_Range_Constraint (Constraint_Node, P_Range_Constraint); |
| 2672 |
end if; |
| 2673 |
|
| 2674 |
return Constraint_Node; |
| 2675 |
end P_Delta_Constraint; |
| 2676 |
|
| 2677 |
-------------------------------- |
| 2678 |
-- 3.6 Array Type Definition -- |
| 2679 |
-------------------------------- |
| 2680 |
|
| 2681 |
-- ARRAY_TYPE_DEFINITION ::= |
| 2682 |
-- UNCONSTRAINED_ARRAY_DEFINITION | CONSTRAINED_ARRAY_DEFINITION |
| 2683 |
|
| 2684 |
-- UNCONSTRAINED_ARRAY_DEFINITION ::= |
| 2685 |
-- array (INDEX_SUBTYPE_DEFINITION {, INDEX_SUBTYPE_DEFINITION}) of |
| 2686 |
-- COMPONENT_DEFINITION |
| 2687 |
|
| 2688 |
-- INDEX_SUBTYPE_DEFINITION ::= SUBTYPE_MARK range <> |
| 2689 |
|
| 2690 |
-- CONSTRAINED_ARRAY_DEFINITION ::= |
| 2691 |
-- array (DISCRETE_SUBTYPE_DEFINITION {, DISCRETE_SUBTYPE_DEFINITION}) of |
| 2692 |
-- COMPONENT_DEFINITION |
| 2693 |
|
| 2694 |
-- DISCRETE_SUBTYPE_DEFINITION ::= |
| 2695 |
-- DISCRETE_SUBTYPE_INDICATION | RANGE |
| 2696 |
|
| 2697 |
-- COMPONENT_DEFINITION ::= |
| 2698 |
-- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION |
| 2699 |
|
| 2700 |
-- The caller has checked that the initial token is ARRAY |
| 2701 |
|
| 2702 |
-- Error recovery: can raise Error_Resync |
| 2703 |
|
| 2704 |
function P_Array_Type_Definition return Node_Id is |
| 2705 |
Array_Loc : Source_Ptr; |
| 2706 |
CompDef_Node : Node_Id; |
| 2707 |
Def_Node : Node_Id; |
| 2708 |
Not_Null_Present : Boolean := False; |
| 2709 |
Subs_List : List_Id; |
| 2710 |
Scan_State : Saved_Scan_State; |
| 2711 |
Aliased_Present : Boolean := False; |
| 2712 |
|
| 2713 |
procedure P_Index_Subtype_Def_With_Fixed_Lower_Bound |
| 2714 |
(Subtype_Mark : Node_Id); |
| 2715 |
-- Parse an unconstrained index range with a fixed lower bound: |
| 2716 |
-- subtype_mark range <expression> .. <> |
| 2717 |
-- This procedure creates a subtype_indication node for the index. |
| 2718 |
|
| 2719 |
-------------------------------------------- |
| 2720 |
-- P_Index_Range_With_Fixed_Lower_Bound -- |
| 2721 |
-------------------------------------------- |
| 2722 |
|
| 2723 |
procedure P_Index_Subtype_Def_With_Fixed_Lower_Bound |
| 2724 |
(Subtype_Mark : Node_Id) |
| 2725 |
is |
| 2726 |
Low_Expr_Node : constant Node_Id := P_Expression; |
| 2727 |
High_Expr_Node : Node_Id; |
| 2728 |
Indic_Node : Node_Id; |
| 2729 |
Constr_Node : Node_Id; |
| 2730 |
Range_Node : Node_Id; |
| 2731 |
|
| 2732 |
begin |
| 2733 |
T_Dot_Dot; -- Error if no .. |
| 2734 |
|
| 2735 |
-- A box is required at this point, and we'll set the upper bound to |
| 2736 |
-- the same expression as the lower bound (see further below), to |
| 2737 |
-- avoid problems with trying to analyze an Empty node. Analysis can |
| 2738 |
-- still tell that this is a fixed-lower-bound range because the |
| 2739 |
-- index is represented by a subtype_indication in an unconstrained |
| 2740 |
-- array type definition. |
| 2741 |
|
| 2742 |
if Token = Tok_Box then |
| 2743 |
Scan; |
| 2744 |
High_Expr_Node := Low_Expr_Node; |
| 2745 |
|
| 2746 |
-- Error if no <> was found, and try to parse an expression since |
| 2747 |
-- it's likely one was given in place of the <>. |
| 2748 |
|
| 2749 |
else |
| 2750 |
Error_Msg_AP -- CODEFIX |
| 2751 |
("missing ""'<'>"""); |
| 2752 |
|
| 2753 |
High_Expr_Node := P_Expression; |
| 2754 |
end if; |
| 2755 |
|
| 2756 |
Constr_Node := New_Node (N_Range_Constraint, Token_Ptr); |
| 2757 |
Range_Node := New_Node (N_Range, Token_Ptr); |
| 2758 |
Set_Range_Expression (Constr_Node, Range_Node); |
| 2759 |
|
| 2760 |
Check_Simple_Expression (Low_Expr_Node); |
| 2761 |
|
| 2762 |
Set_Low_Bound (Range_Node, Low_Expr_Node); |
| 2763 |
Set_High_Bound (Range_Node, High_Expr_Node); |
| 2764 |
|
| 2765 |
Indic_Node := |
| 2766 |
New_Node (N_Subtype_Indication, Sloc (Subtype_Mark)); |
| 2767 |
Set_Subtype_Mark (Indic_Node, Check_Subtype_Mark (Subtype_Mark)); |
| 2768 |
Set_Constraint (Indic_Node, Constr_Node); |
| 2769 |
|
| 2770 |
Append (Indic_Node, Subs_List); |
| 2771 |
end P_Index_Subtype_Def_With_Fixed_Lower_Bound; |
| 2772 |
|
| 2773 |
-- Local variables |
| 2774 |
|
| 2775 |
Is_Constrained_Array_Def : Boolean := True; |
| 2776 |
Subtype_Mark_Node : Node_Id; |
| 2777 |
|
| 2778 |
-- Start of processing for P_Array_Type_Definition |
| 2779 |
|
| 2780 |
begin |
| 2781 |
Array_Loc := Token_Ptr; |
| 2782 |
Scan; -- past ARRAY |
| 2783 |
Subs_List := New_List; |
| 2784 |
T_Left_Paren; |
| 2785 |
|
| 2786 |
-- It's quite tricky to disentangle these two possibilities, so we do |
| 2787 |
-- a prescan to determine which case we have and then reset the scan. |
| 2788 |
-- The prescan skips past possible subtype mark tokens. |
| 2789 |
|
| 2790 |
Save_Scan_State (Scan_State); -- just after paren |
| 2791 |
|
| 2792 |
while Token in Token_Class_Desig or else |
| 2793 |
Token = Tok_Dot or else |
| 2794 |
Token = Tok_Apostrophe -- because of 'BASE, 'CLASS |
| 2795 |
loop |
| 2796 |
Scan; |
| 2797 |
end loop; |
| 2798 |
|
| 2799 |
-- If we end up on RANGE <> then we have the unconstrained case. We |
| 2800 |
-- will also allow the RANGE to be omitted, just to improve error |
| 2801 |
-- handling for a case like array (integer <>) of integer; |
| 2802 |
|
| 2803 |
Scan; -- past possible RANGE or <> |
| 2804 |
|
| 2805 |
if (Prev_Token = Tok_Range and then Token = Tok_Box) or else |
| 2806 |
Prev_Token = Tok_Box |
| 2807 |
then |
| 2808 |
Def_Node := New_Node (N_Unconstrained_Array_Definition, Array_Loc); |
| 2809 |
Restore_Scan_State (Scan_State); -- to first subtype mark |
| 2810 |
|
| 2811 |
Is_Constrained_Array_Def := False; |
| 2812 |
|
| 2813 |
-- Now parse a sequence of indexes where each is either of form: |
| 2814 |
-- <subtype_mark> range <> |
| 2815 |
-- or |
| 2816 |
-- <subtype_mark> range <expr> .. <> |
| 2817 |
-- |
| 2818 |
-- The latter syntax indicates an index with a fixed lower bound, |
| 2819 |
-- and only applies when extensions are enabled (-gnatX). |
| 2820 |
|
| 2821 |
loop |
| 2822 |
Subtype_Mark_Node := P_Subtype_Mark_Resync; |
| 2823 |
|
| 2824 |
T_Range; |
| 2825 |
|
| 2826 |
-- Normal "subtype_mark range <>" form, so simply append |
| 2827 |
-- the subtype reference. |
| 2828 |
|
| 2829 |
if Token = Tok_Box then |
| 2830 |
Append (Subtype_Mark_Node, Subs_List); |
| 2831 |
Scan; |
| 2832 |
|
| 2833 |
-- Fixed-lower-bound form ("subtype_mark range <expr> .. <>") |
| 2834 |
|
| 2835 |
else |
| 2836 |
P_Index_Subtype_Def_With_Fixed_Lower_Bound (Subtype_Mark_Node); |
| 2837 |
|
| 2838 |
Error_Msg_GNAT_Extension ("fixed-lower-bound array", Token_Ptr, |
| 2839 |
Is_Core_Extension => True); |
| 2840 |
end if; |
| 2841 |
|
| 2842 |
exit when Token in Tok_Right_Paren | Tok_Of; |
| 2843 |
T_Comma; |
| 2844 |
end loop; |
| 2845 |
|
| 2846 |
Set_Subtype_Marks (Def_Node, Subs_List); |
| 2847 |
|
| 2848 |
-- If we don't have "range <>", then "range" will be followed by an |
| 2849 |
-- expression, for either a normal range or a fixed-lower-bound range |
| 2850 |
-- ("<exp> .. <>"), and we have to know which, in order to determine |
| 2851 |
-- whether to parse the indexes for an unconstrained or constrained |
| 2852 |
-- array definition. So we look ahead to see if "<>" follows the "..". |
| 2853 |
-- If not, then this must be a discrete_subtype_indication for a |
| 2854 |
-- constrained_array_definition, which will be processed further below. |
| 2855 |
|
| 2856 |
elsif Prev_Token = Tok_Range |
| 2857 |
and then Token not in Tok_Right_Paren | Tok_Comma |
| 2858 |
then |
| 2859 |
-- If we have an expression followed by "..", then scan farther |
| 2860 |
-- and check for "<>" to see if we have a fixed-lower-bound range. |
| 2861 |
|
| 2862 |
if P_Expression_Or_Range_Attribute /= Error |
| 2863 |
and then Expr_Form /= EF_Range_Attr |
| 2864 |
and then Token = Tok_Dot_Dot |
| 2865 |
then |
| 2866 |
Scan; |
| 2867 |
|
| 2868 |
-- If there's a "<>", then we know we have a fixed-lower-bound |
| 2869 |
-- index, so we can proceed with parsing an unconstrained array |
| 2870 |
-- definition. |
| 2871 |
|
| 2872 |
if Token = Tok_Box then |
| 2873 |
Is_Constrained_Array_Def := False; |
| 2874 |
|
| 2875 |
Def_Node := |
| 2876 |
New_Node (N_Unconstrained_Array_Definition, Array_Loc); |
| 2877 |
|
| 2878 |
Restore_Scan_State (Scan_State); -- to first subtype mark |
| 2879 |
|
| 2880 |
-- Now parse a sequence of indexes where each is either of |
| 2881 |
-- form: |
| 2882 |
-- <subtype_mark> range <> |
| 2883 |
-- or |
| 2884 |
-- <subtype_mark> range <expr> .. <> |
| 2885 |
-- |
| 2886 |
-- The latter indicates an index with a fixed lower bound, |
| 2887 |
-- and only applies when extensions are enabled (-gnatX). |
| 2888 |
|
| 2889 |
loop |
| 2890 |
Subtype_Mark_Node := P_Subtype_Mark_Resync; |
| 2891 |
|
| 2892 |
T_Range; |
| 2893 |
|
| 2894 |
-- Normal "subtype_mark range <>" form, so simply append |
| 2895 |
-- the subtype reference. |
| 2896 |
|
| 2897 |
if Token = Tok_Box then |
| 2898 |
Append (Subtype_Mark_Node, Subs_List); |
| 2899 |
Scan; |
| 2900 |
|
| 2901 |
-- This must be an index of form: |
| 2902 |
-- <subtype_mark> range <expr> .. <>" |
| 2903 |
|
| 2904 |
else |
| 2905 |
P_Index_Subtype_Def_With_Fixed_Lower_Bound |
| 2906 |
(Subtype_Mark_Node); |
| 2907 |
|
| 2908 |
Error_Msg_GNAT_Extension |
| 2909 |
("fixed-lower-bound array", Token_Ptr, |
| 2910 |
Is_Core_Extension => True); |
| 2911 |
end if; |
| 2912 |
|
| 2913 |
exit when Token in Tok_Right_Paren | Tok_Of; |
| 2914 |
T_Comma; |
| 2915 |
end loop; |
| 2916 |
|
| 2917 |
Set_Subtype_Marks (Def_Node, Subs_List); |
| 2918 |
end if; |
| 2919 |
end if; |
| 2920 |
end if; |
| 2921 |
|
| 2922 |
if Is_Constrained_Array_Def then |
| 2923 |
Def_Node := New_Node (N_Constrained_Array_Definition, Array_Loc); |
| 2924 |
Restore_Scan_State (Scan_State); -- to first discrete range |
| 2925 |
|
| 2926 |
loop |
| 2927 |
Append (P_Discrete_Subtype_Definition, Subs_List); |
| 2928 |
exit when not Comma_Present; |
| 2929 |
end loop; |
| 2930 |
|
| 2931 |
Set_Discrete_Subtype_Definitions (Def_Node, Subs_List); |
| 2932 |
end if; |
| 2933 |
|
| 2934 |
T_Right_Paren; |
| 2935 |
T_Of; |
| 2936 |
|
| 2937 |
CompDef_Node := New_Node (N_Component_Definition, Token_Ptr); |
| 2938 |
|
| 2939 |
if Token_Name = Name_Aliased then |
| 2940 |
Check_95_Keyword (Tok_Aliased, Tok_Identifier); |
| 2941 |
end if; |
| 2942 |
|
| 2943 |
if Token = Tok_Aliased then |
| 2944 |
Aliased_Present := True; |
| 2945 |
Scan; -- past ALIASED |
| 2946 |
end if; |
| 2947 |
|
| 2948 |
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231/AI-254) |
| 2949 |
|
| 2950 |
-- Ada 2005 (AI-230): Access Definition case |
| 2951 |
|
| 2952 |
if Token = Tok_Access then |
| 2953 |
Error_Msg_Ada_2005_Extension |
| 2954 |
("generalized use of anonymous access types"); |
| 2955 |
|
| 2956 |
-- AI95-406 makes "aliased" legal (and useless) in this context so |
| 2957 |
-- followintg code which used to be needed is commented out. |
| 2958 |
|
| 2959 |
-- if Aliased_Present then |
| 2960 |
-- Error_Msg_SP ("ALIASED not allowed here"); |
| 2961 |
-- end if; |
| 2962 |
|
| 2963 |
Set_Subtype_Indication (CompDef_Node, Empty); |
| 2964 |
Set_Aliased_Present (CompDef_Node, Aliased_Present); |
| 2965 |
Set_Access_Definition (CompDef_Node, |
| 2966 |
P_Access_Definition (Not_Null_Present)); |
| 2967 |
else |
| 2968 |
|
| 2969 |
Set_Access_Definition (CompDef_Node, Empty); |
| 2970 |
Set_Aliased_Present (CompDef_Node, Aliased_Present); |
| 2971 |
Set_Null_Exclusion_Present (CompDef_Node, Not_Null_Present); |
| 2972 |
Set_Subtype_Indication (CompDef_Node, |
| 2973 |
P_Subtype_Indication (Not_Null_Present)); |
| 2974 |
end if; |
| 2975 |
|
| 2976 |
Set_Component_Definition (Def_Node, CompDef_Node); |
| 2977 |
|
| 2978 |
return Def_Node; |
| 2979 |
end P_Array_Type_Definition; |
| 2980 |
|
| 2981 |
----------------------------------------- |
| 2982 |
-- 3.6 Unconstrained Array Definition -- |
| 2983 |
----------------------------------------- |
| 2984 |
|
| 2985 |
-- Parsed by P_Array_Type_Definition (3.6) |
| 2986 |
|
| 2987 |
--------------------------------------- |
| 2988 |
-- 3.6 Constrained Array Definition -- |
| 2989 |
--------------------------------------- |
| 2990 |
|
| 2991 |
-- Parsed by P_Array_Type_Definition (3.6) |
| 2992 |
|
| 2993 |
-------------------------------------- |
| 2994 |
-- 3.6 Discrete Subtype Definition -- |
| 2995 |
-------------------------------------- |
| 2996 |
|
| 2997 |
-- DISCRETE_SUBTYPE_DEFINITION ::= |
| 2998 |
-- discrete_SUBTYPE_INDICATION | RANGE |
| 2999 |
|
| 3000 |
-- Note: the discrete subtype definition appearing in a constrained |
| 3001 |
-- array definition is parsed by P_Array_Type_Definition (3.6) |
| 3002 |
|
| 3003 |
-- Error recovery: cannot raise Error_Resync |
| 3004 |
|
| 3005 |
function P_Discrete_Subtype_Definition return Node_Id is |
| 3006 |
begin |
| 3007 |
-- The syntax of a discrete subtype definition is identical to that |
| 3008 |
-- of a discrete range, so we simply share the same parsing code. |
| 3009 |
|
| 3010 |
return P_Discrete_Range; |
| 3011 |
end P_Discrete_Subtype_Definition; |
| 3012 |
|
| 3013 |
------------------------------- |
| 3014 |
-- 3.6 Component Definition -- |
| 3015 |
------------------------------- |
| 3016 |
|
| 3017 |
-- For the array case, parsed by P_Array_Type_Definition (3.6) |
| 3018 |
-- For the record case, parsed by P_Component_Declaration (3.8) |
| 3019 |
|
| 3020 |
----------------------------- |
| 3021 |
-- 3.6.1 Index Constraint -- |
| 3022 |
----------------------------- |
| 3023 |
|
| 3024 |
-- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1) |
| 3025 |
|
| 3026 |
--------------------------- |
| 3027 |
-- 3.6.1 Discrete Range -- |
| 3028 |
--------------------------- |
| 3029 |
|
| 3030 |
-- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE |
| 3031 |
|
| 3032 |
-- The possible forms for a discrete range are: |
| 3033 |
|
| 3034 |
-- Subtype_Mark (SUBTYPE_INDICATION, 3.2.2) |
| 3035 |
-- Subtype_Mark range Range (SUBTYPE_INDICATION, 3.2.2) |
| 3036 |
-- Range_Attribute (RANGE, 3.5) |
| 3037 |
-- Simple_Expression .. Simple_Expression (RANGE, 3.5) |
| 3038 |
|
| 3039 |
-- Error recovery: cannot raise Error_Resync |
| 3040 |
|
| 3041 |
function P_Discrete_Range return Node_Id is |
| 3042 |
Expr_Node : Node_Id; |
| 3043 |
Range_Node : Node_Id; |
| 3044 |
|
| 3045 |
begin |
| 3046 |
Expr_Node := P_Simple_Expression_Or_Range_Attribute; |
| 3047 |
|
| 3048 |
if Expr_Form = EF_Range_Attr then |
| 3049 |
return Expr_Node; |
| 3050 |
|
| 3051 |
elsif Token = Tok_Range then |
| 3052 |
if Expr_Form /= EF_Simple_Name then |
| 3053 |
Error_Msg_SC ("range must be preceded by subtype mark"); |
| 3054 |
end if; |
| 3055 |
|
| 3056 |
return P_Subtype_Indication (Expr_Node); |
| 3057 |
|
| 3058 |
-- Check Expression .. Expression case |
| 3059 |
|
| 3060 |
elsif Token = Tok_Dot_Dot then |
| 3061 |
Range_Node := New_Node (N_Range, Token_Ptr); |
| 3062 |
Set_Low_Bound (Range_Node, Expr_Node); |
| 3063 |
|
| 3064 |
-- If the bound doesn't require parentheses, then emit a style |
| 3065 |
-- check. Parentheses that change an "expression" syntax node into a |
| 3066 |
-- "simple expression" are required; we filter those nodes both here |
| 3067 |
-- and inside Check_Xtra_Parens itself. |
| 3068 |
|
| 3069 |
if Style_Check |
| 3070 |
and then Nkind (Expr_Node) not in N_Membership_Test |
| 3071 |
| N_Op_Boolean |
| 3072 |
| N_Short_Circuit |
| 3073 |
then |
| 3074 |
Style.Check_Xtra_Parens (Expr_Node); |
| 3075 |
end if; |
| 3076 |
|
| 3077 |
Scan; -- past .. |
| 3078 |
Expr_Node := P_Expression; |
| 3079 |
Check_Simple_Expression (Expr_Node); |
| 3080 |
Set_High_Bound (Range_Node, Expr_Node); |
| 3081 |
|
| 3082 |
-- Check for extra parentheses like for the lower bound |
| 3083 |
|
| 3084 |
if Style_Check |
| 3085 |
and then Nkind (Expr_Node) not in N_Membership_Test |
| 3086 |
| N_Op_Boolean |
| 3087 |
| N_Short_Circuit |
| 3088 |
then |
| 3089 |
Style.Check_Xtra_Parens (Expr_Node); |
| 3090 |
end if; |
| 3091 |
|
| 3092 |
return Range_Node; |
| 3093 |
|
| 3094 |
-- Otherwise we must have a subtype mark, or an Ada 2012 iterator |
| 3095 |
|
| 3096 |
elsif Expr_Form = EF_Simple_Name then |
| 3097 |
return Expr_Node; |
| 3098 |
|
| 3099 |
-- The domain of iteration must be a name. Semantics will determine that |
| 3100 |
-- the expression has the proper form. |
| 3101 |
|
| 3102 |
elsif Ada_Version >= Ada_2012 then |
| 3103 |
return Expr_Node; |
| 3104 |
|
| 3105 |
-- If incorrect, complain that we expect .. |
| 3106 |
|
| 3107 |
else |
| 3108 |
T_Dot_Dot; |
| 3109 |
return Expr_Node; |
| 3110 |
end if; |
| 3111 |
end P_Discrete_Range; |
| 3112 |
|
| 3113 |
---------------------------- |
| 3114 |
-- 3.7 Discriminant Part -- |
| 3115 |
---------------------------- |
| 3116 |
|
| 3117 |
-- DISCRIMINANT_PART ::= |
| 3118 |
-- UNKNOWN_DISCRIMINANT_PART |
| 3119 |
-- | KNOWN_DISCRIMINANT_PART |
| 3120 |
|
| 3121 |
-- A discriminant part is parsed by P_Known_Discriminant_Part_Opt (3.7) |
| 3122 |
-- or P_Unknown_Discriminant_Part (3.7), since we know which we want. |
| 3123 |
|
| 3124 |
------------------------------------ |
| 3125 |
-- 3.7 Unknown Discriminant Part -- |
| 3126 |
------------------------------------ |
| 3127 |
|
| 3128 |
-- UNKNOWN_DISCRIMINANT_PART ::= (<>) |
| 3129 |
|
| 3130 |
-- If no unknown discriminant part is present, then False is returned, |
| 3131 |
-- otherwise the unknown discriminant is scanned out and True is returned. |
| 3132 |
|
| 3133 |
-- Error recovery: cannot raise Error_Resync |
| 3134 |
|
| 3135 |
function P_Unknown_Discriminant_Part_Opt return Boolean is |
| 3136 |
Scan_State : Saved_Scan_State; |
| 3137 |
|
| 3138 |
begin |
| 3139 |
-- If <> right now, then this is missing left paren |
| 3140 |
|
| 3141 |
if Token = Tok_Box then |
| 3142 |
U_Left_Paren; |
| 3143 |
|
| 3144 |
-- If not <> or left paren, then definitely no box |
| 3145 |
|
| 3146 |
elsif Token /= Tok_Left_Paren then |
| 3147 |
return False; |
| 3148 |
|
| 3149 |
-- Left paren, so might be a box after it |
| 3150 |
|
| 3151 |
else |
| 3152 |
Save_Scan_State (Scan_State); |
| 3153 |
Scan; -- past the left paren |
| 3154 |
|
| 3155 |
if Token /= Tok_Box then |
| 3156 |
Restore_Scan_State (Scan_State); |
| 3157 |
return False; |
| 3158 |
end if; |
| 3159 |
end if; |
| 3160 |
|
| 3161 |
-- We are now pointing to the box |
| 3162 |
|
| 3163 |
if Ada_Version = Ada_83 then |
| 3164 |
Error_Msg_SC ("(Ada 83) unknown discriminant not allowed!"); |
| 3165 |
end if; |
| 3166 |
|
| 3167 |
Scan; -- past the box |
| 3168 |
U_Right_Paren; -- must be followed by right paren |
| 3169 |
return True; |
| 3170 |
end P_Unknown_Discriminant_Part_Opt; |
| 3171 |
|
| 3172 |
---------------------------------- |
| 3173 |
-- 3.7 Known Discriminant Part -- |
| 3174 |
---------------------------------- |
| 3175 |
|
| 3176 |
-- KNOWN_DISCRIMINANT_PART ::= |
| 3177 |
-- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION}) |
| 3178 |
|
| 3179 |
-- DISCRIMINANT_SPECIFICATION ::= |
| 3180 |
-- DEFINING_IDENTIFIER_LIST : [NULL_EXCLUSION] SUBTYPE_MARK |
| 3181 |
-- [:= DEFAULT_EXPRESSION] [ASPECT_SPECIFICATION] |
| 3182 |
-- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION |
| 3183 |
-- [:= DEFAULT_EXPRESSION] [ASPECT_SPECIFICATION] |
| 3184 |
|
| 3185 |
-- If no known discriminant part is present, then No_List is returned |
| 3186 |
|
| 3187 |
-- Error recovery: cannot raise Error_Resync |
| 3188 |
|
| 3189 |
function P_Known_Discriminant_Part_Opt return List_Id is |
| 3190 |
Specification_Node : Node_Id; |
| 3191 |
Specification_List : List_Id; |
| 3192 |
Ident_Sloc : Source_Ptr; |
| 3193 |
Scan_State : Saved_Scan_State; |
| 3194 |
Num_Idents : Nat; |
| 3195 |
Not_Null_Present : Boolean; |
| 3196 |
Ident : Nat; |
| 3197 |
|
| 3198 |
Idents : array (Int range 1 .. 4096) of Entity_Id; |
| 3199 |
-- This array holds the list of defining identifiers. The upper bound |
| 3200 |
-- of 4096 is intended to be essentially infinite, and we do not even |
| 3201 |
-- bother to check for it being exceeded. |
| 3202 |
|
| 3203 |
begin |
| 3204 |
if Token = Tok_Left_Paren then |
| 3205 |
Specification_List := New_List; |
| 3206 |
Scan; -- past ( |
| 3207 |
P_Pragmas_Misplaced; |
| 3208 |
|
| 3209 |
Specification_Loop : loop |
| 3210 |
|
| 3211 |
Ident_Sloc := Token_Ptr; |
| 3212 |
Idents (1) := P_Defining_Identifier (C_Comma_Colon); |
| 3213 |
Num_Idents := 1; |
| 3214 |
|
| 3215 |
while Comma_Present loop |
| 3216 |
Num_Idents := Num_Idents + 1; |
| 3217 |
Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon); |
| 3218 |
end loop; |
| 3219 |
|
| 3220 |
-- If there are multiple identifiers, we repeatedly scan the |
| 3221 |
-- type and initialization expression information by resetting |
| 3222 |
-- the scan pointer (so that we get completely separate trees |
| 3223 |
-- for each occurrence). |
| 3224 |
|
| 3225 |
if Num_Idents > 1 then |
| 3226 |
Save_Scan_State (Scan_State); |
| 3227 |
end if; |
| 3228 |
|
| 3229 |
T_Colon; |
| 3230 |
|
| 3231 |
-- Loop through defining identifiers in list |
| 3232 |
|
| 3233 |
Ident := 1; |
| 3234 |
Ident_Loop : loop |
| 3235 |
Specification_Node := |
| 3236 |
New_Node (N_Discriminant_Specification, Ident_Sloc); |
| 3237 |
Set_Defining_Identifier (Specification_Node, Idents (Ident)); |
| 3238 |
Not_Null_Present := -- Ada 2005 (AI-231, AI-447) |
| 3239 |
P_Null_Exclusion (Allow_Anonymous_In_95 => True); |
| 3240 |
|
| 3241 |
if Token = Tok_Access then |
| 3242 |
if Ada_Version = Ada_83 then |
| 3243 |
Error_Msg_SC |
| 3244 |
("(Ada 83) access discriminant not allowed!"); |
| 3245 |
end if; |
| 3246 |
|
| 3247 |
Set_Discriminant_Type |
| 3248 |
(Specification_Node, |
| 3249 |
P_Access_Definition (Not_Null_Present)); |
| 3250 |
|
| 3251 |
-- Catch ouf-of-order keywords |
| 3252 |
|
| 3253 |
elsif Token = Tok_Constant then |
| 3254 |
Scan; |
| 3255 |
|
| 3256 |
if Token = Tok_Access then |
| 3257 |
Error_Msg_SC -- CODEFIX |
| 3258 |
("ACCESS must come before CONSTANT"); |
| 3259 |
Set_Discriminant_Type |
| 3260 |
(Specification_Node, |
| 3261 |
P_Access_Definition (Not_Null_Present)); |
| 3262 |
|
| 3263 |
else |
| 3264 |
Error_Msg_SC ("misplaced CONSTANT"); |
| 3265 |
end if; |
| 3266 |
|
| 3267 |
else |
| 3268 |
Set_Discriminant_Type |
| 3269 |
(Specification_Node, P_Subtype_Mark); |
| 3270 |
No_Constraint; |
| 3271 |
Set_Null_Exclusion_Present -- Ada 2005 (AI-231) |
| 3272 |
(Specification_Node, Not_Null_Present); |
| 3273 |
end if; |
| 3274 |
|
| 3275 |
Set_Expression |
| 3276 |
(Specification_Node, Init_Expr_Opt (True)); |
| 3277 |
|
| 3278 |
if Token = Tok_With then |
| 3279 |
P_Aspect_Specifications |
| 3280 |
(Specification_Node, Semicolon => False); |
| 3281 |
end if; |
| 3282 |
|
| 3283 |
if Ident > 1 then |
| 3284 |
Set_Prev_Ids (Specification_Node, True); |
| 3285 |
end if; |
| 3286 |
|
| 3287 |
if Ident < Num_Idents then |
| 3288 |
Set_More_Ids (Specification_Node, True); |
| 3289 |
end if; |
| 3290 |
|
| 3291 |
Append (Specification_Node, Specification_List); |
| 3292 |
exit Ident_Loop when Ident = Num_Idents; |
| 3293 |
Ident := Ident + 1; |
| 3294 |
Restore_Scan_State (Scan_State); |
| 3295 |
T_Colon; |
| 3296 |
end loop Ident_Loop; |
| 3297 |
|
| 3298 |
exit Specification_Loop when Token /= Tok_Semicolon; |
| 3299 |
Scan; -- past ; |
| 3300 |
P_Pragmas_Misplaced; |
| 3301 |
end loop Specification_Loop; |
| 3302 |
|
| 3303 |
T_Right_Paren; |
| 3304 |
return Specification_List; |
| 3305 |
|
| 3306 |
else |
| 3307 |
return No_List; |
| 3308 |
end if; |
| 3309 |
end P_Known_Discriminant_Part_Opt; |
| 3310 |
|
| 3311 |
------------------------------------- |
| 3312 |
-- 3.7 Discriminant Specification -- |
| 3313 |
------------------------------------- |
| 3314 |
|
| 3315 |
-- Parsed by P_Known_Discriminant_Part_Opt (3.7) |
| 3316 |
|
| 3317 |
----------------------------- |
| 3318 |
-- 3.7 Default Expression -- |
| 3319 |
----------------------------- |
| 3320 |
|
| 3321 |
-- Always parsed (simply as an Expression) by the parent construct |
| 3322 |
|
| 3323 |
------------------------------------ |
| 3324 |
-- 3.7.1 Discriminant Constraint -- |
| 3325 |
------------------------------------ |
| 3326 |
|
| 3327 |
-- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1) |
| 3328 |
|
| 3329 |
-------------------------------------------------------- |
| 3330 |
-- 3.7.1 Index or Discriminant Constraint (also 3.6) -- |
| 3331 |
-------------------------------------------------------- |
| 3332 |
|
| 3333 |
-- DISCRIMINANT_CONSTRAINT ::= |
| 3334 |
-- (DISCRIMINANT_ASSOCIATION {, DISCRIMINANT_ASSOCIATION}) |
| 3335 |
|
| 3336 |
-- DISCRIMINANT_ASSOCIATION ::= |
| 3337 |
-- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>] |
| 3338 |
-- EXPRESSION |
| 3339 |
|
| 3340 |
-- This routine parses either an index or a discriminant constraint. As |
| 3341 |
-- is clear from the above grammar, it is often possible to clearly |
| 3342 |
-- determine which of the two possibilities we have, but there are |
| 3343 |
-- cases (those in which we have a series of expressions of the same |
| 3344 |
-- syntactic form as subtype indications), where we cannot tell. Since |
| 3345 |
-- this means that in any case the semantic phase has to distinguish |
| 3346 |
-- between the two, there is not much point in the parser trying to |
| 3347 |
-- distinguish even those cases where the difference is clear. In any |
| 3348 |
-- case, if we have a situation like: |
| 3349 |
|
| 3350 |
-- (A => 123, 235 .. 500) |
| 3351 |
|
| 3352 |
-- it is not clear which of the two items is the wrong one, better to |
| 3353 |
-- let the semantic phase give a clear message. Consequently, this |
| 3354 |
-- routine in general returns a list of items which can be either |
| 3355 |
-- discrete ranges or discriminant associations. |
| 3356 |
|
| 3357 |
-- The caller has checked that the initial token is a left paren |
| 3358 |
|
| 3359 |
-- Error recovery: can raise Error_Resync |
| 3360 |
|
| 3361 |
function P_Index_Or_Discriminant_Constraint return Node_Id is |
| 3362 |
Scan_State : Saved_Scan_State; |
| 3363 |
Constr_Node : Node_Id; |
| 3364 |
Constr_List : List_Id; |
| 3365 |
Expr_Node : Node_Id; |
| 3366 |
Result_Node : Node_Id; |
| 3367 |
|
| 3368 |
begin |
| 3369 |
Result_Node := New_Node (N_Index_Or_Discriminant_Constraint, Token_Ptr); |
| 3370 |
Scan; -- past ( |
| 3371 |
Constr_List := New_List; |
| 3372 |
Set_Constraints (Result_Node, Constr_List); |
| 3373 |
|
| 3374 |
-- The two syntactic forms are a little mixed up, so what we are doing |
| 3375 |
-- here is looking at the first entry to determine which case we have |
| 3376 |
|
| 3377 |
-- A discriminant constraint is a list of discriminant associations, |
| 3378 |
-- which have one of the following possible forms: |
| 3379 |
|
| 3380 |
-- Expression |
| 3381 |
-- Id => Expression |
| 3382 |
-- Id | Id | .. | Id => Expression |
| 3383 |
|
| 3384 |
-- An index constraint is a list of discrete ranges which have one |
| 3385 |
-- of the following possible forms: |
| 3386 |
|
| 3387 |
-- Subtype_Mark |
| 3388 |
-- Subtype_Mark range Range |
| 3389 |
-- Range_Attribute |
| 3390 |
-- Simple_Expression .. Simple_Expression |
| 3391 |
|
| 3392 |
-- Loop through discriminants in list |
| 3393 |
|
| 3394 |
loop |
| 3395 |
-- Check cases of Id => Expression or Id | Id => Expression |
| 3396 |
|
| 3397 |
if Token = Tok_Identifier then |
| 3398 |
Save_Scan_State (Scan_State); -- at Id |
| 3399 |
Scan; -- past Id |
| 3400 |
|
| 3401 |
if Token in Tok_Arrow | Tok_Vertical_Bar then |
| 3402 |
Restore_Scan_State (Scan_State); -- to Id |
| 3403 |
Append (P_Discriminant_Association, Constr_List); |
| 3404 |
goto Loop_Continue; |
| 3405 |
else |
| 3406 |
Restore_Scan_State (Scan_State); -- to Id |
| 3407 |
end if; |
| 3408 |
end if; |
| 3409 |
|
| 3410 |
-- Otherwise scan out an expression and see what we have got |
| 3411 |
|
| 3412 |
Expr_Node := P_Expression_Or_Range_Attribute; |
| 3413 |
|
| 3414 |
if Expr_Form = EF_Range_Attr then |
| 3415 |
Append (Expr_Node, Constr_List); |
| 3416 |
|
| 3417 |
elsif Token = Tok_Range then |
| 3418 |
if Expr_Form /= EF_Simple_Name then |
| 3419 |
Error_Msg_SC ("subtype mark required before RANGE"); |
| 3420 |
end if; |
| 3421 |
|
| 3422 |
Append (P_Subtype_Indication (Expr_Node), Constr_List); |
| 3423 |
goto Loop_Continue; |
| 3424 |
|
| 3425 |
-- Check Simple_Expression .. Simple_Expression case |
| 3426 |
|
| 3427 |
elsif Token = Tok_Dot_Dot then |
| 3428 |
Check_Simple_Expression (Expr_Node); |
| 3429 |
Constr_Node := New_Node (N_Range, Token_Ptr); |
| 3430 |
Set_Low_Bound (Constr_Node, Expr_Node); |
| 3431 |
Scan; -- past .. |
| 3432 |
|
| 3433 |
-- If the upper bound is given by "<>", this is an index for |
| 3434 |
-- a fixed-lower-bound subtype, so set the expression to Empty |
| 3435 |
-- for now (it will be set to the ranges maximum upper bound |
| 3436 |
-- later during analysis), and scan to the next token. |
| 3437 |
|
| 3438 |
if Token = Tok_Box then |
| 3439 |
Error_Msg_GNAT_Extension ("fixed-lower-bound array", Token_Ptr, |
| 3440 |
Is_Core_Extension => True); |
| 3441 |
|
| 3442 |
Expr_Node := Empty; |
| 3443 |
Scan; |
| 3444 |
|
| 3445 |
-- Otherwise parse the range's upper bound expression |
| 3446 |
|
| 3447 |
else |
| 3448 |
Expr_Node := P_Expression; |
| 3449 |
Check_Simple_Expression (Expr_Node); |
| 3450 |
end if; |
| 3451 |
|
| 3452 |
Set_High_Bound (Constr_Node, Expr_Node); |
| 3453 |
Append (Constr_Node, Constr_List); |
| 3454 |
goto Loop_Continue; |
| 3455 |
|
| 3456 |
-- Case of an expression which could be either form |
| 3457 |
|
| 3458 |
else |
| 3459 |
Append (Expr_Node, Constr_List); |
| 3460 |
goto Loop_Continue; |
| 3461 |
end if; |
| 3462 |
|
| 3463 |
-- Here with a single entry scanned |
| 3464 |
|
| 3465 |
<<Loop_Continue>> |
| 3466 |
exit when not Comma_Present; |
| 3467 |
|
| 3468 |
end loop; |
| 3469 |
|
| 3470 |
T_Right_Paren; |
| 3471 |
return Result_Node; |
| 3472 |
end P_Index_Or_Discriminant_Constraint; |
| 3473 |
|
| 3474 |
------------------------------------- |
| 3475 |
-- 3.7.1 Discriminant Association -- |
| 3476 |
------------------------------------- |
| 3477 |
|
| 3478 |
-- DISCRIMINANT_ASSOCIATION ::= |
| 3479 |
-- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>] |
| 3480 |
-- EXPRESSION |
| 3481 |
|
| 3482 |
-- This routine is used only when the name list is present and the caller |
| 3483 |
-- has already checked this (by scanning ahead and repositioning the |
| 3484 |
-- scan). |
| 3485 |
|
| 3486 |
-- Error_Recovery: cannot raise Error_Resync; |
| 3487 |
|
| 3488 |
function P_Discriminant_Association return Node_Id is |
| 3489 |
Discr_Node : Node_Id; |
| 3490 |
Names_List : List_Id; |
| 3491 |
Ident_Sloc : Source_Ptr; |
| 3492 |
|
| 3493 |
begin |
| 3494 |
Ident_Sloc := Token_Ptr; |
| 3495 |
Names_List := New_List; |
| 3496 |
|
| 3497 |
loop |
| 3498 |
Append (P_Identifier (C_Vertical_Bar_Arrow), Names_List); |
| 3499 |
exit when Token /= Tok_Vertical_Bar; |
| 3500 |
Scan; -- past | |
| 3501 |
end loop; |
| 3502 |
|
| 3503 |
Discr_Node := New_Node (N_Discriminant_Association, Ident_Sloc); |
| 3504 |
Set_Selector_Names (Discr_Node, Names_List); |
| 3505 |
TF_Arrow; |
| 3506 |
Set_Expression (Discr_Node, P_Expression); |
| 3507 |
return Discr_Node; |
| 3508 |
end P_Discriminant_Association; |
| 3509 |
|
| 3510 |
--------------------------------- |
| 3511 |
-- 3.8 Record Type Definition -- |
| 3512 |
--------------------------------- |
| 3513 |
|
| 3514 |
-- RECORD_TYPE_DEFINITION ::= |
| 3515 |
-- [[abstract] tagged] [limited] RECORD_DEFINITION |
| 3516 |
|
| 3517 |
-- There is no node in the tree for a record type definition. Instead |
| 3518 |
-- a record definition node appears, with possible Abstract_Present, |
| 3519 |
-- Tagged_Present, and Limited_Present flags set appropriately. |
| 3520 |
|
| 3521 |
---------------------------- |
| 3522 |
-- 3.8 Record Definition -- |
| 3523 |
---------------------------- |
| 3524 |
|
| 3525 |
-- RECORD_DEFINITION ::= |
| 3526 |
-- record |
| 3527 |
-- COMPONENT_LIST |
| 3528 |
-- end record |
| 3529 |
-- | null record |
| 3530 |
|
| 3531 |
-- Note: in the case where a record definition node is used to represent |
| 3532 |
-- a record type definition, the caller sets the Tagged_Present and |
| 3533 |
-- Limited_Present flags in the resulting N_Record_Definition node as |
| 3534 |
-- required. |
| 3535 |
|
| 3536 |
-- Note that the RECORD token at the start may be missing in certain |
| 3537 |
-- error situations, so this function is expected to post the error |
| 3538 |
|
| 3539 |
-- Error recovery: can raise Error_Resync |
| 3540 |
|
| 3541 |
function P_Record_Definition return Node_Id is |
| 3542 |
|
| 3543 |
procedure Catch_Out_Of_Order_Keywords (Keyword : String); |
| 3544 |
-- Catch ouf-of-order keywords in a record definition |
| 3545 |
|
| 3546 |
--------------------------------- |
| 3547 |
-- Catch_Out_Of_Order_Keywords -- |
| 3548 |
--------------------------------- |
| 3549 |
|
| 3550 |
procedure Catch_Out_Of_Order_Keywords (Keyword : String) is |
| 3551 |
begin |
| 3552 |
loop |
| 3553 |
if Token = Tok_Abstract then |
| 3554 |
Error_Msg_SC -- CODEFIX |
| 3555 |
("ABSTRACT must come before " & Keyword); |
| 3556 |
Scan; -- past ABSTRACT |
| 3557 |
|
| 3558 |
elsif Token = Tok_Tagged then |
| 3559 |
Error_Msg_SC -- CODEFIX |
| 3560 |
("TAGGED must come before " & Keyword); |
| 3561 |
Scan; -- past TAGGED |
| 3562 |
|
| 3563 |
elsif Token = Tok_Limited then |
| 3564 |
Error_Msg_SC -- CODEFIX |
| 3565 |
("LIMITED must come before " & Keyword); |
| 3566 |
Scan; -- past LIMITED |
| 3567 |
|
| 3568 |
else |
| 3569 |
exit; |
| 3570 |
end if; |
| 3571 |
end loop; |
| 3572 |
end Catch_Out_Of_Order_Keywords; |
| 3573 |
|
| 3574 |
Rec_Node : Node_Id; |
| 3575 |
|
| 3576 |
-- Start of processing for P_Record_Definition |
| 3577 |
|
| 3578 |
begin |
| 3579 |
Inside_Record_Definition := True; |
| 3580 |
Rec_Node := New_Node (N_Record_Definition, Token_Ptr); |
| 3581 |
|
| 3582 |
-- Null record case |
| 3583 |
|
| 3584 |
if Token = Tok_Null then |
| 3585 |
Scan; -- past NULL |
| 3586 |
|
| 3587 |
Catch_Out_Of_Order_Keywords ("NULL"); |
| 3588 |
T_Record; |
| 3589 |
Set_Null_Present (Rec_Node, True); |
| 3590 |
Catch_Out_Of_Order_Keywords ("RECORD"); |
| 3591 |
|
| 3592 |
-- Catch incomplete declaration to prevent cascaded errors, see |
| 3593 |
-- ACATS B393002 for an example. |
| 3594 |
|
| 3595 |
elsif Token = Tok_Semicolon then |
| 3596 |
Error_Msg_AP ("missing record definition"); |
| 3597 |
|
| 3598 |
-- Case starting with RECORD keyword. Build scope stack entry. For the |
| 3599 |
-- column, we use the first non-blank character on the line, to deal |
| 3600 |
-- with situations such as: |
| 3601 |
|
| 3602 |
-- type X is record |
| 3603 |
-- ... |
| 3604 |
-- end record; |
| 3605 |
|
| 3606 |
-- which is not official RM indentation, but is not uncommon usage, and |
| 3607 |
-- in particular is standard GNAT coding style, so handle it nicely. |
| 3608 |
|
| 3609 |
else |
| 3610 |
Push_Scope_Stack; |
| 3611 |
Scopes (Scope.Last).Etyp := E_Record; |
| 3612 |
Scopes (Scope.Last).Ecol := Start_Column; |
| 3613 |
Scopes (Scope.Last).Sloc := Token_Ptr; |
| 3614 |
Scopes (Scope.Last).Labl := Error; |
| 3615 |
Scopes (Scope.Last).Junk := (Token /= Tok_Record); |
| 3616 |
|
| 3617 |
T_Record; |
| 3618 |
Catch_Out_Of_Order_Keywords ("RECORD"); |
| 3619 |
|
| 3620 |
Set_Component_List (Rec_Node, P_Component_List); |
| 3621 |
|
| 3622 |
loop |
| 3623 |
exit when Check_End; |
| 3624 |
Discard_Junk_Node (P_Component_List); |
| 3625 |
end loop; |
| 3626 |
end if; |
| 3627 |
|
| 3628 |
Inside_Record_Definition := False; |
| 3629 |
return Rec_Node; |
| 3630 |
end P_Record_Definition; |
| 3631 |
|
| 3632 |
------------------------- |
| 3633 |
-- 3.8 Component List -- |
| 3634 |
------------------------- |
| 3635 |
|
| 3636 |
-- COMPONENT_LIST ::= |
| 3637 |
-- COMPONENT_ITEM {COMPONENT_ITEM} |
| 3638 |
-- | {COMPONENT_ITEM} VARIANT_PART |
| 3639 |
-- | null; |
| 3640 |
|
| 3641 |
-- Error recovery: cannot raise Error_Resync |
| 3642 |
|
| 3643 |
function P_Component_List return Node_Id is |
| 3644 |
Component_List_Node : Node_Id; |
| 3645 |
Decls_List : List_Id; |
| 3646 |
Scan_State : Saved_Scan_State; |
| 3647 |
Null_Loc : Source_Ptr; |
| 3648 |
|
| 3649 |
begin |
| 3650 |
Component_List_Node := New_Node (N_Component_List, Token_Ptr); |
| 3651 |
Decls_List := New_List; |
| 3652 |
|
| 3653 |
-- Handle null |
| 3654 |
|
| 3655 |
if Token = Tok_Null then |
| 3656 |
Null_Loc := Token_Ptr; |
| 3657 |
Scan; -- past NULL |
| 3658 |
TF_Semicolon; |
| 3659 |
P_Pragmas_Opt (Decls_List); |
| 3660 |
|
| 3661 |
-- If we have an END or WHEN now, everything is fine, otherwise we |
| 3662 |
-- complain about the null, ignore it, and scan for more components. |
| 3663 |
|
| 3664 |
if Token in Tok_End | Tok_When then |
| 3665 |
Set_Null_Present (Component_List_Node, True); |
| 3666 |
return Component_List_Node; |
| 3667 |
else |
| 3668 |
Error_Msg ("NULL component only allowed in null record", Null_Loc); |
| 3669 |
end if; |
| 3670 |
end if; |
| 3671 |
|
| 3672 |
-- Scan components for non-null record |
| 3673 |
|
| 3674 |
P_Pragmas_Opt (Decls_List); |
| 3675 |
|
| 3676 |
if Token /= Tok_Case then |
| 3677 |
loop |
| 3678 |
P_Component_Items (Decls_List); |
| 3679 |
P_Pragmas_Opt (Decls_List); |
| 3680 |
|
| 3681 |
exit when Token in Tok_End | Tok_Case | Tok_When; |
| 3682 |
|
| 3683 |
-- We are done if we do not have an identifier. However, if we |
| 3684 |
-- have a misspelled reserved identifier that is in a column to |
| 3685 |
-- the right of the record definition, we will treat it as an |
| 3686 |
-- identifier. It turns out to be too dangerous in practice to |
| 3687 |
-- accept such a mis-spelled identifier which does not have this |
| 3688 |
-- additional clue that confirms the incorrect spelling. |
| 3689 |
|
| 3690 |
if Token /= Tok_Identifier then |
| 3691 |
if Start_Column > Scopes (Scope.Last).Ecol |
| 3692 |
and then Is_Reserved_Identifier |
| 3693 |
then |
| 3694 |
Save_Scan_State (Scan_State); -- at reserved id |
| 3695 |
Scan; -- possible reserved id |
| 3696 |
|
| 3697 |
if Token in Tok_Comma | Tok_Colon then |
| 3698 |
Restore_Scan_State (Scan_State); |
| 3699 |
Scan_Reserved_Identifier (Force_Msg => True); |
| 3700 |
|
| 3701 |
-- Note reserved identifier used as field name after all |
| 3702 |
-- because not followed by colon or comma. |
| 3703 |
|
| 3704 |
else |
| 3705 |
Restore_Scan_State (Scan_State); |
| 3706 |
exit; |
| 3707 |
end if; |
| 3708 |
|
| 3709 |
-- Non-identifier that definitely was not reserved id |
| 3710 |
|
| 3711 |
else |
| 3712 |
exit; |
| 3713 |
end if; |
| 3714 |
end if; |
| 3715 |
end loop; |
| 3716 |
end if; |
| 3717 |
|
| 3718 |
if Token = Tok_Case then |
| 3719 |
Set_Variant_Part (Component_List_Node, P_Variant_Part); |
| 3720 |
|
| 3721 |
-- Check for junk after variant part |
| 3722 |
|
| 3723 |
if Token = Tok_Identifier then |
| 3724 |
Save_Scan_State (Scan_State); |
| 3725 |
Scan; -- past identifier |
| 3726 |
|
| 3727 |
if Token = Tok_Colon then |
| 3728 |
Restore_Scan_State (Scan_State); |
| 3729 |
Error_Msg_SC ("component may not follow variant part"); |
| 3730 |
Discard_Junk_Node (P_Component_List); |
| 3731 |
|
| 3732 |
elsif Token = Tok_Case then |
| 3733 |
Restore_Scan_State (Scan_State); |
| 3734 |
Error_Msg_SC ("only one variant part allowed in a record"); |
| 3735 |
Discard_Junk_Node (P_Component_List); |
| 3736 |
|
| 3737 |
else |
| 3738 |
Restore_Scan_State (Scan_State); |
| 3739 |
end if; |
| 3740 |
end if; |
| 3741 |
end if; |
| 3742 |
|
| 3743 |
Set_Component_Items (Component_List_Node, Decls_List); |
| 3744 |
return Component_List_Node; |
| 3745 |
end P_Component_List; |
| 3746 |
|
| 3747 |
------------------------- |
| 3748 |
-- 3.8 Component Item -- |
| 3749 |
------------------------- |
| 3750 |
|
| 3751 |
-- COMPONENT_ITEM ::= COMPONENT_DECLARATION | REPRESENTATION_CLAUSE |
| 3752 |
|
| 3753 |
-- COMPONENT_DECLARATION ::= |
| 3754 |
-- DEFINING_IDENTIFIER_LIST : COMPONENT_DEFINITION |
| 3755 |
-- [:= DEFAULT_EXPRESSION] |
| 3756 |
-- [ASPECT_SPECIFICATIONS]; |
| 3757 |
|
| 3758 |
-- COMPONENT_DEFINITION ::= |
| 3759 |
-- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION |
| 3760 |
|
| 3761 |
-- Error recovery: cannot raise Error_Resync, if an error occurs, |
| 3762 |
-- the scan is positioned past the following semicolon. |
| 3763 |
|
| 3764 |
-- Note: we do not yet allow representation clauses to appear as component |
| 3765 |
-- items, do we need to add this capability sometime in the future ??? |
| 3766 |
|
| 3767 |
procedure P_Component_Items (Decls : List_Id) is |
| 3768 |
Aliased_Present : Boolean := False; |
| 3769 |
CompDef_Node : Node_Id; |
| 3770 |
Decl_Node : Node_Id := Empty; -- initialize to prevent warning |
| 3771 |
Scan_State : Saved_Scan_State; |
| 3772 |
Not_Null_Present : Boolean := False; |
| 3773 |
Num_Idents : Nat; |
| 3774 |
Ident : Nat; |
| 3775 |
Ident_Sloc : Source_Ptr; |
| 3776 |
|
| 3777 |
Idents : array (Int range 1 .. 4096) of Entity_Id; |
| 3778 |
-- This array holds the list of defining identifiers. The upper bound |
| 3779 |
-- of 4096 is intended to be essentially infinite, and we do not even |
| 3780 |
-- bother to check for it being exceeded. |
| 3781 |
|
| 3782 |
begin |
| 3783 |
if Token /= Tok_Identifier then |
| 3784 |
Error_Msg_SC ("component declaration expected"); |
| 3785 |
Resync_Past_Semicolon; |
| 3786 |
return; |
| 3787 |
end if; |
| 3788 |
|
| 3789 |
Ident_Sloc := Token_Ptr; |
| 3790 |
Check_Bad_Layout; |
| 3791 |
Idents (1) := P_Defining_Identifier (C_Comma_Colon); |
| 3792 |
Num_Idents := 1; |
| 3793 |
|
| 3794 |
while Comma_Present loop |
| 3795 |
Num_Idents := Num_Idents + 1; |
| 3796 |
Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon); |
| 3797 |
end loop; |
| 3798 |
|
| 3799 |
-- If there are multiple identifiers, we repeatedly scan the |
| 3800 |
-- type and initialization expression information by resetting |
| 3801 |
-- the scan pointer (so that we get completely separate trees |
| 3802 |
-- for each occurrence). |
| 3803 |
|
| 3804 |
if Num_Idents > 1 then |
| 3805 |
Save_Scan_State (Scan_State); |
| 3806 |
end if; |
| 3807 |
|
| 3808 |
T_Colon; |
| 3809 |
|
| 3810 |
-- Loop through defining identifiers in list |
| 3811 |
|
| 3812 |
Ident := 1; |
| 3813 |
Ident_Loop : loop |
| 3814 |
|
| 3815 |
-- The following block is present to catch Error_Resync |
| 3816 |
-- which causes the parse to be reset past the semicolon |
| 3817 |
|
| 3818 |
begin |
| 3819 |
Decl_Node := New_Node (N_Component_Declaration, Ident_Sloc); |
| 3820 |
Set_Defining_Identifier (Decl_Node, Idents (Ident)); |
| 3821 |
|
| 3822 |
if Token = Tok_Constant then |
| 3823 |
Error_Msg_SC ("constant component not permitted"); |
| 3824 |
Scan; |
| 3825 |
end if; |
| 3826 |
|
| 3827 |
CompDef_Node := New_Node (N_Component_Definition, Token_Ptr); |
| 3828 |
|
| 3829 |
if Token_Name = Name_Aliased then |
| 3830 |
Check_95_Keyword (Tok_Aliased, Tok_Identifier); |
| 3831 |
end if; |
| 3832 |
|
| 3833 |
if Token = Tok_Aliased then |
| 3834 |
Aliased_Present := True; |
| 3835 |
Scan; -- past ALIASED |
| 3836 |
end if; |
| 3837 |
|
| 3838 |
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231/AI-254) |
| 3839 |
|
| 3840 |
-- Ada 2005 (AI-230): Access Definition case |
| 3841 |
|
| 3842 |
if Token = Tok_Access then |
| 3843 |
Error_Msg_Ada_2005_Extension |
| 3844 |
("generalized use of anonymous access types"); |
| 3845 |
|
| 3846 |
-- AI95-406 makes "aliased" legal (and useless) here, so the |
| 3847 |
-- following code which used to be required is commented out. |
| 3848 |
|
| 3849 |
-- if Aliased_Present then |
| 3850 |
-- Error_Msg_SP ("ALIASED not allowed here"); |
| 3851 |
-- end if; |
| 3852 |
|
| 3853 |
Set_Subtype_Indication (CompDef_Node, Empty); |
| 3854 |
Set_Aliased_Present (CompDef_Node, Aliased_Present); |
| 3855 |
Set_Access_Definition (CompDef_Node, |
| 3856 |
P_Access_Definition (Not_Null_Present)); |
| 3857 |
else |
| 3858 |
|
| 3859 |
Set_Access_Definition (CompDef_Node, Empty); |
| 3860 |
Set_Aliased_Present (CompDef_Node, Aliased_Present); |
| 3861 |
Set_Null_Exclusion_Present (CompDef_Node, Not_Null_Present); |
| 3862 |
|
| 3863 |
if Token = Tok_Array then |
| 3864 |
Error_Msg_SC ("anonymous array not allowed as component"); |
| 3865 |
raise Error_Resync; |
| 3866 |
end if; |
| 3867 |
|
| 3868 |
Set_Subtype_Indication (CompDef_Node, |
| 3869 |
P_Subtype_Indication (Not_Null_Present)); |
| 3870 |
end if; |
| 3871 |
|
| 3872 |
Set_Component_Definition (Decl_Node, CompDef_Node); |
| 3873 |
Set_Expression (Decl_Node, Init_Expr_Opt); |
| 3874 |
|
| 3875 |
if Ident > 1 then |
| 3876 |
Set_Prev_Ids (Decl_Node, True); |
| 3877 |
end if; |
| 3878 |
|
| 3879 |
if Ident < Num_Idents then |
| 3880 |
Set_More_Ids (Decl_Node, True); |
| 3881 |
end if; |
| 3882 |
|
| 3883 |
P_Aspect_Specifications (Decl_Node, Semicolon => True); |
| 3884 |
|
| 3885 |
Append (Decl_Node, Decls); |
| 3886 |
exception |
| 3887 |
when Error_Resync => |
| 3888 |
if Token /= Tok_End then |
| 3889 |
Resync_Past_Semicolon; |
| 3890 |
end if; |
| 3891 |
end; |
| 3892 |
|
| 3893 |
exit Ident_Loop when Ident = Num_Idents; |
| 3894 |
Ident := Ident + 1; |
| 3895 |
Restore_Scan_State (Scan_State); |
| 3896 |
T_Colon; |
| 3897 |
end loop Ident_Loop; |
| 3898 |
end P_Component_Items; |
| 3899 |
|
| 3900 |
-------------------------------- |
| 3901 |
-- 3.8 Component Declaration -- |
| 3902 |
-------------------------------- |
| 3903 |
|
| 3904 |
-- Parsed by P_Component_Items (3.8) |
| 3905 |
|
| 3906 |
------------------------- |
| 3907 |
-- 3.8.1 Variant Part -- |
| 3908 |
------------------------- |
| 3909 |
|
| 3910 |
-- VARIANT_PART ::= |
| 3911 |
-- case discriminant_DIRECT_NAME is |
| 3912 |
-- VARIANT |
| 3913 |
-- {VARIANT} |
| 3914 |
-- end case; |
| 3915 |
|
| 3916 |
-- The caller has checked that the initial token is CASE |
| 3917 |
|
| 3918 |
-- Error recovery: cannot raise Error_Resync |
| 3919 |
|
| 3920 |
function P_Variant_Part return Node_Id is |
| 3921 |
Variant_Part_Node : Node_Id; |
| 3922 |
Variants_List : List_Id; |
| 3923 |
Case_Node : Node_Id; |
| 3924 |
|
| 3925 |
begin |
| 3926 |
Variant_Part_Node := New_Node (N_Variant_Part, Token_Ptr); |
| 3927 |
Push_Scope_Stack; |
| 3928 |
Scopes (Scope.Last).Etyp := E_Case; |
| 3929 |
Scopes (Scope.Last).Sloc := Token_Ptr; |
| 3930 |
Scopes (Scope.Last).Ecol := Start_Column; |
| 3931 |
|
| 3932 |
Scan; -- past CASE |
| 3933 |
Case_Node := P_Expression; |
| 3934 |
Set_Name (Variant_Part_Node, Case_Node); |
| 3935 |
|
| 3936 |
if Nkind (Case_Node) /= N_Identifier then |
| 3937 |
Set_Name (Variant_Part_Node, Error); |
| 3938 |
Error_Msg ("discriminant name expected", Sloc (Case_Node)); |
| 3939 |
|
| 3940 |
elsif Paren_Count (Case_Node) /= 0 then |
| 3941 |
Error_Msg |
| 3942 |
("|discriminant name may not be parenthesized", |
| 3943 |
Sloc (Case_Node)); |
| 3944 |
Set_Paren_Count (Case_Node, 0); |
| 3945 |
end if; |
| 3946 |
|
| 3947 |
TF_Is; |
| 3948 |
Variants_List := New_List; |
| 3949 |
P_Pragmas_Opt (Variants_List); |
| 3950 |
|
| 3951 |
-- Test missing variant |
| 3952 |
|
| 3953 |
if Token = Tok_End then |
| 3954 |
Error_Msg_BC ("WHEN expected (must have at least one variant)"); |
| 3955 |
else |
| 3956 |
Append (P_Variant, Variants_List); |
| 3957 |
end if; |
| 3958 |
|
| 3959 |
-- Loop through variants, note that we allow if in place of when, |
| 3960 |
-- this error will be detected and handled in P_Variant. |
| 3961 |
|
| 3962 |
loop |
| 3963 |
P_Pragmas_Opt (Variants_List); |
| 3964 |
|
| 3965 |
if Token not in Tok_When | Tok_If | Tok_Others then |
| 3966 |
exit when Check_End; |
| 3967 |
end if; |
| 3968 |
|
| 3969 |
Append (P_Variant, Variants_List); |
| 3970 |
end loop; |
| 3971 |
|
| 3972 |
Set_Variants (Variant_Part_Node, Variants_List); |
| 3973 |
return Variant_Part_Node; |
| 3974 |
end P_Variant_Part; |
| 3975 |
|
| 3976 |
-------------------- |
| 3977 |
-- 3.8.1 Variant -- |
| 3978 |
-------------------- |
| 3979 |
|
| 3980 |
-- VARIANT ::= |
| 3981 |
-- when DISCRETE_CHOICE_LIST => |
| 3982 |
-- COMPONENT_LIST |
| 3983 |
|
| 3984 |
-- Error recovery: cannot raise Error_Resync |
| 3985 |
|
| 3986 |
-- The initial token on entry is either WHEN, IF or OTHERS |
| 3987 |
|
| 3988 |
function P_Variant return Node_Id is |
| 3989 |
Variant_Node : Node_Id; |
| 3990 |
|
| 3991 |
begin |
| 3992 |
-- Special check to recover nicely from use of IF in place of WHEN |
| 3993 |
|
| 3994 |
if Token = Tok_If then |
| 3995 |
T_When; |
| 3996 |
Scan; -- past IF |
| 3997 |
else |
| 3998 |
T_When; |
| 3999 |
end if; |
| 4000 |
|
| 4001 |
Variant_Node := New_Node (N_Variant, Prev_Token_Ptr); |
| 4002 |
Set_Discrete_Choices (Variant_Node, P_Discrete_Choice_List); |
| 4003 |
TF_Arrow; |
| 4004 |
Set_Component_List (Variant_Node, P_Component_List); |
| 4005 |
return Variant_Node; |
| 4006 |
end P_Variant; |
| 4007 |
|
| 4008 |
--------------------------------- |
| 4009 |
-- 3.8.1 Discrete Choice List -- |
| 4010 |
--------------------------------- |
| 4011 |
|
| 4012 |
-- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE} |
| 4013 |
|
| 4014 |
-- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others |
| 4015 |
|
| 4016 |
-- Note: in Ada 83, the expression must be a simple expression |
| 4017 |
|
| 4018 |
-- Error recovery: cannot raise Error_Resync |
| 4019 |
|
| 4020 |
function P_Discrete_Choice_List return List_Id is |
| 4021 |
Choices : List_Id; |
| 4022 |
Expr_Node : Node_Id := Empty; -- initialize to prevent warning |
| 4023 |
Choice_Node : Node_Id; |
| 4024 |
|
| 4025 |
begin |
| 4026 |
Choices := New_List; |
| 4027 |
loop |
| 4028 |
if Token = Tok_Others then |
| 4029 |
Append (New_Node (N_Others_Choice, Token_Ptr), Choices); |
| 4030 |
Scan; -- past OTHERS |
| 4031 |
|
| 4032 |
else |
| 4033 |
begin |
| 4034 |
-- Scan out expression or range attribute |
| 4035 |
|
| 4036 |
Expr_Node := P_Expression_Or_Range_Attribute; |
| 4037 |
Ignore (Tok_Right_Paren); |
| 4038 |
|
| 4039 |
if Token = Tok_Colon |
| 4040 |
and then Nkind (Expr_Node) = N_Identifier |
| 4041 |
then |
| 4042 |
Error_Msg_SP ("label not permitted in this context"); |
| 4043 |
Scan; -- past colon |
| 4044 |
|
| 4045 |
-- Range attribute |
| 4046 |
|
| 4047 |
elsif Expr_Form = EF_Range_Attr then |
| 4048 |
Append (Expr_Node, Choices); |
| 4049 |
|
| 4050 |
-- Explicit range |
| 4051 |
|
| 4052 |
elsif Token = Tok_Dot_Dot then |
| 4053 |
Check_Simple_Expression (Expr_Node); |
| 4054 |
Choice_Node := New_Node (N_Range, Token_Ptr); |
| 4055 |
Set_Low_Bound (Choice_Node, Expr_Node); |
| 4056 |
Scan; -- past .. |
| 4057 |
Expr_Node := P_Expression_No_Right_Paren; |
| 4058 |
Check_Simple_Expression (Expr_Node); |
| 4059 |
Set_High_Bound (Choice_Node, Expr_Node); |
| 4060 |
Append (Choice_Node, Choices); |
| 4061 |
|
| 4062 |
-- Simple name, must be subtype, so range allowed |
| 4063 |
|
| 4064 |
elsif Expr_Form = EF_Simple_Name then |
| 4065 |
if Token = Tok_Range then |
| 4066 |
Append (P_Subtype_Indication (Expr_Node), Choices); |
| 4067 |
|
| 4068 |
elsif Token in Token_Class_Consk then |
| 4069 |
Error_Msg_SC |
| 4070 |
("the only constraint allowed here " & |
| 4071 |
"is a range constraint"); |
| 4072 |
Discard_Junk_Node (P_Constraint_Opt); |
| 4073 |
Append (Expr_Node, Choices); |
| 4074 |
|
| 4075 |
else |
| 4076 |
Append (Expr_Node, Choices); |
| 4077 |
end if; |
| 4078 |
|
| 4079 |
-- Expression |
| 4080 |
|
| 4081 |
else |
| 4082 |
-- In Ada 2012 mode, the expression must be a simple |
| 4083 |
-- expression. The reason for this restriction (i.e. going |
| 4084 |
-- back to the Ada 83 rule) is to avoid ambiguities when set |
| 4085 |
-- membership operations are allowed, consider the |
| 4086 |
-- following: |
| 4087 |
|
| 4088 |
-- when A in 1 .. 10 | 12 => |
| 4089 |
|
| 4090 |
-- This is ambiguous without parentheses, so we require one |
| 4091 |
-- of the following two parenthesized forms to disambiguate: |
| 4092 |
|
| 4093 |
-- one of the following: |
| 4094 |
|
| 4095 |
-- when (A in 1 .. 10 | 12) => |
| 4096 |
-- when (A in 1 .. 10) | 12 => |
| 4097 |
|
| 4098 |
-- To solve this, in Ada 2012 mode, we disallow the use of |
| 4099 |
-- membership operations in expressions in choices. |
| 4100 |
|
| 4101 |
-- Technically in the grammar, the expression must match the |
| 4102 |
-- grammar for restricted expression. |
| 4103 |
|
| 4104 |
if Ada_Version >= Ada_2012 then |
| 4105 |
Check_Restricted_Expression (Expr_Node); |
| 4106 |
|
| 4107 |
-- In Ada 83 mode, the syntax required a simple expression |
| 4108 |
|
| 4109 |
else |
| 4110 |
Check_Simple_Expression_In_Ada_83 (Expr_Node); |
| 4111 |
end if; |
| 4112 |
|
| 4113 |
Append (Expr_Node, Choices); |
| 4114 |
end if; |
| 4115 |
|
| 4116 |
exception |
| 4117 |
when Error_Resync => |
| 4118 |
Resync_Choice; |
| 4119 |
return Error_List; |
| 4120 |
end; |
| 4121 |
end if; |
| 4122 |
|
| 4123 |
if Token = Tok_Comma then |
| 4124 |
if Nkind (Expr_Node) = N_Iterated_Component_Association then |
| 4125 |
return Choices; |
| 4126 |
end if; |
| 4127 |
|
| 4128 |
Scan; -- past comma |
| 4129 |
|
| 4130 |
if Token = Tok_Vertical_Bar then |
| 4131 |
Error_Msg_SP -- CODEFIX |
| 4132 |
("|extra "","" ignored"); |
| 4133 |
Scan; -- past | |
| 4134 |
|
| 4135 |
else |
| 4136 |
Error_Msg_SP -- CODEFIX |
| 4137 |
(""","" should be ""'|"""); |
| 4138 |
end if; |
| 4139 |
|
| 4140 |
else |
| 4141 |
exit when Token /= Tok_Vertical_Bar; |
| 4142 |
Scan; -- past | |
| 4143 |
end if; |
| 4144 |
|
| 4145 |
end loop; |
| 4146 |
|
| 4147 |
return Choices; |
| 4148 |
end P_Discrete_Choice_List; |
| 4149 |
|
| 4150 |
---------------------------- |
| 4151 |
-- 3.8.1 Discrete Choice -- |
| 4152 |
---------------------------- |
| 4153 |
|
| 4154 |
-- Parsed by P_Discrete_Choice_List (3.8.1) |
| 4155 |
|
| 4156 |
---------------------------------- |
| 4157 |
-- 3.9.1 Record Extension Part -- |
| 4158 |
---------------------------------- |
| 4159 |
|
| 4160 |
-- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION |
| 4161 |
|
| 4162 |
-- Parsed by P_Derived_Type_Def_Or_Private_Ext_Decl (3.4) |
| 4163 |
|
| 4164 |
-------------------------------------- |
| 4165 |
-- 3.9.4 Interface Type Definition -- |
| 4166 |
-------------------------------------- |
| 4167 |
|
| 4168 |
-- INTERFACE_TYPE_DEFINITION ::= |
| 4169 |
-- [limited | task | protected | synchronized] interface |
| 4170 |
-- [and INTERFACE_LIST] |
| 4171 |
|
| 4172 |
-- Error recovery: cannot raise Error_Resync |
| 4173 |
|
| 4174 |
function P_Interface_Type_Definition |
| 4175 |
(Abstract_Present : Boolean) return Node_Id |
| 4176 |
is |
| 4177 |
Typedef_Node : Node_Id; |
| 4178 |
|
| 4179 |
begin |
| 4180 |
Error_Msg_Ada_2005_Extension ("abstract interface"); |
| 4181 |
|
| 4182 |
if Abstract_Present then |
| 4183 |
Error_Msg_SP |
| 4184 |
("ABSTRACT not allowed in interface type definition " & |
| 4185 |
"(RM 3.9.4(2/2))"); |
| 4186 |
end if; |
| 4187 |
|
| 4188 |
Scan; -- past INTERFACE |
| 4189 |
|
| 4190 |
-- Ada 2005 (AI-345): In case of interfaces with a null list of |
| 4191 |
-- interfaces we build a record_definition node. |
| 4192 |
|
| 4193 |
if Token = Tok_Semicolon or else Aspect_Specifications_Present then |
| 4194 |
Typedef_Node := New_Node (N_Record_Definition, Token_Ptr); |
| 4195 |
|
| 4196 |
Set_Abstract_Present (Typedef_Node); |
| 4197 |
Set_Tagged_Present (Typedef_Node); |
| 4198 |
Set_Null_Present (Typedef_Node); |
| 4199 |
Set_Interface_Present (Typedef_Node); |
| 4200 |
|
| 4201 |
-- Ada 2005 (AI-251): In case of not-synchronized interfaces that have |
| 4202 |
-- a list of interfaces we build a derived_type_definition node. This |
| 4203 |
-- simplifies the semantic analysis (and hence further maintenance) |
| 4204 |
|
| 4205 |
else |
| 4206 |
if Token /= Tok_And then |
| 4207 |
Error_Msg_AP ("AND expected"); |
| 4208 |
else |
| 4209 |
Scan; -- past AND |
| 4210 |
end if; |
| 4211 |
|
| 4212 |
Typedef_Node := New_Node (N_Derived_Type_Definition, Token_Ptr); |
| 4213 |
|
| 4214 |
Set_Abstract_Present (Typedef_Node); |
| 4215 |
Set_Interface_Present (Typedef_Node); |
| 4216 |
Set_Subtype_Indication (Typedef_Node, P_Qualified_Simple_Name); |
| 4217 |
|
| 4218 |
Set_Record_Extension_Part (Typedef_Node, |
| 4219 |
New_Node (N_Record_Definition, Token_Ptr)); |
| 4220 |
Set_Null_Present (Record_Extension_Part (Typedef_Node)); |
| 4221 |
|
| 4222 |
if Token = Tok_And then |
| 4223 |
Set_Interface_List (Typedef_Node, New_List); |
| 4224 |
Scan; -- past AND |
| 4225 |
|
| 4226 |
loop |
| 4227 |
Append (P_Qualified_Simple_Name, |
| 4228 |
Interface_List (Typedef_Node)); |
| 4229 |
exit when Token /= Tok_And; |
| 4230 |
Scan; -- past AND |
| 4231 |
end loop; |
| 4232 |
end if; |
| 4233 |
end if; |
| 4234 |
|
| 4235 |
return Typedef_Node; |
| 4236 |
end P_Interface_Type_Definition; |
| 4237 |
|
| 4238 |
---------------------------------- |
| 4239 |
-- 3.10 Access Type Definition -- |
| 4240 |
---------------------------------- |
| 4241 |
|
| 4242 |
-- ACCESS_TYPE_DEFINITION ::= |
| 4243 |
-- ACCESS_TO_OBJECT_DEFINITION |
| 4244 |
-- | ACCESS_TO_SUBPROGRAM_DEFINITION |
| 4245 |
|
| 4246 |
-- ACCESS_TO_OBJECT_DEFINITION ::= |
| 4247 |
-- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION |
| 4248 |
|
| 4249 |
-- GENERAL_ACCESS_MODIFIER ::= all | constant |
| 4250 |
|
| 4251 |
-- ACCESS_TO_SUBPROGRAM_DEFINITION |
| 4252 |
-- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE |
| 4253 |
-- | [NULL_EXCLUSION] access [protected] function |
| 4254 |
-- PARAMETER_AND_RESULT_PROFILE |
| 4255 |
|
| 4256 |
-- PARAMETER_PROFILE ::= [FORMAL_PART] |
| 4257 |
|
| 4258 |
-- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK |
| 4259 |
|
| 4260 |
-- Ada 2005 (AI-254): If Header_Already_Parsed then the caller has already |
| 4261 |
-- parsed the null_exclusion part and has also removed the ACCESS token; |
| 4262 |
-- otherwise the caller has just checked that the initial token is ACCESS |
| 4263 |
|
| 4264 |
-- Error recovery: can raise Error_Resync |
| 4265 |
|
| 4266 |
function P_Access_Type_Definition |
| 4267 |
(Header_Already_Parsed : Boolean := False) return Node_Id |
| 4268 |
is |
| 4269 |
procedure Check_Junk_Subprogram_Name; |
| 4270 |
-- Used in access to subprogram definition cases to check for an |
| 4271 |
-- identifier or operator symbol that does not belong. |
| 4272 |
|
| 4273 |
-------------------------------- |
| 4274 |
-- Check_Junk_Subprogram_Name -- |
| 4275 |
-------------------------------- |
| 4276 |
|
| 4277 |
procedure Check_Junk_Subprogram_Name is |
| 4278 |
Saved_State : Saved_Scan_State; |
| 4279 |
|
| 4280 |
begin |
| 4281 |
if Token in Tok_Identifier | Tok_Operator_Symbol then |
| 4282 |
Save_Scan_State (Saved_State); |
| 4283 |
Scan; -- past possible junk subprogram name |
| 4284 |
|
| 4285 |
if Token in Tok_Left_Paren | Tok_Semicolon then |
| 4286 |
Error_Msg_SP ("unexpected subprogram name ignored"); |
| 4287 |
else |
| 4288 |
Restore_Scan_State (Saved_State); |
| 4289 |
end if; |
| 4290 |
end if; |
| 4291 |
end Check_Junk_Subprogram_Name; |
| 4292 |
|
| 4293 |
Access_Loc : constant Source_Ptr := Token_Ptr; |
| 4294 |
Prot_Flag : Boolean; |
| 4295 |
Not_Null_Present : Boolean := False; |
| 4296 |
Not_Null_Subtype : Boolean := False; |
| 4297 |
Not_Null_Subtype_Loc : Source_Ptr; -- loc of second "not null" |
| 4298 |
Type_Def_Node : Node_Id; |
| 4299 |
Result_Not_Null : Boolean; |
| 4300 |
Result_Node : Node_Id; |
| 4301 |
|
| 4302 |
-- Start of processing for P_Access_Type_Definition |
| 4303 |
|
| 4304 |
begin |
| 4305 |
if not Header_Already_Parsed then |
| 4306 |
-- NOT NULL ACCESS... is a common form of access definition. ACCESS |
| 4307 |
-- NOT NULL... is certainly rare, but syntactically legal. NOT NULL |
| 4308 |
-- ACCESS NOT NULL... is rarer yet, and also legal. The last two |
| 4309 |
-- cases are only meaningful if the following subtype indication |
| 4310 |
-- denotes an access type. We check below for "not null procedure" |
| 4311 |
-- and "not null function"; in the access-to-object case it is a |
| 4312 |
-- semantic check. The flag Not_Null_Subtype indicates that this |
| 4313 |
-- second null exclusion is present in the access type definition. |
| 4314 |
|
| 4315 |
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231) |
| 4316 |
|
| 4317 |
if Token /= Tok_Access then |
| 4318 |
Error_Msg |
| 4319 |
("ACCESS expected", |
| 4320 |
Token_Ptr); |
| 4321 |
end if; |
| 4322 |
|
| 4323 |
Scan; -- past ACCESS |
| 4324 |
|
| 4325 |
Not_Null_Subtype_Loc := Token_Ptr; |
| 4326 |
Not_Null_Subtype := P_Null_Exclusion; -- Might also appear |
| 4327 |
end if; |
| 4328 |
|
| 4329 |
if Token_Name = Name_Protected then |
| 4330 |
Check_95_Keyword (Tok_Protected, Tok_Procedure); |
| 4331 |
Check_95_Keyword (Tok_Protected, Tok_Function); |
| 4332 |
end if; |
| 4333 |
|
| 4334 |
Prot_Flag := (Token = Tok_Protected); |
| 4335 |
|
| 4336 |
if Prot_Flag then |
| 4337 |
Scan; -- past PROTECTED |
| 4338 |
|
| 4339 |
if Token not in Tok_Procedure | Tok_Function then |
| 4340 |
Error_Msg_SC -- CODEFIX |
| 4341 |
("FUNCTION or PROCEDURE expected"); |
| 4342 |
end if; |
| 4343 |
end if; |
| 4344 |
|
| 4345 |
-- Access-to-subprogram case |
| 4346 |
|
| 4347 |
if Token in Tok_Procedure | Tok_Function then |
| 4348 |
|
| 4349 |
-- Check for "not null [protected] procedure" and "not null |
| 4350 |
-- [protected] function". |
| 4351 |
|
| 4352 |
if Not_Null_Subtype then |
| 4353 |
Error_Msg |
| 4354 |
("null exclusion must apply to access type", |
| 4355 |
Not_Null_Subtype_Loc); |
| 4356 |
end if; |
| 4357 |
end if; |
| 4358 |
|
| 4359 |
if Token = Tok_Procedure then |
| 4360 |
if Ada_Version = Ada_83 then |
| 4361 |
Error_Msg_SC ("(Ada 83) access to procedure not allowed!"); |
| 4362 |
end if; |
| 4363 |
|
| 4364 |
Type_Def_Node := New_Node (N_Access_Procedure_Definition, Access_Loc); |
| 4365 |
Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present); |
| 4366 |
Scan; -- past PROCEDURE |
| 4367 |
Check_Junk_Subprogram_Name; |
| 4368 |
Set_Parameter_Specifications (Type_Def_Node, P_Parameter_Profile); |
| 4369 |
Set_Protected_Present (Type_Def_Node, Prot_Flag); |
| 4370 |
|
| 4371 |
elsif Token = Tok_Function then |
| 4372 |
if Ada_Version = Ada_83 then |
| 4373 |
Error_Msg_SC ("(Ada 83) access to function not allowed!"); |
| 4374 |
end if; |
| 4375 |
|
| 4376 |
Type_Def_Node := New_Node (N_Access_Function_Definition, Access_Loc); |
| 4377 |
Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present); |
| 4378 |
Scan; -- past FUNCTION |
| 4379 |
Check_Junk_Subprogram_Name; |
| 4380 |
Set_Parameter_Specifications (Type_Def_Node, P_Parameter_Profile); |
| 4381 |
Set_Protected_Present (Type_Def_Node, Prot_Flag); |
| 4382 |
TF_Return; |
| 4383 |
|
| 4384 |
Result_Not_Null := P_Null_Exclusion; -- Ada 2005 (AI-231) |
| 4385 |
|
| 4386 |
-- Ada 2005 (AI-318-02) |
| 4387 |
|
| 4388 |
if Token = Tok_Access then |
| 4389 |
Error_Msg_Ada_2005_Extension ("anonymous access result type"); |
| 4390 |
|
| 4391 |
Result_Node := P_Access_Definition (Result_Not_Null); |
| 4392 |
|
| 4393 |
else |
| 4394 |
Result_Node := P_Subtype_Mark; |
| 4395 |
No_Constraint; |
| 4396 |
|
| 4397 |
-- A null exclusion on the result type must be recorded in a flag |
| 4398 |
-- distinct from the one used for the access-to-subprogram type's |
| 4399 |
-- null exclusion. |
| 4400 |
|
| 4401 |
Set_Null_Exclusion_In_Return_Present |
| 4402 |
(Type_Def_Node, Result_Not_Null); |
| 4403 |
end if; |
| 4404 |
|
| 4405 |
Set_Result_Definition (Type_Def_Node, Result_Node); |
| 4406 |
|
| 4407 |
-- Access-to-object case |
| 4408 |
|
| 4409 |
else |
| 4410 |
Type_Def_Node := New_Node (N_Access_To_Object_Definition, Access_Loc); |
| 4411 |
Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present); |
| 4412 |
Set_Null_Excluding_Subtype (Type_Def_Node, Not_Null_Subtype); |
| 4413 |
|
| 4414 |
if Token in Tok_All | Tok_Constant then |
| 4415 |
if Ada_Version = Ada_83 then |
| 4416 |
Error_Msg_SC ("(Ada 83) access modifier not allowed!"); |
| 4417 |
end if; |
| 4418 |
|
| 4419 |
if Token = Tok_All then |
| 4420 |
Set_All_Present (Type_Def_Node, True); |
| 4421 |
|
| 4422 |
else |
| 4423 |
Set_Constant_Present (Type_Def_Node, True); |
| 4424 |
end if; |
| 4425 |
|
| 4426 |
Scan; -- past ALL or CONSTANT |
| 4427 |
end if; |
| 4428 |
|
| 4429 |
Set_Subtype_Indication (Type_Def_Node, |
| 4430 |
P_Subtype_Indication (Not_Null_Present)); |
| 4431 |
end if; |
| 4432 |
|
| 4433 |
return Type_Def_Node; |
| 4434 |
end P_Access_Type_Definition; |
| 4435 |
|
| 4436 |
--------------------------------------- |
| 4437 |
-- 3.10 Access To Object Definition -- |
| 4438 |
--------------------------------------- |
| 4439 |
|
| 4440 |
-- Parsed by P_Access_Type_Definition (3.10) |
| 4441 |
|
| 4442 |
----------------------------------- |
| 4443 |
-- 3.10 General Access Modifier -- |
| 4444 |
----------------------------------- |
| 4445 |
|
| 4446 |
-- Parsed by P_Access_Type_Definition (3.10) |
| 4447 |
|
| 4448 |
------------------------------------------- |
| 4449 |
-- 3.10 Access To Subprogram Definition -- |
| 4450 |
------------------------------------------- |
| 4451 |
|
| 4452 |
-- Parsed by P_Access_Type_Definition (3.10) |
| 4453 |
|
| 4454 |
----------------------------- |
| 4455 |
-- 3.10 Access Definition -- |
| 4456 |
----------------------------- |
| 4457 |
|
| 4458 |
-- ACCESS_DEFINITION ::= |
| 4459 |
-- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK |
| 4460 |
-- | ACCESS_TO_SUBPROGRAM_DEFINITION |
| 4461 |
-- |
| 4462 |
-- ACCESS_TO_SUBPROGRAM_DEFINITION |
| 4463 |
-- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE |
| 4464 |
-- | [NULL_EXCLUSION] access [protected] function |
| 4465 |
-- PARAMETER_AND_RESULT_PROFILE |
| 4466 |
|
| 4467 |
-- The caller has parsed the null-exclusion part and it has also checked |
| 4468 |
-- that the next token is ACCESS |
| 4469 |
|
| 4470 |
-- Error recovery: cannot raise Error_Resync |
| 4471 |
|
| 4472 |
function P_Access_Definition |
| 4473 |
(Null_Exclusion_Present : Boolean) return Node_Id |
| 4474 |
is |
| 4475 |
Def_Node : Node_Id; |
| 4476 |
Subp_Node : Node_Id; |
| 4477 |
|
| 4478 |
begin |
| 4479 |
Def_Node := New_Node (N_Access_Definition, Token_Ptr); |
| 4480 |
Scan; -- past ACCESS |
| 4481 |
|
| 4482 |
-- Ada 2005 (AI-254): Access_To_Subprogram_Definition |
| 4483 |
|
| 4484 |
if Token in Tok_Protected | Tok_Procedure | Tok_Function then |
| 4485 |
Error_Msg_Ada_2005_Extension ("access-to-subprogram"); |
| 4486 |
|
| 4487 |
Subp_Node := P_Access_Type_Definition (Header_Already_Parsed => True); |
| 4488 |
Set_Null_Exclusion_Present (Subp_Node, Null_Exclusion_Present); |
| 4489 |
Set_Access_To_Subprogram_Definition (Def_Node, Subp_Node); |
| 4490 |
|
| 4491 |
-- Ada 2005 (AI-231) |
| 4492 |
-- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK |
| 4493 |
|
| 4494 |
else |
| 4495 |
Set_Null_Exclusion_Present (Def_Node, Null_Exclusion_Present); |
| 4496 |
|
| 4497 |
if Token = Tok_All then |
| 4498 |
if Ada_Version < Ada_2005 then |
| 4499 |
Error_Msg_SP |
| 4500 |
("ALL not permitted for anonymous access type"); |
| 4501 |
end if; |
| 4502 |
|
| 4503 |
Scan; -- past ALL |
| 4504 |
Set_All_Present (Def_Node); |
| 4505 |
|
| 4506 |
elsif Token = Tok_Constant then |
| 4507 |
Error_Msg_Ada_2005_Extension ("access-to-constant"); |
| 4508 |
|
| 4509 |
Scan; -- past CONSTANT |
| 4510 |
Set_Constant_Present (Def_Node); |
| 4511 |
end if; |
| 4512 |
|
| 4513 |
Set_Subtype_Mark (Def_Node, P_Subtype_Mark); |
| 4514 |
No_Constraint; |
| 4515 |
end if; |
| 4516 |
|
| 4517 |
return Def_Node; |
| 4518 |
end P_Access_Definition; |
| 4519 |
|
| 4520 |
----------------------------------------- |
| 4521 |
-- 3.10.1 Incomplete Type Declaration -- |
| 4522 |
----------------------------------------- |
| 4523 |
|
| 4524 |
-- Parsed by P_Type_Declaration (3.2.1) |
| 4525 |
|
| 4526 |
---------------------------- |
| 4527 |
-- 3.11 Declarative Part -- |
| 4528 |
---------------------------- |
| 4529 |
|
| 4530 |
-- DECLARATIVE_PART ::= {DECLARATIVE_ITEM} |
| 4531 |
|
| 4532 |
-- Error recovery: cannot raise Error_Resync (because P_Declarative_Item |
| 4533 |
-- handles errors, and returns cleanly after an error has occurred) |
| 4534 |
|
| 4535 |
function P_Declarative_Part return List_Id is |
| 4536 |
Decls : constant List_Id := New_List; |
| 4537 |
begin |
| 4538 |
-- Indicate no bad declarations detected yet. This will be reset by |
| 4539 |
-- P_Declarative_Items if a bad declaration is discovered. |
| 4540 |
|
| 4541 |
Missing_Begin_Msg := No_Error_Msg; |
| 4542 |
|
| 4543 |
-- Get rid of active SIS entry from outer scope. This means we will |
| 4544 |
-- miss some nested cases, but it doesn't seem worth the effort. See |
| 4545 |
-- discussion in Par for further details |
| 4546 |
|
| 4547 |
SIS_Entry_Active := False; |
| 4548 |
|
| 4549 |
P_Declarative_Items |
| 4550 |
(Decls, Declare_Expression => False, |
| 4551 |
In_Spec => False, In_Statements => False); |
| 4552 |
|
| 4553 |
-- Get rid of active SIS entry which is left set only if we scanned a |
| 4554 |
-- procedure declaration and have not found the body. We could give |
| 4555 |
-- an error message, but that really would be usurping the role of |
| 4556 |
-- semantic analysis (this really is a missing body case). |
| 4557 |
|
| 4558 |
SIS_Entry_Active := False; |
| 4559 |
return Decls; |
| 4560 |
end P_Declarative_Part; |
| 4561 |
|
| 4562 |
---------------------------- |
| 4563 |
-- 3.11 Declarative Item -- |
| 4564 |
---------------------------- |
| 4565 |
|
| 4566 |
-- DECLARATIVE_ITEM ::= BASIC_DECLARATIVE_ITEM | BODY |
| 4567 |
|
| 4568 |
-- Can return Error if a junk declaration is found, or Empty if no |
| 4569 |
-- declaration is found (i.e. a token ending declarations, such as |
| 4570 |
-- BEGIN or END is encountered). |
| 4571 |
|
| 4572 |
-- Error recovery: cannot raise Error_Resync. If an error resync occurs, |
| 4573 |
-- then the scan is set past the next semicolon and Error is returned. |
| 4574 |
|
| 4575 |
procedure P_Declarative_Item |
| 4576 |
(Decls : List_Id; |
| 4577 |
Done : out Boolean; |
| 4578 |
Declare_Expression : Boolean; |
| 4579 |
In_Spec : Boolean; |
| 4580 |
In_Statements : Boolean) |
| 4581 |
is |
| 4582 |
Scan_State : Saved_Scan_State; |
| 4583 |
|
| 4584 |
begin |
| 4585 |
Done := False; |
| 4586 |
|
| 4587 |
-- In -gnatg mode, we don't want a "bad indentation" error inside a |
| 4588 |
-- declare_expression. |
| 4589 |
|
| 4590 |
if Style_Check and not Declare_Expression then |
| 4591 |
Style.Check_Indentation; |
| 4592 |
end if; |
| 4593 |
|
| 4594 |
case Token is |
| 4595 |
when Tok_Function |
| 4596 |
| Tok_Not |
| 4597 |
| Tok_Overriding |
| 4598 |
| Tok_Procedure |
| 4599 |
=> |
| 4600 |
Check_Bad_Layout; |
| 4601 |
Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls); |
| 4602 |
|
| 4603 |
when Tok_For => |
| 4604 |
Check_Bad_Layout; |
| 4605 |
|
| 4606 |
-- Check for loop (premature statement) |
| 4607 |
|
| 4608 |
Save_Scan_State (Scan_State); |
| 4609 |
Scan; -- past FOR |
| 4610 |
|
| 4611 |
declare |
| 4612 |
Is_Statement : Boolean := True; |
| 4613 |
begin |
| 4614 |
if Token = Tok_Identifier then |
| 4615 |
Scan; -- past identifier |
| 4616 |
if Token in Tok_Use | Tok_Apostrophe then |
| 4617 |
Is_Statement := False; |
| 4618 |
elsif Token = Tok_Dot then |
| 4619 |
Scan; |
| 4620 |
if Token = Tok_Identifier then |
| 4621 |
Scan; |
| 4622 |
Is_Statement := Token in Tok_In | Tok_Of; |
| 4623 |
end if; |
| 4624 |
end if; |
| 4625 |
else |
| 4626 |
Is_Statement := False; |
| 4627 |
end if; |
| 4628 |
|
| 4629 |
Restore_Scan_State (Scan_State); |
| 4630 |
|
| 4631 |
if Is_Statement then |
| 4632 |
if not In_Statements then |
| 4633 |
Statement_When_Declaration_Expected |
| 4634 |
(Decls, Done, In_Spec); |
| 4635 |
end if; |
| 4636 |
|
| 4637 |
Done := True; |
| 4638 |
else |
| 4639 |
Append (P_Representation_Clause, Decls); |
| 4640 |
end if; |
| 4641 |
end; |
| 4642 |
|
| 4643 |
when Tok_Generic => |
| 4644 |
Check_Bad_Layout; |
| 4645 |
Append (P_Generic, Decls); |
| 4646 |
|
| 4647 |
when Tok_Identifier => |
| 4648 |
Check_Bad_Layout; |
| 4649 |
|
| 4650 |
-- Special check for misuse of overriding not in Ada 2005 mode |
| 4651 |
|
| 4652 |
if Token_Name = Name_Overriding |
| 4653 |
and then not Next_Token_Is (Tok_Colon) |
| 4654 |
then |
| 4655 |
Error_Msg_SC ("overriding indicator is an Ada 2005 extension"); |
| 4656 |
Error_Msg_SC ("\unit must be compiled with -gnat05 switch"); |
| 4657 |
|
| 4658 |
Token := Tok_Overriding; |
| 4659 |
Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls); |
| 4660 |
|
| 4661 |
-- Normal case, no overriding, or overriding followed by colon |
| 4662 |
|
| 4663 |
else |
| 4664 |
P_Identifier_Declarations (Decls, Done, In_Spec, In_Statements); |
| 4665 |
end if; |
| 4666 |
|
| 4667 |
when Tok_Package => |
| 4668 |
Check_Bad_Layout; |
| 4669 |
Append (P_Package (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls); |
| 4670 |
|
| 4671 |
when Tok_Pragma => |
| 4672 |
-- If we see a pragma and In_Statements is true, we want to let |
| 4673 |
-- the statement-parser deal with it. |
| 4674 |
|
| 4675 |
if In_Statements then |
| 4676 |
Done := True; |
| 4677 |
else |
| 4678 |
Append (P_Pragma, Decls); |
| 4679 |
end if; |
| 4680 |
|
| 4681 |
when Tok_Protected => |
| 4682 |
Check_Bad_Layout; |
| 4683 |
Scan; -- past PROTECTED |
| 4684 |
Append (P_Protected, Decls); |
| 4685 |
|
| 4686 |
when Tok_Subtype => |
| 4687 |
Check_Bad_Layout; |
| 4688 |
Append (P_Subtype_Declaration, Decls); |
| 4689 |
|
| 4690 |
when Tok_Task => |
| 4691 |
Check_Bad_Layout; |
| 4692 |
Scan; -- past TASK |
| 4693 |
Append (P_Task, Decls); |
| 4694 |
|
| 4695 |
when Tok_Type => |
| 4696 |
Check_Bad_Layout; |
| 4697 |
Append (P_Type_Declaration, Decls); |
| 4698 |
|
| 4699 |
when Tok_Use => |
| 4700 |
Check_Bad_Layout; |
| 4701 |
P_Use_Clause (Decls); |
| 4702 |
|
| 4703 |
when Tok_With => |
| 4704 |
Check_Bad_Layout; |
| 4705 |
|
| 4706 |
if Aspect_Specifications_Present (Strict => True) then |
| 4707 |
|
| 4708 |
-- If we are after a semicolon, complain that it was ignored. |
| 4709 |
-- But we don't really ignore it, since we dump the aspects, |
| 4710 |
-- so we make the error message a normal fatal message which |
| 4711 |
-- will inhibit semantic analysis anyway). |
| 4712 |
|
| 4713 |
if Prev_Token = Tok_Semicolon then |
| 4714 |
Error_Msg_SP -- CODEFIX |
| 4715 |
("extra "";"" ignored"); |
| 4716 |
|
| 4717 |
-- If not just past semicolon, just complain that aspects are |
| 4718 |
-- not allowed at this point. |
| 4719 |
|
| 4720 |
else |
| 4721 |
Error_Msg_SC ("aspect specifications not allowed here"); |
| 4722 |
end if; |
| 4723 |
|
| 4724 |
-- Assume that this is a misplaced aspect specification within |
| 4725 |
-- a declarative list. After discarding the misplaced aspects |
| 4726 |
-- we can continue the scan. |
| 4727 |
|
| 4728 |
declare |
| 4729 |
Dummy_Node : constant Node_Id := |
| 4730 |
New_Node (N_Package_Specification, Token_Ptr); |
| 4731 |
pragma Warnings (Off, Dummy_Node); |
| 4732 |
-- Dummy node to attach aspect specifications to. We will |
| 4733 |
-- then throw them away. |
| 4734 |
|
| 4735 |
begin |
| 4736 |
P_Aspect_Specifications (Dummy_Node, Semicolon => True); |
| 4737 |
end; |
| 4738 |
|
| 4739 |
-- Here if not aspect specifications case |
| 4740 |
|
| 4741 |
else |
| 4742 |
Error_Msg_SC ("WITH can only appear in context clause"); |
| 4743 |
raise Error_Resync; |
| 4744 |
end if; |
| 4745 |
|
| 4746 |
-- BEGIN terminates the scan of a sequence of declarations unless |
| 4747 |
-- there is a missing subprogram body, see section on handling |
| 4748 |
-- semicolon in place of IS. We only treat the begin as satisfying |
| 4749 |
-- the subprogram declaration if it falls in the expected column |
| 4750 |
-- or to its right. |
| 4751 |
|
| 4752 |
when Tok_Begin => |
| 4753 |
if SIS_Entry_Active and then Start_Column >= SIS_Ecol then |
| 4754 |
|
| 4755 |
-- Here we have the case where a BEGIN is encountered during |
| 4756 |
-- declarations in a declarative part, or at the outer level, |
| 4757 |
-- and there is a subprogram declaration outstanding for which |
| 4758 |
-- no body has been supplied. This is the case where we assume |
| 4759 |
-- that the semicolon in the subprogram declaration should |
| 4760 |
-- really have been is. The active SIS entry describes the |
| 4761 |
-- subprogram declaration. On return the declaration has been |
| 4762 |
-- modified to become a body. |
| 4763 |
|
| 4764 |
declare |
| 4765 |
Specification_Node : Node_Id; |
| 4766 |
Decl_Node : Node_Id; |
| 4767 |
Body_Node : Node_Id; |
| 4768 |
|
| 4769 |
begin |
| 4770 |
-- First issue the error message. If we had a missing |
| 4771 |
-- semicolon in the declaration, then change the message |
| 4772 |
-- to <missing "is"> |
| 4773 |
|
| 4774 |
if SIS_Missing_Semicolon_Message /= No_Error_Msg then |
| 4775 |
Change_Error_Text -- Replace: "missing "";"" " |
| 4776 |
(SIS_Missing_Semicolon_Message, "missing ""is"""); |
| 4777 |
|
| 4778 |
-- Otherwise we saved the semicolon position, so complain |
| 4779 |
|
| 4780 |
else |
| 4781 |
Error_Msg -- CODEFIX |
| 4782 |
("|"";"" should be IS", SIS_Semicolon_Sloc); |
| 4783 |
end if; |
| 4784 |
|
| 4785 |
-- The next job is to fix up any declarations that occurred |
| 4786 |
-- between the procedure header and the BEGIN. These got |
| 4787 |
-- chained to the outer declarative region (immediately |
| 4788 |
-- after the procedure declaration) and they should be |
| 4789 |
-- chained to the subprogram itself, which is a body |
| 4790 |
-- rather than a spec. |
| 4791 |
|
| 4792 |
Specification_Node := Specification (SIS_Declaration_Node); |
| 4793 |
Change_Node (SIS_Declaration_Node, N_Subprogram_Body); |
| 4794 |
Body_Node := SIS_Declaration_Node; |
| 4795 |
Set_Specification (Body_Node, Specification_Node); |
| 4796 |
Set_Declarations (Body_Node, New_List); |
| 4797 |
|
| 4798 |
loop |
| 4799 |
Decl_Node := Remove_Next (Body_Node); |
| 4800 |
exit when Decl_Node = Empty; |
| 4801 |
Append (Decl_Node, Declarations (Body_Node)); |
| 4802 |
end loop; |
| 4803 |
|
| 4804 |
-- Now make the scope table entry for the Begin-End and |
| 4805 |
-- scan it out |
| 4806 |
|
| 4807 |
Push_Scope_Stack; |
| 4808 |
Scopes (Scope.Last).Sloc := SIS_Sloc; |
| 4809 |
Scopes (Scope.Last).Etyp := E_Name; |
| 4810 |
Scopes (Scope.Last).Ecol := SIS_Ecol; |
| 4811 |
Scopes (Scope.Last).Labl := SIS_Labl; |
| 4812 |
Scopes (Scope.Last).Lreq := False; |
| 4813 |
SIS_Entry_Active := False; |
| 4814 |
Scan; -- past BEGIN |
| 4815 |
Set_Handled_Statement_Sequence (Body_Node, |
| 4816 |
P_Handled_Sequence_Of_Statements); |
| 4817 |
End_Statements (Handled_Statement_Sequence (Body_Node)); |
| 4818 |
end; |
| 4819 |
|
| 4820 |
else |
| 4821 |
Done := True; |
| 4822 |
end if; |
| 4823 |
|
| 4824 |
-- Normally an END terminates the scan for basic declarative items. |
| 4825 |
-- The one exception is END RECORD, which is probably left over from |
| 4826 |
-- some other junk. |
| 4827 |
|
| 4828 |
when Tok_End => |
| 4829 |
Save_Scan_State (Scan_State); -- at END |
| 4830 |
Scan; -- past END |
| 4831 |
|
| 4832 |
if Token = Tok_Record then |
| 4833 |
Error_Msg_SP ("no RECORD for this `end record`!"); |
| 4834 |
Scan; -- past RECORD |
| 4835 |
TF_Semicolon; |
| 4836 |
|
| 4837 |
-- This might happen because of misplaced aspect specification. |
| 4838 |
-- After discarding the misplaced aspects we can continue the |
| 4839 |
-- scan. |
| 4840 |
|
| 4841 |
else |
| 4842 |
Restore_Scan_State (Scan_State); -- to END |
| 4843 |
Done := True; |
| 4844 |
end if; |
| 4845 |
|
| 4846 |
-- The following tokens which can only be the start of a statement |
| 4847 |
-- are considered to end a declarative part (i.e. we have a missing |
| 4848 |
-- BEGIN situation). We are fairly conservative in making this |
| 4849 |
-- judgment, because it is a real mess to go into statement mode |
| 4850 |
-- prematurely in response to a junk declaration. |
| 4851 |
|
| 4852 |
when Tok_Abort |
| 4853 |
| Tok_Accept |
| 4854 |
| Tok_Declare |
| 4855 |
| Tok_Delay |
| 4856 |
| Tok_Exit |
| 4857 |
| Tok_Goto |
| 4858 |
| Tok_If |
| 4859 |
| Tok_Loop |
| 4860 |
| Tok_Null |
| 4861 |
| Tok_Requeue |
| 4862 |
| Tok_Select |
| 4863 |
| Tok_While |
| 4864 |
=> |
| 4865 |
-- If we parsing declarations in a sequence of statements, we want |
| 4866 |
-- to let the caller continue parsing statements. |
| 4867 |
|
| 4868 |
if In_Statements then |
| 4869 |
Done := True; |
| 4870 |
|
| 4871 |
-- Otherwise, give an error. But before we decide that it's a |
| 4872 |
-- statement, check for a reserved word misused as an identifier. |
| 4873 |
|
| 4874 |
elsif Is_Reserved_Identifier then |
| 4875 |
Save_Scan_State (Scan_State); |
| 4876 |
Scan; -- past the token |
| 4877 |
|
| 4878 |
-- If reserved identifier not followed by colon or comma, then |
| 4879 |
-- this is most likely an assignment statement to the bad id. |
| 4880 |
|
| 4881 |
if Token not in Tok_Colon | Tok_Comma then |
| 4882 |
Restore_Scan_State (Scan_State); |
| 4883 |
Statement_When_Declaration_Expected (Decls, Done, In_Spec); |
| 4884 |
|
| 4885 |
-- Otherwise we have a declaration of the bad id |
| 4886 |
|
| 4887 |
else |
| 4888 |
Restore_Scan_State (Scan_State); |
| 4889 |
Scan_Reserved_Identifier (Force_Msg => True); |
| 4890 |
P_Identifier_Declarations |
| 4891 |
(Decls, Done, In_Spec, In_Statements); |
| 4892 |
end if; |
| 4893 |
|
| 4894 |
-- If not reserved identifier, then it's an incorrectly placed a |
| 4895 |
-- statement. |
| 4896 |
|
| 4897 |
else |
| 4898 |
Statement_When_Declaration_Expected (Decls, Done, In_Spec); |
| 4899 |
end if; |
| 4900 |
|
| 4901 |
-- The token RETURN may well also signal a missing BEGIN situation, |
| 4902 |
-- however, we never let it end the declarative part, because it |
| 4903 |
-- might also be part of a half-baked function declaration. If we are |
| 4904 |
-- In_Statements, then let the caller parse it; otherwise, it's an |
| 4905 |
-- error. |
| 4906 |
|
| 4907 |
when Tok_Return => |
| 4908 |
if In_Statements then |
| 4909 |
Done := True; |
| 4910 |
else |
| 4911 |
Error_Msg_SC ("misplaced RETURN statement"); |
| 4912 |
raise Error_Resync; |
| 4913 |
end if; |
| 4914 |
|
| 4915 |
-- PRIVATE definitely terminates the declarations in a spec, |
| 4916 |
-- and is an error in a body. |
| 4917 |
|
| 4918 |
when Tok_Private => |
| 4919 |
if In_Spec then |
| 4920 |
Done := True; |
| 4921 |
else |
| 4922 |
Error_Msg_SC ("PRIVATE not allowed in body"); |
| 4923 |
Scan; -- past PRIVATE |
| 4924 |
end if; |
| 4925 |
|
| 4926 |
-- An end of file definitely terminates the declarations |
| 4927 |
|
| 4928 |
when Tok_EOF => |
| 4929 |
Done := True; |
| 4930 |
|
| 4931 |
-- The remaining tokens do not end the scan, but cannot start a |
| 4932 |
-- valid declaration, so we signal an error and resynchronize. |
| 4933 |
-- But first check for misuse of a reserved identifier. |
| 4934 |
|
| 4935 |
when others => |
| 4936 |
if In_Statements then |
| 4937 |
Done := True; |
| 4938 |
return; |
| 4939 |
end if; |
| 4940 |
|
| 4941 |
-- Here we check for a reserved identifier |
| 4942 |
|
| 4943 |
if Is_Reserved_Identifier then |
| 4944 |
Save_Scan_State (Scan_State); |
| 4945 |
Scan; -- past the token |
| 4946 |
|
| 4947 |
if Token not in Tok_Colon | Tok_Comma then |
| 4948 |
Restore_Scan_State (Scan_State); |
| 4949 |
Set_Declaration_Expected; |
| 4950 |
raise Error_Resync; |
| 4951 |
else |
| 4952 |
Restore_Scan_State (Scan_State); |
| 4953 |
Scan_Reserved_Identifier (Force_Msg => True); |
| 4954 |
Check_Bad_Layout; |
| 4955 |
P_Identifier_Declarations |
| 4956 |
(Decls, Done, In_Spec, In_Statements); |
| 4957 |
end if; |
| 4958 |
|
| 4959 |
else |
| 4960 |
Set_Declaration_Expected; |
| 4961 |
raise Error_Resync; |
| 4962 |
end if; |
| 4963 |
end case; |
| 4964 |
|
| 4965 |
-- To resynchronize after an error, we scan to the next semicolon and |
| 4966 |
-- return with Done = False, indicating that there may still be more |
| 4967 |
-- valid declarations to come. |
| 4968 |
|
| 4969 |
exception |
| 4970 |
when Error_Resync => |
| 4971 |
Resync_Past_Semicolon; |
| 4972 |
end P_Declarative_Item; |
| 4973 |
|
| 4974 |
procedure P_Declarative_Items |
| 4975 |
(Decls : List_Id; |
| 4976 |
Declare_Expression : Boolean; |
| 4977 |
In_Spec : Boolean; |
| 4978 |
In_Statements : Boolean) |
| 4979 |
is |
| 4980 |
Done : Boolean; |
| 4981 |
begin |
| 4982 |
loop |
| 4983 |
P_Declarative_Item |
| 4984 |
(Decls, Done, Declare_Expression, In_Spec, In_Statements); |
| 4985 |
exit when Done; |
| 4986 |
end loop; |
| 4987 |
end P_Declarative_Items; |
| 4988 |
|
| 4989 |
---------------------------------- |
| 4990 |
-- 3.11 Basic Declarative Item -- |
| 4991 |
---------------------------------- |
| 4992 |
|
| 4993 |
-- BASIC_DECLARATIVE_ITEM ::= |
| 4994 |
-- BASIC_DECLARATION | REPRESENTATION_CLAUSE | USE_CLAUSE |
| 4995 |
|
| 4996 |
-- Scan zero or more basic declarative items |
| 4997 |
|
| 4998 |
-- Error recovery: cannot raise Error_Resync. If an error is detected, then |
| 4999 |
-- the scan pointer is repositioned past the next semicolon, and the scan |
| 5000 |
-- for declarative items continues. |
| 5001 |
|
| 5002 |
function P_Basic_Declarative_Items |
| 5003 |
(Declare_Expression : Boolean) return List_Id |
| 5004 |
is |
| 5005 |
Decl : Node_Id; |
| 5006 |
Decls : constant List_Id := New_List; |
| 5007 |
Kind : Node_Kind; |
| 5008 |
|
| 5009 |
begin |
| 5010 |
-- Indicate no bad declarations detected yet in the current context: |
| 5011 |
-- visible or private declarations of a package spec. |
| 5012 |
|
| 5013 |
Missing_Begin_Msg := No_Error_Msg; |
| 5014 |
|
| 5015 |
-- Get rid of active SIS entry from outer scope. This means we will |
| 5016 |
-- miss some nested cases, but it doesn't seem worth the effort. See |
| 5017 |
-- discussion in Par for further details |
| 5018 |
|
| 5019 |
SIS_Entry_Active := False; |
| 5020 |
|
| 5021 |
P_Declarative_Items |
| 5022 |
(Decls, Declare_Expression, In_Spec => True, In_Statements => False); |
| 5023 |
|
| 5024 |
-- Get rid of active SIS entry. This is set only if we have scanned a |
| 5025 |
-- procedure declaration and have not found the body. We could give |
| 5026 |
-- an error message, but that really would be usurping the role of |
| 5027 |
-- semantic analysis (this really is a case of a missing body). |
| 5028 |
|
| 5029 |
SIS_Entry_Active := False; |
| 5030 |
|
| 5031 |
-- Test for assorted illegal declarations not diagnosed elsewhere |
| 5032 |
|
| 5033 |
Decl := First (Decls); |
| 5034 |
|
| 5035 |
while Present (Decl) loop |
| 5036 |
Kind := Nkind (Decl); |
| 5037 |
|
| 5038 |
-- Test for body scanned, not acceptable as basic decl item |
| 5039 |
|
| 5040 |
if Kind = N_Subprogram_Body or else |
| 5041 |
Kind = N_Package_Body or else |
| 5042 |
Kind = N_Task_Body or else |
| 5043 |
Kind = N_Protected_Body |
| 5044 |
then |
| 5045 |
if Declare_Expression then |
| 5046 |
Error_Msg |
| 5047 |
("proper body not allowed in declare_expression", |
| 5048 |
Sloc (Decl)); |
| 5049 |
else |
| 5050 |
Error_Msg |
| 5051 |
("proper body not allowed in package spec", |
| 5052 |
Sloc (Decl)); |
| 5053 |
end if; |
| 5054 |
|
| 5055 |
-- Complete declaration of mangled subprogram body, for better |
| 5056 |
-- recovery if analysis is attempted. |
| 5057 |
|
| 5058 |
if Nkind (Decl) in N_Subprogram_Body | N_Package_Body | N_Task_Body |
| 5059 |
and then No (Handled_Statement_Sequence (Decl)) |
| 5060 |
then |
| 5061 |
Set_Handled_Statement_Sequence (Decl, |
| 5062 |
Make_Handled_Sequence_Of_Statements (Sloc (Decl), |
| 5063 |
Statements => New_List)); |
| 5064 |
end if; |
| 5065 |
|
| 5066 |
-- Test for body stub scanned, not acceptable as basic decl item |
| 5067 |
|
| 5068 |
elsif Kind in N_Body_Stub then |
| 5069 |
Error_Msg ("body stub not allowed in package spec", Sloc (Decl)); |
| 5070 |
|
| 5071 |
elsif Kind = N_Assignment_Statement then |
| 5072 |
Error_Msg |
| 5073 |
("assignment statement not allowed in package spec", |
| 5074 |
Sloc (Decl)); |
| 5075 |
end if; |
| 5076 |
|
| 5077 |
Next (Decl); |
| 5078 |
end loop; |
| 5079 |
|
| 5080 |
return Decls; |
| 5081 |
end P_Basic_Declarative_Items; |
| 5082 |
|
| 5083 |
---------------- |
| 5084 |
-- 3.11 Body -- |
| 5085 |
---------------- |
| 5086 |
|
| 5087 |
-- For proper body, see below |
| 5088 |
-- For body stub, see 10.1.3 |
| 5089 |
|
| 5090 |
----------------------- |
| 5091 |
-- 3.11 Proper Body -- |
| 5092 |
----------------------- |
| 5093 |
|
| 5094 |
-- Subprogram body is parsed by P_Subprogram (6.1) |
| 5095 |
-- Package body is parsed by P_Package (7.1) |
| 5096 |
-- Task body is parsed by P_Task (9.1) |
| 5097 |
-- Protected body is parsed by P_Protected (9.4) |
| 5098 |
|
| 5099 |
------------------------------ |
| 5100 |
-- Set_Declaration_Expected -- |
| 5101 |
------------------------------ |
| 5102 |
|
| 5103 |
procedure Set_Declaration_Expected is |
| 5104 |
begin |
| 5105 |
Error_Msg_SC ("declaration expected"); |
| 5106 |
|
| 5107 |
if Missing_Begin_Msg = No_Error_Msg then |
| 5108 |
Missing_Begin_Msg := Get_Msg_Id; |
| 5109 |
end if; |
| 5110 |
end Set_Declaration_Expected; |
| 5111 |
|
| 5112 |
---------------------- |
| 5113 |
-- Skip_Declaration -- |
| 5114 |
---------------------- |
| 5115 |
|
| 5116 |
procedure Skip_Declaration (S : List_Id) is |
| 5117 |
Ignored_Done : Boolean; |
| 5118 |
begin |
| 5119 |
P_Declarative_Item |
| 5120 |
(S, Ignored_Done, Declare_Expression => False, In_Spec => False, |
| 5121 |
In_Statements => False); |
| 5122 |
end Skip_Declaration; |
| 5123 |
|
| 5124 |
----------------------------------------- |
| 5125 |
-- Statement_When_Declaration_Expected -- |
| 5126 |
----------------------------------------- |
| 5127 |
|
| 5128 |
procedure Statement_When_Declaration_Expected |
| 5129 |
(Decls : List_Id; |
| 5130 |
Done : out Boolean; |
| 5131 |
In_Spec : Boolean) |
| 5132 |
is |
| 5133 |
begin |
| 5134 |
-- Case of second occurrence of statement in one declaration sequence |
| 5135 |
|
| 5136 |
if Missing_Begin_Msg /= No_Error_Msg then |
| 5137 |
|
| 5138 |
-- In the procedure spec case, just ignore it, we only give one |
| 5139 |
-- message for the first occurrence, since otherwise we may get |
| 5140 |
-- horrible cascading if BODY was missing in the header line. |
| 5141 |
|
| 5142 |
if In_Spec then |
| 5143 |
null; |
| 5144 |
|
| 5145 |
-- Just ignore it if we are in -gnatd.2 (allow statements to appear |
| 5146 |
-- in declaration sequences) mode. |
| 5147 |
|
| 5148 |
elsif Debug_Flag_Dot_2 then |
| 5149 |
null; |
| 5150 |
|
| 5151 |
-- In the declarative part case, take a second statement as a sure |
| 5152 |
-- sign that we really have a missing BEGIN, and end the declarative |
| 5153 |
-- part now. Note that the caller will fix up the first message to |
| 5154 |
-- say "missing BEGIN" so that's how the error will be signalled. |
| 5155 |
|
| 5156 |
else |
| 5157 |
Done := True; |
| 5158 |
return; |
| 5159 |
end if; |
| 5160 |
|
| 5161 |
-- Case of first occurrence of unexpected statement |
| 5162 |
|
| 5163 |
else |
| 5164 |
-- Do not give error message if we are operating in -gnatd.2 mode |
| 5165 |
-- (alllow statements to appear in declarative parts). |
| 5166 |
|
| 5167 |
if not Debug_Flag_Dot_2 then |
| 5168 |
|
| 5169 |
-- If we are in a package spec, then give message of statement |
| 5170 |
-- not allowed in package spec. This message never gets changed. |
| 5171 |
|
| 5172 |
if In_Spec then |
| 5173 |
Error_Msg_SC ("statement not allowed in package spec"); |
| 5174 |
|
| 5175 |
-- If in declarative part, then we give the message complaining |
| 5176 |
-- about finding a statement when a declaration is expected. This |
| 5177 |
-- gets changed to a complaint about a missing BEGIN if we later |
| 5178 |
-- find that no BEGIN is present. |
| 5179 |
|
| 5180 |
else |
| 5181 |
Error_Msg_SC ("statement not allowed in declarative part"); |
| 5182 |
end if; |
| 5183 |
|
| 5184 |
-- Capture message Id. This is used for two purposes, first to |
| 5185 |
-- stop multiple messages, see test above, and second, to allow |
| 5186 |
-- the replacement of the message in the declarative part case. |
| 5187 |
|
| 5188 |
Missing_Begin_Msg := Get_Msg_Id; |
| 5189 |
end if; |
| 5190 |
end if; |
| 5191 |
|
| 5192 |
-- In all cases except the case in which we decided to terminate the |
| 5193 |
-- declaration sequence on a second error, we scan out the statement |
| 5194 |
-- and append it to the list of declarations (note that the semantics |
| 5195 |
-- can handle statements in a declaration list so if we proceed to |
| 5196 |
-- call the semantic phase, all will be (reasonably) well. |
| 5197 |
|
| 5198 |
Append_List_To (Decls, P_Sequence_Of_Statements (SS_Unco)); |
| 5199 |
|
| 5200 |
-- Done is set to False, since we want to continue the scan of |
| 5201 |
-- declarations, hoping that this statement was a temporary glitch. |
| 5202 |
-- If we indeed are now in the statement part (i.e. this was a missing |
| 5203 |
-- BEGIN, then it's not terrible, we will simply keep calling this |
| 5204 |
-- procedure to process the statements one by one, and then finally |
| 5205 |
-- hit the missing BEGIN, which will clean up the error message. |
| 5206 |
|
| 5207 |
Done := False; |
| 5208 |
end Statement_When_Declaration_Expected; |
| 5209 |
|
| 5210 |
end Ch3; |