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