OSDN Git Service

2005-03-08 Geert Bosch <bosch@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / par-prag.adb
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,  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 ------------------------------------------------------------------------------
26
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.
32
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;
41
42 separate (Par)
43
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;
50
51    -----------------------
52    -- Local Subprograms --
53    -----------------------
54
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.
61
62    procedure Check_Arg_Count (Required : Int);
63    --  Check argument count for pragma = Required.
64    --  If not give error and raise Error_Resync.
65
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.
69
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.
74
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.
79
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.
84
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.
88
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.
96
97    ----------
98    -- Arg1 --
99    ----------
100
101    function Arg1 return Node_Id is
102    begin
103       return First (Pragma_Argument_Associations (Pragma_Node));
104    end Arg1;
105
106    ----------
107    -- Arg2 --
108    ----------
109
110    function Arg2 return Node_Id is
111    begin
112       return Next (Arg1);
113    end Arg2;
114
115    ----------
116    -- Arg3 --
117    ----------
118
119    function Arg3 return Node_Id is
120    begin
121       return Next (Arg2);
122    end Arg3;
123
124    ---------------------
125    -- Check_Arg_Count --
126    ---------------------
127
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;
135
136    ----------------------------
137    -- Check_Arg_Is_On_Or_Off --
138    ----------------------------
139
140    procedure Check_Arg_Is_On_Or_Off (Arg : Node_Id) is
141       Argx : constant Node_Id := Expression (Arg);
142
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;
151
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;
157
158    ---------------------------------
159    -- Check_Arg_Is_String_Literal --
160    ---------------------------------
161
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;
171
172    -------------------------
173    -- Check_No_Identifier --
174    -------------------------
175
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;
183
184    -------------------------------
185    -- Check_Optional_Identifier --
186    -------------------------------
187
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;
197
198    -------------------------------
199    -- Check_Required_Identifier --
200    -------------------------------
201
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;
209
210    --------------------------------------------------
211    -- Process_Restrictions_Or_Restriction_Warnings --
212    --------------------------------------------------
213
214    procedure Process_Restrictions_Or_Restriction_Warnings is
215       Arg  : Node_Id;
216       Id   : Name_Id;
217       Expr : Node_Id;
218
219    begin
220       Arg := Arg1;
221       while Present (Arg) loop
222          Id := Chars (Arg);
223          Expr := Expression (Arg);
224
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;
232
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;
238
239          Next (Arg);
240       end loop;
241    end Process_Restrictions_Or_Restriction_Warnings;
242
243 --  Start if processing for Prag
244
245 begin
246    Error_Msg_Name_1 := Pragma_Name;
247
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)).
251
252    if Prag_Id = Unknown_Pragma then
253       return Pragma_Node;
254    end if;
255
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.
260
261    Arg_Count := 0;
262
263    if Present (Pragma_Argument_Associations (Pragma_Node)) then
264       Arg_Node := Arg1;
265
266       while Arg_Node /= Empty loop
267          Arg_Count := Arg_Count + 1;
268
269          if Expression (Arg_Node) = Error then
270             return Error;
271          end if;
272
273          Next (Arg_Node);
274       end loop;
275    end if;
276
277    --  Remaining processing is pragma dependent
278
279    case Prag_Id is
280
281       ------------
282       -- Ada_83 --
283       ------------
284
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.
288
289       when Pragma_Ada_83 =>
290          Ada_Version := Ada_83;
291
292       ------------
293       -- Ada_95 --
294       ------------
295
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.
299
300       when Pragma_Ada_95 =>
301          Ada_Version := Ada_95;
302
303       ------------
304       -- Ada_05 --
305       ------------
306
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. However, it is only the zero argument form that
310       --  must be processed at parse time.
311
312       when Pragma_Ada_05 =>
313          if Arg_Count = 0 then
314             Ada_Version := Ada_05;
315          end if;
316
317       -----------
318       -- Debug --
319       -----------
320
321       --  pragma Debug (PROCEDURE_CALL_STATEMENT);
322
323       --  This has to be processed by the parser because of the very peculiar
324       --  form of the second parameter, which is syntactically from a formal
325       --  point of view a function call (since it must be an expression), but
326       --  semantically we treat it as a procedure call (which has exactly the
327       --  same syntactic form, so that's why we can get away with this!)
328
329       when Pragma_Debug =>
330          Check_Arg_Count (1);
331          Check_No_Identifier (Arg1);
332
333          declare
334             Expr : constant Node_Id := New_Copy (Expression (Arg1));
335
336          begin
337             if Nkind (Expr) /= N_Indexed_Component
338               and then Nkind (Expr) /= N_Function_Call
339               and then Nkind (Expr) /= N_Identifier
340               and then Nkind (Expr) /= N_Selected_Component
341             then
342                Error_Msg
343                  ("argument of pragma% is not procedure call", Sloc (Expr));
344                raise Error_Resync;
345             else
346                Set_Debug_Statement
347                  (Pragma_Node, P_Statement_Name (Expr));
348             end if;
349          end;
350
351       -------------------------------
352       -- Extensions_Allowed (GNAT) --
353       -------------------------------
354
355       --  pragma Extensions_Allowed (Off | On)
356
357       --  The processing for pragma Extensions_Allowed must be done at
358       --  parse time, since extensions mode may affect what is accepted.
359
360       when Pragma_Extensions_Allowed =>
361          Check_Arg_Count (1);
362          Check_No_Identifier (Arg1);
363          Check_Arg_Is_On_Or_Off (Arg1);
364
365          if Chars (Expression (Arg1)) = Name_On then
366             Extensions_Allowed := True;
367             Ada_Version := Ada_Version_Type'Last;
368          else
369             Extensions_Allowed := False;
370             Ada_Version := Ada_Version_Type'Min (Ada_Version, Ada_95);
371          end if;
372
373       ----------------
374       -- List (2.8) --
375       ----------------
376
377       --  pragma List (Off | On)
378
379       --  The processing for pragma List must be done at parse time,
380       --  since a listing can be generated in parse only mode.
381
382       when Pragma_List =>
383          Check_Arg_Count (1);
384          Check_No_Identifier (Arg1);
385          Check_Arg_Is_On_Or_Off (Arg1);
386
387          --  We unconditionally make a List_On entry for the pragma, so that
388          --  in the List (Off) case, the pragma will print even in a region
389          --  of code with listing turned off (this is required!)
390
391          List_Pragmas.Increment_Last;
392          List_Pragmas.Table (List_Pragmas.Last) :=
393            (Ptyp => List_On, Ploc => Sloc (Pragma_Node));
394
395          --  Now generate the list off entry for pragma List (Off)
396
397          if Chars (Expression (Arg1)) = Name_Off then
398             List_Pragmas.Increment_Last;
399             List_Pragmas.Table (List_Pragmas.Last) :=
400               (Ptyp => List_Off, Ploc => Semi);
401          end if;
402
403       ----------------
404       -- Page (2.8) --
405       ----------------
406
407       --  pragma Page;
408
409       --  Processing for this pragma must be done at parse time, since a
410       --  listing can be generated in parse only mode with semantics off.
411
412       when Pragma_Page =>
413          Check_Arg_Count (0);
414          List_Pragmas.Increment_Last;
415          List_Pragmas.Table (List_Pragmas.Last) := (Page, Semi);
416
417          ------------------
418          -- Restrictions --
419          ------------------
420
421          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
422
423          --  RESTRICTION ::=
424          --    restriction_IDENTIFIER
425          --  | restriction_parameter_IDENTIFIER => EXPRESSION
426
427          --  We process the case of No_Obsolescent_Features, since this has
428          --  a syntactic effect that we need to detect at parse time (the use
429          --  of replacement characters such as colon for pound sign).
430
431          when Pragma_Restrictions =>
432             Process_Restrictions_Or_Restriction_Warnings;
433
434          --------------------------
435          -- Restriction_Warnings --
436          --------------------------
437
438          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
439
440          --  RESTRICTION ::=
441          --    restriction_IDENTIFIER
442          --  | restriction_parameter_IDENTIFIER => EXPRESSION
443
444          --  See above comment for pragma Restrictions
445
446          when Pragma_Restriction_Warnings =>
447             Process_Restrictions_Or_Restriction_Warnings;
448
449       ----------------------------------------------------------
450       -- Source_File_Name and Source_File_Name_Project (GNAT) --
451       ----------------------------------------------------------
452
453       --  These two pragmas have the same syntax and semantics.
454       --  There are five forms of these pragmas:
455
456       --  pragma Source_File_Name[_Project] (
457       --    [UNIT_NAME      =>] unit_NAME,
458       --     BODY_FILE_NAME =>  STRING_LITERAL
459       --    [, [INDEX =>] INTEGER_LITERAL]);
460
461       --  pragma Source_File_Name[_Project] (
462       --    [UNIT_NAME      =>] unit_NAME,
463       --     SPEC_FILE_NAME =>  STRING_LITERAL
464       --    [, [INDEX =>] INTEGER_LITERAL]);
465
466       --  pragma Source_File_Name[_Project] (
467       --     BODY_FILE_NAME  => STRING_LITERAL
468       --  [, DOT_REPLACEMENT => STRING_LITERAL]
469       --  [, CASING          => CASING_SPEC]);
470
471       --  pragma Source_File_Name[_Project] (
472       --     SPEC_FILE_NAME  => STRING_LITERAL
473       --  [, DOT_REPLACEMENT => STRING_LITERAL]
474       --  [, CASING          => CASING_SPEC]);
475
476       --  pragma Source_File_Name[_Project] (
477       --     SUBUNIT_FILE_NAME  => STRING_LITERAL
478       --  [, DOT_REPLACEMENT    => STRING_LITERAL]
479       --  [, CASING             => CASING_SPEC]);
480
481       --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
482
483       --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
484       --  Source_File_Name (SFN), however their usage is exclusive:
485       --  SFN can only be used when no project file is used, while
486       --  SFNP can only be used when a project file is used.
487
488       --  The Project Manager produces a configuration pragmas file that
489       --  is communicated to the compiler with -gnatec switch. This file
490       --  contains only SFNP pragmas (at least two for the default naming
491       --  scheme. As this configuration pragmas file is always the first
492       --  processed by the compiler, it prevents the use of pragmas SFN in
493       --  other config files when a project file is in use.
494
495       --  Note: we process this during parsing, since we need to have the
496       --  source file names set well before the semantic analysis starts,
497       --  since we load the spec and with'ed packages before analysis.
498
499       when Pragma_Source_File_Name | Pragma_Source_File_Name_Project =>
500          Source_File_Name : declare
501             Unam  : Unit_Name_Type;
502             Expr1 : Node_Id;
503             Pat   : String_Ptr;
504             Typ   : Character;
505             Dot   : String_Ptr;
506             Cas   : Casing_Type;
507             Nast  : Nat;
508             Expr  : Node_Id;
509             Index : Nat;
510
511             function Get_Fname (Arg : Node_Id) return Name_Id;
512             --  Process file name from unit name form of pragma
513
514             function Get_String_Argument (Arg : Node_Id) return String_Ptr;
515             --  Process string literal value from argument
516
517             procedure Process_Casing (Arg : Node_Id);
518             --  Process Casing argument of pattern form of pragma
519
520             procedure Process_Dot_Replacement (Arg : Node_Id);
521             --  Process Dot_Replacement argument of patterm form of pragma
522
523             ---------------
524             -- Get_Fname --
525             ---------------
526
527             function Get_Fname (Arg : Node_Id) return Name_Id is
528             begin
529                String_To_Name_Buffer (Strval (Expression (Arg)));
530
531                for J in 1 .. Name_Len loop
532                   if Is_Directory_Separator (Name_Buffer (J)) then
533                      Error_Msg
534                        ("directory separator character not allowed",
535                         Sloc (Expression (Arg)) + Source_Ptr (J));
536                   end if;
537                end loop;
538
539                return Name_Find;
540             end Get_Fname;
541
542             -------------------------
543             -- Get_String_Argument --
544             -------------------------
545
546             function Get_String_Argument (Arg : Node_Id) return String_Ptr is
547                Str : String_Id;
548
549             begin
550                if Nkind (Expression (Arg)) /= N_String_Literal
551                  and then
552                   Nkind (Expression (Arg)) /= N_Operator_Symbol
553                then
554                   Error_Msg_N
555                     ("argument for pragma% must be string literal", Arg);
556                   raise Error_Resync;
557                end if;
558
559                Str := Strval (Expression (Arg));
560
561                --  Check string has no wide chars
562
563                for J in 1 .. String_Length (Str) loop
564                   if Get_String_Char (Str, J) > 255 then
565                      Error_Msg
566                        ("wide character not allowed in pattern for pragma%",
567                         Sloc (Expression (Arg2)) + Text_Ptr (J) - 1);
568                   end if;
569                end loop;
570
571                --  Acquire string
572
573                String_To_Name_Buffer (Str);
574                return new String'(Name_Buffer (1 .. Name_Len));
575             end Get_String_Argument;
576
577             --------------------
578             -- Process_Casing --
579             --------------------
580
581             procedure Process_Casing (Arg : Node_Id) is
582                Expr : constant Node_Id := Expression (Arg);
583
584             begin
585                Check_Required_Identifier (Arg, Name_Casing);
586
587                if Nkind (Expr) = N_Identifier then
588                   if Chars (Expr) = Name_Lowercase then
589                      Cas := All_Lower_Case;
590                      return;
591                   elsif Chars (Expr) = Name_Uppercase then
592                      Cas := All_Upper_Case;
593                      return;
594                   elsif Chars (Expr) = Name_Mixedcase then
595                      Cas := Mixed_Case;
596                      return;
597                   end if;
598                end if;
599
600                Error_Msg_N
601                  ("Casing argument for pragma% must be " &
602                   "one of Mixedcase, Lowercase, Uppercase",
603                   Arg);
604             end Process_Casing;
605
606             -----------------------------
607             -- Process_Dot_Replacement --
608             -----------------------------
609
610             procedure Process_Dot_Replacement (Arg : Node_Id) is
611             begin
612                Check_Required_Identifier (Arg, Name_Dot_Replacement);
613                Dot := Get_String_Argument (Arg);
614             end Process_Dot_Replacement;
615
616          --  Start of processing for Source_File_Name and
617          --  Source_File_Name_Project pragmas.
618
619          begin
620             if Get_Pragma_Id (Pragma_Name) = Pragma_Source_File_Name then
621                if Project_File_In_Use = In_Use then
622                   Error_Msg
623                     ("pragma Source_File_Name cannot be used " &
624                      "with a project file", Pragma_Sloc);
625
626                else
627                   Project_File_In_Use := Not_In_Use;
628                end if;
629
630             else
631                if Project_File_In_Use = Not_In_Use then
632                   Error_Msg
633                     ("pragma Source_File_Name_Project should only be used " &
634                      "with a project file", Pragma_Sloc);
635                else
636                   Project_File_In_Use := In_Use;
637                end if;
638             end if;
639
640             --  We permit from 1 to 3 arguments
641
642             if Arg_Count not in 1 .. 3 then
643                Check_Arg_Count (1);
644             end if;
645
646             Expr1 := Expression (Arg1);
647
648             --  If first argument is identifier or selected component, then
649             --  we have the specific file case of the Source_File_Name pragma,
650             --  and the first argument is a unit name.
651
652             if Nkind (Expr1) = N_Identifier
653               or else
654                 (Nkind (Expr1) = N_Selected_Component
655                   and then
656                  Nkind (Selector_Name (Expr1)) = N_Identifier)
657             then
658                if Nkind (Expr1) = N_Identifier
659                  and then Chars (Expr1) = Name_System
660                then
661                   Error_Msg_N
662                     ("pragma Source_File_Name may not be used for System",
663                      Arg1);
664                   return Error;
665                end if;
666
667                --  Process index argument if present
668
669                if Arg_Count = 3 then
670                   Expr := Expression (Arg3);
671
672                   if Nkind (Expr) /= N_Integer_Literal
673                     or else not UI_Is_In_Int_Range (Intval (Expr))
674                     or else Intval (Expr) > 999
675                     or else Intval (Expr) <= 0
676                   then
677                      Error_Msg
678                        ("pragma% index must be integer literal" &
679                         " in range 1 .. 999", Sloc (Expr));
680                      raise Error_Resync;
681                   else
682                      Index := UI_To_Int (Intval (Expr));
683                   end if;
684
685                --  No index argument present
686
687                else
688                   Check_Arg_Count (2);
689                   Index := 0;
690                end if;
691
692                Check_Optional_Identifier (Arg1, Name_Unit_Name);
693                Unam := Get_Unit_Name (Expr1);
694
695                Check_Arg_Is_String_Literal (Arg2);
696
697                if Chars (Arg2) = Name_Spec_File_Name then
698                   Set_File_Name
699                     (Get_Spec_Name (Unam), Get_Fname (Arg2), Index);
700
701                elsif Chars (Arg2) = Name_Body_File_Name then
702                   Set_File_Name
703                     (Unam, Get_Fname (Arg2), Index);
704
705                else
706                   Error_Msg_N
707                     ("pragma% argument has incorrect identifier", Arg2);
708                   return Pragma_Node;
709                end if;
710
711             --  If the first argument is not an identifier, then we must have
712             --  the pattern form of the pragma, and the first argument must be
713             --  the pattern string with an appropriate name.
714
715             else
716                if Chars (Arg1) = Name_Spec_File_Name then
717                   Typ := 's';
718
719                elsif Chars (Arg1) = Name_Body_File_Name then
720                   Typ := 'b';
721
722                elsif Chars (Arg1) = Name_Subunit_File_Name then
723                   Typ := 'u';
724
725                elsif Chars (Arg1) = Name_Unit_Name then
726                   Error_Msg_N
727                     ("Unit_Name parameter for pragma% must be an identifier",
728                      Arg1);
729                   raise Error_Resync;
730
731                else
732                   Error_Msg_N
733                     ("pragma% argument has incorrect identifier", Arg1);
734                   raise Error_Resync;
735                end if;
736
737                Pat := Get_String_Argument (Arg1);
738
739                --  Check pattern has exactly one asterisk
740
741                Nast := 0;
742                for J in Pat'Range loop
743                   if Pat (J) = '*' then
744                      Nast := Nast + 1;
745                   end if;
746                end loop;
747
748                if Nast /= 1 then
749                   Error_Msg_N
750                     ("file name pattern must have exactly one * character",
751                      Arg1);
752                   return Pragma_Node;
753                end if;
754
755                --  Set defaults for Casing and Dot_Separator parameters
756
757                Cas := All_Lower_Case;
758                Dot := new String'(".");
759
760                --  Process second and third arguments if present
761
762                if Arg_Count > 1 then
763                   if Chars (Arg2) = Name_Casing then
764                      Process_Casing (Arg2);
765
766                      if Arg_Count = 3 then
767                         Process_Dot_Replacement (Arg3);
768                      end if;
769
770                   else
771                      Process_Dot_Replacement (Arg2);
772
773                      if Arg_Count = 3 then
774                         Process_Casing (Arg3);
775                      end if;
776                   end if;
777                end if;
778
779                Set_File_Name_Pattern (Pat, Typ, Dot, Cas);
780             end if;
781          end Source_File_Name;
782
783       -----------------------------
784       -- Source_Reference (GNAT) --
785       -----------------------------
786
787       --  pragma Source_Reference
788       --    (INTEGER_LITERAL [, STRING_LITERAL] );
789
790       --  Processing for this pragma must be done at parse time, since error
791       --  messages needing the proper line numbers can be generated in parse
792       --  only mode with semantic checking turned off, and indeed we usually
793       --  turn off semantic checking anyway if any parse errors are found.
794
795       when Pragma_Source_Reference => Source_Reference : declare
796          Fname : Name_Id;
797
798       begin
799          if Arg_Count /= 1 then
800             Check_Arg_Count (2);
801             Check_No_Identifier (Arg2);
802          end if;
803
804          --  Check that this is first line of file. We skip this test if
805          --  we are in syntax check only mode, since we may be dealing with
806          --  multiple compilation units.
807
808          if Get_Physical_Line_Number (Pragma_Sloc) /= 1
809            and then Num_SRef_Pragmas (Current_Source_File) = 0
810            and then Operating_Mode /= Check_Syntax
811          then
812             Error_Msg
813               ("first % pragma must be first line of file", Pragma_Sloc);
814             raise Error_Resync;
815          end if;
816
817          Check_No_Identifier (Arg1);
818
819          if Arg_Count = 1 then
820             if Num_SRef_Pragmas (Current_Source_File) = 0 then
821                Error_Msg
822                  ("file name required for first % pragma in file",
823                   Pragma_Sloc);
824                raise Error_Resync;
825             else
826                Fname := No_Name;
827             end if;
828
829          --  File name present
830
831          else
832             Check_Arg_Is_String_Literal (Arg2);
833             String_To_Name_Buffer (Strval (Expression (Arg2)));
834             Fname := Name_Find;
835
836             if Num_SRef_Pragmas (Current_Source_File) > 0 then
837                if Fname /= Full_Ref_Name (Current_Source_File) then
838                   Error_Msg
839                     ("file name must be same in all % pragmas", Pragma_Sloc);
840                   raise Error_Resync;
841                end if;
842             end if;
843          end if;
844
845          if Nkind (Expression (Arg1)) /= N_Integer_Literal then
846             Error_Msg
847               ("argument for pragma% must be integer literal",
848                 Sloc (Expression (Arg1)));
849             raise Error_Resync;
850
851          --  OK, this source reference pragma is effective, however, we
852          --  ignore it if it is not in the first unit in the multiple unit
853          --  case. This is because the only purpose in this case is to
854          --  provide source pragmas for subsequent use by gnatchop.
855
856          else
857             if Num_Library_Units = 1 then
858                Register_Source_Ref_Pragma
859                  (Fname,
860                   Strip_Directory (Fname),
861                   UI_To_Int (Intval (Expression (Arg1))),
862                   Get_Physical_Line_Number (Pragma_Sloc) + 1);
863             end if;
864          end if;
865       end Source_Reference;
866
867       -------------------------
868       -- Style_Checks (GNAT) --
869       -------------------------
870
871       --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
872
873       --  This is processed by the parser since some of the style
874       --  checks take place during source scanning and parsing.
875
876       when Pragma_Style_Checks => Style_Checks : declare
877          A  : Node_Id;
878          S  : String_Id;
879          C  : Char_Code;
880          OK : Boolean := True;
881
882       begin
883          --  Two argument case is only for semantics
884
885          if Arg_Count = 2 then
886             null;
887
888          else
889             Check_Arg_Count (1);
890             Check_No_Identifier (Arg1);
891             A := Expression (Arg1);
892
893             if Nkind (A) = N_String_Literal then
894                S   := Strval (A);
895
896                declare
897                   Slen    : constant Natural := Natural (String_Length (S));
898                   Options : String (1 .. Slen);
899                   J       : Natural;
900                   Ptr     : Natural;
901
902                begin
903                   J := 1;
904                   loop
905                      C := Get_String_Char (S, Int (J));
906
907                      if not In_Character_Range (C) then
908                         OK := False;
909                         Ptr := J;
910                         exit;
911
912                      else
913                         Options (J) := Get_Character (C);
914                      end if;
915
916                      if J = Slen then
917                         Set_Style_Check_Options (Options, OK, Ptr);
918                         exit;
919
920                      else
921                         J := J + 1;
922                      end if;
923                   end loop;
924
925                   if not OK then
926                      Error_Msg
927                        ("invalid style check option",
928                         Sloc (Expression (Arg1)) + Source_Ptr (Ptr));
929                      raise Error_Resync;
930                   end if;
931                end;
932
933             elsif Nkind (A) /= N_Identifier then
934                OK := False;
935
936             elsif Chars (A) = Name_All_Checks then
937                Stylesw.Set_Default_Style_Check_Options;
938
939             elsif Chars (A) = Name_On then
940                Style_Check := True;
941
942             elsif Chars (A) = Name_Off then
943                Style_Check := False;
944
945             else
946                OK := False;
947             end if;
948
949             if not OK then
950                Error_Msg ("incorrect argument for pragma%", Sloc (A));
951                raise Error_Resync;
952             end if;
953          end if;
954       end Style_Checks;
955
956       ---------------------
957       -- Warnings (GNAT) --
958       ---------------------
959
960       --  pragma Warnings (On | Off, [LOCAL_NAME])
961
962       --  The one argument case is processed by the parser, since it may
963       --  control parser warnings as well as semantic warnings, and in any
964       --  case we want to be absolutely sure that the range in the warnings
965       --  table is set well before any semantic analysis is performed.
966
967       when Pragma_Warnings =>
968          if Arg_Count = 1 then
969             Check_No_Identifier (Arg1);
970             Check_Arg_Is_On_Or_Off (Arg1);
971
972             if Chars (Expression (Arg1)) = Name_On then
973                Set_Warnings_Mode_On (Pragma_Sloc);
974             else
975                Set_Warnings_Mode_Off (Pragma_Sloc);
976             end if;
977          end if;
978
979       -----------------------
980       -- All Other Pragmas --
981       -----------------------
982
983       --  For all other pragmas, checking and processing is handled
984       --  entirely in Sem_Prag, and no further checking is done by Par.
985
986       when Pragma_Abort_Defer                  |
987            Pragma_AST_Entry                    |
988            Pragma_All_Calls_Remote             |
989            Pragma_Annotate                     |
990            Pragma_Assert                       |
991            Pragma_Asynchronous                 |
992            Pragma_Atomic                       |
993            Pragma_Atomic_Components            |
994            Pragma_Attach_Handler               |
995            Pragma_Compile_Time_Warning         |
996            Pragma_Convention_Identifier        |
997            Pragma_CPP_Class                    |
998            Pragma_CPP_Constructor              |
999            Pragma_CPP_Virtual                  |
1000            Pragma_CPP_Vtable                   |
1001            Pragma_C_Pass_By_Copy               |
1002            Pragma_Comment                      |
1003            Pragma_Common_Object                |
1004            Pragma_Complex_Representation       |
1005            Pragma_Component_Alignment          |
1006            Pragma_Controlled                   |
1007            Pragma_Convention                   |
1008            Pragma_Detect_Blocking              |
1009            Pragma_Discard_Names                |
1010            Pragma_Eliminate                    |
1011            Pragma_Elaborate                    |
1012            Pragma_Elaborate_All                |
1013            Pragma_Elaborate_Body               |
1014            Pragma_Elaboration_Checks           |
1015            Pragma_Explicit_Overriding          |
1016            Pragma_Export                       |
1017            Pragma_Export_Exception             |
1018            Pragma_Export_Function              |
1019            Pragma_Export_Object                |
1020            Pragma_Export_Procedure             |
1021            Pragma_Export_Value                 |
1022            Pragma_Export_Valued_Procedure      |
1023            Pragma_Extend_System                |
1024            Pragma_External                     |
1025            Pragma_External_Name_Casing         |
1026            Pragma_Finalize_Storage_Only        |
1027            Pragma_Float_Representation         |
1028            Pragma_Ident                        |
1029            Pragma_Import                       |
1030            Pragma_Import_Exception             |
1031            Pragma_Import_Function              |
1032            Pragma_Import_Object                |
1033            Pragma_Import_Procedure             |
1034            Pragma_Import_Valued_Procedure      |
1035            Pragma_Initialize_Scalars           |
1036            Pragma_Inline                       |
1037            Pragma_Inline_Always                |
1038            Pragma_Inline_Generic               |
1039            Pragma_Inspection_Point             |
1040            Pragma_Interface                    |
1041            Pragma_Interface_Name               |
1042            Pragma_Interrupt_Handler            |
1043            Pragma_Interrupt_State              |
1044            Pragma_Interrupt_Priority           |
1045            Pragma_Java_Constructor             |
1046            Pragma_Java_Interface               |
1047            Pragma_Keep_Names                   |
1048            Pragma_License                      |
1049            Pragma_Link_With                    |
1050            Pragma_Linker_Alias                 |
1051            Pragma_Linker_Options               |
1052            Pragma_Linker_Section               |
1053            Pragma_Locking_Policy               |
1054            Pragma_Long_Float                   |
1055            Pragma_Machine_Attribute            |
1056            Pragma_Main                         |
1057            Pragma_Main_Storage                 |
1058            Pragma_Memory_Size                  |
1059            Pragma_No_Return                    |
1060            Pragma_Obsolescent                  |
1061            Pragma_No_Run_Time                  |
1062            Pragma_No_Strict_Aliasing           |
1063            Pragma_Normalize_Scalars            |
1064            Pragma_Optimize                     |
1065            Pragma_Optional_Overriding          |
1066            Pragma_Pack                         |
1067            Pragma_Passive                      |
1068            Pragma_Polling                      |
1069            Pragma_Persistent_Data              |
1070            Pragma_Persistent_Object            |
1071            Pragma_Preelaborate                 |
1072            Pragma_Priority                     |
1073            Pragma_Profile                      |
1074            Pragma_Profile_Warnings             |
1075            Pragma_Propagate_Exceptions         |
1076            Pragma_Psect_Object                 |
1077            Pragma_Pure                         |
1078            Pragma_Pure_Function                |
1079            Pragma_Queuing_Policy               |
1080            Pragma_Remote_Call_Interface        |
1081            Pragma_Remote_Types                 |
1082            Pragma_Restricted_Run_Time          |
1083            Pragma_Ravenscar                    |
1084            Pragma_Reviewable                   |
1085            Pragma_Share_Generic                |
1086            Pragma_Shared                       |
1087            Pragma_Shared_Passive               |
1088            Pragma_Storage_Size                 |
1089            Pragma_Storage_Unit                 |
1090            Pragma_Stream_Convert               |
1091            Pragma_Subtitle                     |
1092            Pragma_Suppress                     |
1093            Pragma_Suppress_All                 |
1094            Pragma_Suppress_Debug_Info          |
1095            Pragma_Suppress_Exception_Locations |
1096            Pragma_Suppress_Initialization      |
1097            Pragma_System_Name                  |
1098            Pragma_Task_Dispatching_Policy      |
1099            Pragma_Task_Info                    |
1100            Pragma_Task_Name                    |
1101            Pragma_Task_Storage                 |
1102            Pragma_Thread_Body                  |
1103            Pragma_Time_Slice                   |
1104            Pragma_Title                        |
1105            Pragma_Unchecked_Union              |
1106            Pragma_Unimplemented_Unit           |
1107            Pragma_Universal_Data               |
1108            Pragma_Unreferenced                 |
1109            Pragma_Unreserve_All_Interrupts     |
1110            Pragma_Unsuppress                   |
1111            Pragma_Use_VADS_Size                |
1112            Pragma_Volatile                     |
1113            Pragma_Volatile_Components          |
1114            Pragma_Weak_External                |
1115            Pragma_Validity_Checks              =>
1116          null;
1117
1118       --------------------
1119       -- Unknown_Pragma --
1120       --------------------
1121
1122       --  Should be impossible, since we excluded this case earlier on
1123
1124       when Unknown_Pragma =>
1125          raise Program_Error;
1126
1127    end case;
1128
1129    return Pragma_Node;
1130
1131    --------------------
1132    -- Error Handling --
1133    --------------------
1134
1135 exception
1136    when Error_Resync =>
1137       return Error;
1138
1139 end Prag;