1
----------------------------------------------------------------------
2
-- Rules.Declaration - Package body --
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. --
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. --
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 --
30
----------------------------------------------------------------------
34
Ada.Strings.Wide_Unbounded;
48
Framework.Rules_Manager,
51
package body Rules.Declaration is
54
type Declaration_Names is (Decl_Access, Decl_Access_Subprogram, Decl_Aliased,
55
Decl_Exception, Decl_Tagged, Decl_Task);
61
function Image (Stmt : Declaration_Names) return Wide_String is
63
Img : constant Wide_String := To_Lower (Declaration_Names'Wide_Image (Stmt));
66
return Img (6 .. Img'Last);
69
type Usage_Flags is array (Declaration_Names) of Boolean;
70
Rule_Used : Usage_Flags := (others => False);
71
Save_Used : Usage_Flags;
72
Usage : array (Declaration_Names) of Simple_Context;
81
User_Message ("Rule: " & Rule_Id);
82
User_Message ("Parameter(s): access | access_subprogram | aliased | exception | tagged | task");
83
User_Message ("Control occurrences of Ada declarations");
90
procedure Add_Use (Label : in Wide_String;
91
Rule_Type : in Rule_Types) is
92
use Ada.Strings.Wide_Unbounded;
93
use Framework.Language;
94
Decl : Declaration_Names;
96
function Get_Declaration_Parameter is new Get_Flag_Parameter (Flags => Declaration_Names,
100
if not Parameter_Exists then
101
Parameter_Error ("At least one parameter required for rule " & Rule_Id);
104
while Parameter_Exists loop
105
Decl := Get_Declaration_Parameter;
106
if Rule_Used (Decl) then
107
Parameter_Error ("Declaration already given for rule " & Rule_Id
108
& ": " & Image (Decl));
111
Rule_Used (Decl) := True;
112
Usage (Decl) := (Rule_Type, To_Unbounded_Wide_String (Label));
120
procedure Command (Action : Framework.Rules_Manager.Rule_Action) is
121
use Framework.Rules_Manager;
125
Rule_Used := (others => False);
127
Save_Used := Rule_Used;
128
Rule_Used := (others => False);
130
Rule_Used := Save_Used;
134
-------------------------
135
-- Process_Declaration --
136
-------------------------
138
procedure Process_Declaration (Element : in Asis.Declaration) is
139
use Ada.Strings.Wide_Unbounded, Asis, Asis.Elements, Asis.Declarations, Framework.Reports;
140
Decl : Declaration_Names;
142
if Rule_Used = (Declaration_Names => False) then
145
Rules_Manager.Enter (Rule_Id);
147
case Declaration_Kind (Element) is
148
when An_Ordinary_Type_Declaration =>
149
case Type_Kind (Type_Declaration_View (Element)) is
150
when An_Access_Type_Definition =>
151
case Access_Type_Kind (Type_Declaration_View (Element)) is
152
when Access_To_Subprogram_Definition =>
153
if Rule_Used (Decl_Access_Subprogram) then
154
Decl := Decl_Access_Subprogram;
162
when A_Tagged_Record_Type_Definition =>
169
when A_Variable_Declaration
170
| A_Constant_Declaration =>
171
case Trait_Kind (Element) is
172
when An_Aliased_Trait =>
173
Decl := Decl_Aliased;
178
when A_Task_Type_Declaration =>
181
when A_Single_Task_Declaration =>
184
when An_Exception_Declaration =>
185
Decl := Decl_Exception;
191
if not Rule_Used (Decl) then
196
To_Wide_String (Usage(Decl).Rule_Label),
197
Usage (Decl).Rule_Type,
198
Get_Location (Element),
199
"use of declaration """ & Image (Decl) & '"');
200
end Process_Declaration;
203
Framework.Rules_Manager.Register (Rule_Id,
205
Add_Use => Add_Use'Access,
206
Command => Command'Access);
207
end Rules.Declaration;