From 81295dc08948e0cf103b4597580ed95a9cc25813 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Wed, 23 Nov 2022 07:55:07 +0100 Subject: file_comments: add comments_range to support deferred gathering For processes. --- src/vhdl/vhdl-comments.adb | 10 ++++++++++ src/vhdl/vhdl-comments.ads | 4 ++++ src/vhdl/vhdl-parse.adb | 17 +++++++++++++++++ 3 files changed, 31 insertions(+) (limited to 'src/vhdl') 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); -- cgit v1.2.3