-- --
-- B o d y --
-- --
--- Copyright (C) 2001-2013, Free Software Foundation, Inc. --
+-- Copyright (C) 2001-2016, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
with Osint; use Osint;
with Opt; use Opt;
with Stylesw; use Stylesw;
+with Targparm; use Targparm;
with Ttypes; use Ttypes;
with Validsw; use Validsw;
with Warnsw; use Warnsw;
with Ada.Unchecked_Deallocation;
+
with System.WCh_Con; use System.WCh_Con;
+with System.OS_Lib;
package body Switch.C is
or else Switch_Chars (Ptr + 3) /= '='
then
Osint.Fail ("missing path for --RTS");
- else
- -- Check that this is the first time --RTS is specified or if
- -- it is not the first time, the same path has been specified.
- if RTS_Specified = null then
- RTS_Specified := new String'(Switch_Chars (Ptr + 4 .. Max));
+ else
+ declare
+ Runtime_Dir : String_Access;
+ begin
+ if System.OS_Lib.Is_Absolute_Path
+ (Switch_Chars (Ptr + 4 .. Max))
+ then
+ Runtime_Dir :=
+ new String'(System.OS_Lib.Normalize_Pathname
+ (Switch_Chars (Ptr + 4 .. Max)));
+ else
+ Runtime_Dir :=
+ new String'(Switch_Chars (Ptr + 4 .. Max));
+ end if;
- elsif
- RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
- then
- Osint.Fail ("--RTS cannot be specified multiple times");
- end if;
+ -- Valid --RTS switch
- -- Valid --RTS switch
+ Opt.No_Stdinc := True;
+ Opt.RTS_Switch := True;
- Opt.No_Stdinc := True;
- Opt.RTS_Switch := True;
+ RTS_Src_Path_Name :=
+ Get_RTS_Search_Dir (Runtime_Dir.all, Include);
- RTS_Src_Path_Name :=
- Get_RTS_Search_Dir
- (Switch_Chars (Ptr + 4 .. Max), Include);
+ RTS_Lib_Path_Name :=
+ Get_RTS_Search_Dir (Runtime_Dir.all, Objects);
- RTS_Lib_Path_Name :=
- Get_RTS_Search_Dir
- (Switch_Chars (Ptr + 4 .. Max), Objects);
+ if RTS_Specified /= null then
+ if RTS_Src_Path_Name = null
+ or else RTS_Lib_Path_Name = null
+ or else
+ System.OS_Lib.Normalize_Pathname
+ (RTS_Specified.all) /=
+ System.OS_Lib.Normalize_Pathname
+ (RTS_Lib_Path_Name.all)
+ then
+ Osint.Fail
+ ("--RTS cannot be specified multiple times");
+ end if;
- if RTS_Src_Path_Name /= null
- and then RTS_Lib_Path_Name /= null
- then
- -- Store the -fRTS switch (Note: Store_Compilation_Switch
- -- changes -fRTS back into --RTS for the actual output).
+ elsif RTS_Src_Path_Name /= null
+ and then RTS_Lib_Path_Name /= null
+ then
+ -- Store the -fRTS switch (Note: Store_Compilation_Switch
+ -- changes -fRTS back into --RTS for the actual output).
- Store_Compilation_Switch (Switch_Chars);
+ Store_Compilation_Switch (Switch_Chars);
+ RTS_Specified := new String'(RTS_Lib_Path_Name.all);
- elsif RTS_Src_Path_Name = null
- and then RTS_Lib_Path_Name = null
- then
- Osint.Fail ("RTS path not valid: missing " &
- "adainclude and adalib directories");
+ elsif RTS_Src_Path_Name = null
+ and then RTS_Lib_Path_Name = null
+ then
+ Osint.Fail ("RTS path not valid: missing "
+ & "adainclude and adalib directories");
- elsif RTS_Src_Path_Name = null then
- Osint.Fail ("RTS path not valid: missing " &
- "adainclude directory");
+ elsif RTS_Src_Path_Name = null then
+ Osint.Fail ("RTS path not valid: missing "
+ & "adainclude directory");
- elsif RTS_Lib_Path_Name = null then
- Osint.Fail ("RTS path not valid: missing " &
- "adalib directory");
- end if;
+ elsif RTS_Lib_Path_Name = null then
+ Osint.Fail ("RTS path not valid: missing "
+ & "adalib directory");
+ end if;
+ end;
end if;
-- There are no other switches not starting with -gnat
("-gnatc must be first if combined with other switches");
end if;
- -- Not allowed if previous -gnatR given
-
- if List_Representation_Info /= 0
- or else List_Representation_Info_Mechanisms
- then
- Osint.Fail
- ("-gnatc not allowed since -gnatR given previously");
- end if;
-
Ptr := Ptr + 1;
Operating_Mode := Check_Semantics;
if C = 'b'
and then (Ptr /= First_Ptr + 1
- or else not First_Switch)
+ or else not First_Switch)
then
Osint.Fail
("-gnatd.b must be first if combined "
return;
- -- -gnateC switch (CodePeer SCIL generation)
-
- -- Not enabled for now, keep it for later???
- -- use -gnatd.I only for now
+ -- -gnateC switch (generate CodePeer messages)
- -- when 'C' =>
- -- Ptr := Ptr + 1;
- -- Generate_SCIL := True;
+ when 'C' =>
+ Ptr := Ptr + 1;
+ Generate_CodePeer_Messages := True;
-- -gnated switch (disable atomic synchronization)
when 'F' =>
Ptr := Ptr + 1;
- Check_Float_Overflow := True;
+ Check_Float_Overflow := not Machine_Overflows_On_Target;
+
+ -- -gnateg (generate C code)
+
+ when 'g' =>
+ -- Special check, -gnateg must occur after -gnatc
+
+ if Operating_Mode /= Check_Semantics then
+ Osint.Fail
+ ("gnateg requires previous occurrence of -gnatc");
+ end if;
+
+ Generate_C_Code := True;
+ Ptr := Ptr + 1;
-- -gnateG (save preprocessor output)
Ptr := Ptr + 1;
Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
+ -- -gnatel
+
+ when 'l' =>
+ Ptr := Ptr + 1;
+ Elab_Info_Messages := True;
+
+ -- -gnateL
+
+ when 'L' =>
+ Ptr := Ptr + 1;
+ Elab_Info_Messages := False;
+
-- -gnatem (mapping file)
when 'm' =>
-- -gnateS (generate SCO information)
-- Include Source Coverage Obligation information in ALI
- -- files for use by source coverage analysis tools (xcov).
+ -- files for use by source coverage analysis tools
+ -- (gnatcov) (equivalent to -fdump-scos, provided for
+ -- backwards compatibility).
when 'S' =>
Generate_SCO := True;
when 'g' =>
Ptr := Ptr + 1;
GNAT_Mode := True;
+ GNAT_Mode_Config := True;
Identifier_Character_Set := 'n';
System_Extend_Unit := Empty;
Warning_Mode := Treat_As_Error;
Style_Check_Main := True;
-
- -- Set Ada 2012 mode explicitly. We don't want to rely on the
- -- implicit setting here, since for example, we want
- -- Preelaborate_05 treated as Preelaborate
-
Ada_Version := Ada_2012;
Ada_Version_Explicit := Ada_2012;
Ada_Version_Pragma := Empty;
when 'o' =>
Ptr := Ptr + 1;
- Suppress_Options.Suppress (Overflow_Check) := False;
- -- Case of no digits after the -gnato
+ -- Case of -gnato0 (overflow checking turned off)
+
+ if Ptr <= Max and then Switch_Chars (Ptr) = '0' then
+ Ptr := Ptr + 1;
+ Suppress_Options.Suppress (Overflow_Check) := True;
+
+ -- We set strict mode in case overflow checking is turned
+ -- on locally (also records that we had a -gnato switch).
- if Ptr > Max or else Switch_Chars (Ptr) not in '1' .. '3' then
Suppress_Options.Overflow_Mode_General := Strict;
Suppress_Options.Overflow_Mode_Assertions := Strict;
- -- At least one digit after the -gnato
+ -- All cases other than -gnato0 (overflow checking turned on)
else
- -- Handle first digit after -gnato
+ Suppress_Options.Suppress (Overflow_Check) := False;
- Suppress_Options.Overflow_Mode_General :=
- Get_Overflow_Mode (Switch_Chars (Ptr));
- Ptr := Ptr + 1;
-
- -- Only one digit after -gnato, set assertions mode to
- -- be the same as general mode.
+ -- Case of no digits after the -gnato
if Ptr > Max
or else Switch_Chars (Ptr) not in '1' .. '3'
then
- Suppress_Options.Overflow_Mode_Assertions :=
- Suppress_Options.Overflow_Mode_General;
+ Suppress_Options.Overflow_Mode_General := Strict;
+ Suppress_Options.Overflow_Mode_Assertions := Strict;
- -- Process second digit after -gnato
+ -- At least one digit after the -gnato
else
- Suppress_Options.Overflow_Mode_Assertions :=
+ -- Handle first digit after -gnato
+
+ Suppress_Options.Overflow_Mode_General :=
Get_Overflow_Mode (Switch_Chars (Ptr));
Ptr := Ptr + 1;
+
+ -- Only one digit after -gnato, set assertions mode to be
+ -- the same as general mode.
+
+ if Ptr > Max
+ or else Switch_Chars (Ptr) not in '1' .. '3'
+ then
+ Suppress_Options.Overflow_Mode_Assertions :=
+ Suppress_Options.Overflow_Mode_General;
+
+ -- Process second digit after -gnato
+
+ else
+ Suppress_Options.Overflow_Mode_Assertions :=
+ Get_Overflow_Mode (Switch_Chars (Ptr));
+ Ptr := Ptr + 1;
+ end if;
end if;
end if;
Validity_Checks_On := False;
Opt.Suppress_Checks := True;
+
+ -- Set overflow mode checking to strict in case it gets
+ -- turned on locally (also signals that overflow checking
+ -- has been specifically turned off).
+
+ Suppress_Options.Overflow_Mode_General := Strict;
+ Suppress_Options.Overflow_Mode_Assertions := Strict;
end if;
-- -gnatP (periodic poll)
("-gnatR not permitted since -gnatD given previously");
end if;
- -- Not allowed if previous -gnatc was given, since we must
- -- call the code generator to determine rep information.
-
- if Operating_Mode = Check_Semantics then
- Osint.Fail
- ("-gnatR not permitted since -gnatc given previously");
- end if;
-
-- Set to annotate rep info, and set default -gnatR mode
Back_Annotate_Rep_Info := True;
Ptr := Ptr + 1;
- if Switch_Chars (Ptr) /= '3' then
+ if Switch_Chars (Ptr) /= '3' or else Latest_Ada_Only then
Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
else
Ptr := Ptr + 1;
Ptr := Ptr + 1;
- if Switch_Chars (Ptr) /= '5' then
+ if Switch_Chars (Ptr) /= '5' or else Latest_Ada_Only then
Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
else
Ptr := Ptr + 1;
Ptr := Ptr + 1;
- if Switch_Chars (Ptr) /= '5' then
+ if Switch_Chars (Ptr) /= '5' or else Latest_Ada_Only then
Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
else
Ptr := Ptr + 1;
if Ptr > Max - 3 then
Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
- elsif Switch_Chars (Ptr .. Ptr + 3) = "2005" then
+ elsif Switch_Chars (Ptr .. Ptr + 3) = "2005"
+ and then not Latest_Ada_Only
+ then
Ada_Version := Ada_2005;
elsif Switch_Chars (Ptr .. Ptr + 3) = "2012" then