OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [ada/] [scos.ads] - Blame information for rev 308

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 281 jeremybenn
------------------------------------------------------------------------------
2
--                                                                          --
3
--                         GNAT COMPILER COMPONENTS                         --
4
--                                                                          --
5
--                                 S C O S                                  --
6
--                                                                          --
7
--                                 S p e c                                  --
8
--                                                                          --
9
--             Copyright (C) 2009, Free Software Foundation, Inc.           --
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 3,  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 COPYING3.  If not, go to --
19
-- http://www.gnu.org/licenses for a complete copy of the license.          --
20
--                                                                          --
21
-- GNAT was originally developed  by the GNAT team at  New York University. --
22
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
23
--                                                                          --
24
------------------------------------------------------------------------------
25
 
26
--  This package defines tables used to store Source Coverage Obligations. It
27
--  is used by Par_SCO to build the SCO information before writing it out to
28
--  the ALI file, and by Get_SCO/Put_SCO to read and write the text form that
29
--  is used in the ALI file.
30
 
31
with Types; use Types;
32
 
33
with GNAT.Table;
34
 
35
package SCOs is
36
 
37
   --  SCO information can exist in one of two forms. In the ALI file, it is
38
   --  represented using a text format that is described in this specification.
39
   --  Internally it is stored using two tables SCO_Table and SCO_Unit_Table,
40
   --  which are also defined in this unit.
41
 
42
   --  Par_SCO is part of the compiler. It scans the parsed source tree and
43
   --  populates the internal tables.
44
 
45
   --  Get_SCO reads the text lines in ALI format and populates the internal
46
   --  tables with corresponding information.
47
 
48
   --  Put_SCO reads the internal tables and generates text lines in the ALI
49
   --  format.
50
 
51
   --------------------
52
   -- SCO ALI Format --
53
   --------------------
54
 
55
   --  Source coverage obligations are generated on a unit-by-unit basis in the
56
   --  ALI file, using lines that start with the identifying character C. These
57
   --  lines are generated if the -gnateS switch is set.
58
 
59
   --  Sloc Ranges
60
 
61
   --    In several places in the SCO lines, Sloc ranges appear. These are used
62
   --    to indicate the first and last Sloc of some construct in the tree and
63
   --    they have the form:
64
 
65
   --      line:col-line:col
66
 
67
   --    Note that SCO's are generated only for generic templates, not for
68
   --    generic instances (since only the first are part of the source). So
69
   --    we don't need generic instantiation stuff in these line:col items.
70
 
71
   --  SCO File headers
72
 
73
   --    The SCO information follows the cross-reference information, so it
74
   --    need not be read by tools like gnatbind, gnatmake etc. The SCO output
75
   --    is divided into sections, one section for each unit for which SCO's
76
   --    are generated. A SCO section has a header of the form:
77
 
78
   --      C dependency-number filename
79
 
80
   --        This header precedes SCO information for the unit identified by
81
   --        dependency number and file name. The dependency number is the
82
   --        index into the generated D lines and is ones origin (i.e. 2 =
83
   --        reference to second generated D line).
84
 
85
   --        Note that the filename here will reflect the original name if
86
   --        a Source_Reference pragma was encountered (since all line number
87
   --        references will be with respect to the original file).
88
 
89
   --        Note: the filename is redundant in that it could be deduced from
90
   --        the corresponding D line, but it is convenient at least for human
91
   --        reading of the SCO information, and means that the SCO information
92
   --        can stand on its own without needing other parts of the ALI file.
93
 
94
   --  Statements
95
 
96
   --    For the purpose of SCO generation, the notion of statement includes
97
   --    simple statements and also the following declaration types:
98
 
99
   --      type_declaration
100
   --      subtype_declaration
101
   --      object_declaration
102
   --      renaming_declaration
103
   --      generic_instantiation
104
 
105
   --    and the following regions of the syntax tree:
106
 
107
   --      the part of a case_statement from CASE up to the expression
108
   --      the part of a FOR loop iteration scheme from FOR up to the
109
   --        loop_parameter_specification
110
   --      the part of a WHILE loop up to the condition
111
   --      the part of an extended_return_statement from RETURN up to the
112
   --        expression (if present) or to the return_subtype_indication (if
113
   --        no expression)
114
 
115
   --    and any pragma that occurs at a place where a statement or declaration
116
   --    is allowed.
117
 
118
   --  Statement lines
119
 
120
   --    These lines correspond to one or more successive statements (in the
121
   --    sense of the above list) which are always executed in sequence (in the
122
   --    absence of exceptions or other external interruptions).
123
 
124
   --    Entry points to such sequences are:
125
 
126
   --      the first declaration of any declarative_part
127
   --      the first statement of any sequence_of_statements that is not in a
128
   --        body or block statement that has a non-empty declarative part
129
   --      the first statement after a compound statement
130
   --      the first statement after an EXIT, RAISE or GOTO statement
131
   --      any statement with a label (the label itself is not part of the
132
   --       entry point that is recorded).
133
 
134
   --    Each entry point must appear as the first entry on a CS line.
135
   --    The idea is that if any simple statement on a CS line is known to have
136
   --    been executed, then all statements that appear before it on the same
137
   --    CS line are certain to also have been executed.
138
 
139
   --    The form of a statement line in the ALI file is:
140
 
141
   --      CS *sloc-range [*sloc-range...]
142
 
143
   --    where each sloc-range corresponds to a single statement, and * is
144
   --    one of:
145
 
146
   --      t  type declaration
147
   --      s  subtype declaration
148
   --      o  object declaration
149
   --      r  renaming declaration
150
   --      i  generic instantiation
151
   --      C  CASE statement (includes only the expression)
152
   --      E  EXIT statement
153
   --      F  FOR loop statement (includes only the iteration scheme)
154
   --      I  IF statement (includes only the condition [in the RM sense, which
155
   --         is a decision in the SCO sense])
156
   --      P  PRAGMA
157
   --      R  extended RETURN statement
158
   --      W  WHILE loop statement (includes only the condition)
159
 
160
   --    and is omitted for all other cases.
161
 
162
   --  Decisions
163
 
164
   --    Note: in the following description, logical operator includes only the
165
   --    short circuited forms and NOT (so can be only NOT, AND THEN, OR ELSE).
166
   --    The reason that we can exclude AND/OR/XOR is that we expect SCO's to
167
   --    be generated using the restriction No_Direct_Boolean_Operators if we
168
   --    are interested in decision coverage, which does not permit the use of
169
   --    AND/OR/XOR on boolean operands. These are permitted on modular integer
170
   --    types, but such operations do not count as decisions in any case. If
171
   --    we are generating SCO's only for simple coverage, then we are not
172
   --    interested in decisions in any case.
173
 
174
   --    Decisions are either simple or complex. A simple decision is a boolean
175
   --    expresssion that occurs in the context of a control structure in the
176
   --    source program, including WHILE, IF, EXIT WHEN, or in an Assert,
177
   --    Check, Pre_Condition or Post_Condition pragma. For pragmas, decision
178
   --    SCOs are generated only if the corresponding pragma is enabled. Note
179
   --    that a boolean expression in any other context, for example as right
180
   --    hand side of an assignment, is not considered to be a simple decision.
181
 
182
   --    A complex decision is an occurrence of a logical operator which is not
183
   --    itself an operand of some other logical operator. If any operand of
184
   --    the logical operator is itself a logical operator, this is not a
185
   --    separate decision, it is part of the same decision.
186
 
187
   --    So for example, if we have
188
 
189
   --        A, B, C, D : Boolean;
190
   --        function F (Arg : Boolean) return Boolean);
191
   --        ...
192
   --        A and then (B or else F (C and then D))
193
 
194
   --    There are two (complex) decisions here:
195
 
196
   --        1. X and then (Y or else Z)
197
 
198
   --           where X = A, Y = B, and Z = F (C and then D)
199
 
200
   --        2. C and then D
201
 
202
   --    For each decision, a decision line is generated with the form:
203
 
204
   --      C*sloc expression
205
 
206
   --    Here * is one of the following characters:
207
 
208
   --      I  decision in IF statement or conditional expression
209
   --      E  decision in EXIT WHEN statement
210
   --      P  decision in pragma Assert/Check/Pre_Condition/Post_Condition
211
   --      W  decision in WHILE iteration scheme
212
   --      X  decision appearing in some other expression context
213
 
214
   --    For I, E, P, W, sloc is the source location of the IF, EXIT, PRAGMA or
215
   --    WHILE token.
216
 
217
   --    For X, sloc is omitted.
218
 
219
   --    The expression is a prefix polish form indicating the structure of
220
   --    the decision, including logical operators and short circuit forms.
221
   --    The following is a grammar showing the structure of expression:
222
 
223
   --      expression ::= term             (if expr is not logical operator)
224
   --      expression ::= &sloc term term  (if expr is AND or AND THEN)
225
   --      expression ::= |sloc term term  (if expr is OR or OR ELSE)
226
   --      expression ::= !sloc term       (if expr is NOT)
227
 
228
   --      In the last four cases, sloc is the source location of the AND, OR,
229
   --      or NOT token, respectively.
230
 
231
   --      term ::= element
232
   --      term ::= expression
233
 
234
   --      element ::= outcome sloc-range
235
 
236
   --    outcome is one of the following letters:
237
 
238
   --      c  condition
239
   --      t  true condition
240
   --      f  false condition
241
 
242
   --      where t/f are used to mark a condition that has been recognized by
243
   --      the compiler as always being true or false.
244
 
245
   --    & indicates AND THEN connecting two conditions.
246
 
247
   --    | indicates OR ELSE connecting two conditions.
248
 
249
   --    ! indicates NOT applied to the expression.
250
 
251
   --    In the context of Couverture, the No_Direct_Boolean_Opeartors
252
   --    restriction is assumed, and no other operator can appear.
253
 
254
   ---------------------------------------------------------------------
255
   -- Internal table used to store Source Coverage Obligations (SCOs) --
256
   ---------------------------------------------------------------------
257
 
258
   type Source_Location is record
259
      Line : Logical_Line_Number;
260
      Col  : Column_Number;
261
   end record;
262
 
263
   No_Source_Location : Source_Location := (No_Line_Number, No_Column_Number);
264
 
265
   type SCO_Table_Entry is record
266
      From : Source_Location;
267
      To   : Source_Location;
268
      C1   : Character;
269
      C2   : Character;
270
      Last : Boolean;
271
   end record;
272
 
273
   package SCO_Table is new GNAT.Table (
274
     Table_Component_Type => SCO_Table_Entry,
275
     Table_Index_Type     => Nat,
276
     Table_Low_Bound      => 1,
277
     Table_Initial        => 500,
278
     Table_Increment      => 300);
279
 
280
   --  The SCO_Table_Entry values appear as follows:
281
 
282
   --    Statements
283
   --      C1   = 'S' for entry point, 's' otherwise
284
   --      C2   = statement type code to appear on CS line (or ' ' if none)
285
   --      From = starting source location
286
   --      To   = ending source location
287
   --      Last = False for all but the last entry, True for last entry
288
 
289
   --    Note: successive statements (possibly interspersed with entries of
290
   --    other kinds, that are ignored for this purpose), starting with one
291
   --    labeled with C1 = 'S', up to and including the first one labeled with
292
   --    Last=True, indicate the sequence to be output for a sequence of
293
   --    statements on a single CS line.
294
 
295
   --    Decision
296
   --      C1   = decision type code
297
   --      C2   = ' '
298
   --      From = location of IF/EXIT/PRAGMA/WHILE token,
299
   --             No_Source_Location for X
300
   --      To   = No_Source_Location
301
   --      Last = unused
302
 
303
   --    Operator
304
   --      C1   = '!', '^', '&', '|'
305
   --      C2   = ' '
306
   --      From = location of NOT/AND/OR token
307
   --      To   = No_Source_Location
308
   --      Last = False
309
 
310
   --    Element (condition)
311
   --      C1   = ' '
312
   --      C2   = 'c', 't', or 'f' (condition/true/false)
313
   --      From = starting source location
314
   --      To   = ending source location
315
   --      Last = False for all but the last entry, True for last entry
316
 
317
   --    Note: the sequence starting with a decision, and continuing with
318
   --    operators and elements up to and including the first one labeled with
319
   --    Last = True, indicate the sequence to be output for a complex decision
320
   --    on a single CD decision line.
321
 
322
   ----------------
323
   -- Unit Table --
324
   ----------------
325
 
326
   --  This table keeps track of the units and the corresponding starting and
327
   --  ending indexes (From, To) in the SCO table. Note that entry zero is
328
   --  unused, it is for convenience in calling the sort routine. Thus the
329
   --  real lower bound for active entries is 1.
330
 
331
   type SCO_Unit_Index is new Int;
332
   --  Used to index values in this table. Values start at 1 and are assigned
333
   --  sequentially as entries are constructed.
334
 
335
   type SCO_Unit_Table_Entry is record
336
      File_Name : String_Ptr;
337
      --  Pointer to file name in ALI file
338
 
339
      Dep_Num : Nat;
340
      --  Dependency number in ALI file
341
 
342
      From : Nat;
343
      --  Starting index in SCO_Table of SCO information for this unit
344
 
345
      To : Nat;
346
      --  Ending index in SCO_Table of SCO information for this unit
347
   end record;
348
 
349
   package SCO_Unit_Table is new GNAT.Table (
350
     Table_Component_Type => SCO_Unit_Table_Entry,
351
     Table_Index_Type     => SCO_Unit_Index,
352
     Table_Low_Bound      => 0, -- see note above on sorting
353
     Table_Initial        => 20,
354
     Table_Increment      => 200);
355
 
356
   -----------------
357
   -- Subprograms --
358
   -----------------
359
 
360
   procedure Initialize;
361
   --  Reset tables for a new compilation
362
 
363
   procedure Add_SCO
364
     (From : Source_Location := No_Source_Location;
365
      To   : Source_Location := No_Source_Location;
366
      C1   : Character       := ' ';
367
      C2   : Character       := ' ';
368
      Last : Boolean         := False);
369
   --  Adds one entry to SCO table with given field values
370
 
371
end SCOs;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.