diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-06-02 09:18:15 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-06-03 06:43:51 +0200 |
commit | edfccd332a56771311fefdbfcffcf269c8026aba (patch) | |
tree | 6bab8f5f9b123f1daf78487403838f17ab2b5bec /src/ghdldrv | |
parent | 6aa66fc7a9bee40e9a3d87bad712d654caad411c (diff) | |
download | ghdl-edfccd332a56771311fefdbfcffcf269c8026aba.tar.gz ghdl-edfccd332a56771311fefdbfcffcf269c8026aba.tar.bz2 ghdl-edfccd332a56771311fefdbfcffcf269c8026aba.zip |
vhdl-formatters: add range for indent.
Diffstat (limited to 'src/ghdldrv')
-rw-r--r-- | src/ghdldrv/ghdlmain.adb | 10 | ||||
-rw-r--r-- | src/ghdldrv/ghdlmain.ads | 3 | ||||
-rw-r--r-- | src/ghdldrv/ghdlprint.adb | 31 |
3 files changed, 42 insertions, 2 deletions
diff --git a/src/ghdldrv/ghdlmain.adb b/src/ghdldrv/ghdlmain.adb index 932228b51..1b849c75c 100644 --- a/src/ghdldrv/ghdlmain.adb +++ b/src/ghdldrv/ghdlmain.adb @@ -263,6 +263,16 @@ package body Ghdlmain is Report_Msg (Msgid_Warning, Option, No_Source_Coord, Msg); end Warning; + function Index (Str : String; C : Character) return Natural is + begin + for I in Str'Range loop + if Str (I) = C then + return I; + end if; + end loop; + return 0; + end Index; + procedure Main is use Ada.Command_Line; diff --git a/src/ghdldrv/ghdlmain.ads b/src/ghdldrv/ghdlmain.ads index f5ac4b05d..226dc9f94 100644 --- a/src/ghdldrv/ghdlmain.ads +++ b/src/ghdldrv/ghdlmain.ads @@ -69,6 +69,9 @@ package Ghdlmain is procedure Error (Msg : String); procedure Warning (Msg : String); + -- Return the index of C in STR, or 0 if not found. + function Index (Str : String; C : Character) return Natural; + -- May be raise by perform_action if the arguments are bad. Option_Error : exception renames Errorout.Option_Error; diff --git a/src/ghdldrv/ghdlprint.adb b/src/ghdldrv/ghdlprint.adb index c06a907ba..b93cd147b 100644 --- a/src/ghdldrv/ghdlprint.adb +++ b/src/ghdldrv/ghdlprint.adb @@ -962,6 +962,8 @@ package body Ghdlprint is Flag_Sem : Boolean := True; Flag_Format : Boolean := False; Flag_Indent : Boolean := False; + First_Line : Positive := 1; + Last_Line : Positive := Positive'Last; end record; function Decode_Command (Cmd : Command_Reprint; Name : String) return Boolean; @@ -991,7 +993,9 @@ package body Ghdlprint is procedure Decode_Option (Cmd : in out Command_Reprint; Option : String; Arg : String; - Res : out Option_Res) is + Res : out Option_Res) + is + pragma Assert (Option'First = 1); begin if Option = "--no-sem" then Cmd.Flag_Sem := False; @@ -1004,6 +1008,28 @@ package body Ghdlprint is Cmd.Flag_Format := False; Cmd.Flag_Indent := True; Res := Option_Ok; + elsif Option'Length > 8 and then Option (1 .. 8) = "--range=" then + declare + F : constant Natural := 9; + L : constant Natural := Option'Last; + Colon : constant Natural := Index (Option (F .. L), ':'); + begin + if Colon = 0 then + Cmd.First_Line := Positive'Value (Option (F .. L)); + Cmd.Last_Line := Cmd.First_Line; + else + if Colon > 9 then + Cmd.First_Line := Positive'Value (Option (F .. Colon - 1)); + end if; + if Colon < Option'Last then + Cmd.Last_Line := Positive'Value (Option (Colon + 1 .. L)); + end if; + end if; + Res := Option_Ok; + exception + when Constraint_Error => + Res := Option_Err; + end; else Decode_Option (Command_Lib (Cmd), Option, Arg, Res); end if; @@ -1075,7 +1101,8 @@ package body Ghdlprint is if Cmd.Flag_Format then Vhdl.Formatters.Format (Design_File); elsif Cmd.Flag_Indent then - Vhdl.Formatters.Indent (Design_File); + Vhdl.Formatters.Indent (Design_File, + Cmd.First_Line, Cmd.Last_Line); end if; end loop; end Perform_Action; |