prj-nmsc.adb: (Ada_Check): Migrate drom Ada_Default_...
[gcc.git] / gcc / ada / prj.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P R J --
6 -- --
7 -- B o d y --
8 -- --
9 -- $Revision$
10 -- --
11 -- Copyright (C) 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 with Ada.Characters.Handling; use Ada.Characters.Handling;
30 with Errout; use Errout;
31 with GNAT.OS_Lib; use GNAT.OS_Lib;
32 with Namet; use Namet;
33 with Prj.Attr;
34 with Prj.Com;
35 with Prj.Env;
36 with Scans; use Scans;
37 with Scn;
38 with Stringt; use Stringt;
39 with Sinfo.CN;
40 with Snames; use Snames;
41
42 package body Prj is
43
44 The_Empty_String : String_Id;
45
46 subtype Known_Casing is Casing_Type range All_Upper_Case .. Mixed_Case;
47
48 The_Casing_Images : array (Known_Casing) of String_Access :=
49 (All_Lower_Case => new String'("lowercase"),
50 All_Upper_Case => new String'("UPPERCASE"),
51 Mixed_Case => new String'("MixedCase"));
52
53 Initialized : Boolean := False;
54
55 Standard_Dot_Replacement : constant Name_Id :=
56 First_Name_Id + Character'Pos ('-');
57
58 Std_Naming_Data : Naming_Data :=
59 (Current_Language => No_Name,
60 Dot_Replacement => Standard_Dot_Replacement,
61 Dot_Repl_Loc => No_Location,
62 Casing => All_Lower_Case,
63 Specification_Suffix => No_Array_Element,
64 Current_Spec_Suffix => No_Name,
65 Spec_Suffix_Loc => No_Location,
66 Implementation_Suffix => No_Array_Element,
67 Current_Impl_Suffix => No_Name,
68 Impl_Suffix_Loc => No_Location,
69 Separate_Suffix => No_Name,
70 Sep_Suffix_Loc => No_Location,
71 Specifications => No_Array_Element,
72 Bodies => No_Array_Element,
73 Specification_Exceptions => No_Array_Element,
74 Implementation_Exceptions => No_Array_Element);
75
76 Project_Empty : constant Project_Data :=
77 (First_Referred_By => No_Project,
78 Name => No_Name,
79 Path_Name => No_Name,
80 Location => No_Location,
81 Directory => No_Name,
82 Library => False,
83 Library_Dir => No_Name,
84 Library_Name => No_Name,
85 Library_Kind => Static,
86 Lib_Internal_Name => No_Name,
87 Lib_Elaboration => False,
88 Sources_Present => True,
89 Sources => Nil_String,
90 Source_Dirs => Nil_String,
91 Object_Directory => No_Name,
92 Modifies => No_Project,
93 Modified_By => No_Project,
94 Naming => Std_Naming_Data,
95 Decl => No_Declarations,
96 Imported_Projects => Empty_Project_List,
97 Include_Path => null,
98 Objects_Path => null,
99 Config_File_Name => No_Name,
100 Config_File_Temp => False,
101 Config_Checked => False,
102 Language_Independent_Checked => False,
103 Checked => False,
104 Seen => False,
105 Flag1 => False,
106 Flag2 => False);
107
108 -------------------
109 -- Empty_Project --
110 -------------------
111
112 function Empty_Project return Project_Data is
113 begin
114 Initialize;
115 return Project_Empty;
116 end Empty_Project;
117
118 ------------------
119 -- Empty_String --
120 ------------------
121
122 function Empty_String return String_Id is
123 begin
124 return The_Empty_String;
125 end Empty_String;
126
127 ------------
128 -- Expect --
129 ------------
130
131 procedure Expect (The_Token : Token_Type; Token_Image : String) is
132 begin
133 if Token /= The_Token then
134 Error_Msg ("""" & Token_Image & """ expected", Token_Ptr);
135 end if;
136 end Expect;
137
138 --------------------------------
139 -- For_Every_Project_Imported --
140 --------------------------------
141
142 procedure For_Every_Project_Imported
143 (By : Project_Id;
144 With_State : in out State)
145 is
146
147 procedure Check (Project : Project_Id);
148 -- Check if a project has already been seen.
149 -- If not seen, mark it as seen, call Action,
150 -- and check all its imported projects.
151
152 procedure Check (Project : Project_Id) is
153 List : Project_List;
154
155 begin
156 if not Projects.Table (Project).Seen then
157 Projects.Table (Project).Seen := False;
158 Action (Project, With_State);
159
160 List := Projects.Table (Project).Imported_Projects;
161 while List /= Empty_Project_List loop
162 Check (Project_Lists.Table (List).Project);
163 List := Project_Lists.Table (List).Next;
164 end loop;
165 end if;
166 end Check;
167
168 begin
169 for Project in Projects.First .. Projects.Last loop
170 Projects.Table (Project).Seen := False;
171 end loop;
172
173 Check (Project => By);
174 end For_Every_Project_Imported;
175
176 -----------
177 -- Image --
178 -----------
179
180 function Image (Casing : Casing_Type) return String is
181 begin
182 return The_Casing_Images (Casing).all;
183 end Image;
184
185 ----------------
186 -- Initialize --
187 ----------------
188
189 procedure Initialize is
190 begin
191 if not Initialized then
192 Initialized := True;
193 Stringt.Initialize;
194 Start_String;
195 The_Empty_String := End_String;
196 Name_Len := 4;
197 Name_Buffer (1 .. 4) := ".ads";
198 Default_Ada_Spec_Suffix := Name_Find;
199 Name_Len := 4;
200 Name_Buffer (1 .. 4) := ".adb";
201 Default_Ada_Impl_Suffix := Name_Find;
202 Std_Naming_Data.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
203 Std_Naming_Data.Current_Impl_Suffix := Default_Ada_Impl_Suffix;
204 Std_Naming_Data.Separate_Suffix := Default_Ada_Impl_Suffix;
205 Prj.Env.Initialize;
206 Prj.Attr.Initialize;
207 Set_Name_Table_Byte (Name_Project, Token_Type'Pos (Tok_Project));
208 Set_Name_Table_Byte (Name_Extends, Token_Type'Pos (Tok_Extends));
209 Set_Name_Table_Byte (Name_External, Token_Type'Pos (Tok_External));
210 end if;
211 end Initialize;
212
213 ------------
214 -- Reset --
215 ------------
216
217 procedure Reset is
218 begin
219 Projects.Init;
220 Project_Lists.Init;
221 Packages.Init;
222 Arrays.Init;
223 Variable_Elements.Init;
224 String_Elements.Init;
225 Prj.Com.Units.Init;
226 Prj.Com.Units_Htable.Reset;
227 end Reset;
228
229 ------------------------
230 -- Same_Naming_Scheme --
231 ------------------------
232
233 function Same_Naming_Scheme
234 (Left, Right : Naming_Data)
235 return Boolean
236 is
237 begin
238 return Left.Dot_Replacement = Right.Dot_Replacement
239 and then Left.Casing = Right.Casing
240 and then Left.Current_Spec_Suffix = Right.Current_Spec_Suffix
241 and then Left.Current_Impl_Suffix = Right.Current_Impl_Suffix
242 and then Left.Separate_Suffix = Right.Separate_Suffix;
243 end Same_Naming_Scheme;
244
245 ----------
246 -- Scan --
247 ----------
248
249 procedure Scan is
250 begin
251 Scn.Scan;
252
253 -- Change operator symbol to literal strings, since that's the way
254 -- we treat all strings in a project file.
255
256 if Token = Tok_Operator_Symbol then
257 Sinfo.CN.Change_Operator_Symbol_To_String_Literal (Token_Node);
258 Token := Tok_String_Literal;
259 end if;
260 end Scan;
261
262 --------------------------
263 -- Standard_Naming_Data --
264 --------------------------
265
266 function Standard_Naming_Data return Naming_Data is
267 begin
268 Initialize;
269 return Std_Naming_Data;
270 end Standard_Naming_Data;
271
272 -----------
273 -- Value --
274 -----------
275
276 function Value (Image : String) return Casing_Type is
277 begin
278 for Casing in The_Casing_Images'Range loop
279 if To_Lower (Image) = To_Lower (The_Casing_Images (Casing).all) then
280 return Casing;
281 end if;
282 end loop;
283
284 raise Constraint_Error;
285 end Value;
286
287 end Prj;