47
48
Framework.Language,
48
49
Framework.Rules_Manager,
51
Framework.Scope_Manager;
50
52
pragma Elaborate (Framework.Language);
51
53
package body Rules.Declarations is
54
type Declaration_Names is (D_Access_Protected_Type, D_Access_Subprogram_Type, D_Access_Task_Type,
55
D_Access_Type, D_Aliased, D_Array,
56
D_Array_Type, D_Child_Unit, D_Constant,
57
D_Constrained_Array_Type, D_Decimal_Fixed_Type, D_Defaulted_Discriminant,
58
D_Defaulted_Generic_Parameter, D_Defaulted_Parameter, D_Derived_Type,
59
D_Discriminant, D_Enumeration_Type, D_Entry,
60
D_Exception, D_Extension, D_Fixed_Type,
61
D_Float_Type, D_Formal_Function, D_Formal_In_Out,
62
D_Formal_Package, D_Formal_Procedure, D_Generic,
63
D_Handlers, D_Integer_Type, D_Modular_Type,
64
D_Multiple_Names, D_Named_Number, D_Not_Operator_Renames,
65
D_Null_Extension, D_Null_Ordinary_Record_Type, D_Null_Tagged_Type,
66
D_Operator, D_Ordinary_Fixed_Type, D_Ordinary_Record_Type,
67
D_Package_Statements, D_Protected, D_Protected_Entry,
68
D_Protected_Type, D_Record_Type, D_Renames,
69
D_Separate, D_Signed_Type, D_Single_Array,
70
D_Single_Protected, D_Single_Task, D_Subtype,
71
D_Tagged_Type, D_Task, D_Task_Entry,
72
D_Task_Type, D_Type, D_Unconstrained_Array_Type);
56
type Declaration_Names is (D_Access_Protected_Type, D_Access_Subprogram_Type, D_Access_Task_Type,
57
D_Access_Type, D_Aliased, D_Array,
58
D_Array_Type, D_Child_Unit, D_Constant,
59
D_Constrained_Array_Type, D_Decimal_Fixed_Type, D_Defaulted_Discriminant,
60
D_Defaulted_Generic_Parameter, D_Defaulted_Parameter, D_Derived_Type,
61
D_Discriminant, D_Enumeration_Type, D_Entry,
62
D_Exception, D_Extension, D_Fixed_Type,
63
D_Float_Type, D_Formal_Function, D_Formal_Package,
64
D_Formal_Procedure, D_Generic, D_Handlers,
65
D_In_Out_Generic_Parameter, D_In_Out_Parameter, D_Initialized_Record_Field,
66
D_Initialized_Protected_Field, D_Integer_Type, D_Limited_Private_Type,
67
D_Modular_Type, D_Multiple_Names, D_Named_Number,
68
D_Nested_Package, D_Nested_Generic_Function, D_Nested_Generic_Package,
69
D_Nested_Generic_Procedure, D_Nested_Function_Instantiation,
70
D_Nested_Package_Instantiation, D_Nested_Procedure_Instantiation,
71
D_Non_Identical_Renaming, D_Non_Limited_Private_Type, D_Not_Operator_Renaming,
72
D_Null_Extension, D_Null_Ordinary_Record_Type, D_Null_Tagged_Type,
73
D_Operator, D_Operator_Renaming, D_Ordinary_Fixed_Type,
74
D_Ordinary_Record_Type, D_Out_Parameter, D_Package_Statements,
75
D_Private_Extension, D_Protected, D_Protected_Entry,
76
D_Protected_Type, D_Record_Type, D_Renaming,
77
D_Separate, D_Signed_Type, D_Single_Array,
78
D_Single_Protected , D_Single_Task, D_Subtype,
79
D_Tagged_Type, D_Task, D_Task_Entry,
80
D_Task_Type, D_Type, D_Unconstrained_Array_Type,
81
D_Uninitialized_Record_Field, D_Uninitialized_Protected_Field);
73
82
type Declaration_Names_List is array (Positive range <>) of Declaration_Names;
75
84
package Usage_Flags_Utilities is new Framework.Language.Flag_Utilities (Declaration_Names, "D_");
367
388
Do_Report ((D_Array, D_Single_Array), Get_Location (Element));
391
when A_Component_Declaration =>
392
if Definition_Kind (Enclosing_Element (Element)) = A_Protected_Definition then
393
if Is_Nil (Initialization_Expression (Element)) then
394
Do_Report (D_Uninitialized_Protected_Field, Get_Location (Element));
396
Do_Report (D_Initialized_Protected_Field, Get_Location (Element));
399
if Is_Nil (Initialization_Expression (Element)) then
400
Do_Report (D_Uninitialized_Record_Field, Get_Location (Element));
402
Do_Report (D_Initialized_Record_Field, Get_Location (Element));
370
406
when A_Parameter_Specification =>
371
if not Is_Nil (Initialization_Expression (Element)) then
372
Do_Report (D_Defaulted_Parameter, Get_Location (Element));
407
-- Do not print message if the parameter is for a procedure or function body
408
-- with an explicit specification
409
Enclosing := Enclosing_Element (Element);
410
if Declaration_Kind (Enclosing) not in A_Procedure_Body_Declaration .. A_Function_Body_Declaration
411
or else Is_Nil (Corresponding_Declaration (Enclosing))
413
if not Is_Nil (Initialization_Expression (Element)) then
414
Do_Report (D_Defaulted_Parameter, Get_Location (Element));
417
case Mode_Kind (Element) is
419
Do_Report (D_Out_Parameter, Get_Location (Element));
420
when An_In_Out_Mode =>
421
Do_Report (D_In_Out_Parameter, Get_Location (Element));
375
427
when A_Formal_Object_Declaration =>
437
494
when An_Exception_Declaration =>
438
495
Do_Report (D_Exception, Get_Location (Element));
440
when A_Generic_Declaration =>
441
Do_Report (D_Generic, Get_Location (Element));
497
when A_Generic_Function_Declaration =>
498
if Current_Depth /= 1 then
499
Do_Report ((D_Generic, D_Nested_Generic_Function), Get_Location (Element));
501
Do_Report (D_Generic, Get_Location (Element));
504
when A_Generic_Package_Declaration =>
505
if Current_Depth /= 1 then
506
Do_Report ((D_Generic, D_Nested_Generic_Package), Get_Location (Element));
508
Do_Report (D_Generic, Get_Location (Element));
511
when A_Generic_Procedure_Declaration =>
512
if Current_Depth /= 1 then
513
Do_Report ((D_Generic, D_Nested_Generic_Procedure), Get_Location (Element));
515
Do_Report (D_Generic, Get_Location (Element));
518
when A_Function_Instantiation =>
519
if Current_Depth /= 1 then
520
Do_Report (D_Nested_Function_Instantiation, Get_Location (Element));
523
when A_Package_Instantiation =>
524
if Current_Depth /= 1 then
525
Do_Report (D_Nested_Package_Instantiation, Get_Location (Element));
528
when A_Procedure_Instantiation =>
529
if Current_Depth /= 1 then
530
Do_Report (D_Nested_Procedure_Instantiation, Get_Location (Element));
443
533
when A_Body_Stub =>
444
534
Do_Report (D_Separate, Get_Location (Element));
446
536
when A_Function_Renaming_Declaration
447
537
| A_Generic_Function_Renaming_Declaration
449
if Rule_Used (D_Not_Operator_Renames) then
450
Renamed_Func := Renamed_Entity (Element);
451
if Expression_Kind (Renamed_Func) = A_Selected_Component then
452
Renamed_Func := Selector (Renamed_Func);
454
if Expression_Kind (Renamed_Func) /= An_Operator_Symbol then
455
Do_Report (D_Not_Operator_Renames, Get_Location (Element));
539
Do_Report (D_Renaming, Get_Location (Element));
541
if Rule_Used (D_Not_Operator_Renaming)
542
or Rule_Used (D_Non_Identical_Renaming)
543
or Rule_Used (D_Operator_Renaming)
545
Renamed_Entity := A4G_Bugs.Renamed_Entity (Element);
546
if Expression_Kind (Renamed_Entity) = A_Selected_Component then
547
Renamed_Entity := Selector (Renamed_Entity);
550
case Expression_Kind (Renamed_Entity) is
551
when An_Explicit_Dereference
552
| An_Attribute_Reference
553
| A_Character_Literal
555
Do_Report (D_Not_Operator_Renaming, Get_Location (Element));
556
-- Cannot be identical name
557
Do_Report (D_Non_Identical_Renaming, Get_Location (Element));
558
when An_Operator_Symbol =>
559
Do_Report (D_Operator_Renaming, Get_Location (Element));
560
if To_Upper (Defining_Name_Image (Names (Element) (1)))
561
/= To_Upper (Name_Image (Renamed_Entity))
563
Do_Report (D_Non_Identical_Renaming, Get_Location (Element));
566
| An_Enumeration_Literal
568
Do_Report (D_Not_Operator_Renaming, Get_Location (Element));
569
if To_Upper (Defining_Name_Image (Names (Element) (1)))
570
/= To_Upper (Name_Image (Renamed_Entity))
572
Do_Report (D_Non_Identical_Renaming, Get_Location (Element));
575
Failure ("Not a function name in function renaming");
458
Do_Report (D_Renames, Get_Location (Element));
460
579
when An_Object_Renaming_Declaration
461
580
| An_Exception_Renaming_Declaration
464
583
| A_Generic_Package_Renaming_Declaration
465
584
| A_Generic_Procedure_Renaming_Declaration
467
if Rule_Used (D_Not_Operator_Renames) then
468
Do_Report (D_Not_Operator_Renames, Get_Location (Element));
470
Do_Report (D_Renames, Get_Location (Element));
586
if Rule_Used (D_Not_Operator_Renaming) then
587
Do_Report (D_Not_Operator_Renaming, Get_Location (Element));
589
if Rule_Used (D_Non_Identical_Renaming) then
590
Renamed_Entity := A4G_Bugs.Renamed_Entity (Element);
592
case Expression_Kind (Renamed_Entity) is
593
when An_Explicit_Dereference
594
| An_Indexed_Component
596
| An_Attribute_Reference
598
| A_Character_Literal
601
Do_Report (D_Non_Identical_Renaming, Get_Location (Element));
603
when A_Selected_Component =>
604
Renamed_Entity := Selector (Renamed_Entity);
605
when A_Type_Conversion =>
606
Renamed_Entity := Converted_Or_Qualified_Expression (Renamed_Entity);
607
when An_Identifier | An_Operator_Symbol | An_Enumeration_Literal =>
608
if To_Upper (Defining_Name_Image (Names (Element)(1))) /= To_Upper (Name_Image (Renamed_Entity))
610
Do_Report (D_Non_Identical_Renaming, Get_Location (Element));
614
Failure ("Not a name in renaming");
618
Do_Report (D_Renaming, Get_Location (Element));
472
620
when A_Formal_Function_Declaration =>
473
621
Do_Report (D_Formal_Function, Get_Location (Element));