2014-07-31 Robert Dewar <dewar@adacore.com>
[official-gcc.git] / gcc / ada / switch-c.adb
blob5cdbd41415f231c93daba55bd56ac2ea96a85e14
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 Ttypes; use Ttypes;
36 with Validsw; use Validsw;
37 with Warnsw; use Warnsw;
39 with Ada.Unchecked_Deallocation;
40 with System.WCh_Con; use System.WCh_Con;
41 with System.OS_Lib;
43 package body Switch.C is
45 RTS_Specified : String_Access := null;
46 -- Used to detect multiple use of --RTS= flag
48 procedure Add_Symbol_Definition (Def : String);
49 -- Add a symbol definition from the command line
51 procedure Free is
52 new Ada.Unchecked_Deallocation (String_List, String_List_Access);
53 -- Avoid using System.Strings.Free, which also frees the designated strings
55 function Get_Overflow_Mode (C : Character) return Overflow_Mode_Type;
56 -- Given a digit in the range 0 .. 3, returns the corresponding value of
57 -- Overflow_Mode_Type. Raises Program_Error if C is outside this range.
59 function Switch_Subsequently_Cancelled
60 (C : String;
61 Args : String_List;
62 Arg_Rank : Positive) return Boolean;
63 -- This function is called from Scan_Front_End_Switches. It determines if
64 -- the switch currently being scanned is followed by a switch of the form
65 -- "-gnat-" & C, where C is the argument. If so, then True is returned,
66 -- and Scan_Front_End_Switches will cancel the effect of the switch. If
67 -- no such switch is found, False is returned.
69 ---------------------------
70 -- Add_Symbol_Definition --
71 ---------------------------
73 procedure Add_Symbol_Definition (Def : String) is
74 begin
75 -- If Preprocessor_Symbol_Defs is not large enough, double its size
77 if Preprocessing_Symbol_Last = Preprocessing_Symbol_Defs'Last then
78 declare
79 New_Symbol_Definitions : constant String_List_Access :=
80 new String_List (1 .. 2 * Preprocessing_Symbol_Last);
81 begin
82 New_Symbol_Definitions (Preprocessing_Symbol_Defs'Range) :=
83 Preprocessing_Symbol_Defs.all;
84 Free (Preprocessing_Symbol_Defs);
85 Preprocessing_Symbol_Defs := New_Symbol_Definitions;
86 end;
87 end if;
89 Preprocessing_Symbol_Last := Preprocessing_Symbol_Last + 1;
90 Preprocessing_Symbol_Defs (Preprocessing_Symbol_Last) :=
91 new String'(Def);
92 end Add_Symbol_Definition;
94 -----------------------
95 -- Get_Overflow_Mode --
96 -----------------------
98 function Get_Overflow_Mode (C : Character) return Overflow_Mode_Type is
99 begin
100 case C is
101 when '1' =>
102 return Strict;
104 when '2' =>
105 return Minimized;
107 -- Eliminated allowed only if Long_Long_Integer is 64 bits (since
108 -- the current implementation of System.Bignums assumes this).
110 when '3' =>
111 if Standard_Long_Long_Integer_Size /= 64 then
112 Bad_Switch ("-gnato3 not implemented for this configuration");
113 else
114 return Eliminated;
115 end if;
117 when others =>
118 raise Program_Error;
119 end case;
120 end Get_Overflow_Mode;
122 -----------------------------
123 -- Scan_Front_End_Switches --
124 -----------------------------
126 procedure Scan_Front_End_Switches
127 (Switch_Chars : String;
128 Args : String_List;
129 Arg_Rank : Positive)
131 First_Switch : Boolean := True;
132 -- False for all but first switch
134 Max : constant Natural := Switch_Chars'Last;
135 Ptr : Natural;
136 C : Character := ' ';
137 Dot : Boolean;
139 Store_Switch : Boolean;
140 -- For -gnatxx switches, the normal processing, signalled by this flag
141 -- being set to True, is to store the switch on exit from the case
142 -- statement, the switch stored is -gnat followed by the characters
143 -- from First_Char to Ptr-1. For cases like -gnaty, where the switch
144 -- is stored in separate pieces, this flag is set to False, and the
145 -- appropriate calls to Store_Compilation_Switch are made from within
146 -- the case branch.
148 First_Char : Positive;
149 -- Marks start of switch to be stored
151 First_Ptr : Positive;
152 -- Save position of first character after -gnatd (for checking that
153 -- debug flags that must come first are first, in particular -gnatd.b),
155 begin
156 Ptr := Switch_Chars'First;
158 -- Skip past the initial character (must be the switch character)
160 if Ptr = Max then
161 Bad_Switch (C);
162 else
163 Ptr := Ptr + 1;
164 end if;
166 -- Handle switches that do not start with -gnat
168 if Ptr + 3 > Max or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat" then
170 -- There are two front-end switches that do not start with -gnat:
171 -- -I, --RTS
173 if Switch_Chars (Ptr) = 'I' then
175 -- Set flag Search_Directory_Present if switch is "-I" only:
176 -- the directory will be the next argument.
178 if Ptr = Max then
179 Search_Directory_Present := True;
180 return;
181 end if;
183 Ptr := Ptr + 1;
185 -- Find out whether this is a -I- or regular -Ixxx switch
187 -- Note: -I switches are not recorded in the ALI file, since the
188 -- meaning of the program depends on the source files compiled,
189 -- not where they came from.
191 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
192 Look_In_Primary_Dir := False;
193 else
194 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
195 end if;
197 -- Processing of the --RTS switch. --RTS may have been modified by
198 -- gcc into -fRTS (for GCC targets).
200 elsif Ptr + 3 <= Max
201 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
202 or else
203 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
204 then
205 Ptr := Ptr + 1;
207 if Ptr + 4 > Max
208 or else Switch_Chars (Ptr + 3) /= '='
209 then
210 Osint.Fail ("missing path for --RTS");
212 else
213 declare
214 Runtime_Dir : String_Access;
216 begin
217 if System.OS_Lib.Is_Absolute_Path
218 (Switch_Chars (Ptr + 4 .. Max))
219 then
220 Runtime_Dir :=
221 new String'
222 (System.OS_Lib.Normalize_Pathname
223 (Switch_Chars (Ptr + 4 .. Max)));
225 else
226 Runtime_Dir :=
227 new String'(Switch_Chars (Ptr + 4 .. Max));
228 end if;
230 -- Check that this is the first time --RTS is specified
231 -- or if it is not the first time, the same path has been
232 -- specified.
234 if RTS_Specified = null then
235 RTS_Specified := Runtime_Dir;
237 elsif RTS_Specified.all /= Runtime_Dir.all then
238 Osint.Fail ("--RTS cannot be specified multiple times");
239 end if;
241 -- Valid --RTS switch
243 Opt.No_Stdinc := True;
244 Opt.RTS_Switch := True;
246 RTS_Src_Path_Name :=
247 Get_RTS_Search_Dir (Runtime_Dir.all, Include);
249 RTS_Lib_Path_Name :=
250 Get_RTS_Search_Dir (Runtime_Dir.all, Objects);
252 if RTS_Src_Path_Name /= null
253 and then RTS_Lib_Path_Name /= null
254 then
255 -- Store the -fRTS switch (Note: Store_Compilation_Switch
256 -- changes -fRTS back into --RTS for the actual output).
258 Store_Compilation_Switch (Switch_Chars);
260 elsif RTS_Src_Path_Name = null
261 and then RTS_Lib_Path_Name = null
262 then
263 Osint.Fail ("RTS path not valid: missing "
264 & "adainclude and adalib directories");
266 elsif RTS_Src_Path_Name = null then
267 Osint.Fail ("RTS path not valid: missing "
268 & "adainclude directory");
270 elsif RTS_Lib_Path_Name = null then
271 Osint.Fail ("RTS path not valid: missing "
272 & "adalib directory");
273 end if;
274 end;
275 end if;
277 -- There are no other switches not starting with -gnat
279 else
280 Bad_Switch (Switch_Chars);
281 end if;
283 -- Case of switch starting with -gnat
285 else
286 Ptr := Ptr + 4;
288 -- Loop to scan through switches given in switch string
290 while Ptr <= Max loop
291 First_Char := Ptr;
292 Store_Switch := True;
294 C := Switch_Chars (Ptr);
296 case C is
298 -- -gnata (assertions enabled)
300 when 'a' =>
301 Ptr := Ptr + 1;
302 Assertions_Enabled := True;
304 -- -gnatA (disregard gnat.adc)
306 when 'A' =>
307 Ptr := Ptr + 1;
308 Config_File := False;
310 -- -gnatb (brief messages to stderr)
312 when 'b' =>
313 Ptr := Ptr + 1;
314 Brief_Output := True;
316 -- -gnatB (assume no invalid values)
318 when 'B' =>
319 Ptr := Ptr + 1;
320 Assume_No_Invalid_Values := True;
322 -- -gnatc (check syntax and semantics only)
324 when 'c' =>
325 if not First_Switch then
326 Osint.Fail
327 ("-gnatc must be first if combined with other switches");
328 end if;
330 Ptr := Ptr + 1;
331 Operating_Mode := Check_Semantics;
333 -- -gnatC (Generate CodePeer information)
335 when 'C' =>
336 Ptr := Ptr + 1;
338 if not CodePeer_Mode then
339 CodePeer_Mode := True;
341 -- Suppress compiler warnings by default, since what we are
342 -- interested in here is what CodePeer can find out. Note
343 -- that if -gnatwxxx is specified after -gnatC on the
344 -- command line, we do not want to override this setting in
345 -- Adjust_Global_Switches, and assume that the user wants to
346 -- get both warnings from GNAT and CodePeer messages.
348 Warning_Mode := Suppress;
349 end if;
351 -- -gnatd (compiler debug options)
353 when 'd' =>
354 Store_Switch := False;
355 Dot := False;
356 First_Ptr := Ptr + 1;
358 -- Note: for the debug switch, the remaining characters in this
359 -- switch field must all be debug flags, since all valid switch
360 -- characters are also valid debug characters.
362 -- Loop to scan out debug flags
364 while Ptr < Max loop
365 Ptr := Ptr + 1;
366 C := Switch_Chars (Ptr);
367 exit when C = ASCII.NUL or else C = '/' or else C = '-';
369 if C in '1' .. '9' or else
370 C in 'a' .. 'z' or else
371 C in 'A' .. 'Z'
372 then
373 -- Case of dotted flag
375 if Dot then
376 Set_Dotted_Debug_Flag (C);
377 Store_Compilation_Switch ("-gnatd." & C);
379 -- Special check, -gnatd.b must come first
381 if C = 'b'
382 and then (Ptr /= First_Ptr + 1
383 or else not First_Switch)
384 then
385 Osint.Fail
386 ("-gnatd.b must be first if combined "
387 & "with other switches");
388 end if;
390 -- Not a dotted flag
392 else
393 Set_Debug_Flag (C);
394 Store_Compilation_Switch ("-gnatd" & C);
395 end if;
397 elsif C = '.' then
398 Dot := True;
400 elsif Dot then
401 Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
402 else
403 Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
404 end if;
405 end loop;
407 return;
409 -- -gnatD (debug expanded code)
411 when 'D' =>
412 Ptr := Ptr + 1;
414 -- Not allowed if previous -gnatR given
416 -- The reason for this prohibition is that the rewriting of
417 -- Sloc values causes strange malfunctions in the tests of
418 -- whether units belong to the main source. This is really a
419 -- bug, but too hard to fix for a marginal capability ???
421 -- The proper fix is to completely redo -gnatD processing so
422 -- that the tree is not messed with, and instead a separate
423 -- table is built on the side for debug information generation.
425 if List_Representation_Info /= 0 then
426 Osint.Fail
427 ("-gnatD not permitted since -gnatR given previously");
428 end if;
430 -- Scan optional integer line limit value
432 if Nat_Present (Switch_Chars, Max, Ptr) then
433 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'D');
434 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
435 end if;
437 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
438 -- generation in the ali file) since otherwise this generation
439 -- gets confused by the "wrong" Sloc values put in the tree.
441 Debug_Generated_Code := True;
442 Xref_Active := False;
443 Set_Debug_Flag ('g');
445 -- -gnate? (extended switches)
447 when 'e' =>
448 Ptr := Ptr + 1;
450 -- The -gnate? switches are all double character switches
451 -- so we must always have a character after the e.
453 if Ptr > Max then
454 Bad_Switch ("-gnate");
455 end if;
457 case Switch_Chars (Ptr) is
459 -- -gnatea (initial delimiter of explicit switches)
461 -- This is an internal switch
463 -- All switches that come before -gnatea have been added by
464 -- the GCC driver and are not stored in the ALI file.
465 -- See also -gnatez below.
467 when 'a' =>
468 Store_Switch := False;
469 Enable_Switch_Storing;
470 Ptr := Ptr + 1;
472 -- -gnateA (aliasing checks on parameters)
474 when 'A' =>
475 Ptr := Ptr + 1;
476 Check_Aliasing_Of_Parameters := True;
478 -- -gnatec (configuration pragmas)
480 when 'c' =>
481 Store_Switch := False;
482 Ptr := Ptr + 1;
484 -- There may be an equal sign between -gnatec and
485 -- the path name of the config file.
487 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
488 Ptr := Ptr + 1;
489 end if;
491 if Ptr > Max then
492 Bad_Switch ("-gnatec");
493 end if;
495 declare
496 Config_File_Name : constant String_Access :=
497 new String'
498 (Switch_Chars (Ptr .. Max));
500 begin
501 if Config_File_Names = null then
502 Config_File_Names :=
503 new String_List'(1 => Config_File_Name);
505 else
506 declare
507 New_Names : constant String_List_Access :=
508 new String_List
509 (1 ..
510 Config_File_Names'Length + 1);
512 begin
513 for Index in Config_File_Names'Range loop
514 New_Names (Index) :=
515 Config_File_Names (Index);
516 Config_File_Names (Index) := null;
517 end loop;
519 New_Names (New_Names'Last) := Config_File_Name;
520 Free (Config_File_Names);
521 Config_File_Names := New_Names;
522 end;
523 end if;
524 end;
526 return;
528 -- -gnateC switch (generate CodePeer messages)
530 when 'C' =>
531 Ptr := Ptr + 1;
532 Generate_CodePeer_Messages := True;
534 -- -gnated switch (disable atomic synchronization)
536 when 'd' =>
537 Suppress_Options.Suppress (Atomic_Synchronization) :=
538 True;
540 -- -gnateD switch (preprocessing symbol definition)
542 when 'D' =>
543 Store_Switch := False;
544 Ptr := Ptr + 1;
546 if Ptr > Max then
547 Bad_Switch ("-gnateD");
548 end if;
550 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
552 -- Store the switch
554 Store_Compilation_Switch
555 ("-gnateD" & Switch_Chars (Ptr .. Max));
556 Ptr := Max + 1;
558 -- -gnateE (extra exception information)
560 when 'E' =>
561 Exception_Extra_Info := True;
562 Ptr := Ptr + 1;
564 -- -gnatef (full source path for brief error messages)
566 when 'f' =>
567 Store_Switch := False;
568 Ptr := Ptr + 1;
569 Full_Path_Name_For_Brief_Errors := True;
571 -- -gnateF (Check_Float_Overflow)
573 when 'F' =>
574 Ptr := Ptr + 1;
575 Check_Float_Overflow := True;
577 -- -gnateG (save preprocessor output)
579 when 'G' =>
580 Generate_Processed_File := True;
581 Ptr := Ptr + 1;
583 -- -gnatei (max number of instantiations)
585 when 'i' =>
586 Ptr := Ptr + 1;
587 Scan_Pos
588 (Switch_Chars, Max, Ptr, Maximum_Instantiations, C);
590 -- -gnateI (index of unit in multi-unit source)
592 when 'I' =>
593 Ptr := Ptr + 1;
594 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
596 -- -gnatel
598 when 'l' =>
599 Ptr := Ptr + 1;
600 Elab_Info_Messages := True;
602 -- -gnateL
604 when 'L' =>
605 Ptr := Ptr + 1;
606 Elab_Info_Messages := False;
608 -- -gnatem (mapping file)
610 when 'm' =>
611 Store_Switch := False;
612 Ptr := Ptr + 1;
614 -- There may be an equal sign between -gnatem and
615 -- the path name of the mapping file.
617 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
618 Ptr := Ptr + 1;
619 end if;
621 if Ptr > Max then
622 Bad_Switch ("-gnatem");
623 end if;
625 Mapping_File_Name :=
626 new String'(Switch_Chars (Ptr .. Max));
627 return;
629 -- -gnateO= (object path file)
631 -- This is an internal switch
633 when 'O' =>
634 Store_Switch := False;
635 Ptr := Ptr + 1;
637 -- Check for '='
639 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
640 Bad_Switch ("-gnateO");
641 else
642 Object_Path_File_Name :=
643 new String'(Switch_Chars (Ptr + 1 .. Max));
644 end if;
646 return;
648 -- -gnatep (preprocessing data file)
650 when 'p' =>
651 Store_Switch := False;
652 Ptr := Ptr + 1;
654 -- There may be an equal sign between -gnatep and
655 -- the path name of the mapping file.
657 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
658 Ptr := Ptr + 1;
659 end if;
661 if Ptr > Max then
662 Bad_Switch ("-gnatep");
663 end if;
665 Preprocessing_Data_File :=
666 new String'(Switch_Chars (Ptr .. Max));
668 -- Store the switch, normalizing to -gnatep=
670 Store_Compilation_Switch
671 ("-gnatep=" & Preprocessing_Data_File.all);
673 Ptr := Max + 1;
675 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
677 when 'P' =>
678 Treat_Categorization_Errors_As_Warnings := True;
680 -- -gnates=file (specify extra file switches for gnat2why)
682 -- This is an internal switch
684 when 's' =>
685 if not First_Switch then
686 Osint.Fail
687 ("-gnates must not be combined with other switches");
688 end if;
690 -- Check for '='
692 Ptr := Ptr + 1;
694 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
695 Bad_Switch ("-gnates");
696 else
697 SPARK_Switches_File_Name :=
698 new String'(Switch_Chars (Ptr + 1 .. Max));
699 end if;
701 return;
703 -- -gnateS (generate SCO information)
705 -- Include Source Coverage Obligation information in ALI
706 -- files for use by source coverage analysis tools
707 -- (gnatcov) (equivalent to -fdump-scos, provided for
708 -- backwards compatibility).
710 when 'S' =>
711 Generate_SCO := True;
712 Generate_SCO_Instance_Table := True;
713 Ptr := Ptr + 1;
715 -- -gnatet (write target dependent information)
717 when 't' =>
718 if not First_Switch then
719 Osint.Fail
720 ("-gnatet must not be combined with other switches");
721 end if;
723 -- Check for '='
725 Ptr := Ptr + 1;
727 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
728 Bad_Switch ("-gnatet");
729 else
730 Target_Dependent_Info_Write_Name :=
731 new String'(Switch_Chars (Ptr + 1 .. Max));
732 end if;
734 return;
736 -- -gnateT (read target dependent information)
738 when 'T' =>
739 if not First_Switch then
740 Osint.Fail
741 ("-gnateT must not be combined with other switches");
742 end if;
744 -- Check for '='
746 Ptr := Ptr + 1;
748 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
749 Bad_Switch ("-gnateT");
750 else
751 -- This parameter was stored by Set_Targ earlier
753 pragma Assert
754 (Target_Dependent_Info_Read_Name.all =
755 Switch_Chars (Ptr + 1 .. Max));
756 null;
757 end if;
759 return;
761 -- -gnateu (unrecognized y,V,w switches)
763 when 'u' =>
764 Ptr := Ptr + 1;
765 Ignore_Unrecognized_VWY_Switches := True;
767 -- -gnateV (validity checks on parameters)
769 when 'V' =>
770 Ptr := Ptr + 1;
771 Check_Validity_Of_Parameters := True;
773 -- -gnateY (ignore Style_Checks pragmas)
775 when 'Y' =>
776 Ignore_Style_Checks_Pragmas := True;
777 Ptr := Ptr + 1;
779 -- -gnatez (final delimiter of explicit switches)
781 -- This is an internal switch
783 -- All switches that come after -gnatez have been added by
784 -- the GCC driver and are not stored in the ALI file. See
785 -- also -gnatea above.
787 when 'z' =>
788 Store_Switch := False;
789 Disable_Switch_Storing;
790 Ptr := Ptr + 1;
792 -- All other -gnate? switches are unassigned
794 when others =>
795 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
796 end case;
798 -- -gnatE (dynamic elaboration checks)
800 when 'E' =>
801 Ptr := Ptr + 1;
802 Dynamic_Elaboration_Checks := True;
804 -- -gnatf (full error messages)
806 when 'f' =>
807 Ptr := Ptr + 1;
808 All_Errors_Mode := True;
810 -- -gnatF (overflow of predefined float types)
812 when 'F' =>
813 Ptr := Ptr + 1;
814 External_Name_Exp_Casing := Uppercase;
815 External_Name_Imp_Casing := Uppercase;
817 -- -gnatg (GNAT implementation mode)
819 when 'g' =>
820 Ptr := Ptr + 1;
821 GNAT_Mode := True;
822 Identifier_Character_Set := 'n';
823 System_Extend_Unit := Empty;
824 Warning_Mode := Treat_As_Error;
825 Style_Check_Main := True;
826 Ada_Version := Ada_2012;
827 Ada_Version_Explicit := Ada_2012;
828 Ada_Version_Pragma := Empty;
830 -- Set default warnings and style checks for -gnatg
832 Set_GNAT_Mode_Warnings;
833 Set_GNAT_Style_Check_Options;
835 -- -gnatG (output generated code)
837 when 'G' =>
838 Ptr := Ptr + 1;
839 Print_Generated_Code := True;
841 -- Scan optional integer line limit value
843 if Nat_Present (Switch_Chars, Max, Ptr) then
844 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
845 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
846 end if;
848 -- -gnath (help information)
850 when 'h' =>
851 Ptr := Ptr + 1;
852 Usage_Requested := True;
854 -- -gnati (character set)
856 when 'i' =>
857 if Ptr = Max then
858 Bad_Switch ("-gnati");
859 end if;
861 Ptr := Ptr + 1;
862 C := Switch_Chars (Ptr);
864 if C in '1' .. '5'
865 or else C = '8'
866 or else C = '9'
867 or else C = 'p'
868 or else C = 'f'
869 or else C = 'n'
870 or else C = 'w'
871 then
872 Identifier_Character_Set := C;
873 Ptr := Ptr + 1;
875 else
876 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
877 end if;
879 -- -gnatI (ignore representation clauses)
881 when 'I' =>
882 Ptr := Ptr + 1;
883 Ignore_Rep_Clauses := True;
885 -- -gnatj (messages in limited length lines)
887 when 'j' =>
888 Ptr := Ptr + 1;
889 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
891 -- -gnatk (limit file name length)
893 when 'k' =>
894 Ptr := Ptr + 1;
895 Scan_Pos
896 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
898 -- -gnatl (output full source)
900 when 'l' =>
901 Ptr := Ptr + 1;
902 Full_List := True;
904 -- There may be an equal sign between -gnatl and a file name
906 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
907 if Ptr = Max then
908 Osint.Fail ("file name for -gnatl= is null");
909 else
910 Opt.Full_List_File_Name :=
911 new String'(Switch_Chars (Ptr + 1 .. Max));
912 Ptr := Max + 1;
913 end if;
914 end if;
916 -- -gnatL (corresponding source text)
918 when 'L' =>
919 Ptr := Ptr + 1;
920 Dump_Source_Text := True;
922 -- -gnatm (max number or errors/warnings)
924 when 'm' =>
925 Ptr := Ptr + 1;
926 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Messages, C);
928 -- -gnatn (enable pragma Inline)
930 when 'n' =>
931 Ptr := Ptr + 1;
932 Inline_Active := True;
934 -- There may be a digit (1 or 2) appended to the switch
936 if Ptr <= Max then
937 C := Switch_Chars (Ptr);
939 if C in '1' .. '2' then
940 Ptr := Ptr + 1;
941 Inline_Level := Character'Pos (C) - Character'Pos ('0');
942 end if;
943 end if;
945 -- -gnatN (obsolescent)
947 when 'N' =>
948 Ptr := Ptr + 1;
949 Inline_Active := True;
950 Front_End_Inlining := True;
952 -- -gnato (overflow checks)
954 when 'o' =>
955 Ptr := Ptr + 1;
957 -- Case of -gnato0 (overflow checking turned off)
959 if Ptr <= Max and then Switch_Chars (Ptr) = '0' then
960 Ptr := Ptr + 1;
961 Suppress_Options.Suppress (Overflow_Check) := True;
963 -- We set strict mode in case overflow checking is turned
964 -- on locally (also records that we had a -gnato switch).
966 Suppress_Options.Overflow_Mode_General := Strict;
967 Suppress_Options.Overflow_Mode_Assertions := Strict;
969 -- All cases other than -gnato0 (overflow checking turned on)
971 else
972 Suppress_Options.Suppress (Overflow_Check) := False;
974 -- Case of no digits after the -gnato
976 if Ptr > Max
977 or else Switch_Chars (Ptr) not in '1' .. '3'
978 then
979 Suppress_Options.Overflow_Mode_General := Strict;
980 Suppress_Options.Overflow_Mode_Assertions := Strict;
982 -- At least one digit after the -gnato
984 else
985 -- Handle first digit after -gnato
987 Suppress_Options.Overflow_Mode_General :=
988 Get_Overflow_Mode (Switch_Chars (Ptr));
989 Ptr := Ptr + 1;
991 -- Only one digit after -gnato, set assertions mode to be
992 -- the same as general mode.
994 if Ptr > Max
995 or else Switch_Chars (Ptr) not in '1' .. '3'
996 then
997 Suppress_Options.Overflow_Mode_Assertions :=
998 Suppress_Options.Overflow_Mode_General;
1000 -- Process second digit after -gnato
1002 else
1003 Suppress_Options.Overflow_Mode_Assertions :=
1004 Get_Overflow_Mode (Switch_Chars (Ptr));
1005 Ptr := Ptr + 1;
1006 end if;
1007 end if;
1008 end if;
1010 -- -gnatO (specify name of the object file)
1012 -- This is an internal switch
1014 when 'O' =>
1015 Store_Switch := False;
1016 Ptr := Ptr + 1;
1017 Output_File_Name_Present := True;
1019 -- -gnatp (suppress all checks)
1021 when 'p' =>
1022 Ptr := Ptr + 1;
1024 -- Skip processing if cancelled by subsequent -gnat-p
1026 if Switch_Subsequently_Cancelled ("p", Args, Arg_Rank) then
1027 Store_Switch := False;
1029 else
1030 -- Set all specific options as well as All_Checks in the
1031 -- Suppress_Options array, excluding Elaboration_Check,
1032 -- since this is treated specially because we do not want
1033 -- -gnatp to disable static elaboration processing. Also
1034 -- exclude Atomic_Synchronization, since this is not a real
1035 -- check.
1037 for J in Suppress_Options.Suppress'Range loop
1038 if J /= Elaboration_Check
1039 and then
1040 J /= Atomic_Synchronization
1041 then
1042 Suppress_Options.Suppress (J) := True;
1043 end if;
1044 end loop;
1046 Validity_Checks_On := False;
1047 Opt.Suppress_Checks := True;
1049 -- Set overflow mode checking to strict in case it gets
1050 -- turned on locally (also signals that overflow checking
1051 -- has been specifically turned off).
1053 Suppress_Options.Overflow_Mode_General := Strict;
1054 Suppress_Options.Overflow_Mode_Assertions := Strict;
1055 end if;
1057 -- -gnatP (periodic poll)
1059 when 'P' =>
1060 Ptr := Ptr + 1;
1061 Polling_Required := True;
1063 -- -gnatq (don't quit)
1065 when 'q' =>
1066 Ptr := Ptr + 1;
1067 Try_Semantics := True;
1069 -- -gnatQ (always write ALI file)
1071 when 'Q' =>
1072 Ptr := Ptr + 1;
1073 Force_ALI_Tree_File := True;
1074 Try_Semantics := True;
1076 -- -gnatr (restrictions as warnings)
1078 when 'r' =>
1079 Ptr := Ptr + 1;
1080 Treat_Restrictions_As_Warnings := True;
1082 -- -gnatR (list rep. info)
1084 when 'R' =>
1086 -- Not allowed if previous -gnatD given. See more extensive
1087 -- comments in the 'D' section for the inverse test.
1089 if Debug_Generated_Code then
1090 Osint.Fail
1091 ("-gnatR not permitted since -gnatD given previously");
1092 end if;
1094 -- Set to annotate rep info, and set default -gnatR mode
1096 Back_Annotate_Rep_Info := True;
1097 List_Representation_Info := 1;
1099 -- Scan possible parameter
1101 Ptr := Ptr + 1;
1102 while Ptr <= Max loop
1103 C := Switch_Chars (Ptr);
1105 if C in '1' .. '3' then
1106 List_Representation_Info :=
1107 Character'Pos (C) - Character'Pos ('0');
1109 elsif Switch_Chars (Ptr) = 's' then
1110 List_Representation_Info_To_File := True;
1112 elsif Switch_Chars (Ptr) = 'm' then
1113 List_Representation_Info_Mechanisms := True;
1115 else
1116 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
1117 end if;
1119 Ptr := Ptr + 1;
1120 end loop;
1122 -- -gnats (syntax check only)
1124 when 's' =>
1125 if not First_Switch then
1126 Osint.Fail
1127 ("-gnats must be first if combined with other switches");
1128 end if;
1130 Ptr := Ptr + 1;
1131 Operating_Mode := Check_Syntax;
1133 -- -gnatS (print package Standard)
1135 when 'S' =>
1136 Print_Standard := True;
1137 Ptr := Ptr + 1;
1139 -- -gnatt (output tree)
1141 when 't' =>
1142 Ptr := Ptr + 1;
1143 Tree_Output := True;
1144 Back_Annotate_Rep_Info := True;
1146 -- -gnatT (change start of internal table sizes)
1148 when 'T' =>
1149 Ptr := Ptr + 1;
1150 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
1152 -- -gnatu (list units for compilation)
1154 when 'u' =>
1155 Ptr := Ptr + 1;
1156 List_Units := True;
1158 -- -gnatU (unique tags)
1160 when 'U' =>
1161 Ptr := Ptr + 1;
1162 Unique_Error_Tag := True;
1164 -- -gnatv (verbose mode)
1166 when 'v' =>
1167 Ptr := Ptr + 1;
1168 Verbose_Mode := True;
1170 -- -gnatV (validity checks)
1172 when 'V' =>
1173 Store_Switch := False;
1174 Ptr := Ptr + 1;
1176 if Ptr > Max then
1177 Bad_Switch ("-gnatV");
1179 else
1180 declare
1181 OK : Boolean;
1183 begin
1184 Set_Validity_Check_Options
1185 (Switch_Chars (Ptr .. Max), OK, Ptr);
1187 if not OK then
1188 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
1189 end if;
1191 for Index in First_Char + 1 .. Max loop
1192 Store_Compilation_Switch
1193 ("-gnatV" & Switch_Chars (Index));
1194 end loop;
1195 end;
1196 end if;
1198 Ptr := Max + 1;
1200 -- -gnatw (warning modes)
1202 when 'w' =>
1203 Store_Switch := False;
1204 Ptr := Ptr + 1;
1206 if Ptr > Max then
1207 Bad_Switch ("-gnatw");
1208 end if;
1210 while Ptr <= Max loop
1211 C := Switch_Chars (Ptr);
1213 -- Case of dot switch
1215 if C = '.' and then Ptr < Max then
1216 Ptr := Ptr + 1;
1217 C := Switch_Chars (Ptr);
1219 if Set_Dot_Warning_Switch (C) then
1220 Store_Compilation_Switch ("-gnatw." & C);
1221 else
1222 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
1223 end if;
1225 -- Normal case, no dot
1227 else
1228 if Set_Warning_Switch (C) then
1229 Store_Compilation_Switch ("-gnatw" & C);
1230 else
1231 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
1232 end if;
1233 end if;
1235 Ptr := Ptr + 1;
1236 end loop;
1238 return;
1240 -- -gnatW (wide character encoding method)
1242 when 'W' =>
1243 Ptr := Ptr + 1;
1245 if Ptr > Max then
1246 Bad_Switch ("-gnatW");
1247 end if;
1249 begin
1250 Wide_Character_Encoding_Method :=
1251 Get_WC_Encoding_Method (Switch_Chars (Ptr));
1252 exception
1253 when Constraint_Error =>
1254 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
1255 end;
1257 Wide_Character_Encoding_Method_Specified := True;
1259 Upper_Half_Encoding :=
1260 Wide_Character_Encoding_Method in
1261 WC_Upper_Half_Encoding_Method;
1263 Ptr := Ptr + 1;
1265 -- -gnatx (suppress cross-ref information)
1267 when 'x' =>
1268 Ptr := Ptr + 1;
1269 Xref_Active := False;
1271 -- -gnatX (language extensions)
1273 when 'X' =>
1274 Ptr := Ptr + 1;
1275 Extensions_Allowed := True;
1276 Ada_Version := Ada_Version_Type'Last;
1277 Ada_Version_Explicit := Ada_Version_Type'Last;
1278 Ada_Version_Pragma := Empty;
1280 -- -gnaty (style checks)
1282 when 'y' =>
1283 Ptr := Ptr + 1;
1284 Style_Check_Main := True;
1286 if Ptr > Max then
1287 Set_Default_Style_Check_Options;
1289 else
1290 Store_Switch := False;
1292 declare
1293 OK : Boolean;
1295 begin
1296 Set_Style_Check_Options
1297 (Switch_Chars (Ptr .. Max), OK, Ptr);
1299 if not OK then
1300 Osint.Fail
1301 ("bad -gnaty switch (" &
1302 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
1303 end if;
1305 Ptr := First_Char + 1;
1306 while Ptr <= Max loop
1307 if Switch_Chars (Ptr) = 'M' then
1308 First_Char := Ptr;
1309 loop
1310 Ptr := Ptr + 1;
1311 exit when Ptr > Max
1312 or else Switch_Chars (Ptr) not in '0' .. '9';
1313 end loop;
1315 Store_Compilation_Switch
1316 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
1318 else
1319 Store_Compilation_Switch
1320 ("-gnaty" & Switch_Chars (Ptr));
1321 Ptr := Ptr + 1;
1322 end if;
1323 end loop;
1324 end;
1325 end if;
1327 -- -gnatz (stub generation)
1329 when 'z' =>
1331 -- -gnatz must be the first and only switch in Switch_Chars,
1332 -- and is a two-letter switch.
1334 if Ptr /= Switch_Chars'First + 5
1335 or else (Max - Ptr + 1) > 2
1336 then
1337 Osint.Fail
1338 ("-gnatz* may not be combined with other switches");
1339 end if;
1341 if Ptr = Max then
1342 Bad_Switch ("-gnatz");
1343 end if;
1345 Ptr := Ptr + 1;
1347 -- Only one occurrence of -gnat* is permitted
1349 if Distribution_Stub_Mode = No_Stubs then
1350 case Switch_Chars (Ptr) is
1351 when 'r' =>
1352 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1354 when 'c' =>
1355 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1357 when others =>
1358 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
1359 end case;
1361 Ptr := Ptr + 1;
1363 else
1364 Osint.Fail ("only one -gnatz* switch allowed");
1365 end if;
1367 -- -gnatZ (obsolescent)
1369 when 'Z' =>
1370 Ptr := Ptr + 1;
1371 Osint.Fail
1372 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1374 -- Note on language version switches: whenever a new language
1375 -- version switch is added, Switch.M.Normalize_Compiler_Switches
1376 -- must be updated.
1378 -- -gnat83
1380 when '8' =>
1381 if Ptr = Max then
1382 Bad_Switch ("-gnat8");
1383 end if;
1385 Ptr := Ptr + 1;
1387 if Switch_Chars (Ptr) /= '3' then
1388 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
1389 else
1390 Ptr := Ptr + 1;
1391 Ada_Version := Ada_83;
1392 Ada_Version_Explicit := Ada_83;
1393 Ada_Version_Pragma := Empty;
1394 end if;
1396 -- -gnat95
1398 when '9' =>
1399 if Ptr = Max then
1400 Bad_Switch ("-gnat9");
1401 end if;
1403 Ptr := Ptr + 1;
1405 if Switch_Chars (Ptr) /= '5' then
1406 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
1407 else
1408 Ptr := Ptr + 1;
1409 Ada_Version := Ada_95;
1410 Ada_Version_Explicit := Ada_95;
1411 Ada_Version_Pragma := Empty;
1412 end if;
1414 -- -gnat05
1416 when '0' =>
1417 if Ptr = Max then
1418 Bad_Switch ("-gnat0");
1419 end if;
1421 Ptr := Ptr + 1;
1423 if Switch_Chars (Ptr) /= '5' then
1424 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1425 else
1426 Ptr := Ptr + 1;
1427 Ada_Version := Ada_2005;
1428 Ada_Version_Explicit := Ada_2005;
1429 Ada_Version_Pragma := Empty;
1430 end if;
1432 -- -gnat12
1434 when '1' =>
1435 if Ptr = Max then
1436 Bad_Switch ("-gnat1");
1437 end if;
1439 Ptr := Ptr + 1;
1441 if Switch_Chars (Ptr) /= '2' then
1442 Bad_Switch ("-gnat1" & Switch_Chars (Ptr .. Max));
1443 else
1444 Ptr := Ptr + 1;
1445 Ada_Version := Ada_2012;
1446 Ada_Version_Explicit := Ada_2012;
1447 Ada_Version_Pragma := Empty;
1448 end if;
1450 -- -gnat2005 and -gnat2012
1452 when '2' =>
1453 if Ptr > Max - 3 then
1454 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1456 elsif Switch_Chars (Ptr .. Ptr + 3) = "2005" then
1457 Ada_Version := Ada_2005;
1459 elsif Switch_Chars (Ptr .. Ptr + 3) = "2012" then
1460 Ada_Version := Ada_2012;
1462 else
1463 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Ptr + 3));
1464 end if;
1466 Ada_Version_Explicit := Ada_Version;
1467 Ada_Version_Pragma := Empty;
1468 Ptr := Ptr + 4;
1470 -- Switch cancellation, currently only -gnat-p is allowed.
1471 -- All we do here is the error checking, since the actual
1472 -- processing for switch cancellation is done by calls to
1473 -- Switch_Subsequently_Cancelled at the appropriate point.
1475 when '-' =>
1477 -- Simple ignore -gnat-p
1479 if Switch_Chars = "-gnat-p" then
1480 return;
1482 -- Any other occurrence of minus is ignored. This is for
1483 -- maximum compatibility with previous version which ignored
1484 -- all occurrences of minus.
1486 else
1487 Store_Switch := False;
1488 Ptr := Ptr + 1;
1489 end if;
1491 -- We ignore '/' in switches, this is historical, still needed???
1493 when '/' =>
1494 Store_Switch := False;
1496 -- Anything else is an error (illegal switch character)
1498 when others =>
1499 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1500 end case;
1502 if Store_Switch then
1503 Store_Compilation_Switch
1504 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1505 end if;
1507 First_Switch := False;
1508 end loop;
1509 end if;
1510 end Scan_Front_End_Switches;
1512 -----------------------------------
1513 -- Switch_Subsequently_Cancelled --
1514 -----------------------------------
1516 function Switch_Subsequently_Cancelled
1517 (C : String;
1518 Args : String_List;
1519 Arg_Rank : Positive) return Boolean
1521 begin
1522 -- Loop through arguments following the current one
1524 for Arg in Arg_Rank + 1 .. Args'Last loop
1525 if Args (Arg).all = "-gnat-" & C then
1526 return True;
1527 end if;
1528 end loop;
1530 -- No match found, not cancelled
1532 return False;
1533 end Switch_Subsequently_Cancelled;
1535 end Switch.C;