1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2009-2014, 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 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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Debug
; use Debug
;
29 with Errout
; use Errout
;
31 with Lib
.Util
; use Lib
.Util
;
32 with Namet
; use Namet
;
33 with Nlists
; use Nlists
;
35 with Output
; use Output
;
39 with Sem_Util
; use Sem_Util
;
40 with Sinfo
; use Sinfo
;
41 with Sinput
; use Sinput
;
42 with Snames
; use Snames
;
45 with GNAT
.HTable
; use GNAT
.HTable
;
46 with GNAT
.Heap_Sort_G
;
48 package body Par_SCO
is
50 -----------------------
51 -- Unit Number Table --
52 -----------------------
54 -- This table parallels the SCO_Unit_Table, keeping track of the unit
55 -- numbers corresponding to the entries made in this table, so that before
56 -- writing out the SCO information to the ALI file, we can fill in the
57 -- proper dependency numbers and file names.
59 -- Note that the zero'th entry is here for convenience in sorting the
60 -- table, the real lower bound is 1.
62 package SCO_Unit_Number_Table
is new Table
.Table
(
63 Table_Component_Type
=> Unit_Number_Type
,
64 Table_Index_Type
=> SCO_Unit_Index
,
65 Table_Low_Bound
=> 0, -- see note above on sort
67 Table_Increment
=> 200,
68 Table_Name
=> "SCO_Unit_Number_Entry");
70 ---------------------------------
71 -- Condition/Pragma Hash Table --
72 ---------------------------------
74 -- We need to be able to get to conditions quickly for handling the calls
75 -- to Set_SCO_Condition efficiently, and similarly to get to pragmas to
76 -- handle calls to Set_SCO_Pragma_Enabled. For this purpose we identify the
77 -- conditions and pragmas in the table by their starting sloc, and use this
78 -- hash table to map from these sloc values to SCO_Table indexes.
80 type Header_Num
is new Integer range 0 .. 996;
81 -- Type for hash table headers
83 function Hash
(F
: Source_Ptr
) return Header_Num
;
84 -- Function to Hash source pointer value
86 function Equal
(F1
, F2
: Source_Ptr
) return Boolean;
87 -- Function to test two keys for equality
89 package Condition_Pragma_Hash_Table
is new Simple_HTable
90 (Header_Num
, Int
, 0, Source_Ptr
, Hash
, Equal
);
91 -- The actual hash table
93 --------------------------
94 -- Internal Subprograms --
95 --------------------------
97 function Has_Decision
(N
: Node_Id
) return Boolean;
98 -- N is the node for a subexpression. Returns True if the subexpression
99 -- contains a nested decision (i.e. either is a logical operator, or
100 -- contains a logical operator in its subtree).
102 function Is_Logical_Operator
(N
: Node_Id
) return Boolean;
103 -- N is the node for a subexpression. This procedure determines whether N
104 -- a logical operator (including short circuit conditions, but excluding
105 -- OR and AND) and returns True if so. Note that in cases where True is
106 -- returned, callers assume Nkind (N) in N_Op.
108 function To_Source_Location
(S
: Source_Ptr
) return Source_Location
;
109 -- Converts Source_Ptr value to Source_Location (line/col) format
111 procedure Process_Decisions
114 Pragma_Sloc
: Source_Ptr
);
115 -- If N is Empty, has no effect. Otherwise scans the tree for the node N,
116 -- to output any decisions it contains. T is one of IEGPWX (for context of
117 -- expression: if/exit when/entry guard/pragma/while/expression). If T is
118 -- other than X, the node N is the if expression involved, and a decision
119 -- is always present (at the very least a simple decision is present at the
122 procedure Process_Decisions
125 Pragma_Sloc
: Source_Ptr
);
126 -- Calls above procedure for each element of the list L
128 procedure Set_Table_Entry
134 Pragma_Sloc
: Source_Ptr
:= No_Location
;
135 Pragma_Aspect_Name
: Name_Id
:= No_Name
);
136 -- Append an entry to SCO_Table with fields set as per arguments
138 type Dominant_Info
is record
140 -- F/T/S/E for a valid dominance marker, or ' ' for no dominant
143 -- Node providing the Sloc(s) for the dominance marker
145 No_Dominant
: constant Dominant_Info
:= (' ', Empty
);
147 procedure Record_Instance
(Id
: Instance_Id
; Inst_Sloc
: Source_Ptr
);
148 -- Add one entry from the instance table to the corresponding SCO table
150 procedure Traverse_Declarations_Or_Statements
152 D
: Dominant_Info
:= No_Dominant
;
153 P
: Node_Id
:= Empty
);
154 -- Process L, a list of statements or declarations dominated by D.
155 -- If P is present, it is processed as though it had been prepended to L.
157 function Traverse_Declarations_Or_Statements
159 D
: Dominant_Info
:= No_Dominant
;
160 P
: Node_Id
:= Empty
) return Dominant_Info
;
161 -- Same as above, and returns dominant information corresponding to the
162 -- last node with SCO in L.
164 -- The following Traverse_* routines perform appropriate calls to
165 -- Traverse_Declarations_Or_Statements to traverse specific node kinds.
166 -- Parameter D, when present, indicates the dominant of the first
167 -- declaration or statement within N.
169 -- Why is Traverse_Sync_Definition commented specificaly and
170 -- the others are not???
172 procedure Traverse_Generic_Package_Declaration
(N
: Node_Id
);
173 procedure Traverse_Handled_Statement_Sequence
175 D
: Dominant_Info
:= No_Dominant
);
176 procedure Traverse_Package_Body
(N
: Node_Id
);
177 procedure Traverse_Package_Declaration
179 D
: Dominant_Info
:= No_Dominant
);
180 procedure Traverse_Subprogram_Or_Task_Body
182 D
: Dominant_Info
:= No_Dominant
);
184 procedure Traverse_Sync_Definition
(N
: Node_Id
);
185 -- Traverse a protected definition or task definition
187 procedure Write_SCOs_To_ALI_File
is new Put_SCOs
;
188 -- Write SCO information to the ALI file using routines in Lib.Util
196 -- Dump SCO unit table
198 Write_Line
("SCO Unit Table");
199 Write_Line
("--------------");
201 for Index
in 1 .. SCO_Unit_Table
.Last
loop
203 UTE
: SCO_Unit_Table_Entry
renames SCO_Unit_Table
.Table
(Index
);
207 Write_Int
(Int
(Index
));
208 Write_Str
(". Dep_Num = ");
209 Write_Int
(Int
(UTE
.Dep_Num
));
210 Write_Str
(" From = ");
211 Write_Int
(Int
(UTE
.From
));
212 Write_Str
(" To = ");
213 Write_Int
(Int
(UTE
.To
));
215 Write_Str
(" File_Name = """);
217 if UTE
.File_Name
/= null then
218 Write_Str
(UTE
.File_Name
.all);
226 -- Dump SCO Unit number table if it contains any entries
228 if SCO_Unit_Number_Table
.Last
>= 1 then
230 Write_Line
("SCO Unit Number Table");
231 Write_Line
("---------------------");
233 for Index
in 1 .. SCO_Unit_Number_Table
.Last
loop
235 Write_Int
(Int
(Index
));
236 Write_Str
(". Unit_Number = ");
237 Write_Int
(Int
(SCO_Unit_Number_Table
.Table
(Index
)));
242 -- Dump SCO table itself
245 Write_Line
("SCO Table");
246 Write_Line
("---------");
248 for Index
in 1 .. SCO_Table
.Last
loop
250 T
: SCO_Table_Entry
renames SCO_Table
.Table
(Index
);
258 Write_Str
(" C1 = '");
264 Write_Str
(" C2 = '");
269 if T
.From
/= No_Source_Location
then
270 Write_Str
(" From = ");
271 Write_Int
(Int
(T
.From
.Line
));
273 Write_Int
(Int
(T
.From
.Col
));
276 if T
.To
/= No_Source_Location
then
277 Write_Str
(" To = ");
278 Write_Int
(Int
(T
.To
.Line
));
280 Write_Int
(Int
(T
.To
.Col
));
286 Write_Str
(" False");
298 function Equal
(F1
, F2
: Source_Ptr
) return Boolean is
307 function Has_Decision
(N
: Node_Id
) return Boolean is
309 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
310 -- Determine if Nkind (N) indicates the presence of a decision (i.e.
311 -- N is a logical operator, which is a decision in itself, or an
312 -- IF-expression whose Condition attribute is a decision).
318 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
320 if Is_Logical_Operator
(N
) or else Nkind
(N
) = N_If_Expression
then
327 function Traverse
is new Traverse_Func
(Check_Node
);
329 -- Start of processing for Has_Decision
332 return Traverse
(N
) = Abandon
;
339 function Hash
(F
: Source_Ptr
) return Header_Num
is
341 return Header_Num
(Nat
(F
) mod 997);
348 procedure Initialize
is
350 SCO_Unit_Number_Table
.Init
;
352 -- The SCO_Unit_Number_Table entry with index 0 is intentionally set
353 -- aside to be used as temporary for sorting.
355 SCO_Unit_Number_Table
.Increment_Last
;
358 -------------------------
359 -- Is_Logical_Operator --
360 -------------------------
362 function Is_Logical_Operator
(N
: Node_Id
) return Boolean is
364 return Nkind_In
(N
, N_Op_Not
, N_And_Then
, N_Or_Else
);
365 end Is_Logical_Operator
;
367 -----------------------
368 -- Process_Decisions --
369 -----------------------
371 -- Version taking a list
373 procedure Process_Decisions
376 Pragma_Sloc
: Source_Ptr
)
382 while Present
(N
) loop
383 Process_Decisions
(N
, T
, Pragma_Sloc
);
387 end Process_Decisions
;
389 -- Version taking a node
391 Current_Pragma_Sloc
: Source_Ptr
:= No_Location
;
392 -- While processing a pragma, this is set to the sloc of the N_Pragma node
394 procedure Process_Decisions
397 Pragma_Sloc
: Source_Ptr
)
400 -- This is used to mark the location of a decision sequence in the SCO
401 -- table. We use it for backing out a simple decision in an expression
402 -- context that contains only NOT operators.
404 X_Not_Decision
: Boolean;
405 -- This flag keeps track of whether a decision sequence in the SCO table
406 -- contains only NOT operators, and is for an expression context (T=X).
407 -- The flag will be set False if T is other than X, or if an operator
408 -- other than NOT is in the sequence.
410 function Process_Node
(N
: Node_Id
) return Traverse_Result
;
411 -- Processes one node in the traversal, looking for logical operators,
412 -- and if one is found, outputs the appropriate table entries.
414 procedure Output_Decision_Operand
(N
: Node_Id
);
415 -- The node N is the top level logical operator of a decision, or it is
416 -- one of the operands of a logical operator belonging to a single
417 -- complex decision. This routine outputs the sequence of table entries
418 -- corresponding to the node. Note that we do not process the sub-
419 -- operands to look for further decisions, that processing is done in
420 -- Process_Decision_Operand, because we can't get decisions mixed up in
421 -- the global table. Call has no effect if N is Empty.
423 procedure Output_Element
(N
: Node_Id
);
424 -- Node N is an operand of a logical operator that is not itself a
425 -- logical operator, or it is a simple decision. This routine outputs
426 -- the table entry for the element, with C1 set to ' '. Last is set
427 -- False, and an entry is made in the condition hash table.
429 procedure Output_Header
(T
: Character);
430 -- Outputs a decision header node. T is I/W/E/P for IF/WHILE/EXIT WHEN/
431 -- PRAGMA, and 'X' for the expression case.
433 procedure Process_Decision_Operand
(N
: Node_Id
);
434 -- This is called on node N, the top level node of a decision, or on one
435 -- of its operands or suboperands after generating the full output for
436 -- the complex decision. It process the suboperands of the decision
437 -- looking for nested decisions.
439 -----------------------------
440 -- Output_Decision_Operand --
441 -----------------------------
443 procedure Output_Decision_Operand
(N
: Node_Id
) is
453 elsif Is_Logical_Operator
(N
) then
454 if Nkind
(N
) = N_Op_Not
then
461 if Nkind_In
(N
, N_Op_Or
, N_Or_Else
) then
464 else pragma Assert
(Nkind_In
(N
, N_Op_And
, N_And_Then
));
476 Output_Decision_Operand
(L
);
477 Output_Decision_Operand
(Right_Opnd
(N
));
479 -- Not a logical operator
484 end Output_Decision_Operand
;
490 procedure Output_Element
(N
: Node_Id
) is
494 Sloc_Range
(N
, FSloc
, LSloc
);
501 Condition_Pragma_Hash_Table
.Set
(FSloc
, SCO_Table
.Last
);
508 procedure Output_Header
(T
: Character) is
509 Loc
: Source_Ptr
:= No_Location
;
510 -- Node whose Sloc is used for the decision
512 Nam
: Name_Id
:= No_Name
;
513 -- For the case of an aspect, aspect name
517 when 'I' |
'E' |
'W' |
'a' |
'A' =>
519 -- For IF, EXIT, WHILE, or aspects, the token SLOC is that of
520 -- the parent of the expression.
522 Loc
:= Sloc
(Parent
(N
));
524 if T
= 'a' or else T
= 'A' then
525 Nam
:= Chars
(Identifier
(Parent
(N
)));
530 -- For entry guard, the token sloc is from the N_Entry_Body.
531 -- For PRAGMA, we must get the location from the pragma node.
532 -- Argument N is the pragma argument, and we have to go up
533 -- two levels (through the pragma argument association) to
534 -- get to the pragma node itself. For the guard on a select
535 -- alternative, we do not have access to the token location for
536 -- the WHEN, so we use the first sloc of the condition itself
537 -- (note: we use First_Sloc, not Sloc, because this is what is
538 -- referenced by dominance markers).
540 -- Doesn't this requirement of using First_Sloc need to be
541 -- documented in the spec ???
543 if Nkind_In
(Parent
(N
), N_Accept_Alternative
,
545 N_Terminate_Alternative
)
547 Loc
:= First_Sloc
(N
);
549 Loc
:= Sloc
(Parent
(Parent
(N
)));
554 -- For an expression, no Sloc
558 -- No other possibilities
570 Pragma_Sloc
=> Pragma_Sloc
,
571 Pragma_Aspect_Name
=> Nam
);
573 -- For an aspect specification, which will be rewritten into a
574 -- pragma, enter a hash table entry now.
577 Condition_Pragma_Hash_Table
.Set
(Loc
, SCO_Table
.Last
);
581 ------------------------------
582 -- Process_Decision_Operand --
583 ------------------------------
585 procedure Process_Decision_Operand
(N
: Node_Id
) is
587 if Is_Logical_Operator
(N
) then
588 if Nkind
(N
) /= N_Op_Not
then
589 Process_Decision_Operand
(Left_Opnd
(N
));
590 X_Not_Decision
:= False;
593 Process_Decision_Operand
(Right_Opnd
(N
));
596 Process_Decisions
(N
, 'X', Pragma_Sloc
);
598 end Process_Decision_Operand
;
604 function Process_Node
(N
: Node_Id
) return Traverse_Result
is
608 -- Logical operators, output table entries and then process
609 -- operands recursively to deal with nested conditions.
611 when N_And_Then | N_Or_Else | N_Op_Not
=>
616 -- If outer level, then type comes from call, otherwise it
617 -- is more deeply nested and counts as X for expression.
619 if N
= Process_Decisions
.N
then
620 T
:= Process_Decisions
.T
;
625 -- Output header for sequence
627 X_Not_Decision
:= T
= 'X' and then Nkind
(N
) = N_Op_Not
;
628 Mark
:= SCO_Table
.Last
;
631 -- Output the decision
633 Output_Decision_Operand
(N
);
635 -- If the decision was in an expression context (T = 'X')
636 -- and contained only NOT operators, then we don't output
639 if X_Not_Decision
then
640 SCO_Table
.Set_Last
(Mark
);
642 -- Otherwise, set Last in last table entry to mark end
645 SCO_Table
.Table
(SCO_Table
.Last
).Last
:= True;
648 -- Process any embedded decisions
650 Process_Decision_Operand
(N
);
656 -- Really hard to believe this is correct given the special
657 -- handling for if expressions below ???
659 when N_Case_Expression
=>
662 -- If expression, processed like an if statement
664 when N_If_Expression
=>
666 Cond
: constant Node_Id
:= First
(Expressions
(N
));
667 Thnx
: constant Node_Id
:= Next
(Cond
);
668 Elsx
: constant Node_Id
:= Next
(Thnx
);
670 Process_Decisions
(Cond
, 'I', Pragma_Sloc
);
671 Process_Decisions
(Thnx
, 'X', Pragma_Sloc
);
672 Process_Decisions
(Elsx
, 'X', Pragma_Sloc
);
676 -- All other cases, continue scan
684 procedure Traverse
is new Traverse_Proc
(Process_Node
);
686 -- Start of processing for Process_Decisions
693 -- See if we have simple decision at outer level and if so then
694 -- generate the decision entry for this simple decision. A simple
695 -- decision is a boolean expression (which is not a logical operator
696 -- or short circuit form) appearing as the operand of an IF, WHILE,
697 -- EXIT WHEN, or special PRAGMA construct.
699 if T
/= 'X' and then not Is_Logical_Operator
(N
) then
703 -- Change Last in last table entry to True to mark end of
704 -- sequence, which is this case is only one element long.
706 SCO_Table
.Table
(SCO_Table
.Last
).Last
:= True;
710 end Process_Decisions
;
718 procedure Write_Info_Char
(C
: Character) renames Write_Char
;
719 -- Write one character;
721 procedure Write_Info_Initiate
(Key
: Character) renames Write_Char
;
722 -- Start new one and write one character;
724 procedure Write_Info_Nat
(N
: Nat
);
727 procedure Write_Info_Terminate
renames Write_Eol
;
728 -- Terminate current line
734 procedure Write_Info_Nat
(N
: Nat
) is
739 procedure Debug_Put_SCOs
is new Put_SCOs
;
741 -- Start of processing for pscos
747 ---------------------
748 -- Record_Instance --
749 ---------------------
751 procedure Record_Instance
(Id
: Instance_Id
; Inst_Sloc
: Source_Ptr
) is
752 Inst_Src
: constant Source_File_Index
:=
753 Get_Source_File_Index
(Inst_Sloc
);
755 SCO_Instance_Table
.Append
756 ((Inst_Dep_Num
=> Dependency_Num
(Unit
(Inst_Src
)),
757 Inst_Loc
=> To_Source_Location
(Inst_Sloc
),
758 Enclosing_Instance
=> SCO_Instance_Index
(Instance
(Inst_Src
))));
760 (SCO_Instance_Table
.Last
= SCO_Instance_Index
(Id
));
767 procedure SCO_Output
is
768 procedure Populate_SCO_Instance_Table
is
769 new Sinput
.Iterate_On_Instances
(Record_Instance
);
774 if Debug_Flag_Dot_OO
then
778 Populate_SCO_Instance_Table
;
780 -- Sort the unit tables based on dependency numbers
782 Unit_Table_Sort
: declare
784 function Lt
(Op1
, Op2
: Natural) return Boolean;
785 -- Comparison routine for sort call
787 procedure Move
(From
: Natural; To
: Natural);
788 -- Move routine for sort call
794 function Lt
(Op1
, Op2
: Natural) return Boolean is
798 (SCO_Unit_Number_Table
.Table
(SCO_Unit_Index
(Op1
)))
801 (SCO_Unit_Number_Table
.Table
(SCO_Unit_Index
(Op2
)));
808 procedure Move
(From
: Natural; To
: Natural) is
810 SCO_Unit_Table
.Table
(SCO_Unit_Index
(To
)) :=
811 SCO_Unit_Table
.Table
(SCO_Unit_Index
(From
));
812 SCO_Unit_Number_Table
.Table
(SCO_Unit_Index
(To
)) :=
813 SCO_Unit_Number_Table
.Table
(SCO_Unit_Index
(From
));
816 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
818 -- Start of processing for Unit_Table_Sort
821 Sorting
.Sort
(Integer (SCO_Unit_Table
.Last
));
824 -- Loop through entries in the unit table to set file name and
825 -- dependency number entries.
827 for J
in 1 .. SCO_Unit_Table
.Last
loop
829 U
: constant Unit_Number_Type
:= SCO_Unit_Number_Table
.Table
(J
);
830 UTE
: SCO_Unit_Table_Entry
renames SCO_Unit_Table
.Table
(J
);
832 Get_Name_String
(Reference_Name
(Source_Index
(U
)));
833 UTE
.File_Name
:= new String'(Name_Buffer (1 .. Name_Len));
834 UTE.Dep_Num := Dependency_Num (U);
838 -- Stamp out SCO entries for decisions in disabled constructs (pragmas
842 while SCO_Index <= SCO_Table.Last loop
843 if Is_Decision (SCO_Table.Table (SCO_Index).C1)
844 and then SCO_Pragma_Disabled
845 (SCO_Table.Table (SCO_Index).Pragma_Sloc)
848 SCO_Table.Table (SCO_Index).C1 := ASCII.NUL;
849 exit when SCO_Table.Table (SCO_Index).Last;
850 SCO_Index := SCO_Index + 1;
854 SCO_Index := SCO_Index + 1;
857 -- Now the tables are all setup for output to the ALI file
859 Write_SCOs_To_ALI_File;
862 -------------------------
863 -- SCO_Pragma_Disabled --
864 -------------------------
866 function SCO_Pragma_Disabled (Loc : Source_Ptr) return Boolean is
870 if Loc = No_Location then
874 Index := Condition_Pragma_Hash_Table.Get (Loc);
876 -- The test here for zero is to deal with possible previous errors, and
877 -- for the case of pragma statement SCOs, for which we always set the
878 -- Pragma_Sloc even if the particular pragma cannot be specifically
883 T : SCO_Table_Entry renames SCO_Table.Table (Index);
892 -- Aspect decision (enabled)
897 -- Aspect decision (not enabled)
902 -- Nullified disabled SCO
914 end SCO_Pragma_Disabled;
920 procedure SCO_Record (U : Unit_Number_Type) is
924 procedure Traverse_Aux_Decls (N : Node_Id);
925 -- Traverse the Aux_Decls_Node of compilation unit N
927 ------------------------
928 -- Traverse_Aux_Decls --
929 ------------------------
931 procedure Traverse_Aux_Decls (N : Node_Id) is
932 ADN : constant Node_Id := Aux_Decls_Node (N);
934 Traverse_Declarations_Or_Statements (Config_Pragmas (ADN));
935 Traverse_Declarations_Or_Statements (Pragmas_After (ADN));
937 -- Declarations and Actions do not correspond to source constructs,
938 -- they contain only nodes from expansion, so at this point they
939 -- should still be empty:
941 pragma Assert (No (Declarations (ADN)));
942 pragma Assert (No (Actions (ADN)));
943 end Traverse_Aux_Decls;
945 -- Start of processing for SCO_Record
948 -- Ignore call if not generating code and generating SCO's
950 if not (Generate_SCO and then Operating_Mode = Generate_Code) then
954 -- Ignore call if this unit already recorded
956 for J in 1 .. SCO_Unit_Number_Table.Last loop
957 if U = SCO_Unit_Number_Table.Table (J) then
962 -- Otherwise record starting entry
964 From := SCO_Table.Last + 1;
966 -- Get Unit (checking case of subunit)
968 Lu := Unit (Cunit (U));
970 if Nkind (Lu) = N_Subunit then
971 Lu := Proper_Body (Lu);
976 Traverse_Aux_Decls (Cunit (U));
980 N_Package_Declaration |
982 N_Subprogram_Declaration |
984 N_Generic_Package_Declaration |
987 N_Generic_Instantiation =>
989 Traverse_Declarations_Or_Statements (L => No_List, P => Lu);
993 -- All other cases of compilation units (e.g. renamings), generate
994 -- no SCO information.
999 -- Make entry for new unit in unit tables, we will fill in the file
1000 -- name and dependency numbers later.
1002 SCO_Unit_Table.Append (
1005 File_Index => Get_Source_File_Index (Sloc (Lu)),
1007 To => SCO_Table.Last));
1009 SCO_Unit_Number_Table.Append (U);
1012 -----------------------
1013 -- Set_SCO_Condition --
1014 -----------------------
1016 procedure Set_SCO_Condition (Cond : Node_Id; Val : Boolean) is
1017 Orig : constant Node_Id := Original_Node (Cond);
1022 Constant_Condition_Code : constant array (Boolean) of Character :=
1023 (False => 'f
', True => 't
');
1025 Sloc_Range (Orig, Start, Dummy);
1026 Index := Condition_Pragma_Hash_Table.Get (Start);
1028 -- Index can be zero for boolean expressions that do not have SCOs
1029 -- (simple decisions outside of a control flow structure), or in case
1030 -- of a previous error.
1036 pragma Assert (SCO_Table.Table (Index).C1 = ' ');
1037 SCO_Table.Table (Index).C2 := Constant_Condition_Code (Val);
1039 end Set_SCO_Condition;
1041 ----------------------------
1042 -- Set_SCO_Pragma_Enabled --
1043 ----------------------------
1045 procedure Set_SCO_Pragma_Enabled (Loc : Source_Ptr) is
1049 -- Nothing to do if not generating SCO, or if we're not processing the
1050 -- original source occurrence of the pragma.
1052 if not (Generate_SCO
1053 and then In_Extended_Main_Source_Unit (Loc)
1054 and then not (In_Instance or In_Inlined_Body))
1059 -- Note: the reason we use the Sloc value as the key is that in the
1060 -- generic case, the call to this procedure is made on a copy of the
1061 -- original node, so we can't use the Node_Id value.
1063 Index := Condition_Pragma_Hash_Table.Get (Loc);
1065 -- A zero index here indicates that semantic analysis found an
1066 -- activated pragma at Loc which does not have a corresponding pragma
1067 -- or aspect at the syntax level. This may occur in legitimate cases
1068 -- because of expanded code (such are Pre/Post conditions generated for
1069 -- formal parameter validity checks), or as a consequence of a previous
1077 T : SCO_Table_Entry renames SCO_Table.Table (Index);
1080 -- Note: may be called multiple times for the same sloc, so
1081 -- account for the fact that the entry may already have been
1085 -- Aspect (decision SCO)
1093 -- Pragma (statement SCO)
1096 pragma Assert (T.C2 = 'p
' or else T.C2 = 'P
');
1100 raise Program_Error;
1104 end Set_SCO_Pragma_Enabled;
1106 ---------------------
1107 -- Set_Table_Entry --
1108 ---------------------
1110 procedure Set_Table_Entry
1116 Pragma_Sloc : Source_Ptr := No_Location;
1117 Pragma_Aspect_Name : Name_Id := No_Name)
1123 From => To_Source_Location (From),
1124 To => To_Source_Location (To),
1126 Pragma_Sloc => Pragma_Sloc,
1127 Pragma_Aspect_Name => Pragma_Aspect_Name));
1128 end Set_Table_Entry;
1130 ------------------------
1131 -- To_Source_Location --
1132 ------------------------
1134 function To_Source_Location (S : Source_Ptr) return Source_Location is
1136 if S = No_Location then
1137 return No_Source_Location;
1140 (Line => Get_Logical_Line_Number (S),
1141 Col => Get_Column_Number (S));
1143 end To_Source_Location;
1145 -----------------------------------------
1146 -- Traverse_Declarations_Or_Statements --
1147 -----------------------------------------
1149 -- Tables used by Traverse_Declarations_Or_Statements for temporarily
1150 -- holding statement and decision entries. These are declared globally
1151 -- since they are shared by recursive calls to this procedure.
1153 type SC_Entry is record
1159 -- Used to store a single entry in the following table, From:To represents
1160 -- the range of entries in the CS line entry, and typ is the type, with
1161 -- space meaning that no type letter will accompany the entry.
1163 package SC is new Table.Table (
1164 Table_Component_Type => SC_Entry,
1165 Table_Index_Type => Nat,
1166 Table_Low_Bound => 1,
1167 Table_Initial => 1000,
1168 Table_Increment => 200,
1169 Table_Name => "SCO_SC");
1170 -- Used to store statement components for a CS entry to be output
1171 -- as a result of the call to this procedure. SC.Last is the last
1172 -- entry stored, so the current statement sequence is represented
1173 -- by SC_Array (SC_First .. SC.Last), where SC_First is saved on
1174 -- entry to each recursive call to the routine.
1176 -- Extend_Statement_Sequence adds an entry to this array, and then
1177 -- Set_Statement_Entry clears the entries starting with SC_First,
1178 -- copying these entries to the main SCO output table. The reason that
1179 -- we do the temporary caching of results in this array is that we want
1180 -- the SCO table entries for a given CS line to be contiguous, and the
1181 -- processing may output intermediate entries such as decision entries.
1183 type SD_Entry is record
1189 -- Used to store a single entry in the following table. Nod is the node to
1190 -- be searched for decisions for the case of Process_Decisions_Defer with a
1191 -- node argument (with Lst set to No_List. Lst is the list to be searched
1192 -- for decisions for the case of Process_Decisions_Defer with a List
1193 -- argument (in which case Nod is set to Empty). Plo is the sloc of the
1194 -- enclosing pragma, if any.
1196 package SD is new Table.Table (
1197 Table_Component_Type => SD_Entry,
1198 Table_Index_Type => Nat,
1199 Table_Low_Bound => 1,
1200 Table_Initial => 1000,
1201 Table_Increment => 200,
1202 Table_Name => "SCO_SD");
1203 -- Used to store possible decision information. Instead of calling the
1204 -- Process_Decisions procedures directly, we call Process_Decisions_Defer,
1205 -- which simply stores the arguments in this table. Then when we clear
1206 -- out a statement sequence using Set_Statement_Entry, after generating
1207 -- the CS lines for the statements, the entries in this table result in
1208 -- calls to Process_Decision. The reason for doing things this way is to
1209 -- ensure that decisions are output after the CS line for the statements
1210 -- in which the decisions occur.
1212 procedure Traverse_Declarations_Or_Statements
1214 D : Dominant_Info := No_Dominant;
1215 P : Node_Id := Empty)
1217 Discard_Dom : Dominant_Info;
1218 pragma Warnings (Off, Discard_Dom);
1220 Discard_Dom := Traverse_Declarations_Or_Statements (L, D, P);
1221 end Traverse_Declarations_Or_Statements;
1223 function Traverse_Declarations_Or_Statements
1225 D : Dominant_Info := No_Dominant;
1226 P : Node_Id := Empty) return Dominant_Info
1228 Current_Dominant : Dominant_Info := D;
1229 -- Dominance information for the current basic block
1231 Current_Test : Node_Id;
1232 -- Conditional node (N_If_Statement or N_Elsiif being processed
1236 SC_First : constant Nat := SC.Last + 1;
1237 SD_First : constant Nat := SD.Last + 1;
1238 -- Record first entries used in SC/SD at this recursive level
1240 procedure Extend_Statement_Sequence (N : Node_Id; Typ : Character);
1241 -- Extend the current statement sequence to encompass the node N. Typ
1242 -- is the letter that identifies the type of statement/declaration that
1243 -- is being added to the sequence.
1245 procedure Set_Statement_Entry;
1246 -- Output CS entries for all statements saved in table SC, and end the
1247 -- current CS sequence. Then output entries for all decisions nested in
1248 -- these statements, which have been deferred so far.
1250 procedure Process_Decisions_Defer (N : Node_Id; T : Character);
1251 pragma Inline (Process_Decisions_Defer);
1252 -- This routine is logically the same as Process_Decisions, except that
1253 -- the arguments are saved in the SD table for later processing when
1254 -- Set_Statement_Entry is called, which goes through the saved entries
1255 -- making the corresponding calls to Process_Decision.
1257 procedure Process_Decisions_Defer (L : List_Id; T : Character);
1258 pragma Inline (Process_Decisions_Defer);
1259 -- Same case for list arguments, deferred call to Process_Decisions
1261 procedure Traverse_One (N : Node_Id);
1262 -- Traverse one declaration or statement
1264 procedure Traverse_Aspects (N : Node_Id);
1265 -- Helper for Traverse_One: traverse N's aspect specifications
1267 -------------------------
1268 -- Set_Statement_Entry --
1269 -------------------------
1271 procedure Set_Statement_Entry is
1272 SC_Last : constant Int := SC.Last;
1273 SD_Last : constant Int := SD.Last;
1276 -- Output statement entries from saved entries in SC table
1278 for J in SC_First .. SC_Last loop
1279 if J = SC_First then
1281 if Current_Dominant /= No_Dominant then
1283 From, To : Source_Ptr;
1285 Sloc_Range (Current_Dominant.N, From, To);
1286 if Current_Dominant.K /= 'E
' then
1291 C2 => Current_Dominant.K,
1295 Pragma_Sloc => No_Location,
1296 Pragma_Aspect_Name => No_Name);
1302 SCE : SC_Entry renames SC.Table (J);
1303 Pragma_Sloc : Source_Ptr := No_Location;
1304 Pragma_Aspect_Name : Name_Id := No_Name;
1306 -- For the case of a statement SCO for a pragma controlled by
1307 -- Set_SCO_Pragma_Enabled, set Pragma_Sloc so that the SCO (and
1308 -- those of any nested decision) is emitted only if the pragma
1311 if SCE.Typ = 'p
' then
1312 Pragma_Sloc := SCE.From;
1313 Condition_Pragma_Hash_Table.Set
1314 (Pragma_Sloc, SCO_Table.Last + 1);
1315 Pragma_Aspect_Name := Pragma_Name (SCE.N);
1316 pragma Assert (Pragma_Aspect_Name /= No_Name);
1318 elsif SCE.Typ = 'P
' then
1319 Pragma_Aspect_Name := Pragma_Name (SCE.N);
1320 pragma Assert (Pragma_Aspect_Name /= No_Name);
1328 Last => (J = SC_Last),
1329 Pragma_Sloc => Pragma_Sloc,
1330 Pragma_Aspect_Name => Pragma_Aspect_Name);
1334 -- Last statement of basic block, if present, becomes new current
1337 if SC_Last >= SC_First then
1338 Current_Dominant := ('S
', SC.Table (SC_Last).N);
1341 -- Clear out used section of SC table
1343 SC.Set_Last (SC_First - 1);
1345 -- Output any embedded decisions
1347 for J in SD_First .. SD_Last loop
1349 SDE : SD_Entry renames SD.Table (J);
1351 if Present (SDE.Nod) then
1352 Process_Decisions (SDE.Nod, SDE.Typ, SDE.Plo);
1354 Process_Decisions (SDE.Lst, SDE.Typ, SDE.Plo);
1359 -- Clear out used section of SD table
1361 SD.Set_Last (SD_First - 1);
1362 end Set_Statement_Entry;
1364 -------------------------------
1365 -- Extend_Statement_Sequence --
1366 -------------------------------
1368 procedure Extend_Statement_Sequence (N : Node_Id; Typ : Character) is
1372 To_Node : Node_Id := Empty;
1375 Sloc_Range (N, F, T);
1378 when N_Accept_Statement =>
1379 if Present (Parameter_Specifications (N)) then
1380 To_Node := Last (Parameter_Specifications (N));
1381 elsif Present (Entry_Index (N)) then
1382 To_Node := Entry_Index (N);
1385 when N_Case_Statement =>
1386 To_Node := Expression (N);
1388 when N_If_Statement | N_Elsif_Part =>
1389 To_Node := Condition (N);
1391 when N_Extended_Return_Statement =>
1392 To_Node := Last (Return_Object_Declarations (N));
1394 when N_Loop_Statement =>
1395 To_Node := Iteration_Scheme (N);
1397 when N_Selective_Accept |
1398 N_Timed_Entry_Call |
1399 N_Conditional_Entry_Call |
1400 N_Asynchronous_Select |
1401 N_Single_Protected_Declaration |
1402 N_Single_Task_Declaration =>
1405 when N_Protected_Type_Declaration | N_Task_Type_Declaration =>
1406 if Has_Aspects (N) then
1407 To_Node := Last (Aspect_Specifications (N));
1409 elsif Present (Discriminant_Specifications (N)) then
1410 To_Node := Last (Discriminant_Specifications (N));
1413 To_Node := Defining_Identifier (N);
1421 if Present (To_Node) then
1422 Sloc_Range (To_Node, Dummy, T);
1425 SC.Append ((N, F, T, Typ));
1426 end Extend_Statement_Sequence;
1428 -----------------------------
1429 -- Process_Decisions_Defer --
1430 -----------------------------
1432 procedure Process_Decisions_Defer (N : Node_Id; T : Character) is
1434 SD.Append ((N, No_List, T, Current_Pragma_Sloc));
1435 end Process_Decisions_Defer;
1437 procedure Process_Decisions_Defer (L : List_Id; T : Character) is
1439 SD.Append ((Empty, L, T, Current_Pragma_Sloc));
1440 end Process_Decisions_Defer;
1442 ----------------------
1443 -- Traverse_Aspects --
1444 ----------------------
1446 procedure Traverse_Aspects (N : Node_Id) is
1452 AN := First (Aspect_Specifications (N));
1453 while Present (AN) loop
1454 AE := Expression (AN);
1456 -- SCOs are generated before semantic analysis/expansion:
1457 -- PPCs are not split yet.
1459 pragma Assert (not Split_PPC (AN));
1463 case Get_Aspect_Id (AN) is
1465 -- Aspects rewritten into pragmas controlled by a Check_Policy:
1466 -- Current_Pragma_Sloc must be set to the sloc of the aspect
1467 -- specification. The corresponding pragma will have the same
1471 Aspect_Precondition |
1473 Aspect_Postcondition |
1478 -- Aspects whose checks are generated in client units,
1479 -- regardless of whether or not the check is activated in the
1480 -- unit which contains the declaration: create decision as
1481 -- unconditionally enabled aspect (but still make a pragma
1482 -- entry since Set_SCO_Pragma_Enabled will be called when
1483 -- analyzing actual checks, possibly in other units).
1485 -- Pre/post can have checks in client units too because of
1486 -- inheritance, so should they be moved here???
1488 when Aspect_Predicate |
1489 Aspect_Static_Predicate |
1490 Aspect_Dynamic_Predicate |
1491 Aspect_Type_Invariant =>
1495 -- Other aspects: just process any decision nested in the
1496 -- aspect expression.
1500 if Has_Decision (AE) then
1506 if C1 /= ASCII.NUL then
1507 pragma Assert (Current_Pragma_Sloc = No_Location);
1509 if C1 = 'a
' or else C1 = 'A
' then
1510 Current_Pragma_Sloc := Sloc (AN);
1513 Process_Decisions_Defer (AE, C1);
1515 Current_Pragma_Sloc := No_Location;
1520 end Traverse_Aspects;
1526 procedure Traverse_One (N : Node_Id) is
1528 -- Initialize or extend current statement sequence. Note that for
1529 -- special cases such as IF and Case statements we will modify
1530 -- the range to exclude internal statements that should not be
1531 -- counted as part of the current statement sequence.
1535 -- Package declaration
1537 when N_Package_Declaration =>
1538 Set_Statement_Entry;
1539 Traverse_Package_Declaration (N, Current_Dominant);
1541 -- Generic package declaration
1543 when N_Generic_Package_Declaration =>
1544 Set_Statement_Entry;
1545 Traverse_Generic_Package_Declaration (N);
1549 when N_Package_Body =>
1550 Set_Statement_Entry;
1551 Traverse_Package_Body (N);
1553 -- Subprogram declaration or subprogram body stub
1555 when N_Subprogram_Declaration | N_Subprogram_Body_Stub =>
1556 Process_Decisions_Defer
1557 (Parameter_Specifications (Specification (N)), 'X
');
1559 -- Entry declaration
1561 when N_Entry_Declaration =>
1562 Process_Decisions_Defer (Parameter_Specifications (N), 'X
');
1564 -- Generic subprogram declaration
1566 when N_Generic_Subprogram_Declaration =>
1567 Process_Decisions_Defer
1568 (Generic_Formal_Declarations (N), 'X
');
1569 Process_Decisions_Defer
1570 (Parameter_Specifications (Specification (N)), 'X
');
1572 -- Task or subprogram body
1574 when N_Task_Body | N_Subprogram_Body =>
1575 Set_Statement_Entry;
1576 Traverse_Subprogram_Or_Task_Body (N);
1580 when N_Entry_Body =>
1582 Cond : constant Node_Id :=
1583 Condition (Entry_Body_Formal_Part (N));
1585 Inner_Dominant : Dominant_Info := No_Dominant;
1588 Set_Statement_Entry;
1590 if Present (Cond) then
1591 Process_Decisions_Defer (Cond, 'G
');
1593 -- For an entry body with a barrier, the entry body
1594 -- is dominanted by a True evaluation of the barrier.
1596 Inner_Dominant := ('T
', N);
1599 Traverse_Subprogram_Or_Task_Body (N, Inner_Dominant);
1604 when N_Protected_Body =>
1605 Set_Statement_Entry;
1606 Traverse_Declarations_Or_Statements (Declarations (N));
1608 -- Exit statement, which is an exit statement in the SCO sense,
1609 -- so it is included in the current statement sequence, but
1610 -- then it terminates this sequence. We also have to process
1611 -- any decisions in the exit statement expression.
1613 when N_Exit_Statement =>
1614 Extend_Statement_Sequence (N, 'E
');
1615 Process_Decisions_Defer (Condition (N), 'E
');
1616 Set_Statement_Entry;
1618 -- If condition is present, then following statement is
1619 -- only executed if the condition evaluates to False.
1621 if Present (Condition (N)) then
1622 Current_Dominant := ('F
', N);
1624 Current_Dominant := No_Dominant;
1627 -- Label, which breaks the current statement sequence, but the
1628 -- label itself is not included in the next statement sequence,
1629 -- since it generates no code.
1632 Set_Statement_Entry;
1633 Current_Dominant := No_Dominant;
1635 -- Block statement, which breaks the current statement sequence
1637 when N_Block_Statement =>
1638 Set_Statement_Entry;
1640 -- The first statement in the handled sequence of statements
1641 -- is dominated by the elaboration of the last declaration.
1643 Current_Dominant := Traverse_Declarations_Or_Statements
1644 (L => Declarations (N),
1645 D => Current_Dominant);
1647 Traverse_Handled_Statement_Sequence
1648 (N => Handled_Statement_Sequence (N),
1649 D => Current_Dominant);
1651 -- If statement, which breaks the current statement sequence,
1652 -- but we include the condition in the current sequence.
1654 when N_If_Statement =>
1656 Extend_Statement_Sequence (N, 'I
');
1657 Process_Decisions_Defer (Condition (N), 'I
');
1658 Set_Statement_Entry;
1660 -- Now we traverse the statements in the THEN part
1662 Traverse_Declarations_Or_Statements
1663 (L => Then_Statements (N),
1666 -- Loop through ELSIF parts if present
1668 if Present (Elsif_Parts (N)) then
1670 Saved_Dominant : constant Dominant_Info :=
1673 Elif : Node_Id := First (Elsif_Parts (N));
1676 while Present (Elif) loop
1678 -- An Elsif is executed only if the previous test
1679 -- got a FALSE outcome.
1681 Current_Dominant := ('F
', Current_Test);
1683 -- Now update current test information
1685 Current_Test := Elif;
1687 -- We generate a statement sequence for the
1688 -- construct "ELSIF condition", so that we have
1689 -- a statement for the resulting decisions.
1691 Extend_Statement_Sequence (Elif, 'I
');
1692 Process_Decisions_Defer (Condition (Elif), 'I
');
1693 Set_Statement_Entry;
1695 -- An ELSIF part is never guaranteed to have
1696 -- been executed, following statements are only
1697 -- dominated by the initial IF statement.
1699 Current_Dominant := Saved_Dominant;
1701 -- Traverse the statements in the ELSIF
1703 Traverse_Declarations_Or_Statements
1704 (L => Then_Statements (Elif),
1711 -- Finally traverse the ELSE statements if present
1713 Traverse_Declarations_Or_Statements
1714 (L => Else_Statements (N),
1715 D => ('F
', Current_Test));
1717 -- CASE statement, which breaks the current statement sequence,
1718 -- but we include the expression in the current sequence.
1720 when N_Case_Statement =>
1721 Extend_Statement_Sequence (N, 'C
');
1722 Process_Decisions_Defer (Expression (N), 'X
');
1723 Set_Statement_Entry;
1725 -- Process case branches, all of which are dominated by the
1731 Alt := First (Alternatives (N));
1732 while Present (Alt) loop
1733 Traverse_Declarations_Or_Statements
1734 (L => Statements (Alt),
1735 D => Current_Dominant);
1742 when N_Accept_Statement =>
1743 Extend_Statement_Sequence (N, 'A
');
1744 Set_Statement_Entry;
1746 -- Process sequence of statements, dominant is the ACCEPT
1749 Traverse_Handled_Statement_Sequence
1750 (N => Handled_Statement_Sequence (N),
1751 D => Current_Dominant);
1755 when N_Selective_Accept =>
1756 Extend_Statement_Sequence (N, 'S
');
1757 Set_Statement_Entry;
1759 -- Process alternatives
1764 S_Dom : Dominant_Info;
1767 Alt := First (Select_Alternatives (N));
1768 while Present (Alt) loop
1769 S_Dom := Current_Dominant;
1770 Guard := Condition (Alt);
1772 if Present (Guard) then
1776 Pragma_Sloc => No_Location);
1777 Current_Dominant := ('T
', Guard);
1782 Current_Dominant := S_Dom;
1787 Traverse_Declarations_Or_Statements
1788 (L => Else_Statements (N),
1789 D => Current_Dominant);
1791 when N_Timed_Entry_Call | N_Conditional_Entry_Call =>
1792 Extend_Statement_Sequence (N, 'S
');
1793 Set_Statement_Entry;
1795 -- Process alternatives
1797 Traverse_One (Entry_Call_Alternative (N));
1799 if Nkind (N) = N_Timed_Entry_Call then
1800 Traverse_One (Delay_Alternative (N));
1802 Traverse_Declarations_Or_Statements
1803 (L => Else_Statements (N),
1804 D => Current_Dominant);
1807 when N_Asynchronous_Select =>
1808 Extend_Statement_Sequence (N, 'S
');
1809 Set_Statement_Entry;
1811 Traverse_One (Triggering_Alternative (N));
1812 Traverse_Declarations_Or_Statements
1813 (L => Statements (Abortable_Part (N)),
1814 D => Current_Dominant);
1816 when N_Accept_Alternative =>
1817 Traverse_Declarations_Or_Statements
1818 (L => Statements (N),
1819 D => Current_Dominant,
1820 P => Accept_Statement (N));
1822 when N_Entry_Call_Alternative =>
1823 Traverse_Declarations_Or_Statements
1824 (L => Statements (N),
1825 D => Current_Dominant,
1826 P => Entry_Call_Statement (N));
1828 when N_Delay_Alternative =>
1829 Traverse_Declarations_Or_Statements
1830 (L => Statements (N),
1831 D => Current_Dominant,
1832 P => Delay_Statement (N));
1834 when N_Triggering_Alternative =>
1835 Traverse_Declarations_Or_Statements
1836 (L => Statements (N),
1837 D => Current_Dominant,
1838 P => Triggering_Statement (N));
1840 when N_Terminate_Alternative =>
1842 -- It is dubious to emit a statement SCO for a TERMINATE
1843 -- alternative, since no code is actually executed if the
1844 -- alternative is selected -- the tasking runtime call just
1847 Extend_Statement_Sequence (N, ' ');
1848 Set_Statement_Entry;
1850 -- Unconditional exit points, which are included in the current
1851 -- statement sequence, but then terminate it
1853 when N_Requeue_Statement |
1855 N_Raise_Statement =>
1856 Extend_Statement_Sequence (N, ' ');
1857 Set_Statement_Entry;
1858 Current_Dominant := No_Dominant;
1860 -- Simple return statement. which is an exit point, but we
1861 -- have to process the return expression for decisions.
1863 when N_Simple_Return_Statement =>
1864 Extend_Statement_Sequence (N, ' ');
1865 Process_Decisions_Defer (Expression (N), 'X
');
1866 Set_Statement_Entry;
1867 Current_Dominant := No_Dominant;
1869 -- Extended return statement
1871 when N_Extended_Return_Statement =>
1872 Extend_Statement_Sequence (N, 'R
');
1873 Process_Decisions_Defer
1874 (Return_Object_Declarations (N), 'X
');
1875 Set_Statement_Entry;
1877 Traverse_Handled_Statement_Sequence
1878 (N => Handled_Statement_Sequence (N),
1879 D => Current_Dominant);
1881 Current_Dominant := No_Dominant;
1883 -- Loop ends the current statement sequence, but we include
1884 -- the iteration scheme if present in the current sequence.
1885 -- But the body of the loop starts a new sequence, since it
1886 -- may not be executed as part of the current sequence.
1888 when N_Loop_Statement =>
1890 ISC : constant Node_Id := Iteration_Scheme (N);
1891 Inner_Dominant : Dominant_Info := No_Dominant;
1894 if Present (ISC) then
1896 -- If iteration scheme present, extend the current
1897 -- statement sequence to include the iteration scheme
1898 -- and process any decisions it contains.
1902 if Present (Condition (ISC)) then
1903 Extend_Statement_Sequence (N, 'W
');
1904 Process_Decisions_Defer (Condition (ISC), 'W
');
1906 -- Set more specific dominant for inner statements
1907 -- (the control sloc for the decision is that of
1908 -- the WHILE token).
1910 Inner_Dominant := ('T
', ISC);
1915 Extend_Statement_Sequence (N, 'F
');
1916 Process_Decisions_Defer
1917 (Loop_Parameter_Specification (ISC), 'X
');
1921 Set_Statement_Entry;
1923 if Inner_Dominant = No_Dominant then
1924 Inner_Dominant := Current_Dominant;
1927 Traverse_Declarations_Or_Statements
1928 (L => Statements (N),
1929 D => Inner_Dominant);
1936 -- Record sloc of pragma (pragmas don't nest)
1938 pragma Assert (Current_Pragma_Sloc = No_Location);
1939 Current_Pragma_Sloc := Sloc (N);
1941 -- Processing depends on the kind of pragma
1944 Nam : constant Name_Id := Pragma_Name (N);
1946 First (Pragma_Argument_Associations (N));
1952 Name_Assert_And_Cut |
1955 Name_Loop_Invariant |
1957 Name_Postcondition =>
1959 -- For Assert/Check/Precondition/Postcondition, we
1960 -- must generate a P entry for the decision. Note
1961 -- that this is done unconditionally at this stage.
1962 -- Output for disabled pragmas is suppressed later
1963 -- on when we output the decision line in Put_SCOs,
1964 -- depending on setting by Set_SCO_Pragma_Enabled.
1966 if Nam = Name_Check then
1970 Process_Decisions_Defer (Expression (Arg), 'P
');
1973 -- Pre/postconditions can be inherited so SCO should
1974 -- never be deactivated???
1977 if Present (Arg) and then Present (Next (Arg)) then
1979 -- Case of a dyadic pragma Debug: first argument
1980 -- is a P decision, any nested decision in the
1981 -- second argument is an X decision.
1983 Process_Decisions_Defer (Expression (Arg), 'P
');
1987 Process_Decisions_Defer (Expression (Arg), 'X
');
1990 -- For all other pragmas, we generate decision entries
1991 -- for any embedded expressions, and the pragma is
1994 -- Should generate P decisions (not X) for assertion
1995 -- related pragmas: [Type_]Invariant,
1996 -- [{Static,Dynamic}_]Predicate???
1999 Process_Decisions_Defer (N, 'X
');
2003 -- Add statement SCO
2005 Extend_Statement_Sequence (N, Typ);
2007 Current_Pragma_Sloc := No_Location;
2010 -- Object declaration. Ignored if Prev_Ids is set, since the
2011 -- parser generates multiple instances of the whole declaration
2012 -- if there is more than one identifier declared, and we only
2013 -- want one entry in the SCOs, so we take the first, for which
2014 -- Prev_Ids is False.
2016 when N_Object_Declaration | N_Number_Declaration =>
2017 if not Prev_Ids (N) then
2018 Extend_Statement_Sequence (N, 'o
');
2020 if Has_Decision (N) then
2021 Process_Decisions_Defer (N, 'X
');
2025 -- All other cases, which extend the current statement sequence
2026 -- but do not terminate it, even if they have nested decisions.
2028 when N_Protected_Type_Declaration | N_Task_Type_Declaration =>
2029 Extend_Statement_Sequence (N, 't
');
2030 Process_Decisions_Defer (Discriminant_Specifications (N), 'X
');
2031 Set_Statement_Entry;
2033 Traverse_Sync_Definition (N);
2035 when N_Single_Protected_Declaration | N_Single_Task_Declaration =>
2036 Extend_Statement_Sequence (N, 'o
');
2037 Set_Statement_Entry;
2039 Traverse_Sync_Definition (N);
2043 -- Determine required type character code, or ASCII.NUL if
2044 -- no SCO should be generated for this node.
2047 NK : constant Node_Kind := Nkind (N);
2052 when N_Full_Type_Declaration |
2053 N_Incomplete_Type_Declaration |
2054 N_Private_Type_Declaration |
2055 N_Private_Extension_Declaration =>
2058 when N_Subtype_Declaration =>
2061 when N_Renaming_Declaration =>
2064 when N_Generic_Instantiation =>
2067 when N_Representation_Clause |
2068 N_Use_Package_Clause |
2070 N_Package_Body_Stub |
2072 N_Protected_Body_Stub =>
2075 when N_Procedure_Call_Statement =>
2079 if NK in N_Statement_Other_Than_Procedure_Call then
2086 if Typ /= ASCII.NUL then
2087 Extend_Statement_Sequence (N, Typ);
2091 -- Process any embedded decisions
2093 if Has_Decision (N) then
2094 Process_Decisions_Defer (N, 'X
');
2098 -- Process aspects if present
2100 Traverse_Aspects (N);
2103 -- Start of processing for Traverse_Declarations_Or_Statements
2106 -- Process single prefixed node
2112 -- Loop through statements or declarations
2114 if Is_Non_Empty_List (L) then
2116 while Present (N) loop
2118 -- Note: For separate bodies, we see the tree after Par.Labl has
2119 -- introduced implicit labels, so we need to ignore those nodes.
2121 if Nkind (N) /= N_Implicit_Label_Declaration then
2130 -- End sequence of statements and flush deferred decisions
2132 if Present (P) or else Is_Non_Empty_List (L) then
2133 Set_Statement_Entry;
2136 return Current_Dominant;
2137 end Traverse_Declarations_Or_Statements;
2139 ------------------------------------------
2140 -- Traverse_Generic_Package_Declaration --
2141 ------------------------------------------
2143 procedure Traverse_Generic_Package_Declaration (N : Node_Id) is
2145 Process_Decisions (Generic_Formal_Declarations (N), 'X
', No_Location);
2146 Traverse_Package_Declaration (N);
2147 end Traverse_Generic_Package_Declaration;
2149 -----------------------------------------
2150 -- Traverse_Handled_Statement_Sequence --
2151 -----------------------------------------
2153 procedure Traverse_Handled_Statement_Sequence
2155 D : Dominant_Info := No_Dominant)
2160 -- For package bodies without a statement part, the parser adds an empty
2161 -- one, to normalize the representation. The null statement therein,
2162 -- which does not come from source, does not get a SCO.
2164 if Present (N) and then Comes_From_Source (N) then
2165 Traverse_Declarations_Or_Statements (Statements (N), D);
2167 if Present (Exception_Handlers (N)) then
2168 Handler := First (Exception_Handlers (N));
2169 while Present (Handler) loop
2170 Traverse_Declarations_Or_Statements
2171 (L => Statements (Handler),
2172 D => ('E
', Handler));
2177 end Traverse_Handled_Statement_Sequence;
2179 ---------------------------
2180 -- Traverse_Package_Body --
2181 ---------------------------
2183 procedure Traverse_Package_Body (N : Node_Id) is
2184 Dom : Dominant_Info;
2186 -- The first statement in the handled sequence of statements is
2187 -- dominated by the elaboration of the last declaration.
2189 Dom := Traverse_Declarations_Or_Statements (Declarations (N));
2191 Traverse_Handled_Statement_Sequence
2192 (Handled_Statement_Sequence (N), Dom);
2193 end Traverse_Package_Body;
2195 ----------------------------------
2196 -- Traverse_Package_Declaration --
2197 ----------------------------------
2199 procedure Traverse_Package_Declaration
2201 D : Dominant_Info := No_Dominant)
2203 Spec : constant Node_Id := Specification (N);
2204 Dom : Dominant_Info;
2208 Traverse_Declarations_Or_Statements (Visible_Declarations (Spec), D);
2210 -- First private declaration is dominated by last visible declaration
2212 Traverse_Declarations_Or_Statements (Private_Declarations (Spec), Dom);
2213 end Traverse_Package_Declaration;
2215 ------------------------------
2216 -- Traverse_Sync_Definition --
2217 ------------------------------
2219 procedure Traverse_Sync_Definition (N : Node_Id) is
2220 Dom_Info : Dominant_Info := ('S
', N);
2221 -- The first declaration is dominated by the protected or task [type]
2225 -- N's protected or task definition
2228 -- Sync_Def's Visible_Declarations
2232 when N_Single_Protected_Declaration | N_Protected_Type_Declaration =>
2233 Sync_Def := Protected_Definition (N);
2235 when N_Single_Task_Declaration | N_Task_Type_Declaration =>
2236 Sync_Def := Task_Definition (N);
2239 raise Program_Error;
2242 Vis_Decl := Visible_Declarations (Sync_Def);
2244 Dom_Info := Traverse_Declarations_Or_Statements
2248 -- If visible declarations are present, the first private declaration
2249 -- is dominated by the last visible declaration.
2251 Traverse_Declarations_Or_Statements
2252 (L => Private_Declarations (Sync_Def),
2254 end Traverse_Sync_Definition;
2256 --------------------------------------
2257 -- Traverse_Subprogram_Or_Task_Body --
2258 --------------------------------------
2260 procedure Traverse_Subprogram_Or_Task_Body
2262 D : Dominant_Info := No_Dominant)
2264 Decls : constant List_Id := Declarations (N);
2265 Dom_Info : Dominant_Info := D;
2267 -- If declarations are present, the first statement is dominated by the
2268 -- last declaration.
2270 Dom_Info := Traverse_Declarations_Or_Statements
2271 (L => Decls, D => Dom_Info);
2273 Traverse_Handled_Statement_Sequence
2274 (N => Handled_Statement_Sequence (N),
2276 end Traverse_Subprogram_Or_Task_Body;