1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248 | --
-- Copyright (C) 2022-2024, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception
--
with Ada.Containers.Hashed_Maps;
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Containers.Indefinite_Hashed_Sets;
with Ada.Containers.Indefinite_Ordered_Maps;
with Ada.Containers.Indefinite_Ordered_Sets;
with GNATCOLL.Refcount;
with GPR2.Containers;
with GPR2.Log;
with GPR2.Project.View.Set;
with GPR2.Build.Compilation_Unit;
with GPR2.Build.Source_Base;
with GPR2.Build.Source;
with GPR2.View_Ids;
limited with GPR2.Build.View_Db;
limited with GPR2.Build.Tree_Db;
private package GPR2.Build.View_Tables is
use type Ada.Containers.Hash_Type;
subtype With_View_Db is GPR2.Project_Kind
with Static_Predicate =>
With_View_Db not in K_Aggregate | K_Configuration;
-- generic file object: can represent any file found on the filesystem
type File_Info (Path_Len : Natural) is record
Stamp : Ada.Calendar.Time;
-- Modification time at the moment we've read the source dir
Dir_Idx : Natural;
-- Index in the Source_Dirs attribute that designes the subdir this
-- source belongs to.
Path : Filename_Optional (1 .. Path_Len);
-- Full path to the file
end record;
overriding function "=" (F1, F2 : File_Info) return Boolean is
(F1.Path = F2.Path);
function "<" (F1, F2 : File_Info) return Boolean is
(F1.Path < F2.Path);
function Hash (F : File_Info) return Ada.Containers.Hash_Type is
(GPR2.Hash (F.Path));
package File_Info_Maps is new Ada.Containers.Indefinite_Hashed_Maps
(Simple_Name, File_Info, Hash, "=");
package File_Sets is new Ada.Containers.Indefinite_Ordered_Sets
(File_Info);
package Basename_Sets is new Ada.Containers.Indefinite_Hashed_Sets
(Simple_Name, Hash, "=");
package Name_Maps is new Ada.Containers.Indefinite_Hashed_Maps
(Name_Type, Name_Type, Hash, "=");
-- Source handling:
-- The sources in the Database are updated by delta comparison with
-- the previous list of sources, to speed up the load of a project from
-- an existing database.
--
-- To handle efficiently such update, and handle properly the visibility
-- of the sources, as well as ensuring data consistency accross views,
-- the following structures are used:
-- * Self.Src_Files: this is the simplest structure as it just represents
-- the file entries in the various source directories declared in the
-- view. This list is used to know files deleted/modified/added between
-- two updates of the database.
-- * Self.Src_Infos: the view's own sources (e.g. sources found in the
-- view's source directories. The values contain various information
-- such as source language, kind, etc. This is the only table that has
-- this information: all other tables will contain references to this
-- table.
-- * Self.Sources: indexed by simple names, points to the actual source
-- info object for each simple name.
-- * Self.Hidden_Sources: indexed by simple names, points to a list of
-- sources that are not visible (because of overloading or errors).
package Src_Info_Maps is new Ada.Containers.Indefinite_Hashed_Maps
(Filename_Optional, Build.Source_Base.Object,
Hash, "=", Source_Base."=");
type Source_Proxy (Path_Len : Natural) is record
View : GPR2.Project.View.Object;
-- The view that owns the source (e.g. that has the source via its
-- source directory or source list)
Inh_From : GPR2.Project.View.Object;
-- Points to the extended view if any, from which the current view
-- inherits the source
Path_Name : Filename_Optional (1 .. Path_Len);
-- The source path name
end record;
No_Proxy : constant Source_Proxy := (Path_Len => 0, others => <>);
function Hash (Proxy : Source_Proxy) return Ada.Containers.Hash_Type
is (GPR2.Hash (Proxy.Path_Name) + View_Ids.Hash (Proxy.View.Id));
package Source_Proxy_Sets is new Ada.Containers.Indefinite_Hashed_Sets
(Source_Proxy, Hash, "=");
-- A set of source reference
package Basename_Source_Maps is new Ada.Containers.Indefinite_Hashed_Maps
(Simple_Name, Source_Proxy, Hash, "=");
-- Basename to source reference maps
package Basename_Source_List_Maps is new
Ada.Containers.Indefinite_Hashed_Maps
(Simple_Name, Source_Proxy_Sets.Set, Hash, "=", Source_Proxy_Sets."=");
-- Basename to source reference list
package Compilation_Unit_Maps is new Ada.Containers.Indefinite_Hashed_Maps
(Name_Type, Compilation_Unit.Object, Hash, "=", Compilation_Unit."=");
package Sources_By_Langs_Maps is new Ada.Containers.Hashed_Maps
(GPR2.Language_Id, Natural, Hash, "=");
package Unit_Maps is new Ada.Containers.Indefinite_Hashed_Maps
(Name_Type,
GPR2.Project.View.Set.Object,
GPR2.Hash,
GPR2."=",
GPR2.Project.View.Set."=");
package Temp_File_Maps is new Ada.Containers.Indefinite_Ordered_Maps
(Simple_Name, Filename_Type);
package Source_Set renames GPR2.Containers.Filename_Type_Set;
type View_Data (Is_Root : Boolean) is record
-- Static data:
Tree_Db : access GPR2.Build.Tree_Db.Object;
View : GPR2.Project.View.Object;
-- Owning view
-- Dynamic data
Sources : Basename_Source_Maps.Map;
-- Sources to take into account for View after visibility is resolved.
Overloaded_Srcs : Basename_Source_List_Maps.Map;
-- Keeps track of source overloading, to reassess source visibility or
-- erroneous cases when a source is added or removed.
Src_Infos : Src_Info_Maps.Map;
-- Sources identified in the source directories of the view, indexed
-- by their full names.
Src_Files : File_Sets.Set;
-- raw list of files found in the source directories, used to check
-- updates
Langs_Usage : Sources_By_Langs_Maps.Map;
-- Indicates the number of sources per language. Allows detecting
-- unused languages.
Listed_Sources : Source_Set.Set;
-- content of Source_Files and Source_List_File attributes
Excluded_Sources : Containers.Source_Path_To_Sloc.Map;
-- content of Excluded_Source_Files and Excluded_Source_List_File
-- attributes.
Actually_Excluded : Source_Set.Set;
-- list of excluded_sources items that matched at least one source
Own_CUs : Unit_Maps.Map;
-- The compilation units whose main unit belongs to the table's view
Temp_Files : Temp_File_Maps.Map;
-- Holds the path of temp files created during build
case Is_Root is
when True =>
CUs : Compilation_Unit_Maps.Map;
-- List of compilation units, indexed by their identifier
--
-- Note: Compilation units are stored in root projects: for
-- aggregate projects, each root project has its own list
-- to prevent clashes between independant subtrees.
Separates : Name_Maps.Map;
-- Map of separates to their declaring unit. Note that the
-- parent unit may not be a compilation unit but another separate
when False =>
null;
end case;
end record;
package Data_Refs is new GNATCOLL.Refcount.Shared_Pointers (View_Data);
subtype View_Data_Ref is Data_Refs.Reference_Type;
procedure Check_Source_Lists
(Data : View_Data_Ref;
Messages : in out GPR2.Log.Object);
-- Check the attributes Source_File_List, Source_Files,
-- Excluded_Source_File_List and Excluded_Source_Files and fill the
-- corresponding structures in Data.
-- To be called before refreshing the sources.
procedure Add_Source
(Data : View_Data_Ref;
View_Owner : GPR2.Project.View.Object;
Path : Filename_Type;
Extended_View : GPR2.Project.View.Object;
Resolve_Visibility : Boolean := False;
Messages : in out GPR2.Log.Object)
with Inline;
procedure Remove_Source
(Data : View_Data_Ref;
View_Owner : GPR2.Project.View.Object;
Path : Filename_Type;
Extended_View : GPR2.Project.View.Object;
Resolve_Visibility : Boolean := False;
Messages : in out GPR2.Log.Object)
with Inline;
procedure Refresh
(Data : View_Data_Ref;
Messages : in out GPR2.Log.Object);
View_Base_For : access function
(Data : View_Data) return View_Db.Object;
Get_Ref : access function
(Obj : View_Db.Object) return View_Data_Ref;
function Source
(Data : View_Data_Ref;
Basename : Simple_Name) return Build.Source.Object;
function Visible_Source
(Data : View_Data_Ref;
Basename : Simple_Name) return Build.Source.Object;
function Get_Data
(Db : access GPR2.Build.Tree_Db.Object;
View : GPR2.Project.View.Object) return View_Data_Ref;
end GPR2.Build.View_Tables;
|