Commit d06e0e9f authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Add Put_Info and Put_Error with colors

parent e27fb2ef
...@@ -166,22 +166,18 @@ package body TASTE.AADL_Parser is ...@@ -166,22 +166,18 @@ package body TASTE.AADL_Parser is
| No_RCM_Error | No_RCM_Error
| Deployment_View_Error | Deployment_View_Error
| Data_View_Error | Data_View_Error
| TASTE.Backend.Skeletons.Skeleton_Error
| Device_Driver_Error => | Device_Driver_Error =>
Put (Red_Bold & "[ERROR] " & White_Bold); Put_Error (Exception_Message (Error));
Put_Line (Exception_Message (Error) & No_Color);
raise Quit_Taste; raise Quit_Taste;
when GNAT.Command_Line.Exit_From_Command_Line => when GNAT.Command_Line.Exit_From_Command_Line =>
New_Line; New_Line;
Put (Yellow_Bold & "[INFO] " & No_Color); Put_Info ("For more information, visit " & Underline & White_Bold
Put ("For more information, visit " & Underline & White_Bold); & "https://taste.tools");
Put_Line ("https://taste.tools" & No_Color);
raise Quit_Taste; raise Quit_Taste;
when GNAT.Command_Line.Invalid_Switch when GNAT.Command_Line.Invalid_Switch
| GNAT.Command_Line.Invalid_Parameter | GNAT.Command_Line.Invalid_Parameter
| GNAT.Command_Line.Invalid_Section => | GNAT.Command_Line.Invalid_Section =>
Put (Red_Bold & "[ERROR] " & White_Bold); Put_Error ("Invalid switch or parameter (try --help)" & No_Color);
Put_Line ("Invalid switch or parameter (try --help)" & No_Color);
raise Quit_Taste; raise Quit_Taste;
when E : others => when E : others =>
Errors.Display_Bug_Box (E); Errors.Display_Bug_Box (E);
...@@ -190,15 +186,15 @@ package body TASTE.AADL_Parser is ...@@ -190,15 +186,15 @@ package body TASTE.AADL_Parser is
procedure Dump (Model : TASTE_Model) is procedure Dump (Model : TASTE_Model) is
begin begin
Put_Line ("==== Dump of the Interface View ===="); Put_Info ("==== Dump of the Interface View ====");
Model.Interface_View.Debug_Dump; Model.Interface_View.Debug_Dump;
if Model.Configuration.Deployment_View.all'Length > 0 then if Model.Configuration.Deployment_View.all'Length > 0 then
Put_Line ("==== Dump of the Deployment View ===="); Put_Info ("==== Dump of the Deployment View ====");
Model.Deployment_View.Debug_Dump; Model.Deployment_View.Debug_Dump;
end if; end if;
Put_Line ("==== Dump of the Data View ===="); Put_Info ("==== Dump of the Data View ====");
Model.Data_View.Debug_Dump; Model.Data_View.Debug_Dump;
Put_Line ("==== Dump of the Command Line ===="); Put_Info ("==== Dump of the Command Line ====");
Model.Configuration.Debug_Dump; Model.Configuration.Debug_Dump;
end Dump; end Dump;
...@@ -210,6 +206,12 @@ package body TASTE.AADL_Parser is ...@@ -210,6 +206,12 @@ package body TASTE.AADL_Parser is
procedure Generate_Skeletons (Model : TASTE_Model) is procedure Generate_Skeletons (Model : TASTE_Model) is
begin begin
TASTE.Backend.Skeletons.Generate (Model); TASTE.Backend.Skeletons.Generate (Model);
exception
when Error : TASTE.Backend.Skeletons.Skeleton_Error =>
Put_Error (Exception_Message (Error));
raise Quit_Taste;
when E : others =>
Errors.Display_Bug_Box (E);
raise Quit_Taste;
end Generate_Skeletons; end Generate_Skeletons;
end TASTE.AADL_Parser; end TASTE.AADL_Parser;
with Text_IO, with Text_IO,
Templates_Parser; Templates_Parser,
TASTE.Parser_Utils;
use Text_IO, use Text_IO,
Templates_Parser; Templates_Parser,
TASTE.Parser_Utils;
package body TASTE.Backend.Build_Script is package body TASTE.Backend.Build_Script is
procedure Generate (Model : TASTE_Model) is procedure Generate (Model : TASTE_Model) is
...@@ -34,7 +36,7 @@ package body TASTE.Backend.Build_Script is ...@@ -34,7 +36,7 @@ package body TASTE.Backend.Build_Script is
end if; end if;
end; end;
end loop; end loop;
Put_Line ("==== Generating build script ===="); Put_Info ("Generating build script");
declare declare
Template_Data : constant Translate_Table := Template_Data : constant Translate_Table :=
(1 => Assoc ("Interface_View_Path", (1 => Assoc ("Interface_View_Path",
......
...@@ -2,11 +2,13 @@ with Text_IO; use Text_IO; ...@@ -2,11 +2,13 @@ with Text_IO; use Text_IO;
with Ada.Strings.Unbounded, with Ada.Strings.Unbounded,
Ada.Characters.Handling, Ada.Characters.Handling,
Ada.Exceptions, Ada.Exceptions,
Ada.Directories; Ada.Directories,
TASTE.Parser_Utils;
use Ada.Characters.Handling, use Ada.Characters.Handling,
Ada.Exceptions, Ada.Exceptions,
Ada.Directories; Ada.Directories,
TASTE.Parser_Utils;
-- This package covers the generation of skeletons for all supported languages -- This package covers the generation of skeletons for all supported languages
-- There is no code that is specific to one particular language. The package -- There is no code that is specific to one particular language. The package
...@@ -70,7 +72,7 @@ package body TASTE.Backend.Skeletons is ...@@ -70,7 +72,7 @@ package body TASTE.Backend.Skeletons is
return Interfaces_Tag; return Interfaces_Tag;
end Process_Interfaces; end Process_Interfaces;
begin begin
Put_Line ("=== Generate skeletons ==="); Put_Info ("=== Generate skeletons ===");
for Each of Model.Interface_View.Flat_Functions loop for Each of Model.Interface_View.Flat_Functions loop
declare declare
Language : constant String := Language_Spelling (Each); Language : constant String := Language_Spelling (Each);
...@@ -122,25 +124,28 @@ package body TASTE.Backend.Skeletons is ...@@ -122,25 +124,28 @@ package body TASTE.Backend.Skeletons is
if Proceed then if Proceed then
-- Create directory tree (output/function/language/src) -- Create directory tree (output/function/language/src)
Create_Path (Output_Src); Create_Path (Output_Src);
Put_Line ("*** Generating " & Header_File); Put_Info ("Generating " & Header_File);
Create (File => Output, Create (File => Output,
Mode => Out_File, Mode => Out_File,
Name => Output_Src & Header_File); Name => Output_Src & Header_File);
Put_Line (Output, Header_Text); Put_Line (Output, Header_Text);
Close (Output); Close (Output);
if not Exists (Output_Src & Body_File) then if not Exists (Output_Src & Body_File) then
Put_Line ("*** Generating " & Body_File); Put_Info ("Generating " & Body_File);
Create (File => Output, Create (File => Output,
Mode => Out_File, Mode => Out_File,
Name => Output_Src & Body_File); Name => Output_Src & Body_File);
Put_Line (Output, Body_Text); Put_Line (Output, Body_Text);
Close (Output); Close (Output);
else
Put_Info (Body_File & " already exists, ignoring");
end if; end if;
else else
Put_Line ("Ignoring function " & To_String (Each.Name)); Put_Info ("Ignoring function " & To_String (Each.Name));
end if; end if;
exception exception
when E : End_Error => when E : End_Error
| Text_IO.Use_Error =>
if Is_Open (Output) then if Is_Open (Output) then
Close (Output); Close (Output);
end if; end if;
......
...@@ -23,6 +23,16 @@ package body TASTE.Parser_Utils is ...@@ -23,6 +23,16 @@ package body TASTE.Parser_Utils is
Ocarina.Instances.Queries, Ocarina.Instances.Queries,
Ocarina.ME_AADL; Ocarina.ME_AADL;
procedure Put_Info (Info : String) is
begin
Put_Line (Yellow_Bold & "[INFO] " & No_Color & Info & No_Color);
end Put_Info;
procedure Put_Error (Error : String) is
begin
Put_Line (Red_Bold & "[ERROR] " & White_Bold & Error & No_Color);
end Put_Error;
procedure Banner is procedure Banner is
The_Banner : constant String := The_Banner : constant String :=
Yellow_Bold & "TASTE AADL Parser" & No_Color & " (Version " Yellow_Bold & "TASTE AADL Parser" & No_Color & " (Version "
......
...@@ -51,6 +51,9 @@ package TASTE.Parser_Utils is ...@@ -51,6 +51,9 @@ package TASTE.Parser_Utils is
(if Is_Tty then ASCII.ESC & "[4m" else ""); (if Is_Tty then ASCII.ESC & "[4m" else "");
function White_Bold return String is (if Is_Tty then White & Bold else ""); function White_Bold return String is (if Is_Tty then White & Bold else "");
procedure Put_Info (Info : String);
procedure Put_Error (Error : String);
procedure Banner; procedure Banner;
AADL_Parser_Error : exception; AADL_Parser_Error : exception;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment