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

33
with Ocarina.Backends.C_Tree.Nodes; use Ocarina.Backends.C_Tree.Nodes;
34

35 1
package Ocarina.Backends.C_Tree.Nutils is
36

37 1
   Int0_Val : Value_Id;
38 1
   Int1_Val : Value_Id;
39

40
   Var_Suffix  : constant String := "_j";
41
   Initialized : Boolean         := False;
42

43
   Output_Unit_Withing : Boolean := False;
44
   --  Control flags
45

46
   type Browsing_Kind is (By_Source, By_Destination, Default);
47

48
   type Token_Type is
49
     (
50
   --   Token name      Token type
51
   --   Keywords
52
   Tok_Null,            -- NULL   **** First Keyword
53
      Tok_Break,           -- BREAK
54
      Tok_Case,            -- CASE
55
      Tok_Const,           -- CONST
56
      Tok_Define,          -- DEFINE
57
      Tok_Default,         -- DEFAULT
58
      Tok_Endif,           -- ENDIF
59
      Tok_Else,            -- ELSE
60
      Tok_Enum,            -- ENUM
61
      Tok_Extern,          -- EXTERN
62
      Tok_Struct,          -- STRUCT
63
      Tok_Union,           -- UNION
64
      Tok_Exit,            -- EXIT
65
      Tok_Goto,            -- GOTO
66
      Tok_If,              -- IF
67
      Tok_Ifdef,           -- IFDEF
68
      Tok_Ifndef,          -- IFNDEF
69
      Tok_Include,         -- INCLUDE
70
      Tok_Return,          -- RETURN
71
      Tok_Until,           -- UNTIL
72
      Tok_For,             -- FOR
73
      Tok_While,           -- WHILE
74
      Tok_Static,          -- STATIC
75
      Tok_Switch,          -- SWITCH
76
      Tok_Typedef,         -- TYPEDEF
77

78
   --  Graphic Characters
79
      Tok_Xor,             -- ^
80
      Tok_Sharp,           -- #
81
      Tok_Mod,             -- %
82
      Tok_Not,             -- !
83
      Tok_Left_Brace,      -- {
84
      Tok_Right_Brace,     -- }
85
      Tok_Or,              -- ||
86
      Tok_And,             -- &&
87
      Tok_Ampersand,       -- &
88
      Tok_Minus,           -- -
89
      Tok_Underscore,      -- _
90
      Tok_Plus,            -- +
91
      Tok_Plus_Plus,       -- ++
92
      Tok_Asterisk,        -- *
93
      Tok_Slash,           -- /
94
      Tok_Quote,           -- "
95
      Tok_Dot,             -- .
96
      Tok_Apostrophe,      -- '
97
      Tok_Left_Paren,      -- (
98
      Tok_Right_Paren,     -- )
99
      Tok_Left_Hook,       -- [
100
      Tok_Right_Hook,      -- ]
101
      Tok_Comma,           -- ,
102
      Tok_Less,            -- <
103
      Tok_Equal,           -- =
104
      Tok_Equal_Equal,     -- ==
105
      Tok_Greater,         -- >
106
      Tok_Not_Equal,       -- /=
107
      Tok_Greater_Equal,   -- >=
108
      Tok_Less_Equal,      -- <=
109
      Tok_Colon,           -- :
110
      Tok_Greater_Greater, -- >>
111
      Tok_Less_Less,       -- <<
112
      Tok_Semicolon,       -- ;
113
      Tok_Arrow,           -- ->
114
      Tok_Vertical_Bar);   -- |
115

116 1
   Token_Image : array (Token_Type) of Name_Id;
117

118
   subtype Keyword_Type is Token_Type range Tok_Null .. Tok_Typedef;
119

120
   type Operator_Type is
121
     (Op_Not,             -- !  -- not
122
      Op_And,             -- &&
123
      --  Op_In,          -- in
124
      --  Op_And_Then,    -- and then
125
      Op_Or,              -- ||
126
      --  Op_Or_Else,     -- or else
127
      Op_And_Symbol,      -- &
128
      Op_Double_Asterisk, -- **
129
      Op_Minus,           -- -
130
      Op_Plus,            -- +
131
      Op_Plus_Plus,       -- ++
132
      Op_Asterisk,        -- *
133
      Op_Slash,           -- /
134
      Op_Less,            -- <
135
      Op_Equal,           -- =
136
      Op_Equal_Equal,     -- ==
137
      Op_Greater,         -- >
138
      Op_Not_Equal,       -- !=
139
      Op_Greater_Equal,   -- >=
140
      Op_Less_Equal,      -- <=
141
      Op_Greater_Greater, -- >>
142
      Op_Less_Less,       -- <<
143
      Op_Semicolon,       -- ;
144
      Op_Arrow,           -- ->
145
      Op_Modulo,           -- %
146
      Op_Vertical_Bar,    -- |
147
      Op_None);           -- No operation
148

149 1
   Operator_Image : array
150
   (Operator_Type'Pos (Op_Not) ..
151
        Operator_Type'Pos (Op_Vertical_Bar)) of Name_Id;
152

153
   type Parameter_Id is
154
     (P_From,
155
      P_To,
156
      P_Unused,
157
      P_Message,
158
      P_Msg,
159
      P_Request,
160
      P_Buffer,
161
      P_Data,
162
      P_Length,
163
      P_Status,
164
      P_Entity,
165
      P_Task,
166
      P_Partition,
167
      P_Pkt,
168
      P_Port,
169
      P_Error,
170
      P_Offset,
171
      P_Self,
172
      P_Value);
173

174 1
   PN : array (Parameter_Id) of Name_Id;
175

176
   type Member_Id is
177
     (M_Operation,
178
      M_Protected_Id,
179
      M_Failed_Process_Id,
180
      M_Error_Code,
181
      M_Port,
182
      M_Entry,
183
      M_Entry_Point,
184
      M_Kind,
185
      M_Data,
186
      M_Length,
187
      M_Msg,
188
      M_Name,
189
      M_Base_Priority,
190
      M_Priority,
191
      M_Failed_Thread,
192
      M_Error_Kind,
193
      M_Time_Capacity,
194
      M_Stack_Size,
195
      M_Deadline,
196
      M_Period,
197
      M_Flags,
198
      M_Nb_Dispatch_Triggers_Of_Each_Transition,
199
      M_Nb_Transitions,
200
      M_Dispatch_Triggers_Of_All_Transitions,
201
      M_Nb_Of_All_Dispatch_Events,
202
      M_States_Attributes,
203
      M_Vars);
204

205 1
   MN : array (Member_Id) of Name_Id;
206

207
   type Constant_Id is (C_Null);
208

209
   CONST : array (Constant_Id) of Name_Id;
210

211
   type Variable_Id is
212
     (V_Request,
213
      V_Ret,
214
      V_Tattr,
215
      V_Lua_Context,
216
      V_Next_Period,
217
      V_Port_Global_To_Entity,
218
      V_Port_Global_To_Local_Port,
219
      V_Server_Entity_Table,
220
      V_Invalid_Server,
221
      V_Got_Data,
222
      V_Dev_Id,
223
      V_Entity,
224
      V_Period,
225
      V_Offset,
226
      V_Port,
227
      V_Pkt,
228
      V_Thread,
229
      V_Error,
230
      V_Error_Status,
231
      V_Out,
232
      V_In,
233
      V_Next_Complete_State,
234
      V_Index_Transition_To_Execute,
235
      V_Message);
236

237 1
   VN : array (Variable_Id) of Name_Id;
238

239
   type Function_Id is
240
     (F_Process_Request, F_Register_Source, F_Init_Lane, F_Sizeof,
241
      F_Malloc, F_Create);
242

243 1
   FN : array (Function_Id) of Name_Id;
244

245
   type Component_Id is
246
     (C_Address,
247
      C_Dispatcher,
248
      C_From,
249
      C_Los,
250
      C_Name,
251
      C_Pid,
252
      C_Proc_Id,
253
      C_Switch,
254
      C_Conf_Table,
255
      C_Priority,
256
      C_Operation);
257

258 1
   CN : array (Component_Id) of Name_Id;
259

260
   type Attribute_Id is
261
     (A_Access,
262
      A_Class,
263
      A_First,
264
      A_Pos,
265
      A_Range,
266
      A_Val,
267
      A_Identity,
268
      A_Adress,
269
      A_Last);
270

271 1
   AN : array (Attribute_Id) of Name_Id;
272

273
   type Type_Id is
274
     (T_Char,
275
      T_Float,
276
      T_Int,
277
      T_Uint8_T,
278
      T_Uint32_T,
279
      T_Int8_T,
280
      T_Int16_T,
281
      T_Int32_T,
282
      T_Int64_T,
283
      T_Void,
284
      T_Unsigned);
285

286 1
   TN : array (Type_Id) of Name_Id;
287

288
   function Add_Prefix_To_Name
289
     (Prefix : String;
290
      Name   : Name_Id) return Name_Id;
291

292
   function Add_Suffix_To_Name
293
     (Suffix : String;
294
      Name   : Name_Id) return Name_Id;
295

296
   function Remove_Suffix_From_Name
297
     (Suffix : String;
298
      Name   : Name_Id) return Name_Id;
299
   --  This function returns a new name without the suffix. If the
300
   --  suffix does not exist, the returned name is equal to the given
301
   --  name.
302

303
   procedure Append_Node_To_List (E : Node_Id; L : List_Id);
304
   procedure Insert_After_Node (E : Node_Id; N : Node_Id);
305
   procedure Insert_Before_Node (E : Node_Id; N : Node_Id; L : List_Id);
306

307
   procedure Push_Entity (E : Node_Id);
308
   procedure Pop_Entity;
309
   function Current_Entity return Node_Id;
310
   function Current_File return Node_Id;
311

312
   function Copy_Node (N : Node_Id) return Node_Id;
313

314
   function New_Node
315
     (Kind : Node_Kind;
316
      From : Node_Id := No_Node) return Node_Id;
317

318
   function New_List
319
     (Kind : Node_Kind;
320
      From : Node_Id := No_Node) return List_Id;
321

322
   function Image (T : Token_Type) return String;
323
   function Image (O : Operator_Type) return String;
324

325
   procedure Initialize;
326
   procedure Reset;
327

328
   procedure New_Token (T : Token_Type; I : String := "");
329

330
   function Length (L : List_Id) return Natural;
331

332
   procedure Remove_Node_From_List (E : Node_Id; L : List_Id);
333
   --  Remove node N to list L.
334

335
   function Is_Empty (L : List_Id) return Boolean;
336
   pragma Inline (Is_Empty);
337
   --  Return True when L is empty
338

339
   function Make_C_Comment
340
     (N                 : Name_Id;
341
      Has_Header_Spaces : Boolean := True) return Node_Id;
342
   --  This function does only the fllowing thing: it creates a node
343
   --  whose name is the full text of the comment. It does not split
344
   --  the comment into many lines. This is done in the code
345
   --  generation phase
346

347
   function Make_Assignment_Statement
348
     (Variable_Identifier : Node_Id;
349
      Expression          : Node_Id) return Node_Id;
350

351
   function Make_Defining_Identifier
352
     (Name             : Name_Id;
353
      C_Conversion     : Boolean := True;
354
      Ada_Conversion   : Boolean := False;
355
      Pointer          : Boolean := False;
356
      Variable_Address : Boolean := False) return Node_Id;
357

358
   function Make_Expression
359
     (Left_Expr  : Node_Id;
360
      Operator   : Operator_Type := Op_None;
361
      Right_Expr : Node_Id       := No_Node) return Node_Id;
362

363
   function Make_For_Statement
364
     (Pre_Cond            : Node_Id;
365
      Condition           : Node_Id;
366
      Post_Cond           : Node_Id;
367
      Statements          : List_Id) return Node_Id;
368

369
   function Make_Variable_Declaration
370
     (Defining_Identifier : Node_Id;
371
      Used_Type           : Node_Id;
372
      Is_Static           : Boolean := False;
373
      Value               : Node_Id := No_Node) return Node_Id;
374

375
   function Make_Member_Declaration
376
     (Defining_Identifier : Node_Id;
377
      Used_Type           : Node_Id) return Node_Id;
378

379
   function Make_Enum_Aggregate (Members : List_Id) return Node_Id;
380

381
   function Make_Struct_Aggregate
382
     (Defining_Identifier : Node_Id := No_Node;
383
      Members             : List_Id) return Node_Id;
384

385
   function Make_Union_Aggregate
386
     (Defining_Identifier : Node_Id := No_Node;
387
      Members             : List_Id) return Node_Id;
388

389
   function Make_While_Statement
390
     (Condition  : Node_Id;
391
      Statements : List_Id) return Node_Id;
392

393
   function Make_Full_Type_Declaration
394
     (Defining_Identifier : Node_Id;
395
      Type_Definition     : Node_Id) return Node_Id;
396
   --  No_Node as Type_Definition made type declaration without actual
397
   --  definition (eg. "type X;").
398

399
   function Make_If_Statement
400
     (Condition       : Node_Id;
401
      Statements      : List_Id;
402
      Else_Statements : List_Id := No_List) return Node_Id;
403

404
   function Make_List_Id
405
     (N1 : Node_Id;
406
      N2 : Node_Id := No_Node;
407
      N3 : Node_Id := No_Node) return List_Id;
408

409
   function Make_Parameter_Specification
410
     (Defining_Identifier : Node_Id;
411
      Parameter_Type      : Node_Id := No_Node) return Node_Id;
412

413
   function Make_Return_Statement
414
     (Expression : Node_Id := No_Node) return Node_Id;
415

416
   function Make_Call_Profile
417
     (Defining_Identifier : Node_Id;
418
      Parameters          : List_Id := No_List) return Node_Id;
419

420
   function Make_Function_Implementation
421
     (Specification : Node_Id;
422
      Declarations  : List_Id;
423
      Statements    : List_Id) return Node_Id;
424

425
   function Make_Function_Specification
426
     (Defining_Identifier : Node_Id;
427
      Parameters          : List_Id := No_List;
428
      Return_Type         : Node_Id := No_Node) return Node_Id;
429

430
   function Make_Type_Attribute
431
     (Designator : Node_Id;
432
      Attribute  : Attribute_Id) return Node_Id;
433

434
   function Make_Type_Conversion
435
     (Subtype_Mark : Node_Id;
436
      Expression   : Node_Id) return Node_Id;
437

438
   procedure Make_Comment_Header (Header : List_Id);
439
   --  This procedure generates a comment header for the generated
440
   --  packages.
441

442
   function Next_N_Node (N : Node_Id; Num : Natural) return Node_Id;
443
   --  This function executes Next_Node Num times
444

445
   function Message_Comment (M : Name_Id) return Node_Id;
446
   function Message_Comment (M : String) return Node_Id;
447
   --  Return a comment message. Used by all the tree
448
   --  converters
449

450
   procedure Set_Activity_Source (N : Node_Id := No_Node);
451

452
   procedure Set_Activity_Header (N : Node_Id := No_Node);
453

454
   procedure Set_Main_Source (N : Node_Id := No_Node);
455

456
   procedure Set_Main_Header (N : Node_Id := No_Node);
457

458
   procedure Set_Request_Source (N : Node_Id := No_Node);
459

460
   procedure Set_Request_Header (N : Node_Id := No_Node);
461

462
   function To_C_Name
463
     (N             : Name_Id;
464
      Ada_Style     : Boolean := False;
465
      Keyword_Check : Boolean := True) return Name_Id;
466
   --  Convert N to a valid Ada identifier (no clashing with keywords,
467
   --  no consecutive '_', no heading '_'...).
468
   --  If Ada_Style is true, '.' is replaced by "__"
469

470
   function Conventional_Base_Name (N : Name_Id) return Name_Id;
471
   --  Return a lower case name of N
472

473
   function Make_Source_File (Identifier : Node_Id) return Node_Id;
474

475
   function Make_Header_File (Identifier : Node_Id) return Node_Id;
476

477
   procedure Set_Deployment_Header (N : Node_Id := No_Node);
478

479
   function Make_Literal (Value : Value_Id) return Node_Id;
480

481
   function Make_Define_Statement
482
     (Defining_Identifier : Node_Id;
483
      Value               : Node_Id) return Node_Id;
484

485
   function Make_Pointer_Type (Used_Type : Node_Id) return Node_Id;
486

487
   procedure Add_Include (E : Node_Id; Preserve_Case : Boolean := False);
488

489
   procedure Set_Types_Header (N : Node_Id := No_Node);
490

491
   procedure Set_Types_Source (N : Node_Id := No_Node);
492

493
   procedure Set_Naming_Source (N : Node_Id := No_Node);
494

495
   procedure Set_Subprograms_Source (N : Node_Id := No_Node);
496

497
   procedure Set_Subprograms_Header (N : Node_Id := No_Node);
498

499
   procedure Set_Marshallers_Source (N : Node_Id := No_Node);
500

501
   procedure Set_Marshallers_Header (N : Node_Id := No_Node);
502

503
   function Make_Variable_Address (Expression : Node_Id) return Node_Id;
504

505
   function Make_Member_Designator
506
     (Defining_Identifier : Node_Id;
507
      Aggregate_Name      : Node_Id;
508
      Is_Pointer          : Boolean := False) return Node_Id;
509

510
   function Make_Switch_Alternative
511
     (Labels     : List_Id;
512
      Statements : List_Id) return Node_Id;
513

514
   function Make_Switch_Statement
515
     (Expression   : Node_Id;
516
      Alternatives : List_Id) return Node_Id;
517

518
   function Make_Macro_Call
519
     (Defining_Identifier : Node_Id;
520
      Parameters          : List_Id := No_List) return Node_Id;
521

522
   procedure POK_Add_Return_Assertion
523
     (Statements      : List_Id;
524
      Exception_Error : Node_Id := No_Node);
525

526
   procedure Handle_Call_Sequence
527
     (Caller            : Node_Id;
528
      Call_Seq          : Node_Id;
529
      Declarations      : List_Id;
530
      Statements        : List_Id;
531
      Containing_Device : Node_Id := No_Node);
532
   --  The Containing_Device argument is used when the call
533
   --  sequence is generated for a thread that is within
534
   --  a device. In that case, the first parameter is ALWAYS
535
   --  the device id of the containing device.
536

537
   procedure Set_Deployment_Source (N : Node_Id := No_Node);
538

539
   function Make_Array_Declaration
540
     (Defining_Identifier : Node_Id;
541
      Array_Size          : Node_Id) return Node_Id;
542

543
   function Make_Array_Values (Values : List_Id := No_List) return Node_Id;
544

545
   function Make_Extern_Entity_Declaration (Entity : Node_Id) return Node_Id;
546

547
   function Make_Constant_Type (Used_Type : Node_Id) return Node_Id;
548

549
   procedure Set_Naming_Header (N : Node_Id := No_Node);
550

551
   function Get_C_Default_Value (D : Node_Id) return Node_Id;
552

553
   function POK_Make_Function_Call_With_Assert
554
     (Function_Name : Node_Id;
555
      Parameters    : List_Id) return Node_Id;
556

557
   function Make_Include_Clause
558
     (Header_Name : Node_Id;
559
      Local       : Boolean := False) return Node_Id;
560

561
   function Make_Ifdef_Clause
562
     (Clause          : Node_Id;
563
      Negation        : Boolean := False;
564
      Then_Statements : List_Id;
565
      Else_Statements : List_Id) return Node_Id;
566

567
   procedure Add_Define_Deployment (E : Node_Id);
568

569
   function Make_Array_Value
570
     (Array_Name : Node_Id;
571
      Array_Item : Node_Id) return Node_Id;
572

573
   function Get_Data_Size (Data : Node_Id;
574
                           Is_Pointer : Boolean := False;
575
                           Maximum_Size : Boolean := False)
576
                          return Node_Id;
577
   --  Returns a node that represent an expression with the size (in
578
   --  bytes) of a data.
579
   --  Note: for some types like Bounded_Array, this expression is dynamic.
580
   --  - Is_Pointer controls wether we build a pointer-like expresison;
581
   --  - Maximum_Size returns the maximum size (static value).
582

583
   procedure Add_Return_Variable_In_Parameters (Parameters : List_Id);
584
   --  Add the name of the return variable in the list.
585
   --  The primary purpose of this function is to add
586
   --  the return variable at the end of a function call
587
   --  for the ARINC653 API.
588

589
   procedure POK_Declare_Return_Variable (Declarations : List_Id);
590
   --  Declare the return variable used for assertions
591
   --  in function declarations or other list.
592

593
   function Get_Inter_Partition_Port_Size (Port : Node_Id) return Node_Id;
594
   --  Get_Inter_Partition_Port_Size returns the port size of an inter
595
   --  partition communication. It takes the whole data flow of a connection
596
   --  and look for virtual bus binding in this flow to see if we need
597
   --  larger data.
598

599
   function Get_Inter_Partition_Port_Type (Port : Node_Id) return Node_Id;
600
   --  Get_Inter_Partition_Port_Type returns a Node_Id that contains
601
   --  all information to generate a C data type linked with
602
   --  virtual bus layers.
603

604
   function Make_Doxygen_C_Comment
605
     (Desc              : String;
606
      Brief             : String  := "";
607
      Element_Name      : String  := "";
608
      Is_Struct         : Boolean := False;
609
      Is_Union          : Boolean := False;
610
      Is_Enum           : Boolean := False;
611
      Is_Function       : Boolean := False;
612
      Is_Variable       : Boolean := False;
613
      Is_Define         : Boolean := False;
614
      Is_Typedef        : Boolean := False;
615
      Is_File           : Boolean := False;
616
      Is_Namespace      : Boolean := False;
617
      Is_Package        : Boolean := False;
618
      Is_Interface      : Boolean := False;
619
      Has_Header_Spaces : Boolean := True) return Node_Id;
620

621
   --  The Make_Doxygen_C_Comment.
622

623 1
end Ocarina.Backends.C_Tree.Nutils;

Read our documentation on viewing source code .

Loading