1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2024, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- Generally the parser checks the basic syntax of pragmas, but does not
27 -- do specialized syntax checks for individual pragmas, these are deferred
28 -- to semantic analysis time (see unit Sem_Prag). There are some pragmas
29 -- which require recognition and either partial or complete processing
30 -- during parsing, and this unit performs this required processing.
32 with Fname
.UF
; use Fname
.UF
;
33 with Osint
; use Osint
;
34 with Rident
; use Rident
;
35 with Restrict
; use Restrict
;
36 with Stringt
; use Stringt
;
37 with Stylesw
; use Stylesw
;
38 with Uintp
; use Uintp
;
39 with Uname
; use Uname
;
41 with System
.WCh_Con
; use System
.WCh_Con
;
45 function Prag
(Pragma_Node
: Node_Id
; Semi
: Source_Ptr
) return Node_Id
is
46 Prag_Name
: constant Name_Id
:= Pragma_Name_Unmapped
(Pragma_Node
);
47 Prag_Id
: constant Pragma_Id
:= Get_Pragma_Id
(Prag_Name
);
48 Pragma_Sloc
: constant Source_Ptr
:= Sloc
(Pragma_Node
);
52 -----------------------
53 -- Local Subprograms --
54 -----------------------
56 procedure Add_List_Pragma_Entry
(PT
: List_Pragma_Type
; Loc
: Source_Ptr
);
57 -- Make a new entry in the List_Pragmas table if this entry is not already
58 -- in the table (it will always be the last one if there is a duplication
59 -- resulting from the use of Save/Restore_Scan_State).
61 function Arg1
return Node_Id
;
62 function Arg2
return Node_Id
;
63 function Arg3
return Node_Id
;
64 -- Obtain specified Pragma_Argument_Association. It is allowable to call
65 -- the routine for the argument one past the last present argument, but
66 -- that is the only case in which a non-present argument can be referenced.
68 procedure Check_Arg_Count
(Required
: Nat
);
69 -- Check argument count for pragma = Required. If not give error and raise
72 procedure Check_Arg_Is_String_Literal
(Arg
: Node_Id
);
73 -- Check the expression of the specified argument to make sure that it
74 -- is a string literal. If not give error and raise Error_Resync.
76 procedure Check_Arg_Is_On_Or_Off
77 (Arg
: Node_Id
; All_Extensions_OK_Too
: Boolean := False);
78 -- Check the expression of the specified argument to make sure that it
79 -- is an identifier which is either ON or OFF, and if not, then issue
80 -- an error message and raise Error_Resync. If All_Extensions_OK_Too is
81 -- True, then an ALL_EXTENSIONS identifer is also acceptable.
83 procedure Check_No_Identifier
(Arg
: Node_Id
);
84 -- Checks that the given argument does not have an identifier. If
85 -- an identifier is present, then an error message is issued, and
86 -- Error_Resync is raised.
88 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
89 -- Checks if the given argument has an identifier, and if so, requires
90 -- it to match the given identifier name. If there is a non-matching
91 -- identifier, then an error message is given and Error_Resync raised.
93 procedure Check_Required_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
94 -- Same as Check_Optional_Identifier, except that the name is required
95 -- to be present and to match the given Id value.
97 procedure Process_Restrictions_Or_Restriction_Warnings
;
98 -- Common processing for Restrictions and Restriction_Warnings pragmas.
99 -- For the most part, restrictions need not be processed at parse time,
100 -- since they only affect semantic processing. This routine handles the
101 -- exceptions as follows
103 -- No_Obsolescent_Features must be processed at parse time, since there
104 -- are some obsolescent features (e.g. character replacements) which are
105 -- handled at parse time.
107 -- No_Dependence must be processed at parse time, since otherwise it gets
110 -- No_Unrecognized_Aspects must be processed at parse time, since
111 -- unrecognized aspects are ignored by the parser.
113 -- Note that we don't need to do full error checking for badly formed cases
114 -- of restrictions, since these will be caught during semantic analysis.
116 ---------------------------
117 -- Add_List_Pragma_Entry --
118 ---------------------------
120 procedure Add_List_Pragma_Entry
(PT
: List_Pragma_Type
; Loc
: Source_Ptr
) is
122 if List_Pragmas
.Last
< List_Pragmas
.First
123 or else List_Pragmas
.Table
(List_Pragmas
.Last
) /= (PT
, Loc
)
125 List_Pragmas
.Append
((PT
, Loc
));
127 end Add_List_Pragma_Entry
;
133 function Arg1
return Node_Id
is
135 return First
(Pragma_Argument_Associations
(Pragma_Node
));
142 function Arg2
return Node_Id
is
151 function Arg3
return Node_Id
is
156 ---------------------
157 -- Check_Arg_Count --
158 ---------------------
160 procedure Check_Arg_Count
(Required
: Nat
) is
162 if Arg_Count
/= Required
then
163 Error_Msg_N
("wrong number of arguments for pragma%", Pragma_Node
);
168 ----------------------------
169 -- Check_Arg_Is_On_Or_Off --
170 ----------------------------
172 procedure Check_Arg_Is_On_Or_Off
173 (Arg
: Node_Id
; All_Extensions_OK_Too
: Boolean := False)
175 Argx
: constant Node_Id
:= Expression
(Arg
);
176 Error
: Boolean := Nkind
(Expression
(Arg
)) /= N_Identifier
;
179 Error
:= Chars
(Argx
) not in Name_On | Name_Off
180 and then not (All_Extensions_OK_Too
181 and then Chars
(Argx
) = Name_All_Extensions
);
184 Error_Msg_Name_2
:= Name_On
;
185 Error_Msg_Name_3
:= Name_Off
;
187 if All_Extensions_OK_Too
then
188 Error_Msg_Name_4
:= Name_All_Extensions
;
189 Error_Msg_N
("argument for pragma% must be% or% or%", Argx
);
191 Error_Msg_N
("argument for pragma% must be% or%", Argx
);
195 end Check_Arg_Is_On_Or_Off
;
197 ---------------------------------
198 -- Check_Arg_Is_String_Literal --
199 ---------------------------------
201 procedure Check_Arg_Is_String_Literal
(Arg
: Node_Id
) is
203 if Nkind
(Expression
(Arg
)) /= N_String_Literal
then
205 ("argument for pragma% must be string literal",
209 end Check_Arg_Is_String_Literal
;
211 -------------------------
212 -- Check_No_Identifier --
213 -------------------------
215 procedure Check_No_Identifier
(Arg
: Node_Id
) is
217 if Chars
(Arg
) /= No_Name
then
218 Error_Msg_N
("pragma% does not permit named arguments", Arg
);
221 end Check_No_Identifier
;
223 -------------------------------
224 -- Check_Optional_Identifier --
225 -------------------------------
227 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
229 if Present
(Arg
) and then Chars
(Arg
) /= No_Name
then
230 if Chars
(Arg
) /= Id
then
231 Error_Msg_Name_2
:= Id
;
232 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
235 end Check_Optional_Identifier
;
237 -------------------------------
238 -- Check_Required_Identifier --
239 -------------------------------
241 procedure Check_Required_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
243 if Chars
(Arg
) /= Id
then
244 Error_Msg_Name_2
:= Id
;
245 Error_Msg_N
("pragma% argument must have identifier%", Arg
);
247 end Check_Required_Identifier
;
249 --------------------------------------------------
250 -- Process_Restrictions_Or_Restriction_Warnings --
251 --------------------------------------------------
253 procedure Process_Restrictions_Or_Restriction_Warnings
is
260 while Present
(Arg
) loop
262 Expr
:= Expression
(Arg
);
264 if Id
= No_Name
and then Nkind
(Expr
) = N_Identifier
then
266 when Name_No_Obsolescent_Features
=>
267 Set_Restriction
(No_Obsolescent_Features
, Pragma_Node
);
268 Restriction_Warnings
(No_Obsolescent_Features
) :=
269 Prag_Id
= Pragma_Restriction_Warnings
;
271 when Name_SPARK_05
=>
272 Error_Msg_Name_1
:= Chars
(Expr
);
274 ("??% restriction is obsolete and ignored, consider " &
275 "using 'S'P'A'R'K_'Mode and gnatprove instead", Arg
);
277 when Name_No_Unrecognized_Aspects
=>
279 (No_Unrecognized_Aspects
,
281 Prag_Id
= Pragma_Restriction_Warnings
);
287 elsif Id
= Name_No_Dependence
then
288 Set_Restriction_No_Dependence
290 Warn
=> Prag_Id
= Pragma_Restriction_Warnings
291 or else Treat_Restrictions_As_Warnings
);
296 end Process_Restrictions_Or_Restriction_Warnings
;
298 -- Start of processing for Prag
301 Error_Msg_Name_1
:= Prag_Name
;
303 -- Ignore unrecognized pragma. We let Sem post the warning for this, since
304 -- it is a semantic error, not a syntactic one (we have already checked
305 -- the syntax for the unrecognized pragma as required by (RM 2.8(11)).
307 if Prag_Id
= Unknown_Pragma
then
311 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
312 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
314 if Should_Ignore_Pragma_Par
(Prag_Name
)
315 or else (Prag_Id
= Pragma_Default_Scalar_Storage_Order
316 and then Ignore_Rep_Clauses
)
321 -- Count number of arguments. This loop also checks if any of the arguments
322 -- are Error, indicating a syntax error as they were parsed. If so, we
323 -- simply return, because we get into trouble with cascaded errors if we
324 -- try to perform our error checks on junk arguments.
328 if Present
(Pragma_Argument_Associations
(Pragma_Node
)) then
330 while Arg_Node
/= Empty
loop
331 Arg_Count
:= Arg_Count
+ 1;
333 if Expression
(Arg_Node
) = Error
then
341 -- Remaining processing is pragma dependent
345 -- Ada version pragmas must be processed at parse time, because we want
346 -- to set the Ada version properly at parse time to recognize the
347 -- appropriate Ada version syntax. However, pragma Ada_2005 and higher
348 -- have an optional argument; it is only the zero argument form that
349 -- must be processed at parse time.
355 when Pragma_Ada_83
=>
356 if not Latest_Ada_Only
then
357 Ada_Version
:= Ada_83
;
358 Ada_Version_Explicit
:= Ada_83
;
359 Ada_Version_Pragma
:= Pragma_Node
;
366 when Pragma_Ada_95
=>
367 if not Latest_Ada_Only
then
368 Ada_Version
:= Ada_95
;
369 Ada_Version_Explicit
:= Ada_95
;
370 Ada_Version_Pragma
:= Pragma_Node
;
373 ---------------------
374 -- Ada_05/Ada_2005 --
375 ---------------------
380 if Arg_Count
= 0 and not Latest_Ada_Only
then
381 Ada_Version
:= Ada_2005
;
382 Ada_Version_Explicit
:= Ada_2005
;
383 Ada_Version_Pragma
:= Pragma_Node
;
386 ---------------------
387 -- Ada_12/Ada_2012 --
388 ---------------------
393 if Arg_Count
= 0 then
394 Ada_Version
:= Ada_2012
;
395 Ada_Version_Explicit
:= Ada_2012
;
396 Ada_Version_Pragma
:= Pragma_Node
;
403 when Pragma_Ada_2022
=>
404 if Arg_Count
= 0 then
405 Ada_Version
:= Ada_2022
;
406 Ada_Version_Explicit
:= Ada_2022
;
407 Ada_Version_Pragma
:= Pragma_Node
;
414 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
417 Check_No_Identifier
(Arg1
);
419 if Arg_Count
= 2 then
420 Check_No_Identifier
(Arg2
);
425 -------------------------------
426 -- Extensions_Allowed (GNAT) --
427 -------------------------------
429 -- pragma Extensions_Allowed (Off | On | All)
431 -- The processing for pragma Extensions_Allowed must be done at
432 -- parse time, since extensions mode may affect what is accepted.
434 when Pragma_Extensions_Allowed
=>
436 Check_No_Identifier
(Arg1
);
437 Check_Arg_Is_On_Or_Off
(Arg1
, All_Extensions_OK_Too
=> True);
439 if Chars
(Expression
(Arg1
)) = Name_On
then
440 Ada_Version
:= Ada_With_Core_Extensions
;
441 elsif Chars
(Expression
(Arg1
)) = Name_All_Extensions
then
442 Ada_Version
:= Ada_With_All_Extensions
;
444 Ada_Version
:= Ada_Version_Explicit
;
451 -- Processing for this pragma must be done at parse time, since we want
452 -- be able to ignore pragmas that are otherwise processed at parse time.
454 when Pragma_Ignore_Pragma
=> Ignore_Pragma
: declare
459 Check_No_Identifier
(Arg1
);
460 A
:= Expression
(Arg1
);
462 if Nkind
(A
) /= N_Identifier
then
463 Error_Msg_N
("incorrect argument for pragma %", A
);
465 Set_Name_Table_Boolean3
(Chars
(A
), True);
473 -- pragma List (Off | On)
475 -- The processing for pragma List must be done at parse time, since a
476 -- listing can be generated in parse only mode.
480 Check_No_Identifier
(Arg1
);
481 Check_Arg_Is_On_Or_Off
(Arg1
);
483 -- We unconditionally make a List_On entry for the pragma, so that
484 -- in the List (Off) case, the pragma will print even in a region
485 -- of code with listing turned off (this is required).
487 Add_List_Pragma_Entry
(List_On
, Sloc
(Pragma_Node
));
489 -- Now generate the list off entry for pragma List (Off)
491 if Chars
(Expression
(Arg1
)) = Name_Off
then
492 Add_List_Pragma_Entry
(List_Off
, Semi
);
501 -- Processing for this pragma must be done at parse time, since a
502 -- listing can be generated in parse only mode with semantics off.
506 Add_List_Pragma_Entry
(Page
, Semi
);
512 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
515 -- restriction_IDENTIFIER
516 -- | restriction_parameter_IDENTIFIER => EXPRESSION
518 -- We process the case of No_Obsolescent_Features, since this has
519 -- a syntactic effect that we need to detect at parse time (the use
520 -- of replacement characters such as colon for pound sign).
522 when Pragma_Restrictions
=>
523 Process_Restrictions_Or_Restriction_Warnings
;
525 --------------------------
526 -- Restriction_Warnings --
527 --------------------------
529 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
532 -- restriction_IDENTIFIER
533 -- | restriction_parameter_IDENTIFIER => EXPRESSION
535 -- See above comment for pragma Restrictions
537 when Pragma_Restriction_Warnings
=>
538 Process_Restrictions_Or_Restriction_Warnings
;
540 ----------------------------------------------------------
541 -- Source_File_Name and Source_File_Name_Project (GNAT) --
542 ----------------------------------------------------------
544 -- These two pragmas have the same syntax and semantics.
545 -- There are five forms of these pragmas:
547 -- pragma Source_File_Name[_Project] (
548 -- [UNIT_NAME =>] unit_NAME,
549 -- BODY_FILE_NAME => STRING_LITERAL
550 -- [, [INDEX =>] INTEGER_LITERAL]);
552 -- pragma Source_File_Name[_Project] (
553 -- [UNIT_NAME =>] unit_NAME,
554 -- SPEC_FILE_NAME => STRING_LITERAL
555 -- [, [INDEX =>] INTEGER_LITERAL]);
557 -- pragma Source_File_Name[_Project] (
558 -- BODY_FILE_NAME => STRING_LITERAL
559 -- [, DOT_REPLACEMENT => STRING_LITERAL]
560 -- [, CASING => CASING_SPEC]);
562 -- pragma Source_File_Name[_Project] (
563 -- SPEC_FILE_NAME => STRING_LITERAL
564 -- [, DOT_REPLACEMENT => STRING_LITERAL]
565 -- [, CASING => CASING_SPEC]);
567 -- pragma Source_File_Name[_Project] (
568 -- SUBUNIT_FILE_NAME => STRING_LITERAL
569 -- [, DOT_REPLACEMENT => STRING_LITERAL]
570 -- [, CASING => CASING_SPEC]);
572 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
574 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
575 -- Source_File_Name (SFN), however their usage is exclusive:
576 -- SFN can only be used when no project file is used, while
577 -- SFNP can only be used when a project file is used.
579 -- The Project Manager produces a configuration pragmas file that
580 -- is communicated to the compiler with -gnatec switch. This file
581 -- contains only SFNP pragmas (at least two for the default naming
582 -- scheme. As this configuration pragmas file is always the first
583 -- processed by the compiler, it prevents the use of pragmas SFN in
584 -- other config files when a project file is in use.
586 -- Note: we process this during parsing, since we need to have the
587 -- source file names set well before the semantic analysis starts,
588 -- since we load the spec and with'ed packages before analysis.
590 when Pragma_Source_File_Name
591 | Pragma_Source_File_Name_Project
593 if Debug_Flag_Underscore_MM
then
594 -- -gnatd_M is causes the compiler to ignore source file name
595 -- pragmas. It's used for reduced reproducer generation.
599 Source_File_Name
: declare
600 Unam
: Unit_Name_Type
;
610 function Get_Fname
(Arg
: Node_Id
) return File_Name_Type
;
611 -- Process file name from unit name form of pragma
613 function Get_String_Argument
(Arg
: Node_Id
) return String_Ptr
;
614 -- Process string literal value from argument
616 procedure Process_Casing
(Arg
: Node_Id
);
617 -- Process Casing argument of pattern form of pragma
619 procedure Process_Dot_Replacement
(Arg
: Node_Id
);
620 -- Process Dot_Replacement argument of pattern form of pragma
626 function Get_Fname
(Arg
: Node_Id
) return File_Name_Type
is
628 String_To_Name_Buffer
(Strval
(Expression
(Arg
)));
630 for J
in 1 .. Name_Len
loop
631 if Is_Directory_Separator
(Name_Buffer
(J
)) then
633 ("directory separator character not allowed",
634 Sloc
(Expression
(Arg
)) + Source_Ptr
(J
));
641 -------------------------
642 -- Get_String_Argument --
643 -------------------------
645 function Get_String_Argument
(Arg
: Node_Id
) return String_Ptr
is
649 if Nkind
(Expression
(Arg
)) /= N_String_Literal
651 Nkind
(Expression
(Arg
)) /= N_Operator_Symbol
654 ("argument for pragma% must be string literal", Arg
);
658 Str
:= Strval
(Expression
(Arg
));
660 -- Check string has no wide chars
662 for J
in 1 .. String_Length
(Str
) loop
663 if Get_String_Char
(Str
, J
) > 255 then
665 ("wide character not allowed in pattern for pragma%",
666 Sloc
(Expression
(Arg2
)) + Text_Ptr
(J
) - 1);
672 String_To_Name_Buffer
(Str
);
673 return new String'(Name_Buffer (1 .. Name_Len));
674 end Get_String_Argument;
680 procedure Process_Casing (Arg : Node_Id) is
681 Expr : constant Node_Id := Expression (Arg);
684 Check_Required_Identifier (Arg, Name_Casing);
686 if Nkind (Expr) = N_Identifier then
687 if Chars (Expr) = Name_Lowercase then
688 Cas := All_Lower_Case;
690 elsif Chars (Expr) = Name_Uppercase then
691 Cas := All_Upper_Case;
693 elsif Chars (Expr) = Name_Mixedcase then
700 ("Casing argument for pragma% must be " &
701 "one of Mixedcase, Lowercase, Uppercase",
705 -----------------------------
706 -- Process_Dot_Replacement --
707 -----------------------------
709 procedure Process_Dot_Replacement (Arg : Node_Id) is
711 Check_Required_Identifier (Arg, Name_Dot_Replacement);
712 Dot := Get_String_Argument (Arg);
713 end Process_Dot_Replacement;
715 -- Start of processing for Source_File_Name and
716 -- Source_File_Name_Project pragmas.
719 if Prag_Id = Pragma_Source_File_Name then
720 if Project_File_In_Use = In_Use then
722 ("pragma Source_File_Name cannot be used " &
723 "with a project file", Pragma_Node);
726 Project_File_In_Use := Not_In_Use;
730 if Project_File_In_Use = Not_In_Use then
732 ("pragma Source_File_Name_Project should only be used " &
733 "with a project file", Pragma_Node);
735 Project_File_In_Use := In_Use;
739 -- We permit from 1 to 3 arguments
741 if Arg_Count not in 1 .. 3 then
745 Expr1 := Expression (Arg1);
747 -- If first argument is identifier or selected component, then
748 -- we have the specific file case of the Source_File_Name pragma,
749 -- and the first argument is a unit name.
751 if Nkind (Expr1) = N_Identifier
753 (Nkind (Expr1) = N_Selected_Component
755 Nkind (Selector_Name (Expr1)) = N_Identifier)
757 if Nkind (Expr1) = N_Identifier
758 and then Chars (Expr1) = Name_System
761 ("pragma Source_File_Name may not be used for System",
766 -- Process index argument if present
768 if Arg_Count = 3 then
769 Expr := Expression (Arg3);
771 if Nkind (Expr) /= N_Integer_Literal
772 or else not UI_Is_In_Int_Range (Intval (Expr))
773 or else Intval (Expr) > 999
774 or else Intval (Expr) <= 0
777 ("pragma% index must be integer literal" &
778 " in range 1 .. 999", Expr);
781 Index := UI_To_Int (Intval (Expr));
784 -- No index argument present
791 Check_Optional_Identifier (Arg1, Name_Unit_Name);
792 Unam := Get_Unit_Name (Expr1);
794 Check_Arg_Is_String_Literal (Arg2);
796 if Chars (Arg2) = Name_Spec_File_Name then
798 (Get_Spec_Name (Unam), Get_Fname (Arg2), Index);
800 elsif Chars (Arg2) = Name_Body_File_Name then
802 (Unam, Get_Fname (Arg2), Index);
806 ("pragma% argument has incorrect identifier", Arg2);
810 -- If the first argument is not an identifier, then we must have
811 -- the pattern form of the pragma, and the first argument must be
812 -- the pattern string with an appropriate name.
815 if Chars (Arg1) = Name_Spec_File_Name then
818 elsif Chars (Arg1) = Name_Body_File_Name then
821 elsif Chars (Arg1) = Name_Subunit_File_Name then
824 elsif Chars (Arg1) = Name_Unit_Name then
826 ("Unit_Name parameter for pragma% must be an identifier",
832 ("pragma% argument has incorrect identifier", Arg1);
836 Pat := Get_String_Argument (Arg1);
838 -- Check pattern has exactly one asterisk
841 for J in Pat'Range loop
842 if Pat (J) = '*' then
849 ("file name pattern must have exactly one * character",
854 -- Set defaults for Casing and Dot_Separator parameters
856 Cas := All_Lower_Case;
857 Dot := new String'(".");
859 -- Process second and third arguments if present
861 if Arg_Count
> 1 then
862 if Chars
(Arg2
) = Name_Casing
then
863 Process_Casing
(Arg2
);
865 if Arg_Count
= 3 then
866 Process_Dot_Replacement
(Arg3
);
870 Process_Dot_Replacement
(Arg2
);
872 if Arg_Count
= 3 then
873 Process_Casing
(Arg3
);
878 Set_File_Name_Pattern
(Pat
, Typ
, Dot
, Cas
);
880 end Source_File_Name
;
882 -----------------------------
883 -- Source_Reference (GNAT) --
884 -----------------------------
886 -- pragma Source_Reference
887 -- (INTEGER_LITERAL [, STRING_LITERAL] );
889 -- Processing for this pragma must be done at parse time, since error
890 -- messages needing the proper line numbers can be generated in parse
891 -- only mode with semantic checking turned off, and indeed we usually
892 -- turn off semantic checking anyway if any parse errors are found.
894 when Pragma_Source_Reference
=> Source_Reference
: declare
895 Fname
: File_Name_Type
;
898 if Arg_Count
/= 1 then
900 Check_No_Identifier
(Arg2
);
903 -- Check that this is first line of file. We skip this test if
904 -- we are in syntax check only mode, since we may be dealing with
905 -- multiple compilation units.
907 if Get_Physical_Line_Number
(Pragma_Sloc
) /= 1
908 and then Num_SRef_Pragmas
(Current_Source_File
) = 0
909 and then Operating_Mode
/= Check_Syntax
911 Error_Msg_N
-- CODEFIX
912 ("first % pragma must be first line of file", Pragma_Node
);
916 Check_No_Identifier
(Arg1
);
918 if Arg_Count
= 1 then
919 if Num_SRef_Pragmas
(Current_Source_File
) = 0 then
921 ("file name required for first % pragma in file",
931 Check_Arg_Is_String_Literal
(Arg2
);
932 String_To_Name_Buffer
(Strval
(Expression
(Arg2
)));
935 if Num_SRef_Pragmas
(Current_Source_File
) > 0 then
936 if Fname
/= Full_Ref_Name
(Current_Source_File
) then
938 ("file name must be same in all % pragmas", Pragma_Node
);
944 if Nkind
(Expression
(Arg1
)) /= N_Integer_Literal
then
946 ("argument for pragma% must be integer literal",
950 -- OK, this source reference pragma is effective, however, we
951 -- ignore it if it is not in the first unit in the multiple unit
952 -- case. This is because the only purpose in this case is to
953 -- provide source pragmas for subsequent use by gnatchop.
956 if Num_Library_Units
= 1 then
957 Register_Source_Ref_Pragma
959 Strip_Directory
(Fname
),
960 UI_To_Int
(Intval
(Expression
(Arg1
))),
961 Get_Physical_Line_Number
(Pragma_Sloc
) + 1);
964 end Source_Reference
;
966 -------------------------
967 -- Style_Checks (GNAT) --
968 -------------------------
970 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
972 -- This is processed by the parser since some of the style
973 -- checks take place during source scanning and parsing.
975 when Pragma_Style_Checks
=> Style_Checks
: declare
979 OK
: Boolean := True;
982 -- Two argument case is only for semantics
984 if Arg_Count
= 2 then
989 Check_No_Identifier
(Arg1
);
990 A
:= Expression
(Arg1
);
992 if Nkind
(A
) = N_String_Literal
then
996 Slen
: constant Natural := Natural (String_Length
(S
));
997 Options
: String (1 .. Slen
);
1004 C
:= Get_String_Char
(S
, Pos
(J
));
1006 if not In_Character_Range
(C
) then
1012 Options
(J
) := Get_Character
(C
);
1016 if not Ignore_Style_Checks_Pragmas
then
1017 Set_Style_Check_Options
(Options
, OK
, Ptr
);
1029 (Style_Msg_Buf
(1 .. Style_Msg_Len
),
1030 Sloc
(Expression
(Arg1
)) + Source_Ptr
(Ptr
));
1035 elsif Nkind
(A
) /= N_Identifier
then
1038 elsif Chars
(A
) = Name_All_Checks
then
1039 if not Ignore_Style_Checks_Pragmas
then
1041 Stylesw
.Set_GNAT_Style_Check_Options
;
1043 Stylesw
.Set_Default_Style_Check_Options
;
1047 elsif Chars
(A
) = Name_On
then
1048 if not Ignore_Style_Checks_Pragmas
then
1049 Style_Check
:= True;
1052 elsif Chars
(A
) = Name_Off
then
1053 if not Ignore_Style_Checks_Pragmas
then
1054 Style_Check
:= False;
1062 Error_Msg_N
("incorrect argument for pragma%", A
);
1068 -------------------------
1069 -- Suppress_All (GNAT) --
1070 -------------------------
1072 -- pragma Suppress_All
1074 -- This is a rather odd pragma, because other compilers allow it in
1075 -- strange places. DEC allows it at the end of units, and Rational
1076 -- allows it as a program unit pragma, when it would be more natural
1077 -- if it were a configuration pragma.
1079 -- Since the reason we provide this pragma is for compatibility with
1080 -- these other compilers, we want to accommodate these strange placement
1081 -- rules, and the easiest thing is simply to allow it anywhere in a
1082 -- unit. If this pragma appears anywhere within a unit, then the effect
1083 -- is as though a pragma Suppress (All_Checks) had appeared as the first
1084 -- line of the current file, i.e. as the first configuration pragma in
1085 -- the current unit.
1087 -- To get this effect, we set the flag Has_Pragma_Suppress_All in the
1088 -- compilation unit node for the current source file then in the last
1089 -- stage of parsing a file, if this flag is set, we materialize the
1090 -- Suppress (All_Checks) pragma, marked as not coming from Source.
1092 when Pragma_Suppress_All
=>
1093 Set_Has_Pragma_Suppress_All
(Cunit
(Current_Source_Unit
));
1095 -----------------------------------
1096 -- User_Aspect_Definition (GNAT) --
1097 -----------------------------------
1099 -- pragma User_Aspect_Definition
1100 -- (Identifier, {, Identifier [(Identifier {, Identifier})]});
1102 when Pragma_User_Aspect_Definition
=>
1103 if Arg_Count
< 1 then
1104 Check_Arg_Count
(1);
1107 OK
: Boolean := True;
1110 function All_Identifiers
(L
: List_Id
) return Boolean;
1111 -- Return True if every list element has Nkind = N_Identifier.
1113 ---------------------
1114 -- All_Identifiers --
1115 ---------------------
1116 function All_Identifiers
(L
: List_Id
) return Boolean is
1117 N
: Node_Id
:= First
(L
);
1119 while Present
(N
) loop
1120 if Nkind
(N
) /= N_Identifier
then
1126 end All_Identifiers
;
1130 while Present
(Arg_Node
) and OK
loop
1131 Check_No_Identifier
(Arg_Node
);
1132 Expr
:= Expression
(Arg_Node
);
1133 case Nkind
(Expr
) is
1134 when N_Identifier
=>
1136 when N_Indexed_Component
=>
1137 OK
:= Arg_Node
/= Arg1
-- first arg must be identifier
1138 and then Nkind
(Prefix
(Expr
)) = N_Identifier
1139 and then All_Identifiers
(Expressions
(Expr
));
1146 Error_Msg_N
("incorrect argument for pragma%", Arg_Node
);
1151 ----------------------
1152 -- Warning_As_Error --
1153 ----------------------
1155 -- pragma Warning_As_Error (static_string_EXPRESSION);
1157 -- Further processing is done in Sem_Prag
1159 when Pragma_Warning_As_Error
=>
1160 Check_Arg_Count
(1);
1161 Check_Arg_Is_String_Literal
(Arg1
);
1162 Warnings_As_Errors_Count
:= Warnings_As_Errors_Count
+ 1;
1163 Warnings_As_Errors
(Warnings_As_Errors_Count
) :=
1164 new String'(Acquire_Warning_Match_String (Get_Pragma_Arg (Arg1)));
1166 ---------------------
1167 -- Warnings (GNAT) --
1168 ---------------------
1170 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
1172 -- DETAILS ::= On | Off
1173 -- DETAILS ::= On | Off, local_NAME
1174 -- DETAILS ::= static_string_EXPRESSION
1175 -- DETAILS ::= On | Off, static_string_EXPRESSION
1177 -- TOOL_NAME ::= GNAT | GNATprove
1179 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
1181 -- Note: If the first argument matches an allowed tool name, it is
1182 -- always considered to be a tool name, even if there is a string
1183 -- variable of that name.
1185 -- The one argument ON/OFF case is processed by the parser, since it may
1186 -- control parser warnings as well as semantic warnings, and in any case
1187 -- we want to be absolutely sure that the range in the warnings table is
1188 -- set well before any semantic analysis is performed. Note that we
1189 -- ignore this pragma if debug flag -gnatd.i is set.
1191 -- Also note that the "one argument" case may have two or three
1192 -- arguments if the first one is a tool name, and/or the last one is a
1195 when Pragma_Warnings => Warnings : declare
1196 function First_Arg_Is_Matching_Tool_Name return Boolean;
1197 -- Returns True if the first argument is a tool name matching the
1198 -- current tool being run.
1200 function Last_Arg return Node_Id;
1201 -- Returns the last argument
1203 function Last_Arg_Is_Reason return Boolean;
1204 -- Returns True if the last argument is a reason argument
1206 function Get_Reason return String_Id;
1207 -- Analyzes Reason argument and returns corresponding String_Id
1208 -- value, or null if there is no Reason argument, or if the
1209 -- argument is not of the required form.
1211 -------------------------------------
1212 -- First_Arg_Is_Matching_Tool_Name --
1213 -------------------------------------
1215 function First_Arg_Is_Matching_Tool_Name return Boolean is
1216 Expr : constant Node_Id := Get_Pragma_Arg (Arg1);
1218 return Nkind (Expr) = N_Identifier
1220 -- Return True if the tool name is GNAT, and we're not in
1221 -- GNATprove or CodePeer mode...
1223 and then ((Chars (Expr) = Name_Gnat
1225 (CodePeer_Mode or GNATprove_Mode))
1227 -- or if the tool name is GNATprove, and we're in GNATprove
1231 (Chars (Expr) = Name_Gnatprove
1232 and then GNATprove_Mode));
1233 end First_Arg_Is_Matching_Tool_Name;
1239 function Get_Reason return String_Id is
1240 Arg : constant Node_Id := Last_Arg;
1242 if Last_Arg_Is_Reason then
1244 Get_Reason_String (Expression (Arg));
1247 return Null_String_Id;
1255 function Last_Arg return Node_Id is
1259 if Arg_Count = 1 then
1261 elsif Arg_Count = 2 then
1263 elsif Arg_Count = 3 then
1265 elsif Arg_Count = 4 then
1266 Last_Arg := Next (Arg3);
1268 -- Illegal case, error issued in semantic analysis
1277 ------------------------
1278 -- Last_Arg_Is_Reason --
1279 ------------------------
1281 function Last_Arg_Is_Reason return Boolean is
1282 Arg : constant Node_Id := Last_Arg;
1284 return Nkind (Arg) in N_Has_Chars
1285 and then Chars (Arg) = Name_Reason;
1286 end Last_Arg_Is_Reason;
1288 The_Arg : Node_Id; -- On/Off argument
1291 -- Start of processing for Warnings
1294 if not Debug_Flag_Dot_I
1295 and then (Arg_Count = 1
1296 or else (Arg_Count = 2
1297 and then (First_Arg_Is_Matching_Tool_Name
1299 Last_Arg_Is_Reason))
1300 or else (Arg_Count = 3
1301 and then First_Arg_Is_Matching_Tool_Name
1302 and then Last_Arg_Is_Reason))
1304 if First_Arg_Is_Matching_Tool_Name then
1310 Check_No_Identifier (The_Arg);
1311 Argx := Expression (The_Arg);
1313 if Nkind (Argx) = N_Identifier then
1314 if Chars (Argx) = Name_On then
1315 Set_Warnings_Mode_On (Pragma_Sloc);
1316 elsif Chars (Argx) = Name_Off then
1317 Set_Warnings_Mode_Off (Pragma_Sloc, Get_Reason);
1323 -----------------------------
1324 -- Wide_Character_Encoding --
1325 -----------------------------
1327 -- pragma Wide_Character_Encoding (IDENTIFIER | CHARACTER_LITERAL);
1329 -- This is processed by the parser, since the scanner is affected
1331 when Pragma_Wide_Character_Encoding => Wide_Character_Encoding : declare
1335 Check_Arg_Count (1);
1336 Check_No_Identifier (Arg1);
1337 A := Expression (Arg1);
1339 if Nkind (A) = N_Identifier then
1340 Get_Name_String (Chars (A));
1341 Wide_Character_Encoding_Method :=
1342 Get_WC_Encoding_Method (Name_Buffer (1 .. Name_Len));
1344 elsif Nkind (A) = N_Character_Literal then
1346 R : constant Char_Code := UI_To_CC (Char_Literal_Value (A));
1348 if In_Character_Range (R) then
1349 Wide_Character_Encoding_Method :=
1350 Get_WC_Encoding_Method (Get_Character (R));
1352 raise Constraint_Error;
1357 raise Constraint_Error;
1360 Upper_Half_Encoding :=
1361 Wide_Character_Encoding_Method in
1362 WC_Upper_Half_Encoding_Method;
1365 when Constraint_Error =>
1366 Error_Msg_N ("invalid argument for pragma%", Arg1);
1367 end Wide_Character_Encoding;
1369 -----------------------
1370 -- All Other Pragmas --
1371 -----------------------
1373 -- For all other pragmas, checking and processing is handled entirely in
1374 -- Sem_Prag, and no further checking is done by Par.
1376 when Pragma_Abort_Defer
1377 | Pragma_Abstract_State
1378 | Pragma_Aggregate_Individually_Assign
1379 | Pragma_All_Calls_Remote
1380 | Pragma_Allow_Integer_Address
1381 | Pragma_Always_Terminates
1384 | Pragma_Assert_And_Cut
1385 | Pragma_Assertion_Policy
1387 | Pragma_Assume_No_Invalid_Values
1388 | Pragma_Async_Readers
1389 | Pragma_Async_Writers
1390 | Pragma_Asynchronous
1392 | Pragma_Atomic_Components
1393 | Pragma_Attach_Handler
1394 | Pragma_Attribute_Definition
1396 | Pragma_CPP_Constructor
1397 | Pragma_CPP_Virtual
1400 | Pragma_CUDA_Device
1401 | Pragma_CUDA_Execute
1402 | Pragma_CUDA_Global
1403 | Pragma_C_Pass_By_Copy
1405 | Pragma_Check_Float_Overflow
1407 | Pragma_Check_Policy
1409 | Pragma_Common_Object
1410 | Pragma_Compile_Time_Error
1411 | Pragma_Compile_Time_Warning
1412 | Pragma_Complete_Representation
1413 | Pragma_Complex_Representation
1414 | Pragma_Component_Alignment
1415 | Pragma_Constant_After_Elaboration
1416 | Pragma_Contract_Cases
1419 | Pragma_Convention_Identifier
1420 | Pragma_Deadline_Floor
1421 | Pragma_Debug_Policy
1422 | Pragma_Default_Initial_Condition
1423 | Pragma_Default_Scalar_Storage_Order
1424 | Pragma_Default_Storage_Pool
1426 | Pragma_Detect_Blocking
1427 | Pragma_Disable_Atomic_Synchronization
1428 | Pragma_Discard_Names
1429 | Pragma_Dispatching_Domain
1430 | Pragma_Effective_Reads
1431 | Pragma_Effective_Writes
1433 | Pragma_Elaborate_All
1434 | Pragma_Elaborate_Body
1435 | Pragma_Elaboration_Checks
1437 | Pragma_Enable_Atomic_Synchronization
1438 | Pragma_Exceptional_Cases
1440 | Pragma_Export_Function
1441 | Pragma_Export_Object
1442 | Pragma_Export_Procedure
1443 | Pragma_Export_Valued_Procedure
1444 | Pragma_Extend_System
1445 | Pragma_Extended_Access
1446 | Pragma_Extensions_Visible
1448 | Pragma_External_Name_Casing
1450 | Pragma_Favor_Top_Level
1451 | Pragma_Finalize_Storage_Only
1452 | Pragma_First_Controlling_Parameter
1455 | Pragma_GNAT_Annotate
1457 | Pragma_Implementation_Defined
1458 | Pragma_Implemented
1459 | Pragma_Implicit_Packing
1461 | Pragma_Import_Function
1462 | Pragma_Import_Object
1463 | Pragma_Import_Procedure
1464 | Pragma_Import_Valued_Procedure
1465 | Pragma_Independent
1466 | Pragma_Independent_Components
1467 | Pragma_Initial_Condition
1468 | Pragma_Initialize_Scalars
1469 | Pragma_Initializes
1471 | Pragma_Inline_Always
1472 | Pragma_Inline_Generic
1473 | Pragma_Inspection_Point
1475 | Pragma_Interface_Name
1476 | Pragma_Interrupt_Handler
1477 | Pragma_Interrupt_Priority
1478 | Pragma_Interrupt_State
1483 | Pragma_Linker_Alias
1484 | Pragma_Linker_Constructor
1485 | Pragma_Linker_Destructor
1486 | Pragma_Linker_Options
1487 | Pragma_Linker_Section
1489 | Pragma_Locking_Policy
1490 | Pragma_Loop_Invariant
1491 | Pragma_Loop_Optimize
1492 | Pragma_Loop_Variant
1493 | Pragma_Machine_Attribute
1495 | Pragma_Main_Storage
1496 | Pragma_Max_Entry_Queue_Length
1497 | Pragma_Max_Queue_Length
1498 | Pragma_Memory_Size
1501 | Pragma_No_Component_Reordering
1502 | Pragma_No_Elaboration_Code_All
1503 | Pragma_No_Heap_Finalization
1507 | Pragma_No_Run_Time
1508 | Pragma_Interrupts_System_By_Default
1509 | Pragma_No_Strict_Aliasing
1510 | Pragma_No_Tagged_Streams
1511 | Pragma_Normalize_Scalars
1512 | Pragma_Obsolescent
1514 | Pragma_Optimize_Alignment
1516 | Pragma_Overflow_Mode
1517 | Pragma_Overriding_Renamings
1520 | Pragma_Partition_Elaboration_Policy
1522 | Pragma_Persistent_BSS
1525 | Pragma_Postcondition
1528 | Pragma_Precondition
1530 | Pragma_Predicate_Failure
1531 | Pragma_Preelaborable_Initialization
1532 | Pragma_Preelaborate
1533 | Pragma_Prefix_Exception_Messages
1535 | Pragma_Priority_Specific_Dispatching
1537 | Pragma_Profile_Warnings
1538 | Pragma_Propagate_Exceptions
1539 | Pragma_Provide_Shift_Operators
1540 | Pragma_Psect_Object
1542 | Pragma_Pure_Function
1543 | Pragma_Queuing_Policy
1546 | Pragma_Refined_Depends
1547 | Pragma_Refined_Global
1548 | Pragma_Refined_Post
1549 | Pragma_Refined_State
1550 | Pragma_Relative_Deadline
1551 | Pragma_Remote_Access_Type
1552 | Pragma_Remote_Call_Interface
1553 | Pragma_Remote_Types
1554 | Pragma_Rename_Pragma
1555 | Pragma_Restricted_Run_Time
1557 | Pragma_Side_Effects
1559 | Pragma_Secondary_Stack_Size
1560 | Pragma_Share_Generic
1562 | Pragma_Shared_Passive
1563 | Pragma_Short_Circuit_And_Or
1564 | Pragma_Short_Descriptors
1565 | Pragma_Simple_Storage_Pool_Type
1566 | Pragma_Simulate_Internal_Error
1567 | Pragma_Static_Elaboration_Desired
1568 | Pragma_Storage_Size
1569 | Pragma_Storage_Unit
1570 | Pragma_Stream_Convert
1572 | Pragma_Subprogram_Variant
1574 | Pragma_Suppress_Debug_Info
1575 | Pragma_Suppress_Exception_Locations
1576 | Pragma_Suppress_Initialization
1577 | Pragma_System_Name
1578 | Pragma_Task_Dispatching_Policy
1581 | Pragma_Task_Storage
1583 | Pragma_Thread_Local_Storage
1586 | Pragma_Type_Invariant
1587 | Pragma_Type_Invariant_Class
1588 | Pragma_Unchecked_Union
1589 | Pragma_Unevaluated_Use_Of_Old
1590 | Pragma_Unimplemented_Unit
1591 | Pragma_Universal_Aliasing
1593 | Pragma_Unreferenced
1594 | Pragma_Unreferenced_Objects
1595 | Pragma_Unreserve_All_Interrupts
1598 | Pragma_Use_VADS_Size
1599 | Pragma_Validity_Checks
1601 | Pragma_Volatile_Components
1602 | Pragma_Volatile_Full_Access
1603 | Pragma_Volatile_Function
1604 | Pragma_Weak_External
1608 --------------------
1609 -- Unknown_Pragma --
1610 --------------------
1612 -- Should be impossible, since we excluded this case earlier on
1614 when Unknown_Pragma =>
1615 raise Program_Error;
1621 --------------------
1622 -- Error Handling --
1623 --------------------
1626 when Error_Resync =>