1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2004 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 Types
; use Types
;
35 with Validsw
; use Validsw
;
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;
196 -- Processing for A switch
200 Config_File := False;
202 -- Processing for b switch
206 Brief_Output := True;
208 -- Processing for c switch
211 if not First_Switch then
213 ("-gnatc must be first if combined with other switches");
217 Operating_Mode := Check_Semantics;
223 -- Processing for d switch
226 Store_Switch := False;
227 Storing (First_Stored) := 'd
';
230 -- Note: for the debug switch, the remaining characters in this
231 -- switch field must all be debug flags, since all valid switch
232 -- characters are also valid debug characters.
234 -- Loop to scan out debug flags
238 C := Switch_Chars (Ptr);
239 exit when C = ASCII.NUL or else C = '/' or else C = '-';
241 if C in '1' .. '9' or else
242 C in 'a
' .. 'z
' or else
246 Set_Dotted_Debug_Flag (C);
247 Storing (First_Stored + 1) := '.';
248 Storing (First_Stored + 2) := C;
249 Store_Compilation_Switch
250 (Storing (Storing'First .. First_Stored + 2));
255 Storing (First_Stored + 1) := C;
256 Store_Compilation_Switch
257 (Storing (Storing'First .. First_Stored + 1));
268 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
269 -- is for backwards compatibility with old versions and usage.
271 if Debug_Flag_XX then
272 Zero_Cost_Exceptions_Set := True;
273 Zero_Cost_Exceptions_Val := True;
278 -- Processing for D switch
283 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
284 -- generation in the ali file) since otherwise this generation
285 -- gets confused by the "wrong" Sloc values put in the tree.
287 Debug_Generated_Code := True;
288 Xref_Active := False;
289 Set_Debug_Flag ('g
');
291 -- -gnate? (extended switches)
296 -- The -gnate? switches are all double character switches
297 -- so we must always have a character after the e.
303 case Switch_Chars (Ptr) is
305 -- -gnatec (configuration pragmas)
308 Store_Switch := False;
311 -- There may be an equal sign between -gnatec and
312 -- the path name of the config file.
314 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
323 Config_File_Name : constant String_Access :=
325 (Switch_Chars
(Ptr
.. Max
));
328 if Config_File_Names
= null then
330 new String_List
'(1 => Config_File_Name);
334 New_Names : constant String_List_Access :=
337 Config_File_Names'Length + 1);
340 for Index in Config_File_Names'Range loop
342 Config_File_Names (Index);
343 Config_File_Names (Index) := null;
346 New_Names (New_Names'Last) := Config_File_Name;
347 Free (Config_File_Names);
348 Config_File_Names := New_Names;
355 -- -gnateD switch (symbol definition)
358 Store_Switch := False;
365 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
369 Storing (First_Stored .. First_Stored + 1) := "eD";
371 (First_Stored + 2 .. First_Stored + Max - Ptr + 2) :=
372 Switch_Chars (Ptr .. Max);
373 Store_Compilation_Switch (Storing
374 (Storing'First .. First_Stored + Max - Ptr + 2));
377 -- -gnatef (full source path for brief error messages)
380 Store_Switch := False;
382 Full_Path_Name_For_Brief_Errors := True;
385 -- -gnateI (index of unit in multi-unit source)
389 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index);
391 -- -gnatem (mapping file)
394 Store_Switch := False;
397 -- There may be an equal sign between -gnatem and
398 -- the path name of the mapping file.
400 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
409 new String'(Switch_Chars
(Ptr
.. Max
));
412 -- -gnatep (preprocessing data file)
415 Store_Switch
:= False;
418 -- There may be an equal sign between -gnatep and
419 -- the path name of the mapping file.
421 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
429 Preprocessing_Data_File
:=
430 new String'(Switch_Chars (Ptr .. Max));
433 -- Because we may store a longer switch (we normalize
434 -- to -gnatep=), use a local variable.
438 (1 .. Preprocessing_Data_File'Length + 8);
441 To_Store (1 .. 8) := "-gnatep=";
442 To_Store (9 .. Preprocessing_Data_File'Length + 8) :=
443 Preprocessing_Data_File.all;
444 Store_Compilation_Switch (To_Store);
450 Store_Switch := False;
451 Disable_Switch_Storing;
454 -- All other -gnate? switches are unassigned
460 -- -gnatE (dynamic elaboration checks)
464 Dynamic_Elaboration_Checks := True;
466 -- -gnatf (full error messages)
470 All_Errors_Mode := True;
472 -- Processing for F switch
476 External_Name_Exp_Casing := Uppercase;
477 External_Name_Imp_Casing := Uppercase;
479 -- Processing for g switch
484 Identifier_Character_Set := 'n
';
485 System_Extend_Unit := Empty;
486 Warning_Mode := Treat_As_Error;
488 -- Set default warnings (basically -gnatwa)
490 Check_Unreferenced := True;
491 Check_Unreferenced_Formals := True;
493 Constant_Condition_Warnings := True;
494 Implementation_Unit_Warnings := True;
495 Ineffective_Inline_Warnings := True;
496 Warn_On_Constant := True;
497 Warn_On_Export_Import := True;
498 Warn_On_Modified_Unread := True;
499 Warn_On_No_Value_Assigned := True;
500 Warn_On_Obsolescent_Feature := True;
501 Warn_On_Redundant_Constructs := True;
502 Warn_On_Unchecked_Conversion := True;
503 Warn_On_Unrecognized_Pragma := True;
505 Set_Default_Style_Check_Options;
507 -- Processing for G switch
511 Print_Generated_Code := True;
513 -- Processing for h switch
517 Usage_Requested := True;
519 -- Processing for H switch
525 -- Processing for i switch
533 C := Switch_Chars (Ptr);
543 Identifier_Character_Set := C;
550 -- Processing for k switch
554 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_File_Name_Length);
556 -- Processing for l switch
562 -- Processing for L switch
566 Zero_Cost_Exceptions_Set := True;
567 Zero_Cost_Exceptions_Val := False;
569 -- Processing for m switch
573 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
575 -- Processing for n switch
579 Inline_Active := True;
581 -- Processing for N switch
585 Inline_Active := True;
586 Front_End_Inlining := True;
588 -- Processing for o switch
592 Suppress_Options (Overflow_Check) := False;
593 Opt.Enable_Overflow_Checks := True;
595 -- Processing for O switch
598 Store_Switch := False;
600 Output_File_Name_Present := True;
602 -- Processing for p switch
606 Suppress_Options := (others => True);
607 Validity_Checks_On := False;
608 Opt.Suppress_Checks := True;
609 Opt.Enable_Overflow_Checks := False;
611 -- Processing for P switch
615 Polling_Required := True;
617 -- Processing for q switch
621 Try_Semantics := True;
623 -- Processing for q switch
627 Force_ALI_Tree_File := True;
628 Try_Semantics := True;
630 -- Processing for R switch
634 Back_Annotate_Rep_Info := True;
635 List_Representation_Info := 1;
637 while Ptr <= Max loop
638 C := Switch_Chars (Ptr);
640 if C in '1' .. '3' then
641 List_Representation_Info :=
642 Character'Pos (C) - Character'Pos ('0');
644 elsif Switch_Chars (Ptr) = 's
' then
645 List_Representation_Info_To_File := True;
647 elsif Switch_Chars (Ptr) = 'm
' then
648 List_Representation_Info_Mechanisms := True;
657 -- Processing for s switch
660 if not First_Switch then
662 ("-gnats must be first if combined with other switches");
666 Operating_Mode := Check_Syntax;
668 -- Processing for S switch
671 Print_Standard := True;
674 -- Processing for t switch
680 if Operating_Mode = Check_Semantics then
684 Back_Annotate_Rep_Info := True;
686 -- Processing for T switch
690 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor);
692 -- Processing for u switch
698 -- Processing for U switch
702 Unique_Error_Tag := True;
704 -- Processing for v switch
708 Verbose_Mode := True;
710 -- Processing for V switch
713 Store_Switch := False;
714 Storing (First_Stored) := 'V
';
725 Set_Validity_Check_Options
726 (Switch_Chars (Ptr .. Max), OK, Ptr);
732 for Index in First_Char + 1 .. Max loop
733 Storing (First_Stored + 1) :=
734 Switch_Chars (Index);
735 Store_Compilation_Switch
736 (Storing (Storing'First .. First_Stored + 1));
743 -- Processing for w switch
746 Store_Switch := False;
747 Storing (First_Stored) := 'w
';
754 while Ptr <= Max loop
755 C := Switch_Chars (Ptr);
759 Check_Unreferenced := True;
760 Check_Unreferenced_Formals := True;
762 Constant_Condition_Warnings := True;
763 Implementation_Unit_Warnings := True;
764 Ineffective_Inline_Warnings := True;
765 Warn_On_Constant := True;
766 Warn_On_Export_Import := True;
767 Warn_On_Modified_Unread := True;
768 Warn_On_No_Value_Assigned := True;
769 Warn_On_Obsolescent_Feature := True;
770 Warn_On_Redundant_Constructs := True;
771 Warn_On_Unchecked_Conversion := True;
772 Warn_On_Unrecognized_Pragma := True;
775 Check_Unreferenced := False;
776 Check_Unreferenced_Formals := False;
777 Check_Withs := False;
778 Constant_Condition_Warnings := False;
779 Elab_Warnings := False;
780 Implementation_Unit_Warnings := False;
781 Ineffective_Inline_Warnings := False;
782 Warn_On_Constant := False;
783 Warn_On_Dereference := False;
784 Warn_On_Export_Import := False;
785 Warn_On_Hiding := False;
786 Warn_On_Modified_Unread := False;
787 Warn_On_No_Value_Assigned := False;
788 Warn_On_Obsolescent_Feature := False;
789 Warn_On_Redundant_Constructs := False;
790 Warn_On_Unchecked_Conversion := False;
791 Warn_On_Unrecognized_Pragma := False;
794 Constant_Condition_Warnings := True;
797 Constant_Condition_Warnings := False;
800 Warn_On_Dereference := True;
803 Warn_On_Dereference := False;
806 Warning_Mode := Treat_As_Error;
809 Check_Unreferenced_Formals := True;
812 Check_Unreferenced_Formals := False;
815 Warn_On_Unrecognized_Pragma := True;
818 Warn_On_Unrecognized_Pragma := False;
821 Warn_On_Hiding := True;
824 Warn_On_Hiding := False;
827 Implementation_Unit_Warnings := True;
830 Implementation_Unit_Warnings := False;
833 Warn_On_Obsolescent_Feature := True;
836 Warn_On_Obsolescent_Feature := False;
839 Warn_On_Constant := True;
842 Warn_On_Constant := False;
845 Elab_Warnings := True;
848 Elab_Warnings := False;
851 Warn_On_Modified_Unread := True;
854 Warn_On_Modified_Unread := False;
857 Warning_Mode := Normal;
860 Address_Clause_Overlay_Warnings := True;
863 Address_Clause_Overlay_Warnings := False;
866 Ineffective_Inline_Warnings := True;
869 Ineffective_Inline_Warnings := False;
872 Warn_On_Redundant_Constructs := True;
875 Warn_On_Redundant_Constructs := False;
878 Warning_Mode := Suppress;
881 Check_Unreferenced := True;
883 Check_Unreferenced_Formals := True;
886 Check_Unreferenced := False;
887 Check_Withs := False;
888 Check_Unreferenced_Formals := False;
891 Warn_On_No_Value_Assigned := True;
894 Warn_On_No_Value_Assigned := False;
897 Warn_On_Export_Import := True;
900 Warn_On_Export_Import := False;
903 Warn_On_Unchecked_Conversion := True;
906 Warn_On_Unchecked_Conversion := False;
908 -- Allow and ignore 'w
' so that the old
909 -- format (e.g. -gnatwuwl) will work.
919 Storing (First_Stored + 1) := C;
920 Store_Compilation_Switch
921 (Storing (Storing'First .. First_Stored + 1));
929 -- Processing for W switch
938 for J in WC_Encoding_Method loop
939 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
940 Wide_Character_Encoding_Method := J;
943 elsif J = WC_Encoding_Method'Last then
948 Upper_Half_Encoding :=
949 Wide_Character_Encoding_Method in
950 WC_Upper_Half_Encoding_Method;
954 -- Processing for x switch
958 Xref_Active := False;
960 -- Processing for X switch
964 Extensions_Allowed := True;
965 Ada_Version := Ada_Version_Type'Last;
967 -- Processing for y switch
973 Set_Default_Style_Check_Options;
976 Store_Switch := False;
977 Storing (First_Stored) := 'y
';
981 Last_Stored : Integer;
984 Set_Style_Check_Options
985 (Switch_Chars (Ptr .. Max), OK, Ptr);
991 Ptr := First_Char + 1;
993 while Ptr <= Max loop
994 Last_Stored := First_Stored + 1;
995 Storing (Last_Stored) := Switch_Chars (Ptr);
997 if Switch_Chars (Ptr) = 'M
' then
1001 or else Switch_Chars (Ptr) not in '0' .. '9';
1002 Last_Stored := Last_Stored + 1;
1003 Storing (Last_Stored) := Switch_Chars (Ptr);
1010 Store_Compilation_Switch
1011 (Storing (Storing'First .. Last_Stored));
1016 -- Processing for z switch
1021 -- Allowed for compiler only if this is the only
1022 -- -z switch, we do not allow multiple occurrences
1024 if Distribution_Stub_Mode = No_Stubs then
1025 case Switch_Chars (Ptr) is
1027 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1030 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1040 -- Processing for Z switch
1044 Zero_Cost_Exceptions_Set := True;
1045 Zero_Cost_Exceptions_Val := True;
1047 -- Processing for 83 switch
1056 if Switch_Chars (Ptr) /= '3' then
1060 Ada_Version := Ada_83;
1063 -- Processing for 95 switch
1072 if Switch_Chars (Ptr) /= '5' then
1076 Ada_Version := Ada_95;
1079 -- Processing for 05 switch
1088 if Switch_Chars (Ptr) /= '5' then
1092 Ada_Version := Ada_05;
1095 -- Ignore extra switch character
1100 -- Anything else is an error (illegal switch character)
1107 if Store_Switch then
1108 Storing (First_Stored .. First_Stored + Ptr - First_Char - 1) :=
1109 Switch_Chars (First_Char .. Ptr - 1);
1110 Store_Compilation_Switch
1111 (Storing (Storing'First .. First_Stored + Ptr - First_Char - 1));
1114 First_Switch := False;
1119 Osint.Fail ("invalid switch: ", (1 => C));
1121 when Bad_Switch_Value =>
1122 Osint.Fail ("numeric value out of range for switch: ", (1 => C));
1124 when Missing_Switch_Value =>
1125 Osint.Fail ("missing numeric value for switch: ", (1 => C));
1127 end Scan_Front_End_Switches;