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