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