Commit 32404665 by Emmanuel Briot Committed by Arnaud Charlet

gnatcmd.adb, [...]: Minor reformatting.

2009-07-13  Emmanuel Briot  <briot@adacore.com>

	* gnatcmd.adb, prj-proc.adb, prj-proc.ads, make.adb, prj-part.adb,
	prj.adb, prj.ads, clean.adb, prj-nmsc.adb, prj-nmsc.ads, prj-pars.adb,
	prj-pars.ads, prj-conf.adb, prj-conf.ads, prj-env.adb, prj-tree.adb,
	prj-tree.ads: Minor reformatting.
	(Processing_Flags): new record to encapsulate the set of common
	parameters to several subprograms in the project manager.
	(Prj.Nmsc.Process_Naming_Scheme): renames Check, and moved to body
	Remove the need for the Current_Dir parameter in subprograms.
	(Look_For_Sources): minor refactoring, now that we no longer need to
	share subprograms between the two Ada_Only and Multi_Language modes
	(Processing_Flags): New field Error_On_Unknown_Language.
	Merge tests for library project between gnatmake and gprbuild.

From-SVN: r149563
parent 959dd7d8
2009-07-13 Emmanuel Briot <briot@adacore.com>
* gnatcmd.adb, prj-proc.adb, prj-proc.ads, make.adb, prj-part.adb,
prj.adb, prj.ads, clean.adb, prj-nmsc.adb, prj-nmsc.ads, prj-pars.adb,
prj-pars.ads, prj-conf.adb, prj-conf.ads, prj-env.adb, prj-tree.adb,
prj-tree.ads: Minor reformatting.
(Processing_Flags): new record to encapsulate the set of common
parameters to several subprograms in the project manager.
(Prj.Nmsc.Process_Naming_Scheme): renames Check, and moved to body
Remove the need for the Current_Dir parameter in subprograms.
(Look_For_Sources): minor refactoring, now that we no longer need to
share subprograms between the two Ada_Only and Multi_Language modes
(Processing_Flags): New field Error_On_Unknown_Language.
Merge tests for library project between gnatmake and gprbuild.
2009-07-13 Arnaud Charlet <charlet@adacore.com> 2009-07-13 Arnaud Charlet <charlet@adacore.com>
* lib.adb, make.adb, mlib.adb, exp_dist.adb: Update comments. * lib.adb, make.adb, mlib.adb, exp_dist.adb: Update comments.
......
...@@ -1391,6 +1391,7 @@ package body Clean is ...@@ -1391,6 +1391,7 @@ package body Clean is
(Project => Main_Project, (Project => Main_Project,
In_Tree => Project_Tree, In_Tree => Project_Tree,
Project_File_Name => Project_File_Name.all, Project_File_Name => Project_File_Name.all,
Flags => Gnatmake_Flags,
Packages_To_Check => Packages_To_Check_By_Gnatmake); Packages_To_Check => Packages_To_Check_By_Gnatmake);
if Main_Project = No_Project then if Main_Project = No_Project then
......
...@@ -1777,6 +1777,7 @@ begin ...@@ -1777,6 +1777,7 @@ begin
(Project => Project, (Project => Project,
In_Tree => Project_Tree, In_Tree => Project_Tree,
Project_File_Name => Project_File.all, Project_File_Name => Project_File.all,
Flags => Gnatmake_Flags,
Packages_To_Check => Packages_To_Check); Packages_To_Check => Packages_To_Check);
if Project = Prj.No_Project then if Project = Prj.No_Project then
......
...@@ -6865,7 +6865,8 @@ package body Make is ...@@ -6865,7 +6865,8 @@ package body Make is
(Project => Main_Project, (Project => Main_Project,
In_Tree => Project_Tree, In_Tree => Project_Tree,
Project_File_Name => Project_File_Name.all, Project_File_Name => Project_File_Name.all,
Packages_To_Check => Packages_To_Check_By_Gnatmake); Packages_To_Check => Packages_To_Check_By_Gnatmake,
Flags => Gnatmake_Flags);
-- The parsing of project files may have changed the current output -- The parsing of project files may have changed the current output
......
...@@ -396,6 +396,7 @@ package body Prj.Conf is ...@@ -396,6 +396,7 @@ package body Prj.Conf is
Config : out Prj.Project_Id; Config : out Prj.Project_Id;
Config_File_Path : out String_Access; Config_File_Path : out String_Access;
Automatically_Generated : out Boolean; Automatically_Generated : out Boolean;
Flags : Processing_Flags;
On_Load_Config : Config_File_Hook := null) On_Load_Config : Config_File_Hook := null)
is is
function Default_File_Name return String; function Default_File_Name return String;
...@@ -862,7 +863,7 @@ package body Prj.Conf is ...@@ -862,7 +863,7 @@ package body Prj.Conf is
Success => Success, Success => Success,
From_Project_Node => Config_Project_Node, From_Project_Node => Config_Project_Node,
From_Project_Node_Tree => Project_Node_Tree, From_Project_Node_Tree => Project_Node_Tree,
Report_Error => null, Flags => Flags,
Reset_Tree => False); Reset_Tree => False);
end if; end if;
...@@ -904,13 +905,9 @@ package body Prj.Conf is ...@@ -904,13 +905,9 @@ package body Prj.Conf is
Config_File_Path : out String_Access; Config_File_Path : out String_Access;
Target_Name : String := ""; Target_Name : String := "";
Normalized_Hostname : String; Normalized_Hostname : String;
Report_Error : Put_Line_Access := null; Flags : Processing_Flags;
On_Load_Config : Config_File_Hook := null; On_Load_Config : Config_File_Hook := null;
Compiler_Driver_Mandatory : Boolean := True; Reset_Tree : Boolean := True)
Allow_Duplicate_Basenames : Boolean := False;
Reset_Tree : Boolean := True;
Require_Sources_Other_Lang : Boolean := True;
When_No_Sources : Error_Warning := Warning)
is is
Main_Config_Project : Project_Id; Main_Config_Project : Project_Id;
Success : Boolean; Success : Boolean;
...@@ -925,7 +922,7 @@ package body Prj.Conf is ...@@ -925,7 +922,7 @@ package body Prj.Conf is
Success => Success, Success => Success,
From_Project_Node => User_Project_Node, From_Project_Node => User_Project_Node,
From_Project_Node_Tree => Project_Node_Tree, From_Project_Node_Tree => Project_Node_Tree,
Report_Error => Report_Error, Flags => Flags,
Reset_Tree => Reset_Tree); Reset_Tree => Reset_Tree);
if not Success then if not Success then
...@@ -948,6 +945,7 @@ package body Prj.Conf is ...@@ -948,6 +945,7 @@ package body Prj.Conf is
Packages_To_Check => Packages_To_Check, Packages_To_Check => Packages_To_Check,
Config_File_Path => Config_File_Path, Config_File_Path => Config_File_Path,
Automatically_Generated => Automatically_Generated, Automatically_Generated => Automatically_Generated,
Flags => Flags,
On_Load_Config => On_Load_Config); On_Load_Config => On_Load_Config);
Apply_Config_File (Main_Config_Project, Project_Tree); Apply_Config_File (Main_Config_Project, Project_Tree);
...@@ -960,12 +958,7 @@ package body Prj.Conf is ...@@ -960,12 +958,7 @@ package body Prj.Conf is
Success => Success, Success => Success,
From_Project_Node => User_Project_Node, From_Project_Node => User_Project_Node,
From_Project_Node_Tree => Project_Node_Tree, From_Project_Node_Tree => Project_Node_Tree,
Report_Error => Report_Error, Flags => Flags);
Current_Dir => Current_Directory,
When_No_Sources => When_No_Sources,
Require_Sources_Other_Lang => Require_Sources_Other_Lang,
Compiler_Driver_Mandatory => Compiler_Driver_Mandatory,
Allow_Duplicate_Basenames => Allow_Duplicate_Basenames);
if not Success then if not Success then
Main_Project := No_Project; Main_Project := No_Project;
...@@ -990,7 +983,7 @@ package body Prj.Conf is ...@@ -990,7 +983,7 @@ package body Prj.Conf is
Config_File_Path : out String_Access; Config_File_Path : out String_Access;
Target_Name : String := ""; Target_Name : String := "";
Normalized_Hostname : String; Normalized_Hostname : String;
Report_Error : Put_Line_Access := null; Flags : Processing_Flags;
On_Load_Config : Config_File_Hook := null) On_Load_Config : Config_File_Hook := null)
is is
begin begin
...@@ -1029,7 +1022,7 @@ package body Prj.Conf is ...@@ -1029,7 +1022,7 @@ package body Prj.Conf is
Config_File_Path => Config_File_Path, Config_File_Path => Config_File_Path,
Target_Name => Target_Name, Target_Name => Target_Name,
Normalized_Hostname => Normalized_Hostname, Normalized_Hostname => Normalized_Hostname,
Report_Error => Report_Error, Flags => Flags,
On_Load_Config => On_Load_Config); On_Load_Config => On_Load_Config);
end Parse_Project_And_Apply_Config; end Parse_Project_And_Apply_Config;
...@@ -1131,19 +1124,22 @@ package body Prj.Conf is ...@@ -1131,19 +1124,22 @@ package body Prj.Conf is
Project_Tree : Project_Node_Tree_Ref) Project_Tree : Project_Node_Tree_Ref)
is is
Name : Name_Id; Name : Name_Id;
begin begin
if Config_File = Empty_Node then if Config_File = Empty_Node then
-- Create a dummy config file is none was found.
-- Create a dummy config file is none was found
Name_Len := Auto_Cgpr'Length; Name_Len := Auto_Cgpr'Length;
Name_Buffer (1 .. Name_Len) := Auto_Cgpr; Name_Buffer (1 .. Name_Len) := Auto_Cgpr;
Name := Name_Find; Name := Name_Find;
Config_File := Create_Project Config_File :=
(In_Tree => Project_Tree, Create_Project
Name => Name, (In_Tree => Project_Tree,
Full_Path => Path_Name_Type (Name), Name => Name,
Is_Config_File => True); Full_Path => Path_Name_Type (Name),
Is_Config_File => True);
-- ??? This isn't strictly required, since Prj.Nmsc.Add_Language -- ??? This isn't strictly required, since Prj.Nmsc.Add_Language
-- already has a workaround in the Ada_Only case. But it would be -- already has a workaround in the Ada_Only case. But it would be
...@@ -1151,6 +1147,8 @@ package body Prj.Conf is ...@@ -1151,6 +1147,8 @@ package body Prj.Conf is
-- Likewise for the default language, hard-coded in -- Likewise for the default language, hard-coded in
-- Pjr.Nmsc.Check_Programming_Languages -- Pjr.Nmsc.Check_Programming_Languages
-- Why is all the following code commented out???
-- Update_Attribute_Value_In_Scenario -- Update_Attribute_Value_In_Scenario
-- (Tree => Project_Tree, -- (Tree => Project_Tree,
-- Project => Config_File, -- Project => Config_File,
......
...@@ -55,7 +55,7 @@ package Prj.Conf is ...@@ -55,7 +55,7 @@ package Prj.Conf is
Config_File_Path : out String_Access; Config_File_Path : out String_Access;
Target_Name : String := ""; Target_Name : String := "";
Normalized_Hostname : String; Normalized_Hostname : String;
Report_Error : Put_Line_Access := null; Flags : Processing_Flags;
On_Load_Config : Config_File_Hook := null); On_Load_Config : Config_File_Hook := null);
-- Find the main configuration project and parse the project tree rooted at -- Find the main configuration project and parse the project tree rooted at
-- this configuration project. -- this configuration project.
...@@ -96,19 +96,17 @@ package Prj.Conf is ...@@ -96,19 +96,17 @@ package Prj.Conf is
Config_File_Path : out String_Access; Config_File_Path : out String_Access;
Target_Name : String := ""; Target_Name : String := "";
Normalized_Hostname : String; Normalized_Hostname : String;
Report_Error : Put_Line_Access := null; Flags : Processing_Flags;
On_Load_Config : Config_File_Hook := null; On_Load_Config : Config_File_Hook := null;
Compiler_Driver_Mandatory : Boolean := True; Reset_Tree : Boolean := True);
Allow_Duplicate_Basenames : Boolean := False;
Reset_Tree : Boolean := True;
Require_Sources_Other_Lang : Boolean := True;
When_No_Sources : Error_Warning := Warning);
-- Same as above, except the project must already have been parsed through -- Same as above, except the project must already have been parsed through
-- Prj.Part.Parse, and only the processing of the project and the -- Prj.Part.Parse, and only the processing of the project and the
-- configuration is done at this level. -- configuration is done at this level.
--
-- If Reset_Tree is true, all projects are first removed from the tree. -- If Reset_Tree is true, all projects are first removed from the tree.
-- When_No_Sources indicates what should be done when no sources are found -- When_No_Sources indicates what should be done when no sources are found
-- for one of the languages of the project. -- for one of the languages of the project.
--
-- If Require_Sources_Other_Lang is true, then all languages must have at -- If Require_Sources_Other_Lang is true, then all languages must have at
-- least one source file, or an error is reported via When_No_Sources. If -- least one source file, or an error is reported via When_No_Sources. If
-- it is false, this is only required for Ada (and only if it is a language -- it is false, this is only required for Ada (and only if it is a language
...@@ -129,6 +127,7 @@ package Prj.Conf is ...@@ -129,6 +127,7 @@ package Prj.Conf is
Config : out Prj.Project_Id; Config : out Prj.Project_Id;
Config_File_Path : out String_Access; Config_File_Path : out String_Access;
Automatically_Generated : out Boolean; Automatically_Generated : out Boolean;
Flags : Processing_Flags;
On_Load_Config : Config_File_Hook := null); On_Load_Config : Config_File_Hook := null);
-- Compute the name of the configuration file that should be used. If no -- Compute the name of the configuration file that should be used. If no
-- default configuration file is found, a new one will be automatically -- default configuration file is found, a new one will be automatically
...@@ -142,20 +141,19 @@ package Prj.Conf is ...@@ -142,20 +141,19 @@ package Prj.Conf is
-- --
-- The choice and generation of a configuration file depends on several -- The choice and generation of a configuration file depends on several
-- attributes of the user's project file (given by the Project argument), -- attributes of the user's project file (given by the Project argument),
-- like the list of languages that must be supported. Project must -- e.g. list of languages that must be supported. Project must therefore
-- therefore have been partially processed (phase one of the processing -- have been partially processed (phase one of the processing only).
-- only).
-- --
-- Config_File_Name should be set to the name of the config file specified -- Config_File_Name should be set to the name of the config file specified
-- by the user (either through gprbuild's --config or --autoconf switches). -- by the user (either through gprbuild's --config or --autoconf switches).
-- In the latter case, Autoconf_Specified should be set to true, to -- In the latter case, Autoconf_Specified should be set to true to indicate
-- indicate that the configuration file can be regenerated to match target -- that the configuration file can be regenerated to match target and
-- and languages. This name can either be an absolute path, or the a base -- languages. This name can either be an absolute path, or the a base name
-- name that will be searched in the default config file directories (which -- that will be searched in the default config file directories (which
-- depends on the installation path for the tools). -- depends on the installation path for the tools).
-- --
-- Target_Name is used to chose among several possibilities -- Target_Name is used to chose the configuration file that will be used
-- the configuration file that will be used. -- from among several possibilities.
-- --
-- If a project file could be found, it is automatically parsed and -- If a project file could be found, it is automatically parsed and
-- processed (and Packages_To_Check is used to indicate which packages -- processed (and Packages_To_Check is used to indicate which packages
...@@ -175,11 +173,11 @@ package Prj.Conf is ...@@ -175,11 +173,11 @@ package Prj.Conf is
procedure Add_Default_GNAT_Naming_Scheme procedure Add_Default_GNAT_Naming_Scheme
(Config_File : in out Prj.Tree.Project_Node_Id; (Config_File : in out Prj.Tree.Project_Node_Id;
Project_Tree : Prj.Tree.Project_Node_Tree_Ref); Project_Tree : Prj.Tree.Project_Node_Tree_Ref);
-- A hook for Get_Or_Create_Configuration_File and -- A hook that will create a new config file (in memory), used for
-- Process_Project_And_Apply_Config that will create a new config file (in -- Get_Or_Create_Configuration_File and Process_Project_And_Apply_Config
-- memory) and add the default GNAT naming scheme to it. Nothing is done -- and add the default GNAT naming scheme to it. Nothing is done if the
-- if the config_file already exists, to avoid overriding what the user -- config_file already exists, to avoid overriding what the user might
-- might have put in there. -- have put in there.
-------------- --------------
-- Runtimes -- -- Runtimes --
...@@ -193,7 +191,7 @@ package Prj.Conf is ...@@ -193,7 +191,7 @@ package Prj.Conf is
-- --config switch then automatically generating a configuration file. -- --config switch then automatically generating a configuration file.
function Runtime_Name_For (Language : Name_Id) return String; function Runtime_Name_For (Language : Name_Id) return String;
-- Returns the runtime name for a language. Returns an empty string if -- Returns the runtime name for a language. Returns an empty string if no
-- no runtime was specified for the language using option --RTS. -- runtime was specified for the language using option --RTS.
end Prj.Conf; end Prj.Conf;
...@@ -646,7 +646,6 @@ package body Prj.Env is ...@@ -646,7 +646,6 @@ package body Prj.Env is
-- Visit all the files and process those that need an SFN pragma -- Visit all the files and process those that need an SFN pragma
Iter := For_Each_Source (In_Tree, For_Project); Iter := For_Each_Source (In_Tree, For_Project);
while Element (Iter) /= No_Source loop while Element (Iter) /= No_Source loop
Source := Element (Iter); Source := Element (Iter);
......
...@@ -23,87 +23,21 @@ ...@@ -23,87 +23,21 @@
-- -- -- --
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Perform various checks on a project and find all its source files -- Find source dirs and source files for a project
with GNAT.Dynamic_HTables;
private package Prj.Nmsc is private package Prj.Nmsc is
type Tree_Processing_Data is private; procedure Process_Naming_Scheme
-- Temporary data which is needed while parsing a project. It does not need (Tree : Project_Tree_Ref;
-- to be kept in memory once a project has been fully loaded, but is Root_Project : Project_Id;
-- necessary while performing consistency checks (duplicate sources,...) Flags : Processing_Flags);
-- This data must be initialized before processing any project, and the -- Perform consistency and semantic checks on all the projects in the tree.
-- same data is used for processing all projects in the tree. -- This procedure interprets the various case statements in the project
-- based on the current environment variables (the "scenario"). After
procedure Initialize -- checking the validity of the naming scheme, it searches for all the
(Data : out Tree_Processing_Data; -- source files of the project. The result of this procedure is a filled-in
Tree : Project_Tree_Ref; -- data structure for Project_Id which contains all the information about
Report_Error : Put_Line_Access; -- the project. This information is only valid while the scenario variables
When_No_Sources : Error_Warning; -- are preserved.
Require_Sources_Other_Lang : Boolean := True;
Allow_Duplicate_Basenames : Boolean := True;
Compiler_Driver_Mandatory : Boolean := False);
-- Initialize Data
-- If Allow_Duplicate_Basenames, then files with the same base names are
-- authorized within a project for source-based languages (never for unit
-- based languages)
-- If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
-- for each language must be defined, or we will not look for its source
-- files.
-- When_No_Sources indicates what should be done when no sources of a
-- language are found in a project where this language is declared.
-- If Require_Sources_Other_Lang is true, then all languages must have at
-- least one source file, or an error is reported via When_No_Sources. If
-- it is false, this is only required for Ada (and only if it is a language
-- of the project).
-- If Report_Error is null, use the standard error reporting mechanism
-- (Errout). Otherwise, report errors using Report_Error.
procedure Free (Data : in out Tree_Processing_Data);
-- Free the memory occupied by Data
procedure Check
(Project : Project_Id;
Current_Dir : String;
Data : in out Tree_Processing_Data);
-- Perform consistency and semantic checks on a project, starting from the
-- project tree parsed from the .gpr file. This procedure interprets the
-- various case statements in the project based on the current environment
-- variables (the "scenario"). After checking the validity of the naming
-- scheme, it searches for all the source files of the project. The result
-- of this procedure is a filled-in data structure for Project_Id which
-- contains all the information about the project. This information is only
-- valid while the scenario variables are preserved. If the current mode
-- is Ada_Only, this procedure will only search Ada sources, but in multi-
-- language mode it will look for sources for all supported languages.
--
-- Current_Dir is for optimization purposes only, avoiding system calls to
-- query it.
private
package Files_Htable is new GNAT.Dynamic_HTables.Simple_HTable
(Header_Num => Header_Num,
Element => Source_Id,
No_Element => No_Source,
Key => File_Name_Type,
Hash => Hash,
Equal => "=");
-- Mapping from base file names to Source_Id (containing full info about
-- the source)
type Tree_Processing_Data is record
Tree : Project_Tree_Ref;
-- The data applies when parsing this tree
File_To_Source : Files_Htable.Instance;
Require_Sources_Other_Lang : Boolean;
Report_Error : Put_Line_Access;
When_No_Sources : Error_Warning;
Allow_Duplicate_Basenames : Boolean := True;
Compiler_Driver_Mandatory : Boolean := False;
-- See comments for Initialize
end record;
end Prj.Nmsc; end Prj.Nmsc;
...@@ -44,8 +44,7 @@ package body Prj.Pars is ...@@ -44,8 +44,7 @@ package body Prj.Pars is
Project : out Project_Id; Project : out Project_Id;
Project_File_Name : String; Project_File_Name : String;
Packages_To_Check : String_List_Access := All_Packages; Packages_To_Check : String_List_Access := All_Packages;
When_No_Sources : Error_Warning := Error; Flags : Processing_Flags;
Report_Error : Put_Line_Access := null;
Reset_Tree : Boolean := True) Reset_Tree : Boolean := True)
is is
Project_Node : Project_Node_Id := Empty_Node; Project_Node : Project_Node_Id := Empty_Node;
...@@ -90,15 +89,11 @@ package body Prj.Pars is ...@@ -90,15 +89,11 @@ package body Prj.Pars is
Allow_Automatic_Generation => False, Allow_Automatic_Generation => False,
Automatically_Generated => Automatically_Generated, Automatically_Generated => Automatically_Generated,
Config_File_Path => Config_File_Path, Config_File_Path => Config_File_Path,
Report_Error => Report_Error, Flags => Flags,
Normalized_Hostname => "", Normalized_Hostname => "",
Compiler_Driver_Mandatory => False,
Allow_Duplicate_Basenames => False,
Require_Sources_Other_Lang => False,
On_Load_Config => On_Load_Config =>
Add_Default_GNAT_Naming_Scheme'Access, Add_Default_GNAT_Naming_Scheme'Access,
Reset_Tree => Reset_Tree, Reset_Tree => Reset_Tree);
When_No_Sources => When_No_Sources);
Success := The_Project /= No_Project; Success := The_Project /= No_Project;
......
...@@ -35,8 +35,7 @@ package Prj.Pars is ...@@ -35,8 +35,7 @@ package Prj.Pars is
Project : out Project_Id; Project : out Project_Id;
Project_File_Name : String; Project_File_Name : String;
Packages_To_Check : String_List_Access := All_Packages; Packages_To_Check : String_List_Access := All_Packages;
When_No_Sources : Error_Warning := Error; Flags : Processing_Flags;
Report_Error : Prj.Put_Line_Access := null;
Reset_Tree : Boolean := True); Reset_Tree : Boolean := True);
-- Parse and process a project files and all its imported project files, in -- Parse and process a project files and all its imported project files, in
-- the project tree In_Tree. -- the project tree In_Tree.
...@@ -56,9 +55,6 @@ package Prj.Pars is ...@@ -56,9 +55,6 @@ package Prj.Pars is
-- produces an error. For other packages, an unknown attribute produces a -- produces an error. For other packages, an unknown attribute produces a
-- warning. -- warning.
-- --
-- When_No_Sources indicates what should be done when no sources are found
-- in a project for a specified or implied language.
--
-- When Reset_Tree is True, all the project data are removed from the -- When Reset_Tree is True, all the project data are removed from the
-- project table before processing. -- project table before processing.
......
...@@ -1110,8 +1110,8 @@ package body Prj.Part is ...@@ -1110,8 +1110,8 @@ package body Prj.Part is
Write_Eol; Write_Eol;
end if; end if;
Project_Directory := Path_Name_Type Project_Directory :=
(Get_Directory (File_Name_Type (Normed_Path_Name))); Path_Name_Type (Get_Directory (File_Name_Type (Normed_Path_Name)));
-- Is there any imported project? -- Is there any imported project?
......
...@@ -37,7 +37,7 @@ package Prj.Proc is ...@@ -37,7 +37,7 @@ package Prj.Proc is
Success : out Boolean; Success : out Boolean;
From_Project_Node : Project_Node_Id; From_Project_Node : Project_Node_Id;
From_Project_Node_Tree : Project_Node_Tree_Ref; From_Project_Node_Tree : Project_Node_Tree_Ref;
Report_Error : Put_Line_Access; Flags : Prj.Processing_Flags;
Reset_Tree : Boolean := True); Reset_Tree : Boolean := True);
-- Process a project tree (ie the direct resulting of parsing a .gpr file) -- Process a project tree (ie the direct resulting of parsing a .gpr file)
-- based on the current scenario variables. -- based on the current scenario variables.
...@@ -48,12 +48,6 @@ package Prj.Proc is ...@@ -48,12 +48,6 @@ package Prj.Proc is
-- needed to automatically generate a configuration file. This first phase -- needed to automatically generate a configuration file. This first phase
-- of the processing does not require a configuration file. -- of the processing does not require a configuration file.
-- --
-- If Report_Error is null, use the error reporting mechanism. Otherwise,
-- report errors using Report_Error.
--
-- When_No_Sources indicates what should be done when no sources are found
-- in a project for a specified or implied language.
--
-- When Reset_Tree is True, all the project data are removed from the -- When Reset_Tree is True, all the project data are removed from the
-- project table before processing. -- project table before processing.
...@@ -63,24 +57,13 @@ package Prj.Proc is ...@@ -63,24 +57,13 @@ package Prj.Proc is
Success : out Boolean; Success : out Boolean;
From_Project_Node : Project_Node_Id; From_Project_Node : Project_Node_Id;
From_Project_Node_Tree : Project_Node_Tree_Ref; From_Project_Node_Tree : Project_Node_Tree_Ref;
Report_Error : Put_Line_Access; Flags : Processing_Flags);
When_No_Sources : Error_Warning := Error;
Current_Dir : String;
Require_Sources_Other_Lang : Boolean;
Compiler_Driver_Mandatory : Boolean;
Allow_Duplicate_Basenames : Boolean);
-- Perform the second phase of the processing, filling the rest of the -- Perform the second phase of the processing, filling the rest of the
-- project with the information extracted from the project tree. This phase -- project with the information extracted from the project tree. This phase
-- requires that the configuration file has already been parsed (in fact -- requires that the configuration file has already been parsed (in fact
-- we currently assume that the contents of the configuration file has -- we currently assume that the contents of the configuration file has
-- been included in Project through Confgpr.Apply_Config_File). The -- been included in Project through Confgpr.Apply_Config_File). The
-- parameters are the same as for phase_1, with the addition of: -- parameters are the same as for phase_1, with the addition of:
--
-- Current_Dir is for optimization purposes, avoiding extra system calls.
--
-- If Allow_Duplicate_Basenames, then files with the same base names are
-- authorized within a project for source-based languages (never for unit
-- based languages)
procedure Process procedure Process
(In_Tree : Project_Tree_Ref; (In_Tree : Project_Tree_Ref;
...@@ -88,10 +71,8 @@ package Prj.Proc is ...@@ -88,10 +71,8 @@ package Prj.Proc is
Success : out Boolean; Success : out Boolean;
From_Project_Node : Project_Node_Id; From_Project_Node : Project_Node_Id;
From_Project_Node_Tree : Project_Node_Tree_Ref; From_Project_Node_Tree : Project_Node_Tree_Ref;
Report_Error : Put_Line_Access; Flags : Processing_Flags;
When_No_Sources : Error_Warning := Error; Reset_Tree : Boolean := True);
Reset_Tree : Boolean := True;
Current_Dir : String := "");
-- Performs the two phases of the processing -- Performs the two phases of the processing
end Prj.Proc; end Prj.Proc;
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation; with Ada.Unchecked_Deallocation;
with Osint; use Osint; with Osint; use Osint;
with Prj.Err; with Prj.Err;
package body Prj.Tree is package body Prj.Tree is
...@@ -97,8 +97,7 @@ package body Prj.Tree is ...@@ -97,8 +97,7 @@ package body Prj.Tree is
begin begin
pragma Assert pragma Assert
(Present (To) (Present (To)
and then and then In_Tree.Project_Nodes.Table (To).Kind /= N_Comment);
In_Tree.Project_Nodes.Table (To).Kind /= N_Comment);
Zone := In_Tree.Project_Nodes.Table (To).Comments; Zone := In_Tree.Project_Nodes.Table (To).Comments;
...@@ -109,25 +108,25 @@ package body Prj.Tree is ...@@ -109,25 +108,25 @@ package body Prj.Tree is
Project_Node_Table.Increment_Last (In_Tree.Project_Nodes); Project_Node_Table.Increment_Last (In_Tree.Project_Nodes);
In_Tree.Project_Nodes.Table In_Tree.Project_Nodes.Table
(Project_Node_Table.Last (In_Tree.Project_Nodes)) := (Project_Node_Table.Last (In_Tree.Project_Nodes)) :=
(Kind => N_Comment_Zones, (Kind => N_Comment_Zones,
Qualifier => Unspecified, Qualifier => Unspecified,
Expr_Kind => Undefined, Expr_Kind => Undefined,
Location => No_Location, Location => No_Location,
Directory => No_Path, Directory => No_Path,
Variables => Empty_Node, Variables => Empty_Node,
Packages => Empty_Node, Packages => Empty_Node,
Pkg_Id => Empty_Package, Pkg_Id => Empty_Package,
Name => No_Name, Name => No_Name,
Src_Index => 0, Src_Index => 0,
Path_Name => No_Path, Path_Name => No_Path,
Value => No_Name, Value => No_Name,
Field1 => Empty_Node, Field1 => Empty_Node,
Field2 => Empty_Node, Field2 => Empty_Node,
Field3 => Empty_Node, Field3 => Empty_Node,
Field4 => Empty_Node, Field4 => Empty_Node,
Flag1 => False, Flag1 => False,
Flag2 => False, Flag2 => False,
Comments => Empty_Node); Comments => Empty_Node);
Zone := Project_Node_Table.Last (In_Tree.Project_Nodes); Zone := Project_Node_Table.Last (In_Tree.Project_Nodes);
In_Tree.Project_Nodes.Table (To).Comments := Zone; In_Tree.Project_Nodes.Table (To).Comments := Zone;
......
...@@ -294,9 +294,8 @@ package Prj.Tree is ...@@ -294,9 +294,8 @@ package Prj.Tree is
(Node : Project_Node_Id; (Node : Project_Node_Id;
In_Tree : Project_Node_Tree_Ref) return Path_Name_Type; In_Tree : Project_Node_Tree_Ref) return Path_Name_Type;
pragma Inline (Directory_Of); pragma Inline (Directory_Of);
-- Only valid for N_Project nodes. -- Returns the directory that contains the project file. This always ends
-- Returns the directory that contains the project file. This always -- with a directory separator. Only valid for N_Project nodes.
-- ends with a directory separator
function Expression_Kind_Of function Expression_Kind_Of
(Node : Project_Node_Id; (Node : Project_Node_Id;
...@@ -441,8 +440,7 @@ package Prj.Tree is ...@@ -441,8 +440,7 @@ package Prj.Tree is
(Node : Project_Node_Id; (Node : Project_Node_Id;
In_Tree : Project_Node_Tree_Ref) return Project_Node_Id; In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
pragma Inline (Project_Of_Renamed_Package_Of); pragma Inline (Project_Of_Renamed_Package_Of);
-- Only valid for N_Package_Declaration nodes. -- Only valid for N_Package_Declaration nodes. May return Empty_Node.
-- May return Empty_Node.
function Next_Package_In_Project function Next_Package_In_Project
(Node : Project_Node_Id; (Node : Project_Node_Id;
...@@ -601,8 +599,8 @@ package Prj.Tree is ...@@ -601,8 +599,8 @@ package Prj.Tree is
-- Set Procedures -- -- Set Procedures --
-------------------- --------------------
-- The following procedures are part of the abstract interface of -- The following procedures are part of the abstract interface of the
-- the Project File tree. -- Project File tree.
-- Each Set_* procedure is valid only for the same Project_Node_Kind -- Each Set_* procedure is valid only for the same Project_Node_Kind
-- nodes as the corresponding query function above. -- nodes as the corresponding query function above.
...@@ -971,6 +969,7 @@ package Prj.Tree is ...@@ -971,6 +969,7 @@ package Prj.Tree is
Pkg_Id : Package_Node_Id := Empty_Package; Pkg_Id : Package_Node_Id := Empty_Package;
-- Only used for N_Package_Declaration -- Only used for N_Package_Declaration
--
-- The component Pkg_Id is an entry into the table Package_Attributes -- The component Pkg_Id is an entry into the table Package_Attributes
-- (in Prj.Attr). It is used to indicate all the attributes of the -- (in Prj.Attr). It is used to indicate all the attributes of the
-- package with their characteristics. -- package with their characteristics.
...@@ -1006,38 +1005,45 @@ package Prj.Tree is ...@@ -1006,38 +1005,45 @@ package Prj.Tree is
Flag1 : Boolean := False; Flag1 : Boolean := False;
-- This flag is significant only for: -- This flag is significant only for:
--
-- N_Attribute_Declaration and N_Attribute_Reference -- N_Attribute_Declaration and N_Attribute_Reference
-- It indicates for an associative array attribute, that the -- Indicates for an associative array attribute, that the
-- index is case insensitive. -- index is case insensitive.
-- N_Comment - it indicates that the comment is preceded by an --
-- empty line. -- N_Comment
-- N_Project - it indicates that there are comments in the project -- Indicates that the comment is preceded by an empty line.
-- source that cannot be kept in the tree. --
-- N_Project
-- Indicates that there are comments in the project source that
-- cannot be kept in the tree.
--
-- N_Project_Declaration -- N_Project_Declaration
-- - it indicates that there are unkept comments in the -- Indicates that there are unkept comments in the project.
-- project. --
-- N_With_Clause -- N_With_Clause
-- - it indicates that this is not the last with in a -- Indicates that this is not the last with in a with clause.
-- with clause. It is set for "A", but not for "B" in -- Set for "A", but not for "B" in with "B"; and with "A", "B";
-- with "B";
-- and
-- with "A", "B";
Flag2 : Boolean := False; Flag2 : Boolean := False;
-- This flag is significant only for: -- This flag is significant only for:
-- N_Project - it indicates that the project "extends all" another --
-- project. -- N_Project
-- N_Comment - it indicates that the comment is followed by an -- Indicates that the project "extends all" another project.
-- empty line. --
-- N_Comment
-- Indicates that the comment is followed by an empty line.
--
-- N_With_Clause -- N_With_Clause
-- - it indicates that the originally imported project -- Indicates that the originally imported project is an extending
-- is an extending all project. -- all project.
Comments : Project_Node_Id := Empty_Node; Comments : Project_Node_Id := Empty_Node;
-- For nodes other that N_Comment_Zones or N_Comment, designates the -- For nodes other that N_Comment_Zones or N_Comment, designates the
-- comment zones associated with the node. -- comment zones associated with the node.
-- for N_Comment_Zones, designates the comment after the "end" of --
-- For N_Comment_Zones, designates the comment after the "end" of
-- the construct. -- the construct.
--
-- For N_Comment, designates the next comment, if any. -- For N_Comment, designates the next comment, if any.
end record; end record;
...@@ -1256,15 +1262,14 @@ package Prj.Tree is ...@@ -1256,15 +1262,14 @@ package Prj.Tree is
-- -- Flag2: comment is followed by an empty line -- -- Flag2: comment is followed by an empty line
-- -- Comments: next comment -- -- Comments: next comment
package Project_Node_Table is package Project_Node_Table is new
new GNAT.Dynamic_Tables GNAT.Dynamic_Tables
(Table_Component_Type => Project_Node_Record, (Table_Component_Type => Project_Node_Record,
Table_Index_Type => Project_Node_Id, Table_Index_Type => Project_Node_Id,
Table_Low_Bound => First_Node_Id, Table_Low_Bound => First_Node_Id,
Table_Initial => Project_Nodes_Initial, Table_Initial => Project_Nodes_Initial,
Table_Increment => Project_Nodes_Increment); Table_Increment => Project_Nodes_Increment);
-- This table contains the syntactic tree of project data -- Table contains the syntactic tree of project data from project files
-- from project files.
type Project_Name_And_Node is record type Project_Name_And_Node is record
Name : Name_Id; Name : Name_Id;
...@@ -1320,13 +1325,9 @@ private ...@@ -1320,13 +1325,9 @@ private
type Comment_State is record type Comment_State is record
End_Of_Line_Node : Project_Node_Id := Empty_Node; End_Of_Line_Node : Project_Node_Id := Empty_Node;
Previous_Line_Node : Project_Node_Id := Empty_Node; Previous_Line_Node : Project_Node_Id := Empty_Node;
Previous_End_Node : Project_Node_Id := Empty_Node; Previous_End_Node : Project_Node_Id := Empty_Node;
Unkept_Comments : Boolean := False; Unkept_Comments : Boolean := False;
Comments : Comments_Ptr := null; Comments : Comments_Ptr := null;
end record; end record;
......
...@@ -1219,6 +1219,28 @@ package body Prj is ...@@ -1219,6 +1219,28 @@ package body Prj is
end if; end if;
end Other_Part; end Other_Part;
------------------
-- Create_Flags --
------------------
function Create_Flags
(Report_Error : Put_Line_Access;
When_No_Sources : Error_Warning;
Require_Sources_Other_Lang : Boolean := True;
Allow_Duplicate_Basenames : Boolean := True;
Compiler_Driver_Mandatory : Boolean := False;
Error_On_Unknown_Language : Boolean := True)
return Processing_Flags is
begin
return Processing_Flags'
(Report_Error => Report_Error,
When_No_Sources => When_No_Sources,
Require_Sources_Other_Lang => Require_Sources_Other_Lang,
Allow_Duplicate_Basenames => Allow_Duplicate_Basenames,
Error_On_Unknown_Language => Error_On_Unknown_Language,
Compiler_Driver_Mandatory => Compiler_Driver_Mandatory);
end Create_Flags;
begin begin
-- Make sure that the standard config and user project file extensions are -- Make sure that the standard config and user project file extensions are
-- compatible with canonical case file naming. -- compatible with canonical case file naming.
......
...@@ -1342,6 +1342,42 @@ package Prj is ...@@ -1342,6 +1342,42 @@ package Prj is
-- This procedure resets all the tables that are used when processing a -- This procedure resets all the tables that are used when processing a
-- project file tree. Initialize must be called before the call to Reset. -- project file tree. Initialize must be called before the call to Reset.
type Processing_Flags is private;
-- Flags used while parsing and processing a project tree.
-- These configure various behavior in the parser, as well as indicate how
-- to report error messages.
-- This structure does not allocate memory and never needs to be freed
function Create_Flags
(Report_Error : Put_Line_Access;
When_No_Sources : Error_Warning;
Require_Sources_Other_Lang : Boolean := True;
Allow_Duplicate_Basenames : Boolean := True;
Compiler_Driver_Mandatory : Boolean := False;
Error_On_Unknown_Language : Boolean := True)
return Processing_Flags;
-- If Allow_Duplicate_Basenames, then files with the same base names are
-- authorized within a project for source-based languages (never for unit
-- based languages)
-- If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
-- for each language must be defined, or we will not look for its source
-- files.
-- When_No_Sources indicates what should be done when no sources of a
-- language are found in a project where this language is declared.
-- If Require_Sources_Other_Lang is true, then all languages must have at
-- least one source file, or an error is reported via When_No_Sources. If
-- it is false, this is only required for Ada (and only if it is a language
-- of the project).
-- If Report_Error is null, use the standard error reporting mechanism
-- (Errout). Otherwise, report errors using Report_Error.
-- If Error_On_Unknown_Language is true, an error is displayed if some of
-- the source files listed in the project do not match any naming scheme
Gprbuild_Flags : constant Processing_Flags;
Gnatmake_Flags : constant Processing_Flags;
-- Flags used by the various tools. They all display the error messages
-- through Prj.Err
package Project_Boolean_Htable is new Simple_HTable package Project_Boolean_Htable is new Simple_HTable
(Header_Num => Header_Num, (Header_Num => Header_Num,
Element => Boolean, Element => Boolean,
...@@ -1517,4 +1553,29 @@ private ...@@ -1517,4 +1553,29 @@ private
-- Type to represent the part of a project tree which is private to the -- Type to represent the part of a project tree which is private to the
-- Project Manager. -- Project Manager.
type Processing_Flags is record
Require_Sources_Other_Lang : Boolean;
Report_Error : Put_Line_Access;
When_No_Sources : Error_Warning;
Allow_Duplicate_Basenames : Boolean;
Compiler_Driver_Mandatory : Boolean;
Error_On_Unknown_Language : Boolean;
end record;
Gprbuild_Flags : constant Processing_Flags :=
(Report_Error => null,
When_No_Sources => Warning,
Require_Sources_Other_Lang => True,
Allow_Duplicate_Basenames => False,
Compiler_Driver_Mandatory => True,
Error_On_Unknown_Language => True);
Gnatmake_Flags : constant Processing_Flags :=
(Report_Error => null,
When_No_Sources => Error,
Require_Sources_Other_Lang => False,
Allow_Duplicate_Basenames => False,
Compiler_Driver_Mandatory => False,
Error_On_Unknown_Language => False);
end Prj; end Prj;
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