From f722f900f4211bbddc0f432ce652e68313807ee0 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Sun, 20 Nov 2022 20:01:14 +0100 Subject: pyGHDL: add file_comments.py --- src/file_comments.adb | 18 ++++++++++++++++++ src/file_comments.ads | 6 ++++++ src/vhdl/vhdl-comments.adb | 11 +++++++++-- src/vhdl/vhdl-comments.ads | 9 +++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/file_comments.adb b/src/file_comments.adb index 183b17144..505a4ee79 100644 --- a/src/file_comments.adb +++ b/src/file_comments.adb @@ -166,6 +166,24 @@ package body File_Comments is Last := Fc.Comments.Table (Idx).Last; end Get_Comment; + function Get_Comment_Start (File : Source_File_Entry; + Idx : Comment_Index) return Source_Ptr + is + Start, Last : Source_Ptr; + begin + Get_Comment (File, Idx, Start, Last); + return Start; + end Get_Comment_Start; + + function Get_Comment_Last (File : Source_File_Entry; + Idx : Comment_Index) return Source_Ptr + is + Start, Last : Source_Ptr; + begin + Get_Comment (File, Idx, Start, Last); + return Last; + end Get_Comment_Last; + function Get_Next_Comment (File : Source_File_Entry; Idx : Comment_Index) return Comment_Index is diff --git a/src/file_comments.ads b/src/file_comments.ads index 8ed07566d..633d15d24 100644 --- a/src/file_comments.ads +++ b/src/file_comments.ads @@ -66,6 +66,12 @@ package File_Comments is Idx : Comment_Index; Start, Last : out Source_Ptr); + -- Simpler functions for python binding. + function Get_Comment_Start (File : Source_File_Entry; + Idx : Comment_Index) return Source_Ptr; + function Get_Comment_Last (File : Source_File_Entry; + Idx : Comment_Index) return Source_Ptr; + -- Return the next comment after IDX. -- Return No_Comment_Index if no related comment exists. function Get_Next_Comment (File : Source_File_Entry; diff --git a/src/vhdl/vhdl-comments.adb b/src/vhdl/vhdl-comments.adb index bc7a3e2e8..c7b98509e 100644 --- a/src/vhdl/vhdl-comments.adb +++ b/src/vhdl/vhdl-comments.adb @@ -20,8 +20,7 @@ -- Since the names are not prefixed, this package is expected to be with'ed -- but not to be use'd. -with Types; use Types; -with File_Comments; use File_Comments; +with Files_Map; with Vhdl.Scanner; use Vhdl.Scanner; @@ -30,4 +29,12 @@ package body Vhdl.Comments is begin Gather_Comments (Get_Current_Source_File, Uns32 (N)); end Gather_Comments; + + function Find_First_Comment (File : Source_File_Entry; N : Node) + return Comment_Index + is + pragma Assert (Files_Map.Location_To_File (Get_Location (N)) = File); + begin + return Find_First_Comment (File, Uns32 (N)); + end Find_First_Comment; end Vhdl.Comments; diff --git a/src/vhdl/vhdl-comments.ads b/src/vhdl/vhdl-comments.ads index b9b63b667..1d9694a49 100644 --- a/src/vhdl/vhdl-comments.ads +++ b/src/vhdl/vhdl-comments.ads @@ -20,9 +20,18 @@ -- Since the names are not prefixed, this package is expected to be with'ed -- but not to be use'd. +with Types; use Types; +with File_Comments; use File_Comments; + with Vhdl.Nodes; use Vhdl.Nodes; package Vhdl.Comments is -- Attach previously scanned comments to node N. procedure Gather_Comments (N : Iir); + + -- Return the first comment attached to node N. FILE must be the file + -- of N. + -- Use File_Comments to iterate on comments. + function Find_First_Comment (File : Source_File_Entry; N : Node) + return Comment_Index; end Vhdl.Comments; -- cgit v1.2.3