1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2000-2011, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Osint; use Osint;
28 with Ada.Unchecked_Deallocation;
30 package body Prj.Ext is
37 (Self : out External_References;
38 Copy_From : External_References := No_External_Refs)
41 N2 : Name_To_Name_Ptr;
43 if Self.Refs = null then
44 Self.Refs := new Name_To_Name_HTable.Instance;
46 if Copy_From.Refs /= null then
47 N := Name_To_Name_HTable.Get_First (Copy_From.Refs.all);
49 N2 := new Name_To_Name'
54 Name_To_Name_HTable.Set (Self.Refs.all, N2);
55 N := Name_To_Name_HTable.Get_Next (Copy_From.Refs.all);
66 (Self : External_References;
67 External_Name : String;
69 Source : External_Source := External_Source'First)
75 Name_Len := External_Name'Length;
76 Name_Buffer (1 .. Name_Len) := External_Name;
77 Canonical_Case_Env_Var_Name (Name_Buffer (1 .. Name_Len));
80 -- Check whether the value is already defined, to properly respect the
83 if Source /= External_Source'First then
84 N := Name_To_Name_HTable.Get (Self.Refs.all, Key);
87 if External_Source'Pos (N.Source) <
88 External_Source'Pos (Source)
90 if Current_Verbosity = High then
92 ("Not overridding existing variable '" & External_Name
93 & "', value was defined in " & N.Source'Img);
100 Name_Len := Value'Length;
101 Name_Buffer (1 .. Name_Len) := Value;
102 N := new Name_To_Name'
108 if Current_Verbosity = High then
109 Debug_Output ("Add external (" & External_Name & ") is", N.Value);
112 Name_To_Name_HTable.Set (Self.Refs.all, N);
120 (Self : External_References;
121 Declaration : String) return Boolean
124 for Equal_Pos in Declaration'Range loop
125 if Declaration (Equal_Pos) = '=' then
126 exit when Equal_Pos = Declaration'First;
130 Declaration (Declaration'First .. Equal_Pos - 1),
132 Declaration (Equal_Pos + 1 .. Declaration'Last),
133 Source => From_Command_Line);
145 procedure Reset (Self : External_References) is
147 if Self.Refs /= null then
148 Debug_Output ("Reset external references");
149 Name_To_Name_HTable.Reset (Self.Refs.all);
158 (Self : External_References;
159 External_Name : Name_Id;
160 With_Default : Name_Id := No_Name)
163 Value : Name_To_Name_Ptr;
165 Name : String := Get_Name_String (External_Name);
168 Canonical_Case_Env_Var_Name (Name);
170 if Self.Refs /= null then
171 Name_Len := Name'Length;
172 Name_Buffer (1 .. Name_Len) := Name;
173 Value := Name_To_Name_HTable.Get (Self.Refs.all, Name_Find);
175 if Value /= null then
176 Debug_Output ("Value_Of (" & Name & ") is in cache", Value.Value);
181 -- Find if it is an environment, if it is, put value in the hash table
184 Env_Value : String_Access := Getenv (Name);
187 if Env_Value /= null and then Env_Value'Length > 0 then
188 Name_Len := Env_Value'Length;
189 Name_Buffer (1 .. Name_Len) := Env_Value.all;
192 if Current_Verbosity = High then
193 Debug_Output ("Value_Of (" & Name & ") is", Val);
196 if Self.Refs /= null then
197 Value := new Name_To_Name'
198 (Key => External_Name,
200 Source => From_Environment,
202 Name_To_Name_HTable.Set (Self.Refs.all, Value);
209 if Current_Verbosity = High then
211 ("Value_Of (" & Name & ") is default", With_Default);
224 procedure Free (Self : in out External_References) is
225 procedure Unchecked_Free is new Ada.Unchecked_Deallocation
226 (Name_To_Name_HTable.Instance, Instance_Access);
228 if Self.Refs /= null then
230 Unchecked_Free (Self.Refs);
238 procedure Set_Next (E : Name_To_Name_Ptr; Next : Name_To_Name_Ptr) is
247 function Next (E : Name_To_Name_Ptr) return Name_To_Name_Ptr is
256 function Get_Key (E : Name_To_Name_Ptr) return Name_Id is