1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2007, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Debug; use Debug;
29 with Osint; use Osint;
31 with Prepcomp; use Prepcomp;
32 with Validsw; use Validsw;
33 with Sem_Warn; use Sem_Warn;
34 with Stylesw; use Stylesw;
36 with System.OS_Lib; use System.OS_Lib;
38 with System.WCh_Con; use System.WCh_Con;
40 package body Switch.C is
42 RTS_Specified : String_Access := null;
43 -- Used to detect multiple use of --RTS= flag
45 -----------------------------
46 -- Scan_Front_End_Switches --
47 -----------------------------
49 procedure Scan_Front_End_Switches (Switch_Chars : String) is
50 First_Switch : Boolean := True;
51 -- False for all but first switch
53 Max : constant Natural := Switch_Chars'Last;
58 Store_Switch : Boolean;
59 -- For -gnatxx switches, the normal processing, signalled by this flag
60 -- being set to True, is to store the switch on exit from the case
61 -- statement, the switch stored is -gnat followed by the characters
62 -- from First_Char to Ptr-1. For cases like -gnaty, where the switch
63 -- is stored in separate pieces, this flag is set to False, and the
64 -- appropriate calls to Store_Compilation_Switch are made from within
67 First_Char : Positive;
68 -- Marks start of switch to be stored
71 Ptr := Switch_Chars'First;
73 -- Skip past the initial character (must be the switch character)
81 -- Handle switches that do not start with -gnat
84 or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat"
86 -- There are two front-end switches that do not start with -gnat:
89 if Switch_Chars (Ptr) = 'I' then
91 -- Set flag Search_Directory_Present if switch is "-I" only:
92 -- the directory will be the next argument.
95 Search_Directory_Present := True;
101 -- Find out whether this is a -I- or regular -Ixxx switch
103 -- Note: -I switches are not recorded in the ALI file, since the
104 -- meaning of the program depends on the source files compiled,
105 -- not where they came from.
107 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
108 Look_In_Primary_Dir := False;
110 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
113 -- Processing of the --RTS switch. --RTS may have been modified by
114 -- gcc into -fRTS (for GCC targets).
117 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
119 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
124 or else Switch_Chars (Ptr + 3) /= '='
126 Osint.Fail ("missing path for --RTS");
128 -- Check that this is the first time --RTS is specified or if
129 -- it is not the first time, the same path has been specified.
131 if RTS_Specified = null then
132 RTS_Specified := new String'(Switch_Chars (Ptr + 4 .. Max));
135 RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
138 ("--RTS cannot be specified multiple times");
141 -- Valid --RTS switch
143 Opt.No_Stdinc := True;
144 Opt.RTS_Switch := True;
148 (Switch_Chars (Ptr + 4 .. Max), Include);
152 (Switch_Chars (Ptr + 4 .. Max), Objects);
154 if RTS_Src_Path_Name /= null
155 and then RTS_Lib_Path_Name /= null
157 -- Store the -fRTS switch (Note: Store_Compilation_Switch
158 -- changes -fRTS back into --RTS for the actual output).
160 Store_Compilation_Switch (Switch_Chars);
162 elsif RTS_Src_Path_Name = null
163 and then RTS_Lib_Path_Name = null
165 Osint.Fail ("RTS path not valid: missing " &
166 "adainclude and adalib directories");
168 elsif RTS_Src_Path_Name = null then
169 Osint.Fail ("RTS path not valid: missing " &
170 "adainclude directory");
172 elsif RTS_Lib_Path_Name = null then
173 Osint.Fail ("RTS path not valid: missing " &
178 -- There are no other switches not starting with -gnat
181 Bad_Switch (Switch_Chars);
184 -- Case of switch starting with -gnat
189 -- Loop to scan through switches given in switch string
191 while Ptr <= Max loop
193 Store_Switch := True;
195 C := Switch_Chars (Ptr);
201 Assertions_Enabled := True;
202 Debug_Pragmas_Enabled := True;
204 -- Processing for A switch
208 Config_File := False;
210 -- Processing for b switch
214 Brief_Output := True;
216 -- Processing for c switch
219 if not First_Switch then
221 ("-gnatc must be first if combined with other switches");
225 Operating_Mode := Check_Semantics;
231 -- Processing for d switch
234 Store_Switch := False;
237 -- Note: for the debug switch, the remaining characters in this
238 -- switch field must all be debug flags, since all valid switch
239 -- characters are also valid debug characters.
241 -- Loop to scan out debug flags
245 C := Switch_Chars (Ptr);
246 exit when C = ASCII.NUL or else C = '/' or else C = '-';
248 if C in '1' .. '9' or else
249 C in 'a' .. 'z' or else
253 Set_Dotted_Debug_Flag (C);
254 Store_Compilation_Switch ("-gnatd." & C);
257 Store_Compilation_Switch ("-gnatd" & C);
264 Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
266 Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
272 -- Processing for D switch
277 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
278 -- generation in the ali file) since otherwise this generation
279 -- gets confused by the "wrong" Sloc values put in the tree.
281 Debug_Generated_Code := True;
282 Xref_Active := False;
283 Set_Debug_Flag ('g');
285 -- -gnate? (extended switches)
290 -- The -gnate? switches are all double character switches
291 -- so we must always have a character after the e.
294 Bad_Switch ("-gnate");
297 case Switch_Chars (Ptr) is
299 -- -gnatec (configuration pragmas)
302 Store_Switch := False;
305 -- There may be an equal sign between -gnatec and
306 -- the path name of the config file.
308 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
313 Bad_Switch ("-gnatec");
317 Config_File_Name : constant String_Access :=
319 (Switch_Chars (Ptr .. Max));
322 if Config_File_Names = null then
324 new String_List'(1 => Config_File_Name);
328 New_Names : constant String_List_Access :=
331 Config_File_Names'Length + 1);
334 for Index in Config_File_Names'Range loop
336 Config_File_Names (Index);
337 Config_File_Names (Index) := null;
340 New_Names (New_Names'Last) := Config_File_Name;
341 Free (Config_File_Names);
342 Config_File_Names := New_Names;
349 -- -gnateD switch (preprocessing symbol definition)
352 Store_Switch := False;
356 Bad_Switch ("-gnateD");
359 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
363 Store_Compilation_Switch
364 ("-gnateD" & Switch_Chars (Ptr .. Max));
367 -- -gnatef (full source path for brief error messages)
370 Store_Switch := False;
372 Full_Path_Name_For_Brief_Errors := True;
375 -- -gnateI (index of unit in multi-unit source)
379 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
381 -- -gnatem (mapping file)
384 Store_Switch := False;
387 -- There may be an equal sign between -gnatem and
388 -- the path name of the mapping file.
390 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
395 Bad_Switch ("-gnatem");
399 new String'(Switch_Chars (Ptr .. Max));
402 -- -gnatep (preprocessing data file)
405 Store_Switch := False;
408 -- There may be an equal sign between -gnatep and
409 -- the path name of the mapping file.
411 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
416 Bad_Switch ("-gnatep");
419 Preprocessing_Data_File :=
420 new String'(Switch_Chars (Ptr .. Max));
422 -- Store the switch, normalizing to -gnatep=
424 Store_Compilation_Switch
425 ("-gnatep=" & Preprocessing_Data_File.all);
430 Store_Switch := False;
431 Disable_Switch_Storing;
434 -- All other -gnate? switches are unassigned
437 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
440 -- -gnatE (dynamic elaboration checks)
444 Dynamic_Elaboration_Checks := True;
446 -- -gnatf (full error messages)
450 All_Errors_Mode := True;
452 -- Processing for F switch
456 External_Name_Exp_Casing := Uppercase;
457 External_Name_Imp_Casing := Uppercase;
459 -- Processing for g switch
464 Identifier_Character_Set := 'n';
465 System_Extend_Unit := Empty;
466 Warning_Mode := Treat_As_Error;
468 -- Set Ada 2005 mode explicitly. We don't want to rely on the
469 -- implicit setting here, since for example, we want
470 -- Preelaborate_05 treated as Preelaborate
472 Ada_Version := Ada_05;
473 Ada_Version_Explicit := Ada_Version;
475 -- Set default warnings for -gnatg
477 Check_Unreferenced := True;
478 Check_Unreferenced_Formals := True;
480 Constant_Condition_Warnings := True;
481 Implementation_Unit_Warnings := True;
482 Ineffective_Inline_Warnings := True;
483 Warn_On_Assumed_Low_Bound := True;
484 Warn_On_Bad_Fixed_Value := True;
485 Warn_On_Constant := True;
486 Warn_On_Export_Import := True;
487 Warn_On_Modified_Unread := True;
488 Warn_On_No_Value_Assigned := True;
489 Warn_On_Non_Local_Exception := False;
490 Warn_On_Obsolescent_Feature := True;
491 Warn_On_Redundant_Constructs := True;
492 Warn_On_Object_Renames_Function := True;
493 Warn_On_Unchecked_Conversion := True;
494 Warn_On_Unrecognized_Pragma := True;
496 Set_GNAT_Style_Check_Options;
498 -- Processing for G switch
502 Print_Generated_Code := True;
504 -- Processing for h switch
508 Usage_Requested := True;
510 -- Processing for H switch
516 -- Processing for i switch
520 Bad_Switch ("-gnati");
524 C := Switch_Chars (Ptr);
534 Identifier_Character_Set := C;
538 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
541 -- Processing for I switch
545 Ignore_Rep_Clauses := True;
547 -- Processing for j switch
552 -- There may be an equal sign between -gnatj and the value
554 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
558 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
560 -- Processing for k switch
565 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
567 -- Processing for l switch
573 -- There may be an equal sign between -gnatl and a file name
575 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
577 Osint.Fail ("file name for -gnatl= is null");
579 Opt.Full_List_File_Name :=
580 new String'(Switch_Chars (Ptr + 1 .. Max));
585 -- Processing for L switch
589 Dump_Source_Text := True;
591 -- Processing for m switch
596 -- There may be an equal sign between -gnatm and the value
598 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
602 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Errors, C);
604 -- Processing for n switch
608 Inline_Active := True;
610 -- Processing for N switch
614 Inline_Active := True;
615 Front_End_Inlining := True;
617 -- Processing for o switch
621 Suppress_Options (Overflow_Check) := False;
622 Opt.Enable_Overflow_Checks := True;
624 -- Processing for O switch
627 Store_Switch := False;
629 Output_File_Name_Present := True;
631 -- Processing for p switch
636 -- Set all specific options as well as All_Checks in the
637 -- Suppress_Options array, excluding Elaboration_Check, since
638 -- this is treated specially because we do not want -gnatp to
639 -- disable static elaboration processing.
641 for J in Suppress_Options'Range loop
642 if J /= Elaboration_Check then
643 Suppress_Options (J) := True;
647 Validity_Checks_On := False;
648 Opt.Suppress_Checks := True;
649 Opt.Enable_Overflow_Checks := False;
651 -- Processing for P switch
655 Polling_Required := True;
657 -- Processing for q switch
661 Try_Semantics := True;
663 -- Processing for q switch
667 Force_ALI_Tree_File := True;
668 Try_Semantics := True;
670 -- Processing for R switch
673 Back_Annotate_Rep_Info := True;
674 List_Representation_Info := 1;
677 while Ptr <= Max loop
678 C := Switch_Chars (Ptr);
680 if C in '1' .. '3' then
681 List_Representation_Info :=
682 Character'Pos (C) - Character'Pos ('0');
684 elsif Switch_Chars (Ptr) = 's' then
685 List_Representation_Info_To_File := True;
687 elsif Switch_Chars (Ptr) = 'm' then
688 List_Representation_Info_Mechanisms := True;
691 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
697 -- Processing for s switch
700 if not First_Switch then
702 ("-gnats must be first if combined with other switches");
706 Operating_Mode := Check_Syntax;
708 -- Processing for S switch
711 Print_Standard := True;
714 -- Processing for t switch
720 if Operating_Mode = Check_Semantics then
724 Back_Annotate_Rep_Info := True;
726 -- Processing for T switch
730 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
732 -- Processing for u switch
738 -- Processing for U switch
742 Unique_Error_Tag := True;
744 -- Processing for v switch
748 Verbose_Mode := True;
750 -- Processing for V switch
753 Store_Switch := False;
757 Bad_Switch ("-gnatV");
764 Set_Validity_Check_Options
765 (Switch_Chars (Ptr .. Max), OK, Ptr);
768 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
771 for Index in First_Char + 1 .. Max loop
772 Store_Compilation_Switch
773 ("-gnatV" & Switch_Chars (Index));
780 -- Processing for w switch
783 Store_Switch := False;
787 Bad_Switch ("-gnatw");
790 while Ptr <= Max loop
791 C := Switch_Chars (Ptr);
793 -- Case of dot switch
795 if C = '.' and then Ptr < Max then
797 C := Switch_Chars (Ptr);
799 if Set_Dot_Warning_Switch (C) then
800 Store_Compilation_Switch ("-gnatw." & C);
802 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
805 -- Normal case, no dot
808 if Set_Warning_Switch (C) then
809 Store_Compilation_Switch ("-gnatw" & C);
811 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
820 -- Processing for W switch
826 Bad_Switch ("-gnatW");
830 Wide_Character_Encoding_Method :=
831 Get_WC_Encoding_Method (Switch_Chars (Ptr));
833 when Constraint_Error =>
834 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
837 Upper_Half_Encoding :=
838 Wide_Character_Encoding_Method in
839 WC_Upper_Half_Encoding_Method;
843 -- Processing for x switch
847 Xref_Active := False;
849 -- Processing for X switch
853 Extensions_Allowed := True;
855 -- Processing for y switch
861 Set_Default_Style_Check_Options;
864 Store_Switch := False;
870 Set_Style_Check_Options
871 (Switch_Chars (Ptr .. Max), OK, Ptr);
875 ("bad -gnaty switch (" &
876 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
879 Ptr := First_Char + 1;
880 while Ptr <= Max loop
881 if Switch_Chars (Ptr) = 'M' then
886 or else Switch_Chars (Ptr) not in '0' .. '9';
889 Store_Compilation_Switch
890 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
893 Store_Compilation_Switch
894 ("-gnaty" & Switch_Chars (Ptr));
901 -- Processing for z switch
906 -- Allowed for compiler only if this is the only
907 -- -z switch, we do not allow multiple occurrences
909 if Distribution_Stub_Mode = No_Stubs then
910 case Switch_Chars (Ptr) is
912 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
915 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
918 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
924 -- Processing for Z switch
929 ("-gnatZ is no longer supported: consider using --RTS=zcx");
931 -- Processing for 83 switch
935 Bad_Switch ("-gnat8");
940 if Switch_Chars (Ptr) /= '3' then
941 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
944 Ada_Version := Ada_83;
945 Ada_Version_Explicit := Ada_Version;
948 -- Processing for 95 switch
952 Bad_Switch ("-gnat9");
957 if Switch_Chars (Ptr) /= '5' then
958 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
961 Ada_Version := Ada_95;
962 Ada_Version_Explicit := Ada_Version;
965 -- Processing for 05 switch
969 Bad_Switch ("-gnat0");
974 if Switch_Chars (Ptr) /= '5' then
975 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
978 Ada_Version := Ada_05;
979 Ada_Version_Explicit := Ada_Version;
982 -- Ignore extra switch character
987 -- Anything else is an error (illegal switch character)
990 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
994 Store_Compilation_Switch
995 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
998 First_Switch := False;
1001 end Scan_Front_End_Switches;