Skip to content

Commit

Permalink
Merge branch 'issue_169' into 'master'
Browse files Browse the repository at this point in the history
Add Keep_Going switch

Closes #169

See merge request eng/ide/libadalang-tools!206
  • Loading branch information
joaopsazevedo committed May 2, 2024
2 parents 9acf52b + de9a16e commit 25789c0
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ testsuite/tests/internal
.clang-format

# VScode settings, updated by ancr
.vscode/settings.jon
.vscode
15 changes: 11 additions & 4 deletions src/pp-actions.adb
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ package body Pp.Actions is
-- files. We don't need any file locking here, because all the inner
-- processes that were writing to the File_Name_File have finished.

pragma Unreferenced (Tool);
use Ada.Text_IO;
File_Name_File : File_Type;
Ignored : Boolean;
Expand Down Expand Up @@ -447,6 +446,10 @@ package body Pp.Actions is
Cmd_Error (Ada.Exceptions.Exception_Message (X));
end;
end if;

if Tool.Failed then
raise Command_Line_Error_No_Tool_Name;
end if;
end Final;

----------------------------
Expand Down Expand Up @@ -6032,8 +6035,6 @@ package body Pp.Actions is
BOM_Seen : Boolean;
Unit : Analysis_Unit)
is
pragma Unreferenced (Tool);

Output_Mode : constant Output_Modes := Get_Output_Mode (Cmd);
Do_Diff : constant Boolean := Output_Mode in Replace_Modes;

Expand Down Expand Up @@ -6312,7 +6313,12 @@ package body Pp.Actions is
end;
end loop;

raise Command_Line_Error_No_Tool_Name;
if Arg (Cmd, Keep_Going) then
Tool.Failed := True;

else
raise Command_Line_Error_No_Tool_Name;
end if;
end if;
end;

Expand Down Expand Up @@ -6390,6 +6396,7 @@ package body Pp.Actions is
Put (" -q, --quiet - Quiet mode\n");
Put (" -v, --verbose - Verbose mode\n");
Put (" -dd - Progress indicator verbose mode\n");
Put (" -k, --keep-going - Keep going after errors formatting a source file\n");
Put (" --version - Display version and exit\n");
Put (" --help - Display usage and exit\n");
Put ("\n\n");
Expand Down
7 changes: 5 additions & 2 deletions src/pp-actions.ads
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- --
-- Libadalang Tools --
-- --
-- Copyright (C) 2021-2023, AdaCore --
-- Copyright (C) 2021-2024, AdaCore --
-- --
-- Libadalang Tools is free software; you can redistribute it and/or modi- --
-- fy it under terms of the GNU General Public License as published by --
Expand Down Expand Up @@ -129,7 +129,10 @@ private
overriding
procedure Tool_Help (Tool : Pp_Tool);

type Pp_Tool is new Tool_State with null record;
type Pp_Tool is new Tool_State with
record
Failed : Boolean := False;
end record;

-- For Debugging:

Expand Down
4 changes: 3 additions & 1 deletion src/pp-buffers.adb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- --
-- Libadalang Tools --
-- --
-- Copyright (C) 2013-2022, AdaCore --
-- Copyright (C) 2013-2024, AdaCore --
-- --
-- Libadalang Tools is free software; you can redistribute it and/or modi- --
-- fy it under terms of the GNU General Public License as published by --
Expand Down Expand Up @@ -158,6 +158,7 @@ package body Pp.Buffers is

procedure Dump_Buf (Buf : Buffer) is
use Dbg_Out;
Saved_Output_Enabled : constant Boolean := Dbg_Out.Output_Enabled;
begin
Dbg_Out.Output_Enabled := True;
Put
Expand All @@ -177,6 +178,7 @@ package body Pp.Buffers is
if At_End (Buf) then
Put ("At_End\n");
end if;
Dbg_Out.Output_Enabled := Saved_Output_Enabled;
end Dump_Buf;

procedure Dump_Buffer (Buf : Buffer) is
Expand Down
8 changes: 5 additions & 3 deletions src/pp-command_lines.ads
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- --
-- Libadalang Tools --
-- --
-- Copyright (C) 2021-2022, AdaCore --
-- Copyright (C) 2021-2024, AdaCore --
-- --
-- Libadalang Tools is free software; you can redistribute it and/or modi- --
-- fy it under terms of the GNU General Public License as published by --
Expand Down Expand Up @@ -61,7 +61,8 @@ package Pp.Command_Lines is
Separate_Label, -- Not documented
Separate_Stmt_Name, -- Not documented
Test, -- Not documented
Warnings); -- Not documented
Warnings, -- Not documented
Keep_Going);

package Pp_Flag_Switches is new Flag_Switches
(Descriptor,
Expand Down Expand Up @@ -93,7 +94,8 @@ package Pp.Command_Lines is
Separate_Label => null, -- Not documented
Separate_Stmt_Name => null, -- Not documented
Test => null, -- Not documented
Warnings => +"-w"]); -- Not documented
Warnings => +"-w", -- Not documented
Keep_Going => +"-k"]);

package Pp_Flag_Shorthands_N is new Pp_Flag_Switches.Set_Shorthands
([No_Tab => +"-N", -- Not documented
Expand Down
61 changes: 39 additions & 22 deletions src/pp-formatting.adb
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,11 @@ package body Pp.Formatting is
-- is terminated by NL.

procedure Raise_Token_Mismatch
(Message : String;
Lines_Data : Lines_Data_Rec;
Src_Buf : Buffer;
Src_Tok, Out_Tok : Scanner.Tokn_Cursor);
(Message : String;
Lines_Data : Lines_Data_Rec;
Src_Buf : Buffer;
Src_Tok : Scanner.Tokn_Cursor;
Out_Tok : Scanner.Tokn_Cursor);
-- Called when either Insert_Comments_And_Blank_Lines or Final_Check finds
-- a mismatch. Prints debugging information and raises Token_Mismatch.

Expand Down Expand Up @@ -1204,11 +1205,16 @@ package body Pp.Formatting is
when Post_Tree_Phases_Done => null;
end Post_Tree_Phases;

--------------------------
-- Raise_Token_Mismatch --
--------------------------

procedure Raise_Token_Mismatch
(Message : String;
Lines_Data : Lines_Data_Rec;
Src_Buf : Buffer;
Src_Tok, Out_Tok : Scanner.Tokn_Cursor)
(Message : String;
Lines_Data : Lines_Data_Rec;
Src_Buf : Buffer;
Src_Tok : Scanner.Tokn_Cursor;
Out_Tok : Scanner.Tokn_Cursor)
is
Out_Buf : Buffer renames Lines_Data.Out_Buf;

Expand All @@ -1228,20 +1234,31 @@ package body Pp.Formatting is
Error_Sloc := To_Langkit (Sloc (Src_Tok));

if Enable_Token_Mismatch then
Utils.Dbg_Out.Output_Enabled := True;
Err_Out.Put ("Src_Buf:\n");
Dump_Buf (Src_Buf);
Err_Out.Put ("Out_Buf:\n");
Dump_Buf (Out_Buf);

Err_Out.Put
("\1: Token mismatch: \2 --> \3\n",
Message, Txt (Src_Tok), Txt (Out_Tok));
Err_Out.Put ("Src tokens:\n");
Put_Tokens (Highlight => Src_Tok);
Err_Out.Put ("========================================\n");
Err_Out.Put ("Out tokens:\n");
Put_Tokens (Highlight => Out_Tok);
declare
Saved_Output_Enabled : constant Boolean :=
Utils.Dbg_Out.Output_Enabled;

begin
Utils.Dbg_Out.Output_Enabled := True;
Err_Out.Put ("Token Mismatch\n");
Err_Out.Put ("Src_Buf:\n");
Dump_Buf (Src_Buf);
Err_Out.Put ("========================================\n");
Err_Out.Put ("Out_Buf:\n");
Dump_Buf (Out_Buf);

Err_Out.Put
("\1: Token mismatch: \2 --> \3\n",
Message, Txt (Src_Tok), Txt (Out_Tok));
Err_Out.Put ("Src tokens:\n");
Put_Tokens
(Highlight => Src_Tok, File => Ada.Text_IO.Standard_Error);
Err_Out.Put ("========================================\n");
Err_Out.Put ("Out tokens:\n");
Put_Tokens
(Highlight => Out_Tok, File => Ada.Text_IO.Standard_Error);
Utils.Dbg_Out.Output_Enabled := Saved_Output_Enabled;
end;
end if;

raise Token_Mismatch;
Expand Down
Loading

0 comments on commit 25789c0

Please sign in to comment.