OSDN Git Service

* sem_warn.adb: Remove stuff for conditionals, we are not going to
[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 --                            $Revision$
10 --                                                                          --
11 --          Copyright (C) 1999-2001 Free Software Foundation, Inc.          --
12 --                                                                          --
13 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- GNAT was originally developed  by the GNAT team at  New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 --                                                                          --
27 ------------------------------------------------------------------------------
28
29 --  This package contains the routines used to deal with issuing warnings
30 --  about uses of uninitialized variables and unused with's. It also has
31 --  some unrelated routines related to the generation of warnings.
32
33 with Types; use Types;
34
35 package Sem_Warn is
36
37    ------------------------------------------
38    -- Routines to Handle Unused References --
39    ------------------------------------------
40
41    procedure Check_References (E : Entity_Id; Anod : Node_Id := Empty);
42    --  Called at the end of processing a declarative region. The entity E
43    --  is the entity for the scope. All entities declared in the region,
44    --  as indicated by First_Entity and the entity chain, are checked to
45    --  see if they are variables for which warnings need to be posted for
46    --  either no assignments, or a use before an assignment or no references
47    --  at all. The Anod node is present for the case of an accept statement,
48    --  and references the accept statement. This is used to place the warning
49    --  messages in the right place.
50
51    procedure Check_Unset_Reference (N : Node_Id);
52    --  N is the node for an expression which occurs in a reference position,
53    --  e.g. as the right side of an assignment. This procedure checks to see
54    --  if the node is a reference to a variable entity where the entity has
55    --  Not_Assigned set. If so, the Unset_Reference field is set if it is not
56    --  the first occurrence. No warning is posted, instead warnings will be
57    --  posted later by Check_References. The reason we do things that
58    --  way is that if there are no assignments anywhere, we prefer to flag
59    --  the entity, rather than a reference to it. Note that for the purposes
60    --  of this routine, a type conversion or qualified expression whose
61    --  expression is an entity is also processed. The reason that we do not
62    --  process these at the point of occurrence is that both these constructs
63    --  can occur in non-reference positions (e.g. as out parameters).
64
65    procedure Check_Unused_Withs (Spec_Unit : Unit_Number_Type := No_Unit);
66    --  This routine performs two kinds of checks. It checks that all with'ed
67    --  units are referenced, and that at least one entity of each with'ed
68    --  unit is referenced (the latter check catches units that are only
69    --  referenced in a use or package renaming statement). Appropriate
70    --  warning messages are generated if either of these situations is
71    --  detected.
72    --
73    --  A special case arises when a package body or a subprogram body with
74    --  a separate spec is being compiled. In this case, a with may appear
75    --  on the spec, but be needed only by the body. This still generates
76    --  a warning, but the text is different (the with is not redundant,
77    --  it is misplaced).
78    --
79    --  This special case is implemented by making an initial call to this
80    --  procedure with Spec_Unit set to the unit number of the separate spec.
81    --  This call does not generate any warning messages, but instead may
82    --  result in flags being set in the N_With_Clause node that record that
83    --  there was no use in the spec.
84    --
85    --  The main call (made after all units have been analyzed, with Spec_Unit
86    --  set to the default value of No_Unit) generates the required warnings
87    --  using the flags set by the initial call where appropriate to specialize
88    --  the text of the warning messages.
89
90    ---------------------
91    -- Output Routines --
92    ---------------------
93
94    procedure Output_Unreferenced_Messages;
95    --  Warnings about unreferenced entities are collected till the end of
96    --  the compilation process (see Check_Unset_Reference for further
97    --  details). This procedure outputs waiting warnings, if any.
98
99    ----------------------------
100    -- Other Warning Routines --
101    ----------------------------
102
103    procedure Warn_On_Known_Condition (C : Node_Id);
104    --  C is a node for a boolean expression resluting from a relational
105    --  or membership operation. If the expression has a compile time known
106    --  value, then a warning is output if all the following conditions hold:
107    --
108    --    1. Original expression comes from source. We don't want to generate
109    --       warnings for internally generated conditionals.
110    --
111    --    2. As noted above, the expression is a relational or membership
112    --       test, we don't want to generate warnings for boolean variables
113    --       since this is typical of conditional compilation in Ada.
114    --
115    --    3. The expression appears in a statement, rather than a declaration.
116    --       In practice, most occurrences in declarations are legitimate
117    --       conditionalizations, but occurrences in statements are often
118    --       errors for which the warning is useful.
119    --
120    --    4. The expression does not occur within an instantiation. A non-
121    --       static expression in a generic may become constant because of
122    --       the attributes of the actuals, and we do not want to warn on
123    --       these legitimate constant foldings.
124    --
125    --  If all these conditions are met, the warning is issued noting that
126    --  the result of the test is always false or always true as appropriate.
127
128 end Sem_Warn;