ocarina-property_sets.adb 8.8 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--                O C A R I N A . P R O P E R T Y _ S E T S                 --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2014 ESA & ISAE.      --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--                                                                          --
-- Ocarina  is free software;  you  can  redistribute  it and/or  modify    --
-- it under terms of the GNU General Public License as published by the     --
-- Free Software Foundation; either version 2, or (at your option) any      --
-- later version. 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. See the GNU General --
-- Public License for more details. You should have received  a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING.   --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA.                                       --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable to be   --
-- covered  by the  GNU  General  Public  License. This exception does not  --
-- however invalidate  any other reasons why the executable file might be   --
-- covered by the GNU Public License.                                       --
--                                                                          --
jhugues's avatar
jhugues committed
29
30
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
31
32
33
34
--                                                                          --
------------------------------------------------------------------------------

with Charset; use Charset;
35
with Ocarina.Namet;   use Ocarina.Namet;
36

37
with Ocarina.ME_AADL.AADL_Tree.Nodes; use Ocarina.ME_AADL.AADL_Tree.Nodes;
38
39
40
41

package body Ocarina.Property_Sets is

   AADLv1_Std_Property_Sets : aliased Standard_Property_Set_Array_Type :=
42
     (S_AADL_Project, S_AADL_Properties);
43
44
45
46
47
48
49

   AADLv2_Std_Property_Sets : aliased Standard_Property_Set_Array_Type :=
     (S_AADL_Project,
      S_Deployment_Properties,
      S_Thread_Properties,
      S_Communication_Properties,
      S_Memory_Properties,
50
      S_Modeling_Properties,
51
52
53
      S_Timing_Properties,
      S_Programming_Properties);

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
   Standard_Property_Sets_Table : constant array
   (AADL_Version_Type) of Standard_Property_Set_Array_Access :=
     (AADL_V1 => AADLv1_Std_Property_Sets'Access,
      AADL_V2 => AADLv2_Std_Property_Sets'Access);

   AADLv1_Ocarina_Property_Sets : aliased Ocarina_Property_Set_Array_Type :=
     (O_Data_Model,
      O_Deployment,
      O_Cheddar_Properties,
      O_Ocarina_Config,
      O_Base_Types,
      O_ASSERT_Types,
      O_ASSERT_Properties);

   AADLv2_Ocarina_Property_Sets : aliased Ocarina_Property_Set_Array_Type :=
     (O_Data_Model,
      O_Deployment,
      O_Cheddar_Properties,
      O_Ocarina_Config,
      O_Transformations,
      O_POK_Properties,
      O_Base_Types,
      O_Taste_Properties,
      O_ARINC653_Properties,
      O_ASSERT_Properties);

   Ocarina_Property_Sets_Table : constant array
   (AADL_Version_Type) of Ocarina_Property_Set_Array_Access :=
     (AADL_V1 => AADLv1_Ocarina_Property_Sets'Access,
      AADL_V2 => AADLv2_Ocarina_Property_Sets'Access);
84
85
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

   User_Defined_Mask : constant Byte := 2**1;

   Standard_Property_Set_Mask : constant Byte := 2**2;
   Ocarina_Property_Set_Mask  : constant Byte := 2**3;

   function Internal_Name (N : Name_Id) return Name_Id;
   function Internal_Name (S : String) return Name_Id;

   -----------
   -- Image --
   -----------

   function Image (S : Standard_Property_Set_Type) return String is
      N : constant String := To_Lower (S'Img);
   begin
      return N (N'First + 2 .. N'Last);
   end Image;

   -----------
   -- Image --
   -----------

   function Image (O : Ocarina_Property_Set_Type) return String is
      N : constant String := To_Lower (O'Img);
   begin
      case O is
         when O_Cheddar_Properties =>
            return "Cheddar_Properties";
         when others =>
            return N (N'First + 2 .. N'Last);
      end case;
   end Image;

   ----------------
   -- Initialize --
   ----------------

   procedure Initialize is
      N : Name_Id;

   begin
      for S in Standard_Property_Sets'Range loop
         N := Internal_Name (Standard_Property_Sets (S)'Img);
         Set_Name_Table_Byte (N, Standard_Property_Set_Mask);
      end loop;

      for S in Ocarina_Property_Sets'Range loop
         N := Internal_Name (Ocarina_Property_Sets (S)'Img);
         Set_Name_Table_Byte (N, Ocarina_Property_Set_Mask);
      end loop;
   end Initialize;

   -------------------
   -- Internal_Name --
   -------------------

   function Internal_Name (N : Name_Id) return Name_Id is
   begin
      return Internal_Name (Get_Name_String (N));
   end Internal_Name;

   -------------------
   -- Internal_Name --
   -------------------

   function Internal_Name (S : String) return Name_Id is
      Tag : constant String := "%property_set%";

   begin
yoogx's avatar
yoogx committed
154
      if S'Length > 2 and then S (S'First + 1) = '_' then
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
         Set_Str_To_Name_Buffer (S (S'First + 2 .. S'Last));
      else
         Set_Str_To_Name_Buffer (S);
      end if;
      Add_Str_To_Name_Buffer (Tag);
      To_Lower (Name_Buffer (1 .. Name_Len));
      return Name_Find;
   end Internal_Name;

   -----------------
   -- Is_Standard --
   -----------------

   function Is_Standard (Identifier : Node_Id) return Boolean is
      pragma Assert (Kind (Identifier) = K_Identifier);
      N : constant Name_Id := Internal_Name (Name (Identifier));

   begin
      return (Get_Name_Table_Byte (N) and Standard_Property_Set_Mask) /= 0;
   end Is_Standard;

   ---------------------
   -- Is_User_Defined --
   ---------------------

   function Is_User_Defined (Identifier : Node_Id) return Boolean is
      pragma Assert (Kind (Identifier) = K_Identifier);
      N : constant Name_Id := Internal_Name (Name (Identifier));
      B : constant Byte    := Get_Name_Table_Byte (N);

   begin
      if B = 0 then
         return False;
      end if;
      return (Get_Name_Table_Byte (N) and User_Defined_Mask) /= 0;
   end Is_User_Defined;

   -------------------------
   -- Property_Set_Entity --
   -------------------------

   function Property_Set_Entity (Identifier : Node_Id) return Node_Id is
      pragma Assert (Kind (Identifier) = K_Identifier);
      N : constant Name_Id := Internal_Name (Name (Identifier));
      B : constant Byte    := Get_Name_Table_Byte (N);

   begin
      if B = 0 then
         return No_Node;
      end if;
      return Node_Id (Get_Name_Table_Info (N));
   end Property_Set_Entity;

   -----------------------------
   -- Set_Property_Set_Entity --
   -----------------------------

   procedure Set_Property_Set_Entity (Identifier : Node_Id) is
      pragma Assert (Kind (Identifier) = K_Identifier);
      N : constant Name_Id := Internal_Name (Name (Identifier));
      B : constant Byte    := Get_Name_Table_Byte (N);

   begin
      if B = 0 then
         return;
      end if;
      Set_Name_Table_Info (N, Int (Identifier));
   end Set_Property_Set_Entity;

   ----------------------------
   -- Standard_Property_Sets --
   ----------------------------

   function Standard_Property_Sets return Standard_Property_Set_Array_Type is
   begin
      return Standard_Property_Sets_Table (AADL_Version).all;
   end Standard_Property_Sets;

   ---------------------------
   -- Ocarina_Property_Sets --
   ---------------------------

   function Ocarina_Property_Sets return Ocarina_Property_Set_Array_Type is
   begin
      return Ocarina_Property_Sets_Table (AADL_Version).all;
   end Ocarina_Property_Sets;

   -------------------------
   -- Set_As_User_Defined --
   -------------------------

   procedure Set_As_User_Defined (Identifier : Node_Id) is
      pragma Assert (Kind (Identifier) = K_Identifier);
      N : constant Name_Id := Internal_Name (Name (Identifier));
      B : constant Byte    := Get_Name_Table_Byte (N);

   begin
      Set_Name_Table_Byte (N, B or User_Defined_Mask);
   end Set_As_User_Defined;

end Ocarina.Property_Sets;