Implement -mmemcpy-strategy= and -mmemset-strategy= options
[official-gcc.git] / gcc / ada / par-prag.adb
blob4d01db09d124c50d489c194e0ae5599233621b8c
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-2013, 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;
311 ------------
312 -- Ada_95 --
313 ------------
315 -- This pragma must be processed at parse time, since we want to set
316 -- the Ada version properly at parse time to recognize the appropriate
317 -- Ada version syntax.
319 when Pragma_Ada_95 =>
320 Ada_Version := Ada_95;
321 Ada_Version_Explicit := Ada_95;
323 ---------------------
324 -- Ada_05/Ada_2005 --
325 ---------------------
327 -- These pragmas 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. However, it is only the zero argument form that
330 -- must be processed at parse time.
332 when Pragma_Ada_05 | Pragma_Ada_2005 =>
333 if Arg_Count = 0 then
334 Ada_Version := Ada_2005;
335 Ada_Version_Explicit := Ada_2005;
336 end if;
338 ---------------------
339 -- Ada_12/Ada_2012 --
340 ---------------------
342 -- These pragmas 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. However, it is only the zero argument form that
345 -- must be processed at parse time.
347 when Pragma_Ada_12 | Pragma_Ada_2012 =>
348 if Arg_Count = 0 then
349 Ada_Version := Ada_2012;
350 Ada_Version_Explicit := Ada_2012;
351 end if;
353 -----------
354 -- Debug --
355 -----------
357 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
359 when Pragma_Debug =>
360 Check_No_Identifier (Arg1);
362 if Arg_Count = 2 then
363 Check_No_Identifier (Arg2);
364 else
365 Check_Arg_Count (1);
366 end if;
368 -------------------------------
369 -- Extensions_Allowed (GNAT) --
370 -------------------------------
372 -- pragma Extensions_Allowed (Off | On)
374 -- The processing for pragma Extensions_Allowed must be done at
375 -- parse time, since extensions mode may affect what is accepted.
377 when Pragma_Extensions_Allowed =>
378 Check_Arg_Count (1);
379 Check_No_Identifier (Arg1);
380 Check_Arg_Is_On_Or_Off (Arg1);
382 if Chars (Expression (Arg1)) = Name_On then
383 Extensions_Allowed := True;
384 Ada_Version := Ada_2012;
385 else
386 Extensions_Allowed := False;
387 Ada_Version := Ada_Version_Explicit;
388 end if;
390 ----------------
391 -- List (2.8) --
392 ----------------
394 -- pragma List (Off | On)
396 -- The processing for pragma List must be done at parse time,
397 -- since a listing can be generated in parse only mode.
399 when Pragma_List =>
400 Check_Arg_Count (1);
401 Check_No_Identifier (Arg1);
402 Check_Arg_Is_On_Or_Off (Arg1);
404 -- We unconditionally make a List_On entry for the pragma, so that
405 -- in the List (Off) case, the pragma will print even in a region
406 -- of code with listing turned off (this is required!)
408 List_Pragmas.Increment_Last;
409 List_Pragmas.Table (List_Pragmas.Last) :=
410 (Ptyp => List_On, Ploc => Sloc (Pragma_Node));
412 -- Now generate the list off entry for pragma List (Off)
414 if Chars (Expression (Arg1)) = Name_Off then
415 List_Pragmas.Increment_Last;
416 List_Pragmas.Table (List_Pragmas.Last) :=
417 (Ptyp => List_Off, Ploc => Semi);
418 end if;
420 ----------------
421 -- Page (2.8) --
422 ----------------
424 -- pragma Page;
426 -- Processing for this pragma must be done at parse time, since a
427 -- listing can be generated in parse only mode with semantics off.
429 when Pragma_Page =>
430 Check_Arg_Count (0);
431 List_Pragmas.Increment_Last;
432 List_Pragmas.Table (List_Pragmas.Last) := (Page, Semi);
434 ------------------
435 -- Restrictions --
436 ------------------
438 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
440 -- RESTRICTION ::=
441 -- restriction_IDENTIFIER
442 -- | restriction_parameter_IDENTIFIER => EXPRESSION
444 -- We process the case of No_Obsolescent_Features, since this has
445 -- a syntactic effect that we need to detect at parse time (the use
446 -- of replacement characters such as colon for pound sign).
448 when Pragma_Restrictions =>
449 Process_Restrictions_Or_Restriction_Warnings;
451 --------------------------
452 -- Restriction_Warnings --
453 --------------------------
455 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
457 -- RESTRICTION ::=
458 -- restriction_IDENTIFIER
459 -- | restriction_parameter_IDENTIFIER => EXPRESSION
461 -- See above comment for pragma Restrictions
463 when Pragma_Restriction_Warnings =>
464 Process_Restrictions_Or_Restriction_Warnings;
466 ----------------------------------------------------------
467 -- Source_File_Name and Source_File_Name_Project (GNAT) --
468 ----------------------------------------------------------
470 -- These two pragmas have the same syntax and semantics.
471 -- There are five forms of these pragmas:
473 -- pragma Source_File_Name[_Project] (
474 -- [UNIT_NAME =>] unit_NAME,
475 -- BODY_FILE_NAME => STRING_LITERAL
476 -- [, [INDEX =>] INTEGER_LITERAL]);
478 -- pragma Source_File_Name[_Project] (
479 -- [UNIT_NAME =>] unit_NAME,
480 -- SPEC_FILE_NAME => STRING_LITERAL
481 -- [, [INDEX =>] INTEGER_LITERAL]);
483 -- pragma Source_File_Name[_Project] (
484 -- BODY_FILE_NAME => STRING_LITERAL
485 -- [, DOT_REPLACEMENT => STRING_LITERAL]
486 -- [, CASING => CASING_SPEC]);
488 -- pragma Source_File_Name[_Project] (
489 -- SPEC_FILE_NAME => STRING_LITERAL
490 -- [, DOT_REPLACEMENT => STRING_LITERAL]
491 -- [, CASING => CASING_SPEC]);
493 -- pragma Source_File_Name[_Project] (
494 -- SUBUNIT_FILE_NAME => STRING_LITERAL
495 -- [, DOT_REPLACEMENT => STRING_LITERAL]
496 -- [, CASING => CASING_SPEC]);
498 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
500 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
501 -- Source_File_Name (SFN), however their usage is exclusive:
502 -- SFN can only be used when no project file is used, while
503 -- SFNP can only be used when a project file is used.
505 -- The Project Manager produces a configuration pragmas file that
506 -- is communicated to the compiler with -gnatec switch. This file
507 -- contains only SFNP pragmas (at least two for the default naming
508 -- scheme. As this configuration pragmas file is always the first
509 -- processed by the compiler, it prevents the use of pragmas SFN in
510 -- other config files when a project file is in use.
512 -- Note: we process this during parsing, since we need to have the
513 -- source file names set well before the semantic analysis starts,
514 -- since we load the spec and with'ed packages before analysis.
516 when Pragma_Source_File_Name | Pragma_Source_File_Name_Project =>
517 Source_File_Name : declare
518 Unam : Unit_Name_Type;
519 Expr1 : Node_Id;
520 Pat : String_Ptr;
521 Typ : Character;
522 Dot : String_Ptr;
523 Cas : Casing_Type;
524 Nast : Nat;
525 Expr : Node_Id;
526 Index : Nat;
528 function Get_Fname (Arg : Node_Id) return File_Name_Type;
529 -- Process file name from unit name form of pragma
531 function Get_String_Argument (Arg : Node_Id) return String_Ptr;
532 -- Process string literal value from argument
534 procedure Process_Casing (Arg : Node_Id);
535 -- Process Casing argument of pattern form of pragma
537 procedure Process_Dot_Replacement (Arg : Node_Id);
538 -- Process Dot_Replacement argument of pattern form of pragma
540 ---------------
541 -- Get_Fname --
542 ---------------
544 function Get_Fname (Arg : Node_Id) return File_Name_Type is
545 begin
546 String_To_Name_Buffer (Strval (Expression (Arg)));
548 for J in 1 .. Name_Len loop
549 if Is_Directory_Separator (Name_Buffer (J)) then
550 Error_Msg
551 ("directory separator character not allowed",
552 Sloc (Expression (Arg)) + Source_Ptr (J));
553 end if;
554 end loop;
556 return Name_Find;
557 end Get_Fname;
559 -------------------------
560 -- Get_String_Argument --
561 -------------------------
563 function Get_String_Argument (Arg : Node_Id) return String_Ptr is
564 Str : String_Id;
566 begin
567 if Nkind (Expression (Arg)) /= N_String_Literal
568 and then
569 Nkind (Expression (Arg)) /= N_Operator_Symbol
570 then
571 Error_Msg_N
572 ("argument for pragma% must be string literal", Arg);
573 raise Error_Resync;
574 end if;
576 Str := Strval (Expression (Arg));
578 -- Check string has no wide chars
580 for J in 1 .. String_Length (Str) loop
581 if Get_String_Char (Str, J) > 255 then
582 Error_Msg
583 ("wide character not allowed in pattern for pragma%",
584 Sloc (Expression (Arg2)) + Text_Ptr (J) - 1);
585 end if;
586 end loop;
588 -- Acquire string
590 String_To_Name_Buffer (Str);
591 return new String'(Name_Buffer (1 .. Name_Len));
592 end Get_String_Argument;
594 --------------------
595 -- Process_Casing --
596 --------------------
598 procedure Process_Casing (Arg : Node_Id) is
599 Expr : constant Node_Id := Expression (Arg);
601 begin
602 Check_Required_Identifier (Arg, Name_Casing);
604 if Nkind (Expr) = N_Identifier then
605 if Chars (Expr) = Name_Lowercase then
606 Cas := All_Lower_Case;
607 return;
608 elsif Chars (Expr) = Name_Uppercase then
609 Cas := All_Upper_Case;
610 return;
611 elsif Chars (Expr) = Name_Mixedcase then
612 Cas := Mixed_Case;
613 return;
614 end if;
615 end if;
617 Error_Msg_N
618 ("Casing argument for pragma% must be " &
619 "one of Mixedcase, Lowercase, Uppercase",
620 Arg);
621 end Process_Casing;
623 -----------------------------
624 -- Process_Dot_Replacement --
625 -----------------------------
627 procedure Process_Dot_Replacement (Arg : Node_Id) is
628 begin
629 Check_Required_Identifier (Arg, Name_Dot_Replacement);
630 Dot := Get_String_Argument (Arg);
631 end Process_Dot_Replacement;
633 -- Start of processing for Source_File_Name and
634 -- Source_File_Name_Project pragmas.
636 begin
637 if Prag_Id = Pragma_Source_File_Name then
638 if Project_File_In_Use = In_Use then
639 Error_Msg
640 ("pragma Source_File_Name cannot be used " &
641 "with a project file", Pragma_Sloc);
643 else
644 Project_File_In_Use := Not_In_Use;
645 end if;
647 else
648 if Project_File_In_Use = Not_In_Use then
649 Error_Msg
650 ("pragma Source_File_Name_Project should only be used " &
651 "with a project file", Pragma_Sloc);
652 else
653 Project_File_In_Use := In_Use;
654 end if;
655 end if;
657 -- We permit from 1 to 3 arguments
659 if Arg_Count not in 1 .. 3 then
660 Check_Arg_Count (1);
661 end if;
663 Expr1 := Expression (Arg1);
665 -- If first argument is identifier or selected component, then
666 -- we have the specific file case of the Source_File_Name pragma,
667 -- and the first argument is a unit name.
669 if Nkind (Expr1) = N_Identifier
670 or else
671 (Nkind (Expr1) = N_Selected_Component
672 and then
673 Nkind (Selector_Name (Expr1)) = N_Identifier)
674 then
675 if Nkind (Expr1) = N_Identifier
676 and then Chars (Expr1) = Name_System
677 then
678 Error_Msg_N
679 ("pragma Source_File_Name may not be used for System",
680 Arg1);
681 return Error;
682 end if;
684 -- Process index argument if present
686 if Arg_Count = 3 then
687 Expr := Expression (Arg3);
689 if Nkind (Expr) /= N_Integer_Literal
690 or else not UI_Is_In_Int_Range (Intval (Expr))
691 or else Intval (Expr) > 999
692 or else Intval (Expr) <= 0
693 then
694 Error_Msg
695 ("pragma% index must be integer literal" &
696 " in range 1 .. 999", Sloc (Expr));
697 raise Error_Resync;
698 else
699 Index := UI_To_Int (Intval (Expr));
700 end if;
702 -- No index argument present
704 else
705 Check_Arg_Count (2);
706 Index := 0;
707 end if;
709 Check_Optional_Identifier (Arg1, Name_Unit_Name);
710 Unam := Get_Unit_Name (Expr1);
712 Check_Arg_Is_String_Literal (Arg2);
714 if Chars (Arg2) = Name_Spec_File_Name then
715 Set_File_Name
716 (Get_Spec_Name (Unam), Get_Fname (Arg2), Index);
718 elsif Chars (Arg2) = Name_Body_File_Name then
719 Set_File_Name
720 (Unam, Get_Fname (Arg2), Index);
722 else
723 Error_Msg_N
724 ("pragma% argument has incorrect identifier", Arg2);
725 return Pragma_Node;
726 end if;
728 -- If the first argument is not an identifier, then we must have
729 -- the pattern form of the pragma, and the first argument must be
730 -- the pattern string with an appropriate name.
732 else
733 if Chars (Arg1) = Name_Spec_File_Name then
734 Typ := 's';
736 elsif Chars (Arg1) = Name_Body_File_Name then
737 Typ := 'b';
739 elsif Chars (Arg1) = Name_Subunit_File_Name then
740 Typ := 'u';
742 elsif Chars (Arg1) = Name_Unit_Name then
743 Error_Msg_N
744 ("Unit_Name parameter for pragma% must be an identifier",
745 Arg1);
746 raise Error_Resync;
748 else
749 Error_Msg_N
750 ("pragma% argument has incorrect identifier", Arg1);
751 raise Error_Resync;
752 end if;
754 Pat := Get_String_Argument (Arg1);
756 -- Check pattern has exactly one asterisk
758 Nast := 0;
759 for J in Pat'Range loop
760 if Pat (J) = '*' then
761 Nast := Nast + 1;
762 end if;
763 end loop;
765 if Nast /= 1 then
766 Error_Msg_N
767 ("file name pattern must have exactly one * character",
768 Arg1);
769 return Pragma_Node;
770 end if;
772 -- Set defaults for Casing and Dot_Separator parameters
774 Cas := All_Lower_Case;
775 Dot := new String'(".");
777 -- Process second and third arguments if present
779 if Arg_Count > 1 then
780 if Chars (Arg2) = Name_Casing then
781 Process_Casing (Arg2);
783 if Arg_Count = 3 then
784 Process_Dot_Replacement (Arg3);
785 end if;
787 else
788 Process_Dot_Replacement (Arg2);
790 if Arg_Count = 3 then
791 Process_Casing (Arg3);
792 end if;
793 end if;
794 end if;
796 Set_File_Name_Pattern (Pat, Typ, Dot, Cas);
797 end if;
798 end Source_File_Name;
800 -----------------------------
801 -- Source_Reference (GNAT) --
802 -----------------------------
804 -- pragma Source_Reference
805 -- (INTEGER_LITERAL [, STRING_LITERAL] );
807 -- Processing for this pragma must be done at parse time, since error
808 -- messages needing the proper line numbers can be generated in parse
809 -- only mode with semantic checking turned off, and indeed we usually
810 -- turn off semantic checking anyway if any parse errors are found.
812 when Pragma_Source_Reference => Source_Reference : declare
813 Fname : File_Name_Type;
815 begin
816 if Arg_Count /= 1 then
817 Check_Arg_Count (2);
818 Check_No_Identifier (Arg2);
819 end if;
821 -- Check that this is first line of file. We skip this test if
822 -- we are in syntax check only mode, since we may be dealing with
823 -- multiple compilation units.
825 if Get_Physical_Line_Number (Pragma_Sloc) /= 1
826 and then Num_SRef_Pragmas (Current_Source_File) = 0
827 and then Operating_Mode /= Check_Syntax
828 then
829 Error_Msg -- CODEFIX
830 ("first % pragma must be first line of file", Pragma_Sloc);
831 raise Error_Resync;
832 end if;
834 Check_No_Identifier (Arg1);
836 if Arg_Count = 1 then
837 if Num_SRef_Pragmas (Current_Source_File) = 0 then
838 Error_Msg
839 ("file name required for first % pragma in file",
840 Pragma_Sloc);
841 raise Error_Resync;
842 else
843 Fname := No_File;
844 end if;
846 -- File name present
848 else
849 Check_Arg_Is_String_Literal (Arg2);
850 String_To_Name_Buffer (Strval (Expression (Arg2)));
851 Fname := Name_Find;
853 if Num_SRef_Pragmas (Current_Source_File) > 0 then
854 if Fname /= Full_Ref_Name (Current_Source_File) then
855 Error_Msg
856 ("file name must be same in all % pragmas", Pragma_Sloc);
857 raise Error_Resync;
858 end if;
859 end if;
860 end if;
862 if Nkind (Expression (Arg1)) /= N_Integer_Literal then
863 Error_Msg
864 ("argument for pragma% must be integer literal",
865 Sloc (Expression (Arg1)));
866 raise Error_Resync;
868 -- OK, this source reference pragma is effective, however, we
869 -- ignore it if it is not in the first unit in the multiple unit
870 -- case. This is because the only purpose in this case is to
871 -- provide source pragmas for subsequent use by gnatchop.
873 else
874 if Num_Library_Units = 1 then
875 Register_Source_Ref_Pragma
876 (Fname,
877 Strip_Directory (Fname),
878 UI_To_Int (Intval (Expression (Arg1))),
879 Get_Physical_Line_Number (Pragma_Sloc) + 1);
880 end if;
881 end if;
882 end Source_Reference;
884 -------------------------
885 -- Style_Checks (GNAT) --
886 -------------------------
888 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
890 -- This is processed by the parser since some of the style
891 -- checks take place during source scanning and parsing.
893 when Pragma_Style_Checks => Style_Checks : declare
894 A : Node_Id;
895 S : String_Id;
896 C : Char_Code;
897 OK : Boolean := True;
899 begin
900 -- Two argument case is only for semantics
902 if Arg_Count = 2 then
903 null;
905 else
906 Check_Arg_Count (1);
907 Check_No_Identifier (Arg1);
908 A := Expression (Arg1);
910 if Nkind (A) = N_String_Literal then
911 S := Strval (A);
913 declare
914 Slen : constant Natural := Natural (String_Length (S));
915 Options : String (1 .. Slen);
916 J : Natural;
917 Ptr : Natural;
919 begin
920 J := 1;
921 loop
922 C := Get_String_Char (S, Int (J));
924 if not In_Character_Range (C) then
925 OK := False;
926 Ptr := J;
927 exit;
929 else
930 Options (J) := Get_Character (C);
931 end if;
933 if J = Slen then
934 if not Ignore_Style_Checks_Pragmas then
935 Set_Style_Check_Options (Options, OK, Ptr);
936 end if;
938 exit;
940 else
941 J := J + 1;
942 end if;
943 end loop;
945 if not OK then
946 Error_Msg
947 (Style_Msg_Buf (1 .. Style_Msg_Len),
948 Sloc (Expression (Arg1)) + Source_Ptr (Ptr));
949 raise Error_Resync;
950 end if;
951 end;
953 elsif Nkind (A) /= N_Identifier then
954 OK := False;
956 elsif Chars (A) = Name_All_Checks then
957 if not Ignore_Style_Checks_Pragmas then
958 if GNAT_Mode then
959 Stylesw.Set_GNAT_Style_Check_Options;
960 else
961 Stylesw.Set_Default_Style_Check_Options;
962 end if;
963 end if;
965 elsif Chars (A) = Name_On then
966 if not Ignore_Style_Checks_Pragmas then
967 Style_Check := True;
968 end if;
970 elsif Chars (A) = Name_Off then
971 if not Ignore_Style_Checks_Pragmas then
972 Style_Check := False;
973 end if;
975 else
976 OK := False;
977 end if;
979 if not OK then
980 Error_Msg ("incorrect argument for pragma%", Sloc (A));
981 raise Error_Resync;
982 end if;
983 end if;
984 end Style_Checks;
986 -------------------------
987 -- Suppress_All (GNAT) --
988 -------------------------
990 -- pragma Suppress_All
992 -- This is a rather odd pragma, because other compilers allow it in
993 -- strange places. DEC allows it at the end of units, and Rational
994 -- allows it as a program unit pragma, when it would be more natural
995 -- if it were a configuration pragma.
997 -- Since the reason we provide this pragma is for compatibility with
998 -- these other compilers, we want to accommodate these strange placement
999 -- rules, and the easiest thing is simply to allow it anywhere in a
1000 -- unit. If this pragma appears anywhere within a unit, then the effect
1001 -- is as though a pragma Suppress (All_Checks) had appeared as the first
1002 -- line of the current file, i.e. as the first configuration pragma in
1003 -- the current unit.
1005 -- To get this effect, we set the flag Has_Pragma_Suppress_All in the
1006 -- compilation unit node for the current source file then in the last
1007 -- stage of parsing a file, if this flag is set, we materialize the
1008 -- Suppress (All_Checks) pragma, marked as not coming from Source.
1010 when Pragma_Suppress_All =>
1011 Set_Has_Pragma_Suppress_All (Cunit (Current_Source_Unit));
1013 ---------------------
1014 -- Warnings (GNAT) --
1015 ---------------------
1017 -- pragma Warnings (On | Off);
1018 -- pragma Warnings (On | Off, LOCAL_NAME);
1019 -- pragma Warnings (static_string_EXPRESSION);
1020 -- pragma Warnings (On | Off, static_string_EXPRESSION);
1022 -- The one argument ON/OFF case is processed by the parser, since it may
1023 -- control parser warnings as well as semantic warnings, and in any case
1024 -- we want to be absolutely sure that the range in the warnings table is
1025 -- set well before any semantic analysis is performed. Note that we
1026 -- ignore this pragma if debug flag -gnatd.i is set.
1028 -- Also note that the "one argument" case may have two arguments if the
1029 -- second one is a reason argument.
1031 when Pragma_Warnings =>
1032 if not Debug_Flag_Dot_I
1033 and then (Arg_Count = 1
1034 or else (Arg_Count = 2
1035 and then Chars (Arg2) = Name_Reason))
1036 then
1037 Check_No_Identifier (Arg1);
1039 declare
1040 Argx : constant Node_Id := Expression (Arg1);
1041 begin
1042 if Nkind (Argx) = N_Identifier then
1043 if Chars (Argx) = Name_On then
1044 Set_Warnings_Mode_On (Pragma_Sloc);
1045 elsif Chars (Argx) = Name_Off then
1046 Set_Warnings_Mode_Off (Pragma_Sloc);
1047 end if;
1048 end if;
1049 end;
1050 end if;
1052 -----------------------------
1053 -- Wide_Character_Encoding --
1054 -----------------------------
1056 -- pragma Wide_Character_Encoding (IDENTIFIER | CHARACTER_LITERAL);
1058 -- This is processed by the parser, since the scanner is affected
1060 when Pragma_Wide_Character_Encoding => Wide_Character_Encoding : declare
1061 A : Node_Id;
1063 begin
1064 Check_Arg_Count (1);
1065 Check_No_Identifier (Arg1);
1066 A := Expression (Arg1);
1068 if Nkind (A) = N_Identifier then
1069 Get_Name_String (Chars (A));
1070 Wide_Character_Encoding_Method :=
1071 Get_WC_Encoding_Method (Name_Buffer (1 .. Name_Len));
1073 elsif Nkind (A) = N_Character_Literal then
1074 declare
1075 R : constant Char_Code :=
1076 Char_Code (UI_To_Int (Char_Literal_Value (A)));
1077 begin
1078 if In_Character_Range (R) then
1079 Wide_Character_Encoding_Method :=
1080 Get_WC_Encoding_Method (Get_Character (R));
1081 else
1082 raise Constraint_Error;
1083 end if;
1084 end;
1086 else
1087 raise Constraint_Error;
1088 end if;
1090 Upper_Half_Encoding :=
1091 Wide_Character_Encoding_Method in
1092 WC_Upper_Half_Encoding_Method;
1094 exception
1095 when Constraint_Error =>
1096 Error_Msg_N ("invalid argument for pragma%", Arg1);
1097 end Wide_Character_Encoding;
1099 -----------------------
1100 -- All Other Pragmas --
1101 -----------------------
1103 -- For all other pragmas, checking and processing is handled
1104 -- entirely in Sem_Prag, and no further checking is done by Par.
1106 when Pragma_Abort_Defer |
1107 Pragma_Abstract_State |
1108 Pragma_Assertion_Policy |
1109 Pragma_Assume |
1110 Pragma_Assume_No_Invalid_Values |
1111 Pragma_AST_Entry |
1112 Pragma_All_Calls_Remote |
1113 Pragma_Annotate |
1114 Pragma_Assert |
1115 Pragma_Assert_And_Cut |
1116 Pragma_Asynchronous |
1117 Pragma_Atomic |
1118 Pragma_Atomic_Components |
1119 Pragma_Attach_Handler |
1120 Pragma_Attribute_Definition |
1121 Pragma_Check |
1122 Pragma_Check_Float_Overflow |
1123 Pragma_Check_Name |
1124 Pragma_Check_Policy |
1125 Pragma_CIL_Constructor |
1126 Pragma_Compile_Time_Error |
1127 Pragma_Compile_Time_Warning |
1128 Pragma_Compiler_Unit |
1129 Pragma_Contract_Cases |
1130 Pragma_Convention_Identifier |
1131 Pragma_CPP_Class |
1132 Pragma_CPP_Constructor |
1133 Pragma_CPP_Virtual |
1134 Pragma_CPP_Vtable |
1135 Pragma_CPU |
1136 Pragma_C_Pass_By_Copy |
1137 Pragma_Comment |
1138 Pragma_Common_Object |
1139 Pragma_Complete_Representation |
1140 Pragma_Complex_Representation |
1141 Pragma_Component_Alignment |
1142 Pragma_Controlled |
1143 Pragma_Convention |
1144 Pragma_Debug_Policy |
1145 Pragma_Depends |
1146 Pragma_Detect_Blocking |
1147 Pragma_Default_Storage_Pool |
1148 Pragma_Disable_Atomic_Synchronization |
1149 Pragma_Discard_Names |
1150 Pragma_Dispatching_Domain |
1151 Pragma_Eliminate |
1152 Pragma_Elaborate |
1153 Pragma_Elaborate_All |
1154 Pragma_Elaborate_Body |
1155 Pragma_Elaboration_Checks |
1156 Pragma_Enable_Atomic_Synchronization |
1157 Pragma_Export |
1158 Pragma_Export_Exception |
1159 Pragma_Export_Function |
1160 Pragma_Export_Object |
1161 Pragma_Export_Procedure |
1162 Pragma_Export_Value |
1163 Pragma_Export_Valued_Procedure |
1164 Pragma_Extend_System |
1165 Pragma_External |
1166 Pragma_External_Name_Casing |
1167 Pragma_Favor_Top_Level |
1168 Pragma_Fast_Math |
1169 Pragma_Finalize_Storage_Only |
1170 Pragma_Float_Representation |
1171 Pragma_Global |
1172 Pragma_Ident |
1173 Pragma_Implementation_Defined |
1174 Pragma_Implemented |
1175 Pragma_Implicit_Packing |
1176 Pragma_Import |
1177 Pragma_Import_Exception |
1178 Pragma_Import_Function |
1179 Pragma_Import_Object |
1180 Pragma_Import_Procedure |
1181 Pragma_Import_Valued_Procedure |
1182 Pragma_Independent |
1183 Pragma_Independent_Components |
1184 Pragma_Initialize_Scalars |
1185 Pragma_Inline |
1186 Pragma_Inline_Always |
1187 Pragma_Inline_Generic |
1188 Pragma_Inspection_Point |
1189 Pragma_Interface |
1190 Pragma_Interface_Name |
1191 Pragma_Interrupt_Handler |
1192 Pragma_Interrupt_State |
1193 Pragma_Interrupt_Priority |
1194 Pragma_Invariant |
1195 Pragma_Java_Constructor |
1196 Pragma_Java_Interface |
1197 Pragma_Keep_Names |
1198 Pragma_License |
1199 Pragma_Link_With |
1200 Pragma_Linker_Alias |
1201 Pragma_Linker_Constructor |
1202 Pragma_Linker_Destructor |
1203 Pragma_Linker_Options |
1204 Pragma_Linker_Section |
1205 Pragma_Lock_Free |
1206 Pragma_Locking_Policy |
1207 Pragma_Long_Float |
1208 Pragma_Loop_Invariant |
1209 Pragma_Loop_Optimize |
1210 Pragma_Loop_Variant |
1211 Pragma_Machine_Attribute |
1212 Pragma_Main |
1213 Pragma_Main_Storage |
1214 Pragma_Memory_Size |
1215 Pragma_No_Body |
1216 Pragma_No_Inline |
1217 Pragma_No_Return |
1218 Pragma_No_Run_Time |
1219 Pragma_No_Strict_Aliasing |
1220 Pragma_Normalize_Scalars |
1221 Pragma_Obsolescent |
1222 Pragma_Ordered |
1223 Pragma_Optimize |
1224 Pragma_Optimize_Alignment |
1225 Pragma_Overflow_Mode |
1226 Pragma_Overriding_Renamings |
1227 Pragma_Pack |
1228 Pragma_Partition_Elaboration_Policy |
1229 Pragma_Passive |
1230 Pragma_Preelaborable_Initialization |
1231 Pragma_Polling |
1232 Pragma_Persistent_BSS |
1233 Pragma_Postcondition |
1234 Pragma_Precondition |
1235 Pragma_Predicate |
1236 Pragma_Preelaborate |
1237 Pragma_Preelaborate_05 |
1238 Pragma_Priority |
1239 Pragma_Priority_Specific_Dispatching |
1240 Pragma_Profile |
1241 Pragma_Profile_Warnings |
1242 Pragma_Propagate_Exceptions |
1243 Pragma_Psect_Object |
1244 Pragma_Pure |
1245 Pragma_Pure_05 |
1246 Pragma_Pure_12 |
1247 Pragma_Pure_Function |
1248 Pragma_Queuing_Policy |
1249 Pragma_Relative_Deadline |
1250 Pragma_Remote_Access_Type |
1251 Pragma_Remote_Call_Interface |
1252 Pragma_Remote_Types |
1253 Pragma_Restricted_Run_Time |
1254 Pragma_Rational |
1255 Pragma_Ravenscar |
1256 Pragma_Reviewable |
1257 Pragma_Share_Generic |
1258 Pragma_Shared |
1259 Pragma_Shared_Passive |
1260 Pragma_Short_Circuit_And_Or |
1261 Pragma_Short_Descriptors |
1262 Pragma_Simple_Storage_Pool_Type |
1263 Pragma_SPARK_Mode |
1264 Pragma_Storage_Size |
1265 Pragma_Storage_Unit |
1266 Pragma_Static_Elaboration_Desired |
1267 Pragma_Stream_Convert |
1268 Pragma_Subtitle |
1269 Pragma_Suppress |
1270 Pragma_Suppress_Debug_Info |
1271 Pragma_Suppress_Exception_Locations |
1272 Pragma_Suppress_Initialization |
1273 Pragma_System_Name |
1274 Pragma_Task_Dispatching_Policy |
1275 Pragma_Task_Info |
1276 Pragma_Task_Name |
1277 Pragma_Task_Storage |
1278 Pragma_Test_Case |
1279 Pragma_Thread_Local_Storage |
1280 Pragma_Time_Slice |
1281 Pragma_Title |
1282 Pragma_Unchecked_Union |
1283 Pragma_Unimplemented_Unit |
1284 Pragma_Universal_Aliasing |
1285 Pragma_Universal_Data |
1286 Pragma_Unmodified |
1287 Pragma_Unreferenced |
1288 Pragma_Unreferenced_Objects |
1289 Pragma_Unreserve_All_Interrupts |
1290 Pragma_Unsuppress |
1291 Pragma_Use_VADS_Size |
1292 Pragma_Volatile |
1293 Pragma_Volatile_Components |
1294 Pragma_Weak_External |
1295 Pragma_Validity_Checks =>
1296 null;
1298 --------------------
1299 -- Unknown_Pragma --
1300 --------------------
1302 -- Should be impossible, since we excluded this case earlier on
1304 when Unknown_Pragma =>
1305 raise Program_Error;
1307 end case;
1309 return Pragma_Node;
1311 --------------------
1312 -- Error Handling --
1313 --------------------
1315 exception
1316 when Error_Resync =>
1317 return Error;
1319 end Prag;