OSDN Git Service

2007-09-10 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_warn.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S E M _ W A R N                              --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1999-2007, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 --  This package contains the routines used to deal with issuing warnings
27 --  about uses of uninitialized variables and unused with's. It also has
28 --  some unrelated routines related to the generation of warnings.
29
30 with Types; use Types;
31
32 package Sem_Warn is
33
34    --------------------
35    -- Initialization --
36    --------------------
37
38    function Set_Warning_Switch (C : Character) return Boolean;
39    --  This function sets the warning switch or switches corresponding to the
40    --  given character. It is used to process a -gnatw switch on the command
41    --  line, or a character in a string literal in pragma Warnings. Returns
42    --  True for valid warning character C, False for invalid character.
43
44    function Set_Dot_Warning_Switch (C : Character) return Boolean;
45    --  This function sets the warning switch or switches corresponding to the
46    --  given character preceded by a dot. Used to process a -gnatw. switch on
47    --  the command line or .C in a string literal in pragma Warnings. Returns
48    --  True for valid warning character C, False for invalid character.
49
50    ------------------------------------------
51    -- Routines to Handle Unused References --
52    ------------------------------------------
53
54    procedure Check_References (E : Entity_Id; Anod : Node_Id := Empty);
55    --  Called at the end of processing a declarative region. The entity E
56    --  is the entity for the scope. All entities declared in the region,
57    --  as indicated by First_Entity and the entity chain, are checked to
58    --  see if they are variables for which warnings need to be posted for
59    --  either no assignments, or a use before an assignment or no references
60    --  at all. The Anod node is present for the case of an accept statement,
61    --  and references the accept statement. This is used to place the warning
62    --  messages in the right place.
63
64    procedure Check_Unset_Reference (N : Node_Id);
65    --  N is the node for an expression which occurs in a reference position,
66    --  e.g. as the right side of an assignment. This procedure checks to see
67    --  if the node is a reference to a variable entity where the entity has
68    --  Not_Assigned set. If so, the Unset_Reference field is set if it is not
69    --  the first occurrence. No warning is posted, instead warnings will be
70    --  posted later by Check_References. The reason we do things that
71    --  way is that if there are no assignments anywhere, we prefer to flag
72    --  the entity, rather than a reference to it. Note that for the purposes
73    --  of this routine, a type conversion or qualified expression whose
74    --  expression is an entity is also processed. The reason that we do not
75    --  process these at the point of occurrence is that both these constructs
76    --  can occur in non-reference positions (e.g. as out parameters).
77
78    procedure Check_Unused_Withs (Spec_Unit : Unit_Number_Type := No_Unit);
79    --  This routine performs two kinds of checks. It checks that all with'ed
80    --  units are referenced, and that at least one entity of each with'ed
81    --  unit is referenced (the latter check catches units that are only
82    --  referenced in a use or package renaming statement). Appropriate
83    --  warning messages are generated if either of these situations is
84    --  detected.
85    --
86    --  A special case arises when a package body or a subprogram body with
87    --  a separate spec is being compiled. In this case, a with may appear
88    --  on the spec, but be needed only by the body. This still generates
89    --  a warning, but the text is different (the with is not redundant,
90    --  it is misplaced).
91    --
92    --  This special case is implemented by making an initial call to this
93    --  procedure with Spec_Unit set to the unit number of the separate spec.
94    --  This call does not generate any warning messages, but instead may
95    --  result in flags being set in the N_With_Clause node that record that
96    --  there was no use in the spec.
97    --
98    --  The main call (made after all units have been analyzed, with Spec_Unit
99    --  set to the default value of No_Unit) generates the required warnings
100    --  using the flags set by the initial call where appropriate to specialize
101    --  the text of the warning messages.
102
103    ---------------------
104    -- Output Routines --
105    ---------------------
106
107    procedure Output_Non_Modifed_In_Out_Warnings;
108    --  Warnings about IN OUT parameters that could be IN are collected till
109    --  the end of the compilation process (see body of this routine for a
110    --  discussion of why this is done). This procedure outputs the warnings.
111    --  Note: this should be called before Output_Unreferenced_Messages, since
112    --  if we have an IN OUT warning, that's the one we want to see!
113
114    procedure Output_Obsolescent_Entity_Warnings (N : Node_Id; E : Entity_Id);
115    --  N is a reference to obsolescent entity E, for which appropriate warning
116    --  messages are to be generated (caller has already checked that warnings
117    --  are active and appropriate for this entity).
118
119    procedure Output_Unreferenced_Messages;
120    --  Warnings about unreferenced entities are collected till the end of
121    --  the compilation process (see Check_Unset_Reference for further
122    --  details). This procedure outputs waiting warnings, if any.
123
124    ----------------------------
125    -- Other Warning Routines --
126    ----------------------------
127
128    procedure Check_Code_Statement (N : Node_Id);
129    --  Perform warning checks on a code statement node
130
131    procedure Check_Infinite_Loop_Warning (Loop_Statement : Node_Id);
132    --  N is the node for a loop statement. This procedure checks if a warning
133    --  should be given for a possible infinite loop, and if so issues it.
134
135    procedure Warn_On_Known_Condition (C : Node_Id);
136    --  C is a node for a boolean expression resluting from a relational
137    --  or membership operation. If the expression has a compile time known
138    --  value, then a warning is output if all the following conditions hold:
139    --
140    --    1. Original expression comes from source. We don't want to generate
141    --       warnings for internally generated conditionals.
142    --
143    --    2. As noted above, the expression is a relational or membership
144    --       test, we don't want to generate warnings for boolean variables
145    --       since this is typical of conditional compilation in Ada.
146    --
147    --    3. The expression appears in a statement, rather than a declaration.
148    --       In practice, most occurrences in declarations are legitimate
149    --       conditionalizations, but occurrences in statements are often
150    --       errors for which the warning is useful.
151    --
152    --    4. The expression does not occur within an instantiation. A non-
153    --       static expression in a generic may become constant because of
154    --       the attributes of the actuals, and we do not want to warn on
155    --       these legitimate constant foldings.
156    --
157    --  If all these conditions are met, the warning is issued noting that
158    --  the result of the test is always false or always true as appropriate.
159
160    procedure Warn_On_Suspicious_Index (Name : Entity_Id; X : Node_Id);
161    --  This is called after resolving an indexed component or a slice. Name
162    --  is the entity for the name of the indexed array, and X is the subscript
163    --  for the indexed component case, or one of the bounds in the slice case.
164    --  If Name is an unconstrained parameter of a standard string type, and
165    --  the index is of the form of a literal or Name'Length [- literal], then
166    --  a warning is generated that the subscripting operation is possibly
167    --  incorrectly assuming a lower bound of 1.
168
169    procedure Warn_On_Unassigned_Out_Parameter
170      (Return_Node : Node_Id;
171       Scope_Id    : Entity_Id);
172    --  Called when processing a return statement given by Return_Node. Scope_Id
173    --  is the Entity_Id for the procedure in which the return statement lives.
174    --  A check is made for the case of a procedure with out parameters that
175    --  have not yet been assigned, and appropriate warnings are given.
176
177    procedure Warn_On_Useless_Assignment
178      (Ent : Entity_Id;
179       Loc : Source_Ptr := No_Location);
180    --  Called to check if we have a case of a useless assignment to the given
181    --  entity Ent, as indicated by a non-empty Last_Assignment field. This call
182    --  should only be made if Warn_On_Modified_Unread is True, and if Ent is in
183    --  the extended main source unit. Loc is No_Location for the end of block
184    --  call (warning msg says value unreferenced), or the it is the location of
185    --  an overwriting assignment (warning msg points to this assignment).
186
187    procedure Warn_On_Useless_Assignments (E : Entity_Id);
188    pragma Inline (Warn_On_Useless_Assignments);
189    --  Called at the end of a block or subprogram. Scans the entities of the
190    --  block or subprogram to see if there are any variables for which useless
191    --  assignments were made (assignments whose values were never read).
192
193 end Sem_Warn;