1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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
(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
: Int
);
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
(Arg
: Node_Id
);
77 -- Check the expression of the specified argument to make sure that it
78 -- is an identifier which is either ON or OFF, and if not, then issue
79 -- an error message and raise Error_Resync.
81 procedure Check_No_Identifier
(Arg
: Node_Id
);
82 -- Checks that the given argument does not have an identifier. If
83 -- an identifier is present, then an error message is issued, and
84 -- Error_Resync is raised.
86 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
87 -- Checks if the given argument has an identifier, and if so, requires
88 -- it to match the given identifier name. If there is a non-matching
89 -- identifier, then an error message is given and Error_Resync raised.
91 procedure Check_Required_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
92 -- Same as Check_Optional_Identifier, except that the name is required
93 -- to be present and to match the given Id value.
95 procedure Process_Restrictions_Or_Restriction_Warnings
;
96 -- Common processing for Restrictions and Restriction_Warnings pragmas.
97 -- For the most part, restrictions need not be processed at parse time,
98 -- since they only affect semantic processing. This routine handles the
99 -- exceptions as follows
101 -- No_Obsolescent_Features must be processed at parse time, since there
102 -- are some obsolescent features (e.g. character replacements) which are
103 -- handled at parse time.
105 -- SPARK must be processed at parse time, since this restriction controls
106 -- whether the scanner recognizes a spark HIDE directive formatted as an
107 -- Ada comment (and generates a Tok_SPARK_Hide token for the directive).
109 -- No_Dependence must be processed at parse time, since otherwise it gets
112 -- Note that we don't need to do full error checking for badly formed cases
113 -- of restrictions, since these will be caught during semantic analysis.
115 ---------------------------
116 -- Add_List_Pragma_Entry --
117 ---------------------------
119 procedure Add_List_Pragma_Entry
(PT
: List_Pragma_Type
; Loc
: Source_Ptr
) is
121 if List_Pragmas
.Last
< List_Pragmas
.First
122 or else (List_Pragmas
.Table
(List_Pragmas
.Last
)) /= ((PT
, Loc
))
124 List_Pragmas
.Append
((PT
, Loc
));
126 end Add_List_Pragma_Entry
;
132 function Arg1
return Node_Id
is
134 return First
(Pragma_Argument_Associations
(Pragma_Node
));
141 function Arg2
return Node_Id
is
150 function Arg3
return Node_Id
is
155 ---------------------
156 -- Check_Arg_Count --
157 ---------------------
159 procedure Check_Arg_Count
(Required
: Int
) is
161 if Arg_Count
/= Required
then
162 Error_Msg
("wrong number of arguments for pragma%", Pragma_Sloc
);
167 ----------------------------
168 -- Check_Arg_Is_On_Or_Off --
169 ----------------------------
171 procedure Check_Arg_Is_On_Or_Off
(Arg
: Node_Id
) is
172 Argx
: constant Node_Id
:= Expression
(Arg
);
175 if Nkind
(Expression
(Arg
)) /= N_Identifier
176 or else not Nam_In
(Chars
(Argx
), Name_On
, Name_Off
)
178 Error_Msg_Name_2
:= Name_On
;
179 Error_Msg_Name_3
:= Name_Off
;
181 Error_Msg
("argument for pragma% must be% or%", Sloc
(Argx
));
184 end Check_Arg_Is_On_Or_Off
;
186 ---------------------------------
187 -- Check_Arg_Is_String_Literal --
188 ---------------------------------
190 procedure Check_Arg_Is_String_Literal
(Arg
: Node_Id
) is
192 if Nkind
(Expression
(Arg
)) /= N_String_Literal
then
194 ("argument for pragma% must be string literal",
195 Sloc
(Expression
(Arg
)));
198 end Check_Arg_Is_String_Literal
;
200 -------------------------
201 -- Check_No_Identifier --
202 -------------------------
204 procedure Check_No_Identifier
(Arg
: Node_Id
) is
206 if Chars
(Arg
) /= No_Name
then
207 Error_Msg_N
("pragma% does not permit named arguments", Arg
);
210 end Check_No_Identifier
;
212 -------------------------------
213 -- Check_Optional_Identifier --
214 -------------------------------
216 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
218 if Present
(Arg
) and then Chars
(Arg
) /= No_Name
then
219 if Chars
(Arg
) /= Id
then
220 Error_Msg_Name_2
:= Id
;
221 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
224 end Check_Optional_Identifier
;
226 -------------------------------
227 -- Check_Required_Identifier --
228 -------------------------------
230 procedure Check_Required_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
232 if Chars
(Arg
) /= Id
then
233 Error_Msg_Name_2
:= Id
;
234 Error_Msg_N
("pragma% argument must have identifier%", Arg
);
236 end Check_Required_Identifier
;
238 --------------------------------------------------
239 -- Process_Restrictions_Or_Restriction_Warnings --
240 --------------------------------------------------
242 procedure Process_Restrictions_Or_Restriction_Warnings
is
249 while Present
(Arg
) loop
251 Expr
:= Expression
(Arg
);
253 if Id
= No_Name
and then Nkind
(Expr
) = N_Identifier
then
255 when Name_No_Obsolescent_Features
=>
256 Set_Restriction
(No_Obsolescent_Features
, Pragma_Node
);
257 Restriction_Warnings
(No_Obsolescent_Features
) :=
258 Prag_Id
= Pragma_Restriction_Warnings
;
260 when Name_SPARK | Name_SPARK_05
=>
261 Set_Restriction
(SPARK_05
, Pragma_Node
);
262 Restriction_Warnings
(SPARK_05
) :=
263 Prag_Id
= Pragma_Restriction_Warnings
;
269 elsif Id
= Name_No_Dependence
then
270 Set_Restriction_No_Dependence
272 Warn
=> Prag_Id
= Pragma_Restriction_Warnings
273 or else Treat_Restrictions_As_Warnings
);
278 end Process_Restrictions_Or_Restriction_Warnings
;
280 -- Start of processing for Prag
283 Error_Msg_Name_1
:= Prag_Name
;
285 -- Ignore unrecognized pragma. We let Sem post the warning for this, since
286 -- it is a semantic error, not a syntactic one (we have already checked
287 -- the syntax for the unrecognized pragma as required by (RM 2.8(11)).
289 if Prag_Id
= Unknown_Pragma
then
293 -- Ignore pragma previously flagged by Ignore_Pragma
295 if Get_Name_Table_Boolean3
(Prag_Name
) then
299 -- Count number of arguments. This loop also checks if any of the arguments
300 -- are Error, indicating a syntax error as they were parsed. If so, we
301 -- simply return, because we get into trouble with cascaded errors if we
302 -- try to perform our error checks on junk arguments.
306 if Present
(Pragma_Argument_Associations
(Pragma_Node
)) then
308 while Arg_Node
/= Empty
loop
309 Arg_Count
:= Arg_Count
+ 1;
311 if Expression
(Arg_Node
) = Error
then
319 -- Remaining processing is pragma dependent
327 -- This pragma must be processed at parse time, since we want to set
328 -- the Ada version properly at parse time to recognize the appropriate
329 -- Ada version syntax.
331 when Pragma_Ada_83
=>
332 if not Latest_Ada_Only
then
333 Ada_Version
:= Ada_83
;
334 Ada_Version_Explicit
:= Ada_83
;
335 Ada_Version_Pragma
:= Pragma_Node
;
342 -- This pragma must be processed at parse time, since we want to set
343 -- the Ada version properly at parse time to recognize the appropriate
344 -- Ada version syntax.
346 when Pragma_Ada_95
=>
347 if not Latest_Ada_Only
then
348 Ada_Version
:= Ada_95
;
349 Ada_Version_Explicit
:= Ada_95
;
350 Ada_Version_Pragma
:= Pragma_Node
;
353 ---------------------
354 -- Ada_05/Ada_2005 --
355 ---------------------
357 -- These pragmas must be processed at parse time, since we want to set
358 -- the Ada version properly at parse time to recognize the appropriate
359 -- Ada version syntax. However, it is only the zero argument form that
360 -- must be processed at parse time.
362 when Pragma_Ada_05 | Pragma_Ada_2005
=>
363 if Arg_Count
= 0 and not Latest_Ada_Only
then
364 Ada_Version
:= Ada_2005
;
365 Ada_Version_Explicit
:= Ada_2005
;
366 Ada_Version_Pragma
:= Pragma_Node
;
369 ---------------------
370 -- Ada_12/Ada_2012 --
371 ---------------------
373 -- These pragmas must be processed at parse time, since we want to set
374 -- the Ada version properly at parse time to recognize the appropriate
375 -- Ada version syntax. However, it is only the zero argument form that
376 -- must be processed at parse time.
378 when Pragma_Ada_12 | Pragma_Ada_2012
=>
379 if Arg_Count
= 0 then
380 Ada_Version
:= Ada_2012
;
381 Ada_Version_Explicit
:= Ada_2012
;
382 Ada_Version_Pragma
:= Pragma_Node
;
385 ---------------------------
386 -- Compiler_Unit_Warning --
387 ---------------------------
389 -- This pragma must be processed at parse time, since the resulting
390 -- status may be tested during the parsing of the program.
392 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning
=>
395 -- Only recognized in main unit
397 if Current_Source_Unit
= Main_Unit
then
398 Compiler_Unit
:= True;
405 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
408 Check_No_Identifier
(Arg1
);
410 if Arg_Count
= 2 then
411 Check_No_Identifier
(Arg2
);
416 -------------------------------
417 -- Extensions_Allowed (GNAT) --
418 -------------------------------
420 -- pragma Extensions_Allowed (Off | On)
422 -- The processing for pragma Extensions_Allowed must be done at
423 -- parse time, since extensions mode may affect what is accepted.
425 when Pragma_Extensions_Allowed
=>
427 Check_No_Identifier
(Arg1
);
428 Check_Arg_Is_On_Or_Off
(Arg1
);
430 if Chars
(Expression
(Arg1
)) = Name_On
then
431 Extensions_Allowed
:= True;
432 Ada_Version
:= Ada_2012
;
434 Extensions_Allowed
:= False;
435 Ada_Version
:= Ada_Version_Explicit
;
442 -- Processing for this pragma must be done at parse time, since we want
443 -- be able to ignore pragmas that are otherwise processed at parse time.
445 when Pragma_Ignore_Pragma
=> Ignore_Pragma
: declare
450 Check_No_Identifier
(Arg1
);
451 A
:= Expression
(Arg1
);
453 if Nkind
(A
) /= N_Identifier
then
454 Error_Msg
("incorrect argument for pragma %", Sloc
(A
));
456 Set_Name_Table_Boolean3
(Chars
(A
), True);
464 -- pragma List (Off | On)
466 -- The processing for pragma List must be done at parse time, since a
467 -- listing can be generated in parse only mode.
471 Check_No_Identifier
(Arg1
);
472 Check_Arg_Is_On_Or_Off
(Arg1
);
474 -- We unconditionally make a List_On entry for the pragma, so that
475 -- in the List (Off) case, the pragma will print even in a region
476 -- of code with listing turned off (this is required).
478 Add_List_Pragma_Entry
(List_On
, Sloc
(Pragma_Node
));
480 -- Now generate the list off entry for pragma List (Off)
482 if Chars
(Expression
(Arg1
)) = Name_Off
then
483 Add_List_Pragma_Entry
(List_Off
, Semi
);
492 -- Processing for this pragma must be done at parse time, since a
493 -- listing can be generated in parse only mode with semantics off.
497 Add_List_Pragma_Entry
(Page
, Semi
);
503 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
506 -- restriction_IDENTIFIER
507 -- | restriction_parameter_IDENTIFIER => EXPRESSION
509 -- We process the case of No_Obsolescent_Features, since this has
510 -- a syntactic effect that we need to detect at parse time (the use
511 -- of replacement characters such as colon for pound sign).
513 when Pragma_Restrictions
=>
514 Process_Restrictions_Or_Restriction_Warnings
;
516 --------------------------
517 -- Restriction_Warnings --
518 --------------------------
520 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
523 -- restriction_IDENTIFIER
524 -- | restriction_parameter_IDENTIFIER => EXPRESSION
526 -- See above comment for pragma Restrictions
528 when Pragma_Restriction_Warnings
=>
529 Process_Restrictions_Or_Restriction_Warnings
;
531 ----------------------------------------------------------
532 -- Source_File_Name and Source_File_Name_Project (GNAT) --
533 ----------------------------------------------------------
535 -- These two pragmas have the same syntax and semantics.
536 -- There are five forms of these pragmas:
538 -- pragma Source_File_Name[_Project] (
539 -- [UNIT_NAME =>] unit_NAME,
540 -- BODY_FILE_NAME => STRING_LITERAL
541 -- [, [INDEX =>] INTEGER_LITERAL]);
543 -- pragma Source_File_Name[_Project] (
544 -- [UNIT_NAME =>] unit_NAME,
545 -- SPEC_FILE_NAME => STRING_LITERAL
546 -- [, [INDEX =>] INTEGER_LITERAL]);
548 -- pragma Source_File_Name[_Project] (
549 -- BODY_FILE_NAME => STRING_LITERAL
550 -- [, DOT_REPLACEMENT => STRING_LITERAL]
551 -- [, CASING => CASING_SPEC]);
553 -- pragma Source_File_Name[_Project] (
554 -- SPEC_FILE_NAME => STRING_LITERAL
555 -- [, DOT_REPLACEMENT => STRING_LITERAL]
556 -- [, CASING => CASING_SPEC]);
558 -- pragma Source_File_Name[_Project] (
559 -- SUBUNIT_FILE_NAME => STRING_LITERAL
560 -- [, DOT_REPLACEMENT => STRING_LITERAL]
561 -- [, CASING => CASING_SPEC]);
563 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
565 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
566 -- Source_File_Name (SFN), however their usage is exclusive:
567 -- SFN can only be used when no project file is used, while
568 -- SFNP can only be used when a project file is used.
570 -- The Project Manager produces a configuration pragmas file that
571 -- is communicated to the compiler with -gnatec switch. This file
572 -- contains only SFNP pragmas (at least two for the default naming
573 -- scheme. As this configuration pragmas file is always the first
574 -- processed by the compiler, it prevents the use of pragmas SFN in
575 -- other config files when a project file is in use.
577 -- Note: we process this during parsing, since we need to have the
578 -- source file names set well before the semantic analysis starts,
579 -- since we load the spec and with'ed packages before analysis.
581 when Pragma_Source_File_Name | Pragma_Source_File_Name_Project
=>
582 Source_File_Name
: declare
583 Unam
: Unit_Name_Type
;
593 function Get_Fname
(Arg
: Node_Id
) return File_Name_Type
;
594 -- Process file name from unit name form of pragma
596 function Get_String_Argument
(Arg
: Node_Id
) return String_Ptr
;
597 -- Process string literal value from argument
599 procedure Process_Casing
(Arg
: Node_Id
);
600 -- Process Casing argument of pattern form of pragma
602 procedure Process_Dot_Replacement
(Arg
: Node_Id
);
603 -- Process Dot_Replacement argument of pattern form of pragma
609 function Get_Fname
(Arg
: Node_Id
) return File_Name_Type
is
611 String_To_Name_Buffer
(Strval
(Expression
(Arg
)));
613 for J
in 1 .. Name_Len
loop
614 if Is_Directory_Separator
(Name_Buffer
(J
)) then
616 ("directory separator character not allowed",
617 Sloc
(Expression
(Arg
)) + Source_Ptr
(J
));
624 -------------------------
625 -- Get_String_Argument --
626 -------------------------
628 function Get_String_Argument
(Arg
: Node_Id
) return String_Ptr
is
632 if Nkind
(Expression
(Arg
)) /= N_String_Literal
634 Nkind
(Expression
(Arg
)) /= N_Operator_Symbol
637 ("argument for pragma% must be string literal", Arg
);
641 Str
:= Strval
(Expression
(Arg
));
643 -- Check string has no wide chars
645 for J
in 1 .. String_Length
(Str
) loop
646 if Get_String_Char
(Str
, J
) > 255 then
648 ("wide character not allowed in pattern for pragma%",
649 Sloc
(Expression
(Arg2
)) + Text_Ptr
(J
) - 1);
655 String_To_Name_Buffer
(Str
);
656 return new String'(Name_Buffer (1 .. Name_Len));
657 end Get_String_Argument;
663 procedure Process_Casing (Arg : Node_Id) is
664 Expr : constant Node_Id := Expression (Arg);
667 Check_Required_Identifier (Arg, Name_Casing);
669 if Nkind (Expr) = N_Identifier then
670 if Chars (Expr) = Name_Lowercase then
671 Cas := All_Lower_Case;
673 elsif Chars (Expr) = Name_Uppercase then
674 Cas := All_Upper_Case;
676 elsif Chars (Expr) = Name_Mixedcase then
683 ("Casing argument for pragma% must be " &
684 "one of Mixedcase, Lowercase, Uppercase",
688 -----------------------------
689 -- Process_Dot_Replacement --
690 -----------------------------
692 procedure Process_Dot_Replacement (Arg : Node_Id) is
694 Check_Required_Identifier (Arg, Name_Dot_Replacement);
695 Dot := Get_String_Argument (Arg);
696 end Process_Dot_Replacement;
698 -- Start of processing for Source_File_Name and
699 -- Source_File_Name_Project pragmas.
702 if Prag_Id = Pragma_Source_File_Name then
703 if Project_File_In_Use = In_Use then
705 ("pragma Source_File_Name cannot be used " &
706 "with a project file", Pragma_Sloc);
709 Project_File_In_Use := Not_In_Use;
713 if Project_File_In_Use = Not_In_Use then
715 ("pragma Source_File_Name_Project should only be used " &
716 "with a project file", Pragma_Sloc);
718 Project_File_In_Use := In_Use;
722 -- We permit from 1 to 3 arguments
724 if Arg_Count not in 1 .. 3 then
728 Expr1 := Expression (Arg1);
730 -- If first argument is identifier or selected component, then
731 -- we have the specific file case of the Source_File_Name pragma,
732 -- and the first argument is a unit name.
734 if Nkind (Expr1) = N_Identifier
736 (Nkind (Expr1) = N_Selected_Component
738 Nkind (Selector_Name (Expr1)) = N_Identifier)
740 if Nkind (Expr1) = N_Identifier
741 and then Chars (Expr1) = Name_System
744 ("pragma Source_File_Name may not be used for System",
749 -- Process index argument if present
751 if Arg_Count = 3 then
752 Expr := Expression (Arg3);
754 if Nkind (Expr) /= N_Integer_Literal
755 or else not UI_Is_In_Int_Range (Intval (Expr))
756 or else Intval (Expr) > 999
757 or else Intval (Expr) <= 0
760 ("pragma% index must be integer literal" &
761 " in range 1 .. 999", Sloc (Expr));
764 Index := UI_To_Int (Intval (Expr));
767 -- No index argument present
774 Check_Optional_Identifier (Arg1, Name_Unit_Name);
775 Unam := Get_Unit_Name (Expr1);
777 Check_Arg_Is_String_Literal (Arg2);
779 if Chars (Arg2) = Name_Spec_File_Name then
781 (Get_Spec_Name (Unam), Get_Fname (Arg2), Index);
783 elsif Chars (Arg2) = Name_Body_File_Name then
785 (Unam, Get_Fname (Arg2), Index);
789 ("pragma% argument has incorrect identifier", Arg2);
793 -- If the first argument is not an identifier, then we must have
794 -- the pattern form of the pragma, and the first argument must be
795 -- the pattern string with an appropriate name.
798 if Chars (Arg1) = Name_Spec_File_Name then
801 elsif Chars (Arg1) = Name_Body_File_Name then
804 elsif Chars (Arg1) = Name_Subunit_File_Name then
807 elsif Chars (Arg1) = Name_Unit_Name then
809 ("Unit_Name parameter for pragma% must be an identifier",
815 ("pragma% argument has incorrect identifier", Arg1);
819 Pat := Get_String_Argument (Arg1);
821 -- Check pattern has exactly one asterisk
824 for J in Pat'Range loop
825 if Pat (J) = '*' then
832 ("file name pattern must have exactly one * character",
837 -- Set defaults for Casing and Dot_Separator parameters
839 Cas := All_Lower_Case;
840 Dot := new String'(".");
842 -- Process second and third arguments if present
844 if Arg_Count
> 1 then
845 if Chars
(Arg2
) = Name_Casing
then
846 Process_Casing
(Arg2
);
848 if Arg_Count
= 3 then
849 Process_Dot_Replacement
(Arg3
);
853 Process_Dot_Replacement
(Arg2
);
855 if Arg_Count
= 3 then
856 Process_Casing
(Arg3
);
861 Set_File_Name_Pattern
(Pat
, Typ
, Dot
, Cas
);
863 end Source_File_Name
;
865 -----------------------------
866 -- Source_Reference (GNAT) --
867 -----------------------------
869 -- pragma Source_Reference
870 -- (INTEGER_LITERAL [, STRING_LITERAL] );
872 -- Processing for this pragma must be done at parse time, since error
873 -- messages needing the proper line numbers can be generated in parse
874 -- only mode with semantic checking turned off, and indeed we usually
875 -- turn off semantic checking anyway if any parse errors are found.
877 when Pragma_Source_Reference
=> Source_Reference
: declare
878 Fname
: File_Name_Type
;
881 if Arg_Count
/= 1 then
883 Check_No_Identifier
(Arg2
);
886 -- Check that this is first line of file. We skip this test if
887 -- we are in syntax check only mode, since we may be dealing with
888 -- multiple compilation units.
890 if Get_Physical_Line_Number
(Pragma_Sloc
) /= 1
891 and then Num_SRef_Pragmas
(Current_Source_File
) = 0
892 and then Operating_Mode
/= Check_Syntax
895 ("first % pragma must be first line of file", Pragma_Sloc
);
899 Check_No_Identifier
(Arg1
);
901 if Arg_Count
= 1 then
902 if Num_SRef_Pragmas
(Current_Source_File
) = 0 then
904 ("file name required for first % pragma in file",
914 Check_Arg_Is_String_Literal
(Arg2
);
915 String_To_Name_Buffer
(Strval
(Expression
(Arg2
)));
918 if Num_SRef_Pragmas
(Current_Source_File
) > 0 then
919 if Fname
/= Full_Ref_Name
(Current_Source_File
) then
921 ("file name must be same in all % pragmas", Pragma_Sloc
);
927 if Nkind
(Expression
(Arg1
)) /= N_Integer_Literal
then
929 ("argument for pragma% must be integer literal",
930 Sloc
(Expression
(Arg1
)));
933 -- OK, this source reference pragma is effective, however, we
934 -- ignore it if it is not in the first unit in the multiple unit
935 -- case. This is because the only purpose in this case is to
936 -- provide source pragmas for subsequent use by gnatchop.
939 if Num_Library_Units
= 1 then
940 Register_Source_Ref_Pragma
942 Strip_Directory
(Fname
),
943 UI_To_Int
(Intval
(Expression
(Arg1
))),
944 Get_Physical_Line_Number
(Pragma_Sloc
) + 1);
947 end Source_Reference
;
949 -------------------------
950 -- Style_Checks (GNAT) --
951 -------------------------
953 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
955 -- This is processed by the parser since some of the style
956 -- checks take place during source scanning and parsing.
958 when Pragma_Style_Checks
=> Style_Checks
: declare
962 OK
: Boolean := True;
965 -- Two argument case is only for semantics
967 if Arg_Count
= 2 then
972 Check_No_Identifier
(Arg1
);
973 A
:= Expression
(Arg1
);
975 if Nkind
(A
) = N_String_Literal
then
979 Slen
: constant Natural := Natural (String_Length
(S
));
980 Options
: String (1 .. Slen
);
987 C
:= Get_String_Char
(S
, Pos
(J
));
989 if not In_Character_Range
(C
) then
995 Options
(J
) := Get_Character
(C
);
999 if not Ignore_Style_Checks_Pragmas
then
1000 Set_Style_Check_Options
(Options
, OK
, Ptr
);
1012 (Style_Msg_Buf
(1 .. Style_Msg_Len
),
1013 Sloc
(Expression
(Arg1
)) + Source_Ptr
(Ptr
));
1018 elsif Nkind
(A
) /= N_Identifier
then
1021 elsif Chars
(A
) = Name_All_Checks
then
1022 if not Ignore_Style_Checks_Pragmas
then
1024 Stylesw
.Set_GNAT_Style_Check_Options
;
1026 Stylesw
.Set_Default_Style_Check_Options
;
1030 elsif Chars
(A
) = Name_On
then
1031 if not Ignore_Style_Checks_Pragmas
then
1032 Style_Check
:= True;
1035 elsif Chars
(A
) = Name_Off
then
1036 if not Ignore_Style_Checks_Pragmas
then
1037 Style_Check
:= False;
1045 Error_Msg
("incorrect argument for pragma%", Sloc
(A
));
1051 -------------------------
1052 -- Suppress_All (GNAT) --
1053 -------------------------
1055 -- pragma Suppress_All
1057 -- This is a rather odd pragma, because other compilers allow it in
1058 -- strange places. DEC allows it at the end of units, and Rational
1059 -- allows it as a program unit pragma, when it would be more natural
1060 -- if it were a configuration pragma.
1062 -- Since the reason we provide this pragma is for compatibility with
1063 -- these other compilers, we want to accommodate these strange placement
1064 -- rules, and the easiest thing is simply to allow it anywhere in a
1065 -- unit. If this pragma appears anywhere within a unit, then the effect
1066 -- is as though a pragma Suppress (All_Checks) had appeared as the first
1067 -- line of the current file, i.e. as the first configuration pragma in
1068 -- the current unit.
1070 -- To get this effect, we set the flag Has_Pragma_Suppress_All in the
1071 -- compilation unit node for the current source file then in the last
1072 -- stage of parsing a file, if this flag is set, we materialize the
1073 -- Suppress (All_Checks) pragma, marked as not coming from Source.
1075 when Pragma_Suppress_All
=>
1076 Set_Has_Pragma_Suppress_All
(Cunit
(Current_Source_Unit
));
1078 ---------------------
1079 -- Warnings (GNAT) --
1080 ---------------------
1082 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
1084 -- DETAILS ::= On | Off
1085 -- DETAILS ::= On | Off, local_NAME
1086 -- DETAILS ::= static_string_EXPRESSION
1087 -- DETAILS ::= On | Off, static_string_EXPRESSION
1089 -- TOOL_NAME ::= GNAT | GNATProve
1091 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
1093 -- Note: If the first argument matches an allowed tool name, it is
1094 -- always considered to be a tool name, even if there is a string
1095 -- variable of that name.
1097 -- The one argument ON/OFF case is processed by the parser, since it may
1098 -- control parser warnings as well as semantic warnings, and in any case
1099 -- we want to be absolutely sure that the range in the warnings table is
1100 -- set well before any semantic analysis is performed. Note that we
1101 -- ignore this pragma if debug flag -gnatd.i is set.
1103 -- Also note that the "one argument" case may have two or three
1104 -- arguments if the first one is a tool name, and/or the last one is a
1107 when Pragma_Warnings
=> Warnings
: declare
1108 function First_Arg_Is_Matching_Tool_Name
return Boolean;
1109 -- Returns True if the first argument is a tool name matching the
1110 -- current tool being run.
1112 function Last_Arg
return Node_Id
;
1113 -- Returns the last argument
1115 function Last_Arg_Is_Reason
return Boolean;
1116 -- Returns True if the last argument is a reason argument
1118 function Get_Reason
return String_Id
;
1119 -- Analyzes Reason argument and returns corresponding String_Id
1120 -- value, or null if there is no Reason argument, or if the
1121 -- argument is not of the required form.
1123 -------------------------------------
1124 -- First_Arg_Is_Matching_Tool_Name --
1125 -------------------------------------
1127 function First_Arg_Is_Matching_Tool_Name
return Boolean is
1129 return Nkind
(Arg1
) = N_Identifier
1131 -- Return True if the tool name is GNAT, and we're not in
1132 -- GNATprove or CodePeer or ASIS mode...
1134 and then ((Chars
(Arg1
) = Name_Gnat
1136 (CodePeer_Mode
or GNATprove_Mode
or ASIS_Mode
))
1138 -- or if the tool name is GNATprove, and we're in GNATprove
1142 (Chars
(Arg1
) = Name_Gnatprove
1143 and then GNATprove_Mode
));
1144 end First_Arg_Is_Matching_Tool_Name
;
1150 function Get_Reason
return String_Id
is
1151 Arg
: constant Node_Id
:= Last_Arg
;
1153 if Last_Arg_Is_Reason
then
1155 Get_Reason_String
(Expression
(Arg
));
1158 return Null_String_Id
;
1166 function Last_Arg
return Node_Id
is
1170 if Arg_Count
= 1 then
1172 elsif Arg_Count
= 2 then
1174 elsif Arg_Count
= 3 then
1176 elsif Arg_Count
= 4 then
1177 Last_Arg
:= Next
(Arg3
);
1179 -- Illegal case, error issued in semantic analysis
1188 ------------------------
1189 -- Last_Arg_Is_Reason --
1190 ------------------------
1192 function Last_Arg_Is_Reason
return Boolean is
1193 Arg
: constant Node_Id
:= Last_Arg
;
1195 return Nkind
(Arg
) in N_Has_Chars
1196 and then Chars
(Arg
) = Name_Reason
;
1197 end Last_Arg_Is_Reason
;
1199 The_Arg
: Node_Id
; -- On/Off argument
1202 -- Start of processing for Warnings
1205 if not Debug_Flag_Dot_I
1206 and then (Arg_Count
= 1
1207 or else (Arg_Count
= 2
1208 and then (First_Arg_Is_Matching_Tool_Name
1210 Last_Arg_Is_Reason
))
1211 or else (Arg_Count
= 3
1212 and then First_Arg_Is_Matching_Tool_Name
1213 and then Last_Arg_Is_Reason
))
1215 if First_Arg_Is_Matching_Tool_Name
then
1221 Check_No_Identifier
(The_Arg
);
1222 Argx
:= Expression
(The_Arg
);
1224 if Nkind
(Argx
) = N_Identifier
then
1225 if Chars
(Argx
) = Name_On
then
1226 Set_Warnings_Mode_On
(Pragma_Sloc
);
1227 elsif Chars
(Argx
) = Name_Off
then
1228 Set_Warnings_Mode_Off
(Pragma_Sloc
, Get_Reason
);
1234 -----------------------------
1235 -- Wide_Character_Encoding --
1236 -----------------------------
1238 -- pragma Wide_Character_Encoding (IDENTIFIER | CHARACTER_LITERAL);
1240 -- This is processed by the parser, since the scanner is affected
1242 when Pragma_Wide_Character_Encoding
=> Wide_Character_Encoding
: declare
1246 Check_Arg_Count
(1);
1247 Check_No_Identifier
(Arg1
);
1248 A
:= Expression
(Arg1
);
1250 if Nkind
(A
) = N_Identifier
then
1251 Get_Name_String
(Chars
(A
));
1252 Wide_Character_Encoding_Method
:=
1253 Get_WC_Encoding_Method
(Name_Buffer
(1 .. Name_Len
));
1255 elsif Nkind
(A
) = N_Character_Literal
then
1257 R
: constant Char_Code
:=
1258 Char_Code
(UI_To_Int
(Char_Literal_Value
(A
)));
1260 if In_Character_Range
(R
) then
1261 Wide_Character_Encoding_Method
:=
1262 Get_WC_Encoding_Method
(Get_Character
(R
));
1264 raise Constraint_Error
;
1269 raise Constraint_Error
;
1272 Upper_Half_Encoding
:=
1273 Wide_Character_Encoding_Method
in
1274 WC_Upper_Half_Encoding_Method
;
1277 when Constraint_Error
=>
1278 Error_Msg_N
("invalid argument for pragma%", Arg1
);
1279 end Wide_Character_Encoding
;
1281 -----------------------
1282 -- All Other Pragmas --
1283 -----------------------
1285 -- For all other pragmas, checking and processing is handled
1286 -- entirely in Sem_Prag, and no further checking is done by Par.
1288 when Pragma_Abort_Defer |
1289 Pragma_Abstract_State |
1290 Pragma_Async_Readers |
1291 Pragma_Async_Writers |
1292 Pragma_Assertion_Policy |
1294 Pragma_Assume_No_Invalid_Values |
1295 Pragma_All_Calls_Remote |
1296 Pragma_Allow_Integer_Address |
1299 Pragma_Assert_And_Cut |
1300 Pragma_Asynchronous |
1302 Pragma_Atomic_Components |
1303 Pragma_Attach_Handler |
1304 Pragma_Attribute_Definition |
1306 Pragma_Check_Float_Overflow |
1308 Pragma_Check_Policy |
1309 Pragma_Compile_Time_Error |
1310 Pragma_Compile_Time_Warning |
1311 Pragma_Constant_After_Elaboration |
1312 Pragma_Contract_Cases |
1313 Pragma_Convention_Identifier |
1315 Pragma_CPP_Constructor |
1316 Pragma_CPP_Virtual |
1319 Pragma_C_Pass_By_Copy |
1321 Pragma_Common_Object |
1322 Pragma_Complete_Representation |
1323 Pragma_Complex_Representation |
1324 Pragma_Component_Alignment |
1327 Pragma_Debug_Policy |
1329 Pragma_Detect_Blocking |
1330 Pragma_Default_Initial_Condition |
1331 Pragma_Default_Scalar_Storage_Order |
1332 Pragma_Default_Storage_Pool |
1333 Pragma_Disable_Atomic_Synchronization |
1334 Pragma_Discard_Names |
1335 Pragma_Dispatching_Domain |
1336 Pragma_Effective_Reads |
1337 Pragma_Effective_Writes |
1340 Pragma_Elaborate_All |
1341 Pragma_Elaborate_Body |
1342 Pragma_Elaboration_Checks |
1343 Pragma_Enable_Atomic_Synchronization |
1345 Pragma_Export_Function |
1346 Pragma_Export_Object |
1347 Pragma_Export_Procedure |
1348 Pragma_Export_Value |
1349 Pragma_Export_Valued_Procedure |
1350 Pragma_Extend_System |
1351 Pragma_Extensions_Visible |
1353 Pragma_External_Name_Casing |
1354 Pragma_Favor_Top_Level |
1356 Pragma_Finalize_Storage_Only |
1360 Pragma_Implementation_Defined |
1361 Pragma_Implemented |
1362 Pragma_Implicit_Packing |
1364 Pragma_Import_Function |
1365 Pragma_Import_Object |
1366 Pragma_Import_Procedure |
1367 Pragma_Import_Valued_Procedure |
1368 Pragma_Independent |
1369 Pragma_Independent_Components |
1370 Pragma_Initial_Condition |
1371 Pragma_Initialize_Scalars |
1372 Pragma_Initializes |
1374 Pragma_Inline_Always |
1375 Pragma_Inline_Generic |
1376 Pragma_Inspection_Point |
1378 Pragma_Interface_Name |
1379 Pragma_Interrupt_Handler |
1380 Pragma_Interrupt_State |
1381 Pragma_Interrupt_Priority |
1386 Pragma_Linker_Alias |
1387 Pragma_Linker_Constructor |
1388 Pragma_Linker_Destructor |
1389 Pragma_Linker_Options |
1390 Pragma_Linker_Section |
1392 Pragma_Locking_Policy |
1393 Pragma_Loop_Invariant |
1394 Pragma_Loop_Optimize |
1395 Pragma_Loop_Variant |
1396 Pragma_Machine_Attribute |
1398 Pragma_Main_Storage |
1399 Pragma_Memory_Size |
1401 Pragma_No_Elaboration_Code_All |
1404 Pragma_No_Run_Time |
1405 Pragma_No_Strict_Aliasing |
1406 Pragma_No_Tagged_Streams |
1407 Pragma_Normalize_Scalars |
1408 Pragma_Obsolescent |
1411 Pragma_Optimize_Alignment |
1412 Pragma_Overflow_Mode |
1413 Pragma_Overriding_Renamings |
1416 Pragma_Partition_Elaboration_Policy |
1418 Pragma_Preelaborable_Initialization |
1420 Pragma_Prefix_Exception_Messages |
1421 Pragma_Persistent_BSS |
1423 Pragma_Postcondition |
1426 Pragma_Precondition |
1428 Pragma_Predicate_Failure |
1429 Pragma_Preelaborate |
1432 Pragma_Priority_Specific_Dispatching |
1434 Pragma_Profile_Warnings |
1435 Pragma_Propagate_Exceptions |
1436 Pragma_Provide_Shift_Operators |
1437 Pragma_Psect_Object |
1439 Pragma_Pure_Function |
1440 Pragma_Queuing_Policy |
1441 Pragma_Refined_Depends |
1442 Pragma_Refined_Global |
1443 Pragma_Refined_Post |
1444 Pragma_Refined_State |
1445 Pragma_Relative_Deadline |
1446 Pragma_Remote_Access_Type |
1447 Pragma_Remote_Call_Interface |
1448 Pragma_Remote_Types |
1449 Pragma_Restricted_Run_Time |
1453 Pragma_Share_Generic |
1455 Pragma_Shared_Passive |
1456 Pragma_Short_Circuit_And_Or |
1457 Pragma_Short_Descriptors |
1458 Pragma_Simple_Storage_Pool_Type |
1460 Pragma_Storage_Size |
1461 Pragma_Storage_Unit |
1462 Pragma_Static_Elaboration_Desired |
1463 Pragma_Stream_Convert |
1466 Pragma_Suppress_Debug_Info |
1467 Pragma_Suppress_Exception_Locations |
1468 Pragma_Suppress_Initialization |
1469 Pragma_System_Name |
1470 Pragma_Task_Dispatching_Policy |
1473 Pragma_Task_Storage |
1475 Pragma_Thread_Local_Storage |
1478 Pragma_Type_Invariant |
1479 Pragma_Type_Invariant_Class |
1480 Pragma_Unchecked_Union |
1481 Pragma_Unevaluated_Use_Of_Old |
1482 Pragma_Unimplemented_Unit |
1483 Pragma_Universal_Aliasing |
1484 Pragma_Universal_Data |
1486 Pragma_Unreferenced |
1487 Pragma_Unreferenced_Objects |
1488 Pragma_Unreserve_All_Interrupts |
1491 Pragma_Use_VADS_Size |
1493 Pragma_Volatile_Components |
1494 Pragma_Volatile_Full_Access |
1495 Pragma_Volatile_Function |
1496 Pragma_Warning_As_Error |
1497 Pragma_Weak_External |
1498 Pragma_Validity_Checks
=>
1501 --------------------
1502 -- Unknown_Pragma --
1503 --------------------
1505 -- Should be impossible, since we excluded this case earlier on
1507 when Unknown_Pragma
=>
1508 raise Program_Error
;
1514 --------------------
1515 -- Error Handling --
1516 --------------------
1519 when Error_Resync
=>