1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2005, 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 GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
29 with Debug
; use Debug
;
31 with Osint
; use Osint
;
33 with Prepcomp
; use Prepcomp
;
34 with Validsw
; use Validsw
;
35 with Sem_Warn
; use Sem_Warn
;
36 with Stylesw
; use Stylesw
;
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 Switch_Starts_With_Gnat
: Boolean;
51 -- True if first four switch characters are "gnat"
53 First_Switch
: Boolean := True;
54 -- False for all but first switch
56 Ptr
: Integer := Switch_Chars
'First;
57 Max
: constant Integer := Switch_Chars
'Last;
61 Store_Switch
: Boolean := True;
62 First_Char
: Integer := Ptr
;
63 Storing
: String := Switch_Chars
;
64 First_Stored
: Positive := Ptr
+ 1;
65 -- The above need comments ???
68 -- Skip past the initial character (must be the switch character)
76 -- Remove "gnat" from the switch, if present
78 Switch_Starts_With_Gnat
:=
79 Ptr
+ 3 <= Max
and then Switch_Chars
(Ptr
.. Ptr
+ 3) = "gnat";
81 if Switch_Starts_With_Gnat
then
86 -- Loop to scan through switches given in switch string
91 C
:= Switch_Chars
(Ptr
);
93 -- Processing for a switch
95 case Switch_Starts_With_Gnat
is
99 -- There are few front-end switches that
100 -- do not start with -gnat: -I, --RTS
102 if Switch_Chars
(Ptr
) = 'I' then
103 Store_Switch
:= False;
111 -- Find out whether this is a -I- or regular -Ixxx switch
113 if Ptr
= Max
and then Switch_Chars
(Ptr
) = '-' then
114 Look_In_Primary_Dir
:= False;
117 Add_Src_Search_Dir
(Switch_Chars
(Ptr
.. Max
));
122 -- Processing of the --RTS switch. --RTS has been modified by
123 -- gcc and is now of the form -fRTS
126 and then Switch_Chars
(Ptr
.. Ptr
+ 3) = "fRTS"
131 or else Switch_Chars
(Ptr
+ 3) /= '='
133 Osint
.Fail
("missing path for --RTS");
135 -- Check that this is the first time --RTS is specified
136 -- or if it is not the first time, the same path has
139 if RTS_Specified
= null then
141 new String'(Switch_Chars (Ptr + 4 .. Max));
144 RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
147 ("--RTS cannot be specified multiple times");
150 -- Valid --RTS switch
152 Opt.No_Stdinc := True;
153 Opt.RTS_Switch := True;
155 RTS_Src_Path_Name := Get_RTS_Search_Dir
156 (Switch_Chars (Ptr + 4 .. Max),
158 RTS_Lib_Path_Name := Get_RTS_Search_Dir
159 (Switch_Chars (Ptr + 4 .. Max),
162 if RTS_Src_Path_Name /= null and then
163 RTS_Lib_Path_Name /= null
167 elsif RTS_Src_Path_Name = null and then
168 RTS_Lib_Path_Name = null
170 Osint.Fail ("RTS path not valid: missing " &
171 "adainclude and adalib directories");
173 elsif RTS_Src_Path_Name = null then
174 Osint.Fail ("RTS path not valid: missing " &
175 "adainclude directory");
177 elsif RTS_Lib_Path_Name = null then
178 Osint.Fail ("RTS path not valid: missing " &
188 -- Process -gnat* options
194 Assertions_Enabled := True;
195 Debug_Pragmas_Enabled := True;
197 -- Processing for A switch
201 Config_File := False;
203 -- Processing for b switch
207 Brief_Output := True;
209 -- Processing for c switch
212 if not First_Switch then
214 ("-gnatc must be first if combined with other switches");
218 Operating_Mode := Check_Semantics;
224 -- Processing for d switch
227 Store_Switch := False;
228 Storing (First_Stored) := 'd
';
231 -- Note: for the debug switch, the remaining characters in this
232 -- switch field must all be debug flags, since all valid switch
233 -- characters are also valid debug characters.
235 -- Loop to scan out debug flags
239 C := Switch_Chars (Ptr);
240 exit when C = ASCII.NUL or else C = '/' or else C = '-';
242 if C in '1' .. '9' or else
243 C in 'a
' .. 'z
' or else
247 Set_Dotted_Debug_Flag (C);
248 Storing (First_Stored + 1) := '.';
249 Storing (First_Stored + 2) := C;
250 Store_Compilation_Switch
251 (Storing (Storing'First .. First_Stored + 2));
256 Storing (First_Stored + 1) := C;
257 Store_Compilation_Switch
258 (Storing (Storing'First .. First_Stored + 1));
271 -- Processing for D switch
276 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
277 -- generation in the ali file) since otherwise this generation
278 -- gets confused by the "wrong" Sloc values put in the tree.
280 Debug_Generated_Code := True;
281 Xref_Active := False;
282 Set_Debug_Flag ('g
');
284 -- -gnate? (extended switches)
289 -- The -gnate? switches are all double character switches
290 -- so we must always have a character after the e.
296 case Switch_Chars (Ptr) is
298 -- -gnatec (configuration pragmas)
301 Store_Switch := False;
304 -- There may be an equal sign between -gnatec and
305 -- the path name of the config file.
307 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
316 Config_File_Name : constant String_Access :=
318 (Switch_Chars
(Ptr
.. Max
));
321 if Config_File_Names
= null then
323 new String_List
'(1 => Config_File_Name);
327 New_Names : constant String_List_Access :=
330 Config_File_Names'Length + 1);
333 for Index in Config_File_Names'Range loop
335 Config_File_Names (Index);
336 Config_File_Names (Index) := null;
339 New_Names (New_Names'Last) := Config_File_Name;
340 Free (Config_File_Names);
341 Config_File_Names := New_Names;
348 -- -gnateD switch (symbol definition)
351 Store_Switch := False;
358 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
362 Storing (First_Stored .. First_Stored + 1) := "eD";
364 (First_Stored + 2 .. First_Stored + Max - Ptr + 2) :=
365 Switch_Chars (Ptr .. Max);
366 Store_Compilation_Switch (Storing
367 (Storing'First .. First_Stored + Max - Ptr + 2));
370 -- -gnatef (full source path for brief error messages)
373 Store_Switch := False;
375 Full_Path_Name_For_Brief_Errors := True;
378 -- -gnateI (index of unit in multi-unit source)
383 (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
385 -- -gnatem (mapping file)
388 Store_Switch := False;
391 -- There may be an equal sign between -gnatem and
392 -- the path name of the mapping file.
394 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
403 new String'(Switch_Chars
(Ptr
.. Max
));
406 -- -gnatep (preprocessing data file)
409 Store_Switch
:= False;
412 -- There may be an equal sign between -gnatep and
413 -- the path name of the mapping file.
415 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
423 Preprocessing_Data_File
:=
424 new String'(Switch_Chars (Ptr .. Max));
427 -- Because we may store a longer switch (we normalize
428 -- to -gnatep=), use a local variable.
432 (1 .. Preprocessing_Data_File'Length + 8);
435 To_Store (1 .. 8) := "-gnatep=";
436 To_Store (9 .. Preprocessing_Data_File'Length + 8) :=
437 Preprocessing_Data_File.all;
438 Store_Compilation_Switch (To_Store);
444 Store_Switch := False;
445 Disable_Switch_Storing;
448 -- All other -gnate? switches are unassigned
454 -- -gnatE (dynamic elaboration checks)
458 Dynamic_Elaboration_Checks := True;
460 -- -gnatf (full error messages)
464 All_Errors_Mode := True;
466 -- Processing for F switch
470 External_Name_Exp_Casing := Uppercase;
471 External_Name_Imp_Casing := Uppercase;
473 -- Processing for g switch
478 Identifier_Character_Set := 'n
';
479 System_Extend_Unit := Empty;
480 Warning_Mode := Treat_As_Error;
482 -- Set Ada 2005 mode explicitly. We don't want to rely on the
483 -- implicit setting here, since for example, we want
484 -- Preelaborate_05 treated as Preelaborate
486 Ada_Version := Ada_05;
487 Ada_Version_Explicit := Ada_Version;
489 -- Set default warnings for -gnatg (same set as -gnatwa)
491 Check_Unreferenced := True;
492 Check_Unreferenced_Formals := True;
494 Constant_Condition_Warnings := True;
495 Implementation_Unit_Warnings := True;
496 Ineffective_Inline_Warnings := True;
497 Warn_On_Bad_Fixed_Value := True;
498 Warn_On_Constant := True;
499 Warn_On_Export_Import := True;
500 Warn_On_Modified_Unread := True;
501 Warn_On_No_Value_Assigned := True;
502 Warn_On_Obsolescent_Feature := True;
503 Warn_On_Redundant_Constructs := True;
504 Warn_On_Unchecked_Conversion := True;
505 Warn_On_Unrecognized_Pragma := True;
507 Set_Style_Check_Options ("3abcdefhiklmnprstux");
509 -- Processing for G switch
513 Print_Generated_Code := True;
515 -- Processing for h switch
519 Usage_Requested := True;
521 -- Processing for H switch
527 -- Processing for i switch
535 C := Switch_Chars (Ptr);
545 Identifier_Character_Set := C;
552 -- Processing for k switch
557 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
559 -- Processing for l switch
565 -- Processing for L switch
570 ("-gnatL is no longer supported: consider using --RTS=sjlj");
572 -- Processing for m switch
577 -- There may be an equal sign between -gnatm and the value
579 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
583 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors, C);
585 -- Processing for n switch
589 Inline_Active := True;
591 -- Processing for N switch
595 Inline_Active := True;
596 Front_End_Inlining := True;
598 -- Processing for o switch
602 Suppress_Options (Overflow_Check) := False;
603 Opt.Enable_Overflow_Checks := True;
605 -- Processing for O switch
608 Store_Switch := False;
610 Output_File_Name_Present := True;
612 -- Processing for p switch
617 -- Set all specific options as well as All_Checks in the
618 -- Suppress_Options array, excluding Elaboration_Check, since
619 -- this is treated specially because we do not want -gnatp to
620 -- disable static elaboration processing.
622 for J in Suppress_Options'Range loop
623 if J /= Elaboration_Check then
624 Suppress_Options (J) := True;
628 Validity_Checks_On := False;
629 Opt.Suppress_Checks := True;
630 Opt.Enable_Overflow_Checks := False;
632 -- Processing for P switch
636 Polling_Required := True;
638 -- Processing for q switch
642 Try_Semantics := True;
644 -- Processing for q switch
648 Force_ALI_Tree_File := True;
649 Try_Semantics := True;
651 -- Processing for R switch
655 Back_Annotate_Rep_Info := True;
656 List_Representation_Info := 1;
658 while Ptr <= Max loop
659 C := Switch_Chars (Ptr);
661 if C in '1' .. '3' then
662 List_Representation_Info :=
663 Character'Pos (C) - Character'Pos ('0');
665 elsif Switch_Chars (Ptr) = 's
' then
666 List_Representation_Info_To_File := True;
668 elsif Switch_Chars (Ptr) = 'm
' then
669 List_Representation_Info_Mechanisms := True;
678 -- Processing for s switch
681 if not First_Switch then
683 ("-gnats must be first if combined with other switches");
687 Operating_Mode := Check_Syntax;
689 -- Processing for S switch
692 Print_Standard := True;
695 -- Processing for t switch
701 if Operating_Mode = Check_Semantics then
705 Back_Annotate_Rep_Info := True;
707 -- Processing for T switch
711 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
713 -- Processing for u switch
719 -- Processing for U switch
723 Unique_Error_Tag := True;
725 -- Processing for v switch
729 Verbose_Mode := True;
731 -- Processing for V switch
734 Store_Switch := False;
735 Storing (First_Stored) := 'V
';
746 Set_Validity_Check_Options
747 (Switch_Chars (Ptr .. Max), OK, Ptr);
753 for Index in First_Char + 1 .. Max loop
754 Storing (First_Stored + 1) :=
755 Switch_Chars (Index);
756 Store_Compilation_Switch
757 (Storing (Storing'First .. First_Stored + 1));
764 -- Processing for w switch
767 Store_Switch := False;
768 Storing (First_Stored) := 'w
';
775 while Ptr <= Max loop
776 C := Switch_Chars (Ptr);
778 if Set_Warning_Switch (C) then
785 Storing (First_Stored + 1) := C;
786 Store_Compilation_Switch
787 (Storing (Storing'First .. First_Stored + 1));
795 -- Processing for W switch
804 for J in WC_Encoding_Method loop
805 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
806 Wide_Character_Encoding_Method := J;
809 elsif J = WC_Encoding_Method'Last then
814 Upper_Half_Encoding :=
815 Wide_Character_Encoding_Method in
816 WC_Upper_Half_Encoding_Method;
820 -- Processing for x switch
824 Xref_Active := False;
826 -- Processing for X switch
830 Extensions_Allowed := True;
831 Ada_Version := Ada_Version_Type'Last;
832 Ada_Version_Explicit := Ada_Version;
834 -- Processing for y switch
840 Set_Default_Style_Check_Options;
843 Store_Switch := False;
844 Storing (First_Stored) := 'y
';
848 Last_Stored : Integer;
851 Set_Style_Check_Options
852 (Switch_Chars (Ptr .. Max), OK, Ptr);
856 R : String (1 .. Style_Msg_Len + 20);
858 R (1 .. 19) := "bad -gnaty switch (";
859 R (20 .. R'Last - 1) :=
860 Style_Msg_Buf (1 .. Style_Msg_Len);
866 Ptr := First_Char + 1;
867 while Ptr <= Max loop
868 Last_Stored := First_Stored + 1;
869 Storing (Last_Stored) := Switch_Chars (Ptr);
871 if Switch_Chars (Ptr) = 'M
' then
875 or else Switch_Chars (Ptr) not in '0' .. '9';
876 Last_Stored := Last_Stored + 1;
877 Storing (Last_Stored) := Switch_Chars (Ptr);
884 Store_Compilation_Switch
885 (Storing (Storing'First .. Last_Stored));
890 -- Processing for z switch
895 -- Allowed for compiler only if this is the only
896 -- -z switch, we do not allow multiple occurrences
898 if Distribution_Stub_Mode = No_Stubs then
899 case Switch_Chars (Ptr) is
901 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
904 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
914 -- Processing for Z switch
919 ("-gnatZ is no longer supported: consider using --RTS=zcx");
921 -- Processing for 83 switch
930 if Switch_Chars (Ptr) /= '3' then
934 Ada_Version := Ada_83;
935 Ada_Version_Explicit := Ada_Version;
938 -- Processing for 95 switch
947 if Switch_Chars (Ptr) /= '5' then
951 Ada_Version := Ada_95;
952 Ada_Version_Explicit := Ada_Version;
955 -- Processing for 05 switch
964 if Switch_Chars (Ptr) /= '5' then
968 Ada_Version := Ada_05;
969 Ada_Version_Explicit := Ada_Version;
972 -- Ignore extra switch character
977 -- Anything else is an error (illegal switch character)
985 Storing (First_Stored .. First_Stored + Ptr - First_Char - 1) :=
986 Switch_Chars (First_Char .. Ptr - 1);
987 Store_Compilation_Switch
988 (Storing (Storing'First .. First_Stored + Ptr - First_Char - 1));
991 First_Switch := False;
993 end Scan_Front_End_Switches;