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