1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2009-2010, 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 Atree
; use Atree
;
27 with Debug
; use Debug
;
29 with Lib
.Util
; use Lib
.Util
;
30 with Namet
; use Namet
;
31 with Nlists
; use Nlists
;
33 with Output
; use Output
;
36 with Sinfo
; use Sinfo
;
37 with Sinput
; use Sinput
;
38 with Snames
; use Snames
;
41 with GNAT
.HTable
; use GNAT
.HTable
;
42 with GNAT
.Heap_Sort_G
;
44 package body Par_SCO
is
46 -----------------------
47 -- Unit Number Table --
48 -----------------------
50 -- This table parallels the SCO_Unit_Table, keeping track of the unit
51 -- numbers corresponding to the entries made in this table, so that before
52 -- writing out the SCO information to the ALI file, we can fill in the
53 -- proper dependency numbers and file names.
55 -- Note that the zero'th entry is here for convenience in sorting the
56 -- table, the real lower bound is 1.
58 package SCO_Unit_Number_Table
is new Table
.Table
(
59 Table_Component_Type
=> Unit_Number_Type
,
60 Table_Index_Type
=> SCO_Unit_Index
,
61 Table_Low_Bound
=> 0, -- see note above on sort
63 Table_Increment
=> 200,
64 Table_Name
=> "SCO_Unit_Number_Entry");
66 ---------------------------------
67 -- Condition/Pragma Hash Table --
68 ---------------------------------
70 -- We need to be able to get to conditions quickly for handling the calls
71 -- to Set_SCO_Condition efficiently, and similarly to get to pragmas to
72 -- handle calls to Set_SCO_Pragma_Enabled. For this purpose we identify the
73 -- conditions and pragmas in the table by their starting sloc, and use this
74 -- hash table to map from these starting sloc values to SCO_Table indexes.
76 type Header_Num
is new Integer range 0 .. 996;
77 -- Type for hash table headers
79 function Hash
(F
: Source_Ptr
) return Header_Num
;
80 -- Function to Hash source pointer value
82 function Equal
(F1
, F2
: Source_Ptr
) return Boolean;
83 -- Function to test two keys for equality
85 package Condition_Pragma_Hash_Table
is new Simple_HTable
86 (Header_Num
, Int
, 0, Source_Ptr
, Hash
, Equal
);
87 -- The actual hash table
89 --------------------------
90 -- Internal Subprograms --
91 --------------------------
93 function Has_Decision
(N
: Node_Id
) return Boolean;
94 -- N is the node for a subexpression. Returns True if the subexpression
95 -- contains a nested decision (i.e. either is a logical operator, or
96 -- contains a logical operator in its subtree).
98 function Is_Logical_Operator
(N
: Node_Id
) return Boolean;
99 -- N is the node for a subexpression. This procedure just tests N to see
100 -- if it is a logical operator (including short circuit conditions, but
101 -- excluding OR and AND) and returns True if so, False otherwise, it does
102 -- no other processing.
104 procedure Process_Decisions
(N
: Node_Id
; T
: Character);
105 -- If N is Empty, has no effect. Otherwise scans the tree for the node N,
106 -- to output any decisions it contains. T is one of IEPWX (for context of
107 -- expresion: if/exit when/pragma/while/expression). If T is other than X,
108 -- the node N is the conditional expression involved, and a decision is
109 -- always present (at the very least a simple decision is present at the
112 procedure Process_Decisions
(L
: List_Id
; T
: Character);
113 -- Calls above procedure for each element of the list L
115 procedure Set_Table_Entry
121 -- Append an entry to SCO_Table with fields set as per arguments
123 procedure Traverse_Declarations_Or_Statements
(L
: List_Id
);
124 procedure Traverse_Generic_Instantiation
(N
: Node_Id
);
125 procedure Traverse_Generic_Package_Declaration
(N
: Node_Id
);
126 procedure Traverse_Handled_Statement_Sequence
(N
: Node_Id
);
127 procedure Traverse_Package_Body
(N
: Node_Id
);
128 procedure Traverse_Package_Declaration
(N
: Node_Id
);
129 procedure Traverse_Subprogram_Body
(N
: Node_Id
);
130 procedure Traverse_Subprogram_Declaration
(N
: Node_Id
);
131 -- Traverse the corresponding construct, generating SCO table entries
133 procedure Write_SCOs_To_ALI_File
is new Put_SCOs
;
134 -- Write SCO information to the ALI file using routines in Lib.Util
142 -- Dump SCO unit table
144 Write_Line
("SCO Unit Table");
145 Write_Line
("--------------");
147 for Index
in 1 .. SCO_Unit_Table
.Last
loop
149 UTE
: SCO_Unit_Table_Entry
renames SCO_Unit_Table
.Table
(Index
);
153 Write_Int
(Int
(Index
));
154 Write_Str
(". Dep_Num = ");
155 Write_Int
(Int
(UTE
.Dep_Num
));
156 Write_Str
(" From = ");
157 Write_Int
(Int
(UTE
.From
));
158 Write_Str
(" To = ");
159 Write_Int
(Int
(UTE
.To
));
161 Write_Str
(" File_Name = """);
163 if UTE
.File_Name
/= null then
164 Write_Str
(UTE
.File_Name
.all);
172 -- Dump SCO Unit number table if it contains any entries
174 if SCO_Unit_Number_Table
.Last
>= 1 then
176 Write_Line
("SCO Unit Number Table");
177 Write_Line
("---------------------");
179 for Index
in 1 .. SCO_Unit_Number_Table
.Last
loop
181 Write_Int
(Int
(Index
));
182 Write_Str
(". Unit_Number = ");
183 Write_Int
(Int
(SCO_Unit_Number_Table
.Table
(Index
)));
188 -- Dump SCO table itself
191 Write_Line
("SCO Table");
192 Write_Line
("---------");
194 for Index
in 1 .. SCO_Table
.Last
loop
196 T
: SCO_Table_Entry
renames SCO_Table
.Table
(Index
);
204 Write_Str
(" C1 = '");
210 Write_Str
(" C2 = '");
215 if T
.From
/= No_Source_Location
then
216 Write_Str
(" From = ");
217 Write_Int
(Int
(T
.From
.Line
));
219 Write_Int
(Int
(T
.From
.Col
));
222 if T
.To
/= No_Source_Location
then
223 Write_Str
(" To = ");
224 Write_Int
(Int
(T
.To
.Line
));
226 Write_Int
(Int
(T
.To
.Col
));
232 Write_Str
(" False");
244 function Equal
(F1
, F2
: Source_Ptr
) return Boolean is
253 function Has_Decision
(N
: Node_Id
) return Boolean is
255 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
261 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
263 if Is_Logical_Operator
(N
) then
270 function Traverse
is new Traverse_Func
(Check_Node
);
272 -- Start of processing for Has_Decision
275 return Traverse
(N
) = Abandon
;
282 function Hash
(F
: Source_Ptr
) return Header_Num
is
284 return Header_Num
(Nat
(F
) mod 997);
291 procedure Initialize
is
293 SCO_Unit_Number_Table
.Init
;
295 -- Set dummy 0'th entry in place for sort
297 SCO_Unit_Number_Table
.Increment_Last
;
300 -------------------------
301 -- Is_Logical_Operator --
302 -------------------------
304 function Is_Logical_Operator
(N
: Node_Id
) return Boolean is
306 return Nkind_In
(N
, N_Op_Not
,
309 end Is_Logical_Operator
;
311 -----------------------
312 -- Process_Decisions --
313 -----------------------
315 -- Version taking a list
317 procedure Process_Decisions
(L
: List_Id
; T
: Character) is
322 while Present
(N
) loop
323 Process_Decisions
(N
, T
);
327 end Process_Decisions
;
329 -- Version taking a node
331 procedure Process_Decisions
(N
: Node_Id
; T
: Character) is
334 -- This is used to mark the location of a decision sequence in the SCO
335 -- table. We use it for backing out a simple decision in an expression
336 -- context that contains only NOT operators.
338 X_Not_Decision
: Boolean;
339 -- This flag keeps track of whether a decision sequence in the SCO table
340 -- contains only NOT operators, and is for an expression context (T=X).
341 -- The flag will be set False if T is other than X, or if an operator
342 -- other than NOT is in the sequence.
344 function Process_Node
(N
: Node_Id
) return Traverse_Result
;
345 -- Processes one node in the traversal, looking for logical operators,
346 -- and if one is found, outputs the appropriate table entries.
348 procedure Output_Decision_Operand
(N
: Node_Id
);
349 -- The node N is the top level logical operator of a decision, or it is
350 -- one of the operands of a logical operator belonging to a single
351 -- complex decision. This routine outputs the sequence of table entries
352 -- corresponding to the node. Note that we do not process the sub-
353 -- operands to look for further decisions, that processing is done in
354 -- Process_Decision_Operand, because we can't get decisions mixed up in
355 -- the global table. Call has no effect if N is Empty.
357 procedure Output_Element
(N
: Node_Id
);
358 -- Node N is an operand of a logical operator that is not itself a
359 -- logical operator, or it is a simple decision. This routine outputs
360 -- the table entry for the element, with C1 set to ' '. Last is set
361 -- False, and an entry is made in the condition hash table.
363 procedure Output_Header
(T
: Character);
364 -- Outputs a decision header node. T is I/W/E/P for IF/WHILE/EXIT WHEN/
365 -- PRAGMA, and 'X' for the expression case.
367 procedure Process_Decision_Operand
(N
: Node_Id
);
368 -- This is called on node N, the top level node of a decision, or on one
369 -- of its operands or suboperands after generating the full output for
370 -- the complex decision. It process the suboperands of the decision
371 -- looking for nested decisions.
373 -----------------------------
374 -- Output_Decision_Operand --
375 -----------------------------
377 procedure Output_Decision_Operand
(N
: Node_Id
) is
387 elsif Is_Logical_Operator
(N
) then
388 if Nkind
(N
) = N_Op_Not
then
395 if Nkind_In
(N
, N_Op_Or
, N_Or_Else
) then
409 Output_Decision_Operand
(L
);
410 Output_Decision_Operand
(Right_Opnd
(N
));
412 -- Not a logical operator
417 end Output_Decision_Operand
;
423 procedure Output_Element
(N
: Node_Id
) is
427 Sloc_Range
(N
, FSloc
, LSloc
);
434 Condition_Pragma_Hash_Table
.Set
(FSloc
, SCO_Table
.Last
);
441 procedure Output_Header
(T
: Character) is
444 when 'I' |
'E' |
'W' =>
446 -- For IF, EXIT, WHILE, the token SLOC can be found from
447 -- the SLOC of the parent of the expression.
452 From
=> Sloc
(Parent
(N
)),
458 -- For PRAGMA, we must get the location from the pragma node.
459 -- Argument N is the pragma argument, and we have to go up two
460 -- levels (through the pragma argument association) to get to
461 -- the pragma node itself.
464 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Parent
(N
)));
474 -- For pragmas we also must make an entry in the hash table
475 -- for later access by Set_SCO_Pragma_Enabled. We set the
476 -- pragma as disabled above, the call will change C2 to 'e'
477 -- to enable the pragma header entry.
479 Condition_Pragma_Hash_Table
.Set
(Loc
, SCO_Table
.Last
);
484 -- For an expression, no Sloc
493 -- No other possibilities
500 ------------------------------
501 -- Process_Decision_Operand --
502 ------------------------------
504 procedure Process_Decision_Operand
(N
: Node_Id
) is
506 if Is_Logical_Operator
(N
) then
507 if Nkind
(N
) /= N_Op_Not
then
508 Process_Decision_Operand
(Left_Opnd
(N
));
509 X_Not_Decision
:= False;
512 Process_Decision_Operand
(Right_Opnd
(N
));
515 Process_Decisions
(N
, 'X');
517 end Process_Decision_Operand
;
523 function Process_Node
(N
: Node_Id
) return Traverse_Result
is
527 -- Logical operators, output table entries and then process
528 -- operands recursively to deal with nested conditions.
538 -- If outer level, then type comes from call, otherwise it
539 -- is more deeply nested and counts as X for expression.
541 if N
= Process_Decisions
.N
then
542 T
:= Process_Decisions
.T
;
547 -- Output header for sequence
549 X_Not_Decision
:= T
= 'X' and then Nkind
(N
) = N_Op_Not
;
550 Mark
:= SCO_Table
.Last
;
553 -- Output the decision
555 Output_Decision_Operand
(N
);
557 -- If the decision was in an expression context (T = 'X')
558 -- and contained only NOT operators, then we don't output
561 if X_Not_Decision
then
562 SCO_Table
.Set_Last
(Mark
);
564 -- Otherwise, set Last in last table entry to mark end
567 SCO_Table
.Table
(SCO_Table
.Last
).Last
:= True;
570 -- Process any embedded decisions
572 Process_Decision_Operand
(N
);
578 when N_Case_Expression
=>
581 -- Conditional expression, processed like an if statement
583 when N_Conditional_Expression
=>
585 Cond
: constant Node_Id
:= First
(Expressions
(N
));
586 Thnx
: constant Node_Id
:= Next
(Cond
);
587 Elsx
: constant Node_Id
:= Next
(Thnx
);
589 Process_Decisions
(Cond
, 'I');
590 Process_Decisions
(Thnx
, 'X');
591 Process_Decisions
(Elsx
, 'X');
595 -- All other cases, continue scan
603 procedure Traverse
is new Traverse_Proc
(Process_Node
);
605 -- Start of processing for Process_Decisions
612 -- See if we have simple decision at outer level and if so then
613 -- generate the decision entry for this simple decision. A simple
614 -- decision is a boolean expression (which is not a logical operator
615 -- or short circuit form) appearing as the operand of an IF, WHILE,
616 -- EXIT WHEN, or special PRAGMA construct.
618 if T
/= 'X' and then not Is_Logical_Operator
(N
) then
622 -- Change Last in last table entry to True to mark end of
623 -- sequence, which is this case is only one element long.
625 SCO_Table
.Table
(SCO_Table
.Last
).Last
:= True;
629 end Process_Decisions
;
637 procedure Write_Info_Char
(C
: Character) renames Write_Char
;
638 -- Write one character;
640 procedure Write_Info_Initiate
(Key
: Character) renames Write_Char
;
641 -- Start new one and write one character;
643 procedure Write_Info_Nat
(N
: Nat
);
646 procedure Write_Info_Terminate
renames Write_Eol
;
647 -- Terminate current line
653 procedure Write_Info_Nat
(N
: Nat
) is
658 procedure Debug_Put_SCOs
is new Put_SCOs
;
660 -- Start of processing for pscos
670 procedure SCO_Output
is
672 if Debug_Flag_Dot_OO
then
676 -- Sort the unit tables based on dependency numbers
678 Unit_Table_Sort
: declare
680 function Lt
(Op1
, Op2
: Natural) return Boolean;
681 -- Comparison routine for sort call
683 procedure Move
(From
: Natural; To
: Natural);
684 -- Move routine for sort call
690 function Lt
(Op1
, Op2
: Natural) return Boolean is
694 (SCO_Unit_Number_Table
.Table
(SCO_Unit_Index
(Op1
)))
697 (SCO_Unit_Number_Table
.Table
(SCO_Unit_Index
(Op2
)));
704 procedure Move
(From
: Natural; To
: Natural) is
706 SCO_Unit_Table
.Table
(SCO_Unit_Index
(To
)) :=
707 SCO_Unit_Table
.Table
(SCO_Unit_Index
(From
));
708 SCO_Unit_Number_Table
.Table
(SCO_Unit_Index
(To
)) :=
709 SCO_Unit_Number_Table
.Table
(SCO_Unit_Index
(From
));
712 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
714 -- Start of processing for Unit_Table_Sort
717 Sorting
.Sort
(Integer (SCO_Unit_Table
.Last
));
720 -- Loop through entries in the unit table to set file name and
721 -- dependency number entries.
723 for J
in 1 .. SCO_Unit_Table
.Last
loop
725 U
: constant Unit_Number_Type
:= SCO_Unit_Number_Table
.Table
(J
);
726 UTE
: SCO_Unit_Table_Entry
renames SCO_Unit_Table
.Table
(J
);
728 Get_Name_String
(Reference_Name
(Source_Index
(U
)));
729 UTE
.File_Name
:= new String'(Name_Buffer (1 .. Name_Len));
730 UTE.Dep_Num := Dependency_Num (U);
734 -- Now the tables are all setup for output to the ALI file
736 Write_SCOs_To_ALI_File;
743 procedure SCO_Record (U : Unit_Number_Type) is
748 -- Ignore call if not generating code and generating SCO's
750 if not (Generate_SCO and then Operating_Mode = Generate_Code) then
754 -- Ignore call if this unit already recorded
756 for J in 1 .. SCO_Unit_Number_Table.Last loop
757 if U = SCO_Unit_Number_Table.Table (J) then
762 -- Otherwise record starting entry
764 From := SCO_Table.Last + 1;
766 -- Get Unit (checking case of subunit)
768 Lu := Unit (Cunit (U));
770 if Nkind (Lu) = N_Subunit then
771 Lu := Proper_Body (Lu);
776 if Nkind (Lu) = N_Subprogram_Body then
777 Traverse_Subprogram_Body (Lu);
779 elsif Nkind (Lu) = N_Subprogram_Declaration then
780 Traverse_Subprogram_Declaration (Lu);
782 elsif Nkind (Lu) = N_Package_Declaration then
783 Traverse_Package_Declaration (Lu);
785 elsif Nkind (Lu) = N_Package_Body then
786 Traverse_Package_Body (Lu);
788 elsif Nkind (Lu) = N_Generic_Package_Declaration then
789 Traverse_Generic_Package_Declaration (Lu);
791 elsif Nkind (Lu) in N_Generic_Instantiation then
792 Traverse_Generic_Instantiation (Lu);
794 -- All other cases of compilation units (e.g. renamings), generate
795 -- no SCO information.
801 -- Make entry for new unit in unit tables, we will fill in the file
802 -- name and dependency numbers later.
804 SCO_Unit_Table.Append (
808 To => SCO_Table.Last));
810 SCO_Unit_Number_Table.Append (U);
813 -----------------------
814 -- Set_SCO_Condition --
815 -----------------------
817 procedure Set_SCO_Condition (Cond : Node_Id; Val : Boolean) is
818 Orig : constant Node_Id := Original_Node (Cond);
823 Constant_Condition_Code : constant array (Boolean) of Character :=
824 (False => 'f
', True => 't
');
826 Sloc_Range (Orig, Start, Dummy);
827 Index := Condition_Pragma_Hash_Table.Get (Start);
829 -- The test here for zero is to deal with possible previous errors
832 pragma Assert (SCO_Table.Table (Index).C1 = ' ');
833 SCO_Table.Table (Index).C2 := Constant_Condition_Code (Val);
835 end Set_SCO_Condition;
837 ----------------------------
838 -- Set_SCO_Pragma_Enabled --
839 ----------------------------
841 procedure Set_SCO_Pragma_Enabled (Loc : Source_Ptr) is
845 -- Note: the reason we use the Sloc value as the key is that in the
846 -- generic case, the call to this procedure is made on a copy of the
847 -- original node, so we can't use the Node_Id value.
849 Index := Condition_Pragma_Hash_Table.Get (Loc);
851 -- The test here for zero is to deal with possible previous errors
854 pragma Assert (SCO_Table.Table (Index).C1 = 'P
');
855 SCO_Table.Table (Index).C2 := 'e
';
857 end Set_SCO_Pragma_Enabled;
859 ---------------------
860 -- Set_Table_Entry --
861 ---------------------
863 procedure Set_Table_Entry
870 function To_Source_Location (S : Source_Ptr) return Source_Location;
871 -- Converts Source_Ptr value to Source_Location (line/col) format
873 ------------------------
874 -- To_Source_Location --
875 ------------------------
877 function To_Source_Location (S : Source_Ptr) return Source_Location is
879 if S = No_Location then
880 return No_Source_Location;
883 (Line => Get_Logical_Line_Number (S),
884 Col => Get_Column_Number (S));
886 end To_Source_Location;
888 -- Start of processing for Set_Table_Entry
894 From => To_Source_Location (From),
895 To => To_Source_Location (To),
899 -----------------------------------------
900 -- Traverse_Declarations_Or_Statements --
901 -----------------------------------------
903 -- Tables used by Traverse_Declarations_Or_Statements for temporarily
904 -- holding statement and decision entries. These are declared globally
905 -- since they are shared by recursive calls to this procedure.
907 type SC_Entry is record
912 -- Used to store a single entry in the following table, From:To represents
913 -- the range of entries in the CS line entry, and typ is the type, with
914 -- space meaning that no type letter will accompany the entry.
916 package SC is new Table.Table (
917 Table_Component_Type => SC_Entry,
918 Table_Index_Type => Nat,
919 Table_Low_Bound => 1,
920 Table_Initial => 1000,
921 Table_Increment => 200,
922 Table_Name => "SCO_SC");
923 -- Used to store statement components for a CS entry to be output
924 -- as a result of the call to this procedure. SC.Last is the last
925 -- entry stored, so the current statement sequence is represented
926 -- by SC_Array (SC_First .. SC.Last), where SC_First is saved on
927 -- entry to each recursive call to the routine.
929 -- Extend_Statement_Sequence adds an entry to this array, and then
930 -- Set_Statement_Entry clears the entries starting with SC_First,
931 -- copying these entries to the main SCO output table. The reason that
932 -- we do the temporary caching of results in this array is that we want
933 -- the SCO table entries for a given CS line to be contiguous, and the
934 -- processing may output intermediate entries such as decision entries.
936 type SD_Entry is record
941 -- Used to store a single entry in the following table. Nod is the node to
942 -- be searched for decisions for the case of Process_Decisions_Defer with a
943 -- node argument (with Lst set to No_List. Lst is the list to be searched
944 -- for decisions for the case of Process_Decisions_Defer with a List
945 -- argument (in which case Nod is set to Empty).
947 package SD is new Table.Table (
948 Table_Component_Type => SD_Entry,
949 Table_Index_Type => Nat,
950 Table_Low_Bound => 1,
951 Table_Initial => 1000,
952 Table_Increment => 200,
953 Table_Name => "SCO_SD");
954 -- Used to store possible decision information. Instead of calling the
955 -- Process_Decisions procedures directly, we call Process_Decisions_Defer,
956 -- which simply stores the arguments in this table. Then when we clear
957 -- out a statement sequence using Set_Statement_Entry, after generating
958 -- the CS lines for the statements, the entries in this table result in
959 -- calls to Process_Decision. The reason for doing things this way is to
960 -- ensure that decisions are output after the CS line for the statements
961 -- in which the decisions occur.
963 procedure Traverse_Declarations_Or_Statements (L : List_Id) is
967 SC_First : constant Nat := SC.Last + 1;
968 SD_First : constant Nat := SD.Last + 1;
969 -- Record first entries used in SC/SD at this recursive level
971 procedure Extend_Statement_Sequence (N : Node_Id; Typ : Character);
972 -- Extend the current statement sequence to encompass the node N. Typ
973 -- is the letter that identifies the type of statement/declaration that
974 -- is being added to the sequence.
976 procedure Extend_Statement_Sequence
980 -- This version extends the current statement sequence with an entry
981 -- that starts with the first token of From, and ends with the last
982 -- token of To. It is used for example in a CASE statement to cover
983 -- the range from the CASE token to the last token of the expression.
985 procedure Set_Statement_Entry;
986 -- If Start is No_Location, does nothing, otherwise outputs a SCO_Table
987 -- statement entry for the range Start-Stop and then sets both Start
988 -- and Stop to No_Location. Unconditionally sets Term to True. This is
989 -- called when we find a statement or declaration that generates its
990 -- own table entry, so that we must end the current statement sequence.
992 procedure Process_Decisions_Defer (N : Node_Id; T : Character);
993 pragma Inline (Process_Decisions_Defer);
994 -- This routine is logically the same as Process_Decisions, except that
995 -- the arguments are saved in the SD table, for later processing when
996 -- Set_Statement_Entry is called, which goes through the saved entries
997 -- making the corresponding calls to Process_Decision.
999 procedure Process_Decisions_Defer (L : List_Id; T : Character);
1000 pragma Inline (Process_Decisions_Defer);
1001 -- Same case for list arguments, deferred call to Process_Decisions
1003 -------------------------
1004 -- Set_Statement_Entry --
1005 -------------------------
1007 procedure Set_Statement_Entry is
1009 SC_Last : constant Int := SC.Last;
1010 SD_Last : constant Int := SD.Last;
1013 -- Output statement entries from saved entries in SC table
1015 for J in SC_First .. SC_Last loop
1016 if J = SC_First then
1023 SCE : SC_Entry renames SC.Table (J);
1030 Last => (J = SC_Last));
1034 -- Clear out used section of SC table
1036 SC.Set_Last (SC_First - 1);
1038 -- Output any embedded decisions
1040 for J in SD_First .. SD_Last loop
1042 SDE : SD_Entry renames SD.Table (J);
1044 if Present (SDE.Nod) then
1045 Process_Decisions (SDE.Nod, SDE.Typ);
1047 Process_Decisions (SDE.Lst, SDE.Typ);
1052 -- Clear out used section of SD table
1054 SD.Set_Last (SD_First - 1);
1055 end Set_Statement_Entry;
1057 -------------------------------
1058 -- Extend_Statement_Sequence --
1059 -------------------------------
1061 procedure Extend_Statement_Sequence (N : Node_Id; Typ : Character) is
1065 Sloc_Range (N, F, T);
1066 SC.Append ((F, T, Typ));
1067 end Extend_Statement_Sequence;
1069 procedure Extend_Statement_Sequence
1077 Sloc_Range (From, F, Dummy);
1078 Sloc_Range (To, Dummy, T);
1079 SC.Append ((F, T, Typ));
1080 end Extend_Statement_Sequence;
1082 -----------------------------
1083 -- Process_Decisions_Defer --
1084 -----------------------------
1086 procedure Process_Decisions_Defer (N : Node_Id; T : Character) is
1088 SD.Append ((N, No_List, T));
1089 end Process_Decisions_Defer;
1091 procedure Process_Decisions_Defer (L : List_Id; T : Character) is
1093 SD.Append ((Empty, L, T));
1094 end Process_Decisions_Defer;
1096 -- Start of processing for Traverse_Declarations_Or_Statements
1099 if Is_Non_Empty_List (L) then
1101 -- Loop through statements or declarations
1104 while Present (N) loop
1106 -- Initialize or extend current statement sequence. Note that for
1107 -- special cases such as IF and Case statements we will modify
1108 -- the range to exclude internal statements that should not be
1109 -- counted as part of the current statement sequence.
1113 -- Package declaration
1115 when N_Package_Declaration =>
1116 Set_Statement_Entry;
1117 Traverse_Package_Declaration (N);
1119 -- Generic package declaration
1121 when N_Generic_Package_Declaration =>
1122 Set_Statement_Entry;
1123 Traverse_Generic_Package_Declaration (N);
1127 when N_Package_Body =>
1128 Set_Statement_Entry;
1129 Traverse_Package_Body (N);
1131 -- Subprogram declaration
1133 when N_Subprogram_Declaration =>
1134 Process_Decisions_Defer
1135 (Parameter_Specifications (Specification (N)), 'X
');
1136 Set_Statement_Entry;
1138 -- Generic subprogram declaration
1140 when N_Generic_Subprogram_Declaration =>
1141 Process_Decisions_Defer
1142 (Generic_Formal_Declarations (N), 'X
');
1143 Process_Decisions_Defer
1144 (Parameter_Specifications (Specification (N)), 'X
');
1145 Set_Statement_Entry;
1149 when N_Subprogram_Body =>
1150 Set_Statement_Entry;
1151 Traverse_Subprogram_Body (N);
1153 -- Exit statement, which is an exit statement in the SCO sense,
1154 -- so it is included in the current statement sequence, but
1155 -- then it terminates this sequence. We also have to process
1156 -- any decisions in the exit statement expression.
1158 when N_Exit_Statement =>
1159 Extend_Statement_Sequence (N, ' ');
1160 Process_Decisions_Defer (Condition (N), 'E
');
1161 Set_Statement_Entry;
1163 -- Label, which breaks the current statement sequence, but the
1164 -- label itself is not included in the next statement sequence,
1165 -- since it generates no code.
1168 Set_Statement_Entry;
1170 -- Block statement, which breaks the current statement sequence
1172 when N_Block_Statement =>
1173 Set_Statement_Entry;
1174 Traverse_Declarations_Or_Statements (Declarations (N));
1175 Traverse_Handled_Statement_Sequence
1176 (Handled_Statement_Sequence (N));
1178 -- If statement, which breaks the current statement sequence,
1179 -- but we include the condition in the current sequence.
1181 when N_If_Statement =>
1182 Extend_Statement_Sequence (N, Condition (N), 'I
');
1183 Process_Decisions_Defer (Condition (N), 'I
');
1184 Set_Statement_Entry;
1186 -- Now we traverse the statements in the THEN part
1188 Traverse_Declarations_Or_Statements (Then_Statements (N));
1190 -- Loop through ELSIF parts if present
1192 if Present (Elsif_Parts (N)) then
1194 Elif : Node_Id := First (Elsif_Parts (N));
1197 while Present (Elif) loop
1199 -- We generate a statement sequence for the
1200 -- construct "ELSIF condition", so that we have
1201 -- a statement for the resulting decisions.
1203 Extend_Statement_Sequence
1204 (Elif, Condition (Elif), 'I
');
1205 Process_Decisions_Defer (Condition (Elif), 'I
');
1206 Set_Statement_Entry;
1208 -- Traverse the statements in the ELSIF
1210 Traverse_Declarations_Or_Statements
1211 (Then_Statements (Elif));
1217 -- Finally traverse the ELSE statements if present
1219 Traverse_Declarations_Or_Statements (Else_Statements (N));
1221 -- Case statement, which breaks the current statement sequence,
1222 -- but we include the expression in the current sequence.
1224 when N_Case_Statement =>
1225 Extend_Statement_Sequence (N, Expression (N), 'C
');
1226 Process_Decisions_Defer (Expression (N), 'X
');
1227 Set_Statement_Entry;
1229 -- Process case branches
1234 Alt := First (Alternatives (N));
1235 while Present (Alt) loop
1236 Traverse_Declarations_Or_Statements (Statements (Alt));
1241 -- Unconditional exit points, which are included in the current
1242 -- statement sequence, but then terminate it
1244 when N_Requeue_Statement |
1246 N_Raise_Statement =>
1247 Extend_Statement_Sequence (N, ' ');
1248 Set_Statement_Entry;
1250 -- Simple return statement. which is an exit point, but we
1251 -- have to process the return expression for decisions.
1253 when N_Simple_Return_Statement =>
1254 Extend_Statement_Sequence (N, ' ');
1255 Process_Decisions_Defer (Expression (N), 'X
');
1256 Set_Statement_Entry;
1258 -- Extended return statement
1260 when N_Extended_Return_Statement =>
1261 Extend_Statement_Sequence
1262 (N, Last (Return_Object_Declarations (N)), 'R
');
1263 Process_Decisions_Defer
1264 (Return_Object_Declarations (N), 'X
');
1265 Set_Statement_Entry;
1267 Traverse_Handled_Statement_Sequence
1268 (Handled_Statement_Sequence (N));
1270 -- Loop ends the current statement sequence, but we include
1271 -- the iteration scheme if present in the current sequence.
1272 -- But the body of the loop starts a new sequence, since it
1273 -- may not be executed as part of the current sequence.
1275 when N_Loop_Statement =>
1276 if Present (Iteration_Scheme (N)) then
1278 -- If iteration scheme present, extend the current
1279 -- statement sequence to include the iteration scheme
1280 -- and process any decisions it contains.
1283 ISC : constant Node_Id := Iteration_Scheme (N);
1288 if Present (Condition (ISC)) then
1289 Extend_Statement_Sequence (N, ISC, 'W
');
1290 Process_Decisions_Defer (Condition (ISC), 'W
');
1295 Extend_Statement_Sequence (N, ISC, 'F
');
1296 Process_Decisions_Defer
1297 (Loop_Parameter_Specification (ISC), 'X
');
1302 Set_Statement_Entry;
1303 Traverse_Declarations_Or_Statements (Statements (N));
1308 Extend_Statement_Sequence (N, 'P
');
1310 -- Processing depends on the kind of pragma
1312 case Pragma_Name (N) is
1316 Name_Postcondition =>
1318 -- For Assert/Check/Precondition/Postcondition, we
1319 -- must generate a P entry for the decision. Note that
1320 -- this is done unconditionally at this stage. Output
1321 -- for disabled pragmas is suppressed later on, when
1322 -- we output the decision line in Put_SCOs.
1325 Nam : constant Name_Id :=
1326 Chars (Pragma_Identifier (N));
1328 First (Pragma_Argument_Associations (N));
1331 if Nam = Name_Check then
1335 Process_Decisions_Defer (Expression (Arg), 'P
');
1338 -- For all other pragmas, we generate decision entries
1339 -- for any embedded expressions.
1342 Process_Decisions_Defer (N, 'X
');
1345 -- Object declaration. Ignored if Prev_Ids is set, since the
1346 -- parser generates multiple instances of the whole declaration
1347 -- if there is more than one identifier declared, and we only
1348 -- want one entry in the SCO's, so we take the first, for which
1349 -- Prev_Ids is False.
1351 when N_Object_Declaration =>
1352 if not Prev_Ids (N) then
1353 Extend_Statement_Sequence (N, 'o
');
1355 if Has_Decision (N) then
1356 Process_Decisions_Defer (N, 'X
');
1360 -- All other cases, which extend the current statement sequence
1361 -- but do not terminate it, even if they have nested decisions.
1365 -- Determine required type character code
1372 when N_Full_Type_Declaration |
1373 N_Incomplete_Type_Declaration |
1374 N_Private_Type_Declaration |
1375 N_Private_Extension_Declaration =>
1378 when N_Subtype_Declaration =>
1381 when N_Renaming_Declaration =>
1384 when N_Generic_Instantiation =>
1391 Extend_Statement_Sequence (N, Typ);
1394 -- Process any embedded decisions
1396 if Has_Decision (N) then
1397 Process_Decisions_Defer (N, 'X
');
1404 Set_Statement_Entry;
1406 end Traverse_Declarations_Or_Statements;
1408 ------------------------------------
1409 -- Traverse_Generic_Instantiation --
1410 ------------------------------------
1412 procedure Traverse_Generic_Instantiation (N : Node_Id) is
1417 -- First we need a statement entry to cover the instantiation
1419 Sloc_Range (N, First, Last);
1427 -- Now output any embedded decisions
1429 Process_Decisions (N, 'X
');
1430 end Traverse_Generic_Instantiation;
1432 ------------------------------------------
1433 -- Traverse_Generic_Package_Declaration --
1434 ------------------------------------------
1436 procedure Traverse_Generic_Package_Declaration (N : Node_Id) is
1438 Process_Decisions (Generic_Formal_Declarations (N), 'X
');
1439 Traverse_Package_Declaration (N);
1440 end Traverse_Generic_Package_Declaration;
1442 -----------------------------------------
1443 -- Traverse_Handled_Statement_Sequence --
1444 -----------------------------------------
1446 procedure Traverse_Handled_Statement_Sequence (N : Node_Id) is
1450 -- For package bodies without a statement part, the parser adds an empty
1451 -- one, to normalize the representation. The null statement therein,
1452 -- which does not come from source, does not get a SCO.
1454 if Present (N) and then Comes_From_Source (N) then
1455 Traverse_Declarations_Or_Statements (Statements (N));
1457 if Present (Exception_Handlers (N)) then
1458 Handler := First (Exception_Handlers (N));
1459 while Present (Handler) loop
1460 Traverse_Declarations_Or_Statements (Statements (Handler));
1465 end Traverse_Handled_Statement_Sequence;
1467 ---------------------------
1468 -- Traverse_Package_Body --
1469 ---------------------------
1471 procedure Traverse_Package_Body (N : Node_Id) is
1473 Traverse_Declarations_Or_Statements (Declarations (N));
1474 Traverse_Handled_Statement_Sequence (Handled_Statement_Sequence (N));
1475 end Traverse_Package_Body;
1477 ----------------------------------
1478 -- Traverse_Package_Declaration --
1479 ----------------------------------
1481 procedure Traverse_Package_Declaration (N : Node_Id) is
1482 Spec : constant Node_Id := Specification (N);
1484 Traverse_Declarations_Or_Statements (Visible_Declarations (Spec));
1485 Traverse_Declarations_Or_Statements (Private_Declarations (Spec));
1486 end Traverse_Package_Declaration;
1488 ------------------------------
1489 -- Traverse_Subprogram_Body --
1490 ------------------------------
1492 procedure Traverse_Subprogram_Body (N : Node_Id) is
1494 Traverse_Declarations_Or_Statements (Declarations (N));
1495 Traverse_Handled_Statement_Sequence (Handled_Statement_Sequence (N));
1496 end Traverse_Subprogram_Body;
1498 -------------------------------------
1499 -- Traverse_Subprogram_Declaration --
1500 -------------------------------------
1502 procedure Traverse_Subprogram_Declaration (N : Node_Id) is
1503 ADN : constant Node_Id := Aux_Decls_Node (Parent (N));
1505 Traverse_Declarations_Or_Statements (Config_Pragmas (ADN));
1506 Traverse_Declarations_Or_Statements (Declarations (ADN));
1507 Traverse_Declarations_Or_Statements (Pragmas_After (ADN));
1508 end Traverse_Subprogram_Declaration;