Commit 1f6eec13 authored by hugues.jerome's avatar hugues.jerome
Browse files

* Add the flag '-y' to command line parameters: allows to

          automatically load AADL files on demand.

	  For all packages "A::B::C" that are withed, add the file
	  a-b-c.aadl to the list of files to be parsed.



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/ocarina@1373 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent e620213c
...@@ -221,4 +221,17 @@ package body Errors is ...@@ -221,4 +221,17 @@ package body Errors is
OS_Exit (3); OS_Exit (3);
end Display_Bug_Box; end Display_Bug_Box;
-------------------
-- Exit_On_Error --
-------------------
procedure Exit_On_Error (Error : Boolean; Reason : String) is
begin
if Error then
Set_Standard_Error;
Write_Line (Reason);
OS_Exit (1);
end if;
end Exit_On_Error;
end Errors; end Errors;
...@@ -35,4 +35,6 @@ package Errors is ...@@ -35,4 +35,6 @@ package Errors is
procedure Display_Bug_Box (E : Ada.Exceptions.Exception_Occurrence); procedure Display_Bug_Box (E : Ada.Exceptions.Exception_Occurrence);
procedure Exit_On_Error (Error : Boolean; Reason : String);
end Errors; end Errors;
...@@ -41,9 +41,42 @@ with Ocarina.Options; use Ocarina.Options; ...@@ -41,9 +41,42 @@ with Ocarina.Options; use Ocarina.Options;
package body Ocarina.Files is package body Ocarina.Files is
use ASCII; use ASCII;
use Namet;
use GNAT.OS_Lib; use GNAT.OS_Lib;
use Errors; use Errors;
use Namet;
----------------------------
-- Add_File_To_Parse_List --
----------------------------
procedure Add_File_To_Parse_List (File_Name : Name_Id) is
File_Name_With_Extension : Name_Id;
-- Full_Name : Name_Id;
Do_Add : Boolean := True;
begin
Get_Name_String (File_Name);
if Name_Buffer (Name_Len - 4 .. Name_Len) /= ".aadl" then
Add_Str_To_Name_Buffer (".aadl");
end if;
File_Name_With_Extension := Name_Find;
-- Full_Name := Search_File (File_Name_With_Extension);
-- Exit_On_Error (Full_Name = No_Name,
-- "Cannot find file "
-- & Get_Name_String (File_Name_With_Extension));
for J in 1 .. Sources.Last loop
if File_Name_With_Extension = Sources.Table (J) then
Do_Add := False;
end if;
end loop;
if Do_Add then
Sources.Append (File_Name_With_Extension);
end if;
end Add_File_To_Parse_List;
----------------- -----------------
-- End_Of_File -- -- End_Of_File --
...@@ -87,7 +120,6 @@ package body Ocarina.Files is ...@@ -87,7 +120,6 @@ package body Ocarina.Files is
Result : Integer; Result : Integer;
Length : Integer; Length : Integer;
begin begin
-- Open the file -- Open the file
Get_Name_String (File_Name); Get_Name_String (File_Name);
...@@ -152,7 +184,6 @@ package body Ocarina.Files is ...@@ -152,7 +184,6 @@ package body Ocarina.Files is
function Search_File (File_Name : Name_Id) return Name_Id is function Search_File (File_Name : Name_Id) return Name_Id is
begin begin
-- Check in the current directory first since -I- is not allowed -- Check in the current directory first since -I- is not allowed
Get_Name_String (File_Name); Get_Name_String (File_Name);
...@@ -166,6 +197,7 @@ package body Ocarina.Files is ...@@ -166,6 +197,7 @@ package body Ocarina.Files is
Get_Name_String (Library_Paths.Table (Path)); Get_Name_String (Library_Paths.Table (Path));
Add_Char_To_Name_Buffer (Directory_Separator); Add_Char_To_Name_Buffer (Directory_Separator);
Get_Name_String_And_Append (File_Name); Get_Name_String_And_Append (File_Name);
if Is_Regular_File (Name_Buffer (1 .. Name_Len)) then if Is_Regular_File (Name_Buffer (1 .. Name_Len)) then
return Name_Find; return Name_Find;
end if; end if;
......
...@@ -35,16 +35,22 @@ ...@@ -35,16 +35,22 @@
-- by the parser for scanning AADL source files. This package is -- by the parser for scanning AADL source files. This package is
-- conformant to the AADL v1.0 issued on 2004-09 -- conformant to the AADL v1.0 issued on 2004-09
with GNAT.Table;
with Types; use Types; with Types; use Types;
with Locations; use Locations; with Locations; use Locations;
package Ocarina.Files is package Ocarina.Files is
package Sources is new GNAT.Table (Name_Id, Nat, 1, 10, 10);
Buffer : Text_Buffer_Ptr; Buffer : Text_Buffer_Ptr;
Buffer_Location : Location; Buffer_Location : Location;
-- The file is loaded in Buffer and Buffer_Location is used to -- The file is loaded in Buffer and Buffer_Location is used to
-- scan it. -- scan it.
procedure Add_File_To_Parse_List (File_Name : Name_Id);
function Search_File (File_Name : Name_Id) return Name_Id; function Search_File (File_Name : Name_Id) return Name_Id;
function Load_File (File_Name : Name_Id) return Location; function Load_File (File_Name : Name_Id) return Location;
......
...@@ -57,6 +57,8 @@ package Ocarina.Options is ...@@ -57,6 +57,8 @@ package Ocarina.Options is
Quiet_Mode : Boolean := False; Quiet_Mode : Boolean := False;
Verbose_Mode : Boolean := False; Verbose_Mode : Boolean := False;
Debug_Mode : Boolean := False; Debug_Mode : Boolean := False;
Use_Scenario_File : Boolean := False;
Auto_Load_AADL_Files : Boolean := False;
procedure Set_Current_Action (Action : Action_Kind); procedure Set_Current_Action (Action : Action_Kind);
function Get_Current_Action return Action_Kind; function Get_Current_Action return Action_Kind;
......
...@@ -35,7 +35,7 @@ with Ocarina.ME_AADL; ...@@ -35,7 +35,7 @@ with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Tree.Nodes; with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Nutils; with Ocarina.ME_AADL.AADL_Tree.Nutils;
with Ocarina.ME_AADL.AADL_Tree.Entities; with Ocarina.ME_AADL.AADL_Tree.Entities;
with Namet; with Namet; use Namet;
with Ocarina.FE_AADL.Lexer; with Ocarina.FE_AADL.Lexer;
with Ocarina.ME_AADL.Tokens; with Ocarina.ME_AADL.Tokens;
with Ocarina.FE_AADL.Parser.Annexes; with Ocarina.FE_AADL.Parser.Annexes;
...@@ -43,6 +43,8 @@ with Ocarina.FE_AADL.Parser.Components; ...@@ -43,6 +43,8 @@ with Ocarina.FE_AADL.Parser.Components;
with Ocarina.FE_AADL.Parser.Properties; with Ocarina.FE_AADL.Parser.Properties;
with Ocarina.FE_AADL.Parser.Identifiers; with Ocarina.FE_AADL.Parser.Identifiers;
with Ocarina.Builder.AADL.Namespaces; with Ocarina.Builder.AADL.Namespaces;
with Ocarina.Options;
with Ocarina.Files;
package body Ocarina.FE_AADL.Parser.Namespaces is package body Ocarina.FE_AADL.Parser.Namespaces is
...@@ -227,7 +229,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is ...@@ -227,7 +229,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is
use Ocarina.ME_AADL.Tokens; use Ocarina.ME_AADL.Tokens;
use Lexer; use Lexer;
use Ocarina.ME_AADL.AADL_Tree.Nodes; use Ocarina.ME_AADL.AADL_Tree.Nodes;
use Namet;
use Ocarina.ME_AADL.AADL_Tree.Nutils; use Ocarina.ME_AADL.AADL_Tree.Nutils;
Loc2, Start_Loc : Location; Loc2, Start_Loc : Location;
...@@ -659,7 +660,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is ...@@ -659,7 +660,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is
-- { package_identifier :: }* package_identifier -- { package_identifier :: }* package_identifier
function P_Package_Name (Container : Node_Id) return Node_Id is function P_Package_Name (Container : Node_Id) return Node_Id is
use Locations; use Locations;
use Ocarina.ME_AADL.Tokens; use Ocarina.ME_AADL.Tokens;
use Lexer; use Lexer;
...@@ -692,7 +692,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is ...@@ -692,7 +692,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is
end if; end if;
return Package_Name; return Package_Name;
end P_Package_Name; end P_Package_Name;
----------------------------------- -----------------------------------
...@@ -726,7 +725,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is ...@@ -726,7 +725,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is
List_Items := New_List (K_List_Id, Loc); List_Items := New_List (K_List_Id, Loc);
loop loop
case Token is case Token is
when T_With => when T_With =>
Item := P_Import_Declaration (Namespace, Loc, Item := P_Import_Declaration (Namespace, Loc,
...@@ -761,7 +759,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is ...@@ -761,7 +759,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is
end if; end if;
return Name_Visibility; return Name_Visibility;
end P_Name_Visibility_Declaration; end P_Name_Visibility_Declaration;
-------------------------- --------------------------
...@@ -851,10 +848,45 @@ package body Ocarina.FE_AADL.Parser.Namespaces is ...@@ -851,10 +848,45 @@ package body Ocarina.FE_AADL.Parser.Namespaces is
Import_Node := Add_New_Import_Declaration (Start_Loc, Namespace, Import_Node := Add_New_Import_Declaration (Start_Loc, Namespace,
Imports_List, Imports_List,
Private_Declarations); Private_Declarations);
end if;
return Import_Node; if Ocarina.Options.Auto_Load_AADL_Files
and then AADL_Version = AADL_V2
and then not Ocarina.Options.Use_Scenario_File
then
declare
I : Node_Id;
begin
I := First_Node (Imports_List);
while Present (I) loop
if Kind (I) = K_Identifier then
Ocarina.Files.Add_File_To_Parse_List (Name (I));
elsif Kind (I) = K_Package_Name then
declare
J : Node_Id;
begin
J := First_Node
(Ocarina.ME_AADL.AADL_Tree.Nodes.Identifiers (I));
if Present (J) then
Get_Name_String (Name (J));
J := Next_Node (J);
while Present (J) loop
Add_Str_To_Name_Buffer
("-" & Get_Name_String (Name (J)));
J := Next_Node (J);
end loop;
Ocarina.Files.Add_File_To_Parse_List (Name_Find);
end if;
end;
end if;
I := Next_Node (I);
end loop;
end;
end if;
return Import_Node;
end if;
end P_Import_Declaration; end P_Import_Declaration;
------------------------- -------------------------
......
...@@ -81,11 +81,14 @@ package body Ocarina.FE_AADL.Parser is ...@@ -81,11 +81,14 @@ package body Ocarina.FE_AADL.Parser is
Initialize_Option_Scan; Initialize_Option_Scan;
loop loop
C := Getopt ("* s f I:"); C := Getopt ("* y s f I:");
case C is case C is
when ASCII.NUL => when ASCII.NUL =>
exit; exit;
when 'y' =>
Auto_Load_Aadl_Files := True;
when 'I' => when 'I' =>
Add_Library_Path (Parameter); Add_Library_Path (Parameter);
...@@ -94,6 +97,7 @@ package body Ocarina.FE_AADL.Parser is ...@@ -94,6 +97,7 @@ package body Ocarina.FE_AADL.Parser is
when others => when others =>
null; null;
end case; end case;
end loop; end loop;
Add_Library_Path (Get_Name_String (Default_Library_Path)); Add_Library_Path (Get_Name_String (Default_Library_Path));
......
...@@ -67,6 +67,7 @@ package body Ocarina.FE_AADL is ...@@ -67,6 +67,7 @@ package body Ocarina.FE_AADL is
procedure Usage is procedure Usage is
begin begin
Write_Line (" -y Automatically load AADL files on demand");
Write_Line (" -f Parse predefined non standard property sets"); Write_Line (" -f Parse predefined non standard property sets");
Write_Line (" -i Instantiate the AADL model"); Write_Line (" -i Instantiate the AADL model");
Write_Line (" -r <name> The name of the instance tree root"); Write_Line (" -r <name> The name of the instance tree root");
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
-- This program is used to drive Ocarina, it is a wrapper to all -- This program is used to drive Ocarina, it is a wrapper to all
-- functions provided by the library. -- functions provided by the library.
with Errors; use Errors;
with Locations; use Locations; with Locations; use Locations;
with Namet; use Namet; with Namet; use Namet;
with Output; use Output; with Output; use Output;
...@@ -49,7 +50,6 @@ with Ada.Text_IO; ...@@ -49,7 +50,6 @@ with Ada.Text_IO;
with GNAT.Command_Line; use GNAT.Command_Line; with GNAT.Command_Line; use GNAT.Command_Line;
with GNAT.Directory_Operations; use GNAT.Directory_Operations; with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with GNAT.OS_Lib; use GNAT.OS_Lib; with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Table;
with Ocarina; use Ocarina; with Ocarina; use Ocarina;
with Ocarina.AADL_Values; use Ocarina.AADL_Values; with Ocarina.AADL_Values; use Ocarina.AADL_Values;
...@@ -77,10 +77,6 @@ with Ocarina.ME_AADL.AADL_Instances.Nodes; ...@@ -77,10 +77,6 @@ with Ocarina.ME_AADL.AADL_Instances.Nodes;
procedure Ocarina_Cmd is procedure Ocarina_Cmd is
procedure Exit_On_Error (Error : Boolean; Reason : String);
package Sources is new GNAT.Table (Name_Id, Nat, 1, 10, 10);
procedure Process_Command_Line procedure Process_Command_Line
(Root_System_Name : out Name_Id; (Root_System_Name : out Name_Id;
Success : out Boolean); Success : out Boolean);
...@@ -405,7 +401,7 @@ procedure Ocarina_Cmd is ...@@ -405,7 +401,7 @@ procedure Ocarina_Cmd is
when Analyze => when Analyze =>
Success := Analyze (Language, AADL_Root); Success := Analyze (Language, AADL_Root);
if not Success then if not Success then
Put_Line ("Cannot analyze AADL specifications"); Write_Line ("Cannot analyze AADL specifications");
else else
Write_Line ("Model analyzed sucessfully"); Write_Line ("Model analyzed sucessfully");
end if; end if;
...@@ -733,19 +729,6 @@ procedure Ocarina_Cmd is ...@@ -733,19 +729,6 @@ procedure Ocarina_Cmd is
N : Node_Id; N : Node_Id;
begin begin
N := First_Node (Source_Files);
while Present (N) loop
declare
File_Name : constant String
:= Image (Value (N), Quoted => False);
begin
Get_Name_String (Current_Scenario_Dirname);
Add_Str_To_Name_Buffer (File_Name);
Sources.Append (Name_Find);
N := Next_Node (N);
end;
end loop;
if not Is_Empty (Needed_PS) then if not Is_Empty (Needed_PS) then
N := First_Node (Needed_Ps); N := First_Node (Needed_Ps);
...@@ -777,22 +760,41 @@ procedure Ocarina_Cmd is ...@@ -777,22 +760,41 @@ procedure Ocarina_Cmd is
Add_Str_To_Name_Buffer (File_Name & ".aadl"); Add_Str_To_Name_Buffer (File_Name & ".aadl");
end; end;
Sources.Append (Name_Find); Ocarina.Files.Add_File_To_Parse_List (Name_Find);
N := Next_Node (N); N := Next_Node (N);
end loop; end loop;
end if; end if;
N := First_Node (Source_Files);
while Present (N) loop
declare
File_Name : constant String
:= Image (Value (N), Quoted => False);
begin
Get_Name_String (Current_Scenario_Dirname);
Add_Str_To_Name_Buffer (File_Name);
Ocarina.Files.Add_File_To_Parse_List (Name_Find);
N := Next_Node (N);
end;
end loop;
end Extract_Source_Files; end Extract_Source_Files;
package OIQ renames Ocarina.Instances.Queries; package OIQ renames Ocarina.Instances.Queries;
F : Types.Int;
begin begin
Current_Scenario_Dirname := No_Name; Current_Scenario_Dirname := No_Name;
for F in Sources.First .. Sources.Last loop AADL_Root := Process_Predefined_Property_Sets (AADL_Root);
F := Sources.First;
loop
Dirname := Get_String_Name Dirname := Get_String_Name
(Dir_Name (Normalize_Pathname (Get_Name_String (Sources.Table (F)))) (Dir_Name (Normalize_Pathname
& Dir_Separator); (Get_Name_String (Sources.Table (F)))));
if Current_Scenario_Dirname = No_Name then if Current_Scenario_Dirname = No_Name then
Current_Scenario_Dirname := Dirname; Current_Scenario_Dirname := Dirname;
...@@ -805,7 +807,6 @@ procedure Ocarina_Cmd is ...@@ -805,7 +807,6 @@ procedure Ocarina_Cmd is
Exit_On_Error Exit_On_Error
(Current_Scenario_Dirname /= Dirname, (Current_Scenario_Dirname /= Dirname,
"Cannot locate scenario files in the directory"); "Cannot locate scenario files in the directory");
File_Name := Search_File (Sources.Table (F)); File_Name := Search_File (Sources.Table (F));
Exit_On_Error Exit_On_Error
((File_Name = No_Name), ((File_Name = No_Name),
...@@ -818,9 +819,10 @@ procedure Ocarina_Cmd is ...@@ -818,9 +819,10 @@ procedure Ocarina_Cmd is
Exit_On_Error Exit_On_Error
(No (AADL_Root), (No (AADL_Root),
"Cannot parse AADL specifications"); "Cannot parse AADL specifications");
end loop;
AADL_Root := Process_Predefined_Property_Sets (AADL_Root); exit when F = Sources.Last; -- XXX Sources.Last may be modified
F := F + 1;
end loop;
-- Analyze the AADL tree -- Analyze the AADL tree
...@@ -934,6 +936,7 @@ procedure Ocarina_Cmd is ...@@ -934,6 +936,7 @@ procedure Ocarina_Cmd is
Ocarina.Configuration.Reset_Modules; Ocarina.Configuration.Reset_Modules;
Ocarina.Reset; Ocarina.Reset;
-- Ocarina.Files.Sources.Init;
Ocarina.Initialize; Ocarina.Initialize;
Language := Get_String_Name ("aadl"); Language := Get_String_Name ("aadl");
...@@ -955,7 +958,7 @@ procedure Ocarina_Cmd is ...@@ -955,7 +958,7 @@ procedure Ocarina_Cmd is
for J in Result'Range loop for J in Result'Range loop
Set_Str_To_Name_Buffer (Result (J).all); Set_Str_To_Name_Buffer (Result (J).all);
Sources.Append (Name_Find); Ocarina.Files.Add_File_To_Parse_List (Name_Find);
end loop; end loop;
-- Avoid memory leaks -- Avoid memory leaks
...@@ -965,19 +968,6 @@ procedure Ocarina_Cmd is ...@@ -965,19 +968,6 @@ procedure Ocarina_Cmd is
end; end;
end Parse_Scenario_Files; end Parse_Scenario_Files;
-------------------
-- Exit_On_Error --
-------------------
procedure Exit_On_Error (Error : Boolean; Reason : String) is
begin
if Error then
Set_Standard_Error;
Write_Line (Reason);
OS_Exit (1);
end if;
end Exit_On_Error;
-------------------------- --------------------------
-- Process_Command_Line -- -- Process_Command_Line --
-------------------------- --------------------------
...@@ -1078,6 +1068,7 @@ procedure Ocarina_Cmd is ...@@ -1078,6 +1068,7 @@ procedure Ocarina_Cmd is
-- an AADL version flag. -- an AADL version flag.
when 'x' => when 'x' =>
Use_Scenario_File := True;
Set_Current_Action (Parse_Scenario_Files_First); Set_Current_Action (Parse_Scenario_Files_First);
when 't' => when 't' =>
...@@ -1116,7 +1107,7 @@ procedure Ocarina_Cmd is ...@@ -1116,7 +1107,7 @@ procedure Ocarina_Cmd is
else else
Set_Str_To_Name_Buffer (S); Set_Str_To_Name_Buffer (S);
Sources.Append (Name_Find); Ocarina.Files.Add_File_To_Parse_List (Name_Find);
end if; end if;
end; end;
end case; end case;
...@@ -1129,6 +1120,7 @@ procedure Ocarina_Cmd is ...@@ -1129,6 +1120,7 @@ procedure Ocarina_Cmd is
and then Get_Current_Action /= Show_Libraries and then Get_Current_Action /= Show_Libraries
and then Get_Current_Action /= Show_Help and then Get_Current_Action /= Show_Help
and then Get_Current_Action /= Shell and then Get_Current_Action /= Shell
and then Get_Current_Action /= Parse_Scenario_Files_First
then then
Set_Current_Action (Show_Usage); Set_Current_Action (Show_Usage);
...