[PolyORB-users] Temporary Files in Idl_Fe.Lexer get wrong
filenames with mingw build
Vadim Godunko
vgodunko at rost.ru
Thu Dec 16 21:52:14 CET 2004
Martin Krischik wrote:
>
> idlac won't compile any files. With each run two temporary files are created -
> on ending on ".exe" the other one beeing empty.
>
Martin, can you please test attached patch without your patch?
--
Vadim Godunko
-------------- next part --------------
Index: MANIFEST
===================================================================
RCS file: /cvsroot/polyorb-ncsl/MANIFEST,v
retrieving revision 1.1.1.16
diff -u -r1.1.1.16 MANIFEST
--- MANIFEST 16 Dec 2004 06:53:59 -0000 1.1.1.16
+++ MANIFEST 16 Dec 2004 20:31:11 -0000
@@ -52,6 +52,8 @@
compilers/idlac/idl_fe-debug.ads
compilers/idlac/idl_fe-display_tree.adb
compilers/idlac/idl_fe-display_tree.ads
+compilers/idlac/idl_fe-files.adb
+compilers/idlac/idl_fe-files.ads
compilers/idlac/idl_fe-lexer.adb
compilers/idlac/idl_fe-lexer.ads
compilers/idlac/idl_fe-parser.adb
Index: compilers/idlac/idl_fe-files.adb
===================================================================
RCS file: compilers/idlac/idl_fe-files.adb
diff -N compilers/idlac/idl_fe-files.adb
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ compilers/idlac/idl_fe-files.adb 16 Dec 2004 20:25:48 -0000
@@ -0,0 +1,192 @@
+
+with Ada.Command_Line;
+
+with GNAT.Command_Line;
+with GNAT.Directory_Operations;
+with GNAT.OS_Lib;
+with GNAT.Table;
+
+with Errors;
+with Platform;
+
+package body Idl_Fe.Files is
+
+ use GNAT.Directory_Operations;
+ use GNAT.OS_Lib;
+
+ IDL_File_Suffix : constant String := ".idl";
+
+ package Search_Path is
+ new GNAT.Table
+ (Table_Component_Type => String_Access,
+ Table_Index_Type => Natural,
+ Table_Low_Bound => Natural'First + 1,
+ Table_Initial => 10,
+ Table_Increment => 100);
+ -- Search paths always stored in table with directory separator at the
+ -- end.
+
+ ---------------------
+ -- Add_Search_Path --
+ ---------------------
+
+ procedure Add_Search_Path
+ (Path : in String;
+ Success : out Boolean)
+ is
+ begin
+ if Is_Directory (Path) then
+ if Path (Path'Last) = Dir_Separator then
+ Search_Path.Append (new String'(Path));
+ else
+ Search_Path.Append (new String'(Path & Dir_Separator));
+ end if;
+ Success := True;
+ else
+ Success := False;
+ end if;
+ end Add_Search_Path;
+
+ ---------------------
+ -- Search_IDL_File --
+ ---------------------
+
+ function Search_IDL_File (File_Name : in String) return String is
+ begin
+ -- If file can't have IDL file extension then add it.
+ if File_Extension (File_Name) /= IDL_File_Suffix then
+ return Search_IDL_File (File_Name & IDL_File_Suffix);
+ end if;
+
+ -- If File_Name have directory perfix then check file existence
+ -- end return File_Name as result.
+ if Dir_Name (File_Name) /= Get_Current_Dir then
+ if Is_Regular_File (File_Name) then
+ return File_Name;
+ else
+ return "";
+ end if;
+ end if;
+
+ for J in Search_Path.First .. Search_Path.Last loop
+ declare
+ Full_Path : constant String
+ := Search_Path.Table (J).all & File_Name;
+
+ begin
+ if Is_Regular_File (Full_Path) then
+ return Full_Path;
+ end if;
+ end;
+ end loop;
+
+ return "";
+ end Search_IDL_File;
+
+ ---------------------
+ -- Preprocess_File --
+ ---------------------
+
+ function Preprocess_File (File_Name : in String) return String is
+
+ use Ada.Command_Line;
+ use GNAT.Command_Line;
+
+ CPP_Arg_List : constant Argument_List_Access
+ := Argument_String_To_List (Platform.CXX_Preprocessor);
+
+ Output_File_Name : Temp_File_Name;
+ Args : Argument_List (1 .. 128);
+ Arg_Count : Natural := Args'First - 1;
+
+ procedure Add_Argument (Arg : in String);
+
+ ------------------
+ -- Add_Argument --
+ ------------------
+
+ procedure Add_Argument (Arg : in String) is
+ begin
+ Arg_Count := Arg_Count + 1;
+ Args (Arg_Count) := new String'(Arg);
+ end Add_Argument;
+
+ begin
+ -- Create temporary file.
+ declare
+ Fd : File_Descriptor;
+ begin
+ Create_Temp_File (Fd, Output_File_Name);
+ if Fd = Invalid_FD then
+ Errors.Error
+ (Base_Name (Command_Name)
+ & ": cannot create temporary file name",
+ Errors.Fatal,
+ Errors.No_Location);
+ return "";
+ end if;
+
+ -- We don't need the file descriptor
+ Close (Fd);
+ end;
+
+ -- Add platform specific C++ preprocessor arguments as well as C++
+ -- preprocessor command name.
+ for J in CPP_Arg_List'First + 1 .. CPP_Arg_List'Last loop
+ Add_Argument (CPP_Arg_List (J).all);
+ end loop;
+
+ -- Pass user options to the preprocessor.
+ Goto_Section ("cppargs");
+ while Getopt ("*") /= ASCII.Nul loop
+ Add_Argument (Full_Switch);
+ end loop;
+
+ -- Add all search paths.
+ for J in Search_Path.First .. Search_Path.Last loop
+ Add_Argument ("-I");
+ Add_Argument (Search_Path.Table (J).all);
+ end loop;
+
+ -- Always add the current directory at the end of the include list
+ Add_Argument ("-I");
+ Add_Argument (".");
+
+ -- Add output and source file names.
+ Add_Argument ("-o");
+ Add_Argument (Output_File_Name & Platform.CXX_Preprocessor_Suffix);
+ Add_Argument (File_Name);
+
+ declare
+ Preprocessor_Full_Pathname : constant String_Access
+ := Locate_Exec_On_Path (CPP_Arg_List (CPP_Arg_List'First).all);
+
+ Spawn_Result : Boolean;
+
+ begin
+ if Preprocessor_Full_Pathname = null then
+ Errors.Error
+ ("Cannot find preprocessor "
+ & "'" & CPP_Arg_List (CPP_Arg_List'First).all & "'",
+ Errors.Fatal,
+ Errors.No_Location);
+ return "";
+ end if;
+
+ Spawn (Preprocessor_Full_Pathname.all,
+ Args (Args'First .. Arg_Count),
+ Spawn_Result);
+
+ if not Spawn_Result then
+ Errors.Error
+ (Base_Name (Command_Name) & ": preprocessor failed",
+ Errors.Fatal,
+ Errors.No_Location);
+ return "";
+ end if;
+ end;
+
+ return Output_File_Name & Platform.CXX_Preprocessor_Suffix;
+ end Preprocess_File;
+
+end Idl_Fe.Files;
Index: compilers/idlac/idl_fe-files.ads
===================================================================
RCS file: compilers/idlac/idl_fe-files.ads
diff -N compilers/idlac/idl_fe-files.ads
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ compilers/idlac/idl_fe-files.ads 16 Dec 2004 20:27:36 -0000
@@ -0,0 +1,24 @@
+
+-- This package containt different utilities for file manipulation:
+-- - seaching included/imported files with substituting IDL file extensions;
+-- - preprocessing files;
+
+-- Most of this functionality moved from idlac driver and idl_fe-lexer.
+
+package Idl_Fe.Files is
+
+ procedure Add_Search_Path
+ (Path : in String;
+ Success : out Boolean);
+ -- Add IDL files search path. If path don't exists or not a direcotry
+ -- then Success is False.
+
+ function Search_IDL_File (File_Name : in String) return String;
+ -- Search file in search paths and return file path. Return empty
+ -- string if file not found. Append IDL file suffix if it absent.
+
+ function Preprocess_File (File_Name : in String) return String;
+ -- Call the C++ preprocessor for processing defined file. Return
+ -- file name of temporary file or empty string if something failed.
+
+end Idl_Fe.Files;
Index: compilers/idlac/idl_fe-lexer.adb
===================================================================
RCS file: /cvsroot/polyorb-ncsl/compilers/idlac/idl_fe-lexer.adb,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 idl_fe-lexer.adb
--- compilers/idlac/idl_fe-lexer.adb 16 Dec 2004 06:54:03 -0000 1.1.1.4
+++ compilers/idlac/idl_fe-lexer.adb 16 Dec 2004 20:26:06 -0000
@@ -33,7 +33,6 @@
-- $Perforce: //droopi/main/compilers/idlac/idl_fe-lexer.adb#16 $
-with Ada.Command_Line;
with Ada.Text_IO;
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
with Ada.Characters.Handling;
@@ -41,7 +40,6 @@
with Ada.Strings;
with Ada.Strings.Maps;
-with GNAT.Command_Line;
with GNAT.Case_Util;
with GNAT.OS_Lib;
with GNAT.Directory_Operations;
@@ -49,10 +47,9 @@
with Idl_Fe.Debug;
pragma Elaborate_All (Idl_Fe.Debug);
+with Idl_Fe.Files;
with Idl_Fe.Types; use Idl_Fe.Types;
-with Platform;
-
package body Idl_Fe.Lexer is
-----------
@@ -163,6 +160,9 @@
-- are used to memorize the begining and the end of an
-- identifier for example.
+ Idl_File : Ada.Text_IO.File_Type;
+ -- Currently processed file
+
------------------------
-- Set_Token_Location --
------------------------
@@ -1164,33 +1164,13 @@
return False;
end Scan_Preprocessor;
- ----------------------------------------------------
- -- Tools and constants for preprocessor execution --
- ----------------------------------------------------
-
- Tmp_File_Name : GNAT.OS_Lib.Temp_File_Name;
- -- Name of the temporary file to which preprocessor output is sent
-
- Args : GNAT.OS_Lib.Argument_List (1 .. 128);
- Arg_Count : Natural := Args'First - 1;
- -- Arguments to be passed to the preprocessor
-
- ------------------
- -- Add_Argument --
- ------------------
-
- procedure Add_Argument (Str : String) is
- begin
- Arg_Count := Arg_Count + 1;
- Args (Arg_Count) := new String'(Str);
- end Add_Argument;
-
----------------
-- Initialize --
----------------
procedure Initialize (Filename : String) is
use GNAT.OS_Lib;
+
begin
if Filename'Length = 0 then
Errors.Error ("Missing IDL file as argument",
@@ -1225,7 +1205,10 @@
end if;
end;
- Preprocess_File (Filename);
+ Ada.Text_IO.Open
+ (Idl_File, Ada.Text_IO.In_File, Files.Preprocess_File (Filename));
+ Ada.Text_IO.Set_Input (Idl_File);
+
pragma Debug (O ("Initialize: end"));
end Initialize;
@@ -1411,95 +1394,13 @@
end Lexer_State;
- ---------------------
- -- Preprocess_File --
- ---------------------
-
- procedure Preprocess_File (Filename : in String) is
- use GNAT.Command_Line;
- use GNAT.OS_Lib;
-
- Spawn_Result : Boolean;
- Fd : File_Descriptor;
- Idl_File : Ada.Text_IO.File_Type;
-
- CPP_Arg_List : constant Argument_List_Access
- := Argument_String_To_List
- (Platform.CXX_Preprocessor);
-
- begin
- for J in CPP_Arg_List'First + 1 .. CPP_Arg_List'Last loop
- Add_Argument (CPP_Arg_List (J).all);
- end loop;
-
- Goto_Section ("cppargs");
- while Getopt ("*") /= ASCII.Nul loop
-
- -- Pass user options to the preprocessor.
-
- Add_Argument (Full_Switch);
- end loop;
-
- -- Always add the current directory at the end of the include list
- Add_Argument ("-I");
- Add_Argument (".");
-
- Create_Temp_File (Fd, Tmp_File_Name);
- if Fd = Invalid_FD then
- Errors.Error
- (Ada.Command_Line.Command_Name &
- ": cannot create temporary " &
- "file name",
- Errors.Fatal,
- Get_Real_Location);
- end if;
-
- -- We don't need the file descriptor
-
- Close (Fd);
-
- Add_Argument ("-o");
- Add_Argument (Tmp_File_Name & Platform.CXX_Preprocessor_Suffix);
- Add_Argument (Filename);
-
- declare
- Preprocessor_Full_Pathname : constant String_Access
- := Locate_Exec_On_Path (CPP_Arg_List (CPP_Arg_List'First).all);
- begin
- if Preprocessor_Full_Pathname = null then
- Errors.Error
- ("Cannot find preprocessor "
- & "'" & CPP_Arg_List (CPP_Arg_List'First).all & "'",
- Errors.Fatal,
- Errors.No_Location);
- end if;
-
- Spawn (Preprocessor_Full_Pathname.all,
- Args (Args'First .. Arg_Count),
- Spawn_Result);
- end;
-
- pragma Debug (O ("Preprocess_File: preprocessing done"));
- if not Spawn_Result then
- pragma Debug (O ("Preprocess_File: preprocessing failed"));
- Errors.Error
- (Ada.Command_Line.Command_Name &
- ": preprocessor failed",
- Errors.Fatal,
- Errors.No_Location);
- end if;
- Ada.Text_IO.Open (Idl_File, Ada.Text_IO.In_File, Tmp_File_Name);
- Ada.Text_IO.Set_Input (Idl_File);
- end Preprocess_File;
-
----------------------------
-- Remove_Temporary_Files --
----------------------------
procedure Remove_Temporary_Files is
- Spawn_Result : Boolean;
begin
- GNAT.OS_Lib.Delete_File (Tmp_File_Name'Address, Spawn_Result);
+ Ada.Text_IO.Delete (Idl_File);
end Remove_Temporary_Files;
end Idl_Fe.Lexer;
Index: compilers/idlac/idl_fe-lexer.ads
===================================================================
RCS file: /cvsroot/polyorb-ncsl/compilers/idlac/idl_fe-lexer.ads,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 idl_fe-lexer.ads
--- compilers/idlac/idl_fe-lexer.ads 16 Dec 2004 06:54:03 -0000 1.1.1.3
+++ compilers/idlac/idl_fe-lexer.ads 16 Dec 2004 20:28:47 -0000
@@ -174,12 +174,6 @@
-- Entry points for the idlac driver --
---------------------------------------
- procedure Add_Argument (Str : String);
- -- Append Str to the list of preprocessor arguments
-
- procedure Preprocess_File (Filename : in String);
- -- Preprocess a file and output the result to a temporary file
-
procedure Remove_Temporary_Files;
-- Remove temporary files created by the preprocessor
Index: compilers/idlac/idlac.adb
===================================================================
RCS file: /cvsroot/polyorb-ncsl/compilers/idlac/idlac.adb,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 idlac.adb
--- compilers/idlac/idlac.adb 18 Oct 2004 18:18:37 -0000 1.1.1.3
+++ compilers/idlac/idlac.adb 16 Dec 2004 20:17:20 -0000
@@ -37,11 +37,11 @@
with Ada.Command_Line; use Ada.Command_Line;
with GNAT.Command_Line; use GNAT.Command_Line;
-with GNAT.IO_Aux; use GNAT.IO_Aux;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with Idlac_Flags; use Idlac_Flags;
+with Idl_Fe.Files;
with Idl_Fe.Types;
with Idl_Fe.Parser;
with Idl_Fe.Lexer;
@@ -98,8 +98,11 @@
Preprocess_Only := True;
when 'I' =>
- Idl_Fe.Lexer.Add_Argument ("-I");
- Idl_Fe.Lexer.Add_Argument (Parameter);
+ declare
+ Success : Boolean;
+ begin
+ Idl_Fe.Files.Add_Search_Path (Parameter, Success);
+ end;
when 'd' =>
Generate_Delegate := True;
@@ -153,17 +156,10 @@
-- If file does not exist, issue an error message unless it works after
-- adding an "idl" extension.
- if not File_Exists (File_Name.all)
- or else not Is_Regular_File (File_Name.all)
- then
- if File_Exists (File_Name.all & ".idl")
- and then Is_Regular_File (File_Name.all & ".idl")
- then
- File_Name := new String'(File_Name.all & ".idl");
- else
- Put_Line (Current_Error, "No such file: " & File_Name.all);
- Usage;
- end if;
+ File_Name := new String'(Idl_Fe.Files.Search_IDL_File (File_Name.all));
+ if File_Name.all'Length = 0 then
+ Put_Line (Current_Error, "No such file: " & File_Name.all);
+ Usage;
end if;
if Preprocess_Only then
@@ -171,16 +167,23 @@
-- If we only want to preprocess, let's preprocess, print the content
-- of the file and exit.
- Idl_Fe.Lexer.Preprocess_File (File_Name.all);
declare
use Ada.Text_IO;
- Line : String (1 .. 1024);
- Last : Natural;
+
+ Idl_File : File_Type;
+ Line : String (1 .. 1024);
+ Last : Natural;
begin
+ Open
+ (Idl_File, In_File, Idl_Fe.Files.Preprocess_File (File_Name.all));
+ Set_Input (Idl_File);
+
while not End_Of_File loop
Get_Line (Line, Last);
Put_Line (Line (1 .. Last));
end loop;
+
+ Delete (Idl_File);
end;
else
More information about the PolyORB-users
mailing list