1
----------------------------------------------------------------------
2
-- Rules.Real_Operators - 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;
50
Framework.Rules_Manager,
53
package body Rules.Real_Operators is
56
Rule_Used : Boolean := False;
58
Rule_Type : Rule_Types;
59
Rule_Label : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
68
User_Message ("Rule: " & Rule_Id);
69
User_Message ("Parameter(s): None");
70
User_Message ("Control occurrences of = or /= operators with real types");
77
procedure Add_Use (Label : in Wide_String;
78
Rule_Use_Type : in Rule_Types) is
79
use Ada.Strings.Wide_Unbounded;
80
use Framework.Language;
83
if Parameter_Exists then
84
Parameter_Error ("No parameter for rule " & Rule_Id);
88
Parameter_Error (Rule_Id & ": this rule can be specified only once");
90
Rule_Type := Rule_Use_Type;
91
Rule_Label := To_Unbounded_Wide_String (Label);
100
procedure Command (Action : Framework.Rules_Manager.Rule_Action) is
101
use Framework.Rules_Manager;
107
Save_Used := Rule_Used;
110
Rule_Used := Save_Used;
114
---------------------------
115
-- Process_Function_Call --
116
---------------------------
118
procedure Process_Function_Call (Call : in Asis.Expression) is
119
use Ada.Strings.Wide_Unbounded, Asis, Asis.Elements,
120
Asis.Expressions, Framework.Reports, Thick_Queries;
122
if not Rule_Used then
125
Rules_Manager.Enter (Rule_Id);
127
-- Ruler calls us for all operators. Check type of operator.
128
case Operator_Kind (Prefix (Call)) is
129
when An_Equal_Operator
130
| A_Not_Equal_Operator
132
-- Now check the context in which the operator is used and report
133
-- errors according to the following rules
135
-- 1) if the left parameter is not universal, print the message
138
-- 2) elsif the right parameter is not universal, print the message
141
-- 3) else we must be in a context like: if 0.0 = 1.0 theni ....
144
Parsed_First_Parameter : Boolean := False;
145
F : constant Asis.Association_List := Function_Call_Parameters (Call);
147
Parameter_Loop: for I in F'RANGE loop
149
P : constant Asis.Expression := Actual_Parameter (F (I));
150
T : constant Asis.Declaration := Ultimate_Expression_Type (P);
152
case Type_Kind (T) is
153
when A_Root_Type_Definition =>
154
case Root_Type_Kind (T) is
155
when A_Root_Real_Definition => -- 3.4.1(8)
158
To_Wide_String (Rule_Label),
161
"equality or inequality with Root Real !!!");
162
when A_Universal_Real_Definition => -- 3.4.1(6)
163
if Parsed_First_Parameter then
166
To_Wide_String (Rule_Label),
169
"equality or inequality with two Universal Real constants !!!");
171
Parsed_First_Parameter := True;
176
when A_Floating_Point_Definition => -- 3.5.7(2)
179
To_Wide_String (Rule_Label),
182
"equality or inequality with Floating Point");
184
when An_Ordinary_Fixed_Point_Definition => -- 3.5.9(3)
187
To_Wide_String (Rule_Label),
190
"equality or inequality with Binary Fixed Point");
192
when A_Decimal_Fixed_Point_Definition => -- 3.5.9(4)
195
To_Wide_String (Rule_Label),
198
"equality or inequality with Decimal Fixed Point");
204
end loop Parameter_Loop;
208
-- Including Not_An_Operator
211
end Process_Function_Call;
214
Framework.Rules_Manager.Register (Rule_Id,
216
Add_Use => Add_Use'Access,
217
Command => Command'Access);
218
end Rules.Real_Operators;