1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 2001-2002 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
28 with Debug
; use Debug
;
30 with Osint
; use Osint
;
32 with Types
; use Types
;
33 with Validsw
; use Validsw
;
34 with Stylesw
; use Stylesw
;
36 with System
.WCh_Con
; use System
.WCh_Con
;
38 package body Switch
.C
is
40 -----------------------------
41 -- Scan_Front_End_Switches --
42 -----------------------------
44 procedure Scan_Front_End_Switches
(Switch_Chars
: String) is
45 Switch_Starts_With_Gnat
: Boolean;
46 -- True if first four switch characters are "gnat"
48 First_Switch
: Boolean := True;
49 -- False for all but first switch
51 Ptr
: Integer := Switch_Chars
'First;
52 Max
: constant Integer := Switch_Chars
'Last;
55 Store_Switch
: Boolean := True;
56 First_Char
: Integer := Ptr
;
57 Storing
: String := Switch_Chars
;
58 First_Stored
: Positive := Ptr
+ 1;
59 -- The above need comments ???
62 -- Skip past the initial character (must be the switch character)
70 -- Remove "gnat" from the switch, if present
72 Switch_Starts_With_Gnat
:=
73 Ptr
+ 3 <= Max
and then Switch_Chars
(Ptr
.. Ptr
+ 3) = "gnat";
75 if Switch_Starts_With_Gnat
then
80 -- Loop to scan through switches given in switch string
85 C
:= Switch_Chars
(Ptr
);
87 -- Processing for a switch
89 case Switch_Starts_With_Gnat
is
92 -- There are only two front-end switches that
93 -- do not start with -gnat, namely -I and --RTS
95 if Switch_Chars
(Ptr
) = 'I' then
96 Store_Switch
:= False;
104 -- Find out whether this is a -I- or regular -Ixxx switch
106 if Ptr
= Max
and then Switch_Chars
(Ptr
) = '-' then
107 Look_In_Primary_Dir
:= False;
110 Add_Src_Search_Dir
(Switch_Chars
(Ptr
.. Max
));
115 -- Processing of the --RTS switch. --RTS has been modified by
116 -- gcc and is now of the form -fRTS
117 elsif Ptr
+ 3 <= Max
and then
118 Switch_Chars
(Ptr
.. Ptr
+ 3) = "fRTS"
122 if Ptr
+ 4 > Max
or else Switch_Chars
(Ptr
+ 3) /= '=' then
123 Osint
.Fail
("missing path for --RTS");
126 -- valid --RTS switch
127 Opt
.No_Stdinc
:= True;
128 Opt
.RTS_Switch
:= True;
131 Src_Path_Name
: String_Ptr
:= Get_RTS_Search_Dir
132 (Switch_Chars
(Ptr
+ 4 .. Max
), Include
);
133 Lib_Path_Name
: String_Ptr
:= Get_RTS_Search_Dir
134 (Switch_Chars
(Ptr
+ 4 .. Max
), Objects
);
136 if Src_Path_Name
/= null and then
137 Lib_Path_Name
/= null
139 Add_Search_Dirs
(Src_Path_Name
, Include
);
140 Add_Search_Dirs
(Lib_Path_Name
, Objects
);
142 elsif Src_Path_Name
= null
143 and Lib_Path_Name
= null then
144 Osint
.Fail
("RTS path not valid: missing " &
145 "adainclude and adalib directories");
146 elsif Src_Path_Name
= null then
147 Osint
.Fail
("RTS path not valid: missing " &
148 "adainclude directory");
149 elsif Lib_Path_Name
= null then
150 Osint
.Fail
("RTS path not valid: missing " &
160 -- Process -gnat* options
166 Assertions_Enabled
:= True;
168 -- Processing for A switch
172 Config_File
:= False;
174 -- Processing for b switch
178 Brief_Output
:= True;
180 -- Processing for c switch
183 if not First_Switch
then
185 ("-gnatc myust be first if combined with other switches");
189 Operating_Mode
:= Check_Semantics
;
191 -- Processing for C switch
195 Compress_Debug_Names
:= True;
197 -- Processing for d switch
200 Store_Switch
:= False;
201 Storing
(First_Stored
) := 'd';
202 -- Note: for the debug switch, the remaining characters in this
203 -- switch field must all be debug flags, since all valid switch
204 -- characters are also valid debug characters.
206 -- Loop to scan out debug flags
210 C
:= Switch_Chars
(Ptr
);
211 exit when C
= ASCII
.NUL
or else C
= '/' or else C
= '-';
213 if C
in '1' .. '9' or else
214 C
in 'a' .. 'z' or else
218 Storing
(First_Stored
+ 1) := C
;
219 Store_Compilation_Switch
220 (Storing
(Storing
'First .. First_Stored
+ 1));
227 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
228 -- is for backwards compatibility with old versions and usage.
230 if Debug_Flag_XX
then
231 Zero_Cost_Exceptions_Set
:= True;
232 Zero_Cost_Exceptions_Val
:= True;
237 -- Processing for D switch
242 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
243 -- generation in the ali file) since otherwise this generation
244 -- gets confused by the "wrong" Sloc values put in the tree.
246 Debug_Generated_Code
:= True;
247 Xref_Active
:= False;
248 Set_Debug_Flag
('g');
250 -- Processing for e switch
259 case Switch_Chars
(Ptr
) is
261 -- Configuration pragmas
264 Store_Switch
:= False;
272 new String'(Switch_Chars (Ptr .. Max));
279 Store_Switch := False;
287 new String'(Switch_Chars
(Ptr
.. Max
));
294 -- Processing for E switch
298 Dynamic_Elaboration_Checks
:= True;
300 -- Processing for f switch
304 All_Errors_Mode
:= True;
306 -- Processing for F switch
310 External_Name_Exp_Casing
:= Uppercase
;
311 External_Name_Imp_Casing
:= Uppercase
;
313 -- Processing for g switch
318 Identifier_Character_Set
:= 'n';
319 Warning_Mode
:= Treat_As_Error
;
320 Check_Unreferenced
:= True;
323 Set_Default_Style_Check_Options
;
325 -- Processing for G switch
329 Print_Generated_Code
:= True;
331 -- Processing for h switch
335 Usage_Requested
:= True;
337 -- Processing for H switch
343 -- Processing for i switch
351 C
:= Switch_Chars
(Ptr
);
361 Identifier_Character_Set
:= C
;
368 -- Processing for k switch
372 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Maximum_File_Name_Length
);
374 -- Processing for l switch
380 -- Processing for L switch
384 Zero_Cost_Exceptions_Set
:= True;
385 Zero_Cost_Exceptions_Val
:= False;
387 -- Processing for m switch
391 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Maximum_Errors
);
393 -- Processing for n switch
397 Inline_Active
:= True;
399 -- Processing for N switch
403 Inline_Active
:= True;
404 Front_End_Inlining
:= True;
406 -- Processing for o switch
410 Suppress_Options
.Overflow_Checks
:= False;
411 Opt
.Enable_Overflow_Checks
:= True;
413 -- Processing for O switch
417 Output_File_Name_Present
:= True;
419 -- Processing for p switch
423 Suppress_Options
.Access_Checks
:= True;
424 Suppress_Options
.Accessibility_Checks
:= True;
425 Suppress_Options
.Discriminant_Checks
:= True;
426 Suppress_Options
.Division_Checks
:= True;
427 Suppress_Options
.Elaboration_Checks
:= True;
428 Suppress_Options
.Index_Checks
:= True;
429 Suppress_Options
.Length_Checks
:= True;
430 Suppress_Options
.Overflow_Checks
:= True;
431 Suppress_Options
.Range_Checks
:= True;
432 Suppress_Options
.Storage_Checks
:= True;
433 Suppress_Options
.Tag_Checks
:= True;
435 Validity_Checks_On
:= False;
436 Opt
.Suppress_Checks
:= True;
437 Opt
.Enable_Overflow_Checks
:= False;
439 -- Processing for P switch
443 Polling_Required
:= True;
445 -- Processing for q switch
449 Try_Semantics
:= True;
451 -- Processing for q switch
455 Force_ALI_Tree_File
:= True;
456 Try_Semantics
:= True;
458 -- Processing for R switch
462 Back_Annotate_Rep_Info
:= True;
465 and then Switch_Chars
(Ptr
) in '0' .. '9'
467 C
:= Switch_Chars
(Ptr
);
469 if C
in '4' .. '9' then
472 List_Representation_Info
:=
473 Character'Pos (C
) - Character'Pos ('0');
477 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = 's' then
480 if List_Representation_Info
/= 0 then
481 List_Representation_Info_To_File
:= True;
486 List_Representation_Info
:= 1;
489 -- Processing for s switch
492 if not First_Switch
then
494 ("-gnats myust be first if combined with other switches");
498 Operating_Mode
:= Check_Syntax
;
500 -- Processing for t switch
505 Back_Annotate_Rep_Info
:= True;
507 -- Processing for T switch
511 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Table_Factor
);
513 -- Processing for u switch
519 -- Processing for U switch
523 Unique_Error_Tag
:= True;
525 -- Processing for v switch
529 Verbose_Mode
:= True;
531 -- Processing for V switch
534 Store_Switch
:= False;
535 Storing
(First_Stored
) := 'V';
546 Set_Validity_Check_Options
547 (Switch_Chars
(Ptr
.. Max
), OK
, Ptr
);
553 for Index
in First_Char
+ 1 .. Max
loop
554 Storing
(First_Stored
+ 1) :=
555 Switch_Chars
(Index
);
556 Store_Compilation_Switch
557 (Storing
(Storing
'First .. First_Stored
+ 1));
564 -- Processing for w switch
567 Store_Switch
:= False;
568 Storing
(First_Stored
) := 'w';
575 while Ptr
<= Max
loop
576 C
:= Switch_Chars
(Ptr
);
581 Constant_Condition_Warnings
:= True;
582 Elab_Warnings
:= True;
583 Check_Unreferenced
:= True;
585 Check_Unreferenced_Formals
:= True;
586 Implementation_Unit_Warnings
:= True;
587 Ineffective_Inline_Warnings
:= True;
588 Warn_On_Redundant_Constructs
:= True;
591 Constant_Condition_Warnings
:= False;
592 Elab_Warnings
:= False;
593 Check_Unreferenced
:= False;
594 Check_Withs
:= False;
595 Check_Unreferenced_Formals
:= False;
596 Implementation_Unit_Warnings
:= False;
597 Warn_On_Biased_Rounding
:= False;
598 Warn_On_Dereference
:= False;
599 Warn_On_Hiding
:= False;
600 Warn_On_Redundant_Constructs
:= False;
601 Ineffective_Inline_Warnings
:= False;
604 Warn_On_Biased_Rounding
:= True;
607 Warn_On_Biased_Rounding
:= False;
610 Constant_Condition_Warnings
:= True;
613 Constant_Condition_Warnings
:= False;
616 Warn_On_Dereference
:= True;
619 Warn_On_Dereference
:= False;
622 Warning_Mode
:= Treat_As_Error
;
625 Check_Unreferenced_Formals
:= True;
628 Check_Unreferenced_Formals
:= False;
631 Warn_On_Hiding
:= True;
634 Warn_On_Hiding
:= False;
637 Implementation_Unit_Warnings
:= True;
640 Implementation_Unit_Warnings
:= False;
643 Elab_Warnings
:= True;
646 Elab_Warnings
:= False;
649 Address_Clause_Overlay_Warnings
:= True;
652 Address_Clause_Overlay_Warnings
:= False;
655 Ineffective_Inline_Warnings
:= True;
658 Ineffective_Inline_Warnings
:= False;
661 Warn_On_Redundant_Constructs
:= True;
664 Warn_On_Redundant_Constructs
:= False;
667 Warning_Mode
:= Suppress
;
670 Check_Unreferenced
:= True;
672 Check_Unreferenced_Formals
:= True;
675 Check_Unreferenced
:= False;
676 Check_Withs
:= False;
677 Check_Unreferenced_Formals
:= False;
679 -- Allow and ignore 'w' so that the old
680 -- format (e.g. -gnatwuwl) will work.
690 Storing
(First_Stored
+ 1) := C
;
691 Store_Compilation_Switch
692 (Storing
(Storing
'First .. First_Stored
+ 1));
700 -- Processing for W switch
709 for J
in WC_Encoding_Method
loop
710 if Switch_Chars
(Ptr
) = WC_Encoding_Letters
(J
) then
711 Wide_Character_Encoding_Method
:= J
;
714 elsif J
= WC_Encoding_Method
'Last then
719 Upper_Half_Encoding
:=
720 Wide_Character_Encoding_Method
in
721 WC_Upper_Half_Encoding_Method
;
725 -- Processing for x switch
729 Xref_Active
:= False;
731 -- Processing for X switch
735 Extensions_Allowed
:= True;
737 -- Processing for y switch
743 Set_Default_Style_Check_Options
;
746 Store_Switch
:= False;
747 Storing
(First_Stored
) := 'y';
751 Last_Stored
: Integer;
754 Set_Style_Check_Options
755 (Switch_Chars
(Ptr
.. Max
), OK
, Ptr
);
761 Ptr
:= First_Char
+ 1;
763 while Ptr
<= Max
loop
764 Last_Stored
:= First_Stored
+ 1;
765 Storing
(Last_Stored
) := Switch_Chars
(Ptr
);
767 if Switch_Chars
(Ptr
) = 'M' then
771 or else Switch_Chars
(Ptr
) not in '0' .. '9';
772 Last_Stored
:= Last_Stored
+ 1;
773 Storing
(Last_Stored
) := Switch_Chars
(Ptr
);
780 Store_Compilation_Switch
781 (Storing
(Storing
'First .. Last_Stored
));
786 -- Processing for z switch
791 -- Allowed for compiler, only if this is the only
792 -- -z switch, we do not allow multiple occurrences
794 if Distribution_Stub_Mode
= No_Stubs
then
795 case Switch_Chars
(Ptr
) is
797 Distribution_Stub_Mode
:= Generate_Receiver_Stub_Body
;
800 Distribution_Stub_Mode
:= Generate_Caller_Stub_Body
;
810 -- Processing for Z switch
814 Zero_Cost_Exceptions_Set
:= True;
815 Zero_Cost_Exceptions_Val
:= True;
817 -- Processing for 83 switch
827 if Switch_Chars
(Ptr
) /= '3' then
835 -- Ignore extra switch character
840 -- Anything else is an error (illegal switch character)
848 Storing
(First_Stored
.. First_Stored
+ Ptr
- First_Char
- 1) :=
849 Switch_Chars
(First_Char
.. Ptr
- 1);
850 Store_Compilation_Switch
851 (Storing
(Storing
'First .. First_Stored
+ Ptr
- First_Char
- 1));
854 First_Switch
:= False;
859 Osint
.Fail
("invalid switch: ", (1 => C
));
861 when Bad_Switch_Value
=>
862 Osint
.Fail
("numeric value too big for switch: ", (1 => C
));
864 when Missing_Switch_Value
=>
865 Osint
.Fail
("missing numeric value for switch: ", (1 => C
));
867 end Scan_Front_End_Switches
;