* g++.dg/template/using30.C: Move ...
[official-gcc.git] / gcc / ada / switch-c.adb
blob46939c6fd523784b92c44fd2a871885e68388a47
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-2014, 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 ------------------------------------------------------------------------------
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.
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;
40 with Ada.Unchecked_Deallocation;
42 with System.WCh_Con; use System.WCh_Con;
43 with System.OS_Lib;
45 package body Switch.C is
47 RTS_Specified : String_Access := null;
48 -- Used to detect multiple use of --RTS= flag
50 procedure Add_Symbol_Definition (Def : String);
51 -- Add a symbol definition from the command line
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
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.
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.
71 ---------------------------
72 -- Add_Symbol_Definition --
73 ---------------------------
75 procedure Add_Symbol_Definition (Def : String) is
76 begin
77 -- If Preprocessor_Symbol_Defs is not large enough, double its size
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;
91 Preprocessing_Symbol_Last := Preprocessing_Symbol_Last + 1;
92 Preprocessing_Symbol_Defs (Preprocessing_Symbol_Last) :=
93 new String'(Def);
94 end Add_Symbol_Definition;
96 -----------------------
97 -- Get_Overflow_Mode --
98 -----------------------
100 function Get_Overflow_Mode (C : Character) return Overflow_Mode_Type is
101 begin
102 case C is
103 when '1' =>
104 return Strict;
106 when '2' =>
107 return Minimized;
109 -- Eliminated allowed only if Long_Long_Integer is 64 bits (since
110 -- the current implementation of System.Bignums assumes this).
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;
119 when others =>
120 raise Program_Error;
121 end case;
122 end Get_Overflow_Mode;
124 -----------------------------
125 -- Scan_Front_End_Switches --
126 -----------------------------
128 procedure Scan_Front_End_Switches
129 (Switch_Chars : String;
130 Args : String_List;
131 Arg_Rank : Positive)
133 First_Switch : Boolean := True;
134 -- False for all but first switch
136 Max : constant Natural := Switch_Chars'Last;
137 Ptr : Natural;
138 C : Character := ' ';
139 Dot : Boolean;
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.
150 First_Char : Positive;
151 -- Marks start of switch to be stored
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),
157 begin
158 Ptr := Switch_Chars'First;
160 -- Skip past the initial character (must be the switch character)
162 if Ptr = Max then
163 Bad_Switch (C);
164 else
165 Ptr := Ptr + 1;
166 end if;
168 -- Handle switches that do not start with -gnat
170 if Ptr + 3 > Max or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat" then
172 -- There are two front-end switches that do not start with -gnat:
173 -- -I, --RTS
175 if Switch_Chars (Ptr) = 'I' then
177 -- Set flag Search_Directory_Present if switch is "-I" only:
178 -- the directory will be the next argument.
180 if Ptr = Max then
181 Search_Directory_Present := True;
182 return;
183 end if;
185 Ptr := Ptr + 1;
187 -- Find out whether this is a -I- or regular -Ixxx switch
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.
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;
199 -- Processing of the --RTS switch. --RTS may have been modified by
200 -- gcc into -fRTS (for GCC targets).
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;
209 if Ptr + 4 > Max
210 or else Switch_Chars (Ptr + 3) /= '='
211 then
212 Osint.Fail ("missing path for --RTS");
214 else
215 declare
216 Runtime_Dir : String_Access;
218 begin
219 if System.OS_Lib.Is_Absolute_Path
220 (Switch_Chars (Ptr + 4 .. Max))
221 then
222 Runtime_Dir :=
223 new String'
224 (System.OS_Lib.Normalize_Pathname
225 (Switch_Chars (Ptr + 4 .. Max)));
227 else
228 Runtime_Dir :=
229 new String'(Switch_Chars (Ptr + 4 .. Max));
230 end if;
232 -- Check that this is the first time --RTS is specified
233 -- or if it is not the first time, the same path has been
234 -- specified.
236 if RTS_Specified = null then
237 RTS_Specified := Runtime_Dir;
239 elsif RTS_Specified.all /= Runtime_Dir.all then
240 Osint.Fail ("--RTS cannot be specified multiple times");
241 end if;
243 -- Valid --RTS switch
245 Opt.No_Stdinc := True;
246 Opt.RTS_Switch := True;
248 RTS_Src_Path_Name :=
249 Get_RTS_Search_Dir (Runtime_Dir.all, Include);
251 RTS_Lib_Path_Name :=
252 Get_RTS_Search_Dir (Runtime_Dir.all, Objects);
254 if RTS_Src_Path_Name /= null
255 and then RTS_Lib_Path_Name /= null
256 then
257 -- Store the -fRTS switch (Note: Store_Compilation_Switch
258 -- changes -fRTS back into --RTS for the actual output).
260 Store_Compilation_Switch (Switch_Chars);
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");
268 elsif RTS_Src_Path_Name = null then
269 Osint.Fail ("RTS path not valid: missing "
270 & "adainclude directory");
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;
279 -- There are no other switches not starting with -gnat
281 else
282 Bad_Switch (Switch_Chars);
283 end if;
285 -- Case of switch starting with -gnat
287 else
288 Ptr := Ptr + 4;
290 -- Loop to scan through switches given in switch string
292 while Ptr <= Max loop
293 First_Char := Ptr;
294 Store_Switch := True;
296 C := Switch_Chars (Ptr);
298 case C is
300 -- -gnata (assertions enabled)
302 when 'a' =>
303 Ptr := Ptr + 1;
304 Assertions_Enabled := True;
306 -- -gnatA (disregard gnat.adc)
308 when 'A' =>
309 Ptr := Ptr + 1;
310 Config_File := False;
312 -- -gnatb (brief messages to stderr)
314 when 'b' =>
315 Ptr := Ptr + 1;
316 Brief_Output := True;
318 -- -gnatB (assume no invalid values)
320 when 'B' =>
321 Ptr := Ptr + 1;
322 Assume_No_Invalid_Values := True;
324 -- -gnatc (check syntax and semantics only)
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;
332 Ptr := Ptr + 1;
333 Operating_Mode := Check_Semantics;
335 -- -gnatC (Generate CodePeer information)
337 when 'C' =>
338 Ptr := Ptr + 1;
340 if not CodePeer_Mode then
341 CodePeer_Mode := True;
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.
350 Warning_Mode := Suppress;
351 end if;
353 -- -gnatd (compiler debug options)
355 when 'd' =>
356 Store_Switch := False;
357 Dot := False;
358 First_Ptr := Ptr + 1;
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.
364 -- Loop to scan out debug flags
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 = '-';
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
377 if Dot then
378 Set_Dotted_Debug_Flag (C);
379 Store_Compilation_Switch ("-gnatd." & C);
381 -- Special check, -gnatd.b must come first
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;
392 -- Not a dotted flag
394 else
395 Set_Debug_Flag (C);
396 Store_Compilation_Switch ("-gnatd" & C);
397 end if;
399 elsif C = '.' then
400 Dot := True;
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;
409 return;
411 -- -gnatD (debug expanded code)
413 when 'D' =>
414 Ptr := Ptr + 1;
416 -- Not allowed if previous -gnatR given
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 ???
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.
427 if List_Representation_Info /= 0 then
428 Osint.Fail
429 ("-gnatD not permitted since -gnatR given previously");
430 end if;
432 -- Scan optional integer line limit value
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;
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.
443 Debug_Generated_Code := True;
444 Xref_Active := False;
445 Set_Debug_Flag ('g');
447 -- -gnate? (extended switches)
449 when 'e' =>
450 Ptr := Ptr + 1;
452 -- The -gnate? switches are all double character switches
453 -- so we must always have a character after the e.
455 if Ptr > Max then
456 Bad_Switch ("-gnate");
457 end if;
459 case Switch_Chars (Ptr) is
461 -- -gnatea (initial delimiter of explicit switches)
463 -- This is an internal switch
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.
469 when 'a' =>
470 Store_Switch := False;
471 Enable_Switch_Storing;
472 Ptr := Ptr + 1;
474 -- -gnateA (aliasing checks on parameters)
476 when 'A' =>
477 Ptr := Ptr + 1;
478 Check_Aliasing_Of_Parameters := True;
480 -- -gnatec (configuration pragmas)
482 when 'c' =>
483 Store_Switch := False;
484 Ptr := Ptr + 1;
486 -- There may be an equal sign between -gnatec and
487 -- the path name of the config file.
489 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
490 Ptr := Ptr + 1;
491 end if;
493 if Ptr > Max then
494 Bad_Switch ("-gnatec");
495 end if;
497 declare
498 Config_File_Name : constant String_Access :=
499 new String'
500 (Switch_Chars (Ptr .. Max));
502 begin
503 if Config_File_Names = null then
504 Config_File_Names :=
505 new String_List'(1 => Config_File_Name);
507 else
508 declare
509 New_Names : constant String_List_Access :=
510 new String_List
511 (1 ..
512 Config_File_Names'Length + 1);
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;
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;
528 return;
530 -- -gnateC switch (generate CodePeer messages)
532 when 'C' =>
533 Ptr := Ptr + 1;
534 Generate_CodePeer_Messages := True;
536 -- -gnated switch (disable atomic synchronization)
538 when 'd' =>
539 Suppress_Options.Suppress (Atomic_Synchronization) :=
540 True;
542 -- -gnateD switch (preprocessing symbol definition)
544 when 'D' =>
545 Store_Switch := False;
546 Ptr := Ptr + 1;
548 if Ptr > Max then
549 Bad_Switch ("-gnateD");
550 end if;
552 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
554 -- Store the switch
556 Store_Compilation_Switch
557 ("-gnateD" & Switch_Chars (Ptr .. Max));
558 Ptr := Max + 1;
560 -- -gnateE (extra exception information)
562 when 'E' =>
563 Exception_Extra_Info := True;
564 Ptr := Ptr + 1;
566 -- -gnatef (full source path for brief error messages)
568 when 'f' =>
569 Store_Switch := False;
570 Ptr := Ptr + 1;
571 Full_Path_Name_For_Brief_Errors := True;
573 -- -gnateF (Check_Float_Overflow)
575 when 'F' =>
576 Ptr := Ptr + 1;
577 Check_Float_Overflow := not Machine_Overflows_On_Target;
579 -- -gnateG (save preprocessor output)
581 when 'G' =>
582 Generate_Processed_File := True;
583 Ptr := Ptr + 1;
585 -- -gnatei (max number of instantiations)
587 when 'i' =>
588 Ptr := Ptr + 1;
589 Scan_Pos
590 (Switch_Chars, Max, Ptr, Maximum_Instantiations, C);
592 -- -gnateI (index of unit in multi-unit source)
594 when 'I' =>
595 Ptr := Ptr + 1;
596 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
598 -- -gnatel
600 when 'l' =>
601 Ptr := Ptr + 1;
602 Elab_Info_Messages := True;
604 -- -gnateL
606 when 'L' =>
607 Ptr := Ptr + 1;
608 Elab_Info_Messages := False;
610 -- -gnatem (mapping file)
612 when 'm' =>
613 Store_Switch := False;
614 Ptr := Ptr + 1;
616 -- There may be an equal sign between -gnatem and
617 -- the path name of the mapping file.
619 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
620 Ptr := Ptr + 1;
621 end if;
623 if Ptr > Max then
624 Bad_Switch ("-gnatem");
625 end if;
627 Mapping_File_Name :=
628 new String'(Switch_Chars (Ptr .. Max));
629 return;
631 -- -gnateO= (object path file)
633 -- This is an internal switch
635 when 'O' =>
636 Store_Switch := False;
637 Ptr := Ptr + 1;
639 -- Check for '='
641 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
642 Bad_Switch ("-gnateO");
643 else
644 Object_Path_File_Name :=
645 new String'(Switch_Chars (Ptr + 1 .. Max));
646 end if;
648 return;
650 -- -gnatep (preprocessing data file)
652 when 'p' =>
653 Store_Switch := False;
654 Ptr := Ptr + 1;
656 -- There may be an equal sign between -gnatep and
657 -- the path name of the mapping file.
659 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
660 Ptr := Ptr + 1;
661 end if;
663 if Ptr > Max then
664 Bad_Switch ("-gnatep");
665 end if;
667 Preprocessing_Data_File :=
668 new String'(Switch_Chars (Ptr .. Max));
670 -- Store the switch, normalizing to -gnatep=
672 Store_Compilation_Switch
673 ("-gnatep=" & Preprocessing_Data_File.all);
675 Ptr := Max + 1;
677 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
679 when 'P' =>
680 Treat_Categorization_Errors_As_Warnings := True;
682 -- -gnates=file (specify extra file switches for gnat2why)
684 -- This is an internal switch
686 when 's' =>
687 if not First_Switch then
688 Osint.Fail
689 ("-gnates must not be combined with other switches");
690 end if;
692 -- Check for '='
694 Ptr := Ptr + 1;
696 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
697 Bad_Switch ("-gnates");
698 else
699 SPARK_Switches_File_Name :=
700 new String'(Switch_Chars (Ptr + 1 .. Max));
701 end if;
703 return;
705 -- -gnateS (generate SCO information)
707 -- Include Source Coverage Obligation information in ALI
708 -- files for use by source coverage analysis tools
709 -- (gnatcov) (equivalent to -fdump-scos, provided for
710 -- backwards compatibility).
712 when 'S' =>
713 Generate_SCO := True;
714 Generate_SCO_Instance_Table := True;
715 Ptr := Ptr + 1;
717 -- -gnatet (write target dependent information)
719 when 't' =>
720 if not First_Switch then
721 Osint.Fail
722 ("-gnatet must not be combined with other switches");
723 end if;
725 -- Check for '='
727 Ptr := Ptr + 1;
729 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
730 Bad_Switch ("-gnatet");
731 else
732 Target_Dependent_Info_Write_Name :=
733 new String'(Switch_Chars (Ptr + 1 .. Max));
734 end if;
736 return;
738 -- -gnateT (read target dependent information)
740 when 'T' =>
741 if not First_Switch then
742 Osint.Fail
743 ("-gnateT must not be combined with other switches");
744 end if;
746 -- Check for '='
748 Ptr := Ptr + 1;
750 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
751 Bad_Switch ("-gnateT");
752 else
753 -- This parameter was stored by Set_Targ earlier
755 pragma Assert
756 (Target_Dependent_Info_Read_Name.all =
757 Switch_Chars (Ptr + 1 .. Max));
758 null;
759 end if;
761 return;
763 -- -gnateu (unrecognized y,V,w switches)
765 when 'u' =>
766 Ptr := Ptr + 1;
767 Ignore_Unrecognized_VWY_Switches := True;
769 -- -gnateV (validity checks on parameters)
771 when 'V' =>
772 Ptr := Ptr + 1;
773 Check_Validity_Of_Parameters := True;
775 -- -gnateY (ignore Style_Checks pragmas)
777 when 'Y' =>
778 Ignore_Style_Checks_Pragmas := True;
779 Ptr := Ptr + 1;
781 -- -gnatez (final delimiter of explicit switches)
783 -- This is an internal switch
785 -- All switches that come after -gnatez have been added by
786 -- the GCC driver and are not stored in the ALI file. See
787 -- also -gnatea above.
789 when 'z' =>
790 Store_Switch := False;
791 Disable_Switch_Storing;
792 Ptr := Ptr + 1;
794 -- All other -gnate? switches are unassigned
796 when others =>
797 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
798 end case;
800 -- -gnatE (dynamic elaboration checks)
802 when 'E' =>
803 Ptr := Ptr + 1;
804 Dynamic_Elaboration_Checks := True;
806 -- -gnatf (full error messages)
808 when 'f' =>
809 Ptr := Ptr + 1;
810 All_Errors_Mode := True;
812 -- -gnatF (overflow of predefined float types)
814 when 'F' =>
815 Ptr := Ptr + 1;
816 External_Name_Exp_Casing := Uppercase;
817 External_Name_Imp_Casing := Uppercase;
819 -- -gnatg (GNAT implementation mode)
821 when 'g' =>
822 Ptr := Ptr + 1;
823 GNAT_Mode := True;
824 Identifier_Character_Set := 'n';
825 System_Extend_Unit := Empty;
826 Warning_Mode := Treat_As_Error;
827 Style_Check_Main := True;
828 Ada_Version := Ada_2012;
829 Ada_Version_Explicit := Ada_2012;
830 Ada_Version_Pragma := Empty;
832 -- Set default warnings and style checks for -gnatg
834 Set_GNAT_Mode_Warnings;
835 Set_GNAT_Style_Check_Options;
837 -- -gnatG (output generated code)
839 when 'G' =>
840 Ptr := Ptr + 1;
841 Print_Generated_Code := True;
843 -- Scan optional integer line limit value
845 if Nat_Present (Switch_Chars, Max, Ptr) then
846 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
847 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
848 end if;
850 -- -gnath (help information)
852 when 'h' =>
853 Ptr := Ptr + 1;
854 Usage_Requested := True;
856 -- -gnati (character set)
858 when 'i' =>
859 if Ptr = Max then
860 Bad_Switch ("-gnati");
861 end if;
863 Ptr := Ptr + 1;
864 C := Switch_Chars (Ptr);
866 if C in '1' .. '5'
867 or else C = '8'
868 or else C = '9'
869 or else C = 'p'
870 or else C = 'f'
871 or else C = 'n'
872 or else C = 'w'
873 then
874 Identifier_Character_Set := C;
875 Ptr := Ptr + 1;
877 else
878 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
879 end if;
881 -- -gnatI (ignore representation clauses)
883 when 'I' =>
884 Ptr := Ptr + 1;
885 Ignore_Rep_Clauses := True;
887 -- -gnatj (messages in limited length lines)
889 when 'j' =>
890 Ptr := Ptr + 1;
891 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
893 -- -gnatk (limit file name length)
895 when 'k' =>
896 Ptr := Ptr + 1;
897 Scan_Pos
898 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
900 -- -gnatl (output full source)
902 when 'l' =>
903 Ptr := Ptr + 1;
904 Full_List := True;
906 -- There may be an equal sign between -gnatl and a file name
908 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
909 if Ptr = Max then
910 Osint.Fail ("file name for -gnatl= is null");
911 else
912 Opt.Full_List_File_Name :=
913 new String'(Switch_Chars (Ptr + 1 .. Max));
914 Ptr := Max + 1;
915 end if;
916 end if;
918 -- -gnatL (corresponding source text)
920 when 'L' =>
921 Ptr := Ptr + 1;
922 Dump_Source_Text := True;
924 -- -gnatm (max number or errors/warnings)
926 when 'm' =>
927 Ptr := Ptr + 1;
928 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Messages, C);
930 -- -gnatn (enable pragma Inline)
932 when 'n' =>
933 Ptr := Ptr + 1;
934 Inline_Active := True;
936 -- There may be a digit (1 or 2) appended to the switch
938 if Ptr <= Max then
939 C := Switch_Chars (Ptr);
941 if C in '1' .. '2' then
942 Ptr := Ptr + 1;
943 Inline_Level := Character'Pos (C) - Character'Pos ('0');
944 end if;
945 end if;
947 -- -gnatN (obsolescent)
949 when 'N' =>
950 Ptr := Ptr + 1;
951 Inline_Active := True;
952 Front_End_Inlining := True;
954 -- -gnato (overflow checks)
956 when 'o' =>
957 Ptr := Ptr + 1;
959 -- Case of -gnato0 (overflow checking turned off)
961 if Ptr <= Max and then Switch_Chars (Ptr) = '0' then
962 Ptr := Ptr + 1;
963 Suppress_Options.Suppress (Overflow_Check) := True;
965 -- We set strict mode in case overflow checking is turned
966 -- on locally (also records that we had a -gnato switch).
968 Suppress_Options.Overflow_Mode_General := Strict;
969 Suppress_Options.Overflow_Mode_Assertions := Strict;
971 -- All cases other than -gnato0 (overflow checking turned on)
973 else
974 Suppress_Options.Suppress (Overflow_Check) := False;
976 -- Case of no digits after the -gnato
978 if Ptr > Max
979 or else Switch_Chars (Ptr) not in '1' .. '3'
980 then
981 Suppress_Options.Overflow_Mode_General := Strict;
982 Suppress_Options.Overflow_Mode_Assertions := Strict;
984 -- At least one digit after the -gnato
986 else
987 -- Handle first digit after -gnato
989 Suppress_Options.Overflow_Mode_General :=
990 Get_Overflow_Mode (Switch_Chars (Ptr));
991 Ptr := Ptr + 1;
993 -- Only one digit after -gnato, set assertions mode to be
994 -- the same as general mode.
996 if Ptr > Max
997 or else Switch_Chars (Ptr) not in '1' .. '3'
998 then
999 Suppress_Options.Overflow_Mode_Assertions :=
1000 Suppress_Options.Overflow_Mode_General;
1002 -- Process second digit after -gnato
1004 else
1005 Suppress_Options.Overflow_Mode_Assertions :=
1006 Get_Overflow_Mode (Switch_Chars (Ptr));
1007 Ptr := Ptr + 1;
1008 end if;
1009 end if;
1010 end if;
1012 -- -gnatO (specify name of the object file)
1014 -- This is an internal switch
1016 when 'O' =>
1017 Store_Switch := False;
1018 Ptr := Ptr + 1;
1019 Output_File_Name_Present := True;
1021 -- -gnatp (suppress all checks)
1023 when 'p' =>
1024 Ptr := Ptr + 1;
1026 -- Skip processing if cancelled by subsequent -gnat-p
1028 if Switch_Subsequently_Cancelled ("p", Args, Arg_Rank) then
1029 Store_Switch := False;
1031 else
1032 -- Set all specific options as well as All_Checks in the
1033 -- Suppress_Options array, excluding Elaboration_Check,
1034 -- since this is treated specially because we do not want
1035 -- -gnatp to disable static elaboration processing. Also
1036 -- exclude Atomic_Synchronization, since this is not a real
1037 -- check.
1039 for J in Suppress_Options.Suppress'Range loop
1040 if J /= Elaboration_Check
1041 and then
1042 J /= Atomic_Synchronization
1043 then
1044 Suppress_Options.Suppress (J) := True;
1045 end if;
1046 end loop;
1048 Validity_Checks_On := False;
1049 Opt.Suppress_Checks := True;
1051 -- Set overflow mode checking to strict in case it gets
1052 -- turned on locally (also signals that overflow checking
1053 -- has been specifically turned off).
1055 Suppress_Options.Overflow_Mode_General := Strict;
1056 Suppress_Options.Overflow_Mode_Assertions := Strict;
1057 end if;
1059 -- -gnatP (periodic poll)
1061 when 'P' =>
1062 Ptr := Ptr + 1;
1063 Polling_Required := True;
1065 -- -gnatq (don't quit)
1067 when 'q' =>
1068 Ptr := Ptr + 1;
1069 Try_Semantics := True;
1071 -- -gnatQ (always write ALI file)
1073 when 'Q' =>
1074 Ptr := Ptr + 1;
1075 Force_ALI_Tree_File := True;
1076 Try_Semantics := True;
1078 -- -gnatr (restrictions as warnings)
1080 when 'r' =>
1081 Ptr := Ptr + 1;
1082 Treat_Restrictions_As_Warnings := True;
1084 -- -gnatR (list rep. info)
1086 when 'R' =>
1088 -- Not allowed if previous -gnatD given. See more extensive
1089 -- comments in the 'D' section for the inverse test.
1091 if Debug_Generated_Code then
1092 Osint.Fail
1093 ("-gnatR not permitted since -gnatD given previously");
1094 end if;
1096 -- Set to annotate rep info, and set default -gnatR mode
1098 Back_Annotate_Rep_Info := True;
1099 List_Representation_Info := 1;
1101 -- Scan possible parameter
1103 Ptr := Ptr + 1;
1104 while Ptr <= Max loop
1105 C := Switch_Chars (Ptr);
1107 if C in '1' .. '3' then
1108 List_Representation_Info :=
1109 Character'Pos (C) - Character'Pos ('0');
1111 elsif Switch_Chars (Ptr) = 's' then
1112 List_Representation_Info_To_File := True;
1114 elsif Switch_Chars (Ptr) = 'm' then
1115 List_Representation_Info_Mechanisms := True;
1117 else
1118 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
1119 end if;
1121 Ptr := Ptr + 1;
1122 end loop;
1124 -- -gnats (syntax check only)
1126 when 's' =>
1127 if not First_Switch then
1128 Osint.Fail
1129 ("-gnats must be first if combined with other switches");
1130 end if;
1132 Ptr := Ptr + 1;
1133 Operating_Mode := Check_Syntax;
1135 -- -gnatS (print package Standard)
1137 when 'S' =>
1138 Print_Standard := True;
1139 Ptr := Ptr + 1;
1141 -- -gnatt (output tree)
1143 when 't' =>
1144 Ptr := Ptr + 1;
1145 Tree_Output := True;
1146 Back_Annotate_Rep_Info := True;
1148 -- -gnatT (change start of internal table sizes)
1150 when 'T' =>
1151 Ptr := Ptr + 1;
1152 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
1154 -- -gnatu (list units for compilation)
1156 when 'u' =>
1157 Ptr := Ptr + 1;
1158 List_Units := True;
1160 -- -gnatU (unique tags)
1162 when 'U' =>
1163 Ptr := Ptr + 1;
1164 Unique_Error_Tag := True;
1166 -- -gnatv (verbose mode)
1168 when 'v' =>
1169 Ptr := Ptr + 1;
1170 Verbose_Mode := True;
1172 -- -gnatV (validity checks)
1174 when 'V' =>
1175 Store_Switch := False;
1176 Ptr := Ptr + 1;
1178 if Ptr > Max then
1179 Bad_Switch ("-gnatV");
1181 else
1182 declare
1183 OK : Boolean;
1185 begin
1186 Set_Validity_Check_Options
1187 (Switch_Chars (Ptr .. Max), OK, Ptr);
1189 if not OK then
1190 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
1191 end if;
1193 for Index in First_Char + 1 .. Max loop
1194 Store_Compilation_Switch
1195 ("-gnatV" & Switch_Chars (Index));
1196 end loop;
1197 end;
1198 end if;
1200 Ptr := Max + 1;
1202 -- -gnatw (warning modes)
1204 when 'w' =>
1205 Store_Switch := False;
1206 Ptr := Ptr + 1;
1208 if Ptr > Max then
1209 Bad_Switch ("-gnatw");
1210 end if;
1212 while Ptr <= Max loop
1213 C := Switch_Chars (Ptr);
1215 -- Case of dot switch
1217 if C = '.' and then Ptr < Max then
1218 Ptr := Ptr + 1;
1219 C := Switch_Chars (Ptr);
1221 if Set_Dot_Warning_Switch (C) then
1222 Store_Compilation_Switch ("-gnatw." & C);
1223 else
1224 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
1225 end if;
1227 -- Normal case, no dot
1229 else
1230 if Set_Warning_Switch (C) then
1231 Store_Compilation_Switch ("-gnatw" & C);
1232 else
1233 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
1234 end if;
1235 end if;
1237 Ptr := Ptr + 1;
1238 end loop;
1240 return;
1242 -- -gnatW (wide character encoding method)
1244 when 'W' =>
1245 Ptr := Ptr + 1;
1247 if Ptr > Max then
1248 Bad_Switch ("-gnatW");
1249 end if;
1251 begin
1252 Wide_Character_Encoding_Method :=
1253 Get_WC_Encoding_Method (Switch_Chars (Ptr));
1254 exception
1255 when Constraint_Error =>
1256 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
1257 end;
1259 Wide_Character_Encoding_Method_Specified := True;
1261 Upper_Half_Encoding :=
1262 Wide_Character_Encoding_Method in
1263 WC_Upper_Half_Encoding_Method;
1265 Ptr := Ptr + 1;
1267 -- -gnatx (suppress cross-ref information)
1269 when 'x' =>
1270 Ptr := Ptr + 1;
1271 Xref_Active := False;
1273 -- -gnatX (language extensions)
1275 when 'X' =>
1276 Ptr := Ptr + 1;
1277 Extensions_Allowed := True;
1278 Ada_Version := Ada_Version_Type'Last;
1279 Ada_Version_Explicit := Ada_Version_Type'Last;
1280 Ada_Version_Pragma := Empty;
1282 -- -gnaty (style checks)
1284 when 'y' =>
1285 Ptr := Ptr + 1;
1286 Style_Check_Main := True;
1288 if Ptr > Max then
1289 Set_Default_Style_Check_Options;
1291 else
1292 Store_Switch := False;
1294 declare
1295 OK : Boolean;
1297 begin
1298 Set_Style_Check_Options
1299 (Switch_Chars (Ptr .. Max), OK, Ptr);
1301 if not OK then
1302 Osint.Fail
1303 ("bad -gnaty switch (" &
1304 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
1305 end if;
1307 Ptr := First_Char + 1;
1308 while Ptr <= Max loop
1309 if Switch_Chars (Ptr) = 'M' then
1310 First_Char := Ptr;
1311 loop
1312 Ptr := Ptr + 1;
1313 exit when Ptr > Max
1314 or else Switch_Chars (Ptr) not in '0' .. '9';
1315 end loop;
1317 Store_Compilation_Switch
1318 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
1320 else
1321 Store_Compilation_Switch
1322 ("-gnaty" & Switch_Chars (Ptr));
1323 Ptr := Ptr + 1;
1324 end if;
1325 end loop;
1326 end;
1327 end if;
1329 -- -gnatz (stub generation)
1331 when 'z' =>
1333 -- -gnatz must be the first and only switch in Switch_Chars,
1334 -- and is a two-letter switch.
1336 if Ptr /= Switch_Chars'First + 5
1337 or else (Max - Ptr + 1) > 2
1338 then
1339 Osint.Fail
1340 ("-gnatz* may not be combined with other switches");
1341 end if;
1343 if Ptr = Max then
1344 Bad_Switch ("-gnatz");
1345 end if;
1347 Ptr := Ptr + 1;
1349 -- Only one occurrence of -gnat* is permitted
1351 if Distribution_Stub_Mode = No_Stubs then
1352 case Switch_Chars (Ptr) is
1353 when 'r' =>
1354 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1356 when 'c' =>
1357 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1359 when others =>
1360 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
1361 end case;
1363 Ptr := Ptr + 1;
1365 else
1366 Osint.Fail ("only one -gnatz* switch allowed");
1367 end if;
1369 -- -gnatZ (obsolescent)
1371 when 'Z' =>
1372 Ptr := Ptr + 1;
1373 Osint.Fail
1374 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1376 -- Note on language version switches: whenever a new language
1377 -- version switch is added, Switch.M.Normalize_Compiler_Switches
1378 -- must be updated.
1380 -- -gnat83
1382 when '8' =>
1383 if Ptr = Max then
1384 Bad_Switch ("-gnat8");
1385 end if;
1387 Ptr := Ptr + 1;
1389 if Switch_Chars (Ptr) /= '3' then
1390 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
1391 else
1392 Ptr := Ptr + 1;
1393 Ada_Version := Ada_83;
1394 Ada_Version_Explicit := Ada_83;
1395 Ada_Version_Pragma := Empty;
1396 end if;
1398 -- -gnat95
1400 when '9' =>
1401 if Ptr = Max then
1402 Bad_Switch ("-gnat9");
1403 end if;
1405 Ptr := Ptr + 1;
1407 if Switch_Chars (Ptr) /= '5' then
1408 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
1409 else
1410 Ptr := Ptr + 1;
1411 Ada_Version := Ada_95;
1412 Ada_Version_Explicit := Ada_95;
1413 Ada_Version_Pragma := Empty;
1414 end if;
1416 -- -gnat05
1418 when '0' =>
1419 if Ptr = Max then
1420 Bad_Switch ("-gnat0");
1421 end if;
1423 Ptr := Ptr + 1;
1425 if Switch_Chars (Ptr) /= '5' then
1426 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1427 else
1428 Ptr := Ptr + 1;
1429 Ada_Version := Ada_2005;
1430 Ada_Version_Explicit := Ada_2005;
1431 Ada_Version_Pragma := Empty;
1432 end if;
1434 -- -gnat12
1436 when '1' =>
1437 if Ptr = Max then
1438 Bad_Switch ("-gnat1");
1439 end if;
1441 Ptr := Ptr + 1;
1443 if Switch_Chars (Ptr) /= '2' then
1444 Bad_Switch ("-gnat1" & Switch_Chars (Ptr .. Max));
1445 else
1446 Ptr := Ptr + 1;
1447 Ada_Version := Ada_2012;
1448 Ada_Version_Explicit := Ada_2012;
1449 Ada_Version_Pragma := Empty;
1450 end if;
1452 -- -gnat2005 and -gnat2012
1454 when '2' =>
1455 if Ptr > Max - 3 then
1456 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1458 elsif Switch_Chars (Ptr .. Ptr + 3) = "2005" then
1459 Ada_Version := Ada_2005;
1461 elsif Switch_Chars (Ptr .. Ptr + 3) = "2012" then
1462 Ada_Version := Ada_2012;
1464 else
1465 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Ptr + 3));
1466 end if;
1468 Ada_Version_Explicit := Ada_Version;
1469 Ada_Version_Pragma := Empty;
1470 Ptr := Ptr + 4;
1472 -- Switch cancellation, currently only -gnat-p is allowed.
1473 -- All we do here is the error checking, since the actual
1474 -- processing for switch cancellation is done by calls to
1475 -- Switch_Subsequently_Cancelled at the appropriate point.
1477 when '-' =>
1479 -- Simple ignore -gnat-p
1481 if Switch_Chars = "-gnat-p" then
1482 return;
1484 -- Any other occurrence of minus is ignored. This is for
1485 -- maximum compatibility with previous version which ignored
1486 -- all occurrences of minus.
1488 else
1489 Store_Switch := False;
1490 Ptr := Ptr + 1;
1491 end if;
1493 -- We ignore '/' in switches, this is historical, still needed???
1495 when '/' =>
1496 Store_Switch := False;
1498 -- Anything else is an error (illegal switch character)
1500 when others =>
1501 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1502 end case;
1504 if Store_Switch then
1505 Store_Compilation_Switch
1506 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1507 end if;
1509 First_Switch := False;
1510 end loop;
1511 end if;
1512 end Scan_Front_End_Switches;
1514 -----------------------------------
1515 -- Switch_Subsequently_Cancelled --
1516 -----------------------------------
1518 function Switch_Subsequently_Cancelled
1519 (C : String;
1520 Args : String_List;
1521 Arg_Rank : Positive) return Boolean
1523 begin
1524 -- Loop through arguments following the current one
1526 for Arg in Arg_Rank + 1 .. Args'Last loop
1527 if Args (Arg).all = "-gnat-" & C then
1528 return True;
1529 end if;
1530 end loop;
1532 -- No match found, not cancelled
1534 return False;
1535 end Switch_Subsequently_Cancelled;
1537 end Switch.C;