Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / ada / prj-ext.adb
blob9c7458e95d48a80e55fe48541f56ea7958428c3a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P R J . E X T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2000-2010, 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 ------------------------------------------------------------------------------
26 with Osint; use Osint;
27 with Prj.Tree; use Prj.Tree;
29 package body Prj.Ext is
31 ---------
32 -- Add --
33 ---------
35 procedure Add
36 (Tree : Prj.Tree.Project_Node_Tree_Ref;
37 External_Name : String;
38 Value : String)
40 The_Key : Name_Id;
41 The_Value : Name_Id;
42 begin
43 Name_Len := Value'Length;
44 Name_Buffer (1 .. Name_Len) := Value;
45 The_Value := Name_Find;
46 Name_Len := External_Name'Length;
47 Name_Buffer (1 .. Name_Len) := External_Name;
48 Canonical_Case_Env_Var_Name (Name_Buffer (1 .. Name_Len));
49 The_Key := Name_Find;
50 Name_To_Name_HTable.Set (Tree.External_References, The_Key, The_Value);
51 end Add;
53 -----------
54 -- Check --
55 -----------
57 function Check
58 (Tree : Prj.Tree.Project_Node_Tree_Ref;
59 Declaration : String) return Boolean
61 begin
62 for Equal_Pos in Declaration'Range loop
63 if Declaration (Equal_Pos) = '=' then
64 exit when Equal_Pos = Declaration'First;
65 Add
66 (Tree => Tree,
67 External_Name =>
68 Declaration (Declaration'First .. Equal_Pos - 1),
69 Value =>
70 Declaration (Equal_Pos + 1 .. Declaration'Last));
71 return True;
72 end if;
73 end loop;
75 return False;
76 end Check;
78 -----------
79 -- Reset --
80 -----------
82 procedure Reset (Tree : Prj.Tree.Project_Node_Tree_Ref) is
83 begin
84 Name_To_Name_HTable.Reset (Tree.External_References);
85 end Reset;
87 --------------
88 -- Value_Of --
89 --------------
91 function Value_Of
92 (Tree : Prj.Tree.Project_Node_Tree_Ref;
93 External_Name : Name_Id;
94 With_Default : Name_Id := No_Name)
95 return Name_Id
97 The_Value : Name_Id;
98 Name : String := Get_Name_String (External_Name);
100 begin
101 Canonical_Case_Env_Var_Name (Name);
102 Name_Len := Name'Length;
103 Name_Buffer (1 .. Name_Len) := Name;
104 The_Value :=
105 Name_To_Name_HTable.Get (Tree.External_References, Name_Find);
107 if The_Value /= No_Name then
108 return The_Value;
109 end if;
111 -- Find if it is an environment, if it is, put value in the hash table
113 declare
114 Env_Value : String_Access := Getenv (Name);
116 begin
117 if Env_Value /= null and then Env_Value'Length > 0 then
118 Name_Len := Env_Value'Length;
119 Name_Buffer (1 .. Name_Len) := Env_Value.all;
120 The_Value := Name_Find;
121 Name_To_Name_HTable.Set
122 (Tree.External_References, External_Name, The_Value);
123 Free (Env_Value);
124 return The_Value;
126 else
127 Free (Env_Value);
128 return With_Default;
129 end if;
130 end;
131 end Value_Of;
133 end Prj.Ext;