46
47
Framework.Language,
47
Framework.Rules_Manager,
49
48
Framework.Scope_Manager;
50
49
pragma Elaborate (Framework.Language);
52
51
package body Rules.Local_Hiding is
53
use Framework, Utilities;
52
use Framework, Framework.Control_Manager, Utilities;
56
55
-- This rule is quite easy, since most of the work is done by Scoped_Store
63
61
-- is already the procedure itself, but the name must be attached to where the procedure is declared,
64
62
-- i.e. the enclosing scope.
66
type Subrules is (Strict, Overloading, Both);
67
subtype True_Subrules is Subrules range Strict .. Overloading;
68
package Subrules_Flag_Utilities is new Framework.Language.Flag_Utilities (Subrules);
70
type Rule_Usage is array (True_Subrules) of Boolean;
64
type Extended_Subrules is (Strict, Overloading, Overloading_Short);
65
subtype Subrules is Extended_Subrules range Extended_Subrules'First .. Extended_Subrules'Pred (Overloading_Short);
66
package Subrules_Flag_Utilities is new Framework.Language.Flag_Utilities (Extended_Subrules);
68
type Modifiers is (Not_Operator, Not_Enumeration);
69
package Modifiers_Flag_Utilities is new Framework.Language.Modifier_Utilities (Modifiers);
71
type Rule_Usage is array (Subrules) of Boolean;
71
72
Not_Used : constant Rule_Usage := (others => False);
73
74
Rule_Used : Rule_Usage := Not_Used;
74
75
Save_Used : Rule_Usage;
75
Rule_Context : array (True_Subrules) of Basic_Rule_Context;
76
Rule_Context : array (Subrules) of Basic_Rule_Context;
78
Include_Op : Rule_Usage;
79
Include_Enum : Rule_Usage;
80
Overloading_Is_Short : Boolean;
77
82
type Identifier_Data (Length : Positive) is
79
Name : Wide_String (1..Length);
80
Short_Last : Positive;
82
Is_Callable : Boolean;
84
Name : Wide_String (1..Length);
85
Short_Last : Positive;
87
Is_Callable : Boolean;
88
Is_Enumeration : Boolean;
84
90
procedure Clear (Item : in out Identifier_Data) is -- null proc
85
91
pragma Unreferenced (Item);
96
use Subrules_Flag_Utilities;
102
use Subrules_Flag_Utilities, Modifiers_Flag_Utilities;
98
104
User_Message ("Rule: " & Rule_Id);
99
Help_On_Flags ("Parameter(s): ", Footer => "(default = strict)");
100
User_Message ("Control occurrences of local identifiers that hide an outer identical name");
105
Help_On_Flags ("Parameter(s): <exceptions> ", Footer => "(default = strict)");
106
Help_On_Modifiers ("<exceptions>:");
107
User_Message ("Control occurrences of local identifiers that hide or overload an identical name");
103
110
-----------------
105
112
-----------------
107
114
procedure Add_Control (Ctl_Label : in Wide_String; Ctl_Kind : in Control_Kinds) is
108
use Framework.Language, Subrules_Flag_Utilities;
115
use Framework.Language, Subrules_Flag_Utilities, Modifiers_Flag_Utilities;
116
Subrule : Extended_Subrules;
117
Modif_Specified : Modifier_Set;
111
119
if Parameter_Exists then
112
120
while Parameter_Exists loop
121
Modif_Specified := Get_Modifier_Set;
113
122
Subrule := Get_Flag_Parameter (Allow_Any => False);
115
when True_Subrules =>
116
if Rule_Used (Subrule) then
117
Parameter_Error (Rule_Id, "subrule already specified");
119
Rule_Used (Subrule) := True;
120
Rule_Context (Subrule) := Basic.New_Context (Ctl_Kind, Ctl_Label);
122
if Rule_Used /= (True_Subrules => False) then
123
Parameter_Error (Rule_Id, "subrule already specified");
125
Rule_Used := (others => True);
126
Rule_Context := (others => Basic.New_Context (Ctl_Kind, Ctl_Label));
125
Overloading_Is_Short := False;
126
when Overloading_Short =>
127
Subrule := Overloading;
128
Overloading_Is_Short := True;
132
if Rule_Used (Subrule) then
133
Parameter_Error (Rule_Id, "subrule already specified");
135
Rule_Used (Subrule) := True;
136
Rule_Context (Subrule) := Basic.New_Context (Ctl_Kind, Ctl_Label);
137
Include_Op (Subrule) := not Modif_Specified (Not_Operator);
138
Include_Enum (Subrule) := not Modif_Specified (Not_Enumeration);
130
141
Rule_Used (Strict) := True;
131
142
Rule_Context (Strict) := Basic.New_Context (Ctl_Kind, Ctl_Label);
143
Include_Op (Strict) := True;
226
238
end Enclosing_Scope;
228
Short_Name : constant Wide_String := To_Upper (Defining_Name_Image (Name));
229
Full_Name : constant Wide_String := Short_Name & To_Upper (Profile_Image (Name, With_Profile => False));
230
Callable_Name : constant Boolean := Is_Callable_Construct (Name);
231
Is_Scope_Name : constant Boolean := Is_Equal (Enclosing_Scope (Name), Current_Scope);
240
Short_Name : constant Wide_String := To_Upper (Defining_Name_Image (Name));
241
Full_Name : constant Wide_String := Short_Name & To_Upper (Profile_Image (Name, With_Profile => False));
242
Callable_Name : constant Boolean := Is_Callable_Construct (Name);
243
Is_Enumeration : constant Boolean := Declaration_Kind (Enclosing_Element (Name))
244
= An_Enumeration_Literal_Specification;
245
Is_Scope_Name : constant Boolean := Is_Equal (Enclosing_Scope (Name), Current_Scope);
232
246
-- Is_Scope_Name is True if Name is the defining name for the current scope
233
247
-- => it belongs to the enclosing scope
234
Already_There : Boolean;
248
Already_There : Boolean;
249
Overload_Count : Natural := 0;
250
Overload_Last : Asis.Element;
236
252
type Hiding_Kinds is (Hides, Overloads, Not_Hiding);
237
253
function Hiding_Kind (Check : Identifier_Data) return Hiding_Kinds is
276
292
case Hiding_Kind (Visible_Identifiers.Current_Data) is
278
if Rule_Used (Strict) then
294
if Rule_Used (Strict)
295
and (Include_Op (Strict) or Short_Name (1) /= '"')
296
and (Include_Enum (Strict)
297
or not Is_Enumeration or not Visible_Identifiers.Current_Data.Is_Enumeration)
280
300
Rule_Context (Strict),
281
301
Get_Location (Name),
284
304
& Image (Get_Location (Visible_Identifiers.Current_Data.Elem)));
286
306
when Overloads =>
287
if Rule_Used (Overloading) then
289
Rule_Context (Overloading),
291
'"' & Framework.Language.Adjust_Image (To_Title (Full_Name))
292
& """ overloads declaration at "
293
& Image (Get_Location (Visible_Identifiers.Current_Data.Elem)));
307
if Rule_Used (Overloading)
308
and (Include_Op (Overloading) or Short_Name (1) /= '"')
309
and (Include_Enum (Overloading)
310
or not Is_Enumeration or not Visible_Identifiers.Current_Data.Is_Enumeration)
312
if Overloading_Is_Short then
313
Overload_Count := Overload_Count + 1;
314
Overload_Last := Visible_Identifiers.Current_Data.Elem;
317
Rule_Context (Overloading),
319
'"' & Framework.Language.Adjust_Image (To_Title (Full_Name))
320
& """ overloads declaration at "
321
& Image (Get_Location (Visible_Identifiers.Current_Data.Elem)));
295
324
when Not_Hiding =>
299
328
Visible_Identifiers.Next;
331
if Overload_Count /= 0 then
332
-- Short form of reports of overloading, issued after the loop
334
Rule_Context (Overloading),
336
'"' & Framework.Language.Adjust_Image (To_Title (Full_Name))
338
& Integer_Img (Overload_Count)
339
& " declaration(s), last at "
340
& Image (Get_Location (Overload_Last)));
303
344
if not Already_There then
307
348
Visible_Identifiers.Push_Enclosing ((Full_Name'Length,
309
350
Short_Name'Length,
352
Is_Callable => Callable_Name,
353
Is_Enumeration => Is_Enumeration));
313
355
Visible_Identifiers.Push ((Full_Name'Length,
315
357
Short_Name'Length,
359
Is_Callable => Callable_Name,
360
Is_Enumeration => Is_Enumeration));
359
402
Short_Name'Length,
361
Is_Callable_Construct (Name)));
404
Is_Callable => Is_Callable_Construct (Name),
405
Is_Enumeration => False));
363
407
exit when Expression_Kind (Current) = An_Identifier;
364
408
Current := Prefix (Current);