ocarina-be_aadl_ba-expressions.adb 16.6 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--       O C A R I N A . B E _ A A D L _ B A . E X P R E S S I O N S        --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--       Copyright (C) 2009 Telecom ParisTech, 2010-2016 ESA & ISAE.        --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. Ocarina is distributed in the hope that it will be useful, but     --
-- WITHOUT ANY WARRANTY; without even the implied warranty of               --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27
28
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29
30
31
--                                                                          --
------------------------------------------------------------------------------

32
with Ocarina.Output;
33
34
35
36
37
38
39
40
41
42
43
44

with Ocarina.AADL_Values;

with Ocarina.ME_AADL_BA;
with Ocarina.ME_AADL_BA.BA_Tree.Nodes;
with Ocarina.ME_AADL_BA.BA_Tree.Nutils;

with Ocarina.BE_AADL_BA.Identifiers;
with Ocarina.BE_AADL_BA.Actions;

package body Ocarina.BE_AADL_BA.Expressions is

45
   use Ocarina.Output;
46
47
48
49
50
51
52
53
54
   use Ocarina.AADL_Values;
   use Ocarina.ME_AADL_BA;
   use Ocarina.ME_AADL_BA.BA_Tree.Nutils;
   use Ocarina.ME_AADL_BA.BA_Tree.Nodes;
   use Ocarina.BE_AADL_BA.Identifiers;
   use Ocarina.BE_AADL_BA.Actions;

   package BAN renames Ocarina.ME_AADL_BA.BA_Tree.Nodes;

55
   procedure Print_Relation          (Node : Node_Id);
56
   procedure Print_Simple_Expression (Node : Node_Id);
57
58
59
   procedure Print_Term              (Node : Node_Id);
   procedure Print_Factor            (Node : Node_Id);
   procedure Print_Value             (Node : Node_Id);
60

61
62
63
   --------------------------
   -- Print_Value_Variable --
   --------------------------
64

65
66
   procedure Print_Value_Variable (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Value_Variable);
67
68
69
70

      Ident : constant Node_Id := BAN.Identifier (Node);
   begin
      case Kind (Ident) is
71
         when K_Name   => Print_Name (Ident);
72
73
74
75

         when K_Data_Component_Reference =>
            Print_Data_Component_Reference (Ident);

76
         when others => Write_Line (Bug_Str);
77
78
79
80
81
82
83
84
85
86
87
88
      end case;

      if Is_Interrogative (Node) then
         Print_Token (T_Interrogative);
      end if;

      if Is_Count (Node) then
         Print_Token (T_Tick);
         Print_Token (T_Count);
      elsif Is_Fresh (Node) then
         Print_Token (T_Tick);
         Print_Token (T_Fresh);
89
90
91
      elsif Is_Updated (Node) then
         Print_Token (T_Tick);
         Print_Token (T_Updated);
92
      end if;
93
   end Print_Value_Variable;
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

   ----------------------------
   -- Print_Value_Expression --
   ----------------------------

   procedure Print_Value_Expression (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Value_Expression);
      pragma Assert (not Is_Empty (Relations (Node)));

      List_Node : Node_Id;
   begin
      List_Node := First_Node (Relations (Node));
      Print_Relation (List_Node);

      List_Node := Next_Node (List_Node);
      while Present (List_Node) loop
         Write_Space;

         case Kind (List_Node) is
113
114
115
            when K_Relation => Print_Relation (List_Node);
            when K_Operator => Print_Operator (List_Node);
            when others     => Write_Line     (Bug_Str);
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
         end case;

         List_Node := Next_Node (List_Node);
      end loop;
   end Print_Value_Expression;

   --------------------
   -- Print_Relation --
   --------------------

   procedure Print_Relation (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Relation);

      List_Node : Node_Id;
   begin
131
132
133
134
135
136
137
      if not Is_Empty (Simple_Exprs (Node)) then
         --  if Boolean_Value (Node) then
         --   Print_Token (T_True);
         --  else
         --   Print_Token (T_False);
         --  end if;
      --  else
138
139
140
141
142
143
144
145
         List_Node := First_Node (Simple_Exprs (Node));
         Print_Simple_Expression (List_Node);

         List_Node := Next_Node (List_Node);
         while Present (List_Node) loop
            Write_Space;

            case Kind (List_Node) is
146
147
148
               when K_Simple_Expression => Print_Simple_Expression (List_Node);
               when K_Operator          => Print_Operator          (List_Node);
               when others              => Write_Line              (Bug_Str);
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
            end case;

            List_Node := Next_Node (List_Node);
         end loop;
      end if;
   end Print_Relation;

   -----------------------------
   -- Print_Simple_Expression --
   -----------------------------

   procedure Print_Simple_Expression (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Simple_Expression);
      pragma Assert (not Is_Empty (Term_And_Operator (Node)));

164
      No_First  : Boolean  := False;
165
166
167
168
169
170
171
172
173
174
175
      List_Node : Node_Id;
   begin
      List_Node := First_Node (Term_And_Operator (Node));

      while Present (List_Node) loop
         if No_First then
            Write_Space;
         end if;
         No_First := True;

         case Kind (List_Node) is
176
177
178
            when K_Operator => Print_Operator (List_Node);
            when K_Term     => Print_Term     (List_Node);
            when others     => Write_Line     (Bug_Str);
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
         end case;

         List_Node := Next_Node (List_Node);
      end loop;
   end Print_Simple_Expression;

   ----------------
   -- Print_Term --
   ----------------

   procedure Print_Term (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Term);
      pragma Assert (not Is_Empty (Factors (Node)));

      No_First  : Boolean := False;
      List_Node : Node_Id;
   begin
      List_Node := First_Node (Factors (Node));

      while Present (List_Node) loop
         if No_First then
            Write_Space;
         end if;
         No_First := True;

         case Kind (List_Node) is
205
206
207
            when K_Operator => Print_Operator (List_Node);
            when K_Factor   => Print_Factor   (List_Node);
            when others     => Write_Line     (Bug_Str);
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
         end case;

         List_Node := Next_Node (List_Node);
      end loop;
   end Print_Term;

   ------------------
   -- Print_Factor --
   ------------------

   procedure Print_Factor (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Factor);

   begin
      if Is_Abs (Node) then
         Print_Token (T_Abs);
         Write_Space;
      elsif Is_Not (Node) then
         Print_Token (T_Not);
         Write_Space;
      end if;

230
      Print_Value (Lower_Value (Node));
231

232
      if Present (Upper_Value (Node)) then
233
234
235
         Write_Space;
         Print_Token (T_Exponent);
         Write_Space;
236
         Print_Value (Upper_Value (Node));
237
238
239
      end if;
   end Print_Factor;

240
241
242
243
244
245
246
247
248
249
250
251
   -----------------
   -- Print_Value --
   -----------------

   procedure Print_Value (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Value_Variable
                       or else Kind (Node) = K_Value_Expression
                       or else Kind (Node) = K_Literal
                       or else Kind (Node) = K_Boolean_Literal
                       or else Kind (Node) = K_Property_Constant
                       or else Kind (Node) = K_Property_Reference
                       or else Kind (Node) = K_Identifier);
252
253
   begin
      case Kind (Node) is
254
255
256
257
258
259
         when K_Value_Variable    => Print_Value_Variable    (Node);
         when K_Literal           => Print_Literal           (Node);
         when K_Boolean_Literal   => Print_Boolean_Literal   (Node);
         when K_Property_Constant => Print_Property_Constant (Node);
         when K_Property_Reference => Print_Property_Reference (Node);
         when K_Value_Expression  =>
260
261
262
            Print_Token (T_Left_Parenthesis);
            Print_Value_Expression (Node);
            Print_Token (T_Right_Parenthesis);
263
264
         when K_Identifier        => Print_Identifier        (Node);
         when others              => Write_Line              (Bug_Str);
265
      end case;
266
   end Print_Value;
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

   -----------------------------
   -- Print_Property_Constant --
   -----------------------------

   procedure Print_Property_Constant (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Property_Constant);

   begin
      if Present (Property_Set (Node)) then
         Print_Identifier (Property_Set (Node));
         Print_Token (T_Colon_Colon);
      end if;

      Print_Identifier (BAN.Identifier (Node));
   end Print_Property_Constant;

284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
   -----------------------------
   -- Print_Property_Reference --
   -----------------------------

   procedure Print_Property_Reference (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Property_Reference);

   begin
      if Present (Property_Set_Idt (Node)) then
         Print_Token (T_Number_Sign);
         Print_Identifier (Property_Set_Idt (Node));
         Print_Token (T_Colon_Colon);
      end if;
      if Present (Entity (Node)) then
         Print_Component_Element_Ref (Entity (Node));
         Print_Token (T_Number_Sign);
      end if;
      Print_Property_Name (Property_Name (Node));
   end Print_Property_Reference;

   -------------------------
   -- Print_Property_Name --
   -------------------------

   procedure Print_Property_Name (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Property_Name);

      List_Node : Node_Id;
   begin
      Print_Identifier (Property_Idt (Node));
      if not Is_Empty (Property_Field (Node)) then
         List_Node := First_Node (Property_Field (Node));
         Print_Property_Field (List_Node);

         List_Node := Next_Node (List_Node);
         while Present (List_Node) loop
            Write_Space;
            Print_Property_Field (List_Node);

            List_Node := Next_Node (List_Node);
         end loop;
      end if;
   end Print_Property_Name;

   --------------------------
   -- Print_Property_Field --
   --------------------------

   procedure Print_Property_Field (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Property_Field);

   begin
      if Is_Upper_Bound (Node) then
         Print_Token (T_Dot);
         Print_Token (T_Upper_Bound);
         Write_Space;
      elsif Is_Lower_Bound (Node) then
         Print_Token (T_Dot);
         Print_Token (T_Lower_Bound);
         Write_Space;
      end if;

      if Present (Entity (Node)) then
         case Kind (Entity (Node)) is
            when K_Identifier =>
               Print_Token (T_Dot);
               Print_Identifier (Entity (Node));
            when K_Integer_Value  =>
               Print_Token (T_Left_Square_Bracket);
               Print_Integer_Value (Entity (Node));
               Print_Token (T_Right_Square_Bracket);
            when others           => Write_Line (Bug_Str);
         end case;
      end if;
   end Print_Property_Field;

   ---------------------------------
   -- Print_Component_Element_Ref --
   ---------------------------------

   procedure Print_Component_Element_Ref (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Component_Element_Reference);

   begin
      if Is_Self (Node) then
         Print_Token (T_Self);
         Write_Space;
      end if;

      if Present (Ident (Node)) then
         Write_Space;
         Print_Identifier (Ident (Node));
      end if;
   end Print_Component_Element_Ref;

379
380
381
382
383
384
385
386
387
388
389
   --------------------
   -- Print_Operator --
   --------------------

   procedure Print_Operator (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Operator);

   begin
      case Operator_Kind'Val (Operator_Category (Node)) is

         --  logical operator
390
391
392
393
394
         when OK_And              => Print_Token (T_And);
         when OK_Or               => Print_Token (T_Or);
         when OK_Xor              => Print_Token (T_Xor);
         when OK_Or_Else          => Print_Tokens ((T_Or, T_Else));
         when OK_And_Then         => Print_Tokens ((T_And, T_Then));
395
396

         --  relational_operator
397
398
399
400
401
402
         when OK_Equal            => Print_Token (T_Equals_Sign);
         when OK_Non_Equal        => Print_Token (T_Non_Equal);
         when OK_Less_Than        => Print_Token (T_Less_Than_Sign);
         when OK_Less_Or_Equal    => Print_Token (T_Less_Or_Equal);
         when OK_Greater_Than     => Print_Token (T_Greater_Than_Sign);
         when OK_Greater_Or_Equal => Print_Token (T_Greater_Or_Equal);
403
404
405

         --  unary_adding_opetor
         --  binary_adding_operator
406
407
         when OK_Plus             => Print_Token (T_Plus);
         when OK_Minus            => Print_Token (T_Minus);
408
409

         --  multiplying operator
410
411
412
413
         when OK_Multiply         => Print_Token (T_Multiply);
         when OK_Divide           => Print_Token (T_Divide);
         when OK_Mod              => Print_Token (T_Mod);
         when OK_Rem              => Print_Token (T_Rem);
414
415

         --  highest precedence operator
416
417
418
419
420
         when OK_Exponent         => Print_Token (T_Exponent);
         when OK_Abs              => Print_Token (T_Abs);
         when OK_Not              => Print_Token (T_Not);

         when others              => Write_Line  (Bug_Str);
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
      end case;
   end Print_Operator;

   -------------------------
   -- Print_Integer_Range --
   -------------------------

   procedure Print_Integer_Range (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Integer_Range);
      pragma Assert (Kind (Lower_Int_Val (Node)) = K_Integer_Value);
      pragma Assert (Kind (Upper_Int_Val (Node)) = K_Integer_Value);

   begin
      Write_Space;
      Print_Integer_Value (Lower_Int_Val (Node));
      Write_Space;
      Print_Token (T_Interval);
      Write_Space;
      Print_Integer_Value (Upper_Int_Val (Node));
   end Print_Integer_Range;

   -------------------------
   -- Print_Integer_Value --
   -------------------------

   procedure Print_Integer_Value (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Integer_Value);
448
449
450
      pragma Assert (Kind (Entity (Node)) = K_Value_Variable
                       or else Kind (Entity (Node)) = K_Literal
                       or else Kind (Entity (Node)) = K_Property_Constant);
451
452
453
454

      Entity_Node : constant Node_Id := Entity (Node);
   begin
      case Kind (Entity_Node) is
455
456
457
458
         when K_Value_Variable    => Print_Value_Variable    (Entity_Node);
         when K_Literal           => Print_Literal           (Entity_Node);
         when K_Property_Constant => Print_Property_Constant (Entity_Node);
         when others              => Write_Line              (Bug_Str);
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
      end case;
   end Print_Integer_Value;

   -------------------------
   -- Print_Behavior_Time --
   -------------------------

   procedure Print_Behavior_Time (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Behavior_Time);

   begin
      Write_Space;
      Print_Integer_Value (Integer_Value (Node));
      Write_Space;
      Print_Identifier (Unit_Identifier (Node));
   end Print_Behavior_Time;

   -------------------
   -- Print_Literal --
   -------------------

   procedure Print_Literal (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Literal);

   begin
      Write_Str (Ocarina.AADL_Values.Image (Value (Node)));
   end Print_Literal;

487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
   ---------------------------
   -- Print_Boolean_Literal --
   ---------------------------

   procedure Print_Boolean_Literal (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Boolean_Literal);

   begin
      if Is_True (Node) then
         Print_Token (T_True);
         Write_Space;
      else
         Print_Token (T_False);
         Write_Space;
      end if;

   end Print_Boolean_Literal;

505
end Ocarina.BE_AADL_BA.Expressions;