1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 2001-2002 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 with Debug; use Debug;
31 with Osint; use Osint;
33 with Types; use Types;
34 with Validsw; use Validsw;
35 with Stylesw; use Stylesw;
37 with System.WCh_Con; use System.WCh_Con;
39 package body Switch.C is
41 -----------------------------
42 -- Scan_Front_End_Switches --
43 -----------------------------
45 procedure Scan_Front_End_Switches (Switch_Chars : String) is
46 Switch_Starts_With_Gnat : Boolean;
47 -- True if first four switch characters are "gnat"
49 First_Switch : Boolean := True;
50 -- False for all but first switch
52 Ptr : Integer := Switch_Chars'First;
53 Max : constant Integer := Switch_Chars'Last;
56 Store_Switch : Boolean := True;
57 First_Char : Integer := Ptr;
58 Storing : String := Switch_Chars;
59 First_Stored : Positive := Ptr + 1;
60 -- The above need comments ???
63 -- Skip past the initial character (must be the switch character)
71 -- Remove "gnat" from the switch, if present
73 Switch_Starts_With_Gnat :=
74 Ptr + 3 <= Max and then Switch_Chars (Ptr .. Ptr + 3) = "gnat";
76 if Switch_Starts_With_Gnat then
81 -- Loop to scan through switches given in switch string
86 C := Switch_Chars (Ptr);
88 -- Processing for a switch
90 case Switch_Starts_With_Gnat is
93 -- There are only two front-end switches that
94 -- do not start with -gnat, namely -I and --RTS
96 if Switch_Chars (Ptr) = 'I' then
97 Store_Switch := False;
105 -- Find out whether this is a -I- or regular -Ixxx switch
107 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
108 Look_In_Primary_Dir := False;
111 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
116 -- Processing of the --RTS switch. --RTS has been modified by
117 -- gcc and is now of the form -fRTS
118 elsif Ptr + 3 <= Max and then
119 Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
123 if Ptr + 4 > Max or else Switch_Chars (Ptr + 3) /= '=' then
124 Osint.Fail ("missing path for --RTS");
127 -- valid --RTS switch
128 Opt.No_Stdinc := True;
129 Opt.RTS_Switch := True;
132 Src_Path_Name : String_Ptr := Get_RTS_Search_Dir
133 (Switch_Chars (Ptr + 4 .. Max), Include);
134 Lib_Path_Name : String_Ptr := Get_RTS_Search_Dir
135 (Switch_Chars (Ptr + 4 .. Max), Objects);
137 if Src_Path_Name /= null and then
138 Lib_Path_Name /= null
140 Add_Search_Dirs (Src_Path_Name, Include);
141 Add_Search_Dirs (Lib_Path_Name, Objects);
143 elsif Src_Path_Name = null
144 and Lib_Path_Name = null then
145 Osint.Fail ("RTS path not valid: missing " &
146 "adainclude and adalib directories");
147 elsif Src_Path_Name = null then
148 Osint.Fail ("RTS path not valid: missing " &
149 "adainclude directory");
150 elsif Lib_Path_Name = null then
151 Osint.Fail ("RTS path not valid: missing " &
161 -- Process -gnat* options
167 Assertions_Enabled := True;
169 -- Processing for A switch
173 Config_File := False;
175 -- Processing for b switch
179 Brief_Output := True;
181 -- Processing for c switch
184 if not First_Switch then
186 ("-gnatc myust be first if combined with other switches");
190 Operating_Mode := Check_Semantics;
192 -- Processing for C switch
196 Compress_Debug_Names := True;
198 -- Processing for d switch
201 Store_Switch := False;
202 Storing (First_Stored) := 'd';
203 -- Note: for the debug switch, the remaining characters in this
204 -- switch field must all be debug flags, since all valid switch
205 -- characters are also valid debug characters.
207 -- Loop to scan out debug flags
211 C := Switch_Chars (Ptr);
212 exit when C = ASCII.NUL or else C = '/' or else C = '-';
214 if C in '1' .. '9' or else
215 C in 'a' .. 'z' or else
219 Storing (First_Stored + 1) := C;
220 Store_Compilation_Switch
221 (Storing (Storing'First .. First_Stored + 1));
228 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
229 -- is for backwards compatibility with old versions and usage.
231 if Debug_Flag_XX then
232 Zero_Cost_Exceptions_Set := True;
233 Zero_Cost_Exceptions_Val := True;
238 -- Processing for D switch
243 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
244 -- generation in the ali file) since otherwise this generation
245 -- gets confused by the "wrong" Sloc values put in the tree.
247 Debug_Generated_Code := True;
248 Xref_Active := False;
249 Set_Debug_Flag ('g');
251 -- Processing for e switch
260 case Switch_Chars (Ptr) is
262 -- Configuration pragmas
265 Store_Switch := False;
273 new String'(Switch_Chars (Ptr .. Max));
280 Store_Switch := False;
288 new String'(Switch_Chars (Ptr .. Max));
295 -- Processing for E switch
299 Dynamic_Elaboration_Checks := True;
301 -- Processing for f switch
305 All_Errors_Mode := True;
307 -- Processing for F switch
311 External_Name_Exp_Casing := Uppercase;
312 External_Name_Imp_Casing := Uppercase;
314 -- Processing for g switch
319 Identifier_Character_Set := 'n';
320 Warning_Mode := Treat_As_Error;
321 Check_Unreferenced := True;
324 Set_Default_Style_Check_Options;
326 -- Processing for G switch
330 Print_Generated_Code := True;
332 -- Processing for h switch
336 Usage_Requested := True;
338 -- Processing for H switch
344 -- Processing for i switch
352 C := Switch_Chars (Ptr);
362 Identifier_Character_Set := C;
369 -- Processing for k switch
373 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_File_Name_Length);
375 -- Processing for l switch
381 -- Processing for L switch
385 Zero_Cost_Exceptions_Set := True;
386 Zero_Cost_Exceptions_Val := False;
388 -- Processing for m switch
392 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
394 -- Processing for n switch
398 Inline_Active := True;
400 -- Processing for N switch
404 Inline_Active := True;
405 Front_End_Inlining := True;
407 -- Processing for o switch
411 Suppress_Options.Overflow_Checks := False;
412 Opt.Enable_Overflow_Checks := True;
414 -- Processing for O switch
418 Output_File_Name_Present := True;
420 -- Processing for p switch
424 Suppress_Options.Access_Checks := True;
425 Suppress_Options.Accessibility_Checks := True;
426 Suppress_Options.Discriminant_Checks := True;
427 Suppress_Options.Division_Checks := True;
428 Suppress_Options.Elaboration_Checks := True;
429 Suppress_Options.Index_Checks := True;
430 Suppress_Options.Length_Checks := True;
431 Suppress_Options.Overflow_Checks := True;
432 Suppress_Options.Range_Checks := True;
433 Suppress_Options.Storage_Checks := True;
434 Suppress_Options.Tag_Checks := True;
436 Validity_Checks_On := False;
437 Opt.Suppress_Checks := True;
438 Opt.Enable_Overflow_Checks := False;
440 -- Processing for P switch
444 Polling_Required := True;
446 -- Processing for q switch
450 Try_Semantics := True;
452 -- Processing for q switch
456 Force_ALI_Tree_File := True;
457 Try_Semantics := True;
459 -- Processing for R switch
463 Back_Annotate_Rep_Info := True;
466 and then Switch_Chars (Ptr) in '0' .. '9'
468 C := Switch_Chars (Ptr);
470 if C in '4' .. '9' then
473 List_Representation_Info :=
474 Character'Pos (C) - Character'Pos ('0');
478 if Ptr <= Max and then Switch_Chars (Ptr) = 's' then
481 if List_Representation_Info /= 0 then
482 List_Representation_Info_To_File := True;
487 List_Representation_Info := 1;
490 -- Processing for s switch
493 if not First_Switch then
495 ("-gnats myust be first if combined with other switches");
499 Operating_Mode := Check_Syntax;
501 -- Processing for t switch
506 Back_Annotate_Rep_Info := True;
508 -- Processing for T switch
512 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor);
514 -- Processing for u switch
520 -- Processing for U switch
524 Unique_Error_Tag := True;
526 -- Processing for v switch
530 Verbose_Mode := True;
532 -- Processing for V switch
535 Store_Switch := False;
536 Storing (First_Stored) := 'V';
547 Set_Validity_Check_Options
548 (Switch_Chars (Ptr .. Max), OK, Ptr);
554 for Index in First_Char + 1 .. Max loop
555 Storing (First_Stored + 1) :=
556 Switch_Chars (Index);
557 Store_Compilation_Switch
558 (Storing (Storing'First .. First_Stored + 1));
565 -- Processing for w switch
568 Store_Switch := False;
569 Storing (First_Stored) := 'w';
576 while Ptr <= Max loop
577 C := Switch_Chars (Ptr);
582 Constant_Condition_Warnings := True;
583 Elab_Warnings := True;
584 Check_Unreferenced := True;
586 Check_Unreferenced_Formals := True;
587 Implementation_Unit_Warnings := True;
588 Ineffective_Inline_Warnings := True;
589 Warn_On_Redundant_Constructs := True;
592 Constant_Condition_Warnings := False;
593 Elab_Warnings := False;
594 Check_Unreferenced := False;
595 Check_Withs := False;
596 Check_Unreferenced_Formals := False;
597 Implementation_Unit_Warnings := False;
598 Warn_On_Biased_Rounding := False;
599 Warn_On_Dereference := False;
600 Warn_On_Hiding := False;
601 Warn_On_Redundant_Constructs := False;
602 Ineffective_Inline_Warnings := False;
605 Warn_On_Biased_Rounding := True;
608 Warn_On_Biased_Rounding := False;
611 Constant_Condition_Warnings := True;
614 Constant_Condition_Warnings := False;
617 Warn_On_Dereference := True;
620 Warn_On_Dereference := False;
623 Warning_Mode := Treat_As_Error;
626 Check_Unreferenced_Formals := True;
629 Check_Unreferenced_Formals := False;
632 Warn_On_Hiding := True;
635 Warn_On_Hiding := False;
638 Implementation_Unit_Warnings := True;
641 Implementation_Unit_Warnings := False;
644 Elab_Warnings := True;
647 Elab_Warnings := False;
650 Address_Clause_Overlay_Warnings := True;
653 Address_Clause_Overlay_Warnings := False;
656 Ineffective_Inline_Warnings := True;
659 Ineffective_Inline_Warnings := False;
662 Warn_On_Redundant_Constructs := True;
665 Warn_On_Redundant_Constructs := False;
668 Warning_Mode := Suppress;
671 Check_Unreferenced := True;
673 Check_Unreferenced_Formals := True;
676 Check_Unreferenced := False;
677 Check_Withs := False;
678 Check_Unreferenced_Formals := False;
680 -- Allow and ignore 'w' so that the old
681 -- format (e.g. -gnatwuwl) will work.
691 Storing (First_Stored + 1) := C;
692 Store_Compilation_Switch
693 (Storing (Storing'First .. First_Stored + 1));
701 -- Processing for W switch
710 for J in WC_Encoding_Method loop
711 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
712 Wide_Character_Encoding_Method := J;
715 elsif J = WC_Encoding_Method'Last then
720 Upper_Half_Encoding :=
721 Wide_Character_Encoding_Method in
722 WC_Upper_Half_Encoding_Method;
726 -- Processing for x switch
730 Xref_Active := False;
732 -- Processing for X switch
736 Extensions_Allowed := True;
738 -- Processing for y switch
744 Set_Default_Style_Check_Options;
747 Store_Switch := False;
748 Storing (First_Stored) := 'y';
752 Last_Stored : Integer;
755 Set_Style_Check_Options
756 (Switch_Chars (Ptr .. Max), OK, Ptr);
762 Ptr := First_Char + 1;
764 while Ptr <= Max loop
765 Last_Stored := First_Stored + 1;
766 Storing (Last_Stored) := Switch_Chars (Ptr);
768 if Switch_Chars (Ptr) = 'M' then
772 or else Switch_Chars (Ptr) not in '0' .. '9';
773 Last_Stored := Last_Stored + 1;
774 Storing (Last_Stored) := Switch_Chars (Ptr);
781 Store_Compilation_Switch
782 (Storing (Storing'First .. Last_Stored));
787 -- Processing for z switch
792 -- Allowed for compiler, only if this is the only
793 -- -z switch, we do not allow multiple occurrences
795 if Distribution_Stub_Mode = No_Stubs then
796 case Switch_Chars (Ptr) is
798 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
801 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
811 -- Processing for Z switch
815 Zero_Cost_Exceptions_Set := True;
816 Zero_Cost_Exceptions_Val := True;
818 -- Processing for 83 switch
828 if Switch_Chars (Ptr) /= '3' then
836 -- Ignore extra switch character
841 -- Anything else is an error (illegal switch character)
849 Storing (First_Stored .. First_Stored + Ptr - First_Char - 1) :=
850 Switch_Chars (First_Char .. Ptr - 1);
851 Store_Compilation_Switch
852 (Storing (Storing'First .. First_Stored + Ptr - First_Char - 1));
855 First_Switch := False;
860 Osint.Fail ("invalid switch: ", (1 => C));
862 when Bad_Switch_Value =>
863 Osint.Fail ("numeric value too big for switch: ", (1 => C));
865 when Missing_Switch_Value =>
866 Osint.Fail ("missing numeric value for switch: ", (1 => C));
868 end Scan_Front_End_Switches;