1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
28 pragma Style_Checks
(All_Checks
);
29 -- Turn off subprogram body ordering check. Subprograms are in order
30 -- by RM section rather than alphabetical
32 with Fname
; use Fname
;
33 with Fname
.UF
; use Fname
.UF
;
34 with Hostparm
; use Hostparm
;
35 with Uname
; use Uname
;
40 -- Local functions, used only in this chapter
42 function P_Context_Clause
return List_Id
;
43 function P_Subunit
return Node_Id
;
45 function Set_Location
return Source_Ptr
;
46 -- The current compilation unit starts with Token at Token_Ptr. This
47 -- function determines the corresponding source location for the start
48 -- of the unit, including any preceding comment lines.
50 procedure Unit_Display
53 SR_Present
: Boolean);
54 -- This procedure is used to generate a line of output for the a unit in
55 -- the source program. Cunit is the node for the compilation unit, and
56 -- Loc is the source location for the start of the unit in the source
57 -- file (which is not necessarily the Sloc of the Cunit node). This
58 -- output is written to the standard output file for use by gnatchop.
60 procedure Unit_Location
(Sind
: Source_File_Index
; Loc
: Source_Ptr
);
61 -- This routine has the same calling sequence as Unit_Display, but
62 -- it outputs only the line number and offset of the location, Loc,
63 -- using Cunit to obtain the proper source file index.
65 -------------------------
66 -- 10.1.1 Compilation --
67 -------------------------
69 -- COMPILATION ::= {COMPILATION_UNIT}
71 -- There is no specific parsing routine for a compilation, since we only
72 -- permit a single compilation in a source file, so there is no explicit
73 -- occurrence of compilations as such (our representation of a compilation
74 -- is a series of separate source files).
76 ------------------------------
77 -- 10.1.1 Compilation unit --
78 ------------------------------
80 -- COMPILATION_UNIT ::=
81 -- CONTEXT_CLAUSE LIBRARY_ITEM
82 -- | CONTEXT_CLAUSE SUBUNIT
85 -- private LIBRARY_UNIT_DECLARATION
86 -- | LIBRARY_UNIT_BODY
87 -- | [private] LIBRARY_UNIT_RENAMING_DECLARATION
89 -- LIBRARY_UNIT_DECLARATION ::=
90 -- SUBPROGRAM_DECLARATION | PACKAGE_DECLARATION
91 -- | GENERIC_DECLARATION | GENERIC_INSTANTIATION
93 -- LIBRARY_UNIT_RENAMING_DECLARATION ::=
94 -- PACKAGE_RENAMING_DECLARATION
95 -- | GENERIC_RENAMING_DECLARATION
96 -- | SUBPROGRAM_RENAMING_DECLARATION
98 -- LIBRARY_UNIT_BODY ::= SUBPROGRAM_BODY | PACKAGE_BODY
100 -- Error recovery: cannot raise Error_Resync. If an error occurs, tokens
101 -- are skipped up to the next possible beginning of a compilation unit.
103 -- Note: if only configuration pragmas are found, Empty is returned
105 -- Note: in syntax-only mode, it is possible for P_Compilation_Unit
106 -- to return strange things that are not really compilation units.
107 -- This is done to help out gnatchop when it is faced with nonsense.
109 function P_Compilation_Unit
return Node_Id
is
110 Scan_State
: Saved_Scan_State
;
112 Specification_Node
: Node_Id
;
114 Comp_Unit_Node
: Node_Id
;
117 Private_Sloc
: Source_Ptr
:= No_Location
;
118 Config_Pragmas
: List_Id
;
120 SR_Present
: Boolean;
122 Cunit_Error_Flag
: Boolean := False;
123 -- This flag is set True if we have to scan for a compilation unit
124 -- token. It is used to ensure clean termination in such cases by
125 -- not insisting on being at the end of file, and, in the sytax only
126 -- case by not scanning for additional compilation units.
128 Cunit_Location
: Source_Ptr
;
129 -- Location of unit for unit identification output (List_Unit option)
132 Num_Library_Units
:= Num_Library_Units
+ 1;
134 -- Set location of the compilation unit if unit list option set
135 -- and we are in syntax check only mode
137 if List_Units
and then Operating_Mode
= Check_Syntax
then
138 Cunit_Location
:= Set_Location
;
140 Cunit_Location
:= No_Location
;
143 -- Deal with initial pragmas
145 Config_Pragmas
:= No_List
;
147 -- If we have an initial Source_Reference pragma, then remember
148 -- the fact to generate an NR parameter in the output line.
152 if Token
= Tok_Pragma
then
153 Save_Scan_State
(Scan_State
);
157 or else Chars
(Item
) /= Name_Source_Reference
159 Restore_Scan_State
(Scan_State
);
164 -- If first unit, record the file name for gnatchop use
166 if Operating_Mode
= Check_Syntax
168 and then Num_Library_Units
= 1
170 Write_Str
("Source_Reference pragma for file """);
171 Write_Name
(Full_Ref_Name
(Current_Source_File
));
176 Config_Pragmas
:= New_List
(Item
);
180 -- Scan out any configuration pragmas
182 while Token
= Tok_Pragma
loop
183 Save_Scan_State
(Scan_State
);
187 or else Chars
(Item
) > Last_Configuration_Pragma_Name
189 Restore_Scan_State
(Scan_State
);
193 if Config_Pragmas
= No_List
then
194 Config_Pragmas
:= Empty_List
;
196 if Operating_Mode
= Check_Syntax
and then List_Units
then
197 Write_Str
("Configuration pragmas at");
198 Unit_Location
(Current_Source_File
, Cunit_Location
);
203 Append
(Item
, Config_Pragmas
);
204 Cunit_Location
:= Set_Location
;
207 -- Establish compilation unit node and scan context items
209 Comp_Unit_Node
:= New_Node
(N_Compilation_Unit
, No_Location
);
210 Set_Cunit
(Current_Source_Unit
, Comp_Unit_Node
);
211 Set_Context_Items
(Comp_Unit_Node
, P_Context_Clause
);
213 (Comp_Unit_Node
, New_Node
(N_Compilation_Unit_Aux
, No_Location
));
215 if Present
(Config_Pragmas
) then
217 -- Check for case of only configuration pragmas present
220 and then Is_Empty_List
(Context_Items
(Comp_Unit_Node
))
222 if Operating_Mode
= Check_Syntax
then
226 Item
:= First
(Config_Pragmas
);
228 ("cannot compile configuration pragmas with gcc", Item
);
230 ("use gnatchop -c to process configuration pragmas!", Item
);
231 raise Unrecoverable_Error
;
234 -- Otherwise configuration pragmas are simply prepended to the
235 -- context of the current unit.
238 Append_List
(Context_Items
(Comp_Unit_Node
), Config_Pragmas
);
239 Set_Context_Items
(Comp_Unit_Node
, Config_Pragmas
);
243 -- Check for PRIVATE. Note that for the moment we allow this in
244 -- Ada_83 mode, since we do not yet know if we are compiling a
245 -- predefined unit, and if we are then it would be allowed anyway.
247 if Token
= Tok_Private
then
248 Private_Sloc
:= Token_Ptr
;
249 Set_Keyword_Casing
(Current_Source_File
, Determine_Token_Casing
);
250 if Style_Check
then Style
.Check_Indentation
; end if;
252 Save_Scan_State
(Scan_State
); -- at PRIVATE
253 Scan
; -- past PRIVATE
255 if Token
= Tok_Separate
then
256 Error_Msg_SP
("cannot have private subunits!");
258 elsif Token
= Tok_Package
then
259 Scan
; -- past PACKAGE
261 if Token
= Tok_Body
then
262 Restore_Scan_State
(Scan_State
); -- to PRIVATE
263 Error_Msg_SC
("cannot have private package body!");
264 Scan
; -- ignore PRIVATE
267 Restore_Scan_State
(Scan_State
); -- to PRIVATE
268 Scan
; -- past PRIVATE
269 Set_Private_Present
(Comp_Unit_Node
, True);
272 elsif Token
= Tok_Procedure
273 or else Token
= Tok_Function
274 or else Token
= Tok_Generic
276 Set_Private_Present
(Comp_Unit_Node
, True);
280 -- Loop to find our way to a compilation unit token
283 exit when Token
in Token_Class_Cunit
and then Token
/= Tok_With
;
285 exit when Bad_Spelling_Of
(Tok_Package
)
286 or else Bad_Spelling_Of
(Tok_Function
)
287 or else Bad_Spelling_Of
(Tok_Generic
)
288 or else Bad_Spelling_Of
(Tok_Separate
)
289 or else Bad_Spelling_Of
(Tok_Procedure
);
291 -- Allow task and protected for nice error recovery purposes
293 exit when Token
= Tok_Task
294 or else Token
= Tok_Protected
;
296 if Token
= Tok_With
then
297 Error_Msg_SC
("misplaced WITH");
298 Append_List
(P_Context_Clause
, Context_Items
(Comp_Unit_Node
));
300 elsif Bad_Spelling_Of
(Tok_With
) then
301 Append_List
(P_Context_Clause
, Context_Items
(Comp_Unit_Node
));
304 Error_Msg_SC
("compilation unit expected");
305 Cunit_Error_Flag
:= True;
308 -- If we are at an end of file, then just quit, the above error
309 -- message was complaint enough.
311 if Token
= Tok_EOF
then
317 -- We have a compilation unit token, so that's a reasonable choice for
318 -- determining the standard casing convention used for keywords in case
319 -- it hasn't already been done on seeing a WITH or PRIVATE.
321 Set_Keyword_Casing
(Current_Source_File
, Determine_Token_Casing
);
322 if Style_Check
then Style
.Check_Indentation
; end if;
324 -- Remaining processing depends on particular type of compilation unit
326 if Token
= Tok_Package
then
328 -- A common error is to omit the body keyword after package. We can
329 -- often diagnose this early on (before getting loads of errors from
330 -- contained subprogram bodies), by knowing that that the file we
331 -- are compiling has a name that requires a body to be found.
333 -- However, we do not do this check if we are operating in syntax
334 -- checking only mode, because in that case there may be multiple
335 -- units in the same file, and the file name is not a reliable guide.
337 Save_Scan_State
(Scan_State
);
338 Scan
; -- past Package keyword
341 and then Operating_Mode
/= Check_Syntax
343 Get_Expected_Unit_Type
344 (File_Name
(Current_Source_File
)) = Expect_Body
346 Error_Msg_BC
("keyword BODY expected here [see file name]");
347 Restore_Scan_State
(Scan_State
);
348 Set_Unit
(Comp_Unit_Node
, P_Package
(Pf_Pbod
));
350 Restore_Scan_State
(Scan_State
);
351 Set_Unit
(Comp_Unit_Node
, P_Package
(Pf_Decl_Gins_Pbod_Rnam
));
354 elsif Token
= Tok_Generic
then
355 Set_Unit
(Comp_Unit_Node
, P_Generic
);
357 elsif Token
= Tok_Separate
then
358 Set_Unit
(Comp_Unit_Node
, P_Subunit
);
360 elsif Token
= Tok_Procedure
361 or else Token
= Tok_Function
363 Set_Unit
(Comp_Unit_Node
, P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam
));
365 -- A little bit of an error recovery check here. If we just scanned
366 -- a subprogram declaration (as indicated by an SIS entry being
367 -- active), then if the following token is BEGIN or an identifier,
368 -- or a token which can reasonably start a declaration but cannot
369 -- start a compilation unit, then we assume that the semicolon in
370 -- the declaration should have been IS.
372 if SIS_Entry_Active
then
375 or else Token
= Tok_Identifier
376 or else Token
in Token_Class_Deckn
379 Scope
.Table
(Scope
.Last
).Etyp
:= E_Name
;
380 Scope
.Table
(Scope
.Last
).Sloc
:= SIS_Sloc
;
381 Scope
.Table
(Scope
.Last
).Ecol
:= SIS_Ecol
;
382 Scope
.Table
(Scope
.Last
).Lreq
:= False;
383 SIS_Entry_Active
:= False;
385 -- If we had a missing semicolon in the declaration, then
386 -- change the message to from <missing ";"> to <missing "is">
388 if SIS_Missing_Semicolon_Message
/= No_Error_Msg
then
389 Change_Error_Text
-- Replace: "missing "";"" "
390 (SIS_Missing_Semicolon_Message
, "missing IS");
392 -- Otherwise we saved the semicolon position, so complain
395 Error_Msg
(""";"" should be IS", SIS_Semicolon_Sloc
);
398 Body_Node
:= Unit
(Comp_Unit_Node
);
399 Specification_Node
:= Specification
(Body_Node
);
400 Change_Node
(Body_Node
, N_Subprogram_Body
);
401 Set_Specification
(Body_Node
, Specification_Node
);
402 Parse_Decls_Begin_End
(Body_Node
);
403 Set_Unit
(Comp_Unit_Node
, Body_Node
);
406 -- If we scanned a subprogram body, make sure we did not have private
408 elsif Private_Sloc
/= No_Location
409 and then Nkind
(Unit
(Comp_Unit_Node
)) /= N_Function_Instantiation
410 and then Nkind
(Unit
(Comp_Unit_Node
)) /= N_Procedure_Instantiation
412 Error_Msg
("cannot have private subprogram body", Private_Sloc
);
414 -- P_Subprogram can yield an abstract subprogram, but this cannot
415 -- be a compilation unit. Treat as a subprogram declaration.
418 Nkind
(Unit
(Comp_Unit_Node
)) = N_Abstract_Subprogram_Declaration
421 ("compilation unit cannot be abstract subprogram",
422 Unit
(Comp_Unit_Node
));
425 New_Node
(N_Subprogram_Declaration
, Sloc
(Comp_Unit_Node
));
426 Set_Specification
(Unit_Node
,
427 Specification
(Unit
(Comp_Unit_Node
)));
428 Set_Unit
(Comp_Unit_Node
, Unit_Node
);
431 -- Otherwise we have TASK. This is not really an acceptable token,
432 -- but we accept it to improve error recovery.
434 elsif Token
= Tok_Task
then
437 if Token
= Tok_Type
then
439 ("task type cannot be used as compilation unit");
442 ("task declaration cannot be used as compilation unit");
445 -- If in check syntax mode, accept the task anyway. This is done
446 -- particularly to improve the behavior of GNATCHOP in this case.
448 if Operating_Mode
= Check_Syntax
then
449 Set_Unit
(Comp_Unit_Node
, P_Task
);
451 -- If not in syntax only mode, treat this as horrible error
454 Cunit_Error_Flag
:= True;
458 else pragma Assert
(Token
= Tok_Protected
);
459 Scan
; -- Past PROTECTED
461 if Token
= Tok_Type
then
463 ("protected type cannot be used as compilation unit");
466 ("protected declaration cannot be used as compilation unit");
469 -- If in check syntax mode, accept protected anyway. This is done
470 -- particularly to improve the behavior of GNATCHOP in this case.
472 if Operating_Mode
= Check_Syntax
then
473 Set_Unit
(Comp_Unit_Node
, P_Protected
);
475 -- If not in syntax only mode, treat this as horrible error
478 Cunit_Error_Flag
:= True;
483 -- Here is where locate the compilation unit entity. This is a little
484 -- tricky, since it is buried in various places.
486 Unit_Node
:= Unit
(Comp_Unit_Node
);
488 -- Another error from which it is hard to recover
490 if Nkind
(Unit_Node
) = N_Subprogram_Body_Stub
491 or else Nkind
(Unit_Node
) = N_Package_Body_Stub
493 Cunit_Error_Flag
:= True;
497 -- Only try this if we got an OK unit!
499 if Unit_Node
/= Error
then
500 if Nkind
(Unit_Node
) = N_Subunit
then
501 Unit_Node
:= Proper_Body
(Unit_Node
);
504 if Nkind
(Unit_Node
) in N_Generic_Declaration
then
505 Unit_Node
:= Specification
(Unit_Node
);
508 if Nkind
(Unit_Node
) = N_Package_Declaration
509 or else Nkind
(Unit_Node
) = N_Subprogram_Declaration
510 or else Nkind
(Unit_Node
) = N_Subprogram_Body
511 or else Nkind
(Unit_Node
) = N_Subprogram_Renaming_Declaration
513 Unit_Node
:= Specification
(Unit_Node
);
515 elsif Nkind
(Unit_Node
) = N_Subprogram_Renaming_Declaration
then
518 ("(Ada 83) library unit renaming not allowed", Unit_Node
);
522 if Nkind
(Unit_Node
) = N_Task_Body
523 or else Nkind
(Unit_Node
) = N_Protected_Body
524 or else Nkind
(Unit_Node
) = N_Task_Type_Declaration
525 or else Nkind
(Unit_Node
) = N_Protected_Type_Declaration
526 or else Nkind
(Unit_Node
) = N_Single_Task_Declaration
527 or else Nkind
(Unit_Node
) = N_Single_Protected_Declaration
529 Name_Node
:= Defining_Identifier
(Unit_Node
);
531 Name_Node
:= Defining_Unit_Name
(Unit_Node
);
534 Set_Sloc
(Comp_Unit_Node
, Sloc
(Name_Node
));
535 Set_Sloc
(Aux_Decls_Node
(Comp_Unit_Node
), Sloc
(Name_Node
));
537 -- Set Entity field in file table. Easier now that we have name!
538 -- Note that this is also skipped if we had a bad unit
540 if Nkind
(Name_Node
) = N_Defining_Program_Unit_Name
then
542 (Current_Source_Unit
, Defining_Identifier
(Name_Node
));
544 Set_Cunit_Entity
(Current_Source_Unit
, Name_Node
);
548 (Current_Source_Unit
, Get_Unit_Name
(Unit
(Comp_Unit_Node
)));
550 -- If we had a bad unit, make sure the fatal flag is set in the file
551 -- table entry, since this is surely a fatal error and also set our
552 -- flag to inhibit the requirement that we be at end of file.
555 Cunit_Error_Flag
:= True;
556 Set_Fatal_Error
(Current_Source_Unit
);
559 -- Clear away any missing semicolon indication, we are done with that
560 -- unit, so what's done is done, and we don't want anything hanging
561 -- around from the attempt to parse it!
563 SIS_Entry_Active
:= False;
565 -- Scan out pragmas after unit
567 while Token
= Tok_Pragma
loop
568 Save_Scan_State
(Scan_State
);
570 -- If we are in syntax scan mode allowing multiple units, then
571 -- start the next unit if we encounter a configuration pragma,
572 -- or a source reference pragma. We take care not to actually
573 -- scan the pragma in this case since we don't want it to take
574 -- effect for the current unit.
576 if Operating_Mode
= Check_Syntax
then
579 if Token
= Tok_Identifier
582 First_Pragma_Name
.. Last_Configuration_Pragma_Name
583 or else Token_Name
= Name_Source_Reference
)
585 Restore_Scan_State
(Scan_State
); -- to Pragma
590 -- Otherwise eat the pragma, it definitely belongs with the
591 -- current unit, and not with the following unit.
593 Restore_Scan_State
(Scan_State
); -- to Pragma
596 if No
(Pragmas_After
(Aux_Decls_Node
(Comp_Unit_Node
))) then
598 (Aux_Decls_Node
(Comp_Unit_Node
), New_List
);
601 Append
(P
, Pragmas_After
(Aux_Decls_Node
(Comp_Unit_Node
)));
604 -- Cancel effect of any outstanding pragma Warnings (Off)
606 Set_Warnings_Mode_On
(Scan_Ptr
);
608 -- Ada 83 error checks
612 -- Check we did not with any child units
614 Item
:= First
(Context_Items
(Comp_Unit_Node
));
616 while Present
(Item
) loop
617 if Nkind
(Item
) = N_With_Clause
618 and then Nkind
(Name
(Item
)) /= N_Identifier
620 Error_Msg_N
("(Ada 83) child units not allowed", Item
);
626 -- Check that we did not have a PRIVATE keyword present
628 if Private_Present
(Comp_Unit_Node
) then
630 ("(Ada 83) private units not allowed", Private_Sloc
);
634 -- If no serious error, then output possible unit information line
635 -- for gnatchop if we are in syntax only, list units mode.
637 if not Cunit_Error_Flag
639 and then Operating_Mode
= Check_Syntax
641 Unit_Display
(Comp_Unit_Node
, Cunit_Location
, SR_Present
);
644 -- And now we should be at the end of file
646 if Token
/= Tok_EOF
then
648 -- If we already had to scan for a compilation unit, then don't
649 -- give any further error message, since it just sems to make
650 -- things worse, and we already gave a serious error message.
652 if Cunit_Error_Flag
then
655 -- If we are in check syntax mode, then we allow multiple units
656 -- so we just return with Token not set to Tok_EOF and no message.
658 elsif Operating_Mode
= Check_Syntax
then
659 return Comp_Unit_Node
;
661 -- Otherwise we have an error. We suppress the error message
662 -- if we already had a fatal error, since this stops junk
663 -- cascaded messages in some situations.
666 if not Fatal_Error
(Current_Source_Unit
) then
668 if Token
in Token_Class_Cunit
then
670 ("end of file expected, " &
671 "file can have only one compilation unit");
674 Error_Msg_SC
("end of file expected");
679 -- Skip tokens to end of file, so that the -gnatl listing
680 -- will be complete in this situation, but no error checking
681 -- other than that provided at the token level.
683 while Token
/= Tok_EOF
loop
689 -- Normal return (we were at the end of file as expected)
692 return Comp_Unit_Node
;
697 -- An error resync is a serious bomb, so indicate result unit no good
700 Set_Fatal_Error
(Current_Source_Unit
);
703 end P_Compilation_Unit
;
705 --------------------------
706 -- 10.1.1 Library Item --
707 --------------------------
709 -- Parsed by P_Compilation_Unit (10.1.1)
711 --------------------------------------
712 -- 10.1.1 Library Unit Declaration --
713 --------------------------------------
715 -- Parsed by P_Compilation_Unit (10.1.1)
717 ------------------------------------------------
718 -- 10.1.1 Library Unit Renaming Declaration --
719 ------------------------------------------------
721 -- Parsed by P_Compilation_Unit (10.1.1)
723 -------------------------------
724 -- 10.1.1 Library Unit Body --
725 -------------------------------
727 -- Parsed by P_Compilation_Unit (10.1.1)
729 ------------------------------
730 -- 10.1.1 Parent Unit Name --
731 ------------------------------
733 -- Parsed (as a name) by its parent construct
735 ----------------------------
736 -- 10.1.2 Context Clause --
737 ----------------------------
739 -- CONTEXT_CLAUSE ::= {CONTEXT_ITEM}
741 -- CONTEXT_ITEM ::= WITH_CLAUSE | USE_CLAUSE | WITH_TYPE_CLAUSE
744 -- with library_unit_NAME {,library_unit_NAME};
746 -- WITH_TYPE_CLAUSE ::=
747 -- with type type_NAME is access; | with type type_NAME is tagged;
749 -- Error recovery: Cannot raise Error_Resync
751 function P_Context_Clause
return List_Id
is
754 First_Flag
: Boolean;
757 Item_List
:= New_List
;
759 -- Get keyword casing from WITH keyword in case not set yet
761 if Token
= Tok_With
then
762 Set_Keyword_Casing
(Current_Source_File
, Determine_Token_Casing
);
765 -- Loop through context items
768 if Style_Check
then Style
.Check_Indentation
; end if;
770 -- Gather any pragmas appearing in the context clause
772 P_Pragmas_Opt
(Item_List
);
774 -- Processing for WITH clause
776 if Token
= Tok_With
then
779 if Token
= Tok_Type
then
781 -- WITH TYPE is an extension
783 if not Extensions_Allowed
then
784 Error_Msg_SP
("`WITH TYPE` is a non-standard extension");
788 ("\unit must be compiled with " &
789 "'/'E'X'T'E'N'S'I'O'N'S'_'A'L'L'O'W'E'D qualifier");
792 ("\unit must be compiled with -gnatX switch");
797 With_Node
:= New_Node
(N_With_Type_Clause
, Token_Ptr
);
798 Append
(With_Node
, Item_List
);
799 Set_Name
(With_Node
, P_Qualified_Simple_Name
);
803 if Token
= Tok_Tagged
then
804 Set_Tagged_Present
(With_Node
);
807 elsif Token
= Tok_Access
then
811 Error_Msg_SC
("expect tagged or access qualifier");
819 -- Loop through names in one with clause, generating a separate
820 -- N_With_Clause node for each nam encountered.
823 With_Node
:= New_Node
(N_With_Clause
, Token_Ptr
);
824 Append
(With_Node
, Item_List
);
826 -- Note that we allow with'ing of child units, even in
827 -- Ada 83 mode, since presumably if this is not desired,
828 -- then the compilation of the child unit itself is the
829 -- place where such an "error" should be caught.
831 Set_Name
(With_Node
, P_Qualified_Simple_Name
);
832 Set_First_Name
(With_Node
, First_Flag
);
834 exit when Token
/= Tok_Comma
;
838 Set_Last_Name
(With_Node
, True);
842 -- Processing for USE clause
844 elsif Token
= Tok_Use
then
845 Append
(P_Use_Clause
, Item_List
);
847 -- Anything else is end of context clause
855 end P_Context_Clause
;
857 --------------------------
858 -- 10.1.2 Context Item --
859 --------------------------
861 -- Parsed by P_Context_Clause (10.1.2)
863 -------------------------
864 -- 10.1.2 With Clause --
865 -------------------------
867 -- Parsed by P_Context_Clause (10.1.2)
869 -----------------------
870 -- 10.1.3 Body Stub --
871 -----------------------
873 -- Subprogram stub parsed by P_Subprogram (6.1)
874 -- Package stub parsed by P_Package (7.1)
875 -- Task stub parsed by P_Task (9.1)
876 -- Protected stub parsed by P_Protected (9.4)
878 ----------------------------------
879 -- 10.1.3 Subprogram Body Stub --
880 ----------------------------------
882 -- Parsed by P_Subprogram (6.1)
884 -------------------------------
885 -- 10.1.3 Package Body Stub --
886 -------------------------------
888 -- Parsed by P_Package (7.1)
890 ----------------------------
891 -- 10.1.3 Task Body Stub --
892 ----------------------------
894 -- Parsed by P_Task (9.1)
896 ---------------------------------
897 -- 10.1.3 Protected Body Stub --
898 ---------------------------------
900 -- Parsed by P_Protected (9.4)
902 ---------------------
904 ---------------------
906 -- SUBUNIT ::= separate (PARENT_UNIT_NAME) PROPER_BODY
908 -- PARENT_UNIT_NAME ::= NAME
910 -- The caller has checked that the initial token is SEPARATE
912 -- Error recovery: cannot raise Error_Resync
914 function P_Subunit
return Node_Id
is
915 Subunit_Node
: Node_Id
;
919 Subunit_Node
:= New_Node
(N_Subunit
, Token_Ptr
);
920 Body_Node
:= Error
; -- in case no good body found
921 Scan
; -- past SEPARATE;
924 Set_Name
(Subunit_Node
, P_Qualified_Simple_Name
);
927 if Token
= Tok_Semicolon
then
928 Error_Msg_SC
("unexpected semicolon ignored");
932 if Token
= Tok_Function
or else Token
= Tok_Procedure
then
933 Body_Node
:= P_Subprogram
(Pf_Pbod
);
935 elsif Token
= Tok_Package
then
936 Body_Node
:= P_Package
(Pf_Pbod
);
938 elsif Token
= Tok_Protected
then
939 Scan
; -- past PROTECTED
941 if Token
= Tok_Body
then
942 Body_Node
:= P_Protected
;
944 Error_Msg_AP
("BODY expected");
948 elsif Token
= Tok_Task
then
951 if Token
= Tok_Body
then
954 Error_Msg_AP
("BODY expected");
959 Error_Msg_SC
("proper body expected");
963 Set_Proper_Body
(Subunit_Node
, Body_Node
);
972 function Set_Location
return Source_Ptr
is
975 Scan_State
: Saved_Scan_State
;
978 -- A special check. If the first token is pragma, and this is a
979 -- Source_Reference pragma, then do NOT eat previous comments, since
980 -- the Source_Reference pragma is required to be the first line in
983 if Token
= Tok_Pragma
then
984 Save_Scan_State
(Scan_State
);
987 if Token
= Tok_Identifier
988 and then Token_Name
= Name_Source_Reference
990 Restore_Scan_State
(Scan_State
);
994 Restore_Scan_State
(Scan_State
);
997 -- Otherwise acquire previous comments and blank lines
999 if Prev_Token
= No_Token
then
1000 return Source_First
(Current_Source_File
);
1003 Loc
:= Prev_Token_Ptr
;
1005 exit when Loc
= Token_Ptr
;
1007 if Source
(Loc
) in Line_Terminator
then
1008 Skip_Line_Terminators
(Loc
, Physical
);
1023 -- The format of the generated line, as expected by GNATCHOP is
1025 -- Unit {unit} line {line}, file offset {offs} [, SR], file name {file}
1029 -- {unit} unit name with terminating (spec) or (body)
1030 -- {line} starting line number
1031 -- {offs} offset to start of text in file
1032 -- {file} source file name
1034 -- The SR parameter is present only if a source reference pragma was
1035 -- scanned for this unit. The significance is that gnatchop should not
1036 -- attempt to add another one.
1038 procedure Unit_Display
1041 SR_Present
: Boolean)
1043 Unum
: constant Unit_Number_Type
:= Get_Cunit_Unit_Number
(Cunit
);
1044 Sind
: constant Source_File_Index
:= Source_Index
(Unum
);
1045 Unam
: constant Unit_Name_Type
:= Unit_Name
(Unum
);
1049 Write_Str
("Unit ");
1050 Write_Unit_Name
(Unit_Name
(Unum
));
1051 Unit_Location
(Sind
, Loc
);
1057 Write_Str
(", file name ");
1058 Write_Name
(Get_File_Name
(Unam
, Nkind
(Unit
(Cunit
)) = N_Subunit
));
1067 procedure Unit_Location
(Sind
: Source_File_Index
; Loc
: Source_Ptr
) is
1068 Line
: constant Logical_Line_Number
:= Get_Logical_Line_Number
(Loc
);
1069 -- Should the above be the physical line number ???
1072 Write_Str
(" line ");
1073 Write_Int
(Int
(Line
));
1075 Write_Str
(", file offset ");
1076 Write_Int
(Int
(Loc
) - Int
(Source_First
(Sind
)));