OSDN Git Service

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