[multiple changes]
[gcc.git] / gcc / ada / switch-c.adb
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-2012, 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 Validsw; use Validsw;
35 with Stylesw; use Stylesw;
36 with Ttypes; use Ttypes;
37 with Warnsw; use Warnsw;
38
39 with Ada.Unchecked_Deallocation;
40 with System.WCh_Con; use System.WCh_Con;
41
42 package body Switch.C is
43
44 RTS_Specified : String_Access := null;
45 -- Used to detect multiple use of --RTS= flag
46
47 procedure Add_Symbol_Definition (Def : String);
48 -- Add a symbol definition from the command line
49
50 procedure Free is
51 new Ada.Unchecked_Deallocation (String_List, String_List_Access);
52 -- Avoid using System.Strings.Free, which also frees the designated strings
53
54 function Get_Overflow_Mode (C : Character) return Overflow_Mode_Type;
55 -- Given a digit in the range 0 .. 3, returns the corresponding value of
56 -- Overflow_Mode_Type. Raises Program_Error if C is outside this range.
57
58 function Switch_Subsequently_Cancelled
59 (C : String;
60 Args : String_List;
61 Arg_Rank : Positive) return Boolean;
62 -- This function is called from Scan_Front_End_Switches. It determines if
63 -- the switch currently being scanned is followed by a switch of the form
64 -- "-gnat-" & C, where C is the argument. If so, then True is returned,
65 -- and Scan_Front_End_Switches will cancel the effect of the switch. If
66 -- no such switch is found, False is returned.
67
68 ---------------------------
69 -- Add_Symbol_Definition --
70 ---------------------------
71
72 procedure Add_Symbol_Definition (Def : String) is
73 begin
74 -- If Preprocessor_Symbol_Defs is not large enough, double its size
75
76 if Preprocessing_Symbol_Last = Preprocessing_Symbol_Defs'Last then
77 declare
78 New_Symbol_Definitions : constant String_List_Access :=
79 new String_List (1 .. 2 * Preprocessing_Symbol_Last);
80 begin
81 New_Symbol_Definitions (Preprocessing_Symbol_Defs'Range) :=
82 Preprocessing_Symbol_Defs.all;
83 Free (Preprocessing_Symbol_Defs);
84 Preprocessing_Symbol_Defs := New_Symbol_Definitions;
85 end;
86 end if;
87
88 Preprocessing_Symbol_Last := Preprocessing_Symbol_Last + 1;
89 Preprocessing_Symbol_Defs (Preprocessing_Symbol_Last) :=
90 new String'(Def);
91 end Add_Symbol_Definition;
92
93 -----------------------
94 -- Get_Overflow_Mode --
95 -----------------------
96
97 function Get_Overflow_Mode (C : Character) return Overflow_Mode_Type is
98 begin
99 case C is
100 when '1' =>
101 return Strict;
102
103 when '2' =>
104 return Minimized;
105
106 -- Eliminated allowed only if Long_Long_Integer is 64 bits (since
107 -- the current implementation of System.Bignums assumes this).
108
109 when '3' =>
110 if Standard_Long_Long_Integer_Size /= 64 then
111 Bad_Switch ("-gnato3 not implemented for this configuration");
112 else
113 return Eliminated;
114 end if;
115
116 when others =>
117 raise Program_Error;
118 end case;
119 end Get_Overflow_Mode;
120
121 -----------------------------
122 -- Scan_Front_End_Switches --
123 -----------------------------
124
125 procedure Scan_Front_End_Switches
126 (Switch_Chars : String;
127 Args : String_List;
128 Arg_Rank : Positive)
129 is
130 First_Switch : Boolean := True;
131 -- False for all but first switch
132
133 Max : constant Natural := Switch_Chars'Last;
134 Ptr : Natural;
135 C : Character := ' ';
136 Dot : Boolean;
137
138 Store_Switch : Boolean;
139 -- For -gnatxx switches, the normal processing, signalled by this flag
140 -- being set to True, is to store the switch on exit from the case
141 -- statement, the switch stored is -gnat followed by the characters
142 -- from First_Char to Ptr-1. For cases like -gnaty, where the switch
143 -- is stored in separate pieces, this flag is set to False, and the
144 -- appropriate calls to Store_Compilation_Switch are made from within
145 -- the case branch.
146
147 First_Char : Positive;
148 -- Marks start of switch to be stored
149
150 begin
151 Ptr := Switch_Chars'First;
152
153 -- Skip past the initial character (must be the switch character)
154
155 if Ptr = Max then
156 Bad_Switch (C);
157 else
158 Ptr := Ptr + 1;
159 end if;
160
161 -- Handle switches that do not start with -gnat
162
163 if Ptr + 3 > Max or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat" then
164
165 -- There are two front-end switches that do not start with -gnat:
166 -- -I, --RTS
167
168 if Switch_Chars (Ptr) = 'I' then
169
170 -- Set flag Search_Directory_Present if switch is "-I" only:
171 -- the directory will be the next argument.
172
173 if Ptr = Max then
174 Search_Directory_Present := True;
175 return;
176 end if;
177
178 Ptr := Ptr + 1;
179
180 -- Find out whether this is a -I- or regular -Ixxx switch
181
182 -- Note: -I switches are not recorded in the ALI file, since the
183 -- meaning of the program depends on the source files compiled,
184 -- not where they came from.
185
186 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
187 Look_In_Primary_Dir := False;
188 else
189 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
190 end if;
191
192 -- Processing of the --RTS switch. --RTS may have been modified by
193 -- gcc into -fRTS (for GCC targets).
194
195 elsif Ptr + 3 <= Max
196 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
197 or else
198 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
199 then
200 Ptr := Ptr + 1;
201
202 if Ptr + 4 > Max
203 or else Switch_Chars (Ptr + 3) /= '='
204 then
205 Osint.Fail ("missing path for --RTS");
206 else
207 -- Check that this is the first time --RTS is specified or if
208 -- it is not the first time, the same path has been specified.
209
210 if RTS_Specified = null then
211 RTS_Specified := new String'(Switch_Chars (Ptr + 4 .. Max));
212
213 elsif
214 RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
215 then
216 Osint.Fail ("--RTS cannot be specified multiple times");
217 end if;
218
219 -- Valid --RTS switch
220
221 Opt.No_Stdinc := True;
222 Opt.RTS_Switch := True;
223
224 RTS_Src_Path_Name :=
225 Get_RTS_Search_Dir
226 (Switch_Chars (Ptr + 4 .. Max), Include);
227
228 RTS_Lib_Path_Name :=
229 Get_RTS_Search_Dir
230 (Switch_Chars (Ptr + 4 .. Max), Objects);
231
232 if RTS_Src_Path_Name /= null
233 and then RTS_Lib_Path_Name /= null
234 then
235 -- Store the -fRTS switch (Note: Store_Compilation_Switch
236 -- changes -fRTS back into --RTS for the actual output).
237
238 Store_Compilation_Switch (Switch_Chars);
239
240 elsif RTS_Src_Path_Name = null
241 and then RTS_Lib_Path_Name = null
242 then
243 Osint.Fail ("RTS path not valid: missing " &
244 "adainclude and adalib directories");
245
246 elsif RTS_Src_Path_Name = null then
247 Osint.Fail ("RTS path not valid: missing " &
248 "adainclude directory");
249
250 elsif RTS_Lib_Path_Name = null then
251 Osint.Fail ("RTS path not valid: missing " &
252 "adalib directory");
253 end if;
254 end if;
255
256 -- There are no other switches not starting with -gnat
257
258 else
259 Bad_Switch (Switch_Chars);
260 end if;
261
262 -- Case of switch starting with -gnat
263
264 else
265 Ptr := Ptr + 4;
266
267 -- Loop to scan through switches given in switch string
268
269 while Ptr <= Max loop
270 First_Char := Ptr;
271 Store_Switch := True;
272
273 C := Switch_Chars (Ptr);
274
275 case C is
276
277 when 'a' =>
278 Ptr := Ptr + 1;
279 Assertions_Enabled := True;
280 Debug_Pragmas_Enabled := True;
281
282 -- Processing for A switch
283
284 when 'A' =>
285 Ptr := Ptr + 1;
286 Config_File := False;
287
288 -- Processing for b switch
289
290 when 'b' =>
291 Ptr := Ptr + 1;
292 Brief_Output := True;
293
294 -- Processing for B switch
295
296 when 'B' =>
297 Ptr := Ptr + 1;
298 Assume_No_Invalid_Values := True;
299
300 -- Processing for c switch
301
302 when 'c' =>
303 if not First_Switch then
304 Osint.Fail
305 ("-gnatc must be first if combined with other switches");
306 end if;
307
308 Ptr := Ptr + 1;
309 Operating_Mode := Check_Semantics;
310
311 -- Processing for C switch
312
313 when 'C' =>
314 Ptr := Ptr + 1;
315
316 if not CodePeer_Mode then
317 CodePeer_Mode := True;
318
319 -- Suppress compiler warnings by default, since what we are
320 -- interested in here is what CodePeer can find out. Note
321 -- that if -gnatwxxx is specified after -gnatC on the
322 -- command line, we do not want to override this setting in
323 -- Adjust_Global_Switches, and assume that the user wants to
324 -- get both warnings from GNAT and CodePeer messages.
325
326 Warning_Mode := Suppress;
327 end if;
328
329 -- Processing for d switch
330
331 when 'd' =>
332 Store_Switch := False;
333 Dot := False;
334
335 -- Note: for the debug switch, the remaining characters in this
336 -- switch field must all be debug flags, since all valid switch
337 -- characters are also valid debug characters.
338
339 -- Loop to scan out debug flags
340
341 while Ptr < Max loop
342 Ptr := Ptr + 1;
343 C := Switch_Chars (Ptr);
344 exit when C = ASCII.NUL or else C = '/' or else C = '-';
345
346 if C in '1' .. '9' or else
347 C in 'a' .. 'z' or else
348 C in 'A' .. 'Z'
349 then
350 if Dot then
351 Set_Dotted_Debug_Flag (C);
352 Store_Compilation_Switch ("-gnatd." & C);
353 else
354 Set_Debug_Flag (C);
355 Store_Compilation_Switch ("-gnatd" & C);
356 end if;
357
358 elsif C = '.' then
359 Dot := True;
360
361 elsif Dot then
362 Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
363 else
364 Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
365 end if;
366 end loop;
367
368 return;
369
370 -- Processing for D switch
371
372 when 'D' =>
373 Ptr := Ptr + 1;
374
375 -- Scan optional integer line limit value
376
377 if Nat_Present (Switch_Chars, Max, Ptr) then
378 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'D');
379 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
380 end if;
381
382 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
383 -- generation in the ali file) since otherwise this generation
384 -- gets confused by the "wrong" Sloc values put in the tree.
385
386 Debug_Generated_Code := True;
387 Xref_Active := False;
388 Set_Debug_Flag ('g');
389
390 -- -gnate? (extended switches)
391
392 when 'e' =>
393 Ptr := Ptr + 1;
394
395 -- The -gnate? switches are all double character switches
396 -- so we must always have a character after the e.
397
398 if Ptr > Max then
399 Bad_Switch ("-gnate");
400 end if;
401
402 case Switch_Chars (Ptr) is
403
404 -- -gnatea (initial delimiter of explicit switches)
405
406 -- All switches that come before -gnatea have been added by
407 -- the GCC driver and are not stored in the ALI file.
408 -- See also -gnatez below.
409
410 when 'a' =>
411 Store_Switch := False;
412 Enable_Switch_Storing;
413 Ptr := Ptr + 1;
414
415 -- -gnateA (aliasing checks on parameters)
416
417 when 'A' =>
418 Ptr := Ptr + 1;
419 Check_Aliasing_Of_Parameters := True;
420
421 -- -gnatec (configuration pragmas)
422
423 when 'c' =>
424 Store_Switch := False;
425 Ptr := Ptr + 1;
426
427 -- There may be an equal sign between -gnatec and
428 -- the path name of the config file.
429
430 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
431 Ptr := Ptr + 1;
432 end if;
433
434 if Ptr > Max then
435 Bad_Switch ("-gnatec");
436 end if;
437
438 declare
439 Config_File_Name : constant String_Access :=
440 new String'
441 (Switch_Chars (Ptr .. Max));
442
443 begin
444 if Config_File_Names = null then
445 Config_File_Names :=
446 new String_List'(1 => Config_File_Name);
447
448 else
449 declare
450 New_Names : constant String_List_Access :=
451 new String_List
452 (1 ..
453 Config_File_Names'Length + 1);
454
455 begin
456 for Index in Config_File_Names'Range loop
457 New_Names (Index) :=
458 Config_File_Names (Index);
459 Config_File_Names (Index) := null;
460 end loop;
461
462 New_Names (New_Names'Last) := Config_File_Name;
463 Free (Config_File_Names);
464 Config_File_Names := New_Names;
465 end;
466 end if;
467 end;
468
469 return;
470
471 -- -gnateC switch (CodePeer SCIL generation)
472
473 -- Not enabled for now, keep it for later???
474 -- use -gnatd.I only for now
475
476 -- when 'C' =>
477 -- Ptr := Ptr + 1;
478 -- Generate_SCIL := True;
479
480 -- -gnated switch (disable atomic synchronization)
481
482 when 'd' =>
483 Suppress_Options.Suppress (Atomic_Synchronization) :=
484 True;
485
486 -- -gnateD switch (preprocessing symbol definition)
487
488 when 'D' =>
489 Store_Switch := False;
490 Ptr := Ptr + 1;
491
492 if Ptr > Max then
493 Bad_Switch ("-gnateD");
494 end if;
495
496 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
497
498 -- Store the switch
499
500 Store_Compilation_Switch
501 ("-gnateD" & Switch_Chars (Ptr .. Max));
502 Ptr := Max + 1;
503
504 -- -gnateE (extra exception information)
505
506 when 'E' =>
507 Exception_Extra_Info := True;
508 Ptr := Ptr + 1;
509
510 -- -gnatef (full source path for brief error messages)
511
512 when 'f' =>
513 Store_Switch := False;
514 Ptr := Ptr + 1;
515 Full_Path_Name_For_Brief_Errors := True;
516
517 -- -gnateG (save preprocessor output)
518
519 when 'G' =>
520 Generate_Processed_File := True;
521 Ptr := Ptr + 1;
522
523 -- -gnatei (max number of instantiations)
524
525 when 'i' =>
526 Ptr := Ptr + 1;
527 Scan_Pos
528 (Switch_Chars, Max, Ptr, Maximum_Instantiations, C);
529
530 -- -gnateI (index of unit in multi-unit source)
531
532 when 'I' =>
533 Ptr := Ptr + 1;
534 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
535
536 -- -gnatem (mapping file)
537
538 when 'm' =>
539 Store_Switch := False;
540 Ptr := Ptr + 1;
541
542 -- There may be an equal sign between -gnatem and
543 -- the path name of the mapping file.
544
545 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
546 Ptr := Ptr + 1;
547 end if;
548
549 if Ptr > Max then
550 Bad_Switch ("-gnatem");
551 end if;
552
553 Mapping_File_Name :=
554 new String'(Switch_Chars (Ptr .. Max));
555 return;
556
557 -- -gnateO= (object path file)
558
559 when 'O' =>
560 Store_Switch := False;
561 Ptr := Ptr + 1;
562
563 -- Check for '='
564
565 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
566 Bad_Switch ("-gnateO");
567
568 else
569 Object_Path_File_Name :=
570 new String'(Switch_Chars (Ptr + 1 .. Max));
571 end if;
572
573 return;
574
575 -- -gnatep (preprocessing data file)
576
577 when 'p' =>
578 Store_Switch := False;
579 Ptr := Ptr + 1;
580
581 -- There may be an equal sign between -gnatep and
582 -- the path name of the mapping file.
583
584 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
585 Ptr := Ptr + 1;
586 end if;
587
588 if Ptr > Max then
589 Bad_Switch ("-gnatep");
590 end if;
591
592 Preprocessing_Data_File :=
593 new String'(Switch_Chars (Ptr .. Max));
594
595 -- Store the switch, normalizing to -gnatep=
596
597 Store_Compilation_Switch
598 ("-gnatep=" & Preprocessing_Data_File.all);
599
600 Ptr := Max + 1;
601
602 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
603
604 when 'P' =>
605 Treat_Categorization_Errors_As_Warnings := True;
606
607 -- -gnateS (generate SCO information)
608
609 -- Include Source Coverage Obligation information in ALI
610 -- files for the benefit of source coverage analysis tools
611 -- (xcov).
612
613 when 'S' =>
614 Generate_SCO := True;
615 Ptr := Ptr + 1;
616
617 -- -gnatet (generate target dependent information)
618
619 when 't' =>
620 Generate_Target_Dependent_Info := True;
621 Ptr := Ptr + 1;
622
623 -- -gnateV (validity checks on parameters)
624
625 when 'V' =>
626 Ptr := Ptr + 1;
627 Check_Validity_Of_Parameters := True;
628
629 -- -gnatez (final delimiter of explicit switches)
630
631 -- All switches that come after -gnatez have been added by
632 -- the GCC driver and are not stored in the ALI file. See
633 -- also -gnatea above.
634
635 when 'z' =>
636 Store_Switch := False;
637 Disable_Switch_Storing;
638 Ptr := Ptr + 1;
639
640 -- All other -gnate? switches are unassigned
641
642 when others =>
643 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
644 end case;
645
646 -- -gnatE (dynamic elaboration checks)
647
648 when 'E' =>
649 Ptr := Ptr + 1;
650 Dynamic_Elaboration_Checks := True;
651
652 -- -gnatf (full error messages)
653
654 when 'f' =>
655 Ptr := Ptr + 1;
656 All_Errors_Mode := True;
657
658 -- Processing for F switch
659
660 when 'F' =>
661 Ptr := Ptr + 1;
662 External_Name_Exp_Casing := Uppercase;
663 External_Name_Imp_Casing := Uppercase;
664
665 -- Processing for g switch
666
667 when 'g' =>
668 Ptr := Ptr + 1;
669 GNAT_Mode := True;
670 Identifier_Character_Set := 'n';
671 System_Extend_Unit := Empty;
672 Warning_Mode := Treat_As_Error;
673
674 -- Set Ada 2012 mode explicitly. We don't want to rely on the
675 -- implicit setting here, since for example, we want
676 -- Preelaborate_05 treated as Preelaborate
677
678 Ada_Version := Ada_2012;
679 Ada_Version_Explicit := Ada_Version;
680
681 -- Set default warnings and style checks for -gnatg
682
683 Set_GNAT_Mode_Warnings;
684 Set_GNAT_Style_Check_Options;
685
686 -- Processing for G switch
687
688 when 'G' =>
689 Ptr := Ptr + 1;
690 Print_Generated_Code := True;
691
692 -- Scan optional integer line limit value
693
694 if Nat_Present (Switch_Chars, Max, Ptr) then
695 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
696 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
697 end if;
698
699 -- Processing for h switch
700
701 when 'h' =>
702 Ptr := Ptr + 1;
703 Usage_Requested := True;
704
705 -- Processing for i switch
706
707 when 'i' =>
708 if Ptr = Max then
709 Bad_Switch ("-gnati");
710 end if;
711
712 Ptr := Ptr + 1;
713 C := Switch_Chars (Ptr);
714
715 if C in '1' .. '5'
716 or else C = '8'
717 or else C = '9'
718 or else C = 'p'
719 or else C = 'f'
720 or else C = 'n'
721 or else C = 'w'
722 then
723 Identifier_Character_Set := C;
724 Ptr := Ptr + 1;
725
726 else
727 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
728 end if;
729
730 -- Processing for I switch
731
732 when 'I' =>
733 Ptr := Ptr + 1;
734 Ignore_Rep_Clauses := True;
735
736 -- Processing for j switch
737
738 when 'j' =>
739 Ptr := Ptr + 1;
740 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
741
742 -- Processing for k switch
743
744 when 'k' =>
745 Ptr := Ptr + 1;
746 Scan_Pos
747 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
748
749 -- Processing for l switch
750
751 when 'l' =>
752 Ptr := Ptr + 1;
753 Full_List := True;
754
755 -- There may be an equal sign between -gnatl and a file name
756
757 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
758 if Ptr = Max then
759 Osint.Fail ("file name for -gnatl= is null");
760 else
761 Opt.Full_List_File_Name :=
762 new String'(Switch_Chars (Ptr + 1 .. Max));
763 Ptr := Max + 1;
764 end if;
765 end if;
766
767 -- Processing for L switch
768
769 when 'L' =>
770 Ptr := Ptr + 1;
771 Dump_Source_Text := True;
772
773 -- Processing for m switch
774
775 when 'm' =>
776 Ptr := Ptr + 1;
777 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Messages, C);
778
779 -- Processing for n switch
780
781 when 'n' =>
782 Ptr := Ptr + 1;
783 Inline_Active := True;
784
785 -- There may be a digit (1 or 2) appended to the switch
786
787 if Ptr <= Max then
788 C := Switch_Chars (Ptr);
789
790 if C in '1' .. '2' then
791 Ptr := Ptr + 1;
792 Inline_Level := Character'Pos (C) - Character'Pos ('0');
793 end if;
794 end if;
795
796 -- Processing for N switch
797
798 when 'N' =>
799 Ptr := Ptr + 1;
800 Inline_Active := True;
801 Front_End_Inlining := True;
802
803 -- Processing for o switch
804
805 when 'o' =>
806 Ptr := Ptr + 1;
807 Suppress_Options.Suppress (Overflow_Check) := False;
808
809 -- Case of no digits after the -gnato
810
811 if Ptr > Max or else Switch_Chars (Ptr) not in '1' .. '3' then
812 Suppress_Options.Overflow_Mode_General := Strict;
813 Suppress_Options.Overflow_Mode_Assertions := Strict;
814
815 -- At least one digit after the -gnato
816
817 else
818 -- Handle first digit after -gnato
819
820 Suppress_Options.Overflow_Mode_General :=
821 Get_Overflow_Mode (Switch_Chars (Ptr));
822 Ptr := Ptr + 1;
823
824 -- Only one digit after -gnato, set assertions mode to
825 -- be the same as general mode.
826
827 if Ptr > Max
828 or else Switch_Chars (Ptr) not in '1' .. '3'
829 then
830 Suppress_Options.Overflow_Mode_Assertions :=
831 Suppress_Options.Overflow_Mode_General;
832
833 -- Process second digit after -gnato
834
835 else
836 Suppress_Options.Overflow_Mode_Assertions :=
837 Get_Overflow_Mode (Switch_Chars (Ptr));
838 Ptr := Ptr + 1;
839 end if;
840 end if;
841
842 -- Processing for O switch
843
844 when 'O' =>
845 Store_Switch := False;
846 Ptr := Ptr + 1;
847 Output_File_Name_Present := True;
848
849 -- Processing for p switch
850
851 when 'p' =>
852 Ptr := Ptr + 1;
853
854 -- Skip processing if cancelled by subsequent -gnat-p
855
856 if Switch_Subsequently_Cancelled ("p", Args, Arg_Rank) then
857 Store_Switch := False;
858
859 else
860 -- Set all specific options as well as All_Checks in the
861 -- Suppress_Options array, excluding Elaboration_Check,
862 -- since this is treated specially because we do not want
863 -- -gnatp to disable static elaboration processing. Also
864 -- exclude Atomic_Synchronization, since this is not a real
865 -- check.
866
867 for J in Suppress_Options.Suppress'Range loop
868 if J /= Elaboration_Check
869 and then
870 J /= Atomic_Synchronization
871 then
872 Suppress_Options.Suppress (J) := True;
873 end if;
874 end loop;
875
876 Validity_Checks_On := False;
877 Opt.Suppress_Checks := True;
878 end if;
879
880 -- Processing for P switch
881
882 when 'P' =>
883 Ptr := Ptr + 1;
884 Polling_Required := True;
885
886 -- Processing for q switch
887
888 when 'q' =>
889 Ptr := Ptr + 1;
890 Try_Semantics := True;
891
892 -- Processing for Q switch
893
894 when 'Q' =>
895 Ptr := Ptr + 1;
896 Force_ALI_Tree_File := True;
897 Try_Semantics := True;
898
899 -- Processing for r switch
900
901 when 'r' =>
902 Ptr := Ptr + 1;
903 Treat_Restrictions_As_Warnings := True;
904
905 -- Processing for R switch
906
907 when 'R' =>
908 Back_Annotate_Rep_Info := True;
909 List_Representation_Info := 1;
910
911 Ptr := Ptr + 1;
912 while Ptr <= Max loop
913 C := Switch_Chars (Ptr);
914
915 if C in '1' .. '3' then
916 List_Representation_Info :=
917 Character'Pos (C) - Character'Pos ('0');
918
919 elsif Switch_Chars (Ptr) = 's' then
920 List_Representation_Info_To_File := True;
921
922 elsif Switch_Chars (Ptr) = 'm' then
923 List_Representation_Info_Mechanisms := True;
924
925 else
926 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
927 end if;
928
929 Ptr := Ptr + 1;
930 end loop;
931
932 -- Processing for s switch
933
934 when 's' =>
935 if not First_Switch then
936 Osint.Fail
937 ("-gnats must be first if combined with other switches");
938 end if;
939
940 Ptr := Ptr + 1;
941 Operating_Mode := Check_Syntax;
942
943 -- Processing for S switch
944
945 when 'S' =>
946 Print_Standard := True;
947 Ptr := Ptr + 1;
948
949 -- Processing for t switch
950
951 when 't' =>
952 Ptr := Ptr + 1;
953 Tree_Output := True;
954 Back_Annotate_Rep_Info := True;
955
956 -- Processing for T switch
957
958 when 'T' =>
959 Ptr := Ptr + 1;
960 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
961
962 -- Processing for u switch
963
964 when 'u' =>
965 Ptr := Ptr + 1;
966 List_Units := True;
967
968 -- Processing for U switch
969
970 when 'U' =>
971 Ptr := Ptr + 1;
972 Unique_Error_Tag := True;
973
974 -- Processing for v switch
975
976 when 'v' =>
977 Ptr := Ptr + 1;
978 Verbose_Mode := True;
979
980 -- Processing for V switch
981
982 when 'V' =>
983 Store_Switch := False;
984 Ptr := Ptr + 1;
985
986 if Ptr > Max then
987 Bad_Switch ("-gnatV");
988
989 else
990 declare
991 OK : Boolean;
992
993 begin
994 Set_Validity_Check_Options
995 (Switch_Chars (Ptr .. Max), OK, Ptr);
996
997 if not OK then
998 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
999 end if;
1000
1001 for Index in First_Char + 1 .. Max loop
1002 Store_Compilation_Switch
1003 ("-gnatV" & Switch_Chars (Index));
1004 end loop;
1005 end;
1006 end if;
1007
1008 Ptr := Max + 1;
1009
1010 -- Processing for w switch
1011
1012 when 'w' =>
1013 Store_Switch := False;
1014 Ptr := Ptr + 1;
1015
1016 if Ptr > Max then
1017 Bad_Switch ("-gnatw");
1018 end if;
1019
1020 while Ptr <= Max loop
1021 C := Switch_Chars (Ptr);
1022
1023 -- Case of dot switch
1024
1025 if C = '.' and then Ptr < Max then
1026 Ptr := Ptr + 1;
1027 C := Switch_Chars (Ptr);
1028
1029 if Set_Dot_Warning_Switch (C) then
1030 Store_Compilation_Switch ("-gnatw." & C);
1031 else
1032 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
1033 end if;
1034
1035 -- Normal case, no dot
1036
1037 else
1038 if Set_Warning_Switch (C) then
1039 Store_Compilation_Switch ("-gnatw" & C);
1040 else
1041 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
1042 end if;
1043 end if;
1044
1045 Ptr := Ptr + 1;
1046 end loop;
1047
1048 return;
1049
1050 -- Processing for W switch
1051
1052 when 'W' =>
1053 Ptr := Ptr + 1;
1054
1055 if Ptr > Max then
1056 Bad_Switch ("-gnatW");
1057 end if;
1058
1059 begin
1060 Wide_Character_Encoding_Method :=
1061 Get_WC_Encoding_Method (Switch_Chars (Ptr));
1062 exception
1063 when Constraint_Error =>
1064 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
1065 end;
1066
1067 Wide_Character_Encoding_Method_Specified := True;
1068
1069 Upper_Half_Encoding :=
1070 Wide_Character_Encoding_Method in
1071 WC_Upper_Half_Encoding_Method;
1072
1073 Ptr := Ptr + 1;
1074
1075 -- Processing for x switch
1076
1077 when 'x' =>
1078 Ptr := Ptr + 1;
1079 Xref_Active := False;
1080
1081 -- Processing for X switch
1082
1083 when 'X' =>
1084 Ptr := Ptr + 1;
1085 Extensions_Allowed := True;
1086 Ada_Version := Ada_Version_Type'Last;
1087 Ada_Version_Explicit := Ada_Version_Type'Last;
1088
1089 -- Processing for y switch
1090
1091 when 'y' =>
1092 Ptr := Ptr + 1;
1093
1094 if Ptr > Max then
1095 Set_Default_Style_Check_Options;
1096
1097 else
1098 Store_Switch := False;
1099
1100 declare
1101 OK : Boolean;
1102
1103 begin
1104 Set_Style_Check_Options
1105 (Switch_Chars (Ptr .. Max), OK, Ptr);
1106
1107 if not OK then
1108 Osint.Fail
1109 ("bad -gnaty switch (" &
1110 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
1111 end if;
1112
1113 Ptr := First_Char + 1;
1114 while Ptr <= Max loop
1115 if Switch_Chars (Ptr) = 'M' then
1116 First_Char := Ptr;
1117 loop
1118 Ptr := Ptr + 1;
1119 exit when Ptr > Max
1120 or else Switch_Chars (Ptr) not in '0' .. '9';
1121 end loop;
1122
1123 Store_Compilation_Switch
1124 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
1125
1126 else
1127 Store_Compilation_Switch
1128 ("-gnaty" & Switch_Chars (Ptr));
1129 Ptr := Ptr + 1;
1130 end if;
1131 end loop;
1132 end;
1133 end if;
1134
1135 -- Processing for z switch
1136
1137 when 'z' =>
1138
1139 -- -gnatz must be the first and only switch in Switch_Chars,
1140 -- and is a two-letter switch.
1141
1142 if Ptr /= Switch_Chars'First + 5
1143 or else (Max - Ptr + 1) > 2
1144 then
1145 Osint.Fail
1146 ("-gnatz* may not be combined with other switches");
1147 end if;
1148
1149 if Ptr = Max then
1150 Bad_Switch ("-gnatz");
1151 end if;
1152
1153 Ptr := Ptr + 1;
1154
1155 -- Only one occurrence of -gnat* is permitted
1156
1157 if Distribution_Stub_Mode = No_Stubs then
1158 case Switch_Chars (Ptr) is
1159 when 'r' =>
1160 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1161
1162 when 'c' =>
1163 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1164
1165 when others =>
1166 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
1167 end case;
1168
1169 Ptr := Ptr + 1;
1170
1171 else
1172 Osint.Fail ("only one -gnatz* switch allowed");
1173 end if;
1174
1175 -- Processing for Z switch
1176
1177 when 'Z' =>
1178 Ptr := Ptr + 1;
1179 Osint.Fail
1180 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1181
1182 -- Note on language version switches: whenever a new language
1183 -- version switch is added, Switch.M.Normalize_Compiler_Switches
1184 -- must be updated.
1185
1186 -- Processing for 83 switch
1187
1188 when '8' =>
1189 if Ptr = Max then
1190 Bad_Switch ("-gnat8");
1191 end if;
1192
1193 Ptr := Ptr + 1;
1194
1195 if Switch_Chars (Ptr) /= '3' then
1196 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
1197 else
1198 Ptr := Ptr + 1;
1199 Ada_Version := Ada_83;
1200 Ada_Version_Explicit := Ada_Version;
1201 end if;
1202
1203 -- Processing for 95 switch
1204
1205 when '9' =>
1206 if Ptr = Max then
1207 Bad_Switch ("-gnat9");
1208 end if;
1209
1210 Ptr := Ptr + 1;
1211
1212 if Switch_Chars (Ptr) /= '5' then
1213 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
1214 else
1215 Ptr := Ptr + 1;
1216 Ada_Version := Ada_95;
1217 Ada_Version_Explicit := Ada_Version;
1218 end if;
1219
1220 -- Processing for 05 switch
1221
1222 when '0' =>
1223 if Ptr = Max then
1224 Bad_Switch ("-gnat0");
1225 end if;
1226
1227 Ptr := Ptr + 1;
1228
1229 if Switch_Chars (Ptr) /= '5' then
1230 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1231 else
1232 Ptr := Ptr + 1;
1233 Ada_Version := Ada_2005;
1234 Ada_Version_Explicit := Ada_Version;
1235 end if;
1236
1237 -- Processing for 12 switch
1238
1239 when '1' =>
1240 if Ptr = Max then
1241 Bad_Switch ("-gnat1");
1242 end if;
1243
1244 Ptr := Ptr + 1;
1245
1246 if Switch_Chars (Ptr) /= '2' then
1247 Bad_Switch ("-gnat1" & Switch_Chars (Ptr .. Max));
1248 else
1249 Ptr := Ptr + 1;
1250 Ada_Version := Ada_2012;
1251 Ada_Version_Explicit := Ada_Version;
1252 end if;
1253
1254 -- Processing for 2005 and 2012 switches
1255
1256 when '2' =>
1257 if Ptr > Max - 3 then
1258 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1259
1260 elsif Switch_Chars (Ptr .. Ptr + 3) = "2005" then
1261 Ada_Version := Ada_2005;
1262
1263 elsif Switch_Chars (Ptr .. Ptr + 3) = "2012" then
1264 Ada_Version := Ada_2012;
1265
1266 else
1267 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Ptr + 3));
1268 end if;
1269
1270 Ada_Version_Explicit := Ada_Version;
1271 Ptr := Ptr + 4;
1272
1273 -- Switch cancellation, currently only -gnat-p is allowed.
1274 -- All we do here is the error checking, since the actual
1275 -- processing for switch cancellation is done by calls to
1276 -- Switch_Subsequently_Cancelled at the appropriate point.
1277
1278 when '-' =>
1279
1280 -- Simple ignore -gnat-p
1281
1282 if Switch_Chars = "-gnat-p" then
1283 return;
1284
1285 -- Any other occurrence of minus is ignored. This is for
1286 -- maximum compatibility with previous version which ignored
1287 -- all occurrences of minus.
1288
1289 else
1290 Store_Switch := False;
1291 Ptr := Ptr + 1;
1292 end if;
1293
1294 -- We ignore '/' in switches, this is historical, still needed???
1295
1296 when '/' =>
1297 Store_Switch := False;
1298
1299 -- Anything else is an error (illegal switch character)
1300
1301 when others =>
1302 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1303 end case;
1304
1305 if Store_Switch then
1306 Store_Compilation_Switch
1307 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1308 end if;
1309
1310 First_Switch := False;
1311 end loop;
1312 end if;
1313 end Scan_Front_End_Switches;
1314
1315 -----------------------------------
1316 -- Switch_Subsequently_Cancelled --
1317 -----------------------------------
1318
1319 function Switch_Subsequently_Cancelled
1320 (C : String;
1321 Args : String_List;
1322 Arg_Rank : Positive) return Boolean
1323 is
1324 begin
1325 -- Loop through arguments following the current one
1326
1327 for Arg in Arg_Rank + 1 .. Args'Last loop
1328 if Args (Arg).all = "-gnat-" & C then
1329 return True;
1330 end if;
1331 end loop;
1332
1333 -- No match found, not cancelled
1334
1335 return False;
1336 end Switch_Subsequently_Cancelled;
1337
1338 end Switch.C;