Debian Codegraph @

gcc/ada/switch-c.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S W I T C H - C --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2001-2025, 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 -- This package is for switch processing and should not depend on higher level
27 -- packages such as those for the scanner, parser, etc. Doing so may cause
28 -- circularities, especially for back ends using Adabkend.
29
30 with Debug; use Debug;
31 with Lib; use Lib;
32 with Osint; use Osint;
33 with Opt; use Opt;
34 with Stylesw; use Stylesw;
35 with Targparm; use Targparm;
36 with Ttypes; use Ttypes;
37 with Validsw; use Validsw;
38 with Warnsw; use Warnsw;
39
40 with Ada.Unchecked_Deallocation;
41
42 with System.WCh_Con; use System.WCh_Con;
43 with System.OS_Lib;
44
45 package body Switch.C is
46
47 RTS_Specified : String_Access := null;
48 -- Used to detect multiple use of --RTS= flag
49
50 procedure Add_Symbol_Definition (Def : String);
51 -- Add a symbol definition from the command line
52
53 procedure Free is
54 new Ada.Unchecked_Deallocation (String_List, String_List_Access);
55 -- Avoid using System.Strings.Free, which also frees the designated strings
56
57 function Get_Overflow_Mode (C : Character) return Overflow_Mode_Type;
58 -- Given a digit in the range 0 .. 3, returns the corresponding value of
59 -- Overflow_Mode_Type. Raises Program_Error if C is outside this range.
60
61 function Switch_Subsequently_Cancelled
62 (C : String;
63 Args : String_List;
64 Arg_Rank : Positive) return Boolean;
65 -- This function is called from Scan_Front_End_Switches. It determines if
66 -- the switch currently being scanned is followed by a switch of the form
67 -- "-gnat-" & C, where C is the argument. If so, then True is returned,
68 -- and Scan_Front_End_Switches will cancel the effect of the switch. If
69 -- no such switch is found, False is returned.
70
71 ---------------------------
72 -- Add_Symbol_Definition --
73 ---------------------------
74
75 procedure Add_Symbol_Definition (Def : String) is
76 begin
77 -- If Preprocessor_Symbol_Defs is not large enough, double its size
78
79 if Preprocessing_Symbol_Last = Preprocessing_Symbol_Defs'Last then
80 declare
81 New_Symbol_Definitions : constant String_List_Access :=
82 new String_List (1 .. 2 * Preprocessing_Symbol_Last);
83 begin
84 New_Symbol_Definitions (Preprocessing_Symbol_Defs'Range) :=
85 Preprocessing_Symbol_Defs.all;
86 Free (Preprocessing_Symbol_Defs);
87 Preprocessing_Symbol_Defs := New_Symbol_Definitions;
88 end;
89 end if;
90
91 Preprocessing_Symbol_Last := Preprocessing_Symbol_Last + 1;
92 Preprocessing_Symbol_Defs (Preprocessing_Symbol_Last) :=
93 new String'(Def);
94 end Add_Symbol_Definition;
95
96 -----------------------
97 -- Get_Overflow_Mode --
98 -----------------------
99
100 function Get_Overflow_Mode (C : Character) return Overflow_Mode_Type is
101 begin
102 case C is
103 when '1' =>
104 return Strict;
105
106 when '2' =>
107 return Minimized;
108
109 -- Eliminated allowed only if Long_Long_Integer is 64 bits (since
110 -- the current implementation of System.Bignums assumes this).
111
112 when '3' =>
113 if Standard_Long_Long_Integer_Size /= 64 then
114 Bad_Switch ("-gnato3 requires Long_Long_Integer'Size = 64");
115 else
116 return Eliminated;
117 end if;
118
119 when others =>
120 raise Program_Error;
121 end case;
122 end Get_Overflow_Mode;
123
124 -----------------------------
125 -- Scan_Front_End_Switches --
126 -----------------------------
127
128 procedure Scan_Front_End_Switches
129 (Switch_Chars : String;
130 Args : String_List;
131 Arg_Rank : Positive)
132 is
133 Max : constant Natural := Switch_Chars'Last;
134 C : Character := ' ';
135 Ptr : Natural;
136
137 Dot : Boolean;
138 -- This flag is set upon encountering a dot in a debug switch
139
140 First_Char : Positive;
141 -- Marks start of switch to be stored
142
143 First_Ptr : Positive;
144 -- Save position of first character after -gnatd (for checking that
145 -- debug flags that must come first are first, in particular -gnatd.b).
146
147 First_Switch : Boolean := True;
148 -- False for all but first switch
149
150 Store_Switch : Boolean;
151 -- For -gnatxx switches, the normal processing, signalled by this flag
152 -- being set to True, is to store the switch on exit from the case
153 -- statement, the switch stored is -gnat followed by the characters
154 -- from First_Char to Ptr-1. For cases like -gnaty, where the switch
155 -- is stored in separate pieces, this flag is set to False, and the
156 -- appropriate calls to Store_Compilation_Switch are made from within
157 -- the case branch.
158
159 Underscore : Boolean;
160 -- This flag is set upon encountering an underscode in a debug switch
161
162 begin
163 Ptr := Switch_Chars'First;
164
165 -- Skip past the initial character (must be the switch character)
166
167 if Ptr = Max then
168 Bad_Switch (C);
169 else
170 Ptr := Ptr + 1;
171 end if;
172
173 -- Handle switches that do not start with -gnat
174
175 if Ptr + 3 > Max or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat" then
176
177 -- There are two front-end switches that do not start with -gnat:
178 -- -I, --RTS
179
180 if Switch_Chars (Ptr) = 'I' then
181
182 -- Set flag Search_Directory_Present if switch is "-I" only:
183 -- the directory will be the next argument.
184
185 if Ptr = Max then
186 Search_Directory_Present := True;
187 return;
188 end if;
189
190 Ptr := Ptr + 1;
191
192 -- Find out whether this is a -I- or regular -Ixxx switch
193
194 -- Note: -I switches are not recorded in the ALI file, since the
195 -- meaning of the program depends on the source files compiled,
196 -- not where they came from.
197
198 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
199 Look_In_Primary_Dir := False;
200 else
201 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
202 end if;
203
204 -- Processing of the --RTS switch. --RTS may have been modified by
205 -- gcc into -fRTS (for GCC targets).
206
207 elsif Ptr + 3 <= Max
208 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
209 or else
210 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
211 then
212 Ptr := Ptr + 1;
213
214 if Ptr + 4 > Max
215 or else Switch_Chars (Ptr + 3) /= '='
216 then
217 Osint.Fail ("missing path for --RTS");
218
219 else
220 declare
221 Runtime_Dir : String_Access;
222 begin
223 if System.OS_Lib.Is_Absolute_Path
224 (Switch_Chars (Ptr + 4 .. Max))
225 then
226 Runtime_Dir :=
227 new String'(System.OS_Lib.Normalize_Pathname
228 (Switch_Chars (Ptr + 4 .. Max)));
229 else
230 Runtime_Dir :=
231 new String'(Switch_Chars (Ptr + 4 .. Max));
232 end if;
233
234 -- Valid --RTS switch
235
236 Opt.No_Stdinc := True;
237 Opt.RTS_Switch := True;
238
239 RTS_Src_Path_Name :=
240 Get_RTS_Search_Dir (Runtime_Dir.all, Include);
241
242 RTS_Lib_Path_Name :=
243 Get_RTS_Search_Dir (Runtime_Dir.all, Objects);
244
245 if RTS_Specified /= null then
246 if RTS_Src_Path_Name = null
247 or else RTS_Lib_Path_Name = null
248 or else
249 System.OS_Lib.Normalize_Pathname
250 (RTS_Specified.all) /=
251 System.OS_Lib.Normalize_Pathname
252 (RTS_Lib_Path_Name.all)
253 then
254 Osint.Fail
255 ("--RTS cannot be specified multiple times");
256 end if;
257
258 elsif RTS_Src_Path_Name /= null
259 and then RTS_Lib_Path_Name /= null
260 then
261 -- Store the -fRTS switch (Note: Store_Compilation_Switch
262 -- changes -fRTS back into --RTS for the actual output).
263
264 Store_Compilation_Switch (Switch_Chars);
265 RTS_Specified := new String'(RTS_Lib_Path_Name.all);
266
267 elsif RTS_Src_Path_Name = null
268 and then RTS_Lib_Path_Name = null
269 then
270 Osint.Fail ("RTS path not valid: missing "
271 & "adainclude and adalib directories");
272
273 elsif RTS_Src_Path_Name = null then
274 Osint.Fail ("RTS path not valid: missing "
275 & "adainclude directory");
276
277 else pragma Assert (RTS_Lib_Path_Name = null);
278 Osint.Fail ("RTS path not valid: missing "
279 & "adalib directory");
280 end if;
281 end;
282 end if;
283
284 -- There are no other switches not starting with -gnat
285
286 else
287 Bad_Switch (Switch_Chars);
288 end if;
289
290 -- Case of switch starting with -gnat
291
292 else
293 Ptr := Ptr + 4;
294
295 -- Loop to scan through switches given in switch string
296
297 while Ptr <= Max loop
298 First_Char := Ptr;
299 Store_Switch := True;
300
301 C := Switch_Chars (Ptr);
302
303 case C is
304
305 -- -gnata (assertions enabled)
306
307 when 'a' =>
308 Ptr := Ptr + 1;
309 Assertions_Enabled := True;
310
311 -- -gnatA (disregard gnat.adc)
312
313 when 'A' =>
314 Ptr := Ptr + 1;
315 Config_File := False;
316
317 -- -gnatb (brief messages to stderr)
318
319 when 'b' =>
320 Ptr := Ptr + 1;
321 Brief_Output := True;
322
323 -- -gnatB (assume no invalid values)
324
325 when 'B' =>
326 Ptr := Ptr + 1;
327 Assume_No_Invalid_Values := True;
328
329 -- -gnatc (check syntax and semantics only)
330
331 when 'c' =>
332 if not First_Switch then
333 Osint.Fail
334 ("-gnatc must be first if combined with other switches");
335 end if;
336
337 Ptr := Ptr + 1;
338 Operating_Mode := Check_Semantics;
339
340 -- -gnatC (Generate CodePeer information)
341
342 when 'C' =>
343 Ptr := Ptr + 1;
344 CodePeer_Mode := True;
345
346 -- -gnatd (compiler debug options)
347
348 when 'd' =>
349 Dot := False;
350 Store_Switch := False;
351 Underscore := False;
352
353 First_Ptr := Ptr + 1;
354
355 -- Note: for the debug switch, the remaining characters in this
356 -- switch field must all be debug flags, since all valid switch
357 -- characters are also valid debug characters.
358
359 -- Loop to scan out debug flags
360
361 while Ptr < Max loop
362 Ptr := Ptr + 1;
363 C := Switch_Chars (Ptr);
364 exit when C = ASCII.NUL or else C = '/' or else C = '-';
365
366 if C in '1' .. '9' or else
367 C in 'a' .. 'z' or else
368 C in 'A' .. 'Z'
369 then
370 -- Case of dotted flag
371
372 if Dot then
373 Set_Dotted_Debug_Flag (C);
374 Store_Compilation_Switch ("-gnatd." & C);
375
376 -- Special check, -gnatd.b must come first
377
378 if C = 'b'
379 and then (Ptr /= First_Ptr + 1
380 or else not First_Switch)
381 then
382 Osint.Fail
383 ("-gnatd.b must be first if combined with other "
384 & "switches");
385 end if;
386
387 -- Case of an underscored flag
388
389 elsif Underscore then
390 Set_Underscored_Debug_Flag (C);
391 Store_Compilation_Switch ("-gnatd_" & C);
392 if Debug_Flag_Underscore_C then
393 Enable_CUDA_Expansion := True;
394 end if;
395
396 -- Normal flag
397
398 else
399 Set_Debug_Flag (C);
400 Store_Compilation_Switch ("-gnatd" & C);
401 end if;
402
403 elsif C = '.' then
404 Dot := True;
405
406 elsif C = '_' then
407 Underscore := True;
408
409 elsif Dot then
410 Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
411
412 elsif Underscore then
413 Bad_Switch ("-gnatd_" & Switch_Chars (Ptr .. Max));
414
415 else
416 Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
417 end if;
418 end loop;
419
420 return;
421
422 -- -gnatD (debug expanded code)
423
424 when 'D' =>
425 Ptr := Ptr + 1;
426
427 -- Not allowed if previous -gnatR given
428
429 -- The reason for this prohibition is that the rewriting of
430 -- Sloc values causes strange malfunctions in the tests of
431 -- whether units belong to the main source. This is really a
432 -- bug, but too hard to fix for a marginal capability.
433
434 -- The proper fix is to completely redo -gnatD processing so
435 -- that the tree is not messed with, and instead a separate
436 -- table is built on the side for debug information generation.
437
438 if List_Representation_Info /= 0 then
439 Osint.Fail
440 ("-gnatD not permitted since -gnatR given previously");
441 end if;
442
443 -- Scan optional integer line limit value
444
445 if Nat_Present (Switch_Chars, Max, Ptr) then
446 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'D');
447 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
448 end if;
449
450 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
451 -- generation in the ali file) since otherwise this generation
452 -- gets confused by the "wrong" Sloc values put in the tree.
453
454 Debug_Generated_Code := True;
455 Xref_Active := False;
456
457 -- -gnate? (extended switches)
458
459 when 'e' =>
460 Ptr := Ptr + 1;
461
462 -- The -gnate? switches are all double character switches
463 -- so we must always have a character after the e.
464
465 if Ptr > Max then
466 Bad_Switch ("-gnate");
467 end if;
468
469 case Switch_Chars (Ptr) is
470
471 -- -gnatea (initial delimiter of explicit switches)
472
473 -- This is an internal switch
474
475 -- All switches that come before -gnatea have been added by
476 -- the GCC driver and are not stored in the ALI file.
477 -- See also -gnatez below.
478
479 when 'a' =>
480 Store_Switch := False;
481 Enable_Switch_Storing;
482 Ptr := Ptr + 1;
483
484 -- -gnateA (aliasing checks on parameters)
485
486 when 'A' =>
487 Ptr := Ptr + 1;
488 Check_Aliasing_Of_Parameters := True;
489
490 -- -gnateb (config file basenames and checksums in ALI)
491
492 when 'b' =>
493 Ptr := Ptr + 1;
494 Config_Files_Store_Basename := True;
495
496 -- -gnatec (configuration pragmas)
497
498 when 'c' =>
499 Store_Switch := False;
500 Ptr := Ptr + 1;
501
502 -- There may be an equal sign between -gnatec and
503 -- the path name of the config file.
504
505 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
506 Ptr := Ptr + 1;
507 end if;
508
509 if Ptr > Max then
510 Bad_Switch ("-gnatec");
511 end if;
512
513 declare
514 Config_File_Name : constant String_Access :=
515 new String'
516 (Switch_Chars (Ptr .. Max));
517
518 begin
519 if Config_File_Names = null then
520 Config_File_Names :=
521 new String_List'(1 => Config_File_Name);
522
523 else
524 declare
525 New_Names : constant String_List_Access :=
526 new String_List
527 (1 ..
528 Config_File_Names'Length + 1);
529
530 begin
531 for Index in Config_File_Names'Range loop
532 New_Names (Index) :=
533 Config_File_Names (Index);
534 Config_File_Names (Index) := null;
535 end loop;
536
537 New_Names (New_Names'Last) := Config_File_Name;
538 Free (Config_File_Names);
539 Config_File_Names := New_Names;
540 end;
541 end if;
542 end;
543
544 return;
545
546 -- -gnateC switch (generate CodePeer messages)
547
548 when 'C' =>
549 Ptr := Ptr + 1;
550
551 if not Generate_CodePeer_Messages then
552 Generate_CodePeer_Messages := True;
553 CodePeer_Mode := True;
554 Warning_Mode := Normal;
555 Warning_Doc_Switch := True; -- -gnatw.d
556
557 -- Enable warnings potentially useful for non GNAT
558 -- users.
559
560 Constant_Condition_Warnings := True; -- -gnatwc
561 Warn_On_Assertion_Failure := True; -- -gnatw.a
562 Warn_On_Assumed_Low_Bound := True; -- -gnatww
563 Warn_On_Bad_Fixed_Value := True; -- -gnatwb
564 Warn_On_Biased_Representation := True; -- -gnatw.b
565 Warn_On_Export_Import := True; -- -gnatwx
566 Warn_On_No_Value_Assigned := True; -- -gnatwv
567 Warn_On_Object_Renames_Function := True; -- -gnatw.r
568 Warn_On_Overlap := True; -- -gnatw.i
569 Warn_On_Parameter_Order := True; -- -gnatw.p
570 Warn_On_Questionable_Missing_Parens := True; -- -gnatwq
571 Warn_On_Redundant_Constructs := True; -- -gnatwr
572 Warn_On_Suspicious_Modulus_Value := True; -- -gnatw.m
573 end if;
574
575 -- -gnated switch (disable atomic synchronization)
576
577 when 'd' =>
578 Suppress_Options.Suppress (Atomic_Synchronization) :=
579 True;
580
581 -- -gnateD switch (preprocessing symbol definition)
582
583 when 'D' =>
584 Store_Switch := False;
585 Ptr := Ptr + 1;
586
587 if Ptr > Max then
588 Bad_Switch ("-gnateD");
589 end if;
590
591 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
592
593 -- Store the switch
594
595 Store_Compilation_Switch
596 ("-gnateD" & Switch_Chars (Ptr .. Max));
597 Ptr := Max + 1;
598
599 -- -gnateE (extra exception information)
600
601 when 'E' =>
602 Exception_Extra_Info := True;
603 Ptr := Ptr + 1;
604
605 -- -gnatef (full source path for brief error messages and
606 -- absolute paths for -fdiagnostics-format=json)
607
608 when 'f' =>
609 Store_Switch := False;
610 Ptr := Ptr + 1;
611 Full_Path_Name_For_Brief_Errors := True;
612
613 -- -gnateF (Check_Float_Overflow)
614
615 when 'F' =>
616 Ptr := Ptr + 1;
617 Check_Float_Overflow := not Machine_Overflows_On_Target;
618
619 -- -gnateg (generate C header)
620
621 when 'g' =>
622 -- Special check, -gnateg must occur after -gnatc
623
624 if Operating_Mode /= Check_Semantics then
625 Osint.Fail
626 ("gnateg requires previous occurrence of -gnatc");
627 end if;
628
629 Generate_C_Header := True;
630 Ptr := Ptr + 1;
631
632 -- -gnateG (save preprocessor output)
633
634 when 'G' =>
635 Generate_Processed_File := True;
636 Ptr := Ptr + 1;
637
638 -- -gnateH (set reverse Bit_Order threshold to 64)
639
640 when 'H' =>
641 Reverse_Bit_Order_Threshold := 64;
642 Ptr := Ptr + 1;
643
644 -- -gnatei (max number of instantiations)
645
646 when 'i' =>
647 Ptr := Ptr + 1;
648 Scan_Pos
649 (Switch_Chars, Max, Ptr, Maximum_Instantiations, C);
650
651 -- -gnateI (index of unit in multi-unit source)
652
653 when 'I' =>
654 Ptr := Ptr + 1;
655 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
656
657 -- -gnatel
658
659 when 'l' =>
660 Ptr := Ptr + 1;
661 Elab_Info_Messages := True;
662
663 -- -gnateL
664
665 when 'L' =>
666 Ptr := Ptr + 1;
667 Elab_Info_Messages := False;
668
669 -- -gnatem (mapping file)
670
671 when 'm' =>
672 Store_Switch := False;
673 Ptr := Ptr + 1;
674
675 -- There may be an equal sign between -gnatem and
676 -- the path name of the mapping file.
677
678 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
679 Ptr := Ptr + 1;
680 end if;
681
682 if Ptr > Max then
683 Bad_Switch ("-gnatem");
684 end if;
685
686 Mapping_File_Name :=
687 new String'(Switch_Chars (Ptr .. Max));
688 return;
689
690 -- -gnaten (memory to allocate for nodes)
691
692 when 'n' =>
693 Ptr := Ptr + 1;
694 Scan_Pos
695 (Switch_Chars, Max, Ptr, Nodes_Size_In_Meg, C);
696
697 -- -gnateO= (object path file)
698
699 -- This is an internal switch
700
701 when 'O' =>
702 Store_Switch := False;
703 Ptr := Ptr + 1;
704
705 -- Check for '='
706
707 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
708 Bad_Switch ("-gnateO");
709 else
710 Object_Path_File_Name :=
711 new String'(Switch_Chars (Ptr + 1 .. Max));
712 end if;
713
714 return;
715
716 -- -gnatep (preprocessing data file)
717
718 when 'p' =>
719 Store_Switch := False;
720 Ptr := Ptr + 1;
721
722 -- There may be an equal sign between -gnatep and
723 -- the path name of the mapping file.
724
725 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
726 Ptr := Ptr + 1;
727 end if;
728
729 if Ptr > Max then
730 Bad_Switch ("-gnatep");
731 end if;
732
733 Preprocessing_Data_File :=
734 new String'(Switch_Chars (Ptr .. Max));
735
736 -- Store the switch, normalizing to -gnatep=
737
738 Store_Compilation_Switch
739 ("-gnatep=" & Preprocessing_Data_File.all);
740
741 Ptr := Max + 1;
742
743 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
744
745 when 'P' =>
746 Treat_Categorization_Errors_As_Warnings := True;
747 Ptr := Ptr + 1;
748
749 -- -gnates=file (specify extra file switches for gnat2why)
750
751 -- This is an internal switch
752
753 when 's' =>
754 if not First_Switch then
755 Osint.Fail
756 ("-gnates must not be combined with other switches");
757 end if;
758
759 -- Check for '='
760
761 Ptr := Ptr + 1;
762
763 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
764 Bad_Switch ("-gnates");
765 else
766 SPARK_Switches_File_Name :=
767 new String'(Switch_Chars (Ptr + 1 .. Max));
768 end if;
769
770 return;
771
772 -- -gnateS (generate SCO information)
773
774 -- Include Source Coverage Obligation information in ALI
775 -- files for use by source coverage analysis tools
776 -- (gnatcov) (equivalent to -fdump-scos, provided for
777 -- backwards compatibility).
778
779 when 'S' =>
780 Generate_SCO := True;
781 Generate_SCO_Instance_Table := True;
782 Ptr := Ptr + 1;
783
784 -- -gnatet (write target dependent information)
785
786 when 't' =>
787 if not First_Switch then
788 Osint.Fail
789 ("-gnatet must not be combined with other switches");
790 end if;
791
792 -- Check for '='
793
794 Ptr := Ptr + 1;
795
796 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
797 Bad_Switch ("-gnatet");
798 else
799 Target_Dependent_Info_Write_Name :=
800 new String'(Switch_Chars (Ptr + 1 .. Max));
801 end if;
802
803 return;
804
805 -- -gnateT (read target dependent information)
806
807 when 'T' =>
808 if not First_Switch then
809 Osint.Fail
810 ("-gnateT must not be combined with other switches");
811 end if;
812
813 -- Check for '='
814
815 Ptr := Ptr + 1;
816
817 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
818 Bad_Switch ("-gnateT");
819 else
820 -- This parameter was stored by Set_Targ earlier
821
822 pragma Assert
823 (Target_Dependent_Info_Read_Name.all =
824 Switch_Chars (Ptr + 1 .. Max));
825 null;
826 end if;
827
828 return;
829
830 -- -gnateu (unrecognized y,V,w switches)
831
832 when 'u' =>
833 Ignore_Unrecognized_VWY_Switches := True;
834 Ptr := Ptr + 1;
835
836 -- -gnateV (validity checks on parameters)
837
838 when 'V' =>
839 Ptr := Ptr + 1;
840 Check_Validity_Of_Parameters := True;
841
842 -- -gnateY (ignore Style_Checks pragmas)
843
844 when 'Y' =>
845 Ignore_Style_Checks_Pragmas := True;
846 Ptr := Ptr + 1;
847
848 -- -gnatez (final delimiter of explicit switches)
849
850 -- This is an internal switch
851
852 -- All switches that come after -gnatez have been added by
853 -- the GCC driver and are not stored in the ALI file. See
854 -- also -gnatea above.
855
856 when 'z' =>
857 Store_Switch := False;
858 Disable_Switch_Storing;
859 Ptr := Ptr + 1;
860
861 -- All other -gnate? switches are unassigned
862
863 when others =>
864 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
865 end case;
866
867 -- -gnatE (dynamic elaboration checks)
868
869 when 'E' =>
870 Ptr := Ptr + 1;
871 Dynamic_Elaboration_Checks := True;
872
873 -- -gnatf (full error messages)
874
875 when 'f' =>
876 Ptr := Ptr + 1;
877 All_Errors_Mode := True;
878
879 -- -gnatF (overflow of predefined float types)
880
881 when 'F' =>
882 Ptr := Ptr + 1;
883 External_Name_Exp_Casing := Uppercase;
884 External_Name_Imp_Casing := Uppercase;
885
886 -- -gnatg (GNAT implementation mode)
887
888 when 'g' =>
889 Ptr := Ptr + 1;
890 GNAT_Mode := True;
891 GNAT_Mode_Config := True;
892 Identifier_Character_Set := 'n';
893 System_Extend_Unit := Empty;
894 Warning_Mode := Treat_As_Error;
895 Style_Check_Main := True;
896 Ada_Version := Ada_2012;
897 Ada_Version_Explicit := Ada_2012;
898 Ada_Version_Pragma := Empty;
899
900 -- Set default warnings and style checks for -gnatg
901
902 Set_GNAT_Mode_Warnings;
903 Set_GNAT_Style_Check_Options;
904
905 -- -gnatG (output generated code)
906
907 when 'G' =>
908 Ptr := Ptr + 1;
909 Print_Generated_Code := True;
910
911 -- Scan optional integer line limit value
912
913 if Nat_Present (Switch_Chars, Max, Ptr) then
914 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
915 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
916 end if;
917
918 -- -gnath (help information)
919
920 when 'h' =>
921 Ptr := Ptr + 1;
922 Usage_Requested := True;
923
924 -- -gnatH (legacy static elaboration checking mode enabled)
925
926 when 'H' =>
927 Ptr := Ptr + 1;
928 Legacy_Elaboration_Checks := True;
929
930 -- -gnati[1-5|8|9|p|f|n|w] (character set)
931 -- -gnatis (suppress info messages)
932
933 when 'i' =>
934 if Ptr = Max then
935 Bad_Switch ("-gnati");
936 end if;
937
938 Ptr := Ptr + 1;
939 C := Switch_Chars (Ptr);
940
941 if C in '1' .. '5' | '8' | 'p' | '9' | 'f' | 'n' | 'w' then
942 Identifier_Character_Set := C;
943 Ptr := Ptr + 1;
944 elsif C = 's' then
945 Info_Suppressed := True;
946 Ptr := Ptr + 1;
947
948 else
949 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
950 end if;
951
952 -- -gnatI (ignore representation clauses)
953
954 when 'I' =>
955 Ptr := Ptr + 1;
956 Ignore_Rep_Clauses := True;
957
958 -- -gnatj (messages in limited length lines)
959
960 when 'j' =>
961 Ptr := Ptr + 1;
962 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
963
964 -- -gnatJ (relaxed elaboration checking mode enabled)
965
966 when 'J' =>
967 Ptr := Ptr + 1;
968 Relaxed_Elaboration_Checks := True;
969
970 -- Common relaxations for both ABE mechanisms
971 --
972 -- -gnatd.G (ignore calls through generic formal parameters
973 -- for elaboration)
974 -- -gnatd.U (ignore indirect calls for static elaboration)
975 -- -gnatd.y (disable implicit pragma Elaborate_All on task
976 -- bodies)
977
978 Debug_Flag_Dot_GG := True;
979 Debug_Flag_Dot_UU := True;
980 Debug_Flag_Dot_Y := True;
981
982 -- Relaxatons to the legacy ABE mechanism
983
984 if Legacy_Elaboration_Checks then
985 null;
986
987 -- Relaxations to the default ABE mechanism
988 --
989 -- -gnatd_a (stop elaboration checks on accept or select
990 -- statement)
991 -- -gnatd_e (ignore entry calls and requeue statements for
992 -- elaboration)
993 -- -gnatd_i (ignore activations and calls to instances for
994 -- elaboration)
995 -- -gnatd_p (ignore assertion pragmas for elaboration)
996 -- -gnatd_s (stop elaboration checks on synchronous
997 -- suspension)
998 -- -gnatdL (ignore external calls from instances for
999 -- elaboration)
1000
1001 else
1002 Debug_Flag_Underscore_A := True;
1003 Debug_Flag_Underscore_E := True;
1004 Debug_Flag_Underscore_I := True;
1005 Debug_Flag_Underscore_P := True;
1006 Debug_Flag_Underscore_S := True;
1007 Debug_Flag_LL := True;
1008 end if;
1009
1010 -- -gnatk (limit file name length)
1011
1012 when 'k' =>
1013 Ptr := Ptr + 1;
1014 Scan_Pos
1015 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
1016
1017 -- -gnatl (output full source)
1018
1019 when 'l' =>
1020 Ptr := Ptr + 1;
1021 Full_List := True;
1022
1023 -- There may be an equal sign between -gnatl and a file name
1024
1025 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
1026 if Ptr = Max then
1027 Osint.Fail ("file name for -gnatl= is null");
1028 else
1029 Opt.Full_List_File_Name :=
1030 new String'(Switch_Chars (Ptr + 1 .. Max));
1031 Ptr := Max + 1;
1032 end if;
1033 end if;
1034
1035 -- -gnatL (corresponding source text)
1036
1037 when 'L' =>
1038 Ptr := Ptr + 1;
1039 Dump_Source_Text := True;
1040
1041 -- -gnatm (max number or errors/warnings)
1042
1043 when 'm' =>
1044 Ptr := Ptr + 1;
1045 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Messages, C);
1046
1047 -- -gnatn (enable pragma Inline)
1048
1049 when 'n' =>
1050 Ptr := Ptr + 1;
1051 Inline_Active := True;
1052
1053 -- There may be a digit (1 or 2) appended to the switch
1054
1055 if Ptr <= Max then
1056 C := Switch_Chars (Ptr);
1057
1058 if C in '1' .. '2' then
1059 Ptr := Ptr + 1;
1060 Inline_Level := Character'Pos (C) - Character'Pos ('0');
1061 end if;
1062 end if;
1063
1064 -- -gnatN (obsolescent)
1065
1066 when 'N' =>
1067 Ptr := Ptr + 1;
1068 Inline_Active := True;
1069 Front_End_Inlining := True;
1070
1071 -- -gnato (overflow checks)
1072
1073 when 'o' =>
1074 Ptr := Ptr + 1;
1075
1076 -- Case of -gnato0 (overflow checking turned off)
1077
1078 if Ptr <= Max and then Switch_Chars (Ptr) = '0' then
1079 Ptr := Ptr + 1;
1080 Suppress_Options.Suppress (Overflow_Check) := True;
1081
1082 -- We set strict mode in case overflow checking is turned
1083 -- on locally (also records that we had a -gnato switch).
1084
1085 Suppress_Options.Overflow_Mode_General := Strict;
1086 Suppress_Options.Overflow_Mode_Assertions := Strict;
1087
1088 -- All cases other than -gnato0 (overflow checking turned on)
1089
1090 else
1091 Suppress_Options.Suppress (Overflow_Check) := False;
1092
1093 -- Case of no digits after the -gnato
1094
1095 if Ptr > Max
1096 or else Switch_Chars (Ptr) not in '1' .. '3'
1097 then
1098 Suppress_Options.Overflow_Mode_General := Strict;
1099 Suppress_Options.Overflow_Mode_Assertions := Strict;
1100
1101 -- At least one digit after the -gnato
1102
1103 else
1104 -- Handle first digit after -gnato
1105
1106 Suppress_Options.Overflow_Mode_General :=
1107 Get_Overflow_Mode (Switch_Chars (Ptr));
1108 Ptr := Ptr + 1;
1109
1110 -- Only one digit after -gnato, set assertions mode to be
1111 -- the same as general mode.
1112
1113 if Ptr > Max
1114 or else Switch_Chars (Ptr) not in '1' .. '3'
1115 then
1116 Suppress_Options.Overflow_Mode_Assertions :=
1117 Suppress_Options.Overflow_Mode_General;
1118
1119 -- Process second digit after -gnato
1120
1121 else
1122 Suppress_Options.Overflow_Mode_Assertions :=
1123 Get_Overflow_Mode (Switch_Chars (Ptr));
1124 Ptr := Ptr + 1;
1125 end if;
1126 end if;
1127 end if;
1128
1129 -- -gnatO (specify name of the object file)
1130
1131 -- This is an internal switch
1132
1133 when 'O' =>
1134 Store_Switch := False;
1135 Ptr := Ptr + 1;
1136 Output_File_Name_Present := True;
1137
1138 -- -gnatp (suppress all checks)
1139
1140 when 'p' =>
1141 Ptr := Ptr + 1;
1142
1143 -- Skip processing if cancelled by subsequent -gnat-p
1144
1145 if Switch_Subsequently_Cancelled ("p", Args, Arg_Rank) then
1146 Store_Switch := False;
1147
1148 else
1149 -- Set all specific options as well as All_Checks in the
1150 -- Suppress_Options array, excluding Elaboration_Check,
1151 -- since this is treated specially because we do not want
1152 -- -gnatp to disable static elaboration processing. Also
1153 -- exclude Atomic_Synchronization, since this is not a real
1154 -- check.
1155
1156 for J in Suppress_Options.Suppress'Range loop
1157 if J not in Elaboration_Check | Atomic_Synchronization
1158 then
1159 Suppress_Options.Suppress (J) := True;
1160 end if;
1161 end loop;
1162
1163 Validity_Checks_On := False;
1164 Opt.Suppress_Checks := True;
1165
1166 -- Set overflow mode checking to strict in case it gets
1167 -- turned on locally (also signals that overflow checking
1168 -- has been specifically turned off).
1169
1170 Suppress_Options.Overflow_Mode_General := Strict;
1171 Suppress_Options.Overflow_Mode_Assertions := Strict;
1172 end if;
1173
1174 -- -gnatq (don't quit)
1175
1176 when 'q' =>
1177 Ptr := Ptr + 1;
1178 Try_Semantics := True;
1179
1180 -- -gnatQ (always write ALI file)
1181
1182 when 'Q' =>
1183 Ptr := Ptr + 1;
1184 Force_ALI_File := True;
1185 Try_Semantics := True;
1186
1187 -- -gnatr (restrictions as warnings)
1188
1189 when 'r' =>
1190 Ptr := Ptr + 1;
1191 Treat_Restrictions_As_Warnings := True;
1192
1193 -- -gnatR (list rep. info)
1194
1195 when 'R' =>
1196
1197 -- Not allowed if previous -gnatD given. See more extensive
1198 -- comments in the 'D' section for the inverse test.
1199
1200 if Debug_Generated_Code then
1201 Osint.Fail
1202 ("-gnatR not permitted since -gnatD given previously");
1203 end if;
1204
1205 -- Set to annotate rep info, and set default -gnatR mode
1206
1207 Back_Annotate_Rep_Info := True;
1208 List_Representation_Info := 1;
1209
1210 -- Scan possible parameter
1211
1212 Ptr := Ptr + 1;
1213 while Ptr <= Max loop
1214 C := Switch_Chars (Ptr);
1215
1216 case C is
1217
1218 when '0' .. '4' =>
1219 List_Representation_Info :=
1220 Character'Pos (C) - Character'Pos ('0');
1221
1222 when 's' =>
1223 List_Representation_Info_To_File := True;
1224
1225 when 'j' =>
1226 List_Representation_Info_To_JSON := True;
1227
1228 when 'm' =>
1229 List_Representation_Info_Mechanisms := True;
1230
1231 when 'e' =>
1232 List_Representation_Info_Extended := True;
1233
1234 when others =>
1235 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
1236 end case;
1237
1238 Ptr := Ptr + 1;
1239 end loop;
1240
1241 if List_Representation_Info_To_JSON
1242 and then List_Representation_Info_Extended
1243 then
1244 Osint.Fail ("-gnatRe is incompatible with -gnatRj");
1245 end if;
1246
1247 -- -gnats (syntax check only)
1248
1249 when 's' =>
1250 if not First_Switch then
1251 Osint.Fail
1252 ("-gnats must be first if combined with other switches");
1253 end if;
1254
1255 Ptr := Ptr + 1;
1256 Operating_Mode := Check_Syntax;
1257
1258 -- -gnatS (print package Standard)
1259
1260 when 'S' =>
1261 Print_Standard := True;
1262 Ptr := Ptr + 1;
1263
1264 -- -gnatT (change start of internal table sizes)
1265
1266 when 'T' =>
1267 Ptr := Ptr + 1;
1268 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
1269
1270 -- -gnatu (list units for compilation)
1271
1272 when 'u' =>
1273 Ptr := Ptr + 1;
1274 List_Units := True;
1275
1276 -- -gnatU (unique tags)
1277
1278 when 'U' =>
1279 Ptr := Ptr + 1;
1280 Unique_Error_Tag := True;
1281
1282 -- -gnatv (verbose mode)
1283
1284 when 'v' =>
1285 Ptr := Ptr + 1;
1286 Verbose_Mode := True;
1287
1288 -- -gnatV (validity checks)
1289
1290 when 'V' =>
1291 Store_Switch := False;
1292 Ptr := Ptr + 1;
1293
1294 if Ptr > Max then
1295 Bad_Switch ("-gnatV");
1296
1297 else
1298 declare
1299 OK : Boolean;
1300
1301 begin
1302 Set_Validity_Check_Options
1303 (Switch_Chars (Ptr .. Max), OK, Ptr);
1304
1305 if not OK then
1306 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
1307 end if;
1308
1309 for Index in First_Char + 1 .. Max loop
1310 Store_Compilation_Switch
1311 ("-gnatV" & Switch_Chars (Index));
1312 end loop;
1313 end;
1314 end if;
1315
1316 Ptr := Max + 1;
1317
1318 -- -gnatw (warning modes)
1319
1320 when 'w' =>
1321 Store_Switch := False;
1322 Ptr := Ptr + 1;
1323
1324 if Ptr > Max then
1325 Bad_Switch ("-gnatw");
1326 end if;
1327
1328 while Ptr <= Max loop
1329 C := Switch_Chars (Ptr);
1330
1331 -- Case of dot switch
1332
1333 if C = '.' and then Ptr < Max then
1334 Ptr := Ptr + 1;
1335 C := Switch_Chars (Ptr);
1336
1337 if Set_Warning_Switch ('.', C) then
1338 Store_Compilation_Switch ("-gnatw." & C);
1339 else
1340 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
1341 end if;
1342
1343 -- Case of underscore switch
1344
1345 elsif C = '_' and then Ptr < Max then
1346 Ptr := Ptr + 1;
1347 C := Switch_Chars (Ptr);
1348
1349 if Set_Warning_Switch ('_', C) then
1350 Store_Compilation_Switch ("-gnatw_" & C);
1351 else
1352 Bad_Switch ("-gnatw_" & Switch_Chars (Ptr .. Max));
1353 end if;
1354
1355 -- Normal case
1356
1357 else
1358 if Set_Warning_Switch (Plain, C) then
1359 Store_Compilation_Switch ("-gnatw" & C);
1360 else
1361 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
1362 end if;
1363 end if;
1364
1365 Ptr := Ptr + 1;
1366 end loop;
1367
1368 return;
1369
1370 -- -gnatW (wide character encoding method)
1371
1372 when 'W' =>
1373 Ptr := Ptr + 1;
1374
1375 if Ptr > Max then
1376 Bad_Switch ("-gnatW");
1377 end if;
1378
1379 begin
1380 Wide_Character_Encoding_Method :=
1381 Get_WC_Encoding_Method (Switch_Chars (Ptr));
1382 exception
1383 when Constraint_Error =>
1384 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
1385 end;
1386
1387 Wide_Character_Encoding_Method_Specified := True;
1388
1389 Upper_Half_Encoding :=
1390 Wide_Character_Encoding_Method in
1391 WC_Upper_Half_Encoding_Method;
1392
1393 Ptr := Ptr + 1;
1394
1395 -- -gnatx (suppress cross-ref information)
1396
1397 when 'x' =>
1398 Ptr := Ptr + 1;
1399 Xref_Active := False;
1400
1401 -- -gnatX (core language extensions)
1402
1403 when 'X' =>
1404 Ptr := Ptr + 1;
1405
1406 if Ptr <= Max and then Switch_Chars (Ptr) = '0' then
1407 -- -gnatX0 (all language extensions)
1408
1409 Ptr := Ptr + 1;
1410 Ada_Version := Ada_With_All_Extensions;
1411 else
1412 Ada_Version := Ada_With_Core_Extensions;
1413 end if;
1414
1415 Ada_Version_Explicit := Ada_Version;
1416 Ada_Version_Pragma := Empty;
1417
1418 -- -gnaty (style checks)
1419
1420 when 'y' =>
1421 Ptr := Ptr + 1;
1422 Style_Check_Main := True;
1423
1424 if Ptr > Max then
1425 Set_Default_Style_Check_Options;
1426
1427 else
1428 Store_Switch := False;
1429
1430 declare
1431 OK : Boolean;
1432
1433 begin
1434 Set_Style_Check_Options
1435 (Switch_Chars (Ptr .. Max), OK, Ptr);
1436
1437 if not OK then
1438 Osint.Fail
1439 ("bad -gnaty switch (" &
1440 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
1441 end if;
1442
1443 Ptr := First_Char + 1;
1444 while Ptr <= Max loop
1445 if Switch_Chars (Ptr) = 'M' then
1446 First_Char := Ptr;
1447 loop
1448 Ptr := Ptr + 1;
1449 exit when Ptr > Max
1450 or else Switch_Chars (Ptr) not in '0' .. '9';
1451 end loop;
1452
1453 Store_Compilation_Switch
1454 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
1455
1456 else
1457 Store_Compilation_Switch
1458 ("-gnaty" & Switch_Chars (Ptr));
1459 Ptr := Ptr + 1;
1460 end if;
1461 end loop;
1462 end;
1463 end if;
1464
1465 -- -gnatz (stub generation)
1466
1467 when 'z' =>
1468
1469 -- -gnatz must be the first and only switch in Switch_Chars,
1470 -- and is a two-letter switch.
1471
1472 if Ptr /= Switch_Chars'First + 5
1473 or else (Max - Ptr + 1) > 2
1474 then
1475 Osint.Fail
1476 ("-gnatz* may not be combined with other switches");
1477 end if;
1478
1479 if Ptr = Max then
1480 Bad_Switch ("-gnatz");
1481 end if;
1482
1483 Ptr := Ptr + 1;
1484
1485 -- Only one occurrence of -gnat* is permitted
1486
1487 if Distribution_Stub_Mode = No_Stubs then
1488 case Switch_Chars (Ptr) is
1489 when 'r' =>
1490 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1491
1492 when 'c' =>
1493 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1494
1495 when others =>
1496 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
1497 end case;
1498
1499 Ptr := Ptr + 1;
1500
1501 else
1502 Osint.Fail ("only one -gnatz* switch allowed");
1503 end if;
1504
1505 -- -gnatZ (obsolescent)
1506
1507 when 'Z' =>
1508 Ptr := Ptr + 1;
1509 Osint.Fail
1510 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1511
1512 -- Note on language version switches: whenever a new language
1513 -- version switch is added, Switch.M.Normalize_Compiler_Switches
1514 -- must be updated.
1515
1516 -- -gnat83
1517
1518 when '8' =>
1519 if Ptr = Max then
1520 Bad_Switch ("-gnat8");
1521 end if;
1522
1523 Ptr := Ptr + 1;
1524
1525 if Switch_Chars (Ptr) /= '3' or else Latest_Ada_Only then
1526 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
1527 else
1528 Ptr := Ptr + 1;
1529 Ada_Version := Ada_83;
1530 Ada_Version_Explicit := Ada_83;
1531 Ada_Version_Pragma := Empty;
1532 end if;
1533
1534 -- -gnat95
1535
1536 when '9' =>
1537 if Ptr = Max then
1538 Bad_Switch ("-gnat9");
1539 end if;
1540
1541 Ptr := Ptr + 1;
1542
1543 if Switch_Chars (Ptr) /= '5' or else Latest_Ada_Only then
1544 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
1545 else
1546 Ptr := Ptr + 1;
1547 Ada_Version := Ada_95;
1548 Ada_Version_Explicit := Ada_95;
1549 Ada_Version_Pragma := Empty;
1550 end if;
1551
1552 -- -gnat05
1553
1554 when '0' =>
1555 if Ptr = Max then
1556 Bad_Switch ("-gnat0");
1557 end if;
1558
1559 Ptr := Ptr + 1;
1560
1561 if Switch_Chars (Ptr) /= '5' or else Latest_Ada_Only then
1562 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1563 else
1564 Ptr := Ptr + 1;
1565 Ada_Version := Ada_2005;
1566 Ada_Version_Explicit := Ada_2005;
1567 Ada_Version_Pragma := Empty;
1568 end if;
1569
1570 -- -gnat12
1571
1572 when '1' =>
1573 if Ptr = Max then
1574 Bad_Switch ("-gnat1");
1575 end if;
1576
1577 Ptr := Ptr + 1;
1578
1579 if Switch_Chars (Ptr) /= '2' then
1580 Bad_Switch ("-gnat1" & Switch_Chars (Ptr .. Max));
1581 else
1582 Ptr := Ptr + 1;
1583 Ada_Version := Ada_2012;
1584 Ada_Version_Explicit := Ada_2012;
1585 Ada_Version_Pragma := Empty;
1586 end if;
1587
1588 -- -gnat2005 and -gnat2012
1589
1590 when '2' =>
1591 if Ptr > Max - 3 then
1592 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1593
1594 elsif Switch_Chars (Ptr .. Ptr + 3) = "2005"
1595 and then not Latest_Ada_Only
1596 then
1597 Ada_Version := Ada_2005;
1598
1599 elsif Switch_Chars (Ptr .. Ptr + 3) = "2012" then
1600 Ada_Version := Ada_2012;
1601
1602 elsif Switch_Chars (Ptr .. Ptr + 3) = "2020"
1603 or else Switch_Chars (Ptr .. Ptr + 3) = "2022"
1604 then
1605 Ada_Version := Ada_2022;
1606
1607 else
1608 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Ptr + 3));
1609 end if;
1610
1611 Ada_Version_Explicit := Ada_Version;
1612 Ada_Version_Pragma := Empty;
1613 Ptr := Ptr + 4;
1614
1615 -- Switch cancellation, currently only -gnat-p is allowed.
1616 -- All we do here is the error checking, since the actual
1617 -- processing for switch cancellation is done by calls to
1618 -- Switch_Subsequently_Cancelled at the appropriate point.
1619
1620 when '-' =>
1621
1622 -- Simple ignore -gnat-p
1623
1624 if Switch_Chars = "-gnat-p" then
1625 return;
1626
1627 -- Any other occurrence of minus is ignored. This is for
1628 -- maximum compatibility with previous version which ignored
1629 -- all occurrences of minus.
1630
1631 else
1632 Store_Switch := False;
1633 Ptr := Ptr + 1;
1634 end if;
1635
1636 -- Anything else is an error (illegal switch character)
1637
1638 when others =>
1639 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1640 end case;
1641
1642 if Store_Switch then
1643 Store_Compilation_Switch
1644 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1645 end if;
1646
1647 First_Switch := False;
1648 end loop;
1649 end if;
1650 end Scan_Front_End_Switches;
1651
1652 -----------------------------------
1653 -- Switch_Subsequently_Cancelled --
1654 -----------------------------------
1655
1656 function Switch_Subsequently_Cancelled
1657 (C : String;
1658 Args : String_List;
1659 Arg_Rank : Positive) return Boolean
1660 is
1661 begin
1662 -- Loop through arguments following the current one
1663
1664 for Arg in Arg_Rank + 1 .. Args'Last loop
1665 if Args (Arg).all = "-gnat-" & C then
1666 return True;
1667 end if;
1668 end loop;
1669
1670 -- No match found, not cancelled
1671
1672 return False;
1673 end Switch_Subsequently_Cancelled;
1674
1675 end Switch.C;