diff options
Diffstat (limited to 'src/vhdl')
-rw-r--r-- | src/vhdl/vhdl-comments.adb | 33 | ||||
-rw-r--r-- | src/vhdl/vhdl-comments.ads | 28 | ||||
-rw-r--r-- | src/vhdl/vhdl-parse.adb | 26 | ||||
-rw-r--r-- | src/vhdl/vhdl-scanner.adb | 7 |
4 files changed, 90 insertions, 4 deletions
diff --git a/src/vhdl/vhdl-comments.adb b/src/vhdl/vhdl-comments.adb new file mode 100644 index 000000000..bc7a3e2e8 --- /dev/null +++ b/src/vhdl/vhdl-comments.adb @@ -0,0 +1,33 @@ +-- Specialisation of File_Comments for vhdl +-- Copyright (C) 2022 Tristan Gingold +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <gnu.org/licenses>. + +-- All the variables declared in this package are set by Parse_Option function +-- and can by read as soon as the command line is parsed. +-- +-- 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.Scanner; use Vhdl.Scanner; + +package body Vhdl.Comments is + procedure Gather_Comments (N : Iir) is + begin + Gather_Comments (Get_Current_Source_File, Uns32 (N)); + end Gather_Comments; +end Vhdl.Comments; diff --git a/src/vhdl/vhdl-comments.ads b/src/vhdl/vhdl-comments.ads new file mode 100644 index 000000000..b9b63b667 --- /dev/null +++ b/src/vhdl/vhdl-comments.ads @@ -0,0 +1,28 @@ +-- Specialisation of File_Comments for vhdl +-- Copyright (C) 2022 Tristan Gingold +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <gnu.org/licenses>. + +-- All the variables declared in this package are set by Parse_Option function +-- and can by read as soon as the command line is parsed. +-- +-- Since the names are not prefixed, this package is expected to be with'ed +-- but not to be use'd. + +with Vhdl.Nodes; use Vhdl.Nodes; + +package Vhdl.Comments is + -- Attach previously scanned comments to node N. + procedure Gather_Comments (N : Iir); +end Vhdl.Comments; diff --git a/src/vhdl/vhdl-parse.adb b/src/vhdl/vhdl-parse.adb index 929f47b61..7e47e05cb 100644 --- a/src/vhdl/vhdl-parse.adb +++ b/src/vhdl/vhdl-parse.adb @@ -13,18 +13,23 @@ -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <gnu.org/licenses>. + +with Std_Names; use Std_Names; +with Flags; use Flags; +with Str_Table; +with Errorout; use Errorout; +with File_Comments; + with Vhdl.Nodes_Utils; use Vhdl.Nodes_Utils; with Vhdl.Tokens; use Vhdl.Tokens; with Vhdl.Scanner; use Vhdl.Scanner; with Vhdl.Utils; use Vhdl.Utils; -with Errorout; use Errorout; with Vhdl.Errors; use Vhdl.Errors; -with Std_Names; use Std_Names; -with Flags; use Flags; with Vhdl.Parse_Psl; -with Str_Table; with Vhdl.Xrefs; with Vhdl.Elocations; use Vhdl.Elocations; +with Vhdl.Comments; use Vhdl.Comments; + with PSL.Types; use PSL.Types; -- Recursive descendant parser. @@ -1709,6 +1714,10 @@ package body Vhdl.Parse is Set_Start_Location (First, Get_Token_Location); end if; + if Flag_Gather_Comments then + Gather_Comments (First); + end if; + if Current_Token = Tok_Identifier then Is_Default := True; Has_Class := False; @@ -11701,6 +11710,11 @@ package body Vhdl.Parse is Set_Location (Res); Set_Date_State (Res, Date_Extern); + -- Attach comments to the design unit. + if Flag_Gather_Comments then + Gather_Comments (Res); + end if; + Parse_Context_Clause (Res); if Get_Library_Unit (Res) = Null_Iir then @@ -11767,6 +11781,10 @@ package body Vhdl.Parse is Set_Last_Design_Unit (Res, Last_Design); end loop; + if Flag_Gather_Comments then + File_Comments.Sort_Comments_By_Node (Get_Current_Source_File); + end if; + if Last_Design = Null_Iir then Error_Msg_Parse ("design file is empty (no design unit found)"); end if; diff --git a/src/vhdl/vhdl-scanner.adb b/src/vhdl/vhdl-scanner.adb index a6c7b64dd..cee853792 100644 --- a/src/vhdl/vhdl-scanner.adb +++ b/src/vhdl/vhdl-scanner.adb @@ -20,6 +20,7 @@ with Files_Map; use Files_Map; with Std_Names; with Str_Table; with Flags; use Flags; +with File_Comments; use File_Comments; package body Vhdl.Scanner is @@ -2162,6 +2163,12 @@ package body Vhdl.Scanner is end if; Pos := Pos + 1; end loop; + + if Flag_Gather_Comments then + Add_Comment (Current_Context.Source_File, + Current_Context.Token_Pos, Pos - 1); + end if; + if Flag_Comment then Current_Token := Tok_Line_Comment; return; |