parser_utils.ads 8.27 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
14
15
16
17
18
19
20
21
22
23
24
25
with Ocarina,
     Ocarina.Types,
     Ocarina.Namet,
     Ocarina.Backends.Properties,
     Ada.Containers.Indefinite_Ordered_Maps,
     Ada.Containers.Indefinite_Vectors,
     Ocarina.ME_AADL.AADL_Tree.Nodes,
     Ocarina.ME_AADL.AADL_Instances.Nodes,
     Ada.Strings.Unbounded,
     Option_Type;

use Ocarina,
    Ocarina.Types,
    Ocarina.Namet,
    Ocarina.Backends.Properties,
    Ocarina.ME_AADL.AADL_Tree.Nodes,
    Ocarina.ME_AADL.AADL_Instances.Nodes,
    Ada.Containers,
    Ada.Strings.Unbounded;

26
package Parser_Utils is
Maxime Perrotin's avatar
Maxime Perrotin committed
27
28
29
30
31
32
33
34
35
36

   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;

   procedure Banner;

   procedure Usage;

37
   AADL_Parser_Error : exception;
Maxime Perrotin's avatar
Maxime Perrotin committed
38
39
40
   No_RCM_Error      : exception;
   Interface_Error   : exception;
   Function_Error    : exception;
41

Maxime Perrotin's avatar
Maxime Perrotin committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
   procedure Exit_On_Error (Error : Boolean; Reason : String);

   type Synchronism is (Sync, Async);

   type Supported_RCM_Operation_Kind is (Unprotected_Operation,
                                         Protected_Operation,
                                         Cyclic_Operation,
                                         Sporadic_Operation,
                                         Any_Operation);

   function Get_RCM_Operation_Kind (E : Node_Id)
     return Supported_RCM_Operation_Kind;

   function Get_RCM_Operation (E : Node_Id) return Node_Id;

   function Get_RCM_Period (D : Node_Id) return Unsigned_Long_Long;

   function Get_APLC_Binding (E : Node_Id) return List_Id;

   type Supported_ASN1_Encoding is (Default, Native, UPER, ACN);

   function Get_ASN1_Encoding (E : Node_Id) return Supported_ASN1_Encoding;

   type Supported_ASN1_Basic_Type is (ASN1_Sequence,
                                      ASN1_SequenceOf,
                                      ASN1_Enumerated,
                                      ASN1_Set,
                                      ASN1_SetOf,
                                      ASN1_Integer,
                                      ASN1_Boolean,
                                      ASN1_Real,
                                      ASN1_OctetString,
                                      ASN1_Choice,
                                      ASN1_String,
                                      ASN1_Unknown);

78
79
80
81
82
83
84
85
   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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
   use Property_Maps;
   package String_Vectors is new Indefinite_Vectors (Natural, String);

   function Get_ASN1_Basic_Type (E : Node_Id) return Supported_ASN1_Basic_Type;

   function Get_Ada_Package_Name (D : Node_Id) return Name_Id;

   function Get_Ellidiss_Tool_Version (D : Node_Id) return Name_Id;

   function Get_Interface_Name (D : Node_Id) return Name_Id;

   function Get_ASN1_Module_Name (D : Node_Id) return 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))));

   --  Types needed to build the AST of the TASTE Interface View in Ada
   type Parameter_Direction is (param_in, param_out);

   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;

   type ASN1_Parameter is
128
129
130
131
132
133
134
135
136
      record
         Name            : Unbounded_String;
         Sort            : Unbounded_String;
         ASN1_Module     : Unbounded_String;
         ASN1_Basic_Type : Supported_ASN1_Basic_Type;
         ASN1_File_Name  : Unbounded_String;
         Encoding        : Supported_ASN1_Encoding;
         Direction       : Parameter_Direction;
      end record;
Maxime Perrotin's avatar
Maxime Perrotin committed
137
138
139

   package Parameters is new Indefinite_Vectors (Natural, ASN1_Parameter);

140
141
142
143
144
145
146
147
148
149
   --  Remote entities reference to the other ends of an interface, when it
   --  is connected. There can be several, but connections are optional.
   type Remote_Entity is
      record
         Function_Name  : Unbounded_String;
         Interface_Name : Unbounded_String;
      end record;

   package Remote_Entities is new Indefinite_Vectors (Natural, Remote_Entity);

Maxime Perrotin's avatar
Maxime Perrotin committed
150
   type Taste_Interface is
151
152
153
      record
         Name              : Unbounded_String;
         Parent_Function   : Unbounded_String;
154
         Remote_Interfaces : Remote_Entities.Vector;
155
156
157
158
159
160
161
         Params            : Parameters.Vector;
         RCM               : Supported_RCM_Operation_Kind;
         Period_Or_MIAT    : Unsigned_Long_Long;
         WCET_ms           : Optional_Long_Long := Nothing;
         Queue_Size        : Optional_Long_Long := Nothing;
         User_Properties   : Property_Maps.Map;
      end record;
Maxime Perrotin's avatar
Maxime Perrotin committed
162

163
164
   package Interfaces_Maps is new Indefinite_Ordered_Maps (String,
                                                           Taste_Interface);
Maxime Perrotin's avatar
Maxime Perrotin committed
165
166

   type Context_Parameter is
167
168
169
170
171
172
173
      record
         Name           : Unbounded_String;
         Sort           : Unbounded_String;
         Default_Value  : Unbounded_String;
         ASN1_Module    : Unbounded_String;
         ASN1_File_Name : Optional_Unbounded_String := Nothing;
      end record;
Maxime Perrotin's avatar
Maxime Perrotin committed
174
175
176
177

   package Ctxt_Params is new Indefinite_Vectors (Natural, Context_Parameter);

   type Taste_Terminal_Function is
178
179
      record
         Name            : Unbounded_String;
180
         Context         : Unbounded_String          := Null_Unbounded_String;
181
         Full_Prefix     : Optional_Unbounded_String := Nothing;
182
183
184
185
186
         Language        : Supported_Source_Language;
         Zip_File        : Optional_Unbounded_String := Nothing;
         Context_Params  : Ctxt_Params.Vector;
         User_Properties : Property_Maps.Map;
         Timers          : String_Vectors.Vector;
187
188
         Provided        : Interfaces_Maps.Map;
         Required        : Interfaces_Maps.Map;
189
      end record;
Maxime Perrotin's avatar
Maxime Perrotin committed
190

191
192
193
194
--   package Functions is new Indefinite_Vectors (Natural,
--                                                Taste_Terminal_Function);
   package Function_Maps is new Indefinite_Ordered_Maps (String,
                                                      Taste_Terminal_Function);
Maxime Perrotin's avatar
Maxime Perrotin committed
195
196

   type Connection is
197
198
199
200
201
202
      record
         Caller  : Unbounded_String;
         Callee  : Unbounded_String;
         RI_Name : Unbounded_String;
         PI_Name : Unbounded_String;
      end record;
203
204
205

   package Option_Connection is new Option_Type (Connection);
   subtype Optional_Connection is Option_Connection.Option;
Maxime Perrotin's avatar
Maxime Perrotin committed
206
207
208

   package Channels is new Indefinite_Vectors (Natural, Connection);
   package Connection_Maps is new Indefinite_Ordered_Maps (String,
209
                                                          Channels.Vector,
Maxime Perrotin's avatar
Maxime Perrotin committed
210
211
                                                          "=" => Channels."=");

212
   type Complete_Interface_View is tagged
213
      record
214
         Flat_Functions  : Function_Maps.Map;
215
      end record;
Maxime Perrotin's avatar
Maxime Perrotin committed
216
217
218
219

   --  Function to build up the Ada AST by transforming the one from Ocarina
   function AADL_to_Ada_IV (System : Node_Id) return Complete_Interface_View;

220
221
222
223
224
225
   --  Model transformation API: Rename a function
   procedure Rename_Function (IV       : in out Complete_Interface_View;
                              From, To : String);

   procedure Debug_Dump_IV (IV : Complete_Interface_View);

226
end Parser_Utils;