Implement -mmemcpy-strategy= and -mmemset-strategy= options
[official-gcc.git] / gcc / ada / switch-c.adb
blob0fc6bdb2188c0280b113af32b7757fcc80b44497
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-2013, 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 Validsw; use Validsw;
35 with Stylesw; use Stylesw;
36 with Ttypes; use Ttypes;
37 with Warnsw; use Warnsw;
39 with Ada.Unchecked_Deallocation;
40 with System.WCh_Con; use System.WCh_Con;
42 package body Switch.C is
44 RTS_Specified : String_Access := null;
45 -- Used to detect multiple use of --RTS= flag
47 procedure Add_Symbol_Definition (Def : String);
48 -- Add a symbol definition from the command line
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
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.
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.
68 ---------------------------
69 -- Add_Symbol_Definition --
70 ---------------------------
72 procedure Add_Symbol_Definition (Def : String) is
73 begin
74 -- If Preprocessor_Symbol_Defs is not large enough, double its size
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;
88 Preprocessing_Symbol_Last := Preprocessing_Symbol_Last + 1;
89 Preprocessing_Symbol_Defs (Preprocessing_Symbol_Last) :=
90 new String'(Def);
91 end Add_Symbol_Definition;
93 -----------------------
94 -- Get_Overflow_Mode --
95 -----------------------
97 function Get_Overflow_Mode (C : Character) return Overflow_Mode_Type is
98 begin
99 case C is
100 when '1' =>
101 return Strict;
103 when '2' =>
104 return Minimized;
106 -- Eliminated allowed only if Long_Long_Integer is 64 bits (since
107 -- the current implementation of System.Bignums assumes this).
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;
116 when others =>
117 raise Program_Error;
118 end case;
119 end Get_Overflow_Mode;
121 -----------------------------
122 -- Scan_Front_End_Switches --
123 -----------------------------
125 procedure Scan_Front_End_Switches
126 (Switch_Chars : String;
127 Args : String_List;
128 Arg_Rank : Positive)
130 First_Switch : Boolean := True;
131 -- False for all but first switch
133 Max : constant Natural := Switch_Chars'Last;
134 Ptr : Natural;
135 C : Character := ' ';
136 Dot : Boolean;
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.
147 First_Char : Positive;
148 -- Marks start of switch to be stored
150 First_Ptr : Positive;
151 -- Save position of first character after -gnatd (for checking that
152 -- debug flags that must come first are first, in particular -gnatd.b),
154 begin
155 Ptr := Switch_Chars'First;
157 -- Skip past the initial character (must be the switch character)
159 if Ptr = Max then
160 Bad_Switch (C);
161 else
162 Ptr := Ptr + 1;
163 end if;
165 -- Handle switches that do not start with -gnat
167 if Ptr + 3 > Max or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat" then
169 -- There are two front-end switches that do not start with -gnat:
170 -- -I, --RTS
172 if Switch_Chars (Ptr) = 'I' then
174 -- Set flag Search_Directory_Present if switch is "-I" only:
175 -- the directory will be the next argument.
177 if Ptr = Max then
178 Search_Directory_Present := True;
179 return;
180 end if;
182 Ptr := Ptr + 1;
184 -- Find out whether this is a -I- or regular -Ixxx switch
186 -- Note: -I switches are not recorded in the ALI file, since the
187 -- meaning of the program depends on the source files compiled,
188 -- not where they came from.
190 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
191 Look_In_Primary_Dir := False;
192 else
193 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
194 end if;
196 -- Processing of the --RTS switch. --RTS may have been modified by
197 -- gcc into -fRTS (for GCC targets).
199 elsif Ptr + 3 <= Max
200 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
201 or else
202 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
203 then
204 Ptr := Ptr + 1;
206 if Ptr + 4 > Max
207 or else Switch_Chars (Ptr + 3) /= '='
208 then
209 Osint.Fail ("missing path for --RTS");
210 else
211 -- Check that this is the first time --RTS is specified or if
212 -- it is not the first time, the same path has been specified.
214 if RTS_Specified = null then
215 RTS_Specified := new String'(Switch_Chars (Ptr + 4 .. Max));
217 elsif
218 RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
219 then
220 Osint.Fail ("--RTS cannot be specified multiple times");
221 end if;
223 -- Valid --RTS switch
225 Opt.No_Stdinc := True;
226 Opt.RTS_Switch := True;
228 RTS_Src_Path_Name :=
229 Get_RTS_Search_Dir
230 (Switch_Chars (Ptr + 4 .. Max), Include);
232 RTS_Lib_Path_Name :=
233 Get_RTS_Search_Dir
234 (Switch_Chars (Ptr + 4 .. Max), Objects);
236 if RTS_Src_Path_Name /= null
237 and then RTS_Lib_Path_Name /= null
238 then
239 -- Store the -fRTS switch (Note: Store_Compilation_Switch
240 -- changes -fRTS back into --RTS for the actual output).
242 Store_Compilation_Switch (Switch_Chars);
244 elsif RTS_Src_Path_Name = null
245 and then RTS_Lib_Path_Name = null
246 then
247 Osint.Fail ("RTS path not valid: missing " &
248 "adainclude and adalib directories");
250 elsif RTS_Src_Path_Name = null then
251 Osint.Fail ("RTS path not valid: missing " &
252 "adainclude directory");
254 elsif RTS_Lib_Path_Name = null then
255 Osint.Fail ("RTS path not valid: missing " &
256 "adalib directory");
257 end if;
258 end if;
260 -- There are no other switches not starting with -gnat
262 else
263 Bad_Switch (Switch_Chars);
264 end if;
266 -- Case of switch starting with -gnat
268 else
269 Ptr := Ptr + 4;
271 -- Loop to scan through switches given in switch string
273 while Ptr <= Max loop
274 First_Char := Ptr;
275 Store_Switch := True;
277 C := Switch_Chars (Ptr);
279 case C is
281 -- -gnata (assertions enabled)
283 when 'a' =>
284 Ptr := Ptr + 1;
285 Assertions_Enabled := True;
287 -- -gnatA (disregard gnat.adc)
289 when 'A' =>
290 Ptr := Ptr + 1;
291 Config_File := False;
293 -- -gnatb (brief messages to stderr)
295 when 'b' =>
296 Ptr := Ptr + 1;
297 Brief_Output := True;
299 -- -gnatB (assume no invalid values)
301 when 'B' =>
302 Ptr := Ptr + 1;
303 Assume_No_Invalid_Values := True;
305 -- -gnatc (check syntax and semantics only)
307 when 'c' =>
308 if not First_Switch then
309 Osint.Fail
310 ("-gnatc must be first if combined with other switches");
311 end if;
313 Ptr := Ptr + 1;
314 Operating_Mode := Check_Semantics;
316 -- -gnatC (Generate CodePeer information)
318 when 'C' =>
319 Ptr := Ptr + 1;
321 if not CodePeer_Mode then
322 CodePeer_Mode := True;
324 -- Suppress compiler warnings by default, since what we are
325 -- interested in here is what CodePeer can find out. Note
326 -- that if -gnatwxxx is specified after -gnatC on the
327 -- command line, we do not want to override this setting in
328 -- Adjust_Global_Switches, and assume that the user wants to
329 -- get both warnings from GNAT and CodePeer messages.
331 Warning_Mode := Suppress;
332 end if;
334 -- -gnatd (compiler debug options)
336 when 'd' =>
337 Store_Switch := False;
338 Dot := False;
339 First_Ptr := Ptr + 1;
341 -- Note: for the debug switch, the remaining characters in this
342 -- switch field must all be debug flags, since all valid switch
343 -- characters are also valid debug characters.
345 -- Loop to scan out debug flags
347 while Ptr < Max loop
348 Ptr := Ptr + 1;
349 C := Switch_Chars (Ptr);
350 exit when C = ASCII.NUL or else C = '/' or else C = '-';
352 if C in '1' .. '9' or else
353 C in 'a' .. 'z' or else
354 C in 'A' .. 'Z'
355 then
356 -- Case of dotted flag
358 if Dot then
359 Set_Dotted_Debug_Flag (C);
360 Store_Compilation_Switch ("-gnatd." & C);
362 -- Special check, -gnatd.b must come first
364 if C = 'b'
365 and then (Ptr /= First_Ptr + 1
366 or else not First_Switch)
367 then
368 Osint.Fail
369 ("-gnatd.b must be first if combined "
370 & "with other switches");
371 end if;
373 -- Not a dotted flag
375 else
376 Set_Debug_Flag (C);
377 Store_Compilation_Switch ("-gnatd" & C);
378 end if;
380 elsif C = '.' then
381 Dot := True;
383 elsif Dot then
384 Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
385 else
386 Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
387 end if;
388 end loop;
390 return;
392 -- -gnatD (debug expanded code)
394 when 'D' =>
395 Ptr := Ptr + 1;
397 -- Not allowed if previous -gnatR given
399 -- The reason for this prohibition is that the rewriting of
400 -- Sloc values causes strange malfunctions in the tests of
401 -- whether units belong to the main source. This is really a
402 -- bug, but too hard to fix for a marginal capability ???
404 -- The proper fix is to completely redo -gnatD processing so
405 -- that the tree is not messed with, and instead a separate
406 -- table is built on the side for debug information generation.
408 if List_Representation_Info /= 0 then
409 Osint.Fail
410 ("-gnatD not permitted since -gnatR given previously");
411 end if;
413 -- Scan optional integer line limit value
415 if Nat_Present (Switch_Chars, Max, Ptr) then
416 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'D');
417 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
418 end if;
420 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
421 -- generation in the ali file) since otherwise this generation
422 -- gets confused by the "wrong" Sloc values put in the tree.
424 Debug_Generated_Code := True;
425 Xref_Active := False;
426 Set_Debug_Flag ('g');
428 -- -gnate? (extended switches)
430 when 'e' =>
431 Ptr := Ptr + 1;
433 -- The -gnate? switches are all double character switches
434 -- so we must always have a character after the e.
436 if Ptr > Max then
437 Bad_Switch ("-gnate");
438 end if;
440 case Switch_Chars (Ptr) is
442 -- -gnatea (initial delimiter of explicit switches)
444 -- This is an internal switch
446 -- All switches that come before -gnatea have been added by
447 -- the GCC driver and are not stored in the ALI file.
448 -- See also -gnatez below.
450 when 'a' =>
451 Store_Switch := False;
452 Enable_Switch_Storing;
453 Ptr := Ptr + 1;
455 -- -gnateA (aliasing checks on parameters)
457 when 'A' =>
458 Ptr := Ptr + 1;
459 Check_Aliasing_Of_Parameters := True;
461 -- -gnatec (configuration pragmas)
463 when 'c' =>
464 Store_Switch := False;
465 Ptr := Ptr + 1;
467 -- There may be an equal sign between -gnatec and
468 -- the path name of the config file.
470 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
471 Ptr := Ptr + 1;
472 end if;
474 if Ptr > Max then
475 Bad_Switch ("-gnatec");
476 end if;
478 declare
479 Config_File_Name : constant String_Access :=
480 new String'
481 (Switch_Chars (Ptr .. Max));
483 begin
484 if Config_File_Names = null then
485 Config_File_Names :=
486 new String_List'(1 => Config_File_Name);
488 else
489 declare
490 New_Names : constant String_List_Access :=
491 new String_List
492 (1 ..
493 Config_File_Names'Length + 1);
495 begin
496 for Index in Config_File_Names'Range loop
497 New_Names (Index) :=
498 Config_File_Names (Index);
499 Config_File_Names (Index) := null;
500 end loop;
502 New_Names (New_Names'Last) := Config_File_Name;
503 Free (Config_File_Names);
504 Config_File_Names := New_Names;
505 end;
506 end if;
507 end;
509 return;
511 -- -gnateC switch (CodePeer SCIL generation)
513 -- Not enabled for now, keep it for later???
514 -- use -gnatd.I only for now
516 -- when 'C' =>
517 -- Ptr := Ptr + 1;
518 -- Generate_SCIL := True;
520 -- -gnated switch (disable atomic synchronization)
522 when 'd' =>
523 Suppress_Options.Suppress (Atomic_Synchronization) :=
524 True;
526 -- -gnateD switch (preprocessing symbol definition)
528 when 'D' =>
529 Store_Switch := False;
530 Ptr := Ptr + 1;
532 if Ptr > Max then
533 Bad_Switch ("-gnateD");
534 end if;
536 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
538 -- Store the switch
540 Store_Compilation_Switch
541 ("-gnateD" & Switch_Chars (Ptr .. Max));
542 Ptr := Max + 1;
544 -- -gnateE (extra exception information)
546 when 'E' =>
547 Exception_Extra_Info := True;
548 Ptr := Ptr + 1;
550 -- -gnatef (full source path for brief error messages)
552 when 'f' =>
553 Store_Switch := False;
554 Ptr := Ptr + 1;
555 Full_Path_Name_For_Brief_Errors := True;
557 -- -gnateF (Check_Float_Overflow)
559 when 'F' =>
560 Ptr := Ptr + 1;
561 Check_Float_Overflow := True;
563 -- -gnateG (save preprocessor output)
565 when 'G' =>
566 Generate_Processed_File := True;
567 Ptr := Ptr + 1;
569 -- -gnatei (max number of instantiations)
571 when 'i' =>
572 Ptr := Ptr + 1;
573 Scan_Pos
574 (Switch_Chars, Max, Ptr, Maximum_Instantiations, C);
576 -- -gnateI (index of unit in multi-unit source)
578 when 'I' =>
579 Ptr := Ptr + 1;
580 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
582 -- -gnatem (mapping file)
584 when 'm' =>
585 Store_Switch := False;
586 Ptr := Ptr + 1;
588 -- There may be an equal sign between -gnatem and
589 -- the path name of the mapping file.
591 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
592 Ptr := Ptr + 1;
593 end if;
595 if Ptr > Max then
596 Bad_Switch ("-gnatem");
597 end if;
599 Mapping_File_Name :=
600 new String'(Switch_Chars (Ptr .. Max));
601 return;
603 -- -gnateO= (object path file)
605 -- This is an internal switch
607 when 'O' =>
608 Store_Switch := False;
609 Ptr := Ptr + 1;
611 -- Check for '='
613 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
614 Bad_Switch ("-gnateO");
615 else
616 Object_Path_File_Name :=
617 new String'(Switch_Chars (Ptr + 1 .. Max));
618 end if;
620 return;
622 -- -gnatep (preprocessing data file)
624 when 'p' =>
625 Store_Switch := False;
626 Ptr := Ptr + 1;
628 -- There may be an equal sign between -gnatep and
629 -- the path name of the mapping file.
631 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
632 Ptr := Ptr + 1;
633 end if;
635 if Ptr > Max then
636 Bad_Switch ("-gnatep");
637 end if;
639 Preprocessing_Data_File :=
640 new String'(Switch_Chars (Ptr .. Max));
642 -- Store the switch, normalizing to -gnatep=
644 Store_Compilation_Switch
645 ("-gnatep=" & Preprocessing_Data_File.all);
647 Ptr := Max + 1;
649 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
651 when 'P' =>
652 Treat_Categorization_Errors_As_Warnings := True;
654 -- -gnateS (generate SCO information)
656 -- Include Source Coverage Obligation information in ALI
657 -- files for the benefit of source coverage analysis tools
658 -- (xcov).
660 when 'S' =>
661 Generate_SCO := True;
662 Generate_SCO_Instance_Table := True;
663 Ptr := Ptr + 1;
665 -- -gnatet (write target dependent information)
667 when 't' =>
668 if not First_Switch then
669 Osint.Fail
670 ("-gnatet must not be combined with other switches");
671 end if;
673 -- Check for '='
675 Ptr := Ptr + 1;
677 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
678 Bad_Switch ("-gnatet");
679 else
680 Target_Dependent_Info_Write_Name :=
681 new String'(Switch_Chars (Ptr + 1 .. Max));
682 end if;
684 return;
686 -- -gnateT (read target dependent information)
688 when 'T' =>
689 if not First_Switch then
690 Osint.Fail
691 ("-gnateT must not be combined with other switches");
692 end if;
694 -- Check for '='
696 Ptr := Ptr + 1;
698 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
699 Bad_Switch ("-gnateT");
700 else
701 -- This parameter was stored by Set_Targ earlier
703 pragma Assert
704 (Target_Dependent_Info_Read_Name.all =
705 Switch_Chars (Ptr + 1 .. Max));
706 null;
707 end if;
709 return;
711 -- -gnateV (validity checks on parameters)
713 when 'V' =>
714 Ptr := Ptr + 1;
715 Check_Validity_Of_Parameters := True;
717 -- -gnateY (ignore Style_Checks pragmas)
719 when 'Y' =>
720 Ignore_Style_Checks_Pragmas := True;
721 Ptr := Ptr + 1;
723 -- -gnatez (final delimiter of explicit switches)
725 -- This is an internal switch
727 -- All switches that come after -gnatez have been added by
728 -- the GCC driver and are not stored in the ALI file. See
729 -- also -gnatea above.
731 when 'z' =>
732 Store_Switch := False;
733 Disable_Switch_Storing;
734 Ptr := Ptr + 1;
736 -- All other -gnate? switches are unassigned
738 when others =>
739 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
740 end case;
742 -- -gnatE (dynamic elaboration checks)
744 when 'E' =>
745 Ptr := Ptr + 1;
746 Dynamic_Elaboration_Checks := True;
748 -- -gnatf (full error messages)
750 when 'f' =>
751 Ptr := Ptr + 1;
752 All_Errors_Mode := True;
754 -- -gnatF (overflow of predefined float types)
756 when 'F' =>
757 Ptr := Ptr + 1;
758 External_Name_Exp_Casing := Uppercase;
759 External_Name_Imp_Casing := Uppercase;
761 -- -gnatg (GNAT implementation mode)
763 when 'g' =>
764 Ptr := Ptr + 1;
765 GNAT_Mode := True;
766 Identifier_Character_Set := 'n';
767 System_Extend_Unit := Empty;
768 Warning_Mode := Treat_As_Error;
769 Style_Check_Main := True;
771 -- Set Ada 2012 mode explicitly. We don't want to rely on the
772 -- implicit setting here, since for example, we want
773 -- Preelaborate_05 treated as Preelaborate
775 Ada_Version := Ada_2012;
776 Ada_Version_Explicit := Ada_Version;
778 -- Set default warnings and style checks for -gnatg
780 Set_GNAT_Mode_Warnings;
781 Set_GNAT_Style_Check_Options;
783 -- -gnatG (output generated code)
785 when 'G' =>
786 Ptr := Ptr + 1;
787 Print_Generated_Code := True;
789 -- Scan optional integer line limit value
791 if Nat_Present (Switch_Chars, Max, Ptr) then
792 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
793 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
794 end if;
796 -- -gnath (help information)
798 when 'h' =>
799 Ptr := Ptr + 1;
800 Usage_Requested := True;
802 -- -gnati (character set)
804 when 'i' =>
805 if Ptr = Max then
806 Bad_Switch ("-gnati");
807 end if;
809 Ptr := Ptr + 1;
810 C := Switch_Chars (Ptr);
812 if C in '1' .. '5'
813 or else C = '8'
814 or else C = '9'
815 or else C = 'p'
816 or else C = 'f'
817 or else C = 'n'
818 or else C = 'w'
819 then
820 Identifier_Character_Set := C;
821 Ptr := Ptr + 1;
823 else
824 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
825 end if;
827 -- -gnatI (ignore representation clauses)
829 when 'I' =>
830 Ptr := Ptr + 1;
831 Ignore_Rep_Clauses := True;
833 -- -gnatj (messages in limited length lines)
835 when 'j' =>
836 Ptr := Ptr + 1;
837 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
839 -- -gnatk (limit file name length)
841 when 'k' =>
842 Ptr := Ptr + 1;
843 Scan_Pos
844 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
846 -- -gnatl (output full source)
848 when 'l' =>
849 Ptr := Ptr + 1;
850 Full_List := True;
852 -- There may be an equal sign between -gnatl and a file name
854 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
855 if Ptr = Max then
856 Osint.Fail ("file name for -gnatl= is null");
857 else
858 Opt.Full_List_File_Name :=
859 new String'(Switch_Chars (Ptr + 1 .. Max));
860 Ptr := Max + 1;
861 end if;
862 end if;
864 -- -gnatL (corresponding source text)
866 when 'L' =>
867 Ptr := Ptr + 1;
868 Dump_Source_Text := True;
870 -- -gnatm (max number or errors/warnings)
872 when 'm' =>
873 Ptr := Ptr + 1;
874 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Messages, C);
876 -- -gnatn (enable pragma Inline)
878 when 'n' =>
879 Ptr := Ptr + 1;
880 Inline_Active := True;
882 -- There may be a digit (1 or 2) appended to the switch
884 if Ptr <= Max then
885 C := Switch_Chars (Ptr);
887 if C in '1' .. '2' then
888 Ptr := Ptr + 1;
889 Inline_Level := Character'Pos (C) - Character'Pos ('0');
890 end if;
891 end if;
893 -- -gnatN (obsolescent)
895 when 'N' =>
896 Ptr := Ptr + 1;
897 Inline_Active := True;
898 Front_End_Inlining := True;
900 -- -gnato (overflow checks)
902 when 'o' =>
903 Ptr := Ptr + 1;
904 Suppress_Options.Suppress (Overflow_Check) := False;
906 -- Case of no digits after the -gnato
908 if Ptr > Max or else Switch_Chars (Ptr) not in '1' .. '3' then
909 Suppress_Options.Overflow_Mode_General := Strict;
910 Suppress_Options.Overflow_Mode_Assertions := Strict;
912 -- At least one digit after the -gnato
914 else
915 -- Handle first digit after -gnato
917 Suppress_Options.Overflow_Mode_General :=
918 Get_Overflow_Mode (Switch_Chars (Ptr));
919 Ptr := Ptr + 1;
921 -- Only one digit after -gnato, set assertions mode to
922 -- be the same as general mode.
924 if Ptr > Max
925 or else Switch_Chars (Ptr) not in '1' .. '3'
926 then
927 Suppress_Options.Overflow_Mode_Assertions :=
928 Suppress_Options.Overflow_Mode_General;
930 -- Process second digit after -gnato
932 else
933 Suppress_Options.Overflow_Mode_Assertions :=
934 Get_Overflow_Mode (Switch_Chars (Ptr));
935 Ptr := Ptr + 1;
936 end if;
937 end if;
939 -- -gnatO (specify name of the object file)
941 -- This is an internal switch
943 when 'O' =>
944 Store_Switch := False;
945 Ptr := Ptr + 1;
946 Output_File_Name_Present := True;
948 -- -gnatp (suppress all checks)
950 when 'p' =>
951 Ptr := Ptr + 1;
953 -- Skip processing if cancelled by subsequent -gnat-p
955 if Switch_Subsequently_Cancelled ("p", Args, Arg_Rank) then
956 Store_Switch := False;
958 else
959 -- Set all specific options as well as All_Checks in the
960 -- Suppress_Options array, excluding Elaboration_Check,
961 -- since this is treated specially because we do not want
962 -- -gnatp to disable static elaboration processing. Also
963 -- exclude Atomic_Synchronization, since this is not a real
964 -- check.
966 for J in Suppress_Options.Suppress'Range loop
967 if J /= Elaboration_Check
968 and then
969 J /= Atomic_Synchronization
970 then
971 Suppress_Options.Suppress (J) := True;
972 end if;
973 end loop;
975 Validity_Checks_On := False;
976 Opt.Suppress_Checks := True;
977 end if;
979 -- -gnatP (periodic poll)
981 when 'P' =>
982 Ptr := Ptr + 1;
983 Polling_Required := True;
985 -- -gnatq (don't quit)
987 when 'q' =>
988 Ptr := Ptr + 1;
989 Try_Semantics := True;
991 -- -gnatQ (always write ALI file)
993 when 'Q' =>
994 Ptr := Ptr + 1;
995 Force_ALI_Tree_File := True;
996 Try_Semantics := True;
998 -- -gnatr (restrictions as warnings)
1000 when 'r' =>
1001 Ptr := Ptr + 1;
1002 Treat_Restrictions_As_Warnings := True;
1004 -- -gnatR (list rep. info)
1006 when 'R' =>
1008 -- Not allowed if previous -gnatD given. See more extensive
1009 -- comments in the 'D' section for the inverse test.
1011 if Debug_Generated_Code then
1012 Osint.Fail
1013 ("-gnatR not permitted since -gnatD given previously");
1014 end if;
1016 -- Set to annotate rep info, and set default -gnatR mode
1018 Back_Annotate_Rep_Info := True;
1019 List_Representation_Info := 1;
1021 -- Scan possible parameter
1023 Ptr := Ptr + 1;
1024 while Ptr <= Max loop
1025 C := Switch_Chars (Ptr);
1027 if C in '1' .. '3' then
1028 List_Representation_Info :=
1029 Character'Pos (C) - Character'Pos ('0');
1031 elsif Switch_Chars (Ptr) = 's' then
1032 List_Representation_Info_To_File := True;
1034 elsif Switch_Chars (Ptr) = 'm' then
1035 List_Representation_Info_Mechanisms := True;
1037 else
1038 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
1039 end if;
1041 Ptr := Ptr + 1;
1042 end loop;
1044 -- -gnats (syntax check only)
1046 when 's' =>
1047 if not First_Switch then
1048 Osint.Fail
1049 ("-gnats must be first if combined with other switches");
1050 end if;
1052 Ptr := Ptr + 1;
1053 Operating_Mode := Check_Syntax;
1055 -- -gnatS (print package Standard)
1057 when 'S' =>
1058 Print_Standard := True;
1059 Ptr := Ptr + 1;
1061 -- -gnatt (output tree)
1063 when 't' =>
1064 Ptr := Ptr + 1;
1065 Tree_Output := True;
1066 Back_Annotate_Rep_Info := True;
1068 -- -gnatT (change start of internal table sizes)
1070 when 'T' =>
1071 Ptr := Ptr + 1;
1072 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
1074 -- -gnatu (list units for compilation)
1076 when 'u' =>
1077 Ptr := Ptr + 1;
1078 List_Units := True;
1080 -- -gnatU (unique tags)
1082 when 'U' =>
1083 Ptr := Ptr + 1;
1084 Unique_Error_Tag := True;
1086 -- -gnatv (verbose mode)
1088 when 'v' =>
1089 Ptr := Ptr + 1;
1090 Verbose_Mode := True;
1092 -- -gnatV (validity checks)
1094 when 'V' =>
1095 Store_Switch := False;
1096 Ptr := Ptr + 1;
1098 if Ptr > Max then
1099 Bad_Switch ("-gnatV");
1101 else
1102 declare
1103 OK : Boolean;
1105 begin
1106 Set_Validity_Check_Options
1107 (Switch_Chars (Ptr .. Max), OK, Ptr);
1109 if not OK then
1110 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
1111 end if;
1113 for Index in First_Char + 1 .. Max loop
1114 Store_Compilation_Switch
1115 ("-gnatV" & Switch_Chars (Index));
1116 end loop;
1117 end;
1118 end if;
1120 Ptr := Max + 1;
1122 -- -gnatw (warning modes)
1124 when 'w' =>
1125 Store_Switch := False;
1126 Ptr := Ptr + 1;
1128 if Ptr > Max then
1129 Bad_Switch ("-gnatw");
1130 end if;
1132 while Ptr <= Max loop
1133 C := Switch_Chars (Ptr);
1135 -- Case of dot switch
1137 if C = '.' and then Ptr < Max then
1138 Ptr := Ptr + 1;
1139 C := Switch_Chars (Ptr);
1141 if Set_Dot_Warning_Switch (C) then
1142 Store_Compilation_Switch ("-gnatw." & C);
1143 else
1144 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
1145 end if;
1147 -- Normal case, no dot
1149 else
1150 if Set_Warning_Switch (C) then
1151 Store_Compilation_Switch ("-gnatw" & C);
1152 else
1153 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
1154 end if;
1155 end if;
1157 Ptr := Ptr + 1;
1158 end loop;
1160 return;
1162 -- -gnatW (wide character encoding method)
1164 when 'W' =>
1165 Ptr := Ptr + 1;
1167 if Ptr > Max then
1168 Bad_Switch ("-gnatW");
1169 end if;
1171 begin
1172 Wide_Character_Encoding_Method :=
1173 Get_WC_Encoding_Method (Switch_Chars (Ptr));
1174 exception
1175 when Constraint_Error =>
1176 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
1177 end;
1179 Wide_Character_Encoding_Method_Specified := True;
1181 Upper_Half_Encoding :=
1182 Wide_Character_Encoding_Method in
1183 WC_Upper_Half_Encoding_Method;
1185 Ptr := Ptr + 1;
1187 -- -gnatx (suppress cross-ref information)
1189 when 'x' =>
1190 Ptr := Ptr + 1;
1191 Xref_Active := False;
1193 -- -gnatX (language extensions)
1195 when 'X' =>
1196 Ptr := Ptr + 1;
1197 Extensions_Allowed := True;
1198 Ada_Version := Ada_Version_Type'Last;
1199 Ada_Version_Explicit := Ada_Version_Type'Last;
1201 -- -gnaty (style checks)
1203 when 'y' =>
1204 Ptr := Ptr + 1;
1205 Style_Check_Main := True;
1207 if Ptr > Max then
1208 Set_Default_Style_Check_Options;
1210 else
1211 Store_Switch := False;
1213 declare
1214 OK : Boolean;
1216 begin
1217 Set_Style_Check_Options
1218 (Switch_Chars (Ptr .. Max), OK, Ptr);
1220 if not OK then
1221 Osint.Fail
1222 ("bad -gnaty switch (" &
1223 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
1224 end if;
1226 Ptr := First_Char + 1;
1227 while Ptr <= Max loop
1228 if Switch_Chars (Ptr) = 'M' then
1229 First_Char := Ptr;
1230 loop
1231 Ptr := Ptr + 1;
1232 exit when Ptr > Max
1233 or else Switch_Chars (Ptr) not in '0' .. '9';
1234 end loop;
1236 Store_Compilation_Switch
1237 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
1239 else
1240 Store_Compilation_Switch
1241 ("-gnaty" & Switch_Chars (Ptr));
1242 Ptr := Ptr + 1;
1243 end if;
1244 end loop;
1245 end;
1246 end if;
1248 -- -gnatz (stub generation)
1250 when 'z' =>
1252 -- -gnatz must be the first and only switch in Switch_Chars,
1253 -- and is a two-letter switch.
1255 if Ptr /= Switch_Chars'First + 5
1256 or else (Max - Ptr + 1) > 2
1257 then
1258 Osint.Fail
1259 ("-gnatz* may not be combined with other switches");
1260 end if;
1262 if Ptr = Max then
1263 Bad_Switch ("-gnatz");
1264 end if;
1266 Ptr := Ptr + 1;
1268 -- Only one occurrence of -gnat* is permitted
1270 if Distribution_Stub_Mode = No_Stubs then
1271 case Switch_Chars (Ptr) is
1272 when 'r' =>
1273 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1275 when 'c' =>
1276 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1278 when others =>
1279 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
1280 end case;
1282 Ptr := Ptr + 1;
1284 else
1285 Osint.Fail ("only one -gnatz* switch allowed");
1286 end if;
1288 -- -gnatZ (obsolescent)
1290 when 'Z' =>
1291 Ptr := Ptr + 1;
1292 Osint.Fail
1293 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1295 -- Note on language version switches: whenever a new language
1296 -- version switch is added, Switch.M.Normalize_Compiler_Switches
1297 -- must be updated.
1299 -- -gnat83
1301 when '8' =>
1302 if Ptr = Max then
1303 Bad_Switch ("-gnat8");
1304 end if;
1306 Ptr := Ptr + 1;
1308 if Switch_Chars (Ptr) /= '3' then
1309 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
1310 else
1311 Ptr := Ptr + 1;
1312 Ada_Version := Ada_83;
1313 Ada_Version_Explicit := Ada_Version;
1314 end if;
1316 -- -gnat95
1318 when '9' =>
1319 if Ptr = Max then
1320 Bad_Switch ("-gnat9");
1321 end if;
1323 Ptr := Ptr + 1;
1325 if Switch_Chars (Ptr) /= '5' then
1326 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
1327 else
1328 Ptr := Ptr + 1;
1329 Ada_Version := Ada_95;
1330 Ada_Version_Explicit := Ada_Version;
1331 end if;
1333 -- -gnat05
1335 when '0' =>
1336 if Ptr = Max then
1337 Bad_Switch ("-gnat0");
1338 end if;
1340 Ptr := Ptr + 1;
1342 if Switch_Chars (Ptr) /= '5' then
1343 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1344 else
1345 Ptr := Ptr + 1;
1346 Ada_Version := Ada_2005;
1347 Ada_Version_Explicit := Ada_Version;
1348 end if;
1350 -- -gnat12
1352 when '1' =>
1353 if Ptr = Max then
1354 Bad_Switch ("-gnat1");
1355 end if;
1357 Ptr := Ptr + 1;
1359 if Switch_Chars (Ptr) /= '2' then
1360 Bad_Switch ("-gnat1" & Switch_Chars (Ptr .. Max));
1361 else
1362 Ptr := Ptr + 1;
1363 Ada_Version := Ada_2012;
1364 Ada_Version_Explicit := Ada_Version;
1365 end if;
1367 -- -gnat2005 and -gnat2012
1369 when '2' =>
1370 if Ptr > Max - 3 then
1371 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1373 elsif Switch_Chars (Ptr .. Ptr + 3) = "2005" then
1374 Ada_Version := Ada_2005;
1376 elsif Switch_Chars (Ptr .. Ptr + 3) = "2012" then
1377 Ada_Version := Ada_2012;
1379 else
1380 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Ptr + 3));
1381 end if;
1383 Ada_Version_Explicit := Ada_Version;
1384 Ptr := Ptr + 4;
1386 -- Switch cancellation, currently only -gnat-p is allowed.
1387 -- All we do here is the error checking, since the actual
1388 -- processing for switch cancellation is done by calls to
1389 -- Switch_Subsequently_Cancelled at the appropriate point.
1391 when '-' =>
1393 -- Simple ignore -gnat-p
1395 if Switch_Chars = "-gnat-p" then
1396 return;
1398 -- Any other occurrence of minus is ignored. This is for
1399 -- maximum compatibility with previous version which ignored
1400 -- all occurrences of minus.
1402 else
1403 Store_Switch := False;
1404 Ptr := Ptr + 1;
1405 end if;
1407 -- We ignore '/' in switches, this is historical, still needed???
1409 when '/' =>
1410 Store_Switch := False;
1412 -- Anything else is an error (illegal switch character)
1414 when others =>
1415 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1416 end case;
1418 if Store_Switch then
1419 Store_Compilation_Switch
1420 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1421 end if;
1423 First_Switch := False;
1424 end loop;
1425 end if;
1426 end Scan_Front_End_Switches;
1428 -----------------------------------
1429 -- Switch_Subsequently_Cancelled --
1430 -----------------------------------
1432 function Switch_Subsequently_Cancelled
1433 (C : String;
1434 Args : String_List;
1435 Arg_Rank : Positive) return Boolean
1437 begin
1438 -- Loop through arguments following the current one
1440 for Arg in Arg_Rank + 1 .. Args'Last loop
1441 if Args (Arg).all = "-gnat-" & C then
1442 return True;
1443 end if;
1444 end loop;
1446 -- No match found, not cancelled
1448 return False;
1449 end Switch_Subsequently_Cancelled;
1451 end Switch.C;