~ubuntu-branches/ubuntu/jaunty/adacontrol/jaunty

« back to all changes in this revision

Viewing changes to src/framework.ads

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Brenta
  • Date: 2006-08-24 08:44:11 UTC
  • Revision ID: james.westby@ubuntu.com-20060824084411-1r15uio1h75lqgpx
Tags: upstream-1.4r20
ImportĀ upstreamĀ versionĀ 1.4r20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
----------------------------------------------------------------------
 
2
--  Framework - Package specification                               --
 
3
--                                                                  --
 
4
--  This software  is (c) The European Organisation  for the Safety --
 
5
--  of Air  Navigation (EUROCONTROL) and Adalog  2004-2005. The Ada --
 
6
--  Controller  is  free software;  you can redistribute  it and/or --
 
7
--  modify  it under  terms of  the GNU  General Public  License as --
 
8
--  published by the Free Software Foundation; either version 2, or --
 
9
--  (at your  option) any later version.  This  unit is distributed --
 
10
--  in the hope  that it will be useful,  but WITHOUT ANY WARRANTY; --
 
11
--  without even the implied warranty of MERCHANTABILITY or FITNESS --
 
12
--  FOR A  PARTICULAR PURPOSE.  See the GNU  General Public License --
 
13
--  for more details.   You should have received a  copy of the GNU --
 
14
--  General Public License distributed  with this program; see file --
 
15
--  COPYING.   If not, write  to the  Free Software  Foundation, 59 --
 
16
--  Temple Place - Suite 330, Boston, MA 02111-1307, USA.           --
 
17
--                                                                  --
 
18
--  As  a special  exception, if  other files  instantiate generics --
 
19
--  from the units  of this program, or if you  link this unit with --
 
20
--  other files  to produce  an executable, this  unit does  not by --
 
21
--  itself cause the resulting executable  to be covered by the GNU --
 
22
--  General  Public  License.   This  exception  does  not  however --
 
23
--  invalidate any  other reasons why the executable  file might be --
 
24
--  covered by the GNU Public License.                              --
 
25
--                                                                  --
 
26
--  This  software is  distributed  in  the hope  that  it will  be --
 
27
--  useful,  but WITHOUT  ANY  WARRANTY; without  even the  implied --
 
28
--  warranty  of  MERCHANTABILITY   or  FITNESS  FOR  A  PARTICULAR --
 
29
--  PURPOSE.                                                        --
 
30
----------------------------------------------------------------------
 
31
 
 
32
-- Ada
 
33
with
 
34
  Ada.Strings.Wide_Unbounded;
 
35
 
 
36
-- ASIS
 
37
with
 
38
  Asis,
 
39
  Asis.Text;
 
40
 
 
41
--  Adalog
 
42
with
 
43
  Binary_Map;
 
44
 
 
45
pragma Elaborate_All (Binary_Map);
 
46
 
 
47
package Framework is
 
48
 
 
49
   --
 
50
   --  General types for rules
 
51
   --
 
52
 
 
53
   type Rule_Types is (Check, Search, Count);
 
54
 
 
55
   --------------------------------------
 
56
   --  Location                        --
 
57
   --------------------------------------
 
58
 
 
59
   -- A location is the position of an element in a file
 
60
 
 
61
   type Location is private;
 
62
   Null_Location : constant Location;
 
63
 
 
64
   function Create_Location (File         : in Wide_String;
 
65
                             First_Line   : in Natural;
 
66
                             First_Column : in Natural) return Location;
 
67
   function Get_Location (E : in Asis.Element) return Location;
 
68
   -- Returns location of an element
 
69
 
 
70
   function Get_File_Name (L : in Location) return Wide_String;
 
71
   -- Returns location file name
 
72
 
 
73
   function Get_First_Line (L : in Location) return Natural;
 
74
   -- Returns location first line
 
75
 
 
76
   function Image (L : in Location) return Wide_String;
 
77
   -- Returns image of a location
 
78
   -- i.e. file:1:1
 
79
 
 
80
   function Value (S : Wide_String) return Location;
 
81
   -- Returns location value of a string
 
82
   -- raises Constraint_Error for an incorrect input string
 
83
 
 
84
 
 
85
   --------------------------------------
 
86
   --  Entity_Specification            --
 
87
   --------------------------------------
 
88
 
 
89
   -- An Entity_Specification is the structure that corresponds to
 
90
   -- the specification of an Ada entity in the command language
 
91
 
 
92
   type Entity_Specification is private;
 
93
   function Image (Entity : Entity_Specification) return Wide_String;
 
94
   function Value (Name : Wide_String) return Entity_Specification;
 
95
   function Is_Box (Entity : Entity_Specification) return Boolean;
 
96
 
 
97
   --------------------------------------
 
98
   --  Rule_Context                    --
 
99
   --------------------------------------
 
100
 
 
101
   -- A context is a rule-specific information associated
 
102
   -- to an entity specification
 
103
 
 
104
   type Rule_Context is tagged null record;
 
105
   procedure Clear (Context : in out Rule_Context);
 
106
   -- The default (inherited) Clear does nothing.
 
107
   -- Redefine clear if you extend Rule_Context with fields (like maps
 
108
   -- or access value) that need finalization when the context store is cleared.
 
109
 
 
110
   Empty_Context       : constant Rule_Context := (null record);
 
111
   No_Matching_Context : constant Rule_Context'Class;
 
112
 
 
113
   -- A simple context is what most rules will need
 
114
   type Simple_Context is new Rule_Context with
 
115
      record
 
116
         Rule_Type  : Rule_Types;
 
117
         Rule_Label : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
 
118
      end record;
 
119
 
 
120
   --------------------------------------
 
121
   --  Context_Store                   --
 
122
   --------------------------------------
 
123
 
 
124
   -- A context_store associates a context to a specific entity specification
 
125
 
 
126
   type Context_Store is limited private;
 
127
   Already_In_Store : exception;
 
128
   Not_In_Store     : exception; -- Raised by Dissociate and Association only
 
129
 
 
130
   procedure Balance (Store : in out Context_Store);
 
131
   procedure Clear   (Store : in out Context_Store);
 
132
 
 
133
   procedure Associate (Into          : in out Context_Store;
 
134
                        Specification : in     Entity_Specification;
 
135
                        Context       : in     Rule_Context'Class;
 
136
                        Additive      : in     Boolean := False);
 
137
   -- If Additive is False, only one context can be associated to the specification
 
138
   --    (or Already_In_Store is raised)
 
139
   -- If Additive is True, several contexts can be associated to a specification
 
140
 
 
141
   procedure Associate_Default (Into    : in out Context_Store;
 
142
                                Context : in     Rule_Context'Class);
 
143
   -- If a default context is defined, it will be returned by Matching_Context if
 
144
   -- the name is not matched, instead of No_Matching_Context.
 
145
 
 
146
   function Matching_Context (Into : Context_Store;
 
147
                              Name : Asis.Element) return Rule_Context'Class;
 
148
   -- Retrieves the context associated to the element if there is a match
 
149
   -- Returns No_Matching_Context otherwise (including if Name is a Nil_Element).
 
150
   --
 
151
   -- Appropriate Element_Kinds for Name:
 
152
   --   A_Pragma (condition searched on pragma name)
 
153
   --   A_Defining_Name
 
154
   --   An_Expression
 
155
   --
 
156
   -- Appropriate Expression_Kinds:
 
157
   --      A_Selected_Component (condition searched on the selector)
 
158
   --      An_Identifier
 
159
   --      An_Attribute_Reference (condition searched on Name'Attribute)
 
160
   --
 
161
   -- Matches are, in decreasing order of priority:
 
162
   --   The name matches with overloading
 
163
   --   The name matches without overloading
 
164
   --   The name matches an "all" association with overloading
 
165
   --   The name matches an "all" association without overloading
 
166
   --   There is a default association (matches everything)
 
167
 
 
168
   function Extended_Matching_Context (Into : Context_Store;
 
169
                                       Name : Asis.Element) return Rule_Context'Class;
 
170
   -- Same as Matching_Context, but extends the search to corresponding generics if Name is
 
171
   -- an instantiation or part of an instantiation
 
172
   -- Restricted to identifiers.
 
173
 
 
174
   function Next_Matching_Context (Into : Context_Store) return Rule_Context'Class;
 
175
   --  Use to retrieve other contexts of an additive association
 
176
   --  Returns the default (or No_Matching_Context) when exhausted
 
177
 
 
178
   function Last_Matching_Name (Into : Context_Store) return Wide_String;
 
179
   -- Name that found the context in the last query to Matching_Context
 
180
 
 
181
   procedure Update (Into    : in out Context_Store;
 
182
                     Context : in     Rule_Context'Class);
 
183
   -- Updates context last returned by Matching_Context or Association
 
184
 
 
185
   function  Association (Into          : in Context_Store;
 
186
                          Specification : in Entity_Specification) return Rule_Context'Class;
 
187
   -- Returns the first Context associated to the specification
 
188
   -- (currently used only for non-additive associations; this may change in the future)
 
189
 
 
190
   procedure Dissociate (From          : in out Context_Store;
 
191
                         Specification : in     Entity_Specification);
 
192
   -- Removes context associated to specification
 
193
 
 
194
private
 
195
   use Ada.Strings.Wide_Unbounded;
 
196
 
 
197
   --
 
198
   -- Location
 
199
   --
 
200
 
 
201
   type Location is record
 
202
      File_Name    : Unbounded_Wide_String;
 
203
      First_Line   : Asis.Text.Line_Number        := 0;
 
204
      First_Column : Asis.Text.Character_Position := 0;
 
205
   end record;
 
206
   Null_Location : constant Location := (Null_Unbounded_Wide_string, 0, 0);
 
207
 
 
208
 
 
209
   --
 
210
   -- Entity_Specification
 
211
   --
 
212
 
 
213
   type Entity_Specification (Is_Box : Boolean := False) is
 
214
      record
 
215
         case Is_Box is
 
216
            when True =>
 
217
               null;
 
218
            when False =>
 
219
               Is_All        : Boolean;
 
220
               Specification : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
 
221
         end case;
 
222
      end record;
 
223
 
 
224
   --
 
225
   -- Context
 
226
   --
 
227
 
 
228
   --  This way of defining No_Matching_Context ensures that it cannot
 
229
   --  be used for anything else than comparisons.
 
230
   type Not_Found_Context is new Rule_Context with null record;
 
231
   No_Matching_Context : constant Rule_Context'Class
 
232
     := Not_Found_Context'(null record);
 
233
 
 
234
   --
 
235
   -- Context_Store
 
236
   --
 
237
 
 
238
   type Context_Access is access Rule_Context'Class;
 
239
   type Context_Node;
 
240
   type Context_Node_Access is access Context_Node;
 
241
   type Context_Node is
 
242
      record
 
243
         Value : Context_Access;
 
244
         Next  : Context_Node_Access;
 
245
      end record;
 
246
   package Context_Tree is new Binary_Map
 
247
     (Key_Type   => Unbounded_Wide_String,
 
248
      Value_Type => Context_Node_Access);
 
249
 
 
250
   type Auto_Pointer (Self : access Context_Store) is limited null record;
 
251
   -- Rosen trick strikes again...
 
252
 
 
253
   type Context_Store is
 
254
      record
 
255
         This             : Auto_Pointer (Context_Store'access);
 
256
         Simple_Names     : Context_Tree.Map;
 
257
         Qualified_Names  : Context_Tree.Map;
 
258
         Default          : Context_Node_Access;
 
259
         Last_Returned    : Context_Node_Access;
 
260
         Last_Name        : Unbounded_Wide_String;
 
261
      end record;
 
262
 
 
263
end Framework;