PR target/16201
[official-gcc.git] / gcc / ada / par-prag.adb
blobd22c5243cee0cf78cbbe0d93229863d40af53b41
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-2004 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 -- Generally the parser checks the basic syntax of pragmas, but does not
28 -- do specialized syntax checks for individual pragmas, these are deferred
29 -- to semantic analysis time (see unit Sem_Prag). There are some pragmas
30 -- which require recognition and either partial or complete processing
31 -- during parsing, and this unit performs this required processing.
33 with Fname.UF; use Fname.UF;
34 with Osint; use Osint;
35 with Rident; use Rident;
36 with Restrict; use Restrict;
37 with Stringt; use Stringt;
38 with Stylesw; use Stylesw;
39 with Uintp; use Uintp;
40 with Uname; use Uname;
42 separate (Par)
44 function Prag (Pragma_Node : Node_Id; Semi : Source_Ptr) return Node_Id is
45 Pragma_Name : constant Name_Id := Chars (Pragma_Node);
46 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pragma_Name);
47 Pragma_Sloc : constant Source_Ptr := Sloc (Pragma_Node);
48 Arg_Count : Nat;
49 Arg_Node : Node_Id;
51 -----------------------
52 -- Local Subprograms --
53 -----------------------
55 function Arg1 return Node_Id;
56 function Arg2 return Node_Id;
57 function Arg3 return Node_Id;
58 -- Obtain specified Pragma_Argument_Association. It is allowable to call
59 -- the routine for the argument one past the last present argument, but
60 -- that is the only case in which a non-present argument can be referenced.
62 procedure Check_Arg_Count (Required : Int);
63 -- Check argument count for pragma = Required.
64 -- If not give error and raise Error_Resync.
66 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
67 -- Check the expression of the specified argument to make sure that it
68 -- is a string literal. If not give error and raise Error_Resync.
70 procedure Check_Arg_Is_On_Or_Off (Arg : Node_Id);
71 -- Check the expression of the specified argument to make sure that it
72 -- is an identifier which is either ON or OFF, and if not, then issue
73 -- an error message and raise Error_Resync.
75 procedure Check_No_Identifier (Arg : Node_Id);
76 -- Checks that the given argument does not have an identifier. If
77 -- an identifier is present, then an error message is issued, and
78 -- Error_Resync is raised.
80 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
81 -- Checks if the given argument has an identifier, and if so, requires
82 -- it to match the given identifier name. If there is a non-matching
83 -- identifier, then an error message is given and Error_Resync raised.
85 procedure Check_Required_Identifier (Arg : Node_Id; Id : Name_Id);
86 -- Same as Check_Optional_Identifier, except that the name is required
87 -- to be present and to match the given Id value.
89 procedure Process_Restrictions_Or_Restriction_Warnings;
90 -- Common processing for Restrictions and Restriction_Warnings pragmas.
91 -- This routine only processes the case of No_Obsolescent_Features,
92 -- which is the only restriction that has syntactic effects. No general
93 -- error checking is done, since this will be done in Sem_Prag. The
94 -- other case processed is pragma Restrictions No_Dependence, since
95 -- otherwise this is done too late.
97 ----------
98 -- Arg1 --
99 ----------
101 function Arg1 return Node_Id is
102 begin
103 return First (Pragma_Argument_Associations (Pragma_Node));
104 end Arg1;
106 ----------
107 -- Arg2 --
108 ----------
110 function Arg2 return Node_Id is
111 begin
112 return Next (Arg1);
113 end Arg2;
115 ----------
116 -- Arg3 --
117 ----------
119 function Arg3 return Node_Id is
120 begin
121 return Next (Arg2);
122 end Arg3;
124 ---------------------
125 -- Check_Arg_Count --
126 ---------------------
128 procedure Check_Arg_Count (Required : Int) is
129 begin
130 if Arg_Count /= Required then
131 Error_Msg ("wrong number of arguments for pragma%", Pragma_Sloc);
132 raise Error_Resync;
133 end if;
134 end Check_Arg_Count;
136 ----------------------------
137 -- Check_Arg_Is_On_Or_Off --
138 ----------------------------
140 procedure Check_Arg_Is_On_Or_Off (Arg : Node_Id) is
141 Argx : constant Node_Id := Expression (Arg);
143 begin
144 if Nkind (Expression (Arg)) /= N_Identifier
145 or else (Chars (Argx) /= Name_On
146 and then
147 Chars (Argx) /= Name_Off)
148 then
149 Error_Msg_Name_2 := Name_On;
150 Error_Msg_Name_3 := Name_Off;
152 Error_Msg
153 ("argument for pragma% must be% or%", Sloc (Argx));
154 raise Error_Resync;
155 end if;
156 end Check_Arg_Is_On_Or_Off;
158 ---------------------------------
159 -- Check_Arg_Is_String_Literal --
160 ---------------------------------
162 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
163 begin
164 if Nkind (Expression (Arg)) /= N_String_Literal then
165 Error_Msg
166 ("argument for pragma% must be string literal",
167 Sloc (Expression (Arg)));
168 raise Error_Resync;
169 end if;
170 end Check_Arg_Is_String_Literal;
172 -------------------------
173 -- Check_No_Identifier --
174 -------------------------
176 procedure Check_No_Identifier (Arg : Node_Id) is
177 begin
178 if Chars (Arg) /= No_Name then
179 Error_Msg_N ("pragma% does not permit named arguments", Arg);
180 raise Error_Resync;
181 end if;
182 end Check_No_Identifier;
184 -------------------------------
185 -- Check_Optional_Identifier --
186 -------------------------------
188 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
189 begin
190 if Present (Arg) and then Chars (Arg) /= No_Name then
191 if Chars (Arg) /= Id then
192 Error_Msg_Name_2 := Id;
193 Error_Msg_N ("pragma% argument expects identifier%", Arg);
194 end if;
195 end if;
196 end Check_Optional_Identifier;
198 -------------------------------
199 -- Check_Required_Identifier --
200 -------------------------------
202 procedure Check_Required_Identifier (Arg : Node_Id; Id : Name_Id) is
203 begin
204 if Chars (Arg) /= Id then
205 Error_Msg_Name_2 := Id;
206 Error_Msg_N ("pragma% argument must have identifier%", Arg);
207 end if;
208 end Check_Required_Identifier;
210 --------------------------------------------------
211 -- Process_Restrictions_Or_Restriction_Warnings --
212 --------------------------------------------------
214 procedure Process_Restrictions_Or_Restriction_Warnings is
215 Arg : Node_Id;
216 Id : Name_Id;
217 Expr : Node_Id;
219 begin
220 Arg := Arg1;
221 while Present (Arg) loop
222 Id := Chars (Arg);
223 Expr := Expression (Arg);
225 if Id = No_Name
226 and then Nkind (Expr) = N_Identifier
227 and then Get_Restriction_Id (Chars (Expr)) = No_Obsolescent_Features
228 then
229 Set_Restriction (No_Obsolescent_Features, Pragma_Node);
230 Restriction_Warnings (No_Obsolescent_Features) :=
231 Prag_Id = Pragma_Restriction_Warnings;
233 elsif Id = Name_No_Dependence then
234 Set_Restriction_No_Dependence
235 (Unit => Expr,
236 Warn => Prag_Id = Pragma_Restriction_Warnings);
237 end if;
239 Next (Arg);
240 end loop;
241 end Process_Restrictions_Or_Restriction_Warnings;
243 -- Start if processing for Prag
245 begin
246 Error_Msg_Name_1 := Pragma_Name;
248 -- Ignore unrecognized pragma. We let Sem post the warning for this, since
249 -- it is a semantic error, not a syntactic one (we have already checked
250 -- the syntax for the unrecognized pragma as required by (RM 2.8(11)).
252 if Prag_Id = Unknown_Pragma then
253 return Pragma_Node;
254 end if;
256 -- Count number of arguments. This loop also checks if any of the arguments
257 -- are Error, indicating a syntax error as they were parsed. If so, we
258 -- simply return, because we get into trouble with cascaded errors if we
259 -- try to perform our error checks on junk arguments.
261 Arg_Count := 0;
263 if Present (Pragma_Argument_Associations (Pragma_Node)) then
264 Arg_Node := Arg1;
266 while Arg_Node /= Empty loop
267 Arg_Count := Arg_Count + 1;
269 if Expression (Arg_Node) = Error then
270 return Error;
271 end if;
273 Next (Arg_Node);
274 end loop;
275 end if;
277 -- Remaining processing is pragma dependent
279 case Prag_Id is
281 ------------
282 -- Ada_83 --
283 ------------
285 -- This pragma must be processed at parse time, since we want to set
286 -- the Ada version properly at parse time to recognize the appropriate
287 -- Ada version syntax.
289 when Pragma_Ada_83 =>
290 Ada_Version := Ada_83;
292 ------------
293 -- Ada_95 --
294 ------------
296 -- This pragma must be processed at parse time, since we want to set
297 -- the Ada version properly at parse time to recognize the appropriate
298 -- Ada version syntax.
300 when Pragma_Ada_95 =>
301 Ada_Version := Ada_95;
303 ------------
304 -- Ada_05 --
305 ------------
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_05 =>
312 Ada_Version := Ada_05;
314 -----------
315 -- Debug --
316 -----------
318 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
320 -- This has to be processed by the parser because of the very peculiar
321 -- form of the second parameter, which is syntactically from a formal
322 -- point of view a function call (since it must be an expression), but
323 -- semantically we treat it as a procedure call (which has exactly the
324 -- same syntactic form, so that's why we can get away with this!)
326 when Pragma_Debug =>
327 Check_Arg_Count (1);
328 Check_No_Identifier (Arg1);
330 declare
331 Expr : constant Node_Id := New_Copy (Expression (Arg1));
333 begin
334 if Nkind (Expr) /= N_Indexed_Component
335 and then Nkind (Expr) /= N_Function_Call
336 and then Nkind (Expr) /= N_Identifier
337 and then Nkind (Expr) /= N_Selected_Component
338 then
339 Error_Msg
340 ("argument of pragma% is not procedure call", Sloc (Expr));
341 raise Error_Resync;
342 else
343 Set_Debug_Statement
344 (Pragma_Node, P_Statement_Name (Expr));
345 end if;
346 end;
348 -------------------------------
349 -- Extensions_Allowed (GNAT) --
350 -------------------------------
352 -- pragma Extensions_Allowed (Off | On)
354 -- The processing for pragma Extensions_Allowed must be done at
355 -- parse time, since extensions mode may affect what is accepted.
357 when Pragma_Extensions_Allowed =>
358 Check_Arg_Count (1);
359 Check_No_Identifier (Arg1);
360 Check_Arg_Is_On_Or_Off (Arg1);
362 if Chars (Expression (Arg1)) = Name_On then
363 Extensions_Allowed := True;
364 Ada_Version := Ada_Version_Type'Last;
365 else
366 Extensions_Allowed := False;
367 Ada_Version := Ada_Version_Type'Min (Ada_Version, Ada_95);
368 end if;
370 ----------------
371 -- List (2.8) --
372 ----------------
374 -- pragma List (Off | On)
376 -- The processing for pragma List must be done at parse time,
377 -- since a listing can be generated in parse only mode.
379 when Pragma_List =>
380 Check_Arg_Count (1);
381 Check_No_Identifier (Arg1);
382 Check_Arg_Is_On_Or_Off (Arg1);
384 -- We unconditionally make a List_On entry for the pragma, so that
385 -- in the List (Off) case, the pragma will print even in a region
386 -- of code with listing turned off (this is required!)
388 List_Pragmas.Increment_Last;
389 List_Pragmas.Table (List_Pragmas.Last) :=
390 (Ptyp => List_On, Ploc => Sloc (Pragma_Node));
392 -- Now generate the list off entry for pragma List (Off)
394 if Chars (Expression (Arg1)) = Name_Off then
395 List_Pragmas.Increment_Last;
396 List_Pragmas.Table (List_Pragmas.Last) :=
397 (Ptyp => List_Off, Ploc => Semi);
398 end if;
400 ----------------
401 -- Page (2.8) --
402 ----------------
404 -- pragma Page;
406 -- Processing for this pragma must be done at parse time, since a
407 -- listing can be generated in parse only mode with semantics off.
409 when Pragma_Page =>
410 Check_Arg_Count (0);
411 List_Pragmas.Increment_Last;
412 List_Pragmas.Table (List_Pragmas.Last) := (Page, Semi);
414 ------------------
415 -- Restrictions --
416 ------------------
418 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
420 -- RESTRICTION ::=
421 -- restriction_IDENTIFIER
422 -- | restriction_parameter_IDENTIFIER => EXPRESSION
424 -- We process the case of No_Obsolescent_Features, since this has
425 -- a syntactic effect that we need to detect at parse time (the use
426 -- of replacement characters such as colon for pound sign).
428 when Pragma_Restrictions =>
429 Process_Restrictions_Or_Restriction_Warnings;
431 --------------------------
432 -- Restriction_Warnings --
433 --------------------------
435 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
437 -- RESTRICTION ::=
438 -- restriction_IDENTIFIER
439 -- | restriction_parameter_IDENTIFIER => EXPRESSION
441 -- See above comment for pragma Restrictions
443 when Pragma_Restriction_Warnings =>
444 Process_Restrictions_Or_Restriction_Warnings;
446 ----------------------------------------------------------
447 -- Source_File_Name and Source_File_Name_Project (GNAT) --
448 ----------------------------------------------------------
450 -- These two pragmas have the same syntax and semantics.
451 -- There are five forms of these pragmas:
453 -- pragma Source_File_Name[_Project] (
454 -- [UNIT_NAME =>] unit_NAME,
455 -- BODY_FILE_NAME => STRING_LITERAL
456 -- [, [INDEX =>] INTEGER_LITERAL]);
458 -- pragma Source_File_Name[_Project] (
459 -- [UNIT_NAME =>] unit_NAME,
460 -- SPEC_FILE_NAME => STRING_LITERAL
461 -- [, [INDEX =>] INTEGER_LITERAL]);
463 -- pragma Source_File_Name[_Project] (
464 -- BODY_FILE_NAME => STRING_LITERAL
465 -- [, DOT_REPLACEMENT => STRING_LITERAL]
466 -- [, CASING => CASING_SPEC]);
468 -- pragma Source_File_Name[_Project] (
469 -- SPEC_FILE_NAME => STRING_LITERAL
470 -- [, DOT_REPLACEMENT => STRING_LITERAL]
471 -- [, CASING => CASING_SPEC]);
473 -- pragma Source_File_Name[_Project] (
474 -- SUBUNIT_FILE_NAME => STRING_LITERAL
475 -- [, DOT_REPLACEMENT => STRING_LITERAL]
476 -- [, CASING => CASING_SPEC]);
478 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
480 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
481 -- Source_File_Name (SFN), however their usage is exclusive:
482 -- SFN can only be used when no project file is used, while
483 -- SFNP can only be used when a project file is used.
485 -- The Project Manager produces a configuration pragmas file that
486 -- is communicated to the compiler with -gnatec switch. This file
487 -- contains only SFNP pragmas (at least two for the default naming
488 -- scheme. As this configuration pragmas file is always the first
489 -- processed by the compiler, it prevents the use of pragmas SFN in
490 -- other config files when a project file is in use.
492 -- Note: we process this during parsing, since we need to have the
493 -- source file names set well before the semantic analysis starts,
494 -- since we load the spec and with'ed packages before analysis.
496 when Pragma_Source_File_Name | Pragma_Source_File_Name_Project =>
497 Source_File_Name : declare
498 Unam : Unit_Name_Type;
499 Expr1 : Node_Id;
500 Pat : String_Ptr;
501 Typ : Character;
502 Dot : String_Ptr;
503 Cas : Casing_Type;
504 Nast : Nat;
505 Expr : Node_Id;
506 Index : Nat;
508 function Get_Fname (Arg : Node_Id) return Name_Id;
509 -- Process file name from unit name form of pragma
511 function Get_String_Argument (Arg : Node_Id) return String_Ptr;
512 -- Process string literal value from argument
514 procedure Process_Casing (Arg : Node_Id);
515 -- Process Casing argument of pattern form of pragma
517 procedure Process_Dot_Replacement (Arg : Node_Id);
518 -- Process Dot_Replacement argument of patterm form of pragma
520 ---------------
521 -- Get_Fname --
522 ---------------
524 function Get_Fname (Arg : Node_Id) return Name_Id is
525 begin
526 String_To_Name_Buffer (Strval (Expression (Arg)));
528 for J in 1 .. Name_Len loop
529 if Is_Directory_Separator (Name_Buffer (J)) then
530 Error_Msg
531 ("directory separator character not allowed",
532 Sloc (Expression (Arg)) + Source_Ptr (J));
533 end if;
534 end loop;
536 return Name_Find;
537 end Get_Fname;
539 -------------------------
540 -- Get_String_Argument --
541 -------------------------
543 function Get_String_Argument (Arg : Node_Id) return String_Ptr is
544 Str : String_Id;
546 begin
547 if Nkind (Expression (Arg)) /= N_String_Literal
548 and then
549 Nkind (Expression (Arg)) /= N_Operator_Symbol
550 then
551 Error_Msg_N
552 ("argument for pragma% must be string literal", Arg);
553 raise Error_Resync;
554 end if;
556 Str := Strval (Expression (Arg));
558 -- Check string has no wide chars
560 for J in 1 .. String_Length (Str) loop
561 if Get_String_Char (Str, J) > 255 then
562 Error_Msg
563 ("wide character not allowed in pattern for pragma%",
564 Sloc (Expression (Arg2)) + Text_Ptr (J) - 1);
565 end if;
566 end loop;
568 -- Acquire string
570 String_To_Name_Buffer (Str);
571 return new String'(Name_Buffer (1 .. Name_Len));
572 end Get_String_Argument;
574 --------------------
575 -- Process_Casing --
576 --------------------
578 procedure Process_Casing (Arg : Node_Id) is
579 Expr : constant Node_Id := Expression (Arg);
581 begin
582 Check_Required_Identifier (Arg, Name_Casing);
584 if Nkind (Expr) = N_Identifier then
585 if Chars (Expr) = Name_Lowercase then
586 Cas := All_Lower_Case;
587 return;
588 elsif Chars (Expr) = Name_Uppercase then
589 Cas := All_Upper_Case;
590 return;
591 elsif Chars (Expr) = Name_Mixedcase then
592 Cas := Mixed_Case;
593 return;
594 end if;
595 end if;
597 Error_Msg_N
598 ("Casing argument for pragma% must be " &
599 "one of Mixedcase, Lowercase, Uppercase",
600 Arg);
601 end Process_Casing;
603 -----------------------------
604 -- Process_Dot_Replacement --
605 -----------------------------
607 procedure Process_Dot_Replacement (Arg : Node_Id) is
608 begin
609 Check_Required_Identifier (Arg, Name_Dot_Replacement);
610 Dot := Get_String_Argument (Arg);
611 end Process_Dot_Replacement;
613 -- Start of processing for Source_File_Name and
614 -- Source_File_Name_Project pragmas.
616 begin
617 if Get_Pragma_Id (Pragma_Name) = Pragma_Source_File_Name then
618 if Project_File_In_Use = In_Use then
619 Error_Msg
620 ("pragma Source_File_Name cannot be used " &
621 "with a project file", Pragma_Sloc);
623 else
624 Project_File_In_Use := Not_In_Use;
625 end if;
627 else
628 if Project_File_In_Use = Not_In_Use then
629 Error_Msg
630 ("pragma Source_File_Name_Project should only be used " &
631 "with a project file", Pragma_Sloc);
632 else
633 Project_File_In_Use := In_Use;
634 end if;
635 end if;
637 -- We permit from 1 to 3 arguments
639 if Arg_Count not in 1 .. 3 then
640 Check_Arg_Count (1);
641 end if;
643 Expr1 := Expression (Arg1);
645 -- If first argument is identifier or selected component, then
646 -- we have the specific file case of the Source_File_Name pragma,
647 -- and the first argument is a unit name.
649 if Nkind (Expr1) = N_Identifier
650 or else
651 (Nkind (Expr1) = N_Selected_Component
652 and then
653 Nkind (Selector_Name (Expr1)) = N_Identifier)
654 then
655 if Nkind (Expr1) = N_Identifier
656 and then Chars (Expr1) = Name_System
657 then
658 Error_Msg_N
659 ("pragma Source_File_Name may not be used for System",
660 Arg1);
661 return Error;
662 end if;
664 -- Process index argument if present
666 if Arg_Count = 3 then
667 Expr := Expression (Arg3);
669 if Nkind (Expr) /= N_Integer_Literal
670 or else not UI_Is_In_Int_Range (Intval (Expr))
671 or else Intval (Expr) > 999
672 or else Intval (Expr) <= 0
673 then
674 Error_Msg
675 ("pragma% index must be integer literal" &
676 " in range 1 .. 999", Sloc (Expr));
677 raise Error_Resync;
678 else
679 Index := UI_To_Int (Intval (Expr));
680 end if;
682 -- No index argument present
684 else
685 Check_Arg_Count (2);
686 Index := 0;
687 end if;
689 Check_Optional_Identifier (Arg1, Name_Unit_Name);
690 Unam := Get_Unit_Name (Expr1);
692 Check_Arg_Is_String_Literal (Arg2);
694 if Chars (Arg2) = Name_Spec_File_Name then
695 Set_File_Name
696 (Get_Spec_Name (Unam), Get_Fname (Arg2), Index);
698 elsif Chars (Arg2) = Name_Body_File_Name then
699 Set_File_Name
700 (Unam, Get_Fname (Arg2), Index);
702 else
703 Error_Msg_N
704 ("pragma% argument has incorrect identifier", Arg2);
705 return Pragma_Node;
706 end if;
708 -- If the first argument is not an identifier, then we must have
709 -- the pattern form of the pragma, and the first argument must be
710 -- the pattern string with an appropriate name.
712 else
713 if Chars (Arg1) = Name_Spec_File_Name then
714 Typ := 's';
716 elsif Chars (Arg1) = Name_Body_File_Name then
717 Typ := 'b';
719 elsif Chars (Arg1) = Name_Subunit_File_Name then
720 Typ := 'u';
722 elsif Chars (Arg1) = Name_Unit_Name then
723 Error_Msg_N
724 ("Unit_Name parameter for pragma% must be an identifier",
725 Arg1);
726 raise Error_Resync;
728 else
729 Error_Msg_N
730 ("pragma% argument has incorrect identifier", Arg1);
731 raise Error_Resync;
732 end if;
734 Pat := Get_String_Argument (Arg1);
736 -- Check pattern has exactly one asterisk
738 Nast := 0;
739 for J in Pat'Range loop
740 if Pat (J) = '*' then
741 Nast := Nast + 1;
742 end if;
743 end loop;
745 if Nast /= 1 then
746 Error_Msg_N
747 ("file name pattern must have exactly one * character",
748 Arg1);
749 return Pragma_Node;
750 end if;
752 -- Set defaults for Casing and Dot_Separator parameters
754 Cas := All_Lower_Case;
755 Dot := new String'(".");
757 -- Process second and third arguments if present
759 if Arg_Count > 1 then
760 if Chars (Arg2) = Name_Casing then
761 Process_Casing (Arg2);
763 if Arg_Count = 3 then
764 Process_Dot_Replacement (Arg3);
765 end if;
767 else
768 Process_Dot_Replacement (Arg2);
770 if Arg_Count = 3 then
771 Process_Casing (Arg3);
772 end if;
773 end if;
774 end if;
776 Set_File_Name_Pattern (Pat, Typ, Dot, Cas);
777 end if;
778 end Source_File_Name;
780 -----------------------------
781 -- Source_Reference (GNAT) --
782 -----------------------------
784 -- pragma Source_Reference
785 -- (INTEGER_LITERAL [, STRING_LITERAL] );
787 -- Processing for this pragma must be done at parse time, since error
788 -- messages needing the proper line numbers can be generated in parse
789 -- only mode with semantic checking turned off, and indeed we usually
790 -- turn off semantic checking anyway if any parse errors are found.
792 when Pragma_Source_Reference => Source_Reference : declare
793 Fname : Name_Id;
795 begin
796 if Arg_Count /= 1 then
797 Check_Arg_Count (2);
798 Check_No_Identifier (Arg2);
799 end if;
801 -- Check that this is first line of file. We skip this test if
802 -- we are in syntax check only mode, since we may be dealing with
803 -- multiple compilation units.
805 if Get_Physical_Line_Number (Pragma_Sloc) /= 1
806 and then Num_SRef_Pragmas (Current_Source_File) = 0
807 and then Operating_Mode /= Check_Syntax
808 then
809 Error_Msg
810 ("first % pragma must be first line of file", Pragma_Sloc);
811 raise Error_Resync;
812 end if;
814 Check_No_Identifier (Arg1);
816 if Arg_Count = 1 then
817 if Num_SRef_Pragmas (Current_Source_File) = 0 then
818 Error_Msg
819 ("file name required for first % pragma in file",
820 Pragma_Sloc);
821 raise Error_Resync;
822 else
823 Fname := No_Name;
824 end if;
826 -- File name present
828 else
829 Check_Arg_Is_String_Literal (Arg2);
830 String_To_Name_Buffer (Strval (Expression (Arg2)));
831 Fname := Name_Find;
833 if Num_SRef_Pragmas (Current_Source_File) > 0 then
834 if Fname /= Full_Ref_Name (Current_Source_File) then
835 Error_Msg
836 ("file name must be same in all % pragmas", Pragma_Sloc);
837 raise Error_Resync;
838 end if;
839 end if;
840 end if;
842 if Nkind (Expression (Arg1)) /= N_Integer_Literal then
843 Error_Msg
844 ("argument for pragma% must be integer literal",
845 Sloc (Expression (Arg1)));
846 raise Error_Resync;
848 -- OK, this source reference pragma is effective, however, we
849 -- ignore it if it is not in the first unit in the multiple unit
850 -- case. This is because the only purpose in this case is to
851 -- provide source pragmas for subsequent use by gnatchop.
853 else
854 if Num_Library_Units = 1 then
855 Register_Source_Ref_Pragma
856 (Fname,
857 Strip_Directory (Fname),
858 UI_To_Int (Intval (Expression (Arg1))),
859 Get_Physical_Line_Number (Pragma_Sloc) + 1);
860 end if;
861 end if;
862 end Source_Reference;
864 -------------------------
865 -- Style_Checks (GNAT) --
866 -------------------------
868 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
870 -- This is processed by the parser since some of the style
871 -- checks take place during source scanning and parsing.
873 when Pragma_Style_Checks => Style_Checks : declare
874 A : Node_Id;
875 S : String_Id;
876 C : Char_Code;
877 OK : Boolean := True;
879 begin
880 -- Two argument case is only for semantics
882 if Arg_Count = 2 then
883 null;
885 else
886 Check_Arg_Count (1);
887 Check_No_Identifier (Arg1);
888 A := Expression (Arg1);
890 if Nkind (A) = N_String_Literal then
891 S := Strval (A);
893 declare
894 Slen : constant Natural := Natural (String_Length (S));
895 Options : String (1 .. Slen);
896 J : Natural;
897 Ptr : Natural;
899 begin
900 J := 1;
901 loop
902 C := Get_String_Char (S, Int (J));
904 if not In_Character_Range (C) then
905 OK := False;
906 Ptr := J;
907 exit;
909 else
910 Options (J) := Get_Character (C);
911 end if;
913 if J = Slen then
914 Set_Style_Check_Options (Options, OK, Ptr);
915 exit;
917 else
918 J := J + 1;
919 end if;
920 end loop;
922 if not OK then
923 Error_Msg
924 ("invalid style check option",
925 Sloc (Expression (Arg1)) + Source_Ptr (Ptr));
926 raise Error_Resync;
927 end if;
928 end;
930 elsif Nkind (A) /= N_Identifier then
931 OK := False;
933 elsif Chars (A) = Name_All_Checks then
934 Stylesw.Set_Default_Style_Check_Options;
936 elsif Chars (A) = Name_On then
937 Style_Check := True;
939 elsif Chars (A) = Name_Off then
940 Style_Check := False;
942 else
943 OK := False;
944 end if;
946 if not OK then
947 Error_Msg ("incorrect argument for pragma%", Sloc (A));
948 raise Error_Resync;
949 end if;
950 end if;
951 end Style_Checks;
953 ---------------------
954 -- Warnings (GNAT) --
955 ---------------------
957 -- pragma Warnings (On | Off, [LOCAL_NAME])
959 -- The one argument case is processed by the parser, since it may
960 -- control parser warnings as well as semantic warnings, and in any
961 -- case we want to be absolutely sure that the range in the warnings
962 -- table is set well before any semantic analysis is performed.
964 when Pragma_Warnings =>
965 if Arg_Count = 1 then
966 Check_No_Identifier (Arg1);
967 Check_Arg_Is_On_Or_Off (Arg1);
969 if Chars (Expression (Arg1)) = Name_On then
970 Set_Warnings_Mode_On (Pragma_Sloc);
971 else
972 Set_Warnings_Mode_Off (Pragma_Sloc);
973 end if;
974 end if;
976 -----------------------
977 -- All Other Pragmas --
978 -----------------------
980 -- For all other pragmas, checking and processing is handled
981 -- entirely in Sem_Prag, and no further checking is done by Par.
983 when Pragma_Abort_Defer |
984 Pragma_AST_Entry |
985 Pragma_All_Calls_Remote |
986 Pragma_Annotate |
987 Pragma_Assert |
988 Pragma_Asynchronous |
989 Pragma_Atomic |
990 Pragma_Atomic_Components |
991 Pragma_Attach_Handler |
992 Pragma_Compile_Time_Warning |
993 Pragma_Convention_Identifier |
994 Pragma_CPP_Class |
995 Pragma_CPP_Constructor |
996 Pragma_CPP_Virtual |
997 Pragma_CPP_Vtable |
998 Pragma_C_Pass_By_Copy |
999 Pragma_Comment |
1000 Pragma_Common_Object |
1001 Pragma_Complex_Representation |
1002 Pragma_Component_Alignment |
1003 Pragma_Controlled |
1004 Pragma_Convention |
1005 Pragma_Detect_Blocking |
1006 Pragma_Discard_Names |
1007 Pragma_Eliminate |
1008 Pragma_Elaborate |
1009 Pragma_Elaborate_All |
1010 Pragma_Elaborate_Body |
1011 Pragma_Elaboration_Checks |
1012 Pragma_Explicit_Overriding |
1013 Pragma_Export |
1014 Pragma_Export_Exception |
1015 Pragma_Export_Function |
1016 Pragma_Export_Object |
1017 Pragma_Export_Procedure |
1018 Pragma_Export_Value |
1019 Pragma_Export_Valued_Procedure |
1020 Pragma_Extend_System |
1021 Pragma_External |
1022 Pragma_External_Name_Casing |
1023 Pragma_Finalize_Storage_Only |
1024 Pragma_Float_Representation |
1025 Pragma_Ident |
1026 Pragma_Import |
1027 Pragma_Import_Exception |
1028 Pragma_Import_Function |
1029 Pragma_Import_Object |
1030 Pragma_Import_Procedure |
1031 Pragma_Import_Valued_Procedure |
1032 Pragma_Initialize_Scalars |
1033 Pragma_Inline |
1034 Pragma_Inline_Always |
1035 Pragma_Inline_Generic |
1036 Pragma_Inspection_Point |
1037 Pragma_Interface |
1038 Pragma_Interface_Name |
1039 Pragma_Interrupt_Handler |
1040 Pragma_Interrupt_State |
1041 Pragma_Interrupt_Priority |
1042 Pragma_Java_Constructor |
1043 Pragma_Java_Interface |
1044 Pragma_Keep_Names |
1045 Pragma_License |
1046 Pragma_Link_With |
1047 Pragma_Linker_Alias |
1048 Pragma_Linker_Options |
1049 Pragma_Linker_Section |
1050 Pragma_Locking_Policy |
1051 Pragma_Long_Float |
1052 Pragma_Machine_Attribute |
1053 Pragma_Main |
1054 Pragma_Main_Storage |
1055 Pragma_Memory_Size |
1056 Pragma_No_Return |
1057 Pragma_Obsolescent |
1058 Pragma_No_Run_Time |
1059 Pragma_No_Strict_Aliasing |
1060 Pragma_Normalize_Scalars |
1061 Pragma_Optimize |
1062 Pragma_Optional_Overriding |
1063 Pragma_Overriding |
1064 Pragma_Pack |
1065 Pragma_Passive |
1066 Pragma_Polling |
1067 Pragma_Persistent_Data |
1068 Pragma_Persistent_Object |
1069 Pragma_Preelaborate |
1070 Pragma_Priority |
1071 Pragma_Profile |
1072 Pragma_Profile_Warnings |
1073 Pragma_Propagate_Exceptions |
1074 Pragma_Psect_Object |
1075 Pragma_Pure |
1076 Pragma_Pure_Function |
1077 Pragma_Queuing_Policy |
1078 Pragma_Remote_Call_Interface |
1079 Pragma_Remote_Types |
1080 Pragma_Restricted_Run_Time |
1081 Pragma_Ravenscar |
1082 Pragma_Reviewable |
1083 Pragma_Share_Generic |
1084 Pragma_Shared |
1085 Pragma_Shared_Passive |
1086 Pragma_Storage_Size |
1087 Pragma_Storage_Unit |
1088 Pragma_Stream_Convert |
1089 Pragma_Subtitle |
1090 Pragma_Suppress |
1091 Pragma_Suppress_All |
1092 Pragma_Suppress_Debug_Info |
1093 Pragma_Suppress_Exception_Locations |
1094 Pragma_Suppress_Initialization |
1095 Pragma_System_Name |
1096 Pragma_Task_Dispatching_Policy |
1097 Pragma_Task_Info |
1098 Pragma_Task_Name |
1099 Pragma_Task_Storage |
1100 Pragma_Thread_Body |
1101 Pragma_Time_Slice |
1102 Pragma_Title |
1103 Pragma_Unchecked_Union |
1104 Pragma_Unimplemented_Unit |
1105 Pragma_Universal_Data |
1106 Pragma_Unreferenced |
1107 Pragma_Unreserve_All_Interrupts |
1108 Pragma_Unsuppress |
1109 Pragma_Use_VADS_Size |
1110 Pragma_Volatile |
1111 Pragma_Volatile_Components |
1112 Pragma_Weak_External |
1113 Pragma_Validity_Checks =>
1114 null;
1116 --------------------
1117 -- Unknown_Pragma --
1118 --------------------
1120 -- Should be impossible, since we excluded this case earlier on
1122 when Unknown_Pragma =>
1123 raise Program_Error;
1125 end case;
1127 return Pragma_Node;
1129 --------------------
1130 -- Error Handling --
1131 --------------------
1133 exception
1134 when Error_Resync =>
1135 return Error;
1137 end Prag;