annotate gcc/ada/scos.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S C O S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2009-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- This package defines tables used to store Source Coverage Obligations. It
kono
parents:
diff changeset
27 -- is used by Par_SCO to build the SCO information before writing it out to
kono
parents:
diff changeset
28 -- the ALI file, and by Get_SCO/Put_SCO to read and write the text form that
kono
parents:
diff changeset
29 -- is used in the ALI file.
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 with Namet; use Namet;
kono
parents:
diff changeset
32 with Table;
kono
parents:
diff changeset
33 with Types; use Types;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 package SCOs is
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 -- SCO information can exist in one of two forms. In the ALI file, it is
kono
parents:
diff changeset
38 -- represented using a text format that is described in this specification.
kono
parents:
diff changeset
39 -- Internally it is stored using two tables SCO_Table and SCO_Unit_Table,
kono
parents:
diff changeset
40 -- which are also defined in this unit.
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 -- Par_SCO is part of the compiler. It scans the parsed source tree and
kono
parents:
diff changeset
43 -- populates the internal tables.
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 -- Get_SCO reads the text lines in ALI format and populates the internal
kono
parents:
diff changeset
46 -- tables with corresponding information.
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 -- Put_SCO reads the internal tables and generates text lines in the ALI
kono
parents:
diff changeset
49 -- format.
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 -- WARNING: There are C bindings for this package. Any changes to this
kono
parents:
diff changeset
52 -- source file must be properly reflected in the C header file scos.h
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 --------------------
kono
parents:
diff changeset
55 -- SCO ALI Format --
kono
parents:
diff changeset
56 --------------------
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 -- Source coverage obligations are generated on a unit-by-unit basis in the
kono
parents:
diff changeset
59 -- ALI file, using lines that start with the identifying character C. These
kono
parents:
diff changeset
60 -- lines are generated if the -gnateS switch is set.
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 -- Sloc Ranges
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 -- In several places in the SCO lines, Sloc ranges appear. These are used
kono
parents:
diff changeset
65 -- to indicate the first and last Sloc of some construct in the tree and
kono
parents:
diff changeset
66 -- they have the form:
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 -- line:col-line:col
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 -- Note that SCO's are generated only for generic templates, not for
kono
parents:
diff changeset
71 -- generic instances (since only the first are part of the source). So
kono
parents:
diff changeset
72 -- we don't need generic instantiation stuff in these line:col items.
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 -- SCO File headers
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 -- The SCO information follows the cross-reference information, so it
kono
parents:
diff changeset
77 -- need not be read by tools like gnatbind, gnatmake etc. The SCO output
kono
parents:
diff changeset
78 -- is divided into sections, one section for each unit for which SCO's
kono
parents:
diff changeset
79 -- are generated. A SCO section has a header of the form:
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 -- C dependency-number filename
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 -- This header precedes SCO information for the unit identified by
kono
parents:
diff changeset
84 -- dependency number and file name. The dependency number is the
kono
parents:
diff changeset
85 -- index into the generated D lines and is ones origin (i.e. 2 =
kono
parents:
diff changeset
86 -- reference to second generated D line).
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 -- Note that the filename here will reflect the original name if
kono
parents:
diff changeset
89 -- a Source_Reference pragma was encountered (since all line number
kono
parents:
diff changeset
90 -- references will be with respect to the original file).
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 -- Note: the filename is redundant in that it could be deduced from
kono
parents:
diff changeset
93 -- the corresponding D line, but it is convenient at least for human
kono
parents:
diff changeset
94 -- reading of the SCO information, and means that the SCO information
kono
parents:
diff changeset
95 -- can stand on its own without needing other parts of the ALI file.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 -- Statements
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 -- For the purpose of SCO generation, the notion of statement includes
kono
parents:
diff changeset
100 -- simple statements and also the following declaration types:
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 -- type_declaration
kono
parents:
diff changeset
103 -- subtype_declaration
kono
parents:
diff changeset
104 -- object_declaration
kono
parents:
diff changeset
105 -- renaming_declaration
kono
parents:
diff changeset
106 -- generic_instantiation
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 -- and the following regions of the syntax tree:
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 -- the part of a case_statement from CASE up to the expression
kono
parents:
diff changeset
111 -- the part of a FOR loop iteration scheme from FOR up to the
kono
parents:
diff changeset
112 -- loop_parameter_specification
kono
parents:
diff changeset
113 -- the part of a WHILE loop up to the condition
kono
parents:
diff changeset
114 -- the part of an extended_return_statement from RETURN up to the
kono
parents:
diff changeset
115 -- expression (if present) or to the return_subtype_indication (if
kono
parents:
diff changeset
116 -- no expression)
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 -- and any pragma that occurs at a place where a statement or declaration
kono
parents:
diff changeset
119 -- is allowed.
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 -- Statement lines
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 -- These lines correspond to one or more successive statements (in the
kono
parents:
diff changeset
124 -- sense of the above list) which are always executed in sequence (in the
kono
parents:
diff changeset
125 -- absence of exceptions or other external interruptions).
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 -- Entry points to such sequences are:
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 -- the first declaration of any declarative_part
kono
parents:
diff changeset
130 -- the first statement of any sequence_of_statements that is not in a
kono
parents:
diff changeset
131 -- body or block statement that has a non-empty declarative part
kono
parents:
diff changeset
132 -- the first statement after a compound statement
kono
parents:
diff changeset
133 -- the first statement after an EXIT, RAISE or GOTO statement
kono
parents:
diff changeset
134 -- any statement with a label (the label itself is not part of the
kono
parents:
diff changeset
135 -- entry point that is recorded).
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 -- Each entry point must appear as the first statement entry on a CS
kono
parents:
diff changeset
138 -- line. Thus, if any simple statement on a CS line is known to have
kono
parents:
diff changeset
139 -- been executed, then all statements that appear before it on the same
kono
parents:
diff changeset
140 -- CS line are certain to also have been executed.
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 -- The form of a statement line in the ALI file is:
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 -- CS [dominance] *sloc-range [*sloc-range...]
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 -- where each sloc-range corresponds to a single statement, and * is
kono
parents:
diff changeset
147 -- one of:
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 -- t type declaration
kono
parents:
diff changeset
150 -- s subtype declaration
kono
parents:
diff changeset
151 -- o object declaration
kono
parents:
diff changeset
152 -- r renaming declaration
kono
parents:
diff changeset
153 -- i generic instantiation
kono
parents:
diff changeset
154 -- d any other kind of declaration
kono
parents:
diff changeset
155 -- A ACCEPT statement (from ACCEPT to end of parameter profile)
kono
parents:
diff changeset
156 -- C CASE statement (from CASE to end of expression)
kono
parents:
diff changeset
157 -- E EXIT statement
kono
parents:
diff changeset
158 -- F FOR loop (from FOR to end of iteration scheme)
kono
parents:
diff changeset
159 -- I IF statement (from IF to end of condition)
kono
parents:
diff changeset
160 -- P[name:] PRAGMA with the indicated name
kono
parents:
diff changeset
161 -- p[name:] disabled PRAGMA with the indicated name
kono
parents:
diff changeset
162 -- R extended RETURN statement
kono
parents:
diff changeset
163 -- S SELECT statement
kono
parents:
diff changeset
164 -- W WHILE loop statement (from WHILE to end of condition)
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 -- Note: for I and W, condition above is in the RM syntax sense (this
kono
parents:
diff changeset
167 -- condition is a decision in SCO terminology).
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 -- and is omitted for all other cases
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 -- The optional dominance marker is of the form gives additional
kono
parents:
diff changeset
172 -- information as to how the sequence of statements denoted by the CS
kono
parents:
diff changeset
173 -- line can be entered:
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 -- >F<sloc>
kono
parents:
diff changeset
176 -- sequence is entered only if the decision at <sloc> is False
kono
parents:
diff changeset
177 -- >T<sloc>
kono
parents:
diff changeset
178 -- sequence is entered only if the decision at <sloc> is True
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 -- >S<sloc>
kono
parents:
diff changeset
181 -- sequence is entered only if the statement at <sloc> has been
kono
parents:
diff changeset
182 -- executed
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 -- >E<sloc-range>
kono
parents:
diff changeset
185 -- sequence is the sequence of statements for a exception_handler
kono
parents:
diff changeset
186 -- with the given sloc range
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 -- Note: up to 6 entries can appear on a single CS line. If more than 6
kono
parents:
diff changeset
189 -- entries appear in one logical statement sequence, continuation lines
kono
parents:
diff changeset
190 -- are marked by Cs and appear immediately after the CS line.
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 -- Implementation permission: a SCO generator is permitted to emit a
kono
parents:
diff changeset
193 -- narrower SLOC range for a statement if the corresponding code
kono
parents:
diff changeset
194 -- generation circuitry ensures that all debug information for the code
kono
parents:
diff changeset
195 -- implementing the statement will be labeled with SLOCs that fall within
kono
parents:
diff changeset
196 -- that narrower range.
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 -- Decisions
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 -- Note: in the following description, logical operator includes only the
kono
parents:
diff changeset
201 -- short-circuited forms and NOT (so can be only NOT, AND THEN, OR ELSE).
kono
parents:
diff changeset
202 -- The reason that we can exclude AND/OR/XOR is that we expect SCO's to
kono
parents:
diff changeset
203 -- be generated using the restriction No_Direct_Boolean_Operators if we
kono
parents:
diff changeset
204 -- are interested in decision coverage, which does not permit the use of
kono
parents:
diff changeset
205 -- AND/OR/XOR on boolean operands. These are permitted on modular integer
kono
parents:
diff changeset
206 -- types, but such operations do not count as decisions in any case. If
kono
parents:
diff changeset
207 -- we are generating SCO's only for simple coverage, then we are not
kono
parents:
diff changeset
208 -- interested in decisions in any case.
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 -- Note: the reason we include NOT is for informational purposes. The
kono
parents:
diff changeset
211 -- presence of NOT does not generate additional coverage obligations,
kono
parents:
diff changeset
212 -- but if we know where the NOT's are, the coverage tool can generate
kono
parents:
diff changeset
213 -- more accurate diagnostics on uncovered tests.
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 -- A top level boolean expression is a boolean expression that is not an
kono
parents:
diff changeset
216 -- operand of a logical operator.
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 -- Decisions are either simple or complex. A simple decision is a top
kono
parents:
diff changeset
219 -- level boolean expression that has only one condition and that occurs
kono
parents:
diff changeset
220 -- in the context of a control structure in the source program, including
kono
parents:
diff changeset
221 -- WHILE, IF, EXIT WHEN, or immediately within an Assert, Check,
kono
parents:
diff changeset
222 -- Pre_Condition or Post_Condition pragma, or as the first argument of a
kono
parents:
diff changeset
223 -- dyadic pragma Debug. Note that a top level boolean expression with
kono
parents:
diff changeset
224 -- only one condition that occurs in any other context, for example as
kono
parents:
diff changeset
225 -- right hand side of an assignment, is not considered to be a (simple)
kono
parents:
diff changeset
226 -- decision.
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 -- A complex decision is a top level boolean expression that has more
kono
parents:
diff changeset
229 -- than one condition. A complex decision may occur in any boolean
kono
parents:
diff changeset
230 -- expression context.
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 -- So for example, if we have
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 -- A, B, C, D : Boolean;
kono
parents:
diff changeset
235 -- function F (Arg : Boolean) return Boolean);
kono
parents:
diff changeset
236 -- ...
kono
parents:
diff changeset
237 -- A and then (B or else F (C and then D))
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 -- There are two (complex) decisions here:
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 -- 1. X and then (Y or else Z)
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 -- where X = A, Y = B, and Z = F (C and then D)
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 -- 2. C and then D
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 -- For each decision, a decision line is generated with the form:
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 -- C* sloc expression
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 -- Here * is one of the following:
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 -- E decision in EXIT WHEN statement
kono
parents:
diff changeset
254 -- G decision in entry guard
kono
parents:
diff changeset
255 -- I decision in IF statement or if expression
kono
parents:
diff changeset
256 -- P decision in pragma Assert / Check / Pre/Post_Condition
kono
parents:
diff changeset
257 -- A[name] decision in aspect Pre/Post (aspect name optional)
kono
parents:
diff changeset
258 -- W decision in WHILE iteration scheme
kono
parents:
diff changeset
259 -- X decision in some other expression context
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 -- For E, G, I, P, W, sloc is the source location of the EXIT, ENTRY, IF,
kono
parents:
diff changeset
262 -- PRAGMA or WHILE token, respectively
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 -- For A sloc is the source location of the aspect identifier
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 -- For X, sloc is omitted
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 -- The expression is a prefix polish form indicating the structure of
kono
parents:
diff changeset
269 -- the decision, including logical operators and short-circuit forms.
kono
parents:
diff changeset
270 -- The following is a grammar showing the structure of expression:
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 -- expression ::= term (if expr is not logical operator)
kono
parents:
diff changeset
273 -- expression ::= &sloc term term (if expr is AND or AND THEN)
kono
parents:
diff changeset
274 -- expression ::= |sloc term term (if expr is OR or OR ELSE)
kono
parents:
diff changeset
275 -- expression ::= !sloc term (if expr is NOT)
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 -- In the last three cases, sloc is the source location of the AND, OR,
kono
parents:
diff changeset
278 -- or NOT token, respectively.
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 -- term ::= element
kono
parents:
diff changeset
281 -- term ::= expression
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 -- element ::= *sloc-range
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 -- where * is one of the following letters:
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 -- c condition
kono
parents:
diff changeset
288 -- t true condition
kono
parents:
diff changeset
289 -- f false condition
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 -- t/f are used to mark a condition that has been recognized by the
kono
parents:
diff changeset
292 -- compiler as always being true or false. c is the normal case of
kono
parents:
diff changeset
293 -- conditions whose value is not known at compile time.
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 -- & indicates AND THEN connecting two conditions
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 -- | indicates OR ELSE connecting two conditions
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 -- ! indicates NOT applied to the expression
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 -- Note that complex decisions do NOT include non-short-circuited logical
kono
parents:
diff changeset
302 -- operators (AND/XOR/OR). In the context of existing coverage tools the
kono
parents:
diff changeset
303 -- No_Direct_Boolean_Operators restriction is assumed, so these operators
kono
parents:
diff changeset
304 -- cannot appear in the source in any case.
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 -- The SCO line for a decision always occurs after the CS line for the
kono
parents:
diff changeset
307 -- enclosing statement. The SCO line for a nested decision always occurs
kono
parents:
diff changeset
308 -- after the line for the enclosing decision.
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 -- Note that membership tests are considered to be a single simple
kono
parents:
diff changeset
311 -- condition, and that is true even if the Ada 2005 set membership
kono
parents:
diff changeset
312 -- form is used, e.g. A in (2,7,11.15).
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 -- Implementation permission: a SCO generator is permitted to emit a
kono
parents:
diff changeset
315 -- narrower SLOC range for a condition if the corresponding code
kono
parents:
diff changeset
316 -- generation circuitry ensures that all debug information for the code
kono
parents:
diff changeset
317 -- evaluating the condition will be labeled with SLOCs that fall within
kono
parents:
diff changeset
318 -- that narrower range.
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 -- Case Expressions
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 -- For case statements, we rely on statement coverage to make sure that
kono
parents:
diff changeset
323 -- all branches of a case statement are covered, but that does not work
kono
parents:
diff changeset
324 -- for case expressions, since the entire expression is contained in a
kono
parents:
diff changeset
325 -- single statement. However, for complete coverage we really should be
kono
parents:
diff changeset
326 -- able to check that every branch of the case statement is covered, so
kono
parents:
diff changeset
327 -- we generate a SCO of the form:
kono
parents:
diff changeset
328
kono
parents:
diff changeset
329 -- CC sloc-range sloc-range ...
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 -- where sloc-range covers the range of the case expression
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 -- Note: up to 6 entries can appear on a single CC line. If more than 6
kono
parents:
diff changeset
334 -- entries appear in one logical statement sequence, continuation lines
kono
parents:
diff changeset
335 -- are marked by Cc and appear immediately after the CC line.
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 -- Generic instances
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 -- A table of all generic instantiations in the compilation is generated
kono
parents:
diff changeset
340 -- whose entries have the form:
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 -- C i index dependency-number|sloc [enclosing]
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 -- Where index is the 1-based index of the entry in the table,
kono
parents:
diff changeset
345 -- dependency-number and sloc indicate the source location of the
kono
parents:
diff changeset
346 -- instantiation, and enclosing is the index of the enclosing
kono
parents:
diff changeset
347 -- instantiation in the table (for a nested instantiation), or is
kono
parents:
diff changeset
348 -- omitted for an outer instantiation.
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 -- Disabled pragmas
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 -- No SCO is generated for disabled pragmas
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 ---------------------------------------------------------------------
kono
parents:
diff changeset
355 -- Internal table used to store Source Coverage Obligations (SCOs) --
kono
parents:
diff changeset
356 ---------------------------------------------------------------------
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 type Source_Location is record
kono
parents:
diff changeset
359 Line : Logical_Line_Number;
kono
parents:
diff changeset
360 Col : Column_Number;
kono
parents:
diff changeset
361 end record;
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 No_Source_Location : constant Source_Location :=
kono
parents:
diff changeset
364 (No_Line_Number, No_Column_Number);
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 type SCO_Table_Entry is record
kono
parents:
diff changeset
367 From : Source_Location := No_Source_Location;
kono
parents:
diff changeset
368 To : Source_Location := No_Source_Location;
kono
parents:
diff changeset
369 C1 : Character := ' ';
kono
parents:
diff changeset
370 C2 : Character := ' ';
kono
parents:
diff changeset
371 Last : Boolean := False;
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 Pragma_Sloc : Source_Ptr := No_Location;
kono
parents:
diff changeset
374 -- For the decision SCO of a pragma, or for the decision SCO of any
kono
parents:
diff changeset
375 -- expression nested in a pragma Debug/Assert/PPC, location of PRAGMA
kono
parents:
diff changeset
376 -- token (used for control of SCO output, value not recorded in ALI
kono
parents:
diff changeset
377 -- file). Similarly, for the decision SCO of an aspect, or for the
kono
parents:
diff changeset
378 -- decision SCO of any expression nested in an aspect, location of
kono
parents:
diff changeset
379 -- aspect identifier token.
kono
parents:
diff changeset
380
kono
parents:
diff changeset
381 Pragma_Aspect_Name : Name_Id := No_Name;
kono
parents:
diff changeset
382 -- For the SCO for a pragma/aspect, gives the pragma/apsect name
kono
parents:
diff changeset
383 end record;
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 package SCO_Table is new Table.Table (
kono
parents:
diff changeset
386 Table_Component_Type => SCO_Table_Entry,
kono
parents:
diff changeset
387 Table_Index_Type => Nat,
kono
parents:
diff changeset
388 Table_Low_Bound => 1,
kono
parents:
diff changeset
389 Table_Initial => 500,
kono
parents:
diff changeset
390 Table_Increment => 300,
kono
parents:
diff changeset
391 Table_Name => "Table");
kono
parents:
diff changeset
392
kono
parents:
diff changeset
393 Is_Decision : constant array (Character) of Boolean :=
kono
parents:
diff changeset
394 ('E' | 'G' | 'I' | 'P' | 'a' | 'A' | 'W' | 'X' => True,
kono
parents:
diff changeset
395 others => False);
kono
parents:
diff changeset
396 -- Indicates which C1 values correspond to decisions
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 -- The SCO_Table_Entry values appear as follows:
kono
parents:
diff changeset
399
kono
parents:
diff changeset
400 -- Statements
kono
parents:
diff changeset
401 -- C1 = 'S'
kono
parents:
diff changeset
402 -- C2 = statement type code to appear on CS line (or ' ' if none)
kono
parents:
diff changeset
403 -- From = starting source location
kono
parents:
diff changeset
404 -- To = ending source location
kono
parents:
diff changeset
405 -- Last = False for all but the last entry, True for last entry
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407 -- Note: successive statements (possibly interspersed with entries of
kono
parents:
diff changeset
408 -- other kinds, that are ignored for this purpose), starting with one
kono
parents:
diff changeset
409 -- labeled with C1 = 'S', up to and including the first one labeled with
kono
parents:
diff changeset
410 -- Last = True, indicate the sequence to be output for a sequence of
kono
parents:
diff changeset
411 -- statements on a single CS line (possibly followed by Cs continuation
kono
parents:
diff changeset
412 -- lines).
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 -- Note: for a pragma that may be disabled (Debug, Assert, PPC, Check),
kono
parents:
diff changeset
415 -- the entry is initially created with C2 = 'p', to mark it as disabled.
kono
parents:
diff changeset
416 -- Later on during semantic analysis, if the pragma is enabled,
kono
parents:
diff changeset
417 -- Set_SCO_Pragma_Enabled changes C2 to 'P' to cause the entry to be
kono
parents:
diff changeset
418 -- emitted in Put_SCOs.
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 -- Dominance marker
kono
parents:
diff changeset
421 -- C1 = '>'
kono
parents:
diff changeset
422 -- C2 = 'F'/'T'/'S'/'E'
kono
parents:
diff changeset
423 -- From = Decision/statement sloc ('F'/'T'/'S'),
kono
parents:
diff changeset
424 -- handler first sloc ('E')
kono
parents:
diff changeset
425 -- To = No_Source_Location ('F'/'T'/'S'), handler last sloc ('E')
kono
parents:
diff changeset
426
kono
parents:
diff changeset
427 -- Note: A dominance marker is always followed by a statement entry
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 -- Decision (EXIT/entry guard/IF/WHILE)
kono
parents:
diff changeset
430 -- C1 = 'E'/'G'/'I'/'W' (for EXIT/entry Guard/IF/WHILE)
kono
parents:
diff changeset
431 -- C2 = ' '
kono
parents:
diff changeset
432 -- From = EXIT/ENTRY/IF/WHILE token
kono
parents:
diff changeset
433 -- To = No_Source_Location
kono
parents:
diff changeset
434 -- Last = unused
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 -- Decision (PRAGMA)
kono
parents:
diff changeset
437 -- C1 = 'P'
kono
parents:
diff changeset
438 -- C2 = ' '
kono
parents:
diff changeset
439 -- From = PRAGMA token
kono
parents:
diff changeset
440 -- To = No_Source_Location
kono
parents:
diff changeset
441 -- Last = unused
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 -- Note: when the parse tree is first scanned, we unconditionally build a
kono
parents:
diff changeset
444 -- pragma decision entry for any decision in a pragma (here as always in
kono
parents:
diff changeset
445 -- SCO contexts, the only pragmas with decisions are Assert, Check,
kono
parents:
diff changeset
446 -- dyadic Debug, Precondition and Postcondition). These entries will
kono
parents:
diff changeset
447 -- be omitted in output if the pragma is disabled (see comments for
kono
parents:
diff changeset
448 -- statement entries): this filtering is achieved during the second pass
kono
parents:
diff changeset
449 -- of SCO generation (Par_SCO.SCO_Record_Filtered).
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 -- Decision (ASPECT)
kono
parents:
diff changeset
452 -- C1 = 'A'
kono
parents:
diff changeset
453 -- C2 = ' '
kono
parents:
diff changeset
454 -- From = aspect identifier
kono
parents:
diff changeset
455 -- To = No_Source_Location
kono
parents:
diff changeset
456 -- Last = unused
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 -- Note: when the parse tree is first scanned, we unconditionally build a
kono
parents:
diff changeset
459 -- pragma decision entry for any decision in an aspect (Pre/Post/
kono
parents:
diff changeset
460 -- [Type_]Invariant/[Static_|Dynamic_]Predicate). Entries for disabled
kono
parents:
diff changeset
461 -- Pre/Post aspects will be omitted from output.
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 -- Decision (Expression)
kono
parents:
diff changeset
464 -- C1 = 'X'
kono
parents:
diff changeset
465 -- C2 = ' '
kono
parents:
diff changeset
466 -- From = No_Source_Location
kono
parents:
diff changeset
467 -- To = No_Source_Location
kono
parents:
diff changeset
468 -- Last = unused
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 -- Operator
kono
parents:
diff changeset
471 -- C1 = '!', '&', '|'
kono
parents:
diff changeset
472 -- C2 = ' '/'?'/ (Logical operator/Putative one)
kono
parents:
diff changeset
473 -- From = location of NOT/AND/OR token
kono
parents:
diff changeset
474 -- To = No_Source_Location
kono
parents:
diff changeset
475 -- Last = False
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 -- Element (condition)
kono
parents:
diff changeset
478 -- C1 = ' '
kono
parents:
diff changeset
479 -- C2 = 'c', 't', or 'f' (condition/true/false)
kono
parents:
diff changeset
480 -- From = starting source location
kono
parents:
diff changeset
481 -- To = ending source location
kono
parents:
diff changeset
482 -- Last = False for all but the last entry, True for last entry
kono
parents:
diff changeset
483
kono
parents:
diff changeset
484 -- Note: the sequence starting with a decision, and continuing with
kono
parents:
diff changeset
485 -- operators and elements up to and including the first one labeled with
kono
parents:
diff changeset
486 -- Last = True, indicate the sequence to be output on one decision line.
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 ----------------
kono
parents:
diff changeset
489 -- Unit Table --
kono
parents:
diff changeset
490 ----------------
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 -- This table keeps track of the units and the corresponding starting and
kono
parents:
diff changeset
493 -- ending indexes (From, To) in the SCO table. Note that entry zero is
kono
parents:
diff changeset
494 -- present but unused, it is for convenience in calling the sort routine.
kono
parents:
diff changeset
495 -- Thus the lower bound for real entries is 1.
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 type SCO_Unit_Index is new Int;
kono
parents:
diff changeset
498 -- Used to index values in this table. Values start at 1 and are assigned
kono
parents:
diff changeset
499 -- sequentially as entries are constructed.
kono
parents:
diff changeset
500
kono
parents:
diff changeset
501 Missing_Dep_Num : constant Nat := 0;
kono
parents:
diff changeset
502 -- Represents a dependency number for a dependency that is ignored. SCO
kono
parents:
diff changeset
503 -- information consumers use this to strip units that must be kept out of
kono
parents:
diff changeset
504 -- the coverage analysis.
kono
parents:
diff changeset
505
kono
parents:
diff changeset
506 type SCO_Unit_Table_Entry is record
kono
parents:
diff changeset
507 File_Name : String_Ptr;
kono
parents:
diff changeset
508 -- Pointer to file name in ALI file
kono
parents:
diff changeset
509
kono
parents:
diff changeset
510 File_Index : Source_File_Index;
kono
parents:
diff changeset
511 -- Index for the source file
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 Dep_Num : Nat;
kono
parents:
diff changeset
514 -- Dependency number in ALI file. This is a positive number when the
kono
parents:
diff changeset
515 -- dependency is actually available in the context, it is
kono
parents:
diff changeset
516 -- Missing_Dep_Num otherwise.
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 From : Nat;
kono
parents:
diff changeset
519 -- Starting index in SCO_Table of SCO information for this unit
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 To : Nat;
kono
parents:
diff changeset
522 -- Ending index in SCO_Table of SCO information for this unit
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 -- Warning: SCOs generation (in Par_SCO) is done in two passes, which
kono
parents:
diff changeset
525 -- communicate through an intermediate table (Par_SCO.SCO_Raw_Table).
kono
parents:
diff changeset
526 -- Before the second pass executes, From and To actually reference index
kono
parents:
diff changeset
527 -- in the internal table: SCO_Table is empty. Then, at the end of the
kono
parents:
diff changeset
528 -- second pass, these indexes are updated in order to reference indexes
kono
parents:
diff changeset
529 -- in SCO_Table.
kono
parents:
diff changeset
530
kono
parents:
diff changeset
531 end record;
kono
parents:
diff changeset
532
kono
parents:
diff changeset
533 package SCO_Unit_Table is new Table.Table (
kono
parents:
diff changeset
534 Table_Component_Type => SCO_Unit_Table_Entry,
kono
parents:
diff changeset
535 Table_Index_Type => SCO_Unit_Index,
kono
parents:
diff changeset
536 Table_Low_Bound => 0, -- see note above on sorting
kono
parents:
diff changeset
537 Table_Initial => 20,
kono
parents:
diff changeset
538 Table_Increment => 200,
kono
parents:
diff changeset
539 Table_Name => "Unit_Table");
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 -----------------------
kono
parents:
diff changeset
542 -- Generic instances --
kono
parents:
diff changeset
543 -----------------------
kono
parents:
diff changeset
544
kono
parents:
diff changeset
545 type SCO_Instance_Index is new Nat;
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 type SCO_Instance_Table_Entry is record
kono
parents:
diff changeset
548 Inst_Dep_Num : Nat;
kono
parents:
diff changeset
549 Inst_Loc : Source_Location;
kono
parents:
diff changeset
550 -- File and source location of instantiation
kono
parents:
diff changeset
551
kono
parents:
diff changeset
552 Enclosing_Instance : SCO_Instance_Index;
kono
parents:
diff changeset
553 end record;
kono
parents:
diff changeset
554
kono
parents:
diff changeset
555 package SCO_Instance_Table is new Table.Table (
kono
parents:
diff changeset
556 Table_Component_Type => SCO_Instance_Table_Entry,
kono
parents:
diff changeset
557 Table_Index_Type => SCO_Instance_Index,
kono
parents:
diff changeset
558 Table_Low_Bound => 1,
kono
parents:
diff changeset
559 Table_Initial => 20,
kono
parents:
diff changeset
560 Table_Increment => 200,
kono
parents:
diff changeset
561 Table_Name => "Instance_Table");
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 -----------------
kono
parents:
diff changeset
564 -- Subprograms --
kono
parents:
diff changeset
565 -----------------
kono
parents:
diff changeset
566
kono
parents:
diff changeset
567 procedure Initialize;
kono
parents:
diff changeset
568 -- Reset tables for a new compilation
kono
parents:
diff changeset
569
kono
parents:
diff changeset
570 end SCOs;