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