aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2022-11-23 07:55:07 +0100
committerTristan Gingold <tgingold@free.fr>2022-11-23 07:55:07 +0100
commit81295dc08948e0cf103b4597580ed95a9cc25813 (patch)
treec78d18a8b447390bbb0b21a4c46c025b31a4f453 /src
parent93a88845da27290669c0dee990b7bb7232d58139 (diff)
downloadghdl-81295dc08948e0cf103b4597580ed95a9cc25813.tar.gz
ghdl-81295dc08948e0cf103b4597580ed95a9cc25813.tar.bz2
ghdl-81295dc08948e0cf103b4597580ed95a9cc25813.zip
file_comments: add comments_range to support deferred gathering
For processes.
Diffstat (limited to 'src')
-rw-r--r--src/file_comments.adb36
-rw-r--r--src/file_comments.ads19
-rw-r--r--src/vhdl/vhdl-comments.adb10
-rw-r--r--src/vhdl/vhdl-comments.ads4
-rw-r--r--src/vhdl/vhdl-parse.adb17
5 files changed, 81 insertions, 5 deletions
diff --git a/src/file_comments.adb b/src/file_comments.adb
index 505a4ee79..8fd0f93a9 100644
--- a/src/file_comments.adb
+++ b/src/file_comments.adb
@@ -53,24 +53,52 @@ package body File_Comments is
raise Internal_Error;
end Discard_Comments;
- procedure Gather_Comments (File : Source_File_Entry; N : Uns32)
+ procedure Save_Comments (File : Source_File_Entry;
+ Rng : out Comments_Range_Type)
is
use File_Comments_Tables;
begin
if Comments_Table.Last < File then
-- No comments for FILE.
+ Rng := (First | Last => No_Comment_Index);
return;
end if;
declare
Fc : File_Comment_Record renames Comments_Table.Table (File);
begin
- while Fc.Next <= Last (Fc.Comments) loop
- Fc.Comments.Table (Fc.Next).N := N;
- Fc.Next := Fc.Next + 1;
+ Rng := (First => Fc.Next, Last => Last (Fc.Comments));
+ Fc.Next := Rng.Last + 1;
+ end;
+ end Save_Comments;
+
+ procedure Gather_Comments (File : Source_File_Entry;
+ Rng : Comments_Range_Type;
+ N : Uns32)
+ is
+ use File_Comments_Tables;
+ begin
+ if Rng.Last = No_Comment_Index then
+ return;
+ end if;
+
+ pragma Assert (File <= Comments_Table.Last);
+ declare
+ Fc : File_Comment_Record renames Comments_Table.Table (File);
+ begin
+ for I in Rng.First .. Rng.Last loop
+ Fc.Comments.Table (I).N := N;
end loop;
end;
end Gather_Comments;
+ procedure Gather_Comments (File : Source_File_Entry; N : Uns32)
+ is
+ Rng : Comments_Range_Type;
+ begin
+ Save_Comments (File, Rng);
+ Gather_Comments (File, Rng, N);
+ end Gather_Comments;
+
procedure Rename_Comments (File : Source_File_Entry;
Prev : Uns32;
N : Uns32) is
diff --git a/src/file_comments.ads b/src/file_comments.ads
index 633d15d24..aa1f3806c 100644
--- a/src/file_comments.ads
+++ b/src/file_comments.ads
@@ -37,10 +37,22 @@ package File_Comments is
-- Discard unassigned comments ?
procedure Discard_Comments (File : Source_File_Entry);
- -- Assign node N to the last comments scanned.
+ type Comments_Range_Type is private;
+
+ -- Save comments recently scanned and not yet gathered.
+ procedure Save_Comments (File : Source_File_Entry;
+ Rng : out Comments_Range_Type);
+
+ -- Assign node N to the saved RNG comments.
-- This procedure is called by the parser when a node that could be
-- annotated with a comment is parsed.
procedure Gather_Comments (File : Source_File_Entry;
+ Rng : Comments_Range_Type;
+ N : Uns32);
+
+ -- Assign node N to the last comments scanned.
+ -- Identical to Save_Comments followed by above Gather_Comments.
+ procedure Gather_Comments (File : Source_File_Entry;
N : Uns32);
-- Reassign comments to node N.
@@ -78,6 +90,11 @@ package File_Comments is
Idx : Comment_Index)
return Comment_Index;
private
+ type Comments_Range_Type is record
+ -- Range of saved comments.
+ First, Last : Comment_Index;
+ end record;
+
type Comment_Record is record
-- Comment range in the source.
Start : Source_Ptr;
diff --git a/src/vhdl/vhdl-comments.adb b/src/vhdl/vhdl-comments.adb
index c7b98509e..a1cc2e7bb 100644
--- a/src/vhdl/vhdl-comments.adb
+++ b/src/vhdl/vhdl-comments.adb
@@ -25,6 +25,16 @@ with Files_Map;
with Vhdl.Scanner; use Vhdl.Scanner;
package body Vhdl.Comments is
+ procedure Save_Comments (Rng : out Comments_Range_Type) is
+ begin
+ Save_Comments (Get_Current_Source_File, Rng);
+ end Save_Comments;
+
+ procedure Gather_Comments (Rng : Comments_Range_Type; N : Iir) is
+ begin
+ Gather_Comments (Get_Current_Source_File, Rng, Uns32 (N));
+ end Gather_Comments;
+
procedure Gather_Comments (N : Iir) is
begin
Gather_Comments (Get_Current_Source_File, Uns32 (N));
diff --git a/src/vhdl/vhdl-comments.ads b/src/vhdl/vhdl-comments.ads
index 1d9694a49..82d469284 100644
--- a/src/vhdl/vhdl-comments.ads
+++ b/src/vhdl/vhdl-comments.ads
@@ -26,6 +26,10 @@ with File_Comments; use File_Comments;
with Vhdl.Nodes; use Vhdl.Nodes;
package Vhdl.Comments is
+ -- Save comments and attached them to a node.
+ procedure Save_Comments (Rng : out Comments_Range_Type);
+ procedure Gather_Comments (Rng : Comments_Range_Type; N : Iir);
+
-- Attach previously scanned comments to node N.
procedure Gather_Comments (N : Iir);
diff --git a/src/vhdl/vhdl-parse.adb b/src/vhdl/vhdl-parse.adb
index 532e6c8f8..d24cde24d 100644
--- a/src/vhdl/vhdl-parse.adb
+++ b/src/vhdl/vhdl-parse.adb
@@ -8562,15 +8562,27 @@ package body Vhdl.Parse is
Res: Iir;
Sensitivity_List : Iir_List;
Start_Loc, Begin_Loc, End_Loc : Location_Type;
+ Comments_Rng : File_Comments.Comments_Range_Type;
begin
Start_Loc := Get_Token_Location;
+ -- Attach comments now, as 'process' may appear alone, followed
+ -- by a comment for the next declaration.
+ if Flag_Gather_Comments then
+ Save_Comments (Comments_Rng);
+ end if;
+
-- Skip 'process'
Scan;
if Current_Token = Tok_Left_Paren then
Res := Create_Iir (Iir_Kind_Sensitized_Process_Statement);
+ -- Comments for the process.
+ if Flag_Gather_Comments then
+ Gather_Comments (Comments_Rng, Res);
+ end if;
+
-- Skip '('
Scan;
@@ -8589,6 +8601,11 @@ package body Vhdl.Parse is
Expect_Scan (Tok_Right_Paren);
else
Res := Create_Iir (Iir_Kind_Process_Statement);
+
+ -- Comments for the process.
+ if Flag_Gather_Comments then
+ Gather_Comments (Comments_Rng, Res);
+ end if;
end if;
Set_Location (Res, Loc);