]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ada/makeutl.adb
trans-array.c (gfc_conv_descriptor_data_get): Rename from gfc_conv_descriptor_data.
[thirdparty/gcc.git] / gcc / ada / makeutl.adb
CommitLineData
8f9df7d8
VC
1------------------------------------------------------------------------------
2-- --
3-- GNAT COMPILER COMPONENTS --
4-- --
5-- M A K E U T L --
6-- --
7-- B o d y --
8-- --
7e98a4c6 9-- Copyright (C) 2004-2005 Free Software Foundation, Inc. --
8f9df7d8
VC
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 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. --
21-- --
22-- GNAT was originally developed by the GNAT team at New York University. --
23-- Extensive contributions were provided by Ada Core Technologies Inc. --
24-- --
25------------------------------------------------------------------------------
26
5950a3ac
AC
27with Namet; use Namet;
28with Osint; use Osint;
29with Prj; use Prj;
8f9df7d8
VC
30with Prj.Ext;
31with Prj.Util;
5950a3ac 32with Snames; use Snames;
8f9df7d8 33with Table;
5950a3ac 34with Types; use Types;
8f9df7d8 35
aa720a54
AC
36with System.HTable;
37
8f9df7d8
VC
38package body Makeutl is
39
aa720a54
AC
40 type Mark_Key is record
41 File : File_Name_Type;
42 Index : Int;
43 end record;
44 -- Identify either a mono-unit source (when Index = 0) or a specific unit
45 -- in a multi-unit source.
46
5950a3ac
AC
47 -- There follow many global undocumented declarations, comments needed ???
48
aa720a54
AC
49 Max_Mask_Num : constant := 2048;
50
51 subtype Mark_Num is Union_Id range 0 .. Max_Mask_Num - 1;
52
53 function Hash (Key : Mark_Key) return Mark_Num;
54
55 package Marks is new System.HTable.Simple_HTable
56 (Header_Num => Mark_Num,
57 Element => Boolean,
58 No_Element => False,
59 Key => Mark_Key,
60 Hash => Hash,
61 Equal => "=");
62 -- A hash table to keep tracks of the marked units.
63
8f9df7d8
VC
64 type Linker_Options_Data is record
65 Project : Project_Id;
66 Options : String_List_Id;
67 end record;
68
69 Linker_Option_Initial_Count : constant := 20;
70
71 Linker_Options_Buffer : String_List_Access :=
72 new String_List (1 .. Linker_Option_Initial_Count);
73
74 Last_Linker_Option : Natural := 0;
75
76 package Linker_Opts is new Table.Table (
77 Table_Component_Type => Linker_Options_Data,
78 Table_Index_Type => Integer,
79 Table_Low_Bound => 1,
80 Table_Initial => 10,
81 Table_Increment => 100,
82 Table_Name => "Make.Linker_Opts");
83
84 procedure Add_Linker_Option (Option : String);
85
86 -----------------------
87 -- Add_Linker_Option --
88 -----------------------
89
90 procedure Add_Linker_Option (Option : String) is
91 begin
92 if Option'Length > 0 then
93 if Last_Linker_Option = Linker_Options_Buffer'Last then
94 declare
95 New_Buffer : constant String_List_Access :=
5950a3ac
AC
96 new String_List
97 (1 .. Linker_Options_Buffer'Last +
98 Linker_Option_Initial_Count);
8f9df7d8
VC
99 begin
100 New_Buffer (Linker_Options_Buffer'Range) :=
101 Linker_Options_Buffer.all;
102 Linker_Options_Buffer.all := (others => null);
103 Free (Linker_Options_Buffer);
104 Linker_Options_Buffer := New_Buffer;
105 end;
106 end if;
107
108 Last_Linker_Option := Last_Linker_Option + 1;
109 Linker_Options_Buffer (Last_Linker_Option) := new String'(Option);
110 end if;
111 end Add_Linker_Option;
112
aa720a54
AC
113 ----------------------
114 -- Delete_All_Marks --
115 ----------------------
116
117 procedure Delete_All_Marks is
118 begin
119 Marks.Reset;
120 end Delete_All_Marks;
121
122 ----------
123 -- Hash --
124 ----------
125
126 function Hash (Key : Mark_Key) return Mark_Num is
127 begin
128 return Union_Id (Key.File) mod Max_Mask_Num;
129 end Hash;
130
8f9df7d8
VC
131 ----------------------------
132 -- Is_External_Assignment --
133 ----------------------------
134
135 function Is_External_Assignment (Argv : String) return Boolean is
136 Start : Positive := 3;
137 Finish : Natural := Argv'Last;
138 Equal_Pos : Natural;
139
140 begin
141 if Argv'Last < 5 then
142 return False;
143
144 elsif Argv (3) = '"' then
145 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
146 return False;
147 else
148 Start := 4;
149 Finish := Argv'Last - 1;
150 end if;
151 end if;
152
153 Equal_Pos := Start;
154
155 while Equal_Pos <= Finish and then Argv (Equal_Pos) /= '=' loop
156 Equal_Pos := Equal_Pos + 1;
157 end loop;
158
159 if Equal_Pos = Start
160 or else Equal_Pos >= Finish
161 then
162 return False;
8f9df7d8
VC
163 else
164 Prj.Ext.Add
165 (External_Name => Argv (Start .. Equal_Pos - 1),
166 Value => Argv (Equal_Pos + 1 .. Finish));
167 return True;
168 end if;
169 end Is_External_Assignment;
170
aa720a54
AC
171 ---------------
172 -- Is_Marked --
173 ---------------
174
175 function Is_Marked
176 (Source_File : File_Name_Type;
5950a3ac 177 Index : Int := 0) return Boolean
aa720a54
AC
178 is
179 begin
180 return Marks.Get (K => (File => Source_File, Index => Index));
181 end Is_Marked;
182
8f9df7d8
VC
183 -----------------------------
184 -- Linker_Options_Switches --
185 -----------------------------
186
187 function Linker_Options_Switches
7e98a4c6
VC
188 (Project : Project_Id;
189 In_Tree : Project_Tree_Ref) return String_List
8f9df7d8 190 is
5950a3ac
AC
191 procedure Recursive_Add_Linker_Options (Proj : Project_Id);
192 -- The recursive routine used to add linker options
8f9df7d8
VC
193
194 ----------------------------------
195 -- Recursive_Add_Linker_Options --
196 ----------------------------------
197
8f9df7d8 198 procedure Recursive_Add_Linker_Options (Proj : Project_Id) is
5950a3ac 199 Data : Project_Data;
8f9df7d8 200 Linker_Package : Package_Id;
5950a3ac
AC
201 Options : Variable_Value;
202 Imported : Project_List;
203
8f9df7d8
VC
204 begin
205 if Proj /= No_Project then
7e98a4c6 206 Data := In_Tree.Projects.Table (Proj);
8f9df7d8
VC
207
208 if not Data.Seen then
7e98a4c6 209 In_Tree.Projects.Table (Proj).Seen := True;
8f9df7d8
VC
210 Imported := Data.Imported_Projects;
211
212 while Imported /= Empty_Project_List loop
213 Recursive_Add_Linker_Options
7e98a4c6
VC
214 (In_Tree.Project_Lists.Table
215 (Imported).Project);
216 Imported := In_Tree.Project_Lists.Table
217 (Imported).Next;
8f9df7d8
VC
218 end loop;
219
220 if Proj /= Project then
221 Linker_Package :=
222 Prj.Util.Value_Of
7e98a4c6
VC
223 (Name => Name_Linker,
224 In_Packages => Data.Decl.Packages,
225 In_Tree => In_Tree);
8f9df7d8
VC
226 Options :=
227 Prj.Util.Value_Of
7e98a4c6
VC
228 (Name => Name_Ada,
229 Index => 0,
8f9df7d8 230 Attribute_Or_Array_Name => Name_Linker_Options,
7e98a4c6
VC
231 In_Package => Linker_Package,
232 In_Tree => In_Tree);
8f9df7d8
VC
233
234 -- If attribute is present, add the project with
235 -- the attribute to table Linker_Opts.
236
237 if Options /= Nil_Variable_Value then
238 Linker_Opts.Increment_Last;
239 Linker_Opts.Table (Linker_Opts.Last) :=
240 (Project => Proj, Options => Options.Values);
241 end if;
242 end if;
243 end if;
244 end if;
245 end Recursive_Add_Linker_Options;
246
5950a3ac
AC
247 -- Start of processing for Linker_Options_Switches
248
8f9df7d8
VC
249 begin
250 Linker_Opts.Init;
251
7e98a4c6
VC
252 for Index in Project_Table.First ..
253 Project_Table.Last (In_Tree.Projects)
254 loop
255 In_Tree.Projects.Table (Index).Seen := False;
8f9df7d8
VC
256 end loop;
257
258 Recursive_Add_Linker_Options (Project);
259
260 Last_Linker_Option := 0;
261
262 for Index in reverse 1 .. Linker_Opts.Last loop
263 declare
264 Options : String_List_Id := Linker_Opts.Table (Index).Options;
265 Proj : constant Project_Id :=
266 Linker_Opts.Table (Index).Project;
267 Option : Name_Id;
268
269 begin
270 -- If Dir_Path has not been computed for this project, do it now
271
7e98a4c6
VC
272 if In_Tree.Projects.Table (Proj).Dir_Path = null then
273 In_Tree.Projects.Table (Proj).Dir_Path :=
8f9df7d8 274 new String'
7e98a4c6
VC
275 (Get_Name_String
276 (In_Tree.Projects.Table
277 (Proj). Directory));
8f9df7d8
VC
278 end if;
279
280 while Options /= Nil_String loop
7e98a4c6
VC
281 Option :=
282 In_Tree.String_Elements.Table (Options).Value;
283 Options :=
284 In_Tree.String_Elements.Table (Options).Next;
8f9df7d8
VC
285 Add_Linker_Option (Get_Name_String (Option));
286
287 -- Object files and -L switches specified with
288 -- relative paths and must be converted to
289 -- absolute paths.
290
291 Test_If_Relative_Path
292 (Switch =>
293 Linker_Options_Buffer (Last_Linker_Option),
7e98a4c6
VC
294 Parent =>
295 In_Tree.Projects.Table (Proj).Dir_Path,
8f9df7d8
VC
296 Including_L_Switch => True);
297 end loop;
298 end;
299 end loop;
300
301 return Linker_Options_Buffer (1 .. Last_Linker_Option);
302 end Linker_Options_Switches;
303
304 -----------
305 -- Mains --
306 -----------
307
308 package body Mains is
309
310 package Names is new Table.Table
311 (Table_Component_Type => File_Name_Type,
312 Table_Index_Type => Integer,
313 Table_Low_Bound => 1,
314 Table_Initial => 10,
315 Table_Increment => 100,
316 Table_Name => "Makeutl.Mains.Names");
317 -- The table that stores the mains
318
319 Current : Natural := 0;
320 -- The index of the last main retrieved from the table
321
322 --------------
323 -- Add_Main --
324 --------------
325
326 procedure Add_Main (Name : String) is
327 begin
328 Name_Len := 0;
329 Add_Str_To_Name_Buffer (Name);
330 Names.Increment_Last;
331 Names.Table (Names.Last) := Name_Find;
332 end Add_Main;
333
334 ------------
335 -- Delete --
336 ------------
337
338 procedure Delete is
339 begin
340 Names.Set_Last (0);
7e98a4c6 341 Mains.Reset;
8f9df7d8
VC
342 end Delete;
343
344 ---------------
345 -- Next_Main --
346 ---------------
347
348 function Next_Main return String is
349 begin
350 if Current >= Names.Last then
351 return "";
352
353 else
354 Current := Current + 1;
355 return Get_Name_String (Names.Table (Current));
356 end if;
357 end Next_Main;
358
359 ---------------------
360 -- Number_Of_Mains --
361 ---------------------
362
363 function Number_Of_Mains return Natural is
364 begin
365 return Names.Last;
366 end Number_Of_Mains;
367
368 -----------
369 -- Reset --
370 -----------
371
372 procedure Reset is
373 begin
374 Current := 0;
375 end Reset;
376
377 end Mains;
378
aa720a54
AC
379 ----------
380 -- Mark --
381 ----------
382
383 procedure Mark (Source_File : File_Name_Type; Index : Int := 0) is
384 begin
385 Marks.Set (K => (File => Source_File, Index => Index), E => True);
386 end Mark;
387
8f9df7d8
VC
388 ---------------------------
389 -- Test_If_Relative_Path --
390 ---------------------------
391
392 procedure Test_If_Relative_Path
393 (Switch : in out String_Access;
394 Parent : String_Access;
395 Including_L_Switch : Boolean := True)
396 is
397 begin
398 if Switch /= null then
8f9df7d8
VC
399 declare
400 Sw : String (1 .. Switch'Length);
401 Start : Positive;
402
403 begin
404 Sw := Switch.all;
405
406 if Sw (1) = '-' then
407 if Sw'Length >= 3
408 and then (Sw (2) = 'A'
409 or else Sw (2) = 'I'
410 or else (Including_L_Switch and then Sw (2) = 'L'))
411 then
412 Start := 3;
413
414 if Sw = "-I-" then
415 return;
416 end if;
417
418 elsif Sw'Length >= 4
419 and then (Sw (2 .. 3) = "aL"
420 or else Sw (2 .. 3) = "aO"
421 or else Sw (2 .. 3) = "aI")
422 then
423 Start := 4;
424
425 else
426 return;
427 end if;
428
429 -- Because relative path arguments to --RTS= may be relative
430 -- to the search directory prefix, those relative path
431 -- arguments are not converted.
432
433 if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
434 if Parent = null or else Parent'Length = 0 then
435 Do_Fail
436 ("relative search path switches (""",
437 Sw,
438 """) are not allowed");
439
440 else
441 Switch :=
442 new String'
443 (Sw (1 .. Start - 1) &
444 Parent.all &
445 Directory_Separator &
446 Sw (Start .. Sw'Last));
447 end if;
448 end if;
449
450 else
451 if not Is_Absolute_Path (Sw) then
452 if Parent = null or else Parent'Length = 0 then
453 Do_Fail
454 ("relative paths (""", Sw, """) are not allowed");
455
456 else
457 Switch :=
458 new String'(Parent.all & Directory_Separator & Sw);
459 end if;
460 end if;
461 end if;
462 end;
463 end if;
464 end Test_If_Relative_Path;
465
aa720a54
AC
466 -------------------
467 -- Unit_Index_Of --
468 -------------------
469
470 function Unit_Index_Of (ALI_File : File_Name_Type) return Int is
471 Start : Natural;
472 Finish : Natural;
473 Result : Int := 0;
5950a3ac 474
aa720a54
AC
475 begin
476 Get_Name_String (ALI_File);
477
478 -- First, find the last dot
479
480 Finish := Name_Len;
481
482 while Finish >= 1 and then Name_Buffer (Finish) /= '.' loop
483 Finish := Finish - 1;
484 end loop;
485
486 if Finish = 1 then
487 return 0;
488 end if;
489
490 -- Now check that the dot is preceded by digits
491
492 Start := Finish;
493 Finish := Finish - 1;
494
495 while Start >= 1 and then Name_Buffer (Start - 1) in '0' .. '9' loop
496 Start := Start - 1;
497 end loop;
498
499 -- If there is no difits, or if the digits are not preceded by
500 -- the character that precedes a unit index, this is not the ALI file
501 -- of a unit in a multi-unit source.
502
5950a3ac
AC
503 if Start > Finish
504 or else Start = 1
505 or else Name_Buffer (Start - 1) /= Multi_Unit_Index_Character
aa720a54
AC
506 then
507 return 0;
508 end if;
509
510 -- Build the index from the digit(s)
511
512 while Start <= Finish loop
5950a3ac
AC
513 Result := Result * 10 +
514 Character'Pos (Name_Buffer (Start)) - Character'Pos ('0');
aa720a54
AC
515 Start := Start + 1;
516 end loop;
517
518 return Result;
519 end Unit_Index_Of;
520
8f9df7d8 521end Makeutl;