Commit a037f912 by Vincent Celier Committed by Arnaud Charlet

gprep.adb (Process_One_File): Call Prep.Preprocess with a Boolean variable...

2008-08-04  Vincent Celier  <celier@adacore.com>

	* gprep.adb (Process_One_File): Call Prep.Preprocess with a Boolean
	variable, but don't check the resulting value as it has no impact on
	the processing.
	
	* opt.ads:
	(Generate_Processed_File): New Boolean flag, set to True in the compiler
	when switch -gnateG is used.
	
	* prep.adb:
	(Preprocess): new Boolean out parameter Source_Modified. Set it to True
	when the source is modified by the preprocessor and there is no
	preprocessing errors.
	
	* prep.ads (Preprocess): new Boolean out parameter Source_Modified
	
	* sinput-l.adb:
	(Load_File): Output the result of preprocessing if the source text was
	modified.
	
	* switch-c.adb (Scan_Front_End_Switches): Recognize switch -gnateG
	
	* switch-m.adb (Normalize_Compiler_Switches): Normalize switch -gnateG
	
	* ug_words: Add VMS equivalent for -gnateG
	
	* vms_data.ads:
	Add VMS option /GENERATE_PROCESSED_SOURCE, equivalent to switch -gnateG

From-SVN: r138590
parent 762dffe7
2008-08-04 Vincent Celier <celier@adacore.com>
* gprep.adb (Process_One_File): Call Prep.Preprocess with a Boolean
variable, but don't check the resulting value as it has no impact on
the processing.
* opt.ads:
(Generate_Processed_File): New Boolean flag, set to True in the compiler
when switch -gnateG is used.
* prep.adb:
(Preprocess): new Boolean out parameter Source_Modified. Set it to True
when the source is modified by the preprocessor and there is no
preprocessing errors.
* prep.ads (Preprocess): new Boolean out parameter Source_Modified
* sinput-l.adb:
(Load_File): Output the result of preprocessing if the source text was
modified.
* switch-c.adb (Scan_Front_End_Switches): Recognize switch -gnateG
* switch-m.adb (Normalize_Compiler_Switches): Normalize switch -gnateG
* ug_words: Add VMS equivalent for -gnateG
* vms_data.ads:
Add VMS option /GENERATE_PROCESSED_SOURCE, equivalent to switch -gnateG
2008-08-04 Doug Rupp <rupp@adacore.com>
* gcc-interface/utils2.c:
......@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 2002-2007, Free Software Foundation, Inc. --
-- Copyright (C) 2002-2008, 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- --
......@@ -475,6 +475,9 @@ package body GPrep is
procedure Process_One_File is
Infile : Source_File_Index;
Modified : Boolean;
pragma Warnings (Off, Modified);
begin
-- Create the output file (fails if this does not work)
......@@ -515,7 +518,7 @@ package body GPrep is
-- Preprocess the input file
Prep.Preprocess;
Prep.Preprocess (Modified);
-- In verbose mode, if there is no error, report it
......
......@@ -528,6 +528,11 @@ package Opt is
-- the name is of the form .xxx, then to name.xxx where name is the source
-- file name with extension stripped.
Generate_Processed_File : Boolean := False;
-- GNAT
-- True when switch -gnateG is used. When True, create in a file
-- <source>.prep, if the source is preprocessed.
Generating_Code : Boolean := False;
-- GNAT
-- True if the frontend finished its work and has called the backend to
......
......@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 2002-2007, Free Software Foundation, Inc. --
-- Copyright (C) 2002-2008, 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- --
......@@ -106,9 +106,10 @@ package Prep is
-- Parse the definition file. The definition file must have already been
-- loaded and the scanner initialized.
procedure Preprocess;
procedure Preprocess (Source_Modified : out Boolean);
-- Preprocess the input file. The input file must have already been loaded
-- and the scanner initialized.
-- and the scanner initialized. Source_Modified is set to True iff the
-- preprocessor modified the source text.
procedure Check_Command_Line_Symbol_Definition
(Definition : String;
......
......@@ -28,6 +28,8 @@ with Atree; use Atree;
with Debug; use Debug;
with Einfo; use Einfo;
with Errout; use Errout;
with Fname; use Fname;
with Hostparm;
with Opt; use Opt;
with Osint; use Osint;
with Output; use Output;
......@@ -39,6 +41,8 @@ with Sinfo; use Sinfo;
with Snames; use Snames;
with System; use System;
with System.OS_Lib; use System.OS_Lib;
with Unchecked_Conversion;
package body Sinput.L is
......@@ -319,7 +323,7 @@ package body Sinput.L is
-- source will be the last created, and we will be able to replace it
-- and modify Hi without stepping on another buffer.
if T = Osint.Source then
if T = Osint.Source and then not Is_Internal_File_Name (N) then
Prepare_To_Preprocess
(Source => N, Preprocessing_Needed => Preprocessing_Needed);
end if;
......@@ -475,6 +479,8 @@ package body Sinput.L is
-- Saved state of the Style_Check flag (which needs to be
-- temporarily set to False during preprocessing, see below).
Modified : Boolean;
begin
-- If this is the first time we preprocess a source, allocate
-- the preprocessing buffer.
......@@ -512,7 +518,7 @@ package body Sinput.L is
Save_Style_Check := Opt.Style_Check;
Opt.Style_Check := False;
Preprocess;
Preprocess (Modified);
-- Reset the scanner to its standard behavior, and restore the
-- Style_Checks flag.
......@@ -531,6 +537,54 @@ package body Sinput.L is
return No_Source_File;
else
-- Output the result of the preprocessing, if requested and
-- the source has been modified by the preprocessing.
if Generate_Processed_File and then Modified then
declare
FD : File_Descriptor;
NB : Integer;
Status : Boolean;
begin
Get_Name_String (N);
if Hostparm.OpenVMS then
Add_Str_To_Name_Buffer ("_prep");
else
Add_Str_To_Name_Buffer (".prep");
end if;
Delete_File (Name_Buffer (1 .. Name_Len), Status);
FD :=
Create_New_File (Name_Buffer (1 .. Name_Len), Text);
Status := FD /= Invalid_FD;
if Status then
NB :=
Write
(FD,
Prep_Buffer (1)'Address,
Integer (Prep_Buffer_Last));
Status := NB = Integer (Prep_Buffer_Last);
end if;
if Status then
Close (FD, Status);
end if;
if not Status then
Errout.Error_Msg
("could not write processed file """ &
Name_Buffer (1 .. Name_Len) & '"',
Lo);
return No_Source_File;
end if;
end;
end if;
-- Set the new value of Hi
Hi := Lo + Source_Ptr (Prep_Buffer_Last);
......
......@@ -371,6 +371,16 @@ package body Switch.C is
Full_Path_Name_For_Brief_Errors := True;
return;
-- -gnateG (save preprocessor output)
when 'G' =>
if Ptr < Max then
Bad_Switch (Switch_Chars);
end if;
Generate_Processed_File := True;
Ptr := Ptr + 1;
-- -gnateI (index of unit in multi-unit source)
when 'I' =>
......
......@@ -267,14 +267,16 @@ package body Switch.M is
when 'e' =>
-- Only -gnateD and -gnatep= need storing in ALI file
-- Store -gnateD, -gnatep= and -gnateG in the ALI file.
-- The other -gnate switches do not need to be stored.
Storing (First_Stored) := 'e';
Ptr := Ptr + 1;
if Ptr > Max
or else (Switch_Chars (Ptr) /= 'D'
and then Switch_Chars (Ptr) /= 'p')
and then Switch_Chars (Ptr) /= 'G'
and then Switch_Chars (Ptr) /= 'p')
then
Last := 0;
return;
......@@ -292,7 +294,7 @@ package body Switch.M is
-- Processing for -gnatep=
else
elsif Switch_Chars (Ptr) = 'p' then
Ptr := Ptr + 1;
if Ptr = Max then
......@@ -316,6 +318,9 @@ package body Switch.M is
Switch_Chars (Ptr .. Max);
Add_Switch_Component (To_Store);
end;
elsif Switch_Chars (Ptr) = 'G' then
Add_Switch_Component ("-gnateG");
end if;
return;
......
......@@ -61,6 +61,7 @@ gcc -c ^ GNAT COMPILE
-gnatec ^ /CONFIGURATION_PRAGMAS_FILE
-gnateD ^ /SYMBOL_PREPROCESSING
-gnatef ^ /FULL_PATH_IN_BRIEF_MESSAGES
-gnateG ^ /GENERATE_PROCESSED_SOURCE
-gnatem ^ /MAPPING_FILE
-gnatep ^ /DATA_PREPROCESSING
-gnatE ^ /CHECKS=ELABORATION
......
......@@ -1526,6 +1526,14 @@ package VMS_Data is
-- /VERBOSE), then error lines start with the full path name of the
-- project file, rather than its simple file name.
S_GCC_Generate : aliased constant S := "/GENERATE_PROCESSED_SOURCE " &
"-gnateG";
-- /NOGENERATE_PROCESSED_SOURCE (D)
-- /GENERATE_PROCESSED_SOURCE
--
-- Generate a file <source>_prep if the integrated preprocessing
-- is modifying the source text.
S_GCC_GNAT : aliased constant S := "/GNAT_INTERNAL " &
"-gnatg";
-- /NOGNAT_INTERNAL (D)
......@@ -3311,6 +3319,7 @@ package VMS_Data is
S_GCC_Follow 'Access,
S_GCC_Force 'Access,
S_GCC_Full 'Access,
S_GCC_Generate'Access,
S_GCC_GNAT 'Access,
S_GCC_Help 'Access,
S_GCC_Ident 'Access,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment