1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
28 with Errout
; use Errout
;
29 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
30 with Namet
; use Namet
;
31 with Osint
; use Osint
;
35 with Scans
; use Scans
;
37 with Stringt
; use Stringt
;
39 with Snames
; use Snames
;
43 The_Empty_String
: String_Id
;
45 Ada_Language
: constant Name_Id
:= Name_Ada
;
47 subtype Known_Casing
is Casing_Type
range All_Upper_Case
.. Mixed_Case
;
49 The_Casing_Images
: array (Known_Casing
) of String_Access
:=
50 (All_Lower_Case
=> new String'("lowercase"),
51 All_Upper_Case => new String'("UPPERCASE"),
52 Mixed_Case
=> new String'("MixedCase"));
54 Initialized : Boolean := False;
56 Standard_Dot_Replacement : constant Name_Id :=
57 First_Name_Id + Character'Pos ('-');
59 Std_Naming_Data : Naming_Data :=
60 (Current_Language => No_Name,
61 Dot_Replacement => Standard_Dot_Replacement,
62 Dot_Repl_Loc => No_Location,
63 Casing => All_Lower_Case,
64 Specification_Suffix => No_Array_Element,
65 Current_Spec_Suffix => No_Name,
66 Spec_Suffix_Loc => No_Location,
67 Implementation_Suffix => No_Array_Element,
68 Current_Impl_Suffix => No_Name,
69 Impl_Suffix_Loc => No_Location,
70 Separate_Suffix => No_Name,
71 Sep_Suffix_Loc => No_Location,
72 Specifications => No_Array_Element,
73 Bodies => No_Array_Element,
74 Specification_Exceptions => No_Array_Element,
75 Implementation_Exceptions => No_Array_Element);
77 Project_Empty : constant Project_Data :=
78 (First_Referred_By => No_Project,
81 Location => No_Location,
84 Library_Dir => No_Name,
85 Library_Name => No_Name,
86 Library_Kind => Static,
87 Lib_Internal_Name => No_Name,
88 Lib_Elaboration => False,
89 Sources_Present => True,
90 Sources => Nil_String,
91 Source_Dirs => Nil_String,
92 Object_Directory => No_Name,
93 Exec_Directory => No_Name,
94 Modifies => No_Project,
95 Modified_By => No_Project,
96 Naming => Std_Naming_Data,
97 Decl => No_Declarations,
98 Imported_Projects => Empty_Project_List,
100 Objects_Path => null,
101 Config_File_Name => No_Name,
102 Config_File_Temp => False,
103 Config_Checked => False,
104 Language_Independent_Checked => False,
114 function Empty_Project return Project_Data is
117 return Project_Empty;
124 function Empty_String return String_Id is
126 return The_Empty_String;
133 procedure Expect (The_Token : Token_Type; Token_Image : String) is
135 if Token /= The_Token then
136 Error_Msg ("""" & Token_Image & """ expected", Token_Ptr);
140 --------------------------------
141 -- For_Every_Project_Imported --
142 --------------------------------
144 procedure For_Every_Project_Imported
146 With_State : in out State)
149 procedure Check (Project : Project_Id);
150 -- Check if a project has already been seen.
151 -- If not seen, mark it as seen, call Action,
152 -- and check all its imported projects.
154 procedure Check (Project : Project_Id) is
158 if not Projects.Table (Project).Seen then
159 Projects.Table (Project).Seen := True;
160 Action (Project, With_State);
162 List := Projects.Table (Project).Imported_Projects;
163 while List /= Empty_Project_List loop
164 Check (Project_Lists.Table (List).Project);
165 List := Project_Lists.Table (List).Next;
171 for Project in Projects.First .. Projects.Last loop
172 Projects.Table (Project).Seen := False;
175 Check (Project => By);
176 end For_Every_Project_Imported;
182 function Image (Casing : Casing_Type) return String is
184 return The_Casing_Images (Casing).all;
191 procedure Initialize is
193 if not Initialized then
197 The_Empty_String := End_String;
199 Name_Buffer (1 .. 4) := ".ads";
200 Default_Ada_Spec_Suffix := Name_Find;
202 Name_Buffer (1 .. 4) := ".adb";
203 Default_Ada_Impl_Suffix := Name_Find;
204 Std_Naming_Data.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
205 Std_Naming_Data.Current_Impl_Suffix := Default_Ada_Impl_Suffix;
206 Std_Naming_Data.Separate_Suffix := Default_Ada_Impl_Suffix;
207 Register_Default_Naming_Scheme
208 (Language => Ada_Language,
209 Default_Spec_Suffix => Default_Ada_Spec_Suffix,
210 Default_Impl_Suffix => Default_Ada_Impl_Suffix);
213 Set_Name_Table_Byte (Name_Project, Token_Type'Pos (Tok_Project));
214 Set_Name_Table_Byte (Name_Extends, Token_Type'Pos (Tok_Extends));
215 Set_Name_Table_Byte (Name_External, Token_Type'Pos (Tok_External));
219 ------------------------------------
220 -- Register_Default_Naming_Scheme --
221 ------------------------------------
223 procedure Register_Default_Naming_Scheme
225 Default_Spec_Suffix : Name_Id;
226 Default_Impl_Suffix : Name_Id)
229 Suffix : Array_Element_Id;
230 Found : Boolean := False;
231 Element : Array_Element;
233 Spec_Str : String_Id;
234 Impl_Str : String_Id;
237 -- The following code is completely uncommented ???
239 Get_Name_String (Language);
240 Name_Buffer (1 .. Name_Len) := To_Lower (Name_Buffer (1 .. Name_Len));
243 Get_Name_String (Default_Spec_Suffix);
245 Store_String_Chars (Name_Buffer (1 .. Name_Len));
246 Spec_Str := End_String;
248 Get_Name_String (Default_Impl_Suffix);
250 Store_String_Chars (Name_Buffer (1 .. Name_Len));
251 Impl_Str := End_String;
253 Suffix := Std_Naming_Data.Specification_Suffix;
256 while Suffix /= No_Array_Element and then not Found loop
257 Element := Array_Elements.Table (Suffix);
259 if Element.Index = Lang then
261 Element.Value.Value := Spec_Str;
262 Array_Elements.Table (Suffix) := Element;
265 Suffix := Element.Next;
272 Value => (Kind => Single,
273 Location => No_Location,
276 Next => Std_Naming_Data.Specification_Suffix);
277 Array_Elements.Increment_Last;
278 Array_Elements.Table (Array_Elements.Last) := Element;
279 Std_Naming_Data.Specification_Suffix := Array_Elements.Last;
282 Suffix := Std_Naming_Data.Implementation_Suffix;
285 while Suffix /= No_Array_Element and then not Found loop
286 Element := Array_Elements.Table (Suffix);
288 if Element.Index = Lang then
290 Element.Value.Value := Impl_Str;
291 Array_Elements.Table (Suffix) := Element;
294 Suffix := Element.Next;
301 Value => (Kind => Single,
302 Location => No_Location,
305 Next => Std_Naming_Data.Implementation_Suffix);
306 Array_Elements.Increment_Last;
307 Array_Elements.Table (Array_Elements.Last) := Element;
308 Std_Naming_Data.Implementation_Suffix := Array_Elements.Last;
310 end Register_Default_Naming_Scheme;
322 Variable_Elements.Init;
323 String_Elements.Init;
325 Prj.Com.Units_Htable.Reset;
328 ------------------------
329 -- Same_Naming_Scheme --
330 ------------------------
332 function Same_Naming_Scheme
333 (Left, Right : Naming_Data)
337 return Left.Dot_Replacement = Right.Dot_Replacement
338 and then Left.Casing = Right.Casing
339 and then Left.Current_Spec_Suffix = Right.Current_Spec_Suffix
340 and then Left.Current_Impl_Suffix = Right.Current_Impl_Suffix
341 and then Left.Separate_Suffix = Right.Separate_Suffix;
342 end Same_Naming_Scheme;
352 -- Change operator symbol to literal strings, since that's the way
353 -- we treat all strings in a project file.
355 if Token = Tok_Operator_Symbol then
356 Sinfo.CN.Change_Operator_Symbol_To_String_Literal (Token_Node);
357 Token := Tok_String_Literal;
361 --------------------------
362 -- Standard_Naming_Data --
363 --------------------------
365 function Standard_Naming_Data return Naming_Data is
368 return Std_Naming_Data;
369 end Standard_Naming_Data;
375 function Value (Image : String) return Casing_Type is
377 for Casing in The_Casing_Images'Range loop
378 if To_Lower (Image) = To_Lower (The_Casing_Images (Casing).all) then
383 raise Constraint_Error;
387 -- Make sure that the standard project file extension is compatible
388 -- with canonical case file naming.
390 Canonical_Case_File_Name (Project_File_Extension);