Daily bump.
[official-gcc.git] / gcc / ada / switch-c.adb
blob96416a5e546d6b0535fe14acf2b72e4ac7ee9937
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 -- Scan optional integer line limit value
399 if Nat_Present (Switch_Chars, Max, Ptr) then
400 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'D');
401 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
402 end if;
404 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
405 -- generation in the ali file) since otherwise this generation
406 -- gets confused by the "wrong" Sloc values put in the tree.
408 Debug_Generated_Code := True;
409 Xref_Active := False;
410 Set_Debug_Flag ('g');
412 -- -gnate? (extended switches)
414 when 'e' =>
415 Ptr := Ptr + 1;
417 -- The -gnate? switches are all double character switches
418 -- so we must always have a character after the e.
420 if Ptr > Max then
421 Bad_Switch ("-gnate");
422 end if;
424 case Switch_Chars (Ptr) is
426 -- -gnatea (initial delimiter of explicit switches)
428 -- This is an internal switch
430 -- All switches that come before -gnatea have been added by
431 -- the GCC driver and are not stored in the ALI file.
432 -- See also -gnatez below.
434 when 'a' =>
435 Store_Switch := False;
436 Enable_Switch_Storing;
437 Ptr := Ptr + 1;
439 -- -gnateA (aliasing checks on parameters)
441 when 'A' =>
442 Ptr := Ptr + 1;
443 Check_Aliasing_Of_Parameters := True;
445 -- -gnatec (configuration pragmas)
447 when 'c' =>
448 Store_Switch := False;
449 Ptr := Ptr + 1;
451 -- There may be an equal sign between -gnatec and
452 -- the path name of the config file.
454 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
455 Ptr := Ptr + 1;
456 end if;
458 if Ptr > Max then
459 Bad_Switch ("-gnatec");
460 end if;
462 declare
463 Config_File_Name : constant String_Access :=
464 new String'
465 (Switch_Chars (Ptr .. Max));
467 begin
468 if Config_File_Names = null then
469 Config_File_Names :=
470 new String_List'(1 => Config_File_Name);
472 else
473 declare
474 New_Names : constant String_List_Access :=
475 new String_List
476 (1 ..
477 Config_File_Names'Length + 1);
479 begin
480 for Index in Config_File_Names'Range loop
481 New_Names (Index) :=
482 Config_File_Names (Index);
483 Config_File_Names (Index) := null;
484 end loop;
486 New_Names (New_Names'Last) := Config_File_Name;
487 Free (Config_File_Names);
488 Config_File_Names := New_Names;
489 end;
490 end if;
491 end;
493 return;
495 -- -gnateC switch (CodePeer SCIL generation)
497 -- Not enabled for now, keep it for later???
498 -- use -gnatd.I only for now
500 -- when 'C' =>
501 -- Ptr := Ptr + 1;
502 -- Generate_SCIL := True;
504 -- -gnated switch (disable atomic synchronization)
506 when 'd' =>
507 Suppress_Options.Suppress (Atomic_Synchronization) :=
508 True;
510 -- -gnateD switch (preprocessing symbol definition)
512 when 'D' =>
513 Store_Switch := False;
514 Ptr := Ptr + 1;
516 if Ptr > Max then
517 Bad_Switch ("-gnateD");
518 end if;
520 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
522 -- Store the switch
524 Store_Compilation_Switch
525 ("-gnateD" & Switch_Chars (Ptr .. Max));
526 Ptr := Max + 1;
528 -- -gnateE (extra exception information)
530 when 'E' =>
531 Exception_Extra_Info := True;
532 Ptr := Ptr + 1;
534 -- -gnatef (full source path for brief error messages)
536 when 'f' =>
537 Store_Switch := False;
538 Ptr := Ptr + 1;
539 Full_Path_Name_For_Brief_Errors := True;
541 -- -gnateF (Check_Float_Overflow)
543 when 'F' =>
544 Ptr := Ptr + 1;
545 Check_Float_Overflow := True;
547 -- -gnateG (save preprocessor output)
549 when 'G' =>
550 Generate_Processed_File := True;
551 Ptr := Ptr + 1;
553 -- -gnatei (max number of instantiations)
555 when 'i' =>
556 Ptr := Ptr + 1;
557 Scan_Pos
558 (Switch_Chars, Max, Ptr, Maximum_Instantiations, C);
560 -- -gnateI (index of unit in multi-unit source)
562 when 'I' =>
563 Ptr := Ptr + 1;
564 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
566 -- -gnatem (mapping file)
568 when 'm' =>
569 Store_Switch := False;
570 Ptr := Ptr + 1;
572 -- There may be an equal sign between -gnatem and
573 -- the path name of the mapping file.
575 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
576 Ptr := Ptr + 1;
577 end if;
579 if Ptr > Max then
580 Bad_Switch ("-gnatem");
581 end if;
583 Mapping_File_Name :=
584 new String'(Switch_Chars (Ptr .. Max));
585 return;
587 -- -gnateO= (object path file)
589 -- This is an internal switch
591 when 'O' =>
592 Store_Switch := False;
593 Ptr := Ptr + 1;
595 -- Check for '='
597 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
598 Bad_Switch ("-gnateO");
599 else
600 Object_Path_File_Name :=
601 new String'(Switch_Chars (Ptr + 1 .. Max));
602 end if;
604 return;
606 -- -gnatep (preprocessing data file)
608 when 'p' =>
609 Store_Switch := False;
610 Ptr := Ptr + 1;
612 -- There may be an equal sign between -gnatep and
613 -- the path name of the mapping file.
615 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
616 Ptr := Ptr + 1;
617 end if;
619 if Ptr > Max then
620 Bad_Switch ("-gnatep");
621 end if;
623 Preprocessing_Data_File :=
624 new String'(Switch_Chars (Ptr .. Max));
626 -- Store the switch, normalizing to -gnatep=
628 Store_Compilation_Switch
629 ("-gnatep=" & Preprocessing_Data_File.all);
631 Ptr := Max + 1;
633 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
635 when 'P' =>
636 Treat_Categorization_Errors_As_Warnings := True;
638 -- -gnateS (generate SCO information)
640 -- Include Source Coverage Obligation information in ALI
641 -- files for the benefit of source coverage analysis tools
642 -- (xcov).
644 when 'S' =>
645 Generate_SCO := True;
646 Generate_SCO_Instance_Table := True;
647 Ptr := Ptr + 1;
649 -- -gnatet (write target dependent information)
651 when 't' =>
652 if not First_Switch then
653 Osint.Fail
654 ("-gnatet must not be combined with other switches");
655 end if;
657 -- Check for '='
659 Ptr := Ptr + 1;
661 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
662 Bad_Switch ("-gnatet");
663 else
664 Target_Dependent_Info_Write_Name :=
665 new String'(Switch_Chars (Ptr + 1 .. Max));
666 end if;
668 return;
670 -- -gnateT (read target dependent information)
672 when 'T' =>
673 if not First_Switch then
674 Osint.Fail
675 ("-gnateT must not be combined with other switches");
676 end if;
678 -- Check for '='
680 Ptr := Ptr + 1;
682 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
683 Bad_Switch ("-gnateT");
684 else
685 -- This parameter was stored by Set_Targ earlier
687 pragma Assert
688 (Target_Dependent_Info_Read_Name.all =
689 Switch_Chars (Ptr + 1 .. Max));
690 null;
691 end if;
693 return;
695 -- -gnateV (validity checks on parameters)
697 when 'V' =>
698 Ptr := Ptr + 1;
699 Check_Validity_Of_Parameters := True;
701 -- -gnateY (ignore Style_Checks pragmas)
703 when 'Y' =>
704 Ignore_Style_Checks_Pragmas := True;
705 Ptr := Ptr + 1;
707 -- -gnatez (final delimiter of explicit switches)
709 -- This is an internal switch
711 -- All switches that come after -gnatez have been added by
712 -- the GCC driver and are not stored in the ALI file. See
713 -- also -gnatea above.
715 when 'z' =>
716 Store_Switch := False;
717 Disable_Switch_Storing;
718 Ptr := Ptr + 1;
720 -- All other -gnate? switches are unassigned
722 when others =>
723 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
724 end case;
726 -- -gnatE (dynamic elaboration checks)
728 when 'E' =>
729 Ptr := Ptr + 1;
730 Dynamic_Elaboration_Checks := True;
732 -- -gnatf (full error messages)
734 when 'f' =>
735 Ptr := Ptr + 1;
736 All_Errors_Mode := True;
738 -- -gnatF (overflow of predefined float types)
740 when 'F' =>
741 Ptr := Ptr + 1;
742 External_Name_Exp_Casing := Uppercase;
743 External_Name_Imp_Casing := Uppercase;
745 -- -gnatg (GNAT implementation mode)
747 when 'g' =>
748 Ptr := Ptr + 1;
749 GNAT_Mode := True;
750 Identifier_Character_Set := 'n';
751 System_Extend_Unit := Empty;
752 Warning_Mode := Treat_As_Error;
753 Style_Check_Main := True;
755 -- Set Ada 2012 mode explicitly. We don't want to rely on the
756 -- implicit setting here, since for example, we want
757 -- Preelaborate_05 treated as Preelaborate
759 Ada_Version := Ada_2012;
760 Ada_Version_Explicit := Ada_Version;
762 -- Set default warnings and style checks for -gnatg
764 Set_GNAT_Mode_Warnings;
765 Set_GNAT_Style_Check_Options;
767 -- -gnatG (output generated code)
769 when 'G' =>
770 Ptr := Ptr + 1;
771 Print_Generated_Code := True;
773 -- Scan optional integer line limit value
775 if Nat_Present (Switch_Chars, Max, Ptr) then
776 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
777 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
778 end if;
780 -- -gnath (help information)
782 when 'h' =>
783 Ptr := Ptr + 1;
784 Usage_Requested := True;
786 -- -gnati (character set)
788 when 'i' =>
789 if Ptr = Max then
790 Bad_Switch ("-gnati");
791 end if;
793 Ptr := Ptr + 1;
794 C := Switch_Chars (Ptr);
796 if C in '1' .. '5'
797 or else C = '8'
798 or else C = '9'
799 or else C = 'p'
800 or else C = 'f'
801 or else C = 'n'
802 or else C = 'w'
803 then
804 Identifier_Character_Set := C;
805 Ptr := Ptr + 1;
807 else
808 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
809 end if;
811 -- -gnatI (ignore representation clauses)
813 when 'I' =>
814 Ptr := Ptr + 1;
815 Ignore_Rep_Clauses := True;
817 -- -gnatj (messages in limited length lines)
819 when 'j' =>
820 Ptr := Ptr + 1;
821 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
823 -- -gnatk (limit file name length)
825 when 'k' =>
826 Ptr := Ptr + 1;
827 Scan_Pos
828 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
830 -- -gnatl (output full source)
832 when 'l' =>
833 Ptr := Ptr + 1;
834 Full_List := True;
836 -- There may be an equal sign between -gnatl and a file name
838 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
839 if Ptr = Max then
840 Osint.Fail ("file name for -gnatl= is null");
841 else
842 Opt.Full_List_File_Name :=
843 new String'(Switch_Chars (Ptr + 1 .. Max));
844 Ptr := Max + 1;
845 end if;
846 end if;
848 -- -gnatL (corresponding source text)
850 when 'L' =>
851 Ptr := Ptr + 1;
852 Dump_Source_Text := True;
854 -- -gnatm (max number or errors/warnings)
856 when 'm' =>
857 Ptr := Ptr + 1;
858 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Messages, C);
860 -- -gnatn (enable pragma Inline)
862 when 'n' =>
863 Ptr := Ptr + 1;
864 Inline_Active := True;
866 -- There may be a digit (1 or 2) appended to the switch
868 if Ptr <= Max then
869 C := Switch_Chars (Ptr);
871 if C in '1' .. '2' then
872 Ptr := Ptr + 1;
873 Inline_Level := Character'Pos (C) - Character'Pos ('0');
874 end if;
875 end if;
877 -- -gnatN (obsolescent)
879 when 'N' =>
880 Ptr := Ptr + 1;
881 Inline_Active := True;
882 Front_End_Inlining := True;
884 -- -gnato (overflow checks)
886 when 'o' =>
887 Ptr := Ptr + 1;
888 Suppress_Options.Suppress (Overflow_Check) := False;
890 -- Case of no digits after the -gnato
892 if Ptr > Max or else Switch_Chars (Ptr) not in '1' .. '3' then
893 Suppress_Options.Overflow_Mode_General := Strict;
894 Suppress_Options.Overflow_Mode_Assertions := Strict;
896 -- At least one digit after the -gnato
898 else
899 -- Handle first digit after -gnato
901 Suppress_Options.Overflow_Mode_General :=
902 Get_Overflow_Mode (Switch_Chars (Ptr));
903 Ptr := Ptr + 1;
905 -- Only one digit after -gnato, set assertions mode to
906 -- be the same as general mode.
908 if Ptr > Max
909 or else Switch_Chars (Ptr) not in '1' .. '3'
910 then
911 Suppress_Options.Overflow_Mode_Assertions :=
912 Suppress_Options.Overflow_Mode_General;
914 -- Process second digit after -gnato
916 else
917 Suppress_Options.Overflow_Mode_Assertions :=
918 Get_Overflow_Mode (Switch_Chars (Ptr));
919 Ptr := Ptr + 1;
920 end if;
921 end if;
923 -- -gnatO (specify name of the object file)
925 -- This is an internal switch
927 when 'O' =>
928 Store_Switch := False;
929 Ptr := Ptr + 1;
930 Output_File_Name_Present := True;
932 -- -gnatp (suppress all checks)
934 when 'p' =>
935 Ptr := Ptr + 1;
937 -- Skip processing if cancelled by subsequent -gnat-p
939 if Switch_Subsequently_Cancelled ("p", Args, Arg_Rank) then
940 Store_Switch := False;
942 else
943 -- Set all specific options as well as All_Checks in the
944 -- Suppress_Options array, excluding Elaboration_Check,
945 -- since this is treated specially because we do not want
946 -- -gnatp to disable static elaboration processing. Also
947 -- exclude Atomic_Synchronization, since this is not a real
948 -- check.
950 for J in Suppress_Options.Suppress'Range loop
951 if J /= Elaboration_Check
952 and then
953 J /= Atomic_Synchronization
954 then
955 Suppress_Options.Suppress (J) := True;
956 end if;
957 end loop;
959 Validity_Checks_On := False;
960 Opt.Suppress_Checks := True;
961 end if;
963 -- -gnatP (periodic poll)
965 when 'P' =>
966 Ptr := Ptr + 1;
967 Polling_Required := True;
969 -- -gnatq (don't quit)
971 when 'q' =>
972 Ptr := Ptr + 1;
973 Try_Semantics := True;
975 -- -gnatQ (always write ALI file)
977 when 'Q' =>
978 Ptr := Ptr + 1;
979 Force_ALI_Tree_File := True;
980 Try_Semantics := True;
982 -- -gnatr (restrictions as warnings)
984 when 'r' =>
985 Ptr := Ptr + 1;
986 Treat_Restrictions_As_Warnings := True;
988 -- -gnatR (list rep. info)
990 when 'R' =>
991 Back_Annotate_Rep_Info := True;
992 List_Representation_Info := 1;
994 Ptr := Ptr + 1;
995 while Ptr <= Max loop
996 C := Switch_Chars (Ptr);
998 if C in '1' .. '3' then
999 List_Representation_Info :=
1000 Character'Pos (C) - Character'Pos ('0');
1002 elsif Switch_Chars (Ptr) = 's' then
1003 List_Representation_Info_To_File := True;
1005 elsif Switch_Chars (Ptr) = 'm' then
1006 List_Representation_Info_Mechanisms := True;
1008 else
1009 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
1010 end if;
1012 Ptr := Ptr + 1;
1013 end loop;
1015 -- -gnats (syntax check only)
1017 when 's' =>
1018 if not First_Switch then
1019 Osint.Fail
1020 ("-gnats must be first if combined with other switches");
1021 end if;
1023 Ptr := Ptr + 1;
1024 Operating_Mode := Check_Syntax;
1026 -- -gnatS (print package Standard)
1028 when 'S' =>
1029 Print_Standard := True;
1030 Ptr := Ptr + 1;
1032 -- -gnatt (output tree)
1034 when 't' =>
1035 Ptr := Ptr + 1;
1036 Tree_Output := True;
1037 Back_Annotate_Rep_Info := True;
1039 -- -gnatT (change start of internal table sizes)
1041 when 'T' =>
1042 Ptr := Ptr + 1;
1043 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
1045 -- -gnatu (list units for compilation)
1047 when 'u' =>
1048 Ptr := Ptr + 1;
1049 List_Units := True;
1051 -- -gnatU (unique tags)
1053 when 'U' =>
1054 Ptr := Ptr + 1;
1055 Unique_Error_Tag := True;
1057 -- -gnatv (verbose mode)
1059 when 'v' =>
1060 Ptr := Ptr + 1;
1061 Verbose_Mode := True;
1063 -- -gnatV (validity checks)
1065 when 'V' =>
1066 Store_Switch := False;
1067 Ptr := Ptr + 1;
1069 if Ptr > Max then
1070 Bad_Switch ("-gnatV");
1072 else
1073 declare
1074 OK : Boolean;
1076 begin
1077 Set_Validity_Check_Options
1078 (Switch_Chars (Ptr .. Max), OK, Ptr);
1080 if not OK then
1081 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
1082 end if;
1084 for Index in First_Char + 1 .. Max loop
1085 Store_Compilation_Switch
1086 ("-gnatV" & Switch_Chars (Index));
1087 end loop;
1088 end;
1089 end if;
1091 Ptr := Max + 1;
1093 -- -gnatw (warning modes)
1095 when 'w' =>
1096 Store_Switch := False;
1097 Ptr := Ptr + 1;
1099 if Ptr > Max then
1100 Bad_Switch ("-gnatw");
1101 end if;
1103 while Ptr <= Max loop
1104 C := Switch_Chars (Ptr);
1106 -- Case of dot switch
1108 if C = '.' and then Ptr < Max then
1109 Ptr := Ptr + 1;
1110 C := Switch_Chars (Ptr);
1112 if Set_Dot_Warning_Switch (C) then
1113 Store_Compilation_Switch ("-gnatw." & C);
1114 else
1115 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
1116 end if;
1118 -- Normal case, no dot
1120 else
1121 if Set_Warning_Switch (C) then
1122 Store_Compilation_Switch ("-gnatw" & C);
1123 else
1124 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
1125 end if;
1126 end if;
1128 Ptr := Ptr + 1;
1129 end loop;
1131 return;
1133 -- -gnatW (wide character encoding method)
1135 when 'W' =>
1136 Ptr := Ptr + 1;
1138 if Ptr > Max then
1139 Bad_Switch ("-gnatW");
1140 end if;
1142 begin
1143 Wide_Character_Encoding_Method :=
1144 Get_WC_Encoding_Method (Switch_Chars (Ptr));
1145 exception
1146 when Constraint_Error =>
1147 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
1148 end;
1150 Wide_Character_Encoding_Method_Specified := True;
1152 Upper_Half_Encoding :=
1153 Wide_Character_Encoding_Method in
1154 WC_Upper_Half_Encoding_Method;
1156 Ptr := Ptr + 1;
1158 -- -gnatx (suppress cross-ref information)
1160 when 'x' =>
1161 Ptr := Ptr + 1;
1162 Xref_Active := False;
1164 -- -gnatX (language extensions)
1166 when 'X' =>
1167 Ptr := Ptr + 1;
1168 Extensions_Allowed := True;
1169 Ada_Version := Ada_Version_Type'Last;
1170 Ada_Version_Explicit := Ada_Version_Type'Last;
1172 -- -gnaty (style checks)
1174 when 'y' =>
1175 Ptr := Ptr + 1;
1176 Style_Check_Main := True;
1178 if Ptr > Max then
1179 Set_Default_Style_Check_Options;
1181 else
1182 Store_Switch := False;
1184 declare
1185 OK : Boolean;
1187 begin
1188 Set_Style_Check_Options
1189 (Switch_Chars (Ptr .. Max), OK, Ptr);
1191 if not OK then
1192 Osint.Fail
1193 ("bad -gnaty switch (" &
1194 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
1195 end if;
1197 Ptr := First_Char + 1;
1198 while Ptr <= Max loop
1199 if Switch_Chars (Ptr) = 'M' then
1200 First_Char := Ptr;
1201 loop
1202 Ptr := Ptr + 1;
1203 exit when Ptr > Max
1204 or else Switch_Chars (Ptr) not in '0' .. '9';
1205 end loop;
1207 Store_Compilation_Switch
1208 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
1210 else
1211 Store_Compilation_Switch
1212 ("-gnaty" & Switch_Chars (Ptr));
1213 Ptr := Ptr + 1;
1214 end if;
1215 end loop;
1216 end;
1217 end if;
1219 -- -gnatz (stub generation)
1221 when 'z' =>
1223 -- -gnatz must be the first and only switch in Switch_Chars,
1224 -- and is a two-letter switch.
1226 if Ptr /= Switch_Chars'First + 5
1227 or else (Max - Ptr + 1) > 2
1228 then
1229 Osint.Fail
1230 ("-gnatz* may not be combined with other switches");
1231 end if;
1233 if Ptr = Max then
1234 Bad_Switch ("-gnatz");
1235 end if;
1237 Ptr := Ptr + 1;
1239 -- Only one occurrence of -gnat* is permitted
1241 if Distribution_Stub_Mode = No_Stubs then
1242 case Switch_Chars (Ptr) is
1243 when 'r' =>
1244 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1246 when 'c' =>
1247 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1249 when others =>
1250 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
1251 end case;
1253 Ptr := Ptr + 1;
1255 else
1256 Osint.Fail ("only one -gnatz* switch allowed");
1257 end if;
1259 -- -gnatZ (obsolescent)
1261 when 'Z' =>
1262 Ptr := Ptr + 1;
1263 Osint.Fail
1264 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1266 -- Note on language version switches: whenever a new language
1267 -- version switch is added, Switch.M.Normalize_Compiler_Switches
1268 -- must be updated.
1270 -- -gnat83
1272 when '8' =>
1273 if Ptr = Max then
1274 Bad_Switch ("-gnat8");
1275 end if;
1277 Ptr := Ptr + 1;
1279 if Switch_Chars (Ptr) /= '3' then
1280 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
1281 else
1282 Ptr := Ptr + 1;
1283 Ada_Version := Ada_83;
1284 Ada_Version_Explicit := Ada_Version;
1285 end if;
1287 -- -gnat95
1289 when '9' =>
1290 if Ptr = Max then
1291 Bad_Switch ("-gnat9");
1292 end if;
1294 Ptr := Ptr + 1;
1296 if Switch_Chars (Ptr) /= '5' then
1297 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
1298 else
1299 Ptr := Ptr + 1;
1300 Ada_Version := Ada_95;
1301 Ada_Version_Explicit := Ada_Version;
1302 end if;
1304 -- -gnat05
1306 when '0' =>
1307 if Ptr = Max then
1308 Bad_Switch ("-gnat0");
1309 end if;
1311 Ptr := Ptr + 1;
1313 if Switch_Chars (Ptr) /= '5' then
1314 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1315 else
1316 Ptr := Ptr + 1;
1317 Ada_Version := Ada_2005;
1318 Ada_Version_Explicit := Ada_Version;
1319 end if;
1321 -- -gnat12
1323 when '1' =>
1324 if Ptr = Max then
1325 Bad_Switch ("-gnat1");
1326 end if;
1328 Ptr := Ptr + 1;
1330 if Switch_Chars (Ptr) /= '2' then
1331 Bad_Switch ("-gnat1" & Switch_Chars (Ptr .. Max));
1332 else
1333 Ptr := Ptr + 1;
1334 Ada_Version := Ada_2012;
1335 Ada_Version_Explicit := Ada_Version;
1336 end if;
1338 -- -gnat2005 and -gnat2012
1340 when '2' =>
1341 if Ptr > Max - 3 then
1342 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1344 elsif Switch_Chars (Ptr .. Ptr + 3) = "2005" then
1345 Ada_Version := Ada_2005;
1347 elsif Switch_Chars (Ptr .. Ptr + 3) = "2012" then
1348 Ada_Version := Ada_2012;
1350 else
1351 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Ptr + 3));
1352 end if;
1354 Ada_Version_Explicit := Ada_Version;
1355 Ptr := Ptr + 4;
1357 -- Switch cancellation, currently only -gnat-p is allowed.
1358 -- All we do here is the error checking, since the actual
1359 -- processing for switch cancellation is done by calls to
1360 -- Switch_Subsequently_Cancelled at the appropriate point.
1362 when '-' =>
1364 -- Simple ignore -gnat-p
1366 if Switch_Chars = "-gnat-p" then
1367 return;
1369 -- Any other occurrence of minus is ignored. This is for
1370 -- maximum compatibility with previous version which ignored
1371 -- all occurrences of minus.
1373 else
1374 Store_Switch := False;
1375 Ptr := Ptr + 1;
1376 end if;
1378 -- We ignore '/' in switches, this is historical, still needed???
1380 when '/' =>
1381 Store_Switch := False;
1383 -- Anything else is an error (illegal switch character)
1385 when others =>
1386 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1387 end case;
1389 if Store_Switch then
1390 Store_Compilation_Switch
1391 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1392 end if;
1394 First_Switch := False;
1395 end loop;
1396 end if;
1397 end Scan_Front_End_Switches;
1399 -----------------------------------
1400 -- Switch_Subsequently_Cancelled --
1401 -----------------------------------
1403 function Switch_Subsequently_Cancelled
1404 (C : String;
1405 Args : String_List;
1406 Arg_Rank : Positive) return Boolean
1408 begin
1409 -- Loop through arguments following the current one
1411 for Arg in Arg_Rank + 1 .. Args'Last loop
1412 if Args (Arg).all = "-gnat-" & C then
1413 return True;
1414 end if;
1415 end loop;
1417 -- No match found, not cancelled
1419 return False;
1420 end Switch_Subsequently_Cancelled;
1422 end Switch.C;