ocarina-be_aadl-annexes.adb 5.99 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 . A N N E X E S               --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2008-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
33
with Ocarina.Namet;
with Ocarina.Output;
34
35
36
37
38
39
40
41
42

with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.BE_AADL.Identifiers;
with Ocarina.BE_AADL.Components.Modes;

with Ocarina.Backends;

package body Ocarina.BE_AADL.Annexes is

43
44
   use Ocarina.Namet;
   use Ocarina.Output;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
   use Ocarina.ME_AADL.AADL_Tree.Nodes;
   use Ocarina.BE_AADL.Identifiers;
   use Ocarina.BE_AADL.Components.Modes;
   use Ocarina.Backends;

   procedure Print_Annex_Content (Node : Node_Id);

   -------------------------
   -- Print_Annex_Content --
   -------------------------

   procedure Print_Annex_Content (Node : Node_Id) is
   begin
      Write_Name (Raw_Text (Node));
   end Print_Annex_Content;

   ---------------------------
   -- Print_Annex_Subclause --
   ---------------------------

   procedure Print_Annex_Subclause (Node : Node_Id) is
      Content : constant Node_Id := Annex_Content (Node);
67
      In_Mode :          Node_Id := In_Modes (Node);
68
69

   begin
70
71
72
73
      if Kind (Node) = K_Annex_Subclause then
         In_Mode := In_Modes (Node);
      end if;

74
75
76
77
78
79
80
81
82
      Write_Indentation;
      Print_Token (T_Annex);
      Write_Space;

      Print_Identifier (Identifier (Node));
      Write_Space;

      case AADL_Version is
         when AADL_V2 =>
83
84
85
86
87
88
89
            if Present (Corresponding_Annex (Node))
              and then Get_Backend (Name (Identifier (Node))) /= 0
            then
               --  Pretty print Annexe if we can parse them and if
               --  there is a pretty printer. Should one of these two
               --  condition fail, we fall back to dumping raw text.

90
               Print_Token (T_Begin_Annex);
91
92
93
               Generate_Code
                 (Corresponding_Annex (Node),
                  Name (Identifier (Node)));
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
128
129
130
131
132
133
               Write_Indentation;
               Print_Token (T_End_Annex);

            elsif Raw_Text (Content) = No_Name then
               Print_Token (T_None);
            else
               Print_Token (T_Begin_Annex);
               Print_Annex_Content (Content);
               Write_Indentation;
               Write_Indentation (-1);
               Print_Token (T_End_Annex);
            end if;

            if Present (In_Mode) then
               Print_In_Modes (In_Mode);
            end if;

         when AADL_V1 =>
            Print_Token (T_Begin_Annex);

            if Present (Content) then
               Print_Annex_Content (Content);
            else
               Write_Eol;
            end if;

            Write_Indentation;
            Write_Indentation (-1);
            Print_Token (T_End_Annex);
      end case;

      Print_Token (T_Semicolon);
   end Print_Annex_Subclause;

   ----------------------
   -- Print_Annex_Path --
   ----------------------

   procedure Print_Annex_Path (Node : Node_Id) is

134
135
      pragma Assert
        (Ocarina.ME_AADL.AADL_Tree.Nodes.Kind (Node) = K_Annex_Path);
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

      List_Node : Node_Id;
   begin

      if Present (Identifier (Node)) then
         Print_Token (T_Left_Curly_Bracket);
         Write_Space;
         Print_Identifier (Identifier (Node));
         Write_Space;
         Print_Token (T_Right_Curly_Bracket);
      end if;

      List_Node :=
        First_Node (Ocarina.ME_AADL.AADL_Tree.Nodes.Identifiers (Node));
      Print_Token (T_Multiply);
      Print_Token (T_Multiply);
      Print_Identifier (Node);

      while Present (List_Node) loop
155
156
157
         if List_Node /=
           First_Node (Ocarina.ME_AADL.AADL_Tree.Nodes.Identifiers (Node))
         then
158
159
160
161
162
163
164
165
166
167
168
169
170
            Write_Space;
            Print_Token (T_Multiply);
            Print_Token (T_Multiply);
         end if;

         Print_Identifier (List_Node);

         List_Node := Next_Node (List_Node);
      end loop;

   end Print_Annex_Path;

end Ocarina.BE_AADL.Annexes;