PR middle-end/61455
[official-gcc.git] / gcc / ada / par-prag.adb
blobe0a71c80e0d9cfa413132b07e6a3de138f72db7e
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P A R . P R A G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
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;
43 separate (Par)
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);
49 Arg_Count : Nat;
50 Arg_Node : Node_Id;
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
65 -- Error_Resync.
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
105 -- handled too late.
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.
110 ----------
111 -- Arg1 --
112 ----------
114 function Arg1 return Node_Id is
115 begin
116 return First (Pragma_Argument_Associations (Pragma_Node));
117 end Arg1;
119 ----------
120 -- Arg2 --
121 ----------
123 function Arg2 return Node_Id is
124 begin
125 return Next (Arg1);
126 end Arg2;
128 ----------
129 -- Arg3 --
130 ----------
132 function Arg3 return Node_Id is
133 begin
134 return Next (Arg2);
135 end Arg3;
137 ---------------------
138 -- Check_Arg_Count --
139 ---------------------
141 procedure Check_Arg_Count (Required : Int) is
142 begin
143 if Arg_Count /= Required then
144 Error_Msg ("wrong number of arguments for pragma%", Pragma_Sloc);
145 raise Error_Resync;
146 end if;
147 end Check_Arg_Count;
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);
156 begin
157 if Nkind (Expression (Arg)) /= N_Identifier
158 or else not Nam_In (Chars (Argx), Name_On, Name_Off)
159 then
160 Error_Msg_Name_2 := Name_On;
161 Error_Msg_Name_3 := Name_Off;
163 Error_Msg ("argument for pragma% must be% or%", Sloc (Argx));
164 raise Error_Resync;
165 end if;
166 end Check_Arg_Is_On_Or_Off;
168 ---------------------------------
169 -- Check_Arg_Is_String_Literal --
170 ---------------------------------
172 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
173 begin
174 if Nkind (Expression (Arg)) /= N_String_Literal then
175 Error_Msg
176 ("argument for pragma% must be string literal",
177 Sloc (Expression (Arg)));
178 raise Error_Resync;
179 end if;
180 end Check_Arg_Is_String_Literal;
182 -------------------------
183 -- Check_No_Identifier --
184 -------------------------
186 procedure Check_No_Identifier (Arg : Node_Id) is
187 begin
188 if Chars (Arg) /= No_Name then
189 Error_Msg_N ("pragma% does not permit named arguments", Arg);
190 raise Error_Resync;
191 end if;
192 end Check_No_Identifier;
194 -------------------------------
195 -- Check_Optional_Identifier --
196 -------------------------------
198 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
199 begin
200 if Present (Arg) and then Chars (Arg) /= No_Name then
201 if Chars (Arg) /= Id then
202 Error_Msg_Name_2 := Id;
203 Error_Msg_N ("pragma% argument expects identifier%", Arg);
204 end if;
205 end if;
206 end Check_Optional_Identifier;
208 -------------------------------
209 -- Check_Required_Identifier --
210 -------------------------------
212 procedure Check_Required_Identifier (Arg : Node_Id; Id : Name_Id) is
213 begin
214 if Chars (Arg) /= Id then
215 Error_Msg_Name_2 := Id;
216 Error_Msg_N ("pragma% argument must have identifier%", Arg);
217 end if;
218 end Check_Required_Identifier;
220 --------------------------------------------------
221 -- Process_Restrictions_Or_Restriction_Warnings --
222 --------------------------------------------------
224 procedure Process_Restrictions_Or_Restriction_Warnings is
225 Arg : Node_Id;
226 Id : Name_Id;
227 Expr : Node_Id;
229 begin
230 Arg := Arg1;
231 while Present (Arg) loop
232 Id := Chars (Arg);
233 Expr := Expression (Arg);
235 if Id = No_Name and then Nkind (Expr) = N_Identifier then
236 case Chars (Expr) is
237 when Name_No_Obsolescent_Features =>
238 Set_Restriction (No_Obsolescent_Features, Pragma_Node);
239 Restriction_Warnings (No_Obsolescent_Features) :=
240 Prag_Id = Pragma_Restriction_Warnings;
242 when Name_SPARK | Name_SPARK_05 =>
243 Set_Restriction (SPARK_05, Pragma_Node);
244 Restriction_Warnings (SPARK_05) :=
245 Prag_Id = Pragma_Restriction_Warnings;
247 when others =>
248 null;
249 end case;
251 elsif Id = Name_No_Dependence then
252 Set_Restriction_No_Dependence
253 (Unit => Expr,
254 Warn => Prag_Id = Pragma_Restriction_Warnings
255 or else Treat_Restrictions_As_Warnings);
256 end if;
258 Next (Arg);
259 end loop;
260 end Process_Restrictions_Or_Restriction_Warnings;
262 -- Start of processing for Prag
264 begin
265 Error_Msg_Name_1 := Prag_Name;
267 -- Ignore unrecognized pragma. We let Sem post the warning for this, since
268 -- it is a semantic error, not a syntactic one (we have already checked
269 -- the syntax for the unrecognized pragma as required by (RM 2.8(11)).
271 if Prag_Id = Unknown_Pragma then
272 return Pragma_Node;
273 end if;
275 -- Count number of arguments. This loop also checks if any of the arguments
276 -- are Error, indicating a syntax error as they were parsed. If so, we
277 -- simply return, because we get into trouble with cascaded errors if we
278 -- try to perform our error checks on junk arguments.
280 Arg_Count := 0;
282 if Present (Pragma_Argument_Associations (Pragma_Node)) then
283 Arg_Node := Arg1;
284 while Arg_Node /= Empty loop
285 Arg_Count := Arg_Count + 1;
287 if Expression (Arg_Node) = Error then
288 return Error;
289 end if;
291 Next (Arg_Node);
292 end loop;
293 end if;
295 -- Remaining processing is pragma dependent
297 case Prag_Id is
299 ------------
300 -- Ada_83 --
301 ------------
303 -- This pragma must be processed at parse time, since we want to set
304 -- the Ada version properly at parse time to recognize the appropriate
305 -- Ada version syntax.
307 when Pragma_Ada_83 =>
308 Ada_Version := Ada_83;
309 Ada_Version_Explicit := Ada_83;
310 Ada_Version_Pragma := Pragma_Node;
312 ------------
313 -- Ada_95 --
314 ------------
316 -- This pragma must be processed at parse time, since we want to set
317 -- the Ada version properly at parse time to recognize the appropriate
318 -- Ada version syntax.
320 when Pragma_Ada_95 =>
321 Ada_Version := Ada_95;
322 Ada_Version_Explicit := Ada_95;
323 Ada_Version_Pragma := Pragma_Node;
325 ---------------------
326 -- Ada_05/Ada_2005 --
327 ---------------------
329 -- These pragmas must be processed at parse time, since we want to set
330 -- the Ada version properly at parse time to recognize the appropriate
331 -- Ada version syntax. However, it is only the zero argument form that
332 -- must be processed at parse time.
334 when Pragma_Ada_05 | Pragma_Ada_2005 =>
335 if Arg_Count = 0 then
336 Ada_Version := Ada_2005;
337 Ada_Version_Explicit := Ada_2005;
338 Ada_Version_Pragma := Pragma_Node;
339 end if;
341 ---------------------
342 -- Ada_12/Ada_2012 --
343 ---------------------
345 -- These pragmas must be processed at parse time, since we want to set
346 -- the Ada version properly at parse time to recognize the appropriate
347 -- Ada version syntax. However, it is only the zero argument form that
348 -- must be processed at parse time.
350 when Pragma_Ada_12 | Pragma_Ada_2012 =>
351 if Arg_Count = 0 then
352 Ada_Version := Ada_2012;
353 Ada_Version_Explicit := Ada_2012;
354 Ada_Version_Pragma := Pragma_Node;
355 end if;
357 ---------------------------
358 -- Compiler_Unit_Warning --
359 ---------------------------
361 -- This pragma must be processed at parse time, since the resulting
362 -- status may be tested during the parsing of the program.
364 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning =>
365 Check_Arg_Count (0);
367 -- Only recognized in main unit
369 if Current_Source_Unit = Main_Unit then
370 Compiler_Unit := True;
371 end if;
373 -----------
374 -- Debug --
375 -----------
377 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
379 when Pragma_Debug =>
380 Check_No_Identifier (Arg1);
382 if Arg_Count = 2 then
383 Check_No_Identifier (Arg2);
384 else
385 Check_Arg_Count (1);
386 end if;
388 -------------------------------
389 -- Extensions_Allowed (GNAT) --
390 -------------------------------
392 -- pragma Extensions_Allowed (Off | On)
394 -- The processing for pragma Extensions_Allowed must be done at
395 -- parse time, since extensions mode may affect what is accepted.
397 when Pragma_Extensions_Allowed =>
398 Check_Arg_Count (1);
399 Check_No_Identifier (Arg1);
400 Check_Arg_Is_On_Or_Off (Arg1);
402 if Chars (Expression (Arg1)) = Name_On then
403 Extensions_Allowed := True;
404 Ada_Version := Ada_2012;
405 else
406 Extensions_Allowed := False;
407 Ada_Version := Ada_Version_Explicit;
408 end if;
410 ----------------
411 -- List (2.8) --
412 ----------------
414 -- pragma List (Off | On)
416 -- The processing for pragma List must be done at parse time,
417 -- since a listing can be generated in parse only mode.
419 when Pragma_List =>
420 Check_Arg_Count (1);
421 Check_No_Identifier (Arg1);
422 Check_Arg_Is_On_Or_Off (Arg1);
424 -- We unconditionally make a List_On entry for the pragma, so that
425 -- in the List (Off) case, the pragma will print even in a region
426 -- of code with listing turned off (this is required).
428 List_Pragmas.Increment_Last;
429 List_Pragmas.Table (List_Pragmas.Last) :=
430 (Ptyp => List_On, Ploc => Sloc (Pragma_Node));
432 -- Now generate the list off entry for pragma List (Off)
434 if Chars (Expression (Arg1)) = Name_Off then
435 List_Pragmas.Increment_Last;
436 List_Pragmas.Table (List_Pragmas.Last) :=
437 (Ptyp => List_Off, Ploc => Semi);
438 end if;
440 ----------------
441 -- Page (2.8) --
442 ----------------
444 -- pragma Page;
446 -- Processing for this pragma must be done at parse time, since a
447 -- listing can be generated in parse only mode with semantics off.
449 when Pragma_Page =>
450 Check_Arg_Count (0);
451 List_Pragmas.Increment_Last;
452 List_Pragmas.Table (List_Pragmas.Last) := (Page, Semi);
454 ------------------
455 -- Restrictions --
456 ------------------
458 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
460 -- RESTRICTION ::=
461 -- restriction_IDENTIFIER
462 -- | restriction_parameter_IDENTIFIER => EXPRESSION
464 -- We process the case of No_Obsolescent_Features, since this has
465 -- a syntactic effect that we need to detect at parse time (the use
466 -- of replacement characters such as colon for pound sign).
468 when Pragma_Restrictions =>
469 Process_Restrictions_Or_Restriction_Warnings;
471 --------------------------
472 -- Restriction_Warnings --
473 --------------------------
475 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
477 -- RESTRICTION ::=
478 -- restriction_IDENTIFIER
479 -- | restriction_parameter_IDENTIFIER => EXPRESSION
481 -- See above comment for pragma Restrictions
483 when Pragma_Restriction_Warnings =>
484 Process_Restrictions_Or_Restriction_Warnings;
486 ----------------------------------------------------------
487 -- Source_File_Name and Source_File_Name_Project (GNAT) --
488 ----------------------------------------------------------
490 -- These two pragmas have the same syntax and semantics.
491 -- There are five forms of these pragmas:
493 -- pragma Source_File_Name[_Project] (
494 -- [UNIT_NAME =>] unit_NAME,
495 -- BODY_FILE_NAME => STRING_LITERAL
496 -- [, [INDEX =>] INTEGER_LITERAL]);
498 -- pragma Source_File_Name[_Project] (
499 -- [UNIT_NAME =>] unit_NAME,
500 -- SPEC_FILE_NAME => STRING_LITERAL
501 -- [, [INDEX =>] INTEGER_LITERAL]);
503 -- pragma Source_File_Name[_Project] (
504 -- BODY_FILE_NAME => STRING_LITERAL
505 -- [, DOT_REPLACEMENT => STRING_LITERAL]
506 -- [, CASING => CASING_SPEC]);
508 -- pragma Source_File_Name[_Project] (
509 -- SPEC_FILE_NAME => STRING_LITERAL
510 -- [, DOT_REPLACEMENT => STRING_LITERAL]
511 -- [, CASING => CASING_SPEC]);
513 -- pragma Source_File_Name[_Project] (
514 -- SUBUNIT_FILE_NAME => STRING_LITERAL
515 -- [, DOT_REPLACEMENT => STRING_LITERAL]
516 -- [, CASING => CASING_SPEC]);
518 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
520 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
521 -- Source_File_Name (SFN), however their usage is exclusive:
522 -- SFN can only be used when no project file is used, while
523 -- SFNP can only be used when a project file is used.
525 -- The Project Manager produces a configuration pragmas file that
526 -- is communicated to the compiler with -gnatec switch. This file
527 -- contains only SFNP pragmas (at least two for the default naming
528 -- scheme. As this configuration pragmas file is always the first
529 -- processed by the compiler, it prevents the use of pragmas SFN in
530 -- other config files when a project file is in use.
532 -- Note: we process this during parsing, since we need to have the
533 -- source file names set well before the semantic analysis starts,
534 -- since we load the spec and with'ed packages before analysis.
536 when Pragma_Source_File_Name | Pragma_Source_File_Name_Project =>
537 Source_File_Name : declare
538 Unam : Unit_Name_Type;
539 Expr1 : Node_Id;
540 Pat : String_Ptr;
541 Typ : Character;
542 Dot : String_Ptr;
543 Cas : Casing_Type;
544 Nast : Nat;
545 Expr : Node_Id;
546 Index : Nat;
548 function Get_Fname (Arg : Node_Id) return File_Name_Type;
549 -- Process file name from unit name form of pragma
551 function Get_String_Argument (Arg : Node_Id) return String_Ptr;
552 -- Process string literal value from argument
554 procedure Process_Casing (Arg : Node_Id);
555 -- Process Casing argument of pattern form of pragma
557 procedure Process_Dot_Replacement (Arg : Node_Id);
558 -- Process Dot_Replacement argument of pattern form of pragma
560 ---------------
561 -- Get_Fname --
562 ---------------
564 function Get_Fname (Arg : Node_Id) return File_Name_Type is
565 begin
566 String_To_Name_Buffer (Strval (Expression (Arg)));
568 for J in 1 .. Name_Len loop
569 if Is_Directory_Separator (Name_Buffer (J)) then
570 Error_Msg
571 ("directory separator character not allowed",
572 Sloc (Expression (Arg)) + Source_Ptr (J));
573 end if;
574 end loop;
576 return Name_Find;
577 end Get_Fname;
579 -------------------------
580 -- Get_String_Argument --
581 -------------------------
583 function Get_String_Argument (Arg : Node_Id) return String_Ptr is
584 Str : String_Id;
586 begin
587 if Nkind (Expression (Arg)) /= N_String_Literal
588 and then
589 Nkind (Expression (Arg)) /= N_Operator_Symbol
590 then
591 Error_Msg_N
592 ("argument for pragma% must be string literal", Arg);
593 raise Error_Resync;
594 end if;
596 Str := Strval (Expression (Arg));
598 -- Check string has no wide chars
600 for J in 1 .. String_Length (Str) loop
601 if Get_String_Char (Str, J) > 255 then
602 Error_Msg
603 ("wide character not allowed in pattern for pragma%",
604 Sloc (Expression (Arg2)) + Text_Ptr (J) - 1);
605 end if;
606 end loop;
608 -- Acquire string
610 String_To_Name_Buffer (Str);
611 return new String'(Name_Buffer (1 .. Name_Len));
612 end Get_String_Argument;
614 --------------------
615 -- Process_Casing --
616 --------------------
618 procedure Process_Casing (Arg : Node_Id) is
619 Expr : constant Node_Id := Expression (Arg);
621 begin
622 Check_Required_Identifier (Arg, Name_Casing);
624 if Nkind (Expr) = N_Identifier then
625 if Chars (Expr) = Name_Lowercase then
626 Cas := All_Lower_Case;
627 return;
628 elsif Chars (Expr) = Name_Uppercase then
629 Cas := All_Upper_Case;
630 return;
631 elsif Chars (Expr) = Name_Mixedcase then
632 Cas := Mixed_Case;
633 return;
634 end if;
635 end if;
637 Error_Msg_N
638 ("Casing argument for pragma% must be " &
639 "one of Mixedcase, Lowercase, Uppercase",
640 Arg);
641 end Process_Casing;
643 -----------------------------
644 -- Process_Dot_Replacement --
645 -----------------------------
647 procedure Process_Dot_Replacement (Arg : Node_Id) is
648 begin
649 Check_Required_Identifier (Arg, Name_Dot_Replacement);
650 Dot := Get_String_Argument (Arg);
651 end Process_Dot_Replacement;
653 -- Start of processing for Source_File_Name and
654 -- Source_File_Name_Project pragmas.
656 begin
657 if Prag_Id = Pragma_Source_File_Name then
658 if Project_File_In_Use = In_Use then
659 Error_Msg
660 ("pragma Source_File_Name cannot be used " &
661 "with a project file", Pragma_Sloc);
663 else
664 Project_File_In_Use := Not_In_Use;
665 end if;
667 else
668 if Project_File_In_Use = Not_In_Use then
669 Error_Msg
670 ("pragma Source_File_Name_Project should only be used " &
671 "with a project file", Pragma_Sloc);
672 else
673 Project_File_In_Use := In_Use;
674 end if;
675 end if;
677 -- We permit from 1 to 3 arguments
679 if Arg_Count not in 1 .. 3 then
680 Check_Arg_Count (1);
681 end if;
683 Expr1 := Expression (Arg1);
685 -- If first argument is identifier or selected component, then
686 -- we have the specific file case of the Source_File_Name pragma,
687 -- and the first argument is a unit name.
689 if Nkind (Expr1) = N_Identifier
690 or else
691 (Nkind (Expr1) = N_Selected_Component
692 and then
693 Nkind (Selector_Name (Expr1)) = N_Identifier)
694 then
695 if Nkind (Expr1) = N_Identifier
696 and then Chars (Expr1) = Name_System
697 then
698 Error_Msg_N
699 ("pragma Source_File_Name may not be used for System",
700 Arg1);
701 return Error;
702 end if;
704 -- Process index argument if present
706 if Arg_Count = 3 then
707 Expr := Expression (Arg3);
709 if Nkind (Expr) /= N_Integer_Literal
710 or else not UI_Is_In_Int_Range (Intval (Expr))
711 or else Intval (Expr) > 999
712 or else Intval (Expr) <= 0
713 then
714 Error_Msg
715 ("pragma% index must be integer literal" &
716 " in range 1 .. 999", Sloc (Expr));
717 raise Error_Resync;
718 else
719 Index := UI_To_Int (Intval (Expr));
720 end if;
722 -- No index argument present
724 else
725 Check_Arg_Count (2);
726 Index := 0;
727 end if;
729 Check_Optional_Identifier (Arg1, Name_Unit_Name);
730 Unam := Get_Unit_Name (Expr1);
732 Check_Arg_Is_String_Literal (Arg2);
734 if Chars (Arg2) = Name_Spec_File_Name then
735 Set_File_Name
736 (Get_Spec_Name (Unam), Get_Fname (Arg2), Index);
738 elsif Chars (Arg2) = Name_Body_File_Name then
739 Set_File_Name
740 (Unam, Get_Fname (Arg2), Index);
742 else
743 Error_Msg_N
744 ("pragma% argument has incorrect identifier", Arg2);
745 return Pragma_Node;
746 end if;
748 -- If the first argument is not an identifier, then we must have
749 -- the pattern form of the pragma, and the first argument must be
750 -- the pattern string with an appropriate name.
752 else
753 if Chars (Arg1) = Name_Spec_File_Name then
754 Typ := 's';
756 elsif Chars (Arg1) = Name_Body_File_Name then
757 Typ := 'b';
759 elsif Chars (Arg1) = Name_Subunit_File_Name then
760 Typ := 'u';
762 elsif Chars (Arg1) = Name_Unit_Name then
763 Error_Msg_N
764 ("Unit_Name parameter for pragma% must be an identifier",
765 Arg1);
766 raise Error_Resync;
768 else
769 Error_Msg_N
770 ("pragma% argument has incorrect identifier", Arg1);
771 raise Error_Resync;
772 end if;
774 Pat := Get_String_Argument (Arg1);
776 -- Check pattern has exactly one asterisk
778 Nast := 0;
779 for J in Pat'Range loop
780 if Pat (J) = '*' then
781 Nast := Nast + 1;
782 end if;
783 end loop;
785 if Nast /= 1 then
786 Error_Msg_N
787 ("file name pattern must have exactly one * character",
788 Arg1);
789 return Pragma_Node;
790 end if;
792 -- Set defaults for Casing and Dot_Separator parameters
794 Cas := All_Lower_Case;
795 Dot := new String'(".");
797 -- Process second and third arguments if present
799 if Arg_Count > 1 then
800 if Chars (Arg2) = Name_Casing then
801 Process_Casing (Arg2);
803 if Arg_Count = 3 then
804 Process_Dot_Replacement (Arg3);
805 end if;
807 else
808 Process_Dot_Replacement (Arg2);
810 if Arg_Count = 3 then
811 Process_Casing (Arg3);
812 end if;
813 end if;
814 end if;
816 Set_File_Name_Pattern (Pat, Typ, Dot, Cas);
817 end if;
818 end Source_File_Name;
820 -----------------------------
821 -- Source_Reference (GNAT) --
822 -----------------------------
824 -- pragma Source_Reference
825 -- (INTEGER_LITERAL [, STRING_LITERAL] );
827 -- Processing for this pragma must be done at parse time, since error
828 -- messages needing the proper line numbers can be generated in parse
829 -- only mode with semantic checking turned off, and indeed we usually
830 -- turn off semantic checking anyway if any parse errors are found.
832 when Pragma_Source_Reference => Source_Reference : declare
833 Fname : File_Name_Type;
835 begin
836 if Arg_Count /= 1 then
837 Check_Arg_Count (2);
838 Check_No_Identifier (Arg2);
839 end if;
841 -- Check that this is first line of file. We skip this test if
842 -- we are in syntax check only mode, since we may be dealing with
843 -- multiple compilation units.
845 if Get_Physical_Line_Number (Pragma_Sloc) /= 1
846 and then Num_SRef_Pragmas (Current_Source_File) = 0
847 and then Operating_Mode /= Check_Syntax
848 then
849 Error_Msg -- CODEFIX
850 ("first % pragma must be first line of file", Pragma_Sloc);
851 raise Error_Resync;
852 end if;
854 Check_No_Identifier (Arg1);
856 if Arg_Count = 1 then
857 if Num_SRef_Pragmas (Current_Source_File) = 0 then
858 Error_Msg
859 ("file name required for first % pragma in file",
860 Pragma_Sloc);
861 raise Error_Resync;
862 else
863 Fname := No_File;
864 end if;
866 -- File name present
868 else
869 Check_Arg_Is_String_Literal (Arg2);
870 String_To_Name_Buffer (Strval (Expression (Arg2)));
871 Fname := Name_Find;
873 if Num_SRef_Pragmas (Current_Source_File) > 0 then
874 if Fname /= Full_Ref_Name (Current_Source_File) then
875 Error_Msg
876 ("file name must be same in all % pragmas", Pragma_Sloc);
877 raise Error_Resync;
878 end if;
879 end if;
880 end if;
882 if Nkind (Expression (Arg1)) /= N_Integer_Literal then
883 Error_Msg
884 ("argument for pragma% must be integer literal",
885 Sloc (Expression (Arg1)));
886 raise Error_Resync;
888 -- OK, this source reference pragma is effective, however, we
889 -- ignore it if it is not in the first unit in the multiple unit
890 -- case. This is because the only purpose in this case is to
891 -- provide source pragmas for subsequent use by gnatchop.
893 else
894 if Num_Library_Units = 1 then
895 Register_Source_Ref_Pragma
896 (Fname,
897 Strip_Directory (Fname),
898 UI_To_Int (Intval (Expression (Arg1))),
899 Get_Physical_Line_Number (Pragma_Sloc) + 1);
900 end if;
901 end if;
902 end Source_Reference;
904 -------------------------
905 -- Style_Checks (GNAT) --
906 -------------------------
908 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
910 -- This is processed by the parser since some of the style
911 -- checks take place during source scanning and parsing.
913 when Pragma_Style_Checks => Style_Checks : declare
914 A : Node_Id;
915 S : String_Id;
916 C : Char_Code;
917 OK : Boolean := True;
919 begin
920 -- Two argument case is only for semantics
922 if Arg_Count = 2 then
923 null;
925 else
926 Check_Arg_Count (1);
927 Check_No_Identifier (Arg1);
928 A := Expression (Arg1);
930 if Nkind (A) = N_String_Literal then
931 S := Strval (A);
933 declare
934 Slen : constant Natural := Natural (String_Length (S));
935 Options : String (1 .. Slen);
936 J : Natural;
937 Ptr : Natural;
939 begin
940 J := 1;
941 loop
942 C := Get_String_Char (S, Int (J));
944 if not In_Character_Range (C) then
945 OK := False;
946 Ptr := J;
947 exit;
949 else
950 Options (J) := Get_Character (C);
951 end if;
953 if J = Slen then
954 if not Ignore_Style_Checks_Pragmas then
955 Set_Style_Check_Options (Options, OK, Ptr);
956 end if;
958 exit;
960 else
961 J := J + 1;
962 end if;
963 end loop;
965 if not OK then
966 Error_Msg
967 (Style_Msg_Buf (1 .. Style_Msg_Len),
968 Sloc (Expression (Arg1)) + Source_Ptr (Ptr));
969 raise Error_Resync;
970 end if;
971 end;
973 elsif Nkind (A) /= N_Identifier then
974 OK := False;
976 elsif Chars (A) = Name_All_Checks then
977 if not Ignore_Style_Checks_Pragmas then
978 if GNAT_Mode then
979 Stylesw.Set_GNAT_Style_Check_Options;
980 else
981 Stylesw.Set_Default_Style_Check_Options;
982 end if;
983 end if;
985 elsif Chars (A) = Name_On then
986 if not Ignore_Style_Checks_Pragmas then
987 Style_Check := True;
988 end if;
990 elsif Chars (A) = Name_Off then
991 if not Ignore_Style_Checks_Pragmas then
992 Style_Check := False;
993 end if;
995 else
996 OK := False;
997 end if;
999 if not OK then
1000 Error_Msg ("incorrect argument for pragma%", Sloc (A));
1001 raise Error_Resync;
1002 end if;
1003 end if;
1004 end Style_Checks;
1006 -------------------------
1007 -- Suppress_All (GNAT) --
1008 -------------------------
1010 -- pragma Suppress_All
1012 -- This is a rather odd pragma, because other compilers allow it in
1013 -- strange places. DEC allows it at the end of units, and Rational
1014 -- allows it as a program unit pragma, when it would be more natural
1015 -- if it were a configuration pragma.
1017 -- Since the reason we provide this pragma is for compatibility with
1018 -- these other compilers, we want to accommodate these strange placement
1019 -- rules, and the easiest thing is simply to allow it anywhere in a
1020 -- unit. If this pragma appears anywhere within a unit, then the effect
1021 -- is as though a pragma Suppress (All_Checks) had appeared as the first
1022 -- line of the current file, i.e. as the first configuration pragma in
1023 -- the current unit.
1025 -- To get this effect, we set the flag Has_Pragma_Suppress_All in the
1026 -- compilation unit node for the current source file then in the last
1027 -- stage of parsing a file, if this flag is set, we materialize the
1028 -- Suppress (All_Checks) pragma, marked as not coming from Source.
1030 when Pragma_Suppress_All =>
1031 Set_Has_Pragma_Suppress_All (Cunit (Current_Source_Unit));
1033 ---------------------
1034 -- Warnings (GNAT) --
1035 ---------------------
1037 -- pragma Warnings (On | Off [,REASON]);
1038 -- pragma Warnings (On | Off, LOCAL_NAME [,REASON]);
1039 -- pragma Warnings (static_string_EXPRESSION [,REASON]);
1040 -- pragma Warnings (On | Off, static_string_EXPRESSION [,REASON]);
1042 -- The one argument ON/OFF case is processed by the parser, since it may
1043 -- control parser warnings as well as semantic warnings, and in any case
1044 -- we want to be absolutely sure that the range in the warnings table is
1045 -- set well before any semantic analysis is performed. Note that we
1046 -- ignore this pragma if debug flag -gnatd.i is set.
1048 -- Also note that the "one argument" case may have two arguments if the
1049 -- second one is a reason argument.
1051 when Pragma_Warnings =>
1052 if not Debug_Flag_Dot_I
1053 and then (Arg_Count = 1
1054 or else (Arg_Count = 2
1055 and then Chars (Arg2) = Name_Reason))
1056 then
1057 Check_No_Identifier (Arg1);
1059 declare
1060 Argx : constant Node_Id := Expression (Arg1);
1062 function Get_Reason return String_Id;
1063 -- Analyzes Reason argument and returns corresponding String_Id
1064 -- value, or null if there is no Reason argument, or if the
1065 -- argument is not of the required form.
1067 ----------------
1068 -- Get_Reason --
1069 ----------------
1071 function Get_Reason return String_Id is
1072 begin
1073 if Arg_Count = 1 then
1074 return Null_String_Id;
1075 else
1076 Start_String;
1077 Get_Reason_String (Expression (Arg2));
1078 return End_String;
1079 end if;
1080 end Get_Reason;
1082 begin
1083 if Nkind (Argx) = N_Identifier then
1084 if Chars (Argx) = Name_On then
1085 Set_Warnings_Mode_On (Pragma_Sloc);
1086 elsif Chars (Argx) = Name_Off then
1087 Set_Warnings_Mode_Off (Pragma_Sloc, Get_Reason);
1088 end if;
1089 end if;
1090 end;
1091 end if;
1093 -----------------------------
1094 -- Wide_Character_Encoding --
1095 -----------------------------
1097 -- pragma Wide_Character_Encoding (IDENTIFIER | CHARACTER_LITERAL);
1099 -- This is processed by the parser, since the scanner is affected
1101 when Pragma_Wide_Character_Encoding => Wide_Character_Encoding : declare
1102 A : Node_Id;
1104 begin
1105 Check_Arg_Count (1);
1106 Check_No_Identifier (Arg1);
1107 A := Expression (Arg1);
1109 if Nkind (A) = N_Identifier then
1110 Get_Name_String (Chars (A));
1111 Wide_Character_Encoding_Method :=
1112 Get_WC_Encoding_Method (Name_Buffer (1 .. Name_Len));
1114 elsif Nkind (A) = N_Character_Literal then
1115 declare
1116 R : constant Char_Code :=
1117 Char_Code (UI_To_Int (Char_Literal_Value (A)));
1118 begin
1119 if In_Character_Range (R) then
1120 Wide_Character_Encoding_Method :=
1121 Get_WC_Encoding_Method (Get_Character (R));
1122 else
1123 raise Constraint_Error;
1124 end if;
1125 end;
1127 else
1128 raise Constraint_Error;
1129 end if;
1131 Upper_Half_Encoding :=
1132 Wide_Character_Encoding_Method in
1133 WC_Upper_Half_Encoding_Method;
1135 exception
1136 when Constraint_Error =>
1137 Error_Msg_N ("invalid argument for pragma%", Arg1);
1138 end Wide_Character_Encoding;
1140 -----------------------
1141 -- All Other Pragmas --
1142 -----------------------
1144 -- For all other pragmas, checking and processing is handled
1145 -- entirely in Sem_Prag, and no further checking is done by Par.
1147 when Pragma_Abort_Defer |
1148 Pragma_Abstract_State |
1149 Pragma_Async_Readers |
1150 Pragma_Async_Writers |
1151 Pragma_Assertion_Policy |
1152 Pragma_Assume |
1153 Pragma_Assume_No_Invalid_Values |
1154 Pragma_All_Calls_Remote |
1155 Pragma_Allow_Integer_Address |
1156 Pragma_Annotate |
1157 Pragma_Assert |
1158 Pragma_Assert_And_Cut |
1159 Pragma_Asynchronous |
1160 Pragma_Atomic |
1161 Pragma_Atomic_Components |
1162 Pragma_Attach_Handler |
1163 Pragma_Attribute_Definition |
1164 Pragma_Check |
1165 Pragma_Check_Float_Overflow |
1166 Pragma_Check_Name |
1167 Pragma_Check_Policy |
1168 Pragma_CIL_Constructor |
1169 Pragma_Compile_Time_Error |
1170 Pragma_Compile_Time_Warning |
1171 Pragma_Contract_Cases |
1172 Pragma_Convention_Identifier |
1173 Pragma_CPP_Class |
1174 Pragma_CPP_Constructor |
1175 Pragma_CPP_Virtual |
1176 Pragma_CPP_Vtable |
1177 Pragma_CPU |
1178 Pragma_C_Pass_By_Copy |
1179 Pragma_Comment |
1180 Pragma_Common_Object |
1181 Pragma_Complete_Representation |
1182 Pragma_Complex_Representation |
1183 Pragma_Component_Alignment |
1184 Pragma_Controlled |
1185 Pragma_Convention |
1186 Pragma_Debug_Policy |
1187 Pragma_Depends |
1188 Pragma_Detect_Blocking |
1189 Pragma_Default_Scalar_Storage_Order |
1190 Pragma_Default_Storage_Pool |
1191 Pragma_Disable_Atomic_Synchronization |
1192 Pragma_Discard_Names |
1193 Pragma_Dispatching_Domain |
1194 Pragma_Effective_Reads |
1195 Pragma_Effective_Writes |
1196 Pragma_Eliminate |
1197 Pragma_Elaborate |
1198 Pragma_Elaborate_All |
1199 Pragma_Elaborate_Body |
1200 Pragma_Elaboration_Checks |
1201 Pragma_Enable_Atomic_Synchronization |
1202 Pragma_Export |
1203 Pragma_Export_Function |
1204 Pragma_Export_Object |
1205 Pragma_Export_Procedure |
1206 Pragma_Export_Value |
1207 Pragma_Export_Valued_Procedure |
1208 Pragma_Extend_System |
1209 Pragma_External |
1210 Pragma_External_Name_Casing |
1211 Pragma_Favor_Top_Level |
1212 Pragma_Fast_Math |
1213 Pragma_Finalize_Storage_Only |
1214 Pragma_Global |
1215 Pragma_Ident |
1216 Pragma_Implementation_Defined |
1217 Pragma_Implemented |
1218 Pragma_Implicit_Packing |
1219 Pragma_Import |
1220 Pragma_Import_Function |
1221 Pragma_Import_Object |
1222 Pragma_Import_Procedure |
1223 Pragma_Import_Valued_Procedure |
1224 Pragma_Independent |
1225 Pragma_Independent_Components |
1226 Pragma_Initial_Condition |
1227 Pragma_Initialize_Scalars |
1228 Pragma_Initializes |
1229 Pragma_Inline |
1230 Pragma_Inline_Always |
1231 Pragma_Inline_Generic |
1232 Pragma_Inspection_Point |
1233 Pragma_Interface |
1234 Pragma_Interface_Name |
1235 Pragma_Interrupt_Handler |
1236 Pragma_Interrupt_State |
1237 Pragma_Interrupt_Priority |
1238 Pragma_Invariant |
1239 Pragma_Java_Constructor |
1240 Pragma_Java_Interface |
1241 Pragma_Keep_Names |
1242 Pragma_License |
1243 Pragma_Link_With |
1244 Pragma_Linker_Alias |
1245 Pragma_Linker_Constructor |
1246 Pragma_Linker_Destructor |
1247 Pragma_Linker_Options |
1248 Pragma_Linker_Section |
1249 Pragma_Lock_Free |
1250 Pragma_Locking_Policy |
1251 Pragma_Loop_Invariant |
1252 Pragma_Loop_Optimize |
1253 Pragma_Loop_Variant |
1254 Pragma_Machine_Attribute |
1255 Pragma_Main |
1256 Pragma_Main_Storage |
1257 Pragma_Memory_Size |
1258 Pragma_No_Body |
1259 Pragma_No_Elaboration_Code_All |
1260 Pragma_No_Inline |
1261 Pragma_No_Return |
1262 Pragma_No_Run_Time |
1263 Pragma_No_Strict_Aliasing |
1264 Pragma_Normalize_Scalars |
1265 Pragma_Obsolescent |
1266 Pragma_Ordered |
1267 Pragma_Optimize |
1268 Pragma_Optimize_Alignment |
1269 Pragma_Overflow_Mode |
1270 Pragma_Overriding_Renamings |
1271 Pragma_Pack |
1272 Pragma_Part_Of |
1273 Pragma_Partition_Elaboration_Policy |
1274 Pragma_Passive |
1275 Pragma_Preelaborable_Initialization |
1276 Pragma_Polling |
1277 Pragma_Persistent_BSS |
1278 Pragma_Post |
1279 Pragma_Postcondition |
1280 Pragma_Post_Class |
1281 Pragma_Pre |
1282 Pragma_Precondition |
1283 Pragma_Predicate |
1284 Pragma_Preelaborate |
1285 Pragma_Pre_Class |
1286 Pragma_Priority |
1287 Pragma_Priority_Specific_Dispatching |
1288 Pragma_Profile |
1289 Pragma_Profile_Warnings |
1290 Pragma_Propagate_Exceptions |
1291 Pragma_Provide_Shift_Operators |
1292 Pragma_Psect_Object |
1293 Pragma_Pure |
1294 Pragma_Pure_Function |
1295 Pragma_Queuing_Policy |
1296 Pragma_Refined_Depends |
1297 Pragma_Refined_Global |
1298 Pragma_Refined_Post |
1299 Pragma_Refined_State |
1300 Pragma_Relative_Deadline |
1301 Pragma_Remote_Access_Type |
1302 Pragma_Remote_Call_Interface |
1303 Pragma_Remote_Types |
1304 Pragma_Restricted_Run_Time |
1305 Pragma_Rational |
1306 Pragma_Ravenscar |
1307 Pragma_Reviewable |
1308 Pragma_Share_Generic |
1309 Pragma_Shared |
1310 Pragma_Shared_Passive |
1311 Pragma_Short_Circuit_And_Or |
1312 Pragma_Short_Descriptors |
1313 Pragma_Simple_Storage_Pool_Type |
1314 Pragma_SPARK_Mode |
1315 Pragma_Storage_Size |
1316 Pragma_Storage_Unit |
1317 Pragma_Static_Elaboration_Desired |
1318 Pragma_Stream_Convert |
1319 Pragma_Subtitle |
1320 Pragma_Suppress |
1321 Pragma_Suppress_Debug_Info |
1322 Pragma_Suppress_Exception_Locations |
1323 Pragma_Suppress_Initialization |
1324 Pragma_System_Name |
1325 Pragma_Task_Dispatching_Policy |
1326 Pragma_Task_Info |
1327 Pragma_Task_Name |
1328 Pragma_Task_Storage |
1329 Pragma_Test_Case |
1330 Pragma_Thread_Local_Storage |
1331 Pragma_Time_Slice |
1332 Pragma_Title |
1333 Pragma_Type_Invariant |
1334 Pragma_Type_Invariant_Class |
1335 Pragma_Unchecked_Union |
1336 Pragma_Unevaluated_Use_Of_Old |
1337 Pragma_Unimplemented_Unit |
1338 Pragma_Universal_Aliasing |
1339 Pragma_Universal_Data |
1340 Pragma_Unmodified |
1341 Pragma_Unreferenced |
1342 Pragma_Unreferenced_Objects |
1343 Pragma_Unreserve_All_Interrupts |
1344 Pragma_Unsuppress |
1345 Pragma_Use_VADS_Size |
1346 Pragma_Volatile |
1347 Pragma_Volatile_Components |
1348 Pragma_Warning_As_Error |
1349 Pragma_Weak_External |
1350 Pragma_Validity_Checks =>
1351 null;
1353 --------------------
1354 -- Unknown_Pragma --
1355 --------------------
1357 -- Should be impossible, since we excluded this case earlier on
1359 when Unknown_Pragma =>
1360 raise Program_Error;
1362 end case;
1364 return Pragma_Node;
1366 --------------------
1367 -- Error Handling --
1368 --------------------
1370 exception
1371 when Error_Resync =>
1372 return Error;
1374 end Prag;