[multiple changes]
[gcc.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-2013, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 -- Generally the parser checks the basic syntax of pragmas, but does not
27 -- do specialized syntax checks for individual pragmas, these are deferred
28 -- to semantic analysis time (see unit Sem_Prag). There are some pragmas
29 -- which require recognition and either partial or complete processing
30 -- during parsing, and this unit performs this required processing.
31
32 with Fname.UF; use Fname.UF;
33 with Osint; use Osint;
34 with Rident; use Rident;
35 with Restrict; use Restrict;
36 with Stringt; use Stringt;
37 with Stylesw; use Stylesw;
38 with Uintp; use Uintp;
39 with Uname; use Uname;
40
41 with System.WCh_Con; use System.WCh_Con;
42
43 separate (Par)
44
45 function Prag (Pragma_Node : Node_Id; Semi : Source_Ptr) return Node_Id is
46 Prag_Name : constant Name_Id := Pragma_Name (Pragma_Node);
47 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Prag_Name);
48 Pragma_Sloc : constant Source_Ptr := Sloc (Pragma_Node);
49 Arg_Count : Nat;
50 Arg_Node : Node_Id;
51
52 -----------------------
53 -- Local Subprograms --
54 -----------------------
55
56 function Arg1 return Node_Id;
57 function Arg2 return Node_Id;
58 function Arg3 return Node_Id;
59 -- Obtain specified Pragma_Argument_Association. It is allowable to call
60 -- the routine for the argument one past the last present argument, but
61 -- that is the only case in which a non-present argument can be referenced.
62
63 procedure Check_Arg_Count (Required : Int);
64 -- Check argument count for pragma = Required. If not give error and raise
65 -- Error_Resync.
66
67 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
68 -- Check the expression of the specified argument to make sure that it
69 -- is a string literal. If not give error and raise Error_Resync.
70
71 procedure Check_Arg_Is_On_Or_Off (Arg : Node_Id);
72 -- Check the expression of the specified argument to make sure that it
73 -- is an identifier which is either ON or OFF, and if not, then issue
74 -- an error message and raise Error_Resync.
75
76 procedure Check_No_Identifier (Arg : Node_Id);
77 -- Checks that the given argument does not have an identifier. If
78 -- an identifier is present, then an error message is issued, and
79 -- Error_Resync is raised.
80
81 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
82 -- Checks if the given argument has an identifier, and if so, requires
83 -- it to match the given identifier name. If there is a non-matching
84 -- identifier, then an error message is given and Error_Resync raised.
85
86 procedure Check_Required_Identifier (Arg : Node_Id; Id : Name_Id);
87 -- Same as Check_Optional_Identifier, except that the name is required
88 -- to be present and to match the given Id value.
89
90 procedure Process_Restrictions_Or_Restriction_Warnings;
91 -- Common processing for Restrictions and Restriction_Warnings pragmas.
92 -- For the most part, restrictions need not be processed at parse time,
93 -- since they only affect semantic processing. This routine handles the
94 -- exceptions as follows
95 --
96 -- No_Obsolescent_Features must be processed at parse time, since there
97 -- are some obsolescent features (e.g. character replacements) which are
98 -- handled at parse time.
99 --
100 -- SPARK must be processed at parse time, since this restriction controls
101 -- whether the scanner recognizes a spark HIDE directive formatted as an
102 -- Ada comment (and generates a Tok_SPARK_Hide token for the directive).
103 --
104 -- No_Dependence must be processed at parse time, since otherwise it gets
105 -- handled too late.
106 --
107 -- Note that we don't need to do full error checking for badly formed cases
108 -- of restrictions, since these will be caught during semantic analysis.
109
110 ----------
111 -- Arg1 --
112 ----------
113
114 function Arg1 return Node_Id is
115 begin
116 return First (Pragma_Argument_Associations (Pragma_Node));
117 end Arg1;
118
119 ----------
120 -- Arg2 --
121 ----------
122
123 function Arg2 return Node_Id is
124 begin
125 return Next (Arg1);
126 end Arg2;
127
128 ----------
129 -- Arg3 --
130 ----------
131
132 function Arg3 return Node_Id is
133 begin
134 return Next (Arg2);
135 end Arg3;
136
137 ---------------------
138 -- Check_Arg_Count --
139 ---------------------
140
141 procedure Check_Arg_Count (Required : Int) is
142 begin
143 if Arg_Count /= Required then
144 Error_Msg ("wrong number of arguments for pragma%", Pragma_Sloc);
145 raise Error_Resync;
146 end if;
147 end Check_Arg_Count;
148
149 ----------------------------
150 -- Check_Arg_Is_On_Or_Off --
151 ----------------------------
152
153 procedure Check_Arg_Is_On_Or_Off (Arg : Node_Id) is
154 Argx : constant Node_Id := Expression (Arg);
155
156 begin
157 if Nkind (Expression (Arg)) /= N_Identifier
158 or else not Nam_In (Chars (Argx), Name_On, Name_Off)
159 then
160 Error_Msg_Name_2 := Name_On;
161 Error_Msg_Name_3 := Name_Off;
162
163 Error_Msg ("argument for pragma% must be% or%", Sloc (Argx));
164 raise Error_Resync;
165 end if;
166 end Check_Arg_Is_On_Or_Off;
167
168 ---------------------------------
169 -- Check_Arg_Is_String_Literal --
170 ---------------------------------
171
172 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
173 begin
174 if Nkind (Expression (Arg)) /= N_String_Literal then
175 Error_Msg
176 ("argument for pragma% must be string literal",
177 Sloc (Expression (Arg)));
178 raise Error_Resync;
179 end if;
180 end Check_Arg_Is_String_Literal;
181
182 -------------------------
183 -- Check_No_Identifier --
184 -------------------------
185
186 procedure Check_No_Identifier (Arg : Node_Id) is
187 begin
188 if Chars (Arg) /= No_Name then
189 Error_Msg_N ("pragma% does not permit named arguments", Arg);
190 raise Error_Resync;
191 end if;
192 end Check_No_Identifier;
193
194 -------------------------------
195 -- Check_Optional_Identifier --
196 -------------------------------
197
198 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
199 begin
200 if Present (Arg) and then Chars (Arg) /= No_Name then
201 if Chars (Arg) /= Id then
202 Error_Msg_Name_2 := Id;
203 Error_Msg_N ("pragma% argument expects identifier%", Arg);
204 end if;
205 end if;
206 end Check_Optional_Identifier;
207
208 -------------------------------
209 -- Check_Required_Identifier --
210 -------------------------------
211
212 procedure Check_Required_Identifier (Arg : Node_Id; Id : Name_Id) is
213 begin
214 if Chars (Arg) /= Id then
215 Error_Msg_Name_2 := Id;
216 Error_Msg_N ("pragma% argument must have identifier%", Arg);
217 end if;
218 end Check_Required_Identifier;
219
220 --------------------------------------------------
221 -- Process_Restrictions_Or_Restriction_Warnings --
222 --------------------------------------------------
223
224 procedure Process_Restrictions_Or_Restriction_Warnings is
225 Arg : Node_Id;
226 Id : Name_Id;
227 Expr : Node_Id;
228
229 begin
230 Arg := Arg1;
231 while Present (Arg) loop
232 Id := Chars (Arg);
233 Expr := Expression (Arg);
234
235 if Id = No_Name
236 and then Nkind (Expr) = N_Identifier
237 then
238 case Get_Restriction_Id (Chars (Expr)) is
239 when No_Obsolescent_Features =>
240 Set_Restriction (No_Obsolescent_Features, Pragma_Node);
241 Restriction_Warnings (No_Obsolescent_Features) :=
242 Prag_Id = Pragma_Restriction_Warnings;
243
244 when SPARK =>
245 Set_Restriction (SPARK, Pragma_Node);
246 Restriction_Warnings (SPARK) :=
247 Prag_Id = Pragma_Restriction_Warnings;
248
249 when others =>
250 null;
251 end case;
252
253 elsif Id = Name_No_Dependence then
254 Set_Restriction_No_Dependence
255 (Unit => Expr,
256 Warn => Prag_Id = Pragma_Restriction_Warnings
257 or else Treat_Restrictions_As_Warnings);
258 end if;
259
260 Next (Arg);
261 end loop;
262 end Process_Restrictions_Or_Restriction_Warnings;
263
264 -- Start of processing for Prag
265
266 begin
267 Error_Msg_Name_1 := Prag_Name;
268
269 -- Ignore unrecognized pragma. We let Sem post the warning for this, since
270 -- it is a semantic error, not a syntactic one (we have already checked
271 -- the syntax for the unrecognized pragma as required by (RM 2.8(11)).
272
273 if Prag_Id = Unknown_Pragma then
274 return Pragma_Node;
275 end if;
276
277 -- Count number of arguments. This loop also checks if any of the arguments
278 -- are Error, indicating a syntax error as they were parsed. If so, we
279 -- simply return, because we get into trouble with cascaded errors if we
280 -- try to perform our error checks on junk arguments.
281
282 Arg_Count := 0;
283
284 if Present (Pragma_Argument_Associations (Pragma_Node)) then
285 Arg_Node := Arg1;
286 while Arg_Node /= Empty loop
287 Arg_Count := Arg_Count + 1;
288
289 if Expression (Arg_Node) = Error then
290 return Error;
291 end if;
292
293 Next (Arg_Node);
294 end loop;
295 end if;
296
297 -- Remaining processing is pragma dependent
298
299 case Prag_Id is
300
301 ------------
302 -- Ada_83 --
303 ------------
304
305 -- This pragma must be processed at parse time, since we want to set
306 -- the Ada version properly at parse time to recognize the appropriate
307 -- Ada version syntax.
308
309 when Pragma_Ada_83 =>
310 Ada_Version := Ada_83;
311 Ada_Version_Explicit := Ada_83;
312
313 ------------
314 -- Ada_95 --
315 ------------
316
317 -- This pragma must be processed at parse time, since we want to set
318 -- the Ada version properly at parse time to recognize the appropriate
319 -- Ada version syntax.
320
321 when Pragma_Ada_95 =>
322 Ada_Version := Ada_95;
323 Ada_Version_Explicit := Ada_95;
324
325 ---------------------
326 -- Ada_05/Ada_2005 --
327 ---------------------
328
329 -- These pragmas must be processed at parse time, since we want to set
330 -- the Ada version properly at parse time to recognize the appropriate
331 -- Ada version syntax. However, it is only the zero argument form that
332 -- must be processed at parse time.
333
334 when Pragma_Ada_05 | Pragma_Ada_2005 =>
335 if Arg_Count = 0 then
336 Ada_Version := Ada_2005;
337 Ada_Version_Explicit := Ada_2005;
338 end if;
339
340 ---------------------
341 -- Ada_12/Ada_2012 --
342 ---------------------
343
344 -- These pragmas must be processed at parse time, since we want to set
345 -- the Ada version properly at parse time to recognize the appropriate
346 -- Ada version syntax. However, it is only the zero argument form that
347 -- must be processed at parse time.
348
349 when Pragma_Ada_12 | Pragma_Ada_2012 =>
350 if Arg_Count = 0 then
351 Ada_Version := Ada_2012;
352 Ada_Version_Explicit := Ada_2012;
353 end if;
354
355 -----------
356 -- Debug --
357 -----------
358
359 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
360
361 when Pragma_Debug =>
362 Check_No_Identifier (Arg1);
363
364 if Arg_Count = 2 then
365 Check_No_Identifier (Arg2);
366 else
367 Check_Arg_Count (1);
368 end if;
369
370 -------------------------------
371 -- Extensions_Allowed (GNAT) --
372 -------------------------------
373
374 -- pragma Extensions_Allowed (Off | On)
375
376 -- The processing for pragma Extensions_Allowed must be done at
377 -- parse time, since extensions mode may affect what is accepted.
378
379 when Pragma_Extensions_Allowed =>
380 Check_Arg_Count (1);
381 Check_No_Identifier (Arg1);
382 Check_Arg_Is_On_Or_Off (Arg1);
383
384 if Chars (Expression (Arg1)) = Name_On then
385 Extensions_Allowed := True;
386 Ada_Version := Ada_2012;
387 else
388 Extensions_Allowed := False;
389 Ada_Version := Ada_Version_Explicit;
390 end if;
391
392 ----------------
393 -- List (2.8) --
394 ----------------
395
396 -- pragma List (Off | On)
397
398 -- The processing for pragma List must be done at parse time,
399 -- since a listing can be generated in parse only mode.
400
401 when Pragma_List =>
402 Check_Arg_Count (1);
403 Check_No_Identifier (Arg1);
404 Check_Arg_Is_On_Or_Off (Arg1);
405
406 -- We unconditionally make a List_On entry for the pragma, so that
407 -- in the List (Off) case, the pragma will print even in a region
408 -- of code with listing turned off (this is required!)
409
410 List_Pragmas.Increment_Last;
411 List_Pragmas.Table (List_Pragmas.Last) :=
412 (Ptyp => List_On, Ploc => Sloc (Pragma_Node));
413
414 -- Now generate the list off entry for pragma List (Off)
415
416 if Chars (Expression (Arg1)) = Name_Off then
417 List_Pragmas.Increment_Last;
418 List_Pragmas.Table (List_Pragmas.Last) :=
419 (Ptyp => List_Off, Ploc => Semi);
420 end if;
421
422 ----------------
423 -- Page (2.8) --
424 ----------------
425
426 -- pragma Page;
427
428 -- Processing for this pragma must be done at parse time, since a
429 -- listing can be generated in parse only mode with semantics off.
430
431 when Pragma_Page =>
432 Check_Arg_Count (0);
433 List_Pragmas.Increment_Last;
434 List_Pragmas.Table (List_Pragmas.Last) := (Page, Semi);
435
436 ------------------
437 -- Restrictions --
438 ------------------
439
440 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
441
442 -- RESTRICTION ::=
443 -- restriction_IDENTIFIER
444 -- | restriction_parameter_IDENTIFIER => EXPRESSION
445
446 -- We process the case of No_Obsolescent_Features, since this has
447 -- a syntactic effect that we need to detect at parse time (the use
448 -- of replacement characters such as colon for pound sign).
449
450 when Pragma_Restrictions =>
451 Process_Restrictions_Or_Restriction_Warnings;
452
453 --------------------------
454 -- Restriction_Warnings --
455 --------------------------
456
457 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
458
459 -- RESTRICTION ::=
460 -- restriction_IDENTIFIER
461 -- | restriction_parameter_IDENTIFIER => EXPRESSION
462
463 -- See above comment for pragma Restrictions
464
465 when Pragma_Restriction_Warnings =>
466 Process_Restrictions_Or_Restriction_Warnings;
467
468 ----------------------------------------------------------
469 -- Source_File_Name and Source_File_Name_Project (GNAT) --
470 ----------------------------------------------------------
471
472 -- These two pragmas have the same syntax and semantics.
473 -- There are five forms of these pragmas:
474
475 -- pragma Source_File_Name[_Project] (
476 -- [UNIT_NAME =>] unit_NAME,
477 -- BODY_FILE_NAME => STRING_LITERAL
478 -- [, [INDEX =>] INTEGER_LITERAL]);
479
480 -- pragma Source_File_Name[_Project] (
481 -- [UNIT_NAME =>] unit_NAME,
482 -- SPEC_FILE_NAME => STRING_LITERAL
483 -- [, [INDEX =>] INTEGER_LITERAL]);
484
485 -- pragma Source_File_Name[_Project] (
486 -- BODY_FILE_NAME => STRING_LITERAL
487 -- [, DOT_REPLACEMENT => STRING_LITERAL]
488 -- [, CASING => CASING_SPEC]);
489
490 -- pragma Source_File_Name[_Project] (
491 -- SPEC_FILE_NAME => STRING_LITERAL
492 -- [, DOT_REPLACEMENT => STRING_LITERAL]
493 -- [, CASING => CASING_SPEC]);
494
495 -- pragma Source_File_Name[_Project] (
496 -- SUBUNIT_FILE_NAME => STRING_LITERAL
497 -- [, DOT_REPLACEMENT => STRING_LITERAL]
498 -- [, CASING => CASING_SPEC]);
499
500 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
501
502 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
503 -- Source_File_Name (SFN), however their usage is exclusive:
504 -- SFN can only be used when no project file is used, while
505 -- SFNP can only be used when a project file is used.
506
507 -- The Project Manager produces a configuration pragmas file that
508 -- is communicated to the compiler with -gnatec switch. This file
509 -- contains only SFNP pragmas (at least two for the default naming
510 -- scheme. As this configuration pragmas file is always the first
511 -- processed by the compiler, it prevents the use of pragmas SFN in
512 -- other config files when a project file is in use.
513
514 -- Note: we process this during parsing, since we need to have the
515 -- source file names set well before the semantic analysis starts,
516 -- since we load the spec and with'ed packages before analysis.
517
518 when Pragma_Source_File_Name | Pragma_Source_File_Name_Project =>
519 Source_File_Name : declare
520 Unam : Unit_Name_Type;
521 Expr1 : Node_Id;
522 Pat : String_Ptr;
523 Typ : Character;
524 Dot : String_Ptr;
525 Cas : Casing_Type;
526 Nast : Nat;
527 Expr : Node_Id;
528 Index : Nat;
529
530 function Get_Fname (Arg : Node_Id) return File_Name_Type;
531 -- Process file name from unit name form of pragma
532
533 function Get_String_Argument (Arg : Node_Id) return String_Ptr;
534 -- Process string literal value from argument
535
536 procedure Process_Casing (Arg : Node_Id);
537 -- Process Casing argument of pattern form of pragma
538
539 procedure Process_Dot_Replacement (Arg : Node_Id);
540 -- Process Dot_Replacement argument of pattern form of pragma
541
542 ---------------
543 -- Get_Fname --
544 ---------------
545
546 function Get_Fname (Arg : Node_Id) return File_Name_Type is
547 begin
548 String_To_Name_Buffer (Strval (Expression (Arg)));
549
550 for J in 1 .. Name_Len loop
551 if Is_Directory_Separator (Name_Buffer (J)) then
552 Error_Msg
553 ("directory separator character not allowed",
554 Sloc (Expression (Arg)) + Source_Ptr (J));
555 end if;
556 end loop;
557
558 return Name_Find;
559 end Get_Fname;
560
561 -------------------------
562 -- Get_String_Argument --
563 -------------------------
564
565 function Get_String_Argument (Arg : Node_Id) return String_Ptr is
566 Str : String_Id;
567
568 begin
569 if Nkind (Expression (Arg)) /= N_String_Literal
570 and then
571 Nkind (Expression (Arg)) /= N_Operator_Symbol
572 then
573 Error_Msg_N
574 ("argument for pragma% must be string literal", Arg);
575 raise Error_Resync;
576 end if;
577
578 Str := Strval (Expression (Arg));
579
580 -- Check string has no wide chars
581
582 for J in 1 .. String_Length (Str) loop
583 if Get_String_Char (Str, J) > 255 then
584 Error_Msg
585 ("wide character not allowed in pattern for pragma%",
586 Sloc (Expression (Arg2)) + Text_Ptr (J) - 1);
587 end if;
588 end loop;
589
590 -- Acquire string
591
592 String_To_Name_Buffer (Str);
593 return new String'(Name_Buffer (1 .. Name_Len));
594 end Get_String_Argument;
595
596 --------------------
597 -- Process_Casing --
598 --------------------
599
600 procedure Process_Casing (Arg : Node_Id) is
601 Expr : constant Node_Id := Expression (Arg);
602
603 begin
604 Check_Required_Identifier (Arg, Name_Casing);
605
606 if Nkind (Expr) = N_Identifier then
607 if Chars (Expr) = Name_Lowercase then
608 Cas := All_Lower_Case;
609 return;
610 elsif Chars (Expr) = Name_Uppercase then
611 Cas := All_Upper_Case;
612 return;
613 elsif Chars (Expr) = Name_Mixedcase then
614 Cas := Mixed_Case;
615 return;
616 end if;
617 end if;
618
619 Error_Msg_N
620 ("Casing argument for pragma% must be " &
621 "one of Mixedcase, Lowercase, Uppercase",
622 Arg);
623 end Process_Casing;
624
625 -----------------------------
626 -- Process_Dot_Replacement --
627 -----------------------------
628
629 procedure Process_Dot_Replacement (Arg : Node_Id) is
630 begin
631 Check_Required_Identifier (Arg, Name_Dot_Replacement);
632 Dot := Get_String_Argument (Arg);
633 end Process_Dot_Replacement;
634
635 -- Start of processing for Source_File_Name and
636 -- Source_File_Name_Project pragmas.
637
638 begin
639 if Prag_Id = Pragma_Source_File_Name then
640 if Project_File_In_Use = In_Use then
641 Error_Msg
642 ("pragma Source_File_Name cannot be used " &
643 "with a project file", Pragma_Sloc);
644
645 else
646 Project_File_In_Use := Not_In_Use;
647 end if;
648
649 else
650 if Project_File_In_Use = Not_In_Use then
651 Error_Msg
652 ("pragma Source_File_Name_Project should only be used " &
653 "with a project file", Pragma_Sloc);
654 else
655 Project_File_In_Use := In_Use;
656 end if;
657 end if;
658
659 -- We permit from 1 to 3 arguments
660
661 if Arg_Count not in 1 .. 3 then
662 Check_Arg_Count (1);
663 end if;
664
665 Expr1 := Expression (Arg1);
666
667 -- If first argument is identifier or selected component, then
668 -- we have the specific file case of the Source_File_Name pragma,
669 -- and the first argument is a unit name.
670
671 if Nkind (Expr1) = N_Identifier
672 or else
673 (Nkind (Expr1) = N_Selected_Component
674 and then
675 Nkind (Selector_Name (Expr1)) = N_Identifier)
676 then
677 if Nkind (Expr1) = N_Identifier
678 and then Chars (Expr1) = Name_System
679 then
680 Error_Msg_N
681 ("pragma Source_File_Name may not be used for System",
682 Arg1);
683 return Error;
684 end if;
685
686 -- Process index argument if present
687
688 if Arg_Count = 3 then
689 Expr := Expression (Arg3);
690
691 if Nkind (Expr) /= N_Integer_Literal
692 or else not UI_Is_In_Int_Range (Intval (Expr))
693 or else Intval (Expr) > 999
694 or else Intval (Expr) <= 0
695 then
696 Error_Msg
697 ("pragma% index must be integer literal" &
698 " in range 1 .. 999", Sloc (Expr));
699 raise Error_Resync;
700 else
701 Index := UI_To_Int (Intval (Expr));
702 end if;
703
704 -- No index argument present
705
706 else
707 Check_Arg_Count (2);
708 Index := 0;
709 end if;
710
711 Check_Optional_Identifier (Arg1, Name_Unit_Name);
712 Unam := Get_Unit_Name (Expr1);
713
714 Check_Arg_Is_String_Literal (Arg2);
715
716 if Chars (Arg2) = Name_Spec_File_Name then
717 Set_File_Name
718 (Get_Spec_Name (Unam), Get_Fname (Arg2), Index);
719
720 elsif Chars (Arg2) = Name_Body_File_Name then
721 Set_File_Name
722 (Unam, Get_Fname (Arg2), Index);
723
724 else
725 Error_Msg_N
726 ("pragma% argument has incorrect identifier", Arg2);
727 return Pragma_Node;
728 end if;
729
730 -- If the first argument is not an identifier, then we must have
731 -- the pattern form of the pragma, and the first argument must be
732 -- the pattern string with an appropriate name.
733
734 else
735 if Chars (Arg1) = Name_Spec_File_Name then
736 Typ := 's';
737
738 elsif Chars (Arg1) = Name_Body_File_Name then
739 Typ := 'b';
740
741 elsif Chars (Arg1) = Name_Subunit_File_Name then
742 Typ := 'u';
743
744 elsif Chars (Arg1) = Name_Unit_Name then
745 Error_Msg_N
746 ("Unit_Name parameter for pragma% must be an identifier",
747 Arg1);
748 raise Error_Resync;
749
750 else
751 Error_Msg_N
752 ("pragma% argument has incorrect identifier", Arg1);
753 raise Error_Resync;
754 end if;
755
756 Pat := Get_String_Argument (Arg1);
757
758 -- Check pattern has exactly one asterisk
759
760 Nast := 0;
761 for J in Pat'Range loop
762 if Pat (J) = '*' then
763 Nast := Nast + 1;
764 end if;
765 end loop;
766
767 if Nast /= 1 then
768 Error_Msg_N
769 ("file name pattern must have exactly one * character",
770 Arg1);
771 return Pragma_Node;
772 end if;
773
774 -- Set defaults for Casing and Dot_Separator parameters
775
776 Cas := All_Lower_Case;
777 Dot := new String'(".");
778
779 -- Process second and third arguments if present
780
781 if Arg_Count > 1 then
782 if Chars (Arg2) = Name_Casing then
783 Process_Casing (Arg2);
784
785 if Arg_Count = 3 then
786 Process_Dot_Replacement (Arg3);
787 end if;
788
789 else
790 Process_Dot_Replacement (Arg2);
791
792 if Arg_Count = 3 then
793 Process_Casing (Arg3);
794 end if;
795 end if;
796 end if;
797
798 Set_File_Name_Pattern (Pat, Typ, Dot, Cas);
799 end if;
800 end Source_File_Name;
801
802 -----------------------------
803 -- Source_Reference (GNAT) --
804 -----------------------------
805
806 -- pragma Source_Reference
807 -- (INTEGER_LITERAL [, STRING_LITERAL] );
808
809 -- Processing for this pragma must be done at parse time, since error
810 -- messages needing the proper line numbers can be generated in parse
811 -- only mode with semantic checking turned off, and indeed we usually
812 -- turn off semantic checking anyway if any parse errors are found.
813
814 when Pragma_Source_Reference => Source_Reference : declare
815 Fname : File_Name_Type;
816
817 begin
818 if Arg_Count /= 1 then
819 Check_Arg_Count (2);
820 Check_No_Identifier (Arg2);
821 end if;
822
823 -- Check that this is first line of file. We skip this test if
824 -- we are in syntax check only mode, since we may be dealing with
825 -- multiple compilation units.
826
827 if Get_Physical_Line_Number (Pragma_Sloc) /= 1
828 and then Num_SRef_Pragmas (Current_Source_File) = 0
829 and then Operating_Mode /= Check_Syntax
830 then
831 Error_Msg -- CODEFIX
832 ("first % pragma must be first line of file", Pragma_Sloc);
833 raise Error_Resync;
834 end if;
835
836 Check_No_Identifier (Arg1);
837
838 if Arg_Count = 1 then
839 if Num_SRef_Pragmas (Current_Source_File) = 0 then
840 Error_Msg
841 ("file name required for first % pragma in file",
842 Pragma_Sloc);
843 raise Error_Resync;
844 else
845 Fname := No_File;
846 end if;
847
848 -- File name present
849
850 else
851 Check_Arg_Is_String_Literal (Arg2);
852 String_To_Name_Buffer (Strval (Expression (Arg2)));
853 Fname := Name_Find;
854
855 if Num_SRef_Pragmas (Current_Source_File) > 0 then
856 if Fname /= Full_Ref_Name (Current_Source_File) then
857 Error_Msg
858 ("file name must be same in all % pragmas", Pragma_Sloc);
859 raise Error_Resync;
860 end if;
861 end if;
862 end if;
863
864 if Nkind (Expression (Arg1)) /= N_Integer_Literal then
865 Error_Msg
866 ("argument for pragma% must be integer literal",
867 Sloc (Expression (Arg1)));
868 raise Error_Resync;
869
870 -- OK, this source reference pragma is effective, however, we
871 -- ignore it if it is not in the first unit in the multiple unit
872 -- case. This is because the only purpose in this case is to
873 -- provide source pragmas for subsequent use by gnatchop.
874
875 else
876 if Num_Library_Units = 1 then
877 Register_Source_Ref_Pragma
878 (Fname,
879 Strip_Directory (Fname),
880 UI_To_Int (Intval (Expression (Arg1))),
881 Get_Physical_Line_Number (Pragma_Sloc) + 1);
882 end if;
883 end if;
884 end Source_Reference;
885
886 -------------------------
887 -- Style_Checks (GNAT) --
888 -------------------------
889
890 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
891
892 -- This is processed by the parser since some of the style
893 -- checks take place during source scanning and parsing.
894
895 when Pragma_Style_Checks => Style_Checks : declare
896 A : Node_Id;
897 S : String_Id;
898 C : Char_Code;
899 OK : Boolean := True;
900
901 begin
902 -- Two argument case is only for semantics
903
904 if Arg_Count = 2 then
905 null;
906
907 else
908 Check_Arg_Count (1);
909 Check_No_Identifier (Arg1);
910 A := Expression (Arg1);
911
912 if Nkind (A) = N_String_Literal then
913 S := Strval (A);
914
915 declare
916 Slen : constant Natural := Natural (String_Length (S));
917 Options : String (1 .. Slen);
918 J : Natural;
919 Ptr : Natural;
920
921 begin
922 J := 1;
923 loop
924 C := Get_String_Char (S, Int (J));
925
926 if not In_Character_Range (C) then
927 OK := False;
928 Ptr := J;
929 exit;
930
931 else
932 Options (J) := Get_Character (C);
933 end if;
934
935 if J = Slen then
936 if not Ignore_Style_Checks_Pragmas then
937 Set_Style_Check_Options (Options, OK, Ptr);
938 end if;
939
940 exit;
941
942 else
943 J := J + 1;
944 end if;
945 end loop;
946
947 if not OK then
948 Error_Msg
949 (Style_Msg_Buf (1 .. Style_Msg_Len),
950 Sloc (Expression (Arg1)) + Source_Ptr (Ptr));
951 raise Error_Resync;
952 end if;
953 end;
954
955 elsif Nkind (A) /= N_Identifier then
956 OK := False;
957
958 elsif Chars (A) = Name_All_Checks then
959 if not Ignore_Style_Checks_Pragmas then
960 if GNAT_Mode then
961 Stylesw.Set_GNAT_Style_Check_Options;
962 else
963 Stylesw.Set_Default_Style_Check_Options;
964 end if;
965 end if;
966
967 elsif Chars (A) = Name_On then
968 if not Ignore_Style_Checks_Pragmas then
969 Style_Check := True;
970 end if;
971
972 elsif Chars (A) = Name_Off then
973 if not Ignore_Style_Checks_Pragmas then
974 Style_Check := False;
975 end if;
976
977 else
978 OK := False;
979 end if;
980
981 if not OK then
982 Error_Msg ("incorrect argument for pragma%", Sloc (A));
983 raise Error_Resync;
984 end if;
985 end if;
986 end Style_Checks;
987
988 -------------------------
989 -- Suppress_All (GNAT) --
990 -------------------------
991
992 -- pragma Suppress_All
993
994 -- This is a rather odd pragma, because other compilers allow it in
995 -- strange places. DEC allows it at the end of units, and Rational
996 -- allows it as a program unit pragma, when it would be more natural
997 -- if it were a configuration pragma.
998
999 -- Since the reason we provide this pragma is for compatibility with
1000 -- these other compilers, we want to accommodate these strange placement
1001 -- rules, and the easiest thing is simply to allow it anywhere in a
1002 -- unit. If this pragma appears anywhere within a unit, then the effect
1003 -- is as though a pragma Suppress (All_Checks) had appeared as the first
1004 -- line of the current file, i.e. as the first configuration pragma in
1005 -- the current unit.
1006
1007 -- To get this effect, we set the flag Has_Pragma_Suppress_All in the
1008 -- compilation unit node for the current source file then in the last
1009 -- stage of parsing a file, if this flag is set, we materialize the
1010 -- Suppress (All_Checks) pragma, marked as not coming from Source.
1011
1012 when Pragma_Suppress_All =>
1013 Set_Has_Pragma_Suppress_All (Cunit (Current_Source_Unit));
1014
1015 ---------------------
1016 -- Warnings (GNAT) --
1017 ---------------------
1018
1019 -- pragma Warnings (On | Off);
1020 -- pragma Warnings (On | Off, LOCAL_NAME);
1021 -- pragma Warnings (static_string_EXPRESSION);
1022 -- pragma Warnings (On | Off, static_string_EXPRESSION);
1023
1024 -- The one argument ON/OFF case is processed by the parser, since it may
1025 -- control parser warnings as well as semantic warnings, and in any case
1026 -- we want to be absolutely sure that the range in the warnings table is
1027 -- set well before any semantic analysis is performed. Note that we
1028 -- ignore this pragma if debug flag -gnatd.i is set.
1029
1030 when Pragma_Warnings =>
1031 if Arg_Count = 1 and then not Debug_Flag_Dot_I then
1032 Check_No_Identifier (Arg1);
1033
1034 declare
1035 Argx : constant Node_Id := Expression (Arg1);
1036 begin
1037 if Nkind (Argx) = N_Identifier then
1038 if Chars (Argx) = Name_On then
1039 Set_Warnings_Mode_On (Pragma_Sloc);
1040 elsif Chars (Argx) = Name_Off then
1041 Set_Warnings_Mode_Off (Pragma_Sloc);
1042 end if;
1043 end if;
1044 end;
1045 end if;
1046
1047 -----------------------------
1048 -- Wide_Character_Encoding --
1049 -----------------------------
1050
1051 -- pragma Wide_Character_Encoding (IDENTIFIER | CHARACTER_LITERAL);
1052
1053 -- This is processed by the parser, since the scanner is affected
1054
1055 when Pragma_Wide_Character_Encoding => Wide_Character_Encoding : declare
1056 A : Node_Id;
1057
1058 begin
1059 Check_Arg_Count (1);
1060 Check_No_Identifier (Arg1);
1061 A := Expression (Arg1);
1062
1063 if Nkind (A) = N_Identifier then
1064 Get_Name_String (Chars (A));
1065 Wide_Character_Encoding_Method :=
1066 Get_WC_Encoding_Method (Name_Buffer (1 .. Name_Len));
1067
1068 elsif Nkind (A) = N_Character_Literal then
1069 declare
1070 R : constant Char_Code :=
1071 Char_Code (UI_To_Int (Char_Literal_Value (A)));
1072 begin
1073 if In_Character_Range (R) then
1074 Wide_Character_Encoding_Method :=
1075 Get_WC_Encoding_Method (Get_Character (R));
1076 else
1077 raise Constraint_Error;
1078 end if;
1079 end;
1080
1081 else
1082 raise Constraint_Error;
1083 end if;
1084
1085 Upper_Half_Encoding :=
1086 Wide_Character_Encoding_Method in
1087 WC_Upper_Half_Encoding_Method;
1088
1089 exception
1090 when Constraint_Error =>
1091 Error_Msg_N ("invalid argument for pragma%", Arg1);
1092 end Wide_Character_Encoding;
1093
1094 -----------------------
1095 -- All Other Pragmas --
1096 -----------------------
1097
1098 -- For all other pragmas, checking and processing is handled
1099 -- entirely in Sem_Prag, and no further checking is done by Par.
1100
1101 when Pragma_Abort_Defer |
1102 Pragma_Abstract_State |
1103 Pragma_Assertion_Policy |
1104 Pragma_Assume |
1105 Pragma_Assume_No_Invalid_Values |
1106 Pragma_AST_Entry |
1107 Pragma_All_Calls_Remote |
1108 Pragma_Annotate |
1109 Pragma_Assert |
1110 Pragma_Assert_And_Cut |
1111 Pragma_Asynchronous |
1112 Pragma_Atomic |
1113 Pragma_Atomic_Components |
1114 Pragma_Attach_Handler |
1115 Pragma_Attribute_Definition |
1116 Pragma_Check |
1117 Pragma_Check_Float_Overflow |
1118 Pragma_Check_Name |
1119 Pragma_Check_Policy |
1120 Pragma_CIL_Constructor |
1121 Pragma_Compile_Time_Error |
1122 Pragma_Compile_Time_Warning |
1123 Pragma_Compiler_Unit |
1124 Pragma_Contract_Cases |
1125 Pragma_Convention_Identifier |
1126 Pragma_CPP_Class |
1127 Pragma_CPP_Constructor |
1128 Pragma_CPP_Virtual |
1129 Pragma_CPP_Vtable |
1130 Pragma_CPU |
1131 Pragma_C_Pass_By_Copy |
1132 Pragma_Comment |
1133 Pragma_Common_Object |
1134 Pragma_Complete_Representation |
1135 Pragma_Complex_Representation |
1136 Pragma_Component_Alignment |
1137 Pragma_Controlled |
1138 Pragma_Convention |
1139 Pragma_Debug_Policy |
1140 Pragma_Depends |
1141 Pragma_Detect_Blocking |
1142 Pragma_Default_Storage_Pool |
1143 Pragma_Disable_Atomic_Synchronization |
1144 Pragma_Discard_Names |
1145 Pragma_Dispatching_Domain |
1146 Pragma_Eliminate |
1147 Pragma_Elaborate |
1148 Pragma_Elaborate_All |
1149 Pragma_Elaborate_Body |
1150 Pragma_Elaboration_Checks |
1151 Pragma_Enable_Atomic_Synchronization |
1152 Pragma_Export |
1153 Pragma_Export_Exception |
1154 Pragma_Export_Function |
1155 Pragma_Export_Object |
1156 Pragma_Export_Procedure |
1157 Pragma_Export_Value |
1158 Pragma_Export_Valued_Procedure |
1159 Pragma_Extend_System |
1160 Pragma_External |
1161 Pragma_External_Name_Casing |
1162 Pragma_Favor_Top_Level |
1163 Pragma_Fast_Math |
1164 Pragma_Finalize_Storage_Only |
1165 Pragma_Float_Representation |
1166 Pragma_Global |
1167 Pragma_Ident |
1168 Pragma_Implementation_Defined |
1169 Pragma_Implemented |
1170 Pragma_Implicit_Packing |
1171 Pragma_Import |
1172 Pragma_Import_Exception |
1173 Pragma_Import_Function |
1174 Pragma_Import_Object |
1175 Pragma_Import_Procedure |
1176 Pragma_Import_Valued_Procedure |
1177 Pragma_Independent |
1178 Pragma_Independent_Components |
1179 Pragma_Initialize_Scalars |
1180 Pragma_Inline |
1181 Pragma_Inline_Always |
1182 Pragma_Inline_Generic |
1183 Pragma_Inspection_Point |
1184 Pragma_Interface |
1185 Pragma_Interface_Name |
1186 Pragma_Interrupt_Handler |
1187 Pragma_Interrupt_State |
1188 Pragma_Interrupt_Priority |
1189 Pragma_Invariant |
1190 Pragma_Java_Constructor |
1191 Pragma_Java_Interface |
1192 Pragma_Keep_Names |
1193 Pragma_License |
1194 Pragma_Link_With |
1195 Pragma_Linker_Alias |
1196 Pragma_Linker_Constructor |
1197 Pragma_Linker_Destructor |
1198 Pragma_Linker_Options |
1199 Pragma_Linker_Section |
1200 Pragma_Lock_Free |
1201 Pragma_Locking_Policy |
1202 Pragma_Long_Float |
1203 Pragma_Loop_Invariant |
1204 Pragma_Loop_Optimize |
1205 Pragma_Loop_Variant |
1206 Pragma_Machine_Attribute |
1207 Pragma_Main |
1208 Pragma_Main_Storage |
1209 Pragma_Memory_Size |
1210 Pragma_No_Body |
1211 Pragma_No_Inline |
1212 Pragma_No_Return |
1213 Pragma_No_Run_Time |
1214 Pragma_No_Strict_Aliasing |
1215 Pragma_Normalize_Scalars |
1216 Pragma_Obsolescent |
1217 Pragma_Ordered |
1218 Pragma_Optimize |
1219 Pragma_Optimize_Alignment |
1220 Pragma_Overflow_Mode |
1221 Pragma_Overriding_Renamings |
1222 Pragma_Pack |
1223 Pragma_Partition_Elaboration_Policy |
1224 Pragma_Passive |
1225 Pragma_Preelaborable_Initialization |
1226 Pragma_Polling |
1227 Pragma_Persistent_BSS |
1228 Pragma_Postcondition |
1229 Pragma_Precondition |
1230 Pragma_Predicate |
1231 Pragma_Preelaborate |
1232 Pragma_Preelaborate_05 |
1233 Pragma_Priority |
1234 Pragma_Priority_Specific_Dispatching |
1235 Pragma_Profile |
1236 Pragma_Profile_Warnings |
1237 Pragma_Propagate_Exceptions |
1238 Pragma_Psect_Object |
1239 Pragma_Pure |
1240 Pragma_Pure_05 |
1241 Pragma_Pure_12 |
1242 Pragma_Pure_Function |
1243 Pragma_Queuing_Policy |
1244 Pragma_Relative_Deadline |
1245 Pragma_Remote_Access_Type |
1246 Pragma_Remote_Call_Interface |
1247 Pragma_Remote_Types |
1248 Pragma_Restricted_Run_Time |
1249 Pragma_Rational |
1250 Pragma_Ravenscar |
1251 Pragma_Reviewable |
1252 Pragma_Share_Generic |
1253 Pragma_Shared |
1254 Pragma_Shared_Passive |
1255 Pragma_Short_Circuit_And_Or |
1256 Pragma_Short_Descriptors |
1257 Pragma_Simple_Storage_Pool_Type |
1258 Pragma_Storage_Size |
1259 Pragma_Storage_Unit |
1260 Pragma_Static_Elaboration_Desired |
1261 Pragma_Stream_Convert |
1262 Pragma_Subtitle |
1263 Pragma_Suppress |
1264 Pragma_Suppress_Debug_Info |
1265 Pragma_Suppress_Exception_Locations |
1266 Pragma_Suppress_Initialization |
1267 Pragma_System_Name |
1268 Pragma_Task_Dispatching_Policy |
1269 Pragma_Task_Info |
1270 Pragma_Task_Name |
1271 Pragma_Task_Storage |
1272 Pragma_Test_Case |
1273 Pragma_Thread_Local_Storage |
1274 Pragma_Time_Slice |
1275 Pragma_Title |
1276 Pragma_Unchecked_Union |
1277 Pragma_Unimplemented_Unit |
1278 Pragma_Universal_Aliasing |
1279 Pragma_Universal_Data |
1280 Pragma_Unmodified |
1281 Pragma_Unreferenced |
1282 Pragma_Unreferenced_Objects |
1283 Pragma_Unreserve_All_Interrupts |
1284 Pragma_Unsuppress |
1285 Pragma_Use_VADS_Size |
1286 Pragma_Volatile |
1287 Pragma_Volatile_Components |
1288 Pragma_Weak_External |
1289 Pragma_Validity_Checks =>
1290 null;
1291
1292 --------------------
1293 -- Unknown_Pragma --
1294 --------------------
1295
1296 -- Should be impossible, since we excluded this case earlier on
1297
1298 when Unknown_Pragma =>
1299 raise Program_Error;
1300
1301 end case;
1302
1303 return Pragma_Node;
1304
1305 --------------------
1306 -- Error Handling --
1307 --------------------
1308
1309 exception
1310 when Error_Resync =>
1311 return Error;
1312
1313 end Prag;