Commit e4ffa8ad by Vincent Celier Committed by Arnaud Charlet

prj-makr.adb (Make): Preserve the comments from the original project file.

2006-02-13  Vincent Celier  <celier@adacore.com>

	* prj-makr.adb (Make): Preserve the comments from the original project
	file.
	When removing nodes (attributes Source_Dirs, Source_Files,
	Source_List_File and package Naming), save the comments and attach the
	saved comments to the newly created nodes.
	Do not add a with clause for the naming package if one already exists.

From-SVN: r111085
parent 97b7ca6f
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2001-2005, Free Software Foundation, Inc. -- -- Copyright (C) 2001-2006, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -136,6 +136,11 @@ package body Prj.Makr is ...@@ -136,6 +136,11 @@ package body Prj.Makr is
Project_Naming_Node : Project_Node_Id := Empty_Node; Project_Naming_Node : Project_Node_Id := Empty_Node;
Project_Naming_Decl : Project_Node_Id := Empty_Node; Project_Naming_Decl : Project_Node_Id := Empty_Node;
Naming_Package : Project_Node_Id := Empty_Node; Naming_Package : Project_Node_Id := Empty_Node;
Naming_Package_Comments : Project_Node_Id := Empty_Node;
Source_Files_Comments : Project_Node_Id := Empty_Node;
Source_Dirs_Comments : Project_Node_Id := Empty_Node;
Source_List_File_Comments : Project_Node_Id := Empty_Node;
Project_Naming_File_Name : String (1 .. Output_Name'Length + Project_Naming_File_Name : String (1 .. Output_Name'Length +
Naming_File_Suffix'Length); Naming_File_Suffix'Length);
...@@ -724,7 +729,8 @@ package body Prj.Makr is ...@@ -724,7 +729,8 @@ package body Prj.Makr is
(In_Tree => Tree, (In_Tree => Tree,
Project => Project_Node, Project => Project_Node,
Project_File_Name => Output_Name (1 .. Output_Name_Last), Project_File_Name => Output_Name (1 .. Output_Name_Last),
Always_Errout_Finalize => False); Always_Errout_Finalize => False,
Store_Comments => True);
-- Fail if parsing was not successful -- Fail if parsing was not successful
...@@ -768,7 +774,8 @@ package body Prj.Makr is ...@@ -768,7 +774,8 @@ package body Prj.Makr is
-- Remove attribute declarations of Source_Files, -- Remove attribute declarations of Source_Files,
-- Source_List_File, Source_Dirs, and the declaration of -- Source_List_File, Source_Dirs, and the declaration of
-- package Naming, if they exist. -- package Naming, if they exist, but preserve the comments
-- attached to these nodes.
declare declare
Declaration : Project_Node_Id := Declaration : Project_Node_Id :=
...@@ -779,38 +786,60 @@ package body Prj.Makr is ...@@ -779,38 +786,60 @@ package body Prj.Makr is
Previous : Project_Node_Id := Empty_Node; Previous : Project_Node_Id := Empty_Node;
Current_Node : Project_Node_Id := Empty_Node; Current_Node : Project_Node_Id := Empty_Node;
Name : Name_Id;
Kind_Of_Node : Project_Node_Kind;
Comments : Project_Node_Id;
begin begin
while Declaration /= Empty_Node loop while Declaration /= Empty_Node loop
Current_Node := Current_Item_Node (Declaration, Tree); Current_Node := Current_Item_Node (Declaration, Tree);
if (Kind_Of (Current_Node, Tree) = N_Attribute_Declaration Kind_Of_Node := Kind_Of (Current_Node, Tree);
and then
(Prj.Tree.Name_Of (Current_Node, Tree) = if Kind_Of_Node = N_Attribute_Declaration or else
Name_Source_Files Kind_Of_Node = N_Package_Declaration
or else Prj.Tree.Name_Of (Current_Node, Tree) = then
Name_Source_List_File Name := Prj.Tree.Name_Of (Current_Node, Tree);
or else Prj.Tree.Name_Of (Current_Node, Tree) =
Name_Source_Dirs)) if Name = Name_Source_Files or else
or else Name = Name_Source_List_File or else
(Kind_Of (Current_Node, Tree) = N_Package_Declaration Name = Name_Source_Dirs or else
and then Prj.Tree.Name_Of (Current_Node, Tree) = Name = Name_Naming
Name_Naming)
then then
Comments :=
Tree.Project_Nodes.Table (Current_Node).Comments;
if Name = Name_Source_Files then
Source_Files_Comments := Comments;
elsif Name = Name_Source_List_File then
Source_List_File_Comments := Comments;
elsif Name = Name_Source_Dirs then
Source_Dirs_Comments := Comments;
elsif Name = Name_Naming then
Naming_Package_Comments := Comments;
end if;
if Previous = Empty_Node then if Previous = Empty_Node then
Set_First_Declarative_Item_Of Set_First_Declarative_Item_Of
(Project_Declaration_Of (Project_Node, Tree), (Project_Declaration_Of (Project_Node, Tree),
Tree, Tree,
To => Next_Declarative_Item (Declaration, Tree)); To => Next_Declarative_Item
(Declaration, Tree));
else else
Set_Next_Declarative_Item Set_Next_Declarative_Item
(Previous, Tree, (Previous, Tree,
To => Next_Declarative_Item (Declaration, Tree)); To => Next_Declarative_Item
(Declaration, Tree));
end if; end if;
else else
Previous := Declaration; Previous := Declaration;
end if; end if;
end if;
Declaration := Next_Declarative_Item (Declaration, Tree); Declaration := Next_Declarative_Item (Declaration, Tree);
end loop; end loop;
...@@ -1058,18 +1087,28 @@ package body Prj.Makr is ...@@ -1058,18 +1087,28 @@ package body Prj.Makr is
Set_Current_Term (Term, Tree, To => Empty_List); Set_Current_Term (Term, Tree, To => Empty_List);
end; end;
-- Add a with clause on the naming project in the main project -- Add a with clause on the naming project in the main project, if
-- there is not already one.
declare declare
With_Clause : constant Project_Node_Id := With_Clause : Project_Node_Id :=
Default_Project_Node First_With_Clause_Of (Project_Node, Tree);
(Of_Kind => N_With_Clause, In_Tree => Tree);
begin begin
while With_Clause /= Empty_Node loop
exit when
Prj.Tree.Name_Of (With_Clause, Tree) = Project_Naming_Id;
With_Clause := Next_With_Clause_Of (With_Clause, Tree);
end loop;
if With_Clause = Empty_Node then
With_Clause := Default_Project_Node
(Of_Kind => N_With_Clause, In_Tree => Tree);
Set_Next_With_Clause_Of Set_Next_With_Clause_Of
(With_Clause, Tree, (With_Clause, Tree,
To => First_With_Clause_Of (Project_Node, Tree)); To => First_With_Clause_Of (Project_Node, Tree));
Set_First_With_Clause_Of (Project_Node, Tree, To => With_Clause); Set_First_With_Clause_Of
(Project_Node, Tree, To => With_Clause);
Set_Name_Of (With_Clause, Tree, To => Project_Naming_Id); Set_Name_Of (With_Clause, Tree, To => Project_Naming_Id);
-- We set the project node to something different than -- We set the project node to something different than
...@@ -1082,6 +1121,7 @@ package body Prj.Makr is ...@@ -1082,6 +1121,7 @@ package body Prj.Makr is
Name_Buffer (1 .. Name_Len) := Name_Buffer (1 .. Name_Len) :=
Project_Naming_File_Name (1 .. Project_Naming_Last); Project_Naming_File_Name (1 .. Project_Naming_Last);
Set_String_Value_Of (With_Clause, Tree, To => Name_Find); Set_String_Value_Of (With_Clause, Tree, To => Name_Find);
end if;
end; end;
Project_Declaration := Project_Declaration_Of (Project_Node, Tree); Project_Declaration := Project_Declaration_Of (Project_Node, Tree);
...@@ -1109,6 +1149,12 @@ package body Prj.Makr is ...@@ -1109,6 +1149,12 @@ package body Prj.Makr is
Set_Name_Of (Naming, Tree, To => Name_Naming); Set_Name_Of (Naming, Tree, To => Name_Naming);
Set_Project_Of_Renamed_Package_Of Set_Project_Of_Renamed_Package_Of
(Naming, Tree, To => Project_Naming_Node); (Naming, Tree, To => Project_Naming_Node);
-- Attach the comments, if any, that were saved for package
-- Naming.
Tree.Project_Nodes.Table (Naming).Comments :=
Naming_Package_Comments;
end; end;
-- Add an attribute declaration for Source_Dirs, initialized as an -- Add an attribute declaration for Source_Dirs, initialized as an
...@@ -1154,6 +1200,12 @@ package body Prj.Makr is ...@@ -1154,6 +1200,12 @@ package body Prj.Makr is
In_Tree => Tree, In_Tree => Tree,
And_Expr_Kind => List); And_Expr_Kind => List);
Set_Current_Term (Term, Tree, To => Source_Dirs_List); Set_Current_Term (Term, Tree, To => Source_Dirs_List);
-- Attach the comments, if any, that were saved for attribute
-- Source_Dirs.
Tree.Project_Nodes.Table (Attribute).Comments :=
Source_Dirs_Comments;
end; end;
-- Add an attribute declaration for Source_List_File with the -- Add an attribute declaration for Source_List_File with the
...@@ -1204,6 +1256,17 @@ package body Prj.Makr is ...@@ -1204,6 +1256,17 @@ package body Prj.Makr is
Name_Buffer (1 .. Name_Len) := Name_Buffer (1 .. Name_Len) :=
Source_List_Path (1 .. Source_List_Last); Source_List_Path (1 .. Source_List_Last);
Set_String_Value_Of (Value, Tree, To => Name_Find); Set_String_Value_Of (Value, Tree, To => Name_Find);
-- If there was no comments for attribute Source_List_File, put
-- those for Source_Files, if they exist.
if Source_List_File_Comments /= Empty_Node then
Tree.Project_Nodes.Table (Attribute).Comments :=
Source_List_File_Comments;
else
Tree.Project_Nodes.Table (Attribute).Comments :=
Source_Files_Comments;
end if;
end; end;
end if; end if;
......
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