1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2009, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Debug; use Debug;
28 with Osint; use Osint;
30 with Prepcomp; use Prepcomp;
31 with Validsw; use Validsw;
32 with Sem_Warn; use Sem_Warn;
33 with Stylesw; use Stylesw;
35 with System.OS_Lib; use System.OS_Lib;
37 with System.WCh_Con; use System.WCh_Con;
39 package body Switch.C is
41 RTS_Specified : String_Access := null;
42 -- Used to detect multiple use of --RTS= flag
44 -----------------------------
45 -- Scan_Front_End_Switches --
46 -----------------------------
48 procedure Scan_Front_End_Switches (Switch_Chars : String) is
49 First_Switch : Boolean := True;
50 -- False for all but first switch
52 Max : constant Natural := Switch_Chars'Last;
57 Store_Switch : Boolean;
58 -- For -gnatxx switches, the normal processing, signalled by this flag
59 -- being set to True, is to store the switch on exit from the case
60 -- statement, the switch stored is -gnat followed by the characters
61 -- from First_Char to Ptr-1. For cases like -gnaty, where the switch
62 -- is stored in separate pieces, this flag is set to False, and the
63 -- appropriate calls to Store_Compilation_Switch are made from within
66 First_Char : Positive;
67 -- Marks start of switch to be stored
70 Ptr := Switch_Chars'First;
72 -- Skip past the initial character (must be the switch character)
80 -- Handle switches that do not start with -gnat
83 or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat"
85 -- There are two front-end switches that do not start with -gnat:
88 if Switch_Chars (Ptr) = 'I' then
90 -- Set flag Search_Directory_Present if switch is "-I" only:
91 -- the directory will be the next argument.
94 Search_Directory_Present := True;
100 -- Find out whether this is a -I- or regular -Ixxx switch
102 -- Note: -I switches are not recorded in the ALI file, since the
103 -- meaning of the program depends on the source files compiled,
104 -- not where they came from.
106 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
107 Look_In_Primary_Dir := False;
109 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
112 -- Processing of the --RTS switch. --RTS may have been modified by
113 -- gcc into -fRTS (for GCC targets).
116 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
118 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
123 or else Switch_Chars (Ptr + 3) /= '='
125 Osint.Fail ("missing path for --RTS");
127 -- Check that this is the first time --RTS is specified or if
128 -- it is not the first time, the same path has been specified.
130 if RTS_Specified = null then
131 RTS_Specified := new String'(Switch_Chars (Ptr + 4 .. Max));
134 RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
136 Osint.Fail ("--RTS cannot be specified multiple times");
139 -- Valid --RTS switch
141 Opt.No_Stdinc := True;
142 Opt.RTS_Switch := True;
146 (Switch_Chars (Ptr + 4 .. Max), Include);
150 (Switch_Chars (Ptr + 4 .. Max), Objects);
152 if RTS_Src_Path_Name /= null
153 and then RTS_Lib_Path_Name /= null
155 -- Store the -fRTS switch (Note: Store_Compilation_Switch
156 -- changes -fRTS back into --RTS for the actual output).
158 Store_Compilation_Switch (Switch_Chars);
160 elsif RTS_Src_Path_Name = null
161 and then RTS_Lib_Path_Name = null
163 Osint.Fail ("RTS path not valid: missing " &
164 "adainclude and adalib directories");
166 elsif RTS_Src_Path_Name = null then
167 Osint.Fail ("RTS path not valid: missing " &
168 "adainclude directory");
170 elsif RTS_Lib_Path_Name = null then
171 Osint.Fail ("RTS path not valid: missing " &
176 -- There are no other switches not starting with -gnat
179 Bad_Switch (Switch_Chars);
182 -- Case of switch starting with -gnat
187 -- Loop to scan through switches given in switch string
189 while Ptr <= Max loop
191 Store_Switch := True;
193 C := Switch_Chars (Ptr);
199 Assertions_Enabled := True;
200 Debug_Pragmas_Enabled := True;
202 -- Processing for A switch
206 Config_File := False;
208 -- Processing for b switch
212 Brief_Output := True;
214 -- Processing for B switch
218 Assume_No_Invalid_Values := True;
220 -- Processing for c switch
223 if not First_Switch then
225 ("-gnatc must be first if combined with other switches");
229 Operating_Mode := Check_Semantics;
231 -- Processing for C switch
235 CodePeer_Mode := True;
237 -- Processing for d switch
240 Store_Switch := False;
243 -- Note: for the debug switch, the remaining characters in this
244 -- switch field must all be debug flags, since all valid switch
245 -- characters are also valid debug characters.
247 -- Loop to scan out debug flags
251 C := Switch_Chars (Ptr);
252 exit when C = ASCII.NUL or else C = '/' or else C = '-';
254 if C in '1' .. '9' or else
255 C in 'a' .. 'z' or else
259 Set_Dotted_Debug_Flag (C);
260 Store_Compilation_Switch ("-gnatd." & C);
263 Store_Compilation_Switch ("-gnatd" & C);
270 Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
272 Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
278 -- Processing for D switch
283 -- Scan optional integer line limit value
285 if Nat_Present (Switch_Chars, Max, Ptr) then
286 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'D');
287 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
290 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
291 -- generation in the ali file) since otherwise this generation
292 -- gets confused by the "wrong" Sloc values put in the tree.
294 Debug_Generated_Code := True;
295 Xref_Active := False;
296 Set_Debug_Flag ('g');
298 -- -gnate? (extended switches)
303 -- The -gnate? switches are all double character switches
304 -- so we must always have a character after the e.
307 Bad_Switch ("-gnate");
310 case Switch_Chars (Ptr) is
313 Store_Switch := False;
314 Enable_Switch_Storing;
317 -- -gnatec (configuration pragmas)
320 Store_Switch := False;
323 -- There may be an equal sign between -gnatec and
324 -- the path name of the config file.
326 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
331 Bad_Switch ("-gnatec");
335 Config_File_Name : constant String_Access :=
337 (Switch_Chars (Ptr .. Max));
340 if Config_File_Names = null then
342 new String_List'(1 => Config_File_Name);
346 New_Names : constant String_List_Access :=
349 Config_File_Names'Length + 1);
352 for Index in Config_File_Names'Range loop
354 Config_File_Names (Index);
355 Config_File_Names (Index) := null;
358 New_Names (New_Names'Last) := Config_File_Name;
359 Free (Config_File_Names);
360 Config_File_Names := New_Names;
367 -- -gnateC switch (CodePeer SCIL generation)
368 -- Not enabled for now, keep it for later???
369 -- use -gnatd.I only for now
373 -- Generate_SCIL := True;
375 -- -gnateD switch (preprocessing symbol definition)
378 Store_Switch := False;
382 Bad_Switch ("-gnateD");
385 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
389 Store_Compilation_Switch
390 ("-gnateD" & Switch_Chars (Ptr .. Max));
393 -- -gnatef (full source path for brief error messages)
396 Store_Switch := False;
398 Full_Path_Name_For_Brief_Errors := True;
401 -- -gnateG (save preprocessor output)
405 Bad_Switch (Switch_Chars);
408 Generate_Processed_File := True;
411 -- -gnateI (index of unit in multi-unit source)
415 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
417 -- -gnatem (mapping file)
420 Store_Switch := False;
423 -- There may be an equal sign between -gnatem and
424 -- the path name of the mapping file.
426 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
431 Bad_Switch ("-gnatem");
435 new String'(Switch_Chars (Ptr .. Max));
438 -- -gnatep (preprocessing data file)
441 Store_Switch := False;
444 -- There may be an equal sign between -gnatep and
445 -- the path name of the mapping file.
447 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
452 Bad_Switch ("-gnatep");
455 Preprocessing_Data_File :=
456 new String'(Switch_Chars (Ptr .. Max));
458 -- Store the switch, normalizing to -gnatep=
460 Store_Compilation_Switch
461 ("-gnatep=" & Preprocessing_Data_File.all);
466 Store_Switch := False;
467 Disable_Switch_Storing;
470 -- All other -gnate? switches are unassigned
473 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
476 -- -gnatE (dynamic elaboration checks)
480 Dynamic_Elaboration_Checks := True;
482 -- -gnatf (full error messages)
486 All_Errors_Mode := True;
488 -- Processing for F switch
492 External_Name_Exp_Casing := Uppercase;
493 External_Name_Imp_Casing := Uppercase;
495 -- Processing for g switch
500 Identifier_Character_Set := 'n';
501 System_Extend_Unit := Empty;
502 Warning_Mode := Treat_As_Error;
504 -- Set Ada 2005 mode explicitly. We don't want to rely on the
505 -- implicit setting here, since for example, we want
506 -- Preelaborate_05 treated as Preelaborate
508 Ada_Version := Ada_05;
509 Ada_Version_Explicit := Ada_Version;
511 -- Set default warnings and style checks for -gnatg
513 Set_GNAT_Mode_Warnings;
514 Set_GNAT_Style_Check_Options;
516 -- Processing for G switch
520 Print_Generated_Code := True;
522 -- Scan optional integer line limit value
524 if Nat_Present (Switch_Chars, Max, Ptr) then
525 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
526 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
529 -- Processing for h switch
533 Usage_Requested := True;
535 -- Processing for H switch
541 -- Processing for i switch
545 Bad_Switch ("-gnati");
549 C := Switch_Chars (Ptr);
559 Identifier_Character_Set := C;
563 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
566 -- Processing for I switch
570 Ignore_Rep_Clauses := True;
572 -- Processing for j switch
576 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
578 -- Processing for k switch
583 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
585 -- Processing for l switch
591 -- There may be an equal sign between -gnatl and a file name
593 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
595 Osint.Fail ("file name for -gnatl= is null");
597 Opt.Full_List_File_Name :=
598 new String'(Switch_Chars (Ptr + 1 .. Max));
603 -- Processing for L switch
607 Dump_Source_Text := True;
609 -- Processing for m switch
613 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Messages, C);
615 -- Processing for n switch
619 Inline_Active := True;
621 -- Processing for N switch
625 Inline_Active := True;
626 Front_End_Inlining := True;
628 -- Processing for o switch
632 Suppress_Options (Overflow_Check) := False;
633 Opt.Enable_Overflow_Checks := True;
635 -- Processing for O switch
638 Store_Switch := False;
640 Output_File_Name_Present := True;
642 -- Processing for p switch
647 -- Set all specific options as well as All_Checks in the
648 -- Suppress_Options array, excluding Elaboration_Check, since
649 -- this is treated specially because we do not want -gnatp to
650 -- disable static elaboration processing.
652 for J in Suppress_Options'Range loop
653 if J /= Elaboration_Check then
654 Suppress_Options (J) := True;
658 Validity_Checks_On := False;
659 Opt.Suppress_Checks := True;
660 Opt.Enable_Overflow_Checks := False;
662 -- Processing for P switch
666 Polling_Required := True;
668 -- Processing for q switch
672 Try_Semantics := True;
674 -- Processing for Q switch
678 Force_ALI_Tree_File := True;
679 Try_Semantics := True;
681 -- Processing for r switch
685 Treat_Restrictions_As_Warnings := True;
687 -- Processing for R switch
690 Back_Annotate_Rep_Info := True;
691 List_Representation_Info := 1;
694 while Ptr <= Max loop
695 C := Switch_Chars (Ptr);
697 if C in '1' .. '3' then
698 List_Representation_Info :=
699 Character'Pos (C) - Character'Pos ('0');
701 elsif Switch_Chars (Ptr) = 's' then
702 List_Representation_Info_To_File := True;
704 elsif Switch_Chars (Ptr) = 'm' then
705 List_Representation_Info_Mechanisms := True;
708 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
714 -- Processing for s switch
717 if not First_Switch then
719 ("-gnats must be first if combined with other switches");
723 Operating_Mode := Check_Syntax;
725 -- Processing for S switch
728 Print_Standard := True;
731 -- Processing for t switch
736 Back_Annotate_Rep_Info := True;
738 -- Processing for T switch
742 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
744 -- Processing for u switch
750 -- Processing for U switch
754 Unique_Error_Tag := True;
756 -- Processing for v switch
760 Verbose_Mode := True;
762 -- Processing for V switch
765 Store_Switch := False;
769 Bad_Switch ("-gnatV");
776 Set_Validity_Check_Options
777 (Switch_Chars (Ptr .. Max), OK, Ptr);
780 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
783 for Index in First_Char + 1 .. Max loop
784 Store_Compilation_Switch
785 ("-gnatV" & Switch_Chars (Index));
792 -- Processing for w switch
795 Store_Switch := False;
799 Bad_Switch ("-gnatw");
802 while Ptr <= Max loop
803 C := Switch_Chars (Ptr);
805 -- Case of dot switch
807 if C = '.' and then Ptr < Max then
809 C := Switch_Chars (Ptr);
811 if Set_Dot_Warning_Switch (C) then
812 Store_Compilation_Switch ("-gnatw." & C);
814 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
817 -- Normal case, no dot
820 if Set_Warning_Switch (C) then
821 Store_Compilation_Switch ("-gnatw" & C);
823 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
832 -- Processing for W switch
838 Bad_Switch ("-gnatW");
842 Wide_Character_Encoding_Method :=
843 Get_WC_Encoding_Method (Switch_Chars (Ptr));
845 when Constraint_Error =>
846 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
849 Wide_Character_Encoding_Method_Specified := True;
851 Upper_Half_Encoding :=
852 Wide_Character_Encoding_Method in
853 WC_Upper_Half_Encoding_Method;
857 -- Processing for x switch
861 Xref_Active := False;
863 -- Processing for X switch
867 Extensions_Allowed := True;
869 -- Processing for y switch
875 Set_Default_Style_Check_Options;
878 Store_Switch := False;
884 Set_Style_Check_Options
885 (Switch_Chars (Ptr .. Max), OK, Ptr);
889 ("bad -gnaty switch (" &
890 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
893 Ptr := First_Char + 1;
894 while Ptr <= Max loop
895 if Switch_Chars (Ptr) = 'M' then
900 or else Switch_Chars (Ptr) not in '0' .. '9';
903 Store_Compilation_Switch
904 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
907 Store_Compilation_Switch
908 ("-gnaty" & Switch_Chars (Ptr));
915 -- Processing for z switch
920 -- Allowed for compiler only if this is the only
921 -- -z switch, we do not allow multiple occurrences
923 if Distribution_Stub_Mode = No_Stubs then
924 case Switch_Chars (Ptr) is
926 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
929 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
932 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
938 -- Processing for Z switch
943 ("-gnatZ is no longer supported: consider using --RTS=zcx");
945 -- Processing for 83 switch
949 Bad_Switch ("-gnat8");
954 if Switch_Chars (Ptr) /= '3' then
955 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
958 Ada_Version := Ada_83;
959 Ada_Version_Explicit := Ada_Version;
962 -- Processing for 95 switch
966 Bad_Switch ("-gnat9");
971 if Switch_Chars (Ptr) /= '5' then
972 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
975 Ada_Version := Ada_95;
976 Ada_Version_Explicit := Ada_Version;
979 -- Processing for 05 switch
983 Bad_Switch ("-gnat0");
988 if Switch_Chars (Ptr) /= '5' then
989 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
992 Ada_Version := Ada_05;
993 Ada_Version_Explicit := Ada_Version;
996 -- Ignore extra switch character
1001 -- Anything else is an error (illegal switch character)
1004 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1007 if Store_Switch then
1008 Store_Compilation_Switch
1009 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1012 First_Switch := False;
1015 end Scan_Front_End_Switches;