parser_utils.ads 4.37 KB
Newer Older
1
--  *************************** taste aadl parser ***********************  --
Maxime Perrotin's avatar
Maxime Perrotin committed
2
3
4
--  (c) 2017 European Space Agency - maxime.perrotin@esa.int
--  LGPL license, see LICENSE file

5
--  Set of helper functions for the parser
Maxime Perrotin's avatar
Maxime Perrotin committed
6
7
8
9
10
11
12
13
with Ocarina,
     Ocarina.Types,
     Ocarina.Namet,
     Ada.Containers.Indefinite_Ordered_Maps,
     Ada.Containers.Indefinite_Vectors,
     Ocarina.ME_AADL.AADL_Tree.Nodes,
     Ocarina.ME_AADL.AADL_Instances.Nodes,
     Ada.Strings.Unbounded,
Maxime Perrotin's avatar
Maxime Perrotin committed
14
     Option_Type,
15
     GNAT.Strings,
Maxime Perrotin's avatar
Maxime Perrotin committed
16
     Interfaces.C_Streams;
Maxime Perrotin's avatar
Maxime Perrotin committed
17
18
19
20
21
22
23

use Ocarina,
    Ocarina.Types,
    Ocarina.Namet,
    Ocarina.ME_AADL.AADL_Tree.Nodes,
    Ocarina.ME_AADL.AADL_Instances.Nodes,
    Ada.Containers,
Maxime Perrotin's avatar
Maxime Perrotin committed
24
25
    Ada.Strings.Unbounded,
    Interfaces.C_Streams;
Maxime Perrotin's avatar
Maxime Perrotin committed
26

27
package Parser_Utils is
Maxime Perrotin's avatar
Maxime Perrotin committed
28

Maxime Perrotin's avatar
Maxime Perrotin committed
29
30
31
32
   Default_Interface_View  : aliased String := "InterfaceView.aadl";
   Default_Deployment_View : aliased String := "DeploymentView.aadl";
   Default_Data_View       : aliased String := "DataView.aadl";

Maxime Perrotin's avatar
Maxime Perrotin committed
33
34
35
36
37
   package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
   function US (Source : String) return Unbounded_String renames
       To_Unbounded_String;

Maxime Perrotin's avatar
Maxime Perrotin committed
38
   Yellow      : constant String := ASCII.ESC & "[33m";
Maxime Perrotin's avatar
Maxime Perrotin committed
39
   White       : constant String := ASCII.ESC & "[37m";
Maxime Perrotin's avatar
Maxime Perrotin committed
40
41
42
43
44
45
46
47
48
   Red         : constant String := ASCII.ESC & "[31m";
   Bold        : constant String := ASCII.ESC & "[1m";

   function Is_Tty return Boolean is (Isatty (Fileno (Stdout)) /= 0);
   function Red_Bold return String is (if Is_Tty then Red & Bold else "");
   function Yellow_Bold return String is
     (if Is_Tty then Yellow & Bold else "");
   function No_Color return String is
     (if Is_Tty then ASCII.ESC & "[0m" else "");
Maxime Perrotin's avatar
Maxime Perrotin committed
49
   function Underline return String is
Maxime Perrotin's avatar
Maxime Perrotin committed
50
51
     (if Is_Tty then ASCII.ESC & "[4m" else "");
   function White_Bold return String is (if Is_Tty then White & Bold else "");
Maxime Perrotin's avatar
Maxime Perrotin committed
52

Maxime Perrotin's avatar
Maxime Perrotin committed
53
54
   procedure Banner;

55
56
   AADL_Parser_Error : exception;

Maxime Perrotin's avatar
Maxime Perrotin committed
57
58
   function Get_APLC_Binding (E : Node_Id) return List_Id;

59
60
   function Get_Interface_Name (D : Node_Id) return Name_Id;

61
   --  Record to store properties
62
63
64
65
66
67
68
   type User_Property is
      record
         Name  : Unbounded_String;
         Value : Unbounded_String;
      end record;
   package Property_Maps is new Indefinite_Ordered_Maps (String,
                                                         User_Property);
Maxime Perrotin's avatar
Maxime Perrotin committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
   use Property_Maps;
   package String_Vectors is new Indefinite_Vectors (Natural, String);
   function Get_Properties_Map (D : Node_Id) return Property_Maps.Map;

   --  Shortcut to read an identifier from the parser, in lowercase
   function ATN_Lower (N : Node_Id) return String is
       (Get_Name_String (ATN.Name (ATN.Identifier (N))));

   --  Shortcut to read an identifier from the parser, with original case
   function ATN_Case (N : Node_Id) return String is
       (Get_Name_String (ATN.Display_Name (ATN.Identifier (N))));

   --  Shortcut to read an identifier from the parser, in lowercase
   function AIN_Lower (N : Node_Id) return String is
       (Get_Name_String (AIN.Name (AIN.Identifier (N))));

   --  Shortcut to read an identifier from the parser, with original case
   function AIN_Case (N : Node_Id) return String is
       (Get_Name_String (AIN.Display_Name (AIN.Identifier (N))));

   package Option_UString is new Option_Type (Unbounded_String);
   use Option_UString;
   subtype Optional_Unbounded_String is Option_UString.Option;
   package Option_ULL is new Option_Type (Unsigned_Long_Long);
   use Option_ULL;
   subtype Optional_Long_Long is Option_ULL.Option;

96
97
98
99
100
101
102
103
   procedure Initialize_Ocarina;

   type Taste_Configuration is
      record
         Interface_View   : aliased GNAT.Strings.String_Access;
         Deployment_View  : aliased GNAT.Strings.String_Access;
         Data_View        : aliased GNAT.Strings.String_Access;
         Output_Dir       : aliased GNAT.Strings.String_Access;
Maxime Perrotin's avatar
Maxime Perrotin committed
104
105
106
107
108
109
         Skeletons        : aliased Boolean := False;
         Glue             : aliased Boolean := False;
         Use_POHIC        : aliased Boolean := False;
         Timer_Resolution : aliased Integer := 100;
         Debug_Flag       : aliased Boolean := False;
         Version          : aliased Boolean := False;
Maxime Perrotin's avatar
Maxime Perrotin committed
110
         Other_Files      : String_Vectors.Vector;
111
112
      end record;

Maxime Perrotin's avatar
Maxime Perrotin committed
113
114
115
116
117
   Current_Config : Taste_Configuration;

   procedure Parse_Command_Line (Result : out Taste_Configuration);

   procedure Dump_Configuration (Config : Taste_Configuration);
118

119
end Parser_Utils;