From 0af513e7b59a01f456f6f76369cedf67d8ffc5cf Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Mon, 21 Nov 2022 08:03:20 +0100 Subject: vhdl-parse: handle inside comments --- pyGHDL/libghdl/file_comments.py | 2 +- src/vhdl/vhdl-parse.adb | 31 +++++++++++++++++++++++++++++ testsuite/pyunit/DesignComment.vhdl | 14 ------------- testsuite/pyunit/libghdl/DesignComment.vhdl | 14 +++++++++++++ 4 files changed, 46 insertions(+), 15 deletions(-) delete mode 100644 testsuite/pyunit/DesignComment.vhdl create mode 100644 testsuite/pyunit/libghdl/DesignComment.vhdl diff --git a/pyGHDL/libghdl/file_comments.py b/pyGHDL/libghdl/file_comments.py index 1a942d008..a1ca11384 100644 --- a/pyGHDL/libghdl/file_comments.py +++ b/pyGHDL/libghdl/file_comments.py @@ -83,7 +83,7 @@ def Get_Comment(File: SourceFileEntry, Idx: Comment_Index) -> str: buf = files_map.Get_File_Buffer(File) s = Get_Comment_Start(File, Idx); l = Get_Comment_Last(File, Idx); - return buf[s:l].decode("iso-8859-1") + return buf[s:l+1].decode("iso-8859-1") @export @BindToLibGHDL("file_comments__get_next_comment") diff --git a/src/vhdl/vhdl-parse.adb b/src/vhdl/vhdl-parse.adb index 7e47e05cb..dee22aaed 100644 --- a/src/vhdl/vhdl-parse.adb +++ b/src/vhdl/vhdl-parse.adb @@ -1714,6 +1714,7 @@ package body Vhdl.Parse is Set_Start_Location (First, Get_Token_Location); end if; + -- Comments for the interface. if Flag_Gather_Comments then Gather_Comments (First); end if; @@ -5696,6 +5697,12 @@ package body Vhdl.Parse is -- Skip 'is'. Expect_Scan (Tok_Is); + -- Comments after 'entity' but before the first generic or port are + -- attached to the entity. + if Flag_Gather_Comments then + Gather_Comments (Res); + end if; + Parse_Generic_Port_Clauses (Res); Parse_Declarative_Part (Res, Res); @@ -10541,6 +10548,12 @@ package body Vhdl.Parse is -- Skip 'is'. Expect_Scan (Tok_Is); + -- Comments after 'architecture' but before the first declaration are + -- attached to the architecture. + if Flag_Gather_Comments then + Gather_Comments (Res); + end if; + Parse_Declarative_Part (Res, Res); -- Skip 'begin'. @@ -11032,6 +11045,12 @@ package body Vhdl.Parse is -- Skip 'is'. Expect_Scan (Tok_Is); + -- Comments after 'context' but before the first clause are attached + -- to the context. + if Flag_Gather_Comments then + Gather_Comments (Res); + end if; + Parse_Configuration_Declarative_Part (Res); Set_Block_Configuration (Res, Parse_Block_Configuration); @@ -11132,6 +11151,12 @@ package body Vhdl.Parse is Set_Identifier (Res, Id); Set_Parent (Res, Parent); + -- Comments after 'package' but before the first declaration are + -- attached to the package. + if Flag_Gather_Comments then + Gather_Comments (Res); + end if; + if Current_Token = Tok_Generic then Check_Vhdl_At_Least_2008 ("generic packages"); Set_Package_Header (Res, Parse_Package_Header); @@ -11592,6 +11617,12 @@ package body Vhdl.Parse is -- Skip 'is' Scan; + -- Comments after 'context' but before the first clause are attached + -- to the context. + if Flag_Gather_Comments then + Gather_Comments (Decl); + end if; + Parse_Context_Clause (Decl); Expect (Tok_End); diff --git a/testsuite/pyunit/DesignComment.vhdl b/testsuite/pyunit/DesignComment.vhdl deleted file mode 100644 index 5cd555d33..000000000 --- a/testsuite/pyunit/DesignComment.vhdl +++ /dev/null @@ -1,14 +0,0 @@ --- No copyright for :accum: design. - -library ieee; -use ieee.std_logic_1164.all; - -entity accum is - port ( - -- :a: and :b: are the inputs of the adder. - a, b : in std_logic_vector (31 downto 0); - -- :res: is the result of the adder. - res : out std_logic_vector (31 downto 0) - ); -end accum; - diff --git a/testsuite/pyunit/libghdl/DesignComment.vhdl b/testsuite/pyunit/libghdl/DesignComment.vhdl new file mode 100644 index 000000000..5cd555d33 --- /dev/null +++ b/testsuite/pyunit/libghdl/DesignComment.vhdl @@ -0,0 +1,14 @@ +-- No copyright for :accum: design. + +library ieee; +use ieee.std_logic_1164.all; + +entity accum is + port ( + -- :a: and :b: are the inputs of the adder. + a, b : in std_logic_vector (31 downto 0); + -- :res: is the result of the adder. + res : out std_logic_vector (31 downto 0) + ); +end accum; + -- cgit v1.2.3