ocarina-instances-real_finder.adb 8.62 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--        O C A R I N A . I N S T A N C E S . R E A L _ F I N D E R         --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--          Copyright (C) 2009-2011, European Space Agency (ESA).           --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--                                                                          --
-- 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.                                       --
--                                                                          --
--                 Ocarina is maintained by the Ocarina team                --
--                       (ocarina-users@listes.enst.fr)                     --
--                                                                          --
------------------------------------------------------------------------------

with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Entities.Properties;
with Ocarina.Instances.Queries;
use Ocarina.Instances.Queries;
with Ocarina.ME_REAL.REAL_Tree.Nodes;
with Ocarina.ME_REAL.REAL_Tree.Nutils;
with Ocarina.REAL_Values;
with Ocarina.AADL_Values;
with Locations;
with Ocarina.ME_AADL.AADL_Instances.Entities;

package body Ocarina.Instances.REAL_Finder is
   use Ocarina.ME_REAL.REAL_Tree.Nodes;
   use Ocarina.ME_REAL.REAL_Tree.Nutils;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.REAL_Values;

   package RNU renames Ocarina.ME_REAL.REAL_Tree.Nutils;
   package AIEP renames Ocarina.ME_AADL.AADL_Instances.Entities.Properties;
   package RV renames Ocarina.REAL_Values;

   ------------------------
   -- Get_Property_Value --
   ------------------------

   function Get_Property_Value
     (Property_Name : Name_Id;
      Node          : Node_Id) return Value_Id
   is
      V : Value_Id;
   begin
      V := RV.New_String_Value (Property_Name);
      return Get_Property_Value_Function (V, RT_Unknown, Node);
   end Get_Property_Value;

   ---------------------------------
   -- Get_Property_Value_Function --
   ---------------------------------

   function Get_Property_Value_Function
     (Property : Value_Id;
      T        : Return_Type;
      Var      : Node_Id)
     return Value_Id
   is
      use Locations;

      package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
      package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
      package OV renames Ocarina.AADL_Values;
      use OV;

      pragma Assert (AIN.Kind (Var) = AIN.K_Component_Instance or else
                     AIN.Kind (Var) = AIN.K_Call_Instance);

      VT2           : constant RV.Value_Type := RV.Get_Value_Type (Property);
      Property_Name : constant Name_Id := To_Lower (VT2.SVal);
      VT            : OV.Value_Type;
93
      Result        : Value_Id := Real_Values.No_Value;
94
95
96
97
98
99
      N             : Node_Id;
      Is_List       : Boolean := False;
      Resolved_Var  : Node_Id;
      Val           : Node_Id;
      Result_List   : constant List_Id := RNU.New_List
        (K_List_Id, No_Location);
100

101
102
103
104
105
106
107
108
109
110
111
112
113
   begin
      if AIN.Kind (Var) = AIN.K_Call_Instance then
         Resolved_Var := AIN.Corresponding_Instance (Var);
      else
         Resolved_Var := Var;
      end if;

      --  XXX Expanded_Multi_Value seems bugged. Fix it, and use
      --  Get_Value_Of_Property_Association instead

      N := AIEP.Find_Property_Association_From_Name
        (Property_List => AIN.Properties (Resolved_Var),
         Property_Name => Property_Name);
114

115
116
117
118
119
120
121
122
123
124
125
126
      if Present (N) then
         N := AIN.Property_Association_Value (N);
         if ATN.Expanded_Single_Value (N) /= No_Node then
            N := ATN.Expanded_Single_Value (N);
         elsif ATN.Single_Value (N) /= No_Node then
            N := ATN.Single_Value (N);
         elsif ATN.Multi_Value (N) /= No_List then
            N := ATN.First_Node (ATN.Multi_Value (N));
            Is_List := True;
         else
            N := No_Node;
         end if;
127

128
      else
129
         --  In the specific case of lists, we always returns an empty list
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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

         case T is
            when RT_String_List
              | RT_Float_List
              | RT_Int_List
              | RT_Bool_List
              | RT_Range_List
              | RT_Element_List =>
               Result := RV.New_List_Value (Result_List);
               return Result;

            when others =>
               Result := RV.No_Value;
         end case;
      end if;

      while Present (N) loop
         if not Is_List then
            Is_List := Present (ATN.Next_Node (N));
         end if;

         case ATN.Kind (N) is
            when ATN.K_Signed_AADLNumber =>
               Result := AADL_Value (ATN.Value (ATN.Number_Value (N)));

            when ATN.K_Literal =>
               VT := OV.Get_Value_Type (ATN.Value (N));

               --  Enum are turned into strings

               if VT.T = OV.LT_Enumeration then
                  Result := RV.New_String_Value (VT.EVal);
               else
                  Result := AADL_Value (ATN.Value (N));
               end if;

            when ATN.K_Number_Range_Term =>
               declare
                  L, R   : Value_Id;
                  LT, RT : RV.Value_Type;
               begin
                  L := AADL_Value (ATN.Value (ATN.Number_Value
                                              (ATN.Lower_Bound (N))));
                  LT := Get_Value_Type (L);
                  R := AADL_Value (ATN.Value (ATN.Number_Value
                                              (ATN.Upper_Bound (N))));
                  RT := Get_Value_Type (R);

                  if LT.T = LT_Integer then
                     Result := New_Range_Value
                       (Long_Long_Float (LT.IVal),
                        Long_Long_Float (RT.IVal),
                        LT.ISign, RT.ISign,
                        RT.IBase, RT.IExp);
                  else
                     Result := New_Range_Value
186
187
                       (LT.RVal,
                        RT.RVal,
188
189
190
191
192
193
194
195
196
197
                        LT.RSign, RT.RSign,
                        RT.RBase, RT.RExp);
                  end if;
               end;

            when ATN.K_Enumeration_Term =>
               Result := RV.New_String_Value
                 (ATN.Name (ATN.Identifier (N)));

            when ATN.K_Reference_Term =>
198
199
200
201
202
203
204
205
               Result := RV.New_Elem_Value
                 (Get_Reference_Property
                    (Resolved_Var, Property_Name));

            when ATN.K_Component_Classifier_Term =>
               Result := RV.New_Elem_Value
                 (Get_Classifier_Property
                    (Resolved_Var, Property_Name));
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

            when others =>
               return RV.No_Value;
         end case;

         if Is_List then
            Val := New_Node (K_Value_Node, No_Location);
            Set_Item_Val (Val, Result);
            RNU.Append_Node_To_List (Val, Result_List);
         end if;

         N := ATN.Next_Node (N);
      end loop;

      if Is_List then
         Result := RV.New_List_Value (Result_List);
      end if;

      return Result;
   end Get_Property_Value_Function;

end Ocarina.Instances.REAL_Finder;