1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT COMPILER COMPONENTS                         --
4--                                                                          --
5--                            E X P _ S P A R K                             --
6--                                                                          --
7--                                 B o d y                                  --
8--                                                                          --
9--          Copyright (C) 1992-2013, 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
26with Atree;    use Atree;
27with Einfo;    use Einfo;
28with Exp_Dbug; use Exp_Dbug;
29with Exp_Util; use Exp_Util;
30with Sem_Res;  use Sem_Res;
31with Sem_Util; use Sem_Util;
32with Sinfo;    use Sinfo;
33
34package body Exp_SPARK is
35
36   -----------------------
37   -- Local Subprograms --
38   -----------------------
39
40   procedure Expand_SPARK_N_Object_Renaming_Declaration (N : Node_Id);
41   --  Perform name evaluation for a renamed object
42
43   procedure Expand_Potential_Renaming (N : Node_Id);
44   --  N denotes a N_Identifier or N_Expanded_Name. If N references a renaming,
45   --  replace N with the renamed object.
46
47   ------------------
48   -- Expand_SPARK --
49   ------------------
50
51   procedure Expand_SPARK (N : Node_Id) is
52   begin
53      case Nkind (N) is
54
55         --  Qualification of entity names in formal verification mode
56         --  is limited to the addition of a suffix for homonyms (see
57         --  Exp_Dbug.Qualify_Entity_Name). We used to qualify entity names
58         --  as full expansion does, but this was removed as this prevents the
59         --  verification back-end from using a short name for debugging and
60         --  user interaction. The verification back-end already takes care
61         --  of qualifying names when needed.
62
63         when N_Block_Statement     |
64              N_Package_Body        |
65              N_Package_Declaration |
66              N_Subprogram_Body     =>
67            Qualify_Entity_Names (N);
68
69         when N_Expanded_Name |
70              N_Identifier    =>
71            Expand_Potential_Renaming (N);
72
73         when N_Object_Renaming_Declaration =>
74            Expand_SPARK_N_Object_Renaming_Declaration (N);
75
76         --  In SPARK mode, no other constructs require expansion
77
78         when others =>
79            null;
80      end case;
81   end Expand_SPARK;
82
83   ------------------------------------------------
84   -- Expand_SPARK_N_Object_Renaming_Declaration --
85   ------------------------------------------------
86
87   procedure Expand_SPARK_N_Object_Renaming_Declaration (N : Node_Id) is
88   begin
89      --  Unconditionally remove all side effects from the name
90
91      Evaluate_Name (Name (N));
92   end Expand_SPARK_N_Object_Renaming_Declaration;
93
94   -------------------------------
95   -- Expand_Potential_Renaming --
96   -------------------------------
97
98   procedure Expand_Potential_Renaming (N : Node_Id) is
99      E : constant Entity_Id := Entity (N);
100      T : constant Entity_Id := Etype (N);
101
102   begin
103      --  Replace a reference to a renaming with the actual renamed object
104
105      if Ekind (E) in Object_Kind and then Present (Renamed_Object (E)) then
106         Rewrite (N, New_Copy_Tree (Renamed_Object (E)));
107         Reset_Analyzed_Flags (N);
108         Analyze_And_Resolve (N, T);
109      end if;
110   end Expand_Potential_Renaming;
111
112end Exp_SPARK;
113