Merge form mainline (hopefully)
[official-gcc.git] / gcc / ada / par-prag.adb
blob097ddd0caf342a539d09dc6b1ee23fa2adaabe0a
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-2005 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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;
291 Ada_Version_Explicit := Ada_Version;
293 ------------
294 -- Ada_95 --
295 ------------
297 -- This pragma must be processed at parse time, since we want to set
298 -- the Ada version properly at parse time to recognize the appropriate
299 -- Ada version syntax.
301 when Pragma_Ada_95 =>
302 Ada_Version := Ada_95;
303 Ada_Version_Explicit := Ada_Version;
305 ------------
306 -- Ada_05 --
307 ------------
309 -- This pragma must be processed at parse time, since we want to set
310 -- the Ada version properly at parse time to recognize the appropriate
311 -- Ada version syntax. However, it is only the zero argument form that
312 -- must be processed at parse time.
314 when Pragma_Ada_05 =>
315 if Arg_Count = 0 then
316 Ada_Version := Ada_05;
317 Ada_Version_Explicit := Ada_Version;
318 end if;
320 -----------
321 -- Debug --
322 -----------
324 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
326 -- This has to be processed by the parser because of the very peculiar
327 -- form of the second parameter, which is syntactically from a formal
328 -- point of view a function call (since it must be an expression), but
329 -- semantically we treat it as a procedure call (which has exactly the
330 -- same syntactic form, so that's why we can get away with this!)
332 when Pragma_Debug =>
333 Check_Arg_Count (1);
334 Check_No_Identifier (Arg1);
336 declare
337 Expr : constant Node_Id := New_Copy (Expression (Arg1));
339 begin
340 if Nkind (Expr) /= N_Indexed_Component
341 and then Nkind (Expr) /= N_Function_Call
342 and then Nkind (Expr) /= N_Identifier
343 and then Nkind (Expr) /= N_Selected_Component
344 then
345 Error_Msg
346 ("argument of pragma% is not procedure call", Sloc (Expr));
347 raise Error_Resync;
348 else
349 Set_Debug_Statement
350 (Pragma_Node, P_Statement_Name (Expr));
351 end if;
352 end;
354 -------------------------------
355 -- Extensions_Allowed (GNAT) --
356 -------------------------------
358 -- pragma Extensions_Allowed (Off | On)
360 -- The processing for pragma Extensions_Allowed must be done at
361 -- parse time, since extensions mode may affect what is accepted.
363 when Pragma_Extensions_Allowed =>
364 Check_Arg_Count (1);
365 Check_No_Identifier (Arg1);
366 Check_Arg_Is_On_Or_Off (Arg1);
368 if Chars (Expression (Arg1)) = Name_On then
369 Extensions_Allowed := True;
370 Ada_Version := Ada_Version_Type'Last;
371 else
372 Extensions_Allowed := False;
373 Ada_Version := Ada_Version_Type'Min (Ada_Version, Ada_95);
374 end if;
376 Ada_Version_Explicit := Ada_Version;
378 ----------------
379 -- List (2.8) --
380 ----------------
382 -- pragma List (Off | On)
384 -- The processing for pragma List must be done at parse time,
385 -- since a listing can be generated in parse only mode.
387 when Pragma_List =>
388 Check_Arg_Count (1);
389 Check_No_Identifier (Arg1);
390 Check_Arg_Is_On_Or_Off (Arg1);
392 -- We unconditionally make a List_On entry for the pragma, so that
393 -- in the List (Off) case, the pragma will print even in a region
394 -- of code with listing turned off (this is required!)
396 List_Pragmas.Increment_Last;
397 List_Pragmas.Table (List_Pragmas.Last) :=
398 (Ptyp => List_On, Ploc => Sloc (Pragma_Node));
400 -- Now generate the list off entry for pragma List (Off)
402 if Chars (Expression (Arg1)) = Name_Off then
403 List_Pragmas.Increment_Last;
404 List_Pragmas.Table (List_Pragmas.Last) :=
405 (Ptyp => List_Off, Ploc => Semi);
406 end if;
408 ----------------
409 -- Page (2.8) --
410 ----------------
412 -- pragma Page;
414 -- Processing for this pragma must be done at parse time, since a
415 -- listing can be generated in parse only mode with semantics off.
417 when Pragma_Page =>
418 Check_Arg_Count (0);
419 List_Pragmas.Increment_Last;
420 List_Pragmas.Table (List_Pragmas.Last) := (Page, Semi);
422 ------------------
423 -- Restrictions --
424 ------------------
426 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
428 -- RESTRICTION ::=
429 -- restriction_IDENTIFIER
430 -- | restriction_parameter_IDENTIFIER => EXPRESSION
432 -- We process the case of No_Obsolescent_Features, since this has
433 -- a syntactic effect that we need to detect at parse time (the use
434 -- of replacement characters such as colon for pound sign).
436 when Pragma_Restrictions =>
437 Process_Restrictions_Or_Restriction_Warnings;
439 --------------------------
440 -- Restriction_Warnings --
441 --------------------------
443 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
445 -- RESTRICTION ::=
446 -- restriction_IDENTIFIER
447 -- | restriction_parameter_IDENTIFIER => EXPRESSION
449 -- See above comment for pragma Restrictions
451 when Pragma_Restriction_Warnings =>
452 Process_Restrictions_Or_Restriction_Warnings;
454 ----------------------------------------------------------
455 -- Source_File_Name and Source_File_Name_Project (GNAT) --
456 ----------------------------------------------------------
458 -- These two pragmas have the same syntax and semantics.
459 -- There are five forms of these pragmas:
461 -- pragma Source_File_Name[_Project] (
462 -- [UNIT_NAME =>] unit_NAME,
463 -- BODY_FILE_NAME => STRING_LITERAL
464 -- [, [INDEX =>] INTEGER_LITERAL]);
466 -- pragma Source_File_Name[_Project] (
467 -- [UNIT_NAME =>] unit_NAME,
468 -- SPEC_FILE_NAME => STRING_LITERAL
469 -- [, [INDEX =>] INTEGER_LITERAL]);
471 -- pragma Source_File_Name[_Project] (
472 -- BODY_FILE_NAME => STRING_LITERAL
473 -- [, DOT_REPLACEMENT => STRING_LITERAL]
474 -- [, CASING => CASING_SPEC]);
476 -- pragma Source_File_Name[_Project] (
477 -- SPEC_FILE_NAME => STRING_LITERAL
478 -- [, DOT_REPLACEMENT => STRING_LITERAL]
479 -- [, CASING => CASING_SPEC]);
481 -- pragma Source_File_Name[_Project] (
482 -- SUBUNIT_FILE_NAME => STRING_LITERAL
483 -- [, DOT_REPLACEMENT => STRING_LITERAL]
484 -- [, CASING => CASING_SPEC]);
486 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
488 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
489 -- Source_File_Name (SFN), however their usage is exclusive:
490 -- SFN can only be used when no project file is used, while
491 -- SFNP can only be used when a project file is used.
493 -- The Project Manager produces a configuration pragmas file that
494 -- is communicated to the compiler with -gnatec switch. This file
495 -- contains only SFNP pragmas (at least two for the default naming
496 -- scheme. As this configuration pragmas file is always the first
497 -- processed by the compiler, it prevents the use of pragmas SFN in
498 -- other config files when a project file is in use.
500 -- Note: we process this during parsing, since we need to have the
501 -- source file names set well before the semantic analysis starts,
502 -- since we load the spec and with'ed packages before analysis.
504 when Pragma_Source_File_Name | Pragma_Source_File_Name_Project =>
505 Source_File_Name : declare
506 Unam : Unit_Name_Type;
507 Expr1 : Node_Id;
508 Pat : String_Ptr;
509 Typ : Character;
510 Dot : String_Ptr;
511 Cas : Casing_Type;
512 Nast : Nat;
513 Expr : Node_Id;
514 Index : Nat;
516 function Get_Fname (Arg : Node_Id) return Name_Id;
517 -- Process file name from unit name form of pragma
519 function Get_String_Argument (Arg : Node_Id) return String_Ptr;
520 -- Process string literal value from argument
522 procedure Process_Casing (Arg : Node_Id);
523 -- Process Casing argument of pattern form of pragma
525 procedure Process_Dot_Replacement (Arg : Node_Id);
526 -- Process Dot_Replacement argument of patterm form of pragma
528 ---------------
529 -- Get_Fname --
530 ---------------
532 function Get_Fname (Arg : Node_Id) return Name_Id is
533 begin
534 String_To_Name_Buffer (Strval (Expression (Arg)));
536 for J in 1 .. Name_Len loop
537 if Is_Directory_Separator (Name_Buffer (J)) then
538 Error_Msg
539 ("directory separator character not allowed",
540 Sloc (Expression (Arg)) + Source_Ptr (J));
541 end if;
542 end loop;
544 return Name_Find;
545 end Get_Fname;
547 -------------------------
548 -- Get_String_Argument --
549 -------------------------
551 function Get_String_Argument (Arg : Node_Id) return String_Ptr is
552 Str : String_Id;
554 begin
555 if Nkind (Expression (Arg)) /= N_String_Literal
556 and then
557 Nkind (Expression (Arg)) /= N_Operator_Symbol
558 then
559 Error_Msg_N
560 ("argument for pragma% must be string literal", Arg);
561 raise Error_Resync;
562 end if;
564 Str := Strval (Expression (Arg));
566 -- Check string has no wide chars
568 for J in 1 .. String_Length (Str) loop
569 if Get_String_Char (Str, J) > 255 then
570 Error_Msg
571 ("wide character not allowed in pattern for pragma%",
572 Sloc (Expression (Arg2)) + Text_Ptr (J) - 1);
573 end if;
574 end loop;
576 -- Acquire string
578 String_To_Name_Buffer (Str);
579 return new String'(Name_Buffer (1 .. Name_Len));
580 end Get_String_Argument;
582 --------------------
583 -- Process_Casing --
584 --------------------
586 procedure Process_Casing (Arg : Node_Id) is
587 Expr : constant Node_Id := Expression (Arg);
589 begin
590 Check_Required_Identifier (Arg, Name_Casing);
592 if Nkind (Expr) = N_Identifier then
593 if Chars (Expr) = Name_Lowercase then
594 Cas := All_Lower_Case;
595 return;
596 elsif Chars (Expr) = Name_Uppercase then
597 Cas := All_Upper_Case;
598 return;
599 elsif Chars (Expr) = Name_Mixedcase then
600 Cas := Mixed_Case;
601 return;
602 end if;
603 end if;
605 Error_Msg_N
606 ("Casing argument for pragma% must be " &
607 "one of Mixedcase, Lowercase, Uppercase",
608 Arg);
609 end Process_Casing;
611 -----------------------------
612 -- Process_Dot_Replacement --
613 -----------------------------
615 procedure Process_Dot_Replacement (Arg : Node_Id) is
616 begin
617 Check_Required_Identifier (Arg, Name_Dot_Replacement);
618 Dot := Get_String_Argument (Arg);
619 end Process_Dot_Replacement;
621 -- Start of processing for Source_File_Name and
622 -- Source_File_Name_Project pragmas.
624 begin
625 if Get_Pragma_Id (Pragma_Name) = Pragma_Source_File_Name then
626 if Project_File_In_Use = In_Use then
627 Error_Msg
628 ("pragma Source_File_Name cannot be used " &
629 "with a project file", Pragma_Sloc);
631 else
632 Project_File_In_Use := Not_In_Use;
633 end if;
635 else
636 if Project_File_In_Use = Not_In_Use then
637 Error_Msg
638 ("pragma Source_File_Name_Project should only be used " &
639 "with a project file", Pragma_Sloc);
640 else
641 Project_File_In_Use := In_Use;
642 end if;
643 end if;
645 -- We permit from 1 to 3 arguments
647 if Arg_Count not in 1 .. 3 then
648 Check_Arg_Count (1);
649 end if;
651 Expr1 := Expression (Arg1);
653 -- If first argument is identifier or selected component, then
654 -- we have the specific file case of the Source_File_Name pragma,
655 -- and the first argument is a unit name.
657 if Nkind (Expr1) = N_Identifier
658 or else
659 (Nkind (Expr1) = N_Selected_Component
660 and then
661 Nkind (Selector_Name (Expr1)) = N_Identifier)
662 then
663 if Nkind (Expr1) = N_Identifier
664 and then Chars (Expr1) = Name_System
665 then
666 Error_Msg_N
667 ("pragma Source_File_Name may not be used for System",
668 Arg1);
669 return Error;
670 end if;
672 -- Process index argument if present
674 if Arg_Count = 3 then
675 Expr := Expression (Arg3);
677 if Nkind (Expr) /= N_Integer_Literal
678 or else not UI_Is_In_Int_Range (Intval (Expr))
679 or else Intval (Expr) > 999
680 or else Intval (Expr) <= 0
681 then
682 Error_Msg
683 ("pragma% index must be integer literal" &
684 " in range 1 .. 999", Sloc (Expr));
685 raise Error_Resync;
686 else
687 Index := UI_To_Int (Intval (Expr));
688 end if;
690 -- No index argument present
692 else
693 Check_Arg_Count (2);
694 Index := 0;
695 end if;
697 Check_Optional_Identifier (Arg1, Name_Unit_Name);
698 Unam := Get_Unit_Name (Expr1);
700 Check_Arg_Is_String_Literal (Arg2);
702 if Chars (Arg2) = Name_Spec_File_Name then
703 Set_File_Name
704 (Get_Spec_Name (Unam), Get_Fname (Arg2), Index);
706 elsif Chars (Arg2) = Name_Body_File_Name then
707 Set_File_Name
708 (Unam, Get_Fname (Arg2), Index);
710 else
711 Error_Msg_N
712 ("pragma% argument has incorrect identifier", Arg2);
713 return Pragma_Node;
714 end if;
716 -- If the first argument is not an identifier, then we must have
717 -- the pattern form of the pragma, and the first argument must be
718 -- the pattern string with an appropriate name.
720 else
721 if Chars (Arg1) = Name_Spec_File_Name then
722 Typ := 's';
724 elsif Chars (Arg1) = Name_Body_File_Name then
725 Typ := 'b';
727 elsif Chars (Arg1) = Name_Subunit_File_Name then
728 Typ := 'u';
730 elsif Chars (Arg1) = Name_Unit_Name then
731 Error_Msg_N
732 ("Unit_Name parameter for pragma% must be an identifier",
733 Arg1);
734 raise Error_Resync;
736 else
737 Error_Msg_N
738 ("pragma% argument has incorrect identifier", Arg1);
739 raise Error_Resync;
740 end if;
742 Pat := Get_String_Argument (Arg1);
744 -- Check pattern has exactly one asterisk
746 Nast := 0;
747 for J in Pat'Range loop
748 if Pat (J) = '*' then
749 Nast := Nast + 1;
750 end if;
751 end loop;
753 if Nast /= 1 then
754 Error_Msg_N
755 ("file name pattern must have exactly one * character",
756 Arg1);
757 return Pragma_Node;
758 end if;
760 -- Set defaults for Casing and Dot_Separator parameters
762 Cas := All_Lower_Case;
763 Dot := new String'(".");
765 -- Process second and third arguments if present
767 if Arg_Count > 1 then
768 if Chars (Arg2) = Name_Casing then
769 Process_Casing (Arg2);
771 if Arg_Count = 3 then
772 Process_Dot_Replacement (Arg3);
773 end if;
775 else
776 Process_Dot_Replacement (Arg2);
778 if Arg_Count = 3 then
779 Process_Casing (Arg3);
780 end if;
781 end if;
782 end if;
784 Set_File_Name_Pattern (Pat, Typ, Dot, Cas);
785 end if;
786 end Source_File_Name;
788 -----------------------------
789 -- Source_Reference (GNAT) --
790 -----------------------------
792 -- pragma Source_Reference
793 -- (INTEGER_LITERAL [, STRING_LITERAL] );
795 -- Processing for this pragma must be done at parse time, since error
796 -- messages needing the proper line numbers can be generated in parse
797 -- only mode with semantic checking turned off, and indeed we usually
798 -- turn off semantic checking anyway if any parse errors are found.
800 when Pragma_Source_Reference => Source_Reference : declare
801 Fname : Name_Id;
803 begin
804 if Arg_Count /= 1 then
805 Check_Arg_Count (2);
806 Check_No_Identifier (Arg2);
807 end if;
809 -- Check that this is first line of file. We skip this test if
810 -- we are in syntax check only mode, since we may be dealing with
811 -- multiple compilation units.
813 if Get_Physical_Line_Number (Pragma_Sloc) /= 1
814 and then Num_SRef_Pragmas (Current_Source_File) = 0
815 and then Operating_Mode /= Check_Syntax
816 then
817 Error_Msg
818 ("first % pragma must be first line of file", Pragma_Sloc);
819 raise Error_Resync;
820 end if;
822 Check_No_Identifier (Arg1);
824 if Arg_Count = 1 then
825 if Num_SRef_Pragmas (Current_Source_File) = 0 then
826 Error_Msg
827 ("file name required for first % pragma in file",
828 Pragma_Sloc);
829 raise Error_Resync;
830 else
831 Fname := No_Name;
832 end if;
834 -- File name present
836 else
837 Check_Arg_Is_String_Literal (Arg2);
838 String_To_Name_Buffer (Strval (Expression (Arg2)));
839 Fname := Name_Find;
841 if Num_SRef_Pragmas (Current_Source_File) > 0 then
842 if Fname /= Full_Ref_Name (Current_Source_File) then
843 Error_Msg
844 ("file name must be same in all % pragmas", Pragma_Sloc);
845 raise Error_Resync;
846 end if;
847 end if;
848 end if;
850 if Nkind (Expression (Arg1)) /= N_Integer_Literal then
851 Error_Msg
852 ("argument for pragma% must be integer literal",
853 Sloc (Expression (Arg1)));
854 raise Error_Resync;
856 -- OK, this source reference pragma is effective, however, we
857 -- ignore it if it is not in the first unit in the multiple unit
858 -- case. This is because the only purpose in this case is to
859 -- provide source pragmas for subsequent use by gnatchop.
861 else
862 if Num_Library_Units = 1 then
863 Register_Source_Ref_Pragma
864 (Fname,
865 Strip_Directory (Fname),
866 UI_To_Int (Intval (Expression (Arg1))),
867 Get_Physical_Line_Number (Pragma_Sloc) + 1);
868 end if;
869 end if;
870 end Source_Reference;
872 -------------------------
873 -- Style_Checks (GNAT) --
874 -------------------------
876 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
878 -- This is processed by the parser since some of the style
879 -- checks take place during source scanning and parsing.
881 when Pragma_Style_Checks => Style_Checks : declare
882 A : Node_Id;
883 S : String_Id;
884 C : Char_Code;
885 OK : Boolean := True;
887 begin
888 -- Two argument case is only for semantics
890 if Arg_Count = 2 then
891 null;
893 else
894 Check_Arg_Count (1);
895 Check_No_Identifier (Arg1);
896 A := Expression (Arg1);
898 if Nkind (A) = N_String_Literal then
899 S := Strval (A);
901 declare
902 Slen : constant Natural := Natural (String_Length (S));
903 Options : String (1 .. Slen);
904 J : Natural;
905 Ptr : Natural;
907 begin
908 J := 1;
909 loop
910 C := Get_String_Char (S, Int (J));
912 if not In_Character_Range (C) then
913 OK := False;
914 Ptr := J;
915 exit;
917 else
918 Options (J) := Get_Character (C);
919 end if;
921 if J = Slen then
922 Set_Style_Check_Options (Options, OK, Ptr);
923 exit;
925 else
926 J := J + 1;
927 end if;
928 end loop;
930 if not OK then
931 Error_Msg
932 ("invalid style check option",
933 Sloc (Expression (Arg1)) + Source_Ptr (Ptr));
934 raise Error_Resync;
935 end if;
936 end;
938 elsif Nkind (A) /= N_Identifier then
939 OK := False;
941 elsif Chars (A) = Name_All_Checks then
942 Stylesw.Set_Default_Style_Check_Options;
944 elsif Chars (A) = Name_On then
945 Style_Check := True;
947 elsif Chars (A) = Name_Off then
948 Style_Check := False;
950 else
951 OK := False;
952 end if;
954 if not OK then
955 Error_Msg ("incorrect argument for pragma%", Sloc (A));
956 raise Error_Resync;
957 end if;
958 end if;
959 end Style_Checks;
961 ---------------------
962 -- Warnings (GNAT) --
963 ---------------------
965 -- pragma Warnings (On | Off, [LOCAL_NAME])
967 -- The one argument case is processed by the parser, since it may
968 -- control parser warnings as well as semantic warnings, and in any
969 -- case we want to be absolutely sure that the range in the warnings
970 -- table is set well before any semantic analysis is performed.
972 when Pragma_Warnings =>
973 if Arg_Count = 1 then
974 Check_No_Identifier (Arg1);
975 Check_Arg_Is_On_Or_Off (Arg1);
977 if Chars (Expression (Arg1)) = Name_On then
978 Set_Warnings_Mode_On (Pragma_Sloc);
979 else
980 Set_Warnings_Mode_Off (Pragma_Sloc);
981 end if;
982 end if;
984 -----------------------
985 -- All Other Pragmas --
986 -----------------------
988 -- For all other pragmas, checking and processing is handled
989 -- entirely in Sem_Prag, and no further checking is done by Par.
991 when Pragma_Abort_Defer |
992 Pragma_Assertion_Policy |
993 Pragma_AST_Entry |
994 Pragma_All_Calls_Remote |
995 Pragma_Annotate |
996 Pragma_Assert |
997 Pragma_Asynchronous |
998 Pragma_Atomic |
999 Pragma_Atomic_Components |
1000 Pragma_Attach_Handler |
1001 Pragma_Compile_Time_Warning |
1002 Pragma_Convention_Identifier |
1003 Pragma_CPP_Class |
1004 Pragma_CPP_Constructor |
1005 Pragma_CPP_Virtual |
1006 Pragma_CPP_Vtable |
1007 Pragma_C_Pass_By_Copy |
1008 Pragma_Comment |
1009 Pragma_Common_Object |
1010 Pragma_Complex_Representation |
1011 Pragma_Component_Alignment |
1012 Pragma_Controlled |
1013 Pragma_Convention |
1014 Pragma_Debug_Policy |
1015 Pragma_Detect_Blocking |
1016 Pragma_Discard_Names |
1017 Pragma_Eliminate |
1018 Pragma_Elaborate |
1019 Pragma_Elaborate_All |
1020 Pragma_Elaborate_Body |
1021 Pragma_Elaboration_Checks |
1022 Pragma_Explicit_Overriding |
1023 Pragma_Export |
1024 Pragma_Export_Exception |
1025 Pragma_Export_Function |
1026 Pragma_Export_Object |
1027 Pragma_Export_Procedure |
1028 Pragma_Export_Value |
1029 Pragma_Export_Valued_Procedure |
1030 Pragma_Extend_System |
1031 Pragma_External |
1032 Pragma_External_Name_Casing |
1033 Pragma_Finalize_Storage_Only |
1034 Pragma_Float_Representation |
1035 Pragma_Ident |
1036 Pragma_Import |
1037 Pragma_Import_Exception |
1038 Pragma_Import_Function |
1039 Pragma_Import_Object |
1040 Pragma_Import_Procedure |
1041 Pragma_Import_Valued_Procedure |
1042 Pragma_Initialize_Scalars |
1043 Pragma_Inline |
1044 Pragma_Inline_Always |
1045 Pragma_Inline_Generic |
1046 Pragma_Inspection_Point |
1047 Pragma_Interface |
1048 Pragma_Interface_Name |
1049 Pragma_Interrupt_Handler |
1050 Pragma_Interrupt_State |
1051 Pragma_Interrupt_Priority |
1052 Pragma_Java_Constructor |
1053 Pragma_Java_Interface |
1054 Pragma_Keep_Names |
1055 Pragma_License |
1056 Pragma_Link_With |
1057 Pragma_Linker_Alias |
1058 Pragma_Linker_Constructor |
1059 Pragma_Linker_Destructor |
1060 Pragma_Linker_Options |
1061 Pragma_Linker_Section |
1062 Pragma_Locking_Policy |
1063 Pragma_Long_Float |
1064 Pragma_Machine_Attribute |
1065 Pragma_Main |
1066 Pragma_Main_Storage |
1067 Pragma_Memory_Size |
1068 Pragma_No_Return |
1069 Pragma_Obsolescent |
1070 Pragma_No_Run_Time |
1071 Pragma_No_Strict_Aliasing |
1072 Pragma_Normalize_Scalars |
1073 Pragma_Optimize |
1074 Pragma_Optional_Overriding |
1075 Pragma_Pack |
1076 Pragma_Passive |
1077 Pragma_Polling |
1078 Pragma_Persistent_BSS |
1079 Pragma_Preelaborate |
1080 Pragma_Preelaborate_05 |
1081 Pragma_Priority |
1082 Pragma_Profile |
1083 Pragma_Profile_Warnings |
1084 Pragma_Propagate_Exceptions |
1085 Pragma_Psect_Object |
1086 Pragma_Pure |
1087 Pragma_Pure_05 |
1088 Pragma_Pure_Function |
1089 Pragma_Queuing_Policy |
1090 Pragma_Remote_Call_Interface |
1091 Pragma_Remote_Types |
1092 Pragma_Restricted_Run_Time |
1093 Pragma_Ravenscar |
1094 Pragma_Reviewable |
1095 Pragma_Share_Generic |
1096 Pragma_Shared |
1097 Pragma_Shared_Passive |
1098 Pragma_Storage_Size |
1099 Pragma_Storage_Unit |
1100 Pragma_Stream_Convert |
1101 Pragma_Subtitle |
1102 Pragma_Suppress |
1103 Pragma_Suppress_All |
1104 Pragma_Suppress_Debug_Info |
1105 Pragma_Suppress_Exception_Locations |
1106 Pragma_Suppress_Initialization |
1107 Pragma_System_Name |
1108 Pragma_Task_Dispatching_Policy |
1109 Pragma_Task_Info |
1110 Pragma_Task_Name |
1111 Pragma_Task_Storage |
1112 Pragma_Thread_Body |
1113 Pragma_Time_Slice |
1114 Pragma_Title |
1115 Pragma_Unchecked_Union |
1116 Pragma_Unimplemented_Unit |
1117 Pragma_Universal_Data |
1118 Pragma_Unreferenced |
1119 Pragma_Unreserve_All_Interrupts |
1120 Pragma_Unsuppress |
1121 Pragma_Use_VADS_Size |
1122 Pragma_Volatile |
1123 Pragma_Volatile_Components |
1124 Pragma_Weak_External |
1125 Pragma_Validity_Checks =>
1126 null;
1128 --------------------
1129 -- Unknown_Pragma --
1130 --------------------
1132 -- Should be impossible, since we excluded this case earlier on
1134 when Unknown_Pragma =>
1135 raise Program_Error;
1137 end case;
1139 return Pragma_Node;
1141 --------------------
1142 -- Error Handling --
1143 --------------------
1145 exception
1146 when Error_Resync =>
1147 return Error;
1149 end Prag;