summaryrefslogtreecommitdiff
path: root/gcc/ada/sinput-l.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2008-08-04 09:17:44 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2008-08-04 09:17:44 +0000
commit938d8e9f0d95bd35699cba2357fee68e18fe556e (patch)
tree3c10c3eda55b5d4bd88c5ae29f4d8dba412f8e42 /gcc/ada/sinput-l.adb
parented92d2e057b4a40cc025ee14ae46200c7093693f (diff)
downloadgcc-938d8e9f0d95bd35699cba2357fee68e18fe556e.tar.gz
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 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@138590 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/sinput-l.adb')
-rw-r--r--gcc/ada/sinput-l.adb58
1 files changed, 56 insertions, 2 deletions
diff --git a/gcc/ada/sinput-l.adb b/gcc/ada/sinput-l.adb
index eee61f664e0..8bb6778fbd7 100644
--- a/gcc/ada/sinput-l.adb
+++ b/gcc/ada/sinput-l.adb
@@ -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);