1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, 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 function Arg1
return Node_Id
;
57 function Arg2
return Node_Id
;
58 function Arg3
return Node_Id
;
59 -- Obtain specified Pragma_Argument_Association. It is allowable to call
60 -- the routine for the argument one past the last present argument, but
61 -- that is the only case in which a non-present argument can be referenced.
63 procedure Check_Arg_Count
(Required
: Int
);
64 -- Check argument count for pragma = Required. If not give error and raise
67 procedure Check_Arg_Is_String_Literal
(Arg
: Node_Id
);
68 -- Check the expression of the specified argument to make sure that it
69 -- is a string literal. If not give error and raise Error_Resync.
71 procedure Check_Arg_Is_On_Or_Off
(Arg
: Node_Id
);
72 -- Check the expression of the specified argument to make sure that it
73 -- is an identifier which is either ON or OFF, and if not, then issue
74 -- an error message and raise Error_Resync.
76 procedure Check_No_Identifier
(Arg
: Node_Id
);
77 -- Checks that the given argument does not have an identifier. If
78 -- an identifier is present, then an error message is issued, and
79 -- Error_Resync is raised.
81 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
82 -- Checks if the given argument has an identifier, and if so, requires
83 -- it to match the given identifier name. If there is a non-matching
84 -- identifier, then an error message is given and Error_Resync raised.
86 procedure Check_Required_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
87 -- Same as Check_Optional_Identifier, except that the name is required
88 -- to be present and to match the given Id value.
90 procedure Process_Restrictions_Or_Restriction_Warnings
;
91 -- Common processing for Restrictions and Restriction_Warnings pragmas.
92 -- For the most part, restrictions need not be processed at parse time,
93 -- since they only affect semantic processing. This routine handles the
94 -- exceptions as follows
96 -- No_Obsolescent_Features must be processed at parse time, since there
97 -- are some obsolescent features (e.g. character replacements) which are
98 -- handled at parse time.
100 -- SPARK must be processed at parse time, since this restriction controls
101 -- whether the scanner recognizes a spark HIDE directive formatted as an
102 -- Ada comment (and generates a Tok_SPARK_Hide token for the directive).
104 -- No_Dependence must be processed at parse time, since otherwise it gets
107 -- Note that we don't need to do full error checking for badly formed cases
108 -- of restrictions, since these will be caught during semantic analysis.
114 function Arg1
return Node_Id
is
116 return First
(Pragma_Argument_Associations
(Pragma_Node
));
123 function Arg2
return Node_Id
is
132 function Arg3
return Node_Id
is
137 ---------------------
138 -- Check_Arg_Count --
139 ---------------------
141 procedure Check_Arg_Count
(Required
: Int
) is
143 if Arg_Count
/= Required
then
144 Error_Msg
("wrong number of arguments for pragma%", Pragma_Sloc
);
149 ----------------------------
150 -- Check_Arg_Is_On_Or_Off --
151 ----------------------------
153 procedure Check_Arg_Is_On_Or_Off
(Arg
: Node_Id
) is
154 Argx
: constant Node_Id
:= Expression
(Arg
);
157 if Nkind
(Expression
(Arg
)) /= N_Identifier
158 or else (Chars
(Argx
) /= Name_On
160 Chars
(Argx
) /= Name_Off
)
162 Error_Msg_Name_2
:= Name_On
;
163 Error_Msg_Name_3
:= Name_Off
;
165 Error_Msg
("argument for pragma% must be% or%", Sloc
(Argx
));
168 end Check_Arg_Is_On_Or_Off
;
170 ---------------------------------
171 -- Check_Arg_Is_String_Literal --
172 ---------------------------------
174 procedure Check_Arg_Is_String_Literal
(Arg
: Node_Id
) is
176 if Nkind
(Expression
(Arg
)) /= N_String_Literal
then
178 ("argument for pragma% must be string literal",
179 Sloc
(Expression
(Arg
)));
182 end Check_Arg_Is_String_Literal
;
184 -------------------------
185 -- Check_No_Identifier --
186 -------------------------
188 procedure Check_No_Identifier
(Arg
: Node_Id
) is
190 if Chars
(Arg
) /= No_Name
then
191 Error_Msg_N
("pragma% does not permit named arguments", Arg
);
194 end Check_No_Identifier
;
196 -------------------------------
197 -- Check_Optional_Identifier --
198 -------------------------------
200 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
202 if Present
(Arg
) and then Chars
(Arg
) /= No_Name
then
203 if Chars
(Arg
) /= Id
then
204 Error_Msg_Name_2
:= Id
;
205 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
208 end Check_Optional_Identifier
;
210 -------------------------------
211 -- Check_Required_Identifier --
212 -------------------------------
214 procedure Check_Required_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
216 if Chars
(Arg
) /= Id
then
217 Error_Msg_Name_2
:= Id
;
218 Error_Msg_N
("pragma% argument must have identifier%", Arg
);
220 end Check_Required_Identifier
;
222 --------------------------------------------------
223 -- Process_Restrictions_Or_Restriction_Warnings --
224 --------------------------------------------------
226 procedure Process_Restrictions_Or_Restriction_Warnings
is
233 while Present
(Arg
) loop
235 Expr
:= Expression
(Arg
);
238 and then Nkind
(Expr
) = N_Identifier
240 case Get_Restriction_Id
(Chars
(Expr
)) is
241 when No_Obsolescent_Features
=>
242 Set_Restriction
(No_Obsolescent_Features
, Pragma_Node
);
243 Restriction_Warnings
(No_Obsolescent_Features
) :=
244 Prag_Id
= Pragma_Restriction_Warnings
;
247 Set_Restriction
(SPARK
, Pragma_Node
);
248 Restriction_Warnings
(SPARK
) :=
249 Prag_Id
= Pragma_Restriction_Warnings
;
255 elsif Id
= Name_No_Dependence
then
256 Set_Restriction_No_Dependence
258 Warn
=> Prag_Id
= Pragma_Restriction_Warnings
259 or else Treat_Restrictions_As_Warnings
);
264 end Process_Restrictions_Or_Restriction_Warnings
;
266 -- Start of processing for Prag
269 Error_Msg_Name_1
:= Prag_Name
;
271 -- Ignore unrecognized pragma. We let Sem post the warning for this, since
272 -- it is a semantic error, not a syntactic one (we have already checked
273 -- the syntax for the unrecognized pragma as required by (RM 2.8(11)).
275 if Prag_Id
= Unknown_Pragma
then
279 -- Count number of arguments. This loop also checks if any of the arguments
280 -- are Error, indicating a syntax error as they were parsed. If so, we
281 -- simply return, because we get into trouble with cascaded errors if we
282 -- try to perform our error checks on junk arguments.
286 if Present
(Pragma_Argument_Associations
(Pragma_Node
)) then
288 while Arg_Node
/= Empty
loop
289 Arg_Count
:= Arg_Count
+ 1;
291 if Expression
(Arg_Node
) = Error
then
299 -- Remaining processing is pragma dependent
307 -- This pragma must be processed at parse time, since we want to set
308 -- the Ada version properly at parse time to recognize the appropriate
309 -- Ada version syntax.
311 when Pragma_Ada_83
=>
312 Ada_Version
:= Ada_83
;
313 Ada_Version_Explicit
:= Ada_83
;
319 -- This pragma must be processed at parse time, since we want to set
320 -- the Ada version properly at parse time to recognize the appropriate
321 -- Ada version syntax.
323 when Pragma_Ada_95
=>
324 Ada_Version
:= Ada_95
;
325 Ada_Version_Explicit
:= Ada_95
;
327 ---------------------
328 -- Ada_05/Ada_2005 --
329 ---------------------
331 -- These pragmas must be processed at parse time, since we want to set
332 -- the Ada version properly at parse time to recognize the appropriate
333 -- Ada version syntax. However, it is only the zero argument form that
334 -- must be processed at parse time.
336 when Pragma_Ada_05 | Pragma_Ada_2005
=>
337 if Arg_Count
= 0 then
338 Ada_Version
:= Ada_2005
;
339 Ada_Version_Explicit
:= Ada_2005
;
342 ---------------------
343 -- Ada_12/Ada_2012 --
344 ---------------------
346 -- These pragmas must be processed at parse time, since we want to set
347 -- the Ada version properly at parse time to recognize the appropriate
348 -- Ada version syntax. However, it is only the zero argument form that
349 -- must be processed at parse time.
351 when Pragma_Ada_12 | Pragma_Ada_2012
=>
352 if Arg_Count
= 0 then
353 Ada_Version
:= Ada_2012
;
354 Ada_Version_Explicit
:= Ada_2012
;
361 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
364 Check_No_Identifier
(Arg1
);
366 if Arg_Count
= 2 then
367 Check_No_Identifier
(Arg2
);
372 -------------------------------
373 -- Extensions_Allowed (GNAT) --
374 -------------------------------
376 -- pragma Extensions_Allowed (Off | On)
378 -- The processing for pragma Extensions_Allowed must be done at
379 -- parse time, since extensions mode may affect what is accepted.
381 when Pragma_Extensions_Allowed
=>
383 Check_No_Identifier
(Arg1
);
384 Check_Arg_Is_On_Or_Off
(Arg1
);
386 if Chars
(Expression
(Arg1
)) = Name_On
then
387 Extensions_Allowed
:= True;
388 Ada_Version
:= Ada_2012
;
390 Extensions_Allowed
:= False;
391 Ada_Version
:= Ada_Version_Explicit
;
398 -- pragma List (Off | On)
400 -- The processing for pragma List must be done at parse time,
401 -- since a listing can be generated in parse only mode.
405 Check_No_Identifier
(Arg1
);
406 Check_Arg_Is_On_Or_Off
(Arg1
);
408 -- We unconditionally make a List_On entry for the pragma, so that
409 -- in the List (Off) case, the pragma will print even in a region
410 -- of code with listing turned off (this is required!)
412 List_Pragmas
.Increment_Last
;
413 List_Pragmas
.Table
(List_Pragmas
.Last
) :=
414 (Ptyp
=> List_On
, Ploc
=> Sloc
(Pragma_Node
));
416 -- Now generate the list off entry for pragma List (Off)
418 if Chars
(Expression
(Arg1
)) = Name_Off
then
419 List_Pragmas
.Increment_Last
;
420 List_Pragmas
.Table
(List_Pragmas
.Last
) :=
421 (Ptyp
=> List_Off
, Ploc
=> Semi
);
430 -- Processing for this pragma must be done at parse time, since a
431 -- listing can be generated in parse only mode with semantics off.
435 List_Pragmas
.Increment_Last
;
436 List_Pragmas
.Table
(List_Pragmas
.Last
) := (Page
, Semi
);
442 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
445 -- restriction_IDENTIFIER
446 -- | restriction_parameter_IDENTIFIER => EXPRESSION
448 -- We process the case of No_Obsolescent_Features, since this has
449 -- a syntactic effect that we need to detect at parse time (the use
450 -- of replacement characters such as colon for pound sign).
452 when Pragma_Restrictions
=>
453 Process_Restrictions_Or_Restriction_Warnings
;
455 --------------------------
456 -- Restriction_Warnings --
457 --------------------------
459 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
462 -- restriction_IDENTIFIER
463 -- | restriction_parameter_IDENTIFIER => EXPRESSION
465 -- See above comment for pragma Restrictions
467 when Pragma_Restriction_Warnings
=>
468 Process_Restrictions_Or_Restriction_Warnings
;
470 ----------------------------------------------------------
471 -- Source_File_Name and Source_File_Name_Project (GNAT) --
472 ----------------------------------------------------------
474 -- These two pragmas have the same syntax and semantics.
475 -- There are five forms of these pragmas:
477 -- pragma Source_File_Name[_Project] (
478 -- [UNIT_NAME =>] unit_NAME,
479 -- BODY_FILE_NAME => STRING_LITERAL
480 -- [, [INDEX =>] INTEGER_LITERAL]);
482 -- pragma Source_File_Name[_Project] (
483 -- [UNIT_NAME =>] unit_NAME,
484 -- SPEC_FILE_NAME => STRING_LITERAL
485 -- [, [INDEX =>] INTEGER_LITERAL]);
487 -- pragma Source_File_Name[_Project] (
488 -- BODY_FILE_NAME => STRING_LITERAL
489 -- [, DOT_REPLACEMENT => STRING_LITERAL]
490 -- [, CASING => CASING_SPEC]);
492 -- pragma Source_File_Name[_Project] (
493 -- SPEC_FILE_NAME => STRING_LITERAL
494 -- [, DOT_REPLACEMENT => STRING_LITERAL]
495 -- [, CASING => CASING_SPEC]);
497 -- pragma Source_File_Name[_Project] (
498 -- SUBUNIT_FILE_NAME => STRING_LITERAL
499 -- [, DOT_REPLACEMENT => STRING_LITERAL]
500 -- [, CASING => CASING_SPEC]);
502 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
504 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
505 -- Source_File_Name (SFN), however their usage is exclusive:
506 -- SFN can only be used when no project file is used, while
507 -- SFNP can only be used when a project file is used.
509 -- The Project Manager produces a configuration pragmas file that
510 -- is communicated to the compiler with -gnatec switch. This file
511 -- contains only SFNP pragmas (at least two for the default naming
512 -- scheme. As this configuration pragmas file is always the first
513 -- processed by the compiler, it prevents the use of pragmas SFN in
514 -- other config files when a project file is in use.
516 -- Note: we process this during parsing, since we need to have the
517 -- source file names set well before the semantic analysis starts,
518 -- since we load the spec and with'ed packages before analysis.
520 when Pragma_Source_File_Name | Pragma_Source_File_Name_Project
=>
521 Source_File_Name
: declare
522 Unam
: Unit_Name_Type
;
532 function Get_Fname
(Arg
: Node_Id
) return File_Name_Type
;
533 -- Process file name from unit name form of pragma
535 function Get_String_Argument
(Arg
: Node_Id
) return String_Ptr
;
536 -- Process string literal value from argument
538 procedure Process_Casing
(Arg
: Node_Id
);
539 -- Process Casing argument of pattern form of pragma
541 procedure Process_Dot_Replacement
(Arg
: Node_Id
);
542 -- Process Dot_Replacement argument of pattern form of pragma
548 function Get_Fname
(Arg
: Node_Id
) return File_Name_Type
is
550 String_To_Name_Buffer
(Strval
(Expression
(Arg
)));
552 for J
in 1 .. Name_Len
loop
553 if Is_Directory_Separator
(Name_Buffer
(J
)) then
555 ("directory separator character not allowed",
556 Sloc
(Expression
(Arg
)) + Source_Ptr
(J
));
563 -------------------------
564 -- Get_String_Argument --
565 -------------------------
567 function Get_String_Argument
(Arg
: Node_Id
) return String_Ptr
is
571 if Nkind
(Expression
(Arg
)) /= N_String_Literal
573 Nkind
(Expression
(Arg
)) /= N_Operator_Symbol
576 ("argument for pragma% must be string literal", Arg
);
580 Str
:= Strval
(Expression
(Arg
));
582 -- Check string has no wide chars
584 for J
in 1 .. String_Length
(Str
) loop
585 if Get_String_Char
(Str
, J
) > 255 then
587 ("wide character not allowed in pattern for pragma%",
588 Sloc
(Expression
(Arg2
)) + Text_Ptr
(J
) - 1);
594 String_To_Name_Buffer
(Str
);
595 return new String'(Name_Buffer (1 .. Name_Len));
596 end Get_String_Argument;
602 procedure Process_Casing (Arg : Node_Id) is
603 Expr : constant Node_Id := Expression (Arg);
606 Check_Required_Identifier (Arg, Name_Casing);
608 if Nkind (Expr) = N_Identifier then
609 if Chars (Expr) = Name_Lowercase then
610 Cas := All_Lower_Case;
612 elsif Chars (Expr) = Name_Uppercase then
613 Cas := All_Upper_Case;
615 elsif Chars (Expr) = Name_Mixedcase then
622 ("Casing argument for pragma% must be " &
623 "one of Mixedcase, Lowercase, Uppercase",
627 -----------------------------
628 -- Process_Dot_Replacement --
629 -----------------------------
631 procedure Process_Dot_Replacement (Arg : Node_Id) is
633 Check_Required_Identifier (Arg, Name_Dot_Replacement);
634 Dot := Get_String_Argument (Arg);
635 end Process_Dot_Replacement;
637 -- Start of processing for Source_File_Name and
638 -- Source_File_Name_Project pragmas.
641 if Prag_Id = Pragma_Source_File_Name then
642 if Project_File_In_Use = In_Use then
644 ("pragma Source_File_Name cannot be used " &
645 "with a project file", Pragma_Sloc);
648 Project_File_In_Use := Not_In_Use;
652 if Project_File_In_Use = Not_In_Use then
654 ("pragma Source_File_Name_Project should only be used " &
655 "with a project file", Pragma_Sloc);
657 Project_File_In_Use := In_Use;
661 -- We permit from 1 to 3 arguments
663 if Arg_Count not in 1 .. 3 then
667 Expr1 := Expression (Arg1);
669 -- If first argument is identifier or selected component, then
670 -- we have the specific file case of the Source_File_Name pragma,
671 -- and the first argument is a unit name.
673 if Nkind (Expr1) = N_Identifier
675 (Nkind (Expr1) = N_Selected_Component
677 Nkind (Selector_Name (Expr1)) = N_Identifier)
679 if Nkind (Expr1) = N_Identifier
680 and then Chars (Expr1) = Name_System
683 ("pragma Source_File_Name may not be used for System",
688 -- Process index argument if present
690 if Arg_Count = 3 then
691 Expr := Expression (Arg3);
693 if Nkind (Expr) /= N_Integer_Literal
694 or else not UI_Is_In_Int_Range (Intval (Expr))
695 or else Intval (Expr) > 999
696 or else Intval (Expr) <= 0
699 ("pragma% index must be integer literal" &
700 " in range 1 .. 999", Sloc (Expr));
703 Index := UI_To_Int (Intval (Expr));
706 -- No index argument present
713 Check_Optional_Identifier (Arg1, Name_Unit_Name);
714 Unam := Get_Unit_Name (Expr1);
716 Check_Arg_Is_String_Literal (Arg2);
718 if Chars (Arg2) = Name_Spec_File_Name then
720 (Get_Spec_Name (Unam), Get_Fname (Arg2), Index);
722 elsif Chars (Arg2) = Name_Body_File_Name then
724 (Unam, Get_Fname (Arg2), Index);
728 ("pragma% argument has incorrect identifier", Arg2);
732 -- If the first argument is not an identifier, then we must have
733 -- the pattern form of the pragma, and the first argument must be
734 -- the pattern string with an appropriate name.
737 if Chars (Arg1) = Name_Spec_File_Name then
740 elsif Chars (Arg1) = Name_Body_File_Name then
743 elsif Chars (Arg1) = Name_Subunit_File_Name then
746 elsif Chars (Arg1) = Name_Unit_Name then
748 ("Unit_Name parameter for pragma% must be an identifier",
754 ("pragma% argument has incorrect identifier", Arg1);
758 Pat := Get_String_Argument (Arg1);
760 -- Check pattern has exactly one asterisk
763 for J in Pat'Range loop
764 if Pat (J) = '*' then
771 ("file name pattern must have exactly one * character",
776 -- Set defaults for Casing and Dot_Separator parameters
778 Cas := All_Lower_Case;
779 Dot := new String'(".");
781 -- Process second and third arguments if present
783 if Arg_Count
> 1 then
784 if Chars
(Arg2
) = Name_Casing
then
785 Process_Casing
(Arg2
);
787 if Arg_Count
= 3 then
788 Process_Dot_Replacement
(Arg3
);
792 Process_Dot_Replacement
(Arg2
);
794 if Arg_Count
= 3 then
795 Process_Casing
(Arg3
);
800 Set_File_Name_Pattern
(Pat
, Typ
, Dot
, Cas
);
802 end Source_File_Name
;
804 -----------------------------
805 -- Source_Reference (GNAT) --
806 -----------------------------
808 -- pragma Source_Reference
809 -- (INTEGER_LITERAL [, STRING_LITERAL] );
811 -- Processing for this pragma must be done at parse time, since error
812 -- messages needing the proper line numbers can be generated in parse
813 -- only mode with semantic checking turned off, and indeed we usually
814 -- turn off semantic checking anyway if any parse errors are found.
816 when Pragma_Source_Reference
=> Source_Reference
: declare
817 Fname
: File_Name_Type
;
820 if Arg_Count
/= 1 then
822 Check_No_Identifier
(Arg2
);
825 -- Check that this is first line of file. We skip this test if
826 -- we are in syntax check only mode, since we may be dealing with
827 -- multiple compilation units.
829 if Get_Physical_Line_Number
(Pragma_Sloc
) /= 1
830 and then Num_SRef_Pragmas
(Current_Source_File
) = 0
831 and then Operating_Mode
/= Check_Syntax
834 ("first % pragma must be first line of file", Pragma_Sloc
);
838 Check_No_Identifier
(Arg1
);
840 if Arg_Count
= 1 then
841 if Num_SRef_Pragmas
(Current_Source_File
) = 0 then
843 ("file name required for first % pragma in file",
853 Check_Arg_Is_String_Literal
(Arg2
);
854 String_To_Name_Buffer
(Strval
(Expression
(Arg2
)));
857 if Num_SRef_Pragmas
(Current_Source_File
) > 0 then
858 if Fname
/= Full_Ref_Name
(Current_Source_File
) then
860 ("file name must be same in all % pragmas", Pragma_Sloc
);
866 if Nkind
(Expression
(Arg1
)) /= N_Integer_Literal
then
868 ("argument for pragma% must be integer literal",
869 Sloc
(Expression
(Arg1
)));
872 -- OK, this source reference pragma is effective, however, we
873 -- ignore it if it is not in the first unit in the multiple unit
874 -- case. This is because the only purpose in this case is to
875 -- provide source pragmas for subsequent use by gnatchop.
878 if Num_Library_Units
= 1 then
879 Register_Source_Ref_Pragma
881 Strip_Directory
(Fname
),
882 UI_To_Int
(Intval
(Expression
(Arg1
))),
883 Get_Physical_Line_Number
(Pragma_Sloc
) + 1);
886 end Source_Reference
;
888 -------------------------
889 -- Style_Checks (GNAT) --
890 -------------------------
892 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
894 -- This is processed by the parser since some of the style
895 -- checks take place during source scanning and parsing.
897 when Pragma_Style_Checks
=> Style_Checks
: declare
901 OK
: Boolean := True;
904 -- Two argument case is only for semantics
906 if Arg_Count
= 2 then
911 Check_No_Identifier
(Arg1
);
912 A
:= Expression
(Arg1
);
914 if Nkind
(A
) = N_String_Literal
then
918 Slen
: constant Natural := Natural (String_Length
(S
));
919 Options
: String (1 .. Slen
);
926 C
:= Get_String_Char
(S
, Int
(J
));
928 if not In_Character_Range
(C
) then
934 Options
(J
) := Get_Character
(C
);
938 Set_Style_Check_Options
(Options
, OK
, Ptr
);
948 (Style_Msg_Buf
(1 .. Style_Msg_Len
),
949 Sloc
(Expression
(Arg1
)) + Source_Ptr
(Ptr
));
954 elsif Nkind
(A
) /= N_Identifier
then
957 elsif Chars
(A
) = Name_All_Checks
then
959 Stylesw
.Set_GNAT_Style_Check_Options
;
961 Stylesw
.Set_Default_Style_Check_Options
;
964 elsif Chars
(A
) = Name_On
then
967 elsif Chars
(A
) = Name_Off
then
968 Style_Check
:= False;
975 Error_Msg
("incorrect argument for pragma%", Sloc
(A
));
981 -------------------------
982 -- Suppress_All (GNAT) --
983 -------------------------
985 -- pragma Suppress_All
987 -- This is a rather odd pragma, because other compilers allow it in
988 -- strange places. DEC allows it at the end of units, and Rational
989 -- allows it as a program unit pragma, when it would be more natural
990 -- if it were a configuration pragma.
992 -- Since the reason we provide this pragma is for compatibility with
993 -- these other compilers, we want to accommodate these strange placement
994 -- rules, and the easiest thing is simply to allow it anywhere in a
995 -- unit. If this pragma appears anywhere within a unit, then the effect
996 -- is as though a pragma Suppress (All_Checks) had appeared as the first
997 -- line of the current file, i.e. as the first configuration pragma in
1000 -- To get this effect, we set the flag Has_Pragma_Suppress_All in the
1001 -- compilation unit node for the current source file then in the last
1002 -- stage of parsing a file, if this flag is set, we materialize the
1003 -- Suppress (All_Checks) pragma, marked as not coming from Source.
1005 when Pragma_Suppress_All
=>
1006 Set_Has_Pragma_Suppress_All
(Cunit
(Current_Source_Unit
));
1008 ---------------------
1009 -- Warnings (GNAT) --
1010 ---------------------
1012 -- pragma Warnings (On | Off);
1013 -- pragma Warnings (On | Off, LOCAL_NAME);
1014 -- pragma Warnings (static_string_EXPRESSION);
1015 -- pragma Warnings (On | Off, static_string_EXPRESSION);
1017 -- The one argument ON/OFF case is processed by the parser, since it may
1018 -- control parser warnings as well as semantic warnings, and in any case
1019 -- we want to be absolutely sure that the range in the warnings table is
1020 -- set well before any semantic analysis is performed. Note that we
1021 -- ignore this pragma if debug flag -gnatd.i is set.
1023 when Pragma_Warnings
=>
1024 if Arg_Count
= 1 and then not Debug_Flag_Dot_I
then
1025 Check_No_Identifier
(Arg1
);
1028 Argx
: constant Node_Id
:= Expression
(Arg1
);
1030 if Nkind
(Argx
) = N_Identifier
then
1031 if Chars
(Argx
) = Name_On
then
1032 Set_Warnings_Mode_On
(Pragma_Sloc
);
1033 elsif Chars
(Argx
) = Name_Off
then
1034 Set_Warnings_Mode_Off
(Pragma_Sloc
);
1040 -----------------------------
1041 -- Wide_Character_Encoding --
1042 -----------------------------
1044 -- pragma Wide_Character_Encoding (IDENTIFIER | CHARACTER_LITERAL);
1046 -- This is processed by the parser, since the scanner is affected
1048 when Pragma_Wide_Character_Encoding
=> Wide_Character_Encoding
: declare
1052 Check_Arg_Count
(1);
1053 Check_No_Identifier
(Arg1
);
1054 A
:= Expression
(Arg1
);
1056 if Nkind
(A
) = N_Identifier
then
1057 Get_Name_String
(Chars
(A
));
1058 Wide_Character_Encoding_Method
:=
1059 Get_WC_Encoding_Method
(Name_Buffer
(1 .. Name_Len
));
1061 elsif Nkind
(A
) = N_Character_Literal
then
1063 R
: constant Char_Code
:=
1064 Char_Code
(UI_To_Int
(Char_Literal_Value
(A
)));
1066 if In_Character_Range
(R
) then
1067 Wide_Character_Encoding_Method
:=
1068 Get_WC_Encoding_Method
(Get_Character
(R
));
1070 raise Constraint_Error
;
1075 raise Constraint_Error
;
1078 Upper_Half_Encoding
:=
1079 Wide_Character_Encoding_Method
in
1080 WC_Upper_Half_Encoding_Method
;
1083 when Constraint_Error
=>
1084 Error_Msg_N
("invalid argument for pragma%", Arg1
);
1085 end Wide_Character_Encoding
;
1087 -----------------------
1088 -- All Other Pragmas --
1089 -----------------------
1091 -- For all other pragmas, checking and processing is handled
1092 -- entirely in Sem_Prag, and no further checking is done by Par.
1094 when Pragma_Abort_Defer |
1095 Pragma_Assertion_Policy |
1096 Pragma_Assume_No_Invalid_Values |
1098 Pragma_All_Calls_Remote |
1101 Pragma_Asynchronous |
1103 Pragma_Atomic_Components |
1104 Pragma_Attach_Handler |
1107 Pragma_Check_Policy |
1108 Pragma_CIL_Constructor |
1109 Pragma_Compile_Time_Error |
1110 Pragma_Compile_Time_Warning |
1111 Pragma_Compiler_Unit |
1112 Pragma_Contract_Case |
1113 Pragma_Convention_Identifier |
1115 Pragma_CPP_Constructor |
1116 Pragma_CPP_Virtual |
1119 Pragma_C_Pass_By_Copy |
1121 Pragma_Common_Object |
1122 Pragma_Complete_Representation |
1123 Pragma_Complex_Representation |
1124 Pragma_Component_Alignment |
1127 Pragma_Debug_Policy |
1128 Pragma_Detect_Blocking |
1129 Pragma_Default_Storage_Pool |
1130 Pragma_Disable_Atomic_Synchronization |
1131 Pragma_Discard_Names |
1132 Pragma_Dispatching_Domain |
1135 Pragma_Elaborate_All |
1136 Pragma_Elaborate_Body |
1137 Pragma_Elaboration_Checks |
1138 Pragma_Enable_Atomic_Synchronization |
1140 Pragma_Export_Exception |
1141 Pragma_Export_Function |
1142 Pragma_Export_Object |
1143 Pragma_Export_Procedure |
1144 Pragma_Export_Value |
1145 Pragma_Export_Valued_Procedure |
1146 Pragma_Extend_System |
1148 Pragma_External_Name_Casing |
1149 Pragma_Favor_Top_Level |
1151 Pragma_Finalize_Storage_Only |
1152 Pragma_Float_Representation |
1154 Pragma_Implementation_Defined |
1155 Pragma_Implemented |
1156 Pragma_Implicit_Packing |
1158 Pragma_Import_Exception |
1159 Pragma_Import_Function |
1160 Pragma_Import_Object |
1161 Pragma_Import_Procedure |
1162 Pragma_Import_Valued_Procedure |
1163 Pragma_Independent |
1164 Pragma_Independent_Components |
1165 Pragma_Initialize_Scalars |
1167 Pragma_Inline_Always |
1168 Pragma_Inline_Generic |
1169 Pragma_Inspection_Point |
1171 Pragma_Interface_Name |
1172 Pragma_Interrupt_Handler |
1173 Pragma_Interrupt_State |
1174 Pragma_Interrupt_Priority |
1176 Pragma_Java_Constructor |
1177 Pragma_Java_Interface |
1181 Pragma_Linker_Alias |
1182 Pragma_Linker_Constructor |
1183 Pragma_Linker_Destructor |
1184 Pragma_Linker_Options |
1185 Pragma_Linker_Section |
1187 Pragma_Locking_Policy |
1189 Pragma_Machine_Attribute |
1191 Pragma_Main_Storage |
1192 Pragma_Memory_Size |
1195 Pragma_No_Run_Time |
1196 Pragma_No_Strict_Aliasing |
1197 Pragma_Normalize_Scalars |
1198 Pragma_Obsolescent |
1201 Pragma_Optimize_Alignment |
1204 Pragma_Preelaborable_Initialization |
1206 Pragma_Persistent_BSS |
1207 Pragma_Postcondition |
1208 Pragma_Precondition |
1210 Pragma_Preelaborate |
1211 Pragma_Preelaborate_05 |
1213 Pragma_Priority_Specific_Dispatching |
1215 Pragma_Profile_Warnings |
1216 Pragma_Propagate_Exceptions |
1217 Pragma_Psect_Object |
1221 Pragma_Pure_Function |
1222 Pragma_Queuing_Policy |
1223 Pragma_Relative_Deadline |
1224 Pragma_Remote_Access_Type |
1225 Pragma_Remote_Call_Interface |
1226 Pragma_Remote_Types |
1227 Pragma_Restricted_Run_Time |
1230 Pragma_Share_Generic |
1232 Pragma_Shared_Passive |
1233 Pragma_Short_Circuit_And_Or |
1234 Pragma_Short_Descriptors |
1235 Pragma_Simple_Storage_Pool_Type |
1236 Pragma_Storage_Size |
1237 Pragma_Storage_Unit |
1238 Pragma_Static_Elaboration_Desired |
1239 Pragma_Stream_Convert |
1242 Pragma_Suppress_Debug_Info |
1243 Pragma_Suppress_Exception_Locations |
1244 Pragma_Suppress_Initialization |
1245 Pragma_System_Name |
1246 Pragma_Task_Dispatching_Policy |
1249 Pragma_Task_Storage |
1251 Pragma_Thread_Local_Storage |
1254 Pragma_Unchecked_Union |
1255 Pragma_Unimplemented_Unit |
1256 Pragma_Universal_Aliasing |
1257 Pragma_Universal_Data |
1259 Pragma_Unreferenced |
1260 Pragma_Unreferenced_Objects |
1261 Pragma_Unreserve_All_Interrupts |
1263 Pragma_Use_VADS_Size |
1265 Pragma_Volatile_Components |
1266 Pragma_Weak_External |
1267 Pragma_Validity_Checks
=>
1270 --------------------
1271 -- Unknown_Pragma --
1272 --------------------
1274 -- Should be impossible, since we excluded this case earlier on
1276 when Unknown_Pragma
=>
1277 raise Program_Error
;
1283 --------------------
1284 -- Error Handling --
1285 --------------------
1288 when Error_Resync
=>