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

* 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
OS_Exit (3);
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;
......@@ -35,4 +35,6 @@ package Errors is
procedure Display_Bug_Box (E : Ada.Exceptions.Exception_Occurrence);
procedure Exit_On_Error (Error : Boolean; Reason : String);
end Errors;
......@@ -41,9 +41,42 @@ with Ocarina.Options; use Ocarina.Options;
package body Ocarina.Files is
use ASCII;
use Namet;
use GNAT.OS_Lib;
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 --
......@@ -87,7 +120,6 @@ package body Ocarina.Files is
Result : Integer;
Length : Integer;
begin
-- Open the file
Get_Name_String (File_Name);
......@@ -152,7 +184,6 @@ package body Ocarina.Files is
function Search_File (File_Name : Name_Id) return Name_Id is
begin
-- Check in the current directory first since -I- is not allowed
Get_Name_String (File_Name);
......@@ -166,6 +197,7 @@ package body Ocarina.Files is
Get_Name_String (Library_Paths.Table (Path));
Add_Char_To_Name_Buffer (Directory_Separator);
Get_Name_String_And_Append (File_Name);
if Is_Regular_File (Name_Buffer (1 .. Name_Len)) then
return Name_Find;
end if;
......
......@@ -35,16 +35,22 @@
-- by the parser for scanning AADL source files. This package is
-- conformant to the AADL v1.0 issued on 2004-09
with GNAT.Table;
with Types; use Types;
with Locations; use Locations;
package Ocarina.Files is
package Sources is new GNAT.Table (Name_Id, Nat, 1, 10, 10);
Buffer : Text_Buffer_Ptr;
Buffer_Location : Location;
-- The file is loaded in Buffer and Buffer_Location is used to
-- scan it.
procedure Add_File_To_Parse_List (File_Name : Name_Id);
function Search_File (File_Name : Name_Id) return Name_Id;
function Load_File (File_Name : Name_Id) return Location;
......
......@@ -57,6 +57,8 @@ package Ocarina.Options is
Quiet_Mode : Boolean := False;
Verbose_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);
function Get_Current_Action return Action_Kind;
......
......@@ -35,7 +35,7 @@ with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Nutils;
with Ocarina.ME_AADL.AADL_Tree.Entities;
with Namet;
with Namet; use Namet;
with Ocarina.FE_AADL.Lexer;
with Ocarina.ME_AADL.Tokens;
with Ocarina.FE_AADL.Parser.Annexes;
......@@ -43,6 +43,8 @@ with Ocarina.FE_AADL.Parser.Components;
with Ocarina.FE_AADL.Parser.Properties;
with Ocarina.FE_AADL.Parser.Identifiers;
with Ocarina.Builder.AADL.Namespaces;
with Ocarina.Options;
with Ocarina.Files;
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 Lexer;
use Ocarina.ME_AADL.AADL_Tree.Nodes;
use Namet;
use Ocarina.ME_AADL.AADL_Tree.Nutils;
Loc2, Start_Loc : Location;
......@@ -659,7 +660,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is
-- { package_identifier :: }* package_identifier
function P_Package_Name (Container : Node_Id) return Node_Id is
use Locations;
use Ocarina.ME_AADL.Tokens;
use Lexer;
......@@ -692,7 +692,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is
end if;
return Package_Name;
end P_Package_Name;
-----------------------------------
......@@ -726,7 +725,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is
List_Items := New_List (K_List_Id, Loc);
loop
case Token is
when T_With =>
Item := P_Import_Declaration (Namespace, Loc,
......@@ -761,7 +759,6 @@ package body Ocarina.FE_AADL.Parser.Namespaces is
end if;
return Name_Visibility;
end P_Name_Visibility_Declaration;
--------------------------
......@@ -851,10 +848,45 @@ package body Ocarina.FE_AADL.Parser.Namespaces is
Import_Node := Add_New_Import_Declaration (Start_Loc, Namespace,
Imports_List,
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;
-------------------------
......
......@@ -81,11 +81,14 @@ package body Ocarina.FE_AADL.Parser is
Initialize_Option_Scan;
loop
C := Getopt ("* s f I:");
C := Getopt ("* y s f I:");
case C is
when ASCII.NUL =>
exit;
when 'y' =>
Auto_Load_Aadl_Files := True;
when 'I' =>
Add_Library_Path (Parameter);
......@@ -94,6 +97,7 @@ package body Ocarina.FE_AADL.Parser is
when others =>
null;
end case;
end loop;
Add_Library_Path (Get_Name_String (Default_Library_Path));
......
......@@ -67,6 +67,7 @@ package body Ocarina.FE_AADL is
procedure Usage is
begin
Write_Line (" -y Automatically load AADL files on demand");
Write_Line (" -f Parse predefined non standard property sets");
Write_Line (" -i Instantiate the AADL model");
Write_Line (" -r <name> The name of the instance tree root");
......
......@@ -34,6 +34,7 @@
-- This program is used to drive Ocarina, it is a wrapper to all
-- functions provided by the library.
with Errors; use Errors;
with Locations; use Locations;
with Namet; use Namet;
with Output; use Output;
......@@ -49,7 +50,6 @@ with Ada.Text_IO;
with GNAT.Command_Line; use GNAT.Command_Line;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Table;
with Ocarina; use Ocarina;
with Ocarina.AADL_Values; use Ocarina.AADL_Values;
......@@ -77,10 +77,6 @@ with Ocarina.ME_AADL.AADL_Instances.Nodes;
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
(Root_System_Name : out Name_Id;
Success : out Boolean);
......@@ -405,7 +401,7 @@ procedure Ocarina_Cmd is
when Analyze =>
Success := Analyze (Language, AADL_Root);
if not Success then
Put_Line ("Cannot analyze AADL specifications");
Write_Line ("Cannot analyze AADL specifications");
else
Write_Line ("Model analyzed sucessfully");
end if;
......@@ -733,19 +729,6 @@ procedure Ocarina_Cmd is
N : Node_Id;
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
N := First_Node (Needed_Ps);
......@@ -777,22 +760,41 @@ procedure Ocarina_Cmd is
Add_Str_To_Name_Buffer (File_Name & ".aadl");
end;
Sources.Append (Name_Find);
Ocarina.Files.Add_File_To_Parse_List (Name_Find);
N := Next_Node (N);
end loop;
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;
package OIQ renames Ocarina.Instances.Queries;
F : Types.Int;
begin
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
(Dir_Name (Normalize_Pathname (Get_Name_String (Sources.Table (F))))
& Dir_Separator);
(Dir_Name (Normalize_Pathname
(Get_Name_String (Sources.Table (F)))));
if Current_Scenario_Dirname = No_Name then
Current_Scenario_Dirname := Dirname;
......@@ -805,7 +807,6 @@ procedure Ocarina_Cmd is
Exit_On_Error
(Current_Scenario_Dirname /= Dirname,
"Cannot locate scenario files in the directory");
File_Name := Search_File (Sources.Table (F));
Exit_On_Error
((File_Name = No_Name),
......@@ -818,9 +819,10 @@ procedure Ocarina_Cmd is
Exit_On_Error
(No (AADL_Root),
"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
......@@ -934,6 +936,7 @@ procedure Ocarina_Cmd is
Ocarina.Configuration.Reset_Modules;
Ocarina.Reset;
-- Ocarina.Files.Sources.Init;
Ocarina.Initialize;
Language := Get_String_Name ("aadl");
......@@ -955,7 +958,7 @@ procedure Ocarina_Cmd is
for J in Result'Range loop
Set_Str_To_Name_Buffer (Result (J).all);
Sources.Append (Name_Find);
Ocarina.Files.Add_File_To_Parse_List (Name_Find);
end loop;
-- Avoid memory leaks
......@@ -965,19 +968,6 @@ procedure Ocarina_Cmd is
end;
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 --
--------------------------
......@@ -1078,6 +1068,7 @@ procedure Ocarina_Cmd is
-- an AADL version flag.
when 'x' =>
Use_Scenario_File := True;
Set_Current_Action (Parse_Scenario_Files_First);
when 't' =>
......@@ -1116,7 +1107,7 @@ procedure Ocarina_Cmd is
else
Set_Str_To_Name_Buffer (S);
Sources.Append (Name_Find);
Ocarina.Files.Add_File_To_Parse_List (Name_Find);
end if;
end;
end case;
......@@ -1129,6 +1120,7 @@ procedure Ocarina_Cmd is
and then Get_Current_Action /= Show_Libraries
and then Get_Current_Action /= Show_Help
and then Get_Current_Action /= Shell
and then Get_Current_Action /= Parse_Scenario_Files_First
then
Set_Current_Action (Show_Usage);
......@@ -1141,7 +1133,7 @@ procedure Ocarina_Cmd is
exception
when Invalid_Options =>
Write_Line (Base_Name (Command_Name)
& ": invalid combination of options");
& ": invalid combination of options");
Write_Eol;
OS_Exit (1);
......@@ -1186,14 +1178,14 @@ procedure Ocarina_Cmd is
Write_Eol;
Write_Line (" Scenario file options:");
Write_Line (" -b build the generated application code");
Write_Line (" -z clean the generated application code");
Write_Line (" -ec execute the generated application code and");
Write_Line (" -b Generate and build code from the AADL model");
Write_Line (" -z Clean code generated from the AADL model");
Write_Line (" -ec Execute the generated application code and");
Write_Line (" retrieve coverage information");
Write_Line (" -er execute the generated application code and");
Write_Line (" -er Execute the generated application code and");
Write_Line (" verify that there is no regression");
Write_Line (" -p only parse and instantiate the application model");
Write_Line (" -c only perform schedulability analysis");
Write_Line (" -p Only parse and instantiate the application model");
Write_Line (" -c Only perform schedulability analysis");
Write_Eol;
Write_Line (" Advanced user options:");
......@@ -1282,7 +1274,6 @@ begin
Parse_Scenario_Files;
Reset_Current_Action;
Set_Current_Action (After_Scenario_Action);
when others =>
null;
end case;
......@@ -1291,20 +1282,26 @@ begin
-- Parse the AADL files
AADL_Root := No_Node;
for F in Sources.First .. Sources.Last loop
File_Name := Search_File (Sources.Table (F));
Exit_On_Error
((File_Name = No_Name),
"Cannot find file " & Get_Name_String (Sources.Table (F)));
Buffer := Load_File (File_Name);
Exit_On_Error
((File_Name = No_Name),
"Cannot read file " & Get_Name_String (Sources.Table (F)));
AADL_Root := Parse (Language, AADL_Root, Buffer);
Exit_On_Error
(No (AADL_Root),
"Cannot parse AADL specifications");
end loop;
declare
F : Types.Int := Sources.First;
begin
loop
File_Name := Search_File (Sources.Table (F));
Exit_On_Error
((File_Name = No_Name),
"Cannot find file " & Get_Name_String (Sources.Table (F)));
Buffer := Load_File (File_Name);
Exit_On_Error
((File_Name = No_Name),
"Cannot read file " & Get_Name_String (Sources.Table (F)));
AADL_Root := Parse (Language, AADL_Root, Buffer);
Exit_On_Error
(No (AADL_Root),
"Cannot parse AADL specifications");
exit when F = Sources.Last;
F := F + 1;
end loop;
end;
Success := Analyze (Language, AADL_Root);
Exit_On_Error (not Success, "Cannot analyze AADL specifications");
......
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