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-2008. 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
33private with
34  Ada.Strings.Wide_Unbounded;
35
36-- ASIS
37with
38  Asis,
39  Asis.Text;
40
41-- Adactl
42with
43  Adactl_Constants;
44package Framework is
45   use Adactl_Constants;
46
47   -------------------------------------------------------------------
48   -- The ASIS context                                              --
49   -------------------------------------------------------------------
50
51   Adactl_Context : aliased Asis.Context;
52
53   -------------------------------------------------------------------
54   --  General types for rules                                      --
55   -------------------------------------------------------------------
56
57   type Control_Index is range 0 ..  Max_Controls_For_Rule;
58   type Control_Index_Set is array (Control_Index range 1 .. Max_Controls_Set) of Boolean; -- Purposedly limited
59   pragma Pack (Control_Index_Set);
60   Empty_Control_Index_Set : constant Control_Index_Set := (others => False);
61
62   type Control_Kinds is (Check, Search, Count);
63   type Control_Kinds_Set is array (Control_Kinds) of Boolean;
64   pragma Pack (Control_Kinds_Set);
65   Empty_Control_Kinds_Set : constant Control_Kinds_Set := (others => False);
66
67   type Uncheckable_Kinds is (False_Positive, False_Negative, Missing_Unit);
68   subtype Uncheckable_Consequence is Uncheckable_Kinds range False_Positive .. False_Negative;
69
70   type Matching_Extension is (Instance, Renaming);
71   type Extension_Set is array (Matching_Extension) of Boolean;
72   No_Extension   : constant Extension_Set := (others => False);
73   All_Extensions : constant Extension_Set := (others => True);
74
75   -------------------------------------------------------------------
76   --  Location                                                     --
77   -------------------------------------------------------------------
78
79   -- A location is the position of an element in a file
80
81   type Location is private;
82   Null_Location : constant Location;
83
84   type Search_Start is (From_Head, From_Tail);
85
86   function Create_Location (File         : in Wide_String;
87                             First_Line   : in Asis.Text.Line_Number;
88                             First_Column : in Asis.Text.Character_Position) return Location;
89   function Get_Location (E : in Asis.Element) return Location;
90   -- Returns location of an element
91
92   function Get_End_Location (E : in Asis.Element) return Location;
93   -- Returns location of end of an element
94
95   function Get_Previous_Word_Location (E        : in Asis.Element;
96                                        Matching : Wide_String := "";
97                                        Starting : Search_Start := From_Head)
98                                        return Location;
99   -- Returns the location of the first "word" (identifier of keyword) that immediately
100   -- precedes the beginning of E (if Starting = From_Head) or the end of E (if Starting = From_Tail).
101   -- If Matching is specified, returns the location of the first word identical to Matching
102   -- Matching must be given in upper-case
103
104   function Get_Previous_Word_Location (L        : in Asis.Element_List;
105                                        Matching : Wide_String := "";
106                                        Starting : Search_Start := From_Head)
107                                        return Location;
108   -- Returns the location of the first "word" (identifier of keyword) that immediately
109   -- precedes the beginning of the first element of E (if Starting = From_Head)
110   -- or the end of the last element of E (if Starting = From_Tail).
111   -- If Matching is specified, returns the location of the first word identical to Matching
112   -- Matching must be given in upper-case
113
114   function Get_Next_Word_Location (E        : in Asis.Element;
115                                    Matching : Wide_String := "";
116                                    Starting : Search_Start := From_Tail)
117                                    return Location;
118   -- Returns the location of the first "word" (identifier of keyword) that immediately
119   -- follows the beginning of E (if Starting = From_Head) or the end of E (if Starting = From_Tail).
120   -- If Matching is specified, returns the location of the first word identical to Matching
121   -- Matching must be given in upper-case
122
123   function Get_Next_Word_Location (L        : in Asis.Element_List;
124                                    Matching : Wide_String := "";
125                                    Starting : Search_Start := From_Tail)
126                                    return Location;
127   -- Returns the location of the first "word" (identifier of keyword) that immediately
128   -- follows the beginning of the first element of E (if Starting = From_Head)
129   -- or the end of the last element of E (if Starting = From_Tail).
130   -- If Matching is specified, returns the location of the first word identical to Matching
131   -- Matching must be given in upper-case
132   -- Precondition: L is not empty
133
134   function Get_File_Name (L : in Location) return Wide_String;
135   -- Returns location file name
136
137   function Get_First_Line (L : in Location) return Asis.Text.Line_Number;
138   -- Returns location first line
139
140   function Get_First_Column (L : in Location) return Asis.Text.Character_Position;
141   -- Returns location first column
142
143   Short_Name : Boolean := False;
144   function Image (L          : in Location;
145                   Separator  : in Wide_Character := ':';
146                   Quoted     : in Boolean        := False)
147                   return Wide_String;
148   -- Returns image of a location
149   -- i.e. file:1:1
150   -- If Short_Name = True, strip File name from any path
151   -- Separator: character used to separate file name, lines and cols
152   -- Fails if L = Null_Location
153
154   function Safe_Image (L          : in Location;
155                        Separator  : in Wide_Character := ':')
156                        return Wide_String;
157   -- Like Image, but returns the string "unknown location" if L = Null_Location
158
159
160   function Value (S : in Wide_String) return Location;
161   -- Returns location value of a string
162   -- raises Constraint_Error for an incorrect input string
163
164
165   -------------------------------------------------------------------
166   --  Entity_Specification                                         --
167   -------------------------------------------------------------------
168
169   -- An Entity_Specification is the structure that corresponds to
170   -- the specification of an Ada entity in the command language
171
172   type Entity_Specification is private;
173   type Entity_Specification_Kinds is (Box, Equal, Regular_Id, All_Id);
174   type Entity_Specification_List is array (Asis.List_Index range <>) of Entity_Specification;
175
176   function Entity_Specification_Kind (Entity : in Entity_Specification) return Entity_Specification_Kinds;
177
178   function Image   (Entity : in Entity_Specification) return Wide_String;
179   function Value   (Name   : in Wide_String)          return Entity_Specification;
180   -- (pseudo) entity specification corresponding to a string
181   -- Name can be in any case
182
183   function Matches (Entity    : in Entity_Specification;
184                     Name      : in Asis.Element;
185                     Extend_To : in Extension_Set := No_Extension) return Boolean;
186   -- Appropriate element kinds for Matches:
187   --   like Matching_Context, see Framework.Control_Manager
188
189private
190   use Ada.Strings.Wide_Unbounded;
191
192   --
193   -- Location
194   --
195
196   type Location is record
197      File_Name    : Unbounded_Wide_String;
198      First_Line   : Asis.Text.Line_Number        := 0;
199      First_Column : Asis.Text.Character_Position := 0;
200   end record;
201   Null_Location : constant Location := (Null_Unbounded_Wide_String, 0, 0);
202
203
204   --
205   -- Entity_Specification
206   --
207
208   type Entity_Specification (Kind : Entity_Specification_Kinds := Regular_Id) is
209      record
210         case Kind is
211            when Box | Equal =>
212               null;
213            when Regular_Id | All_Id =>
214               Specification : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
215         end case;
216      end record;
217
218end Framework;
219