OSDN Git Service

2011-08-29 Hristian Kirtchev <kirtchev@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / put_scos.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             P U T _ S C O S                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 2009-2011, 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 with Par_SCO; use Par_SCO;
27 with SCOs;    use SCOs;
28
29 procedure Put_SCOs is
30    Ctr : Nat;
31
32    procedure Output_Range (T : SCO_Table_Entry);
33    --  Outputs T.From and T.To in line:col-line:col format
34
35    procedure Output_Source_Location (Loc : Source_Location);
36    --  Output source location in line:col format
37
38    ------------------
39    -- Output_Range --
40    ------------------
41
42    procedure Output_Range (T : SCO_Table_Entry) is
43    begin
44       Output_Source_Location (T.From);
45       Write_Info_Char ('-');
46       Output_Source_Location (T.To);
47    end Output_Range;
48
49    ----------------------------
50    -- Output_Source_Location --
51    ----------------------------
52
53    procedure Output_Source_Location (Loc : Source_Location) is
54    begin
55       Write_Info_Nat  (Nat (Loc.Line));
56       Write_Info_Char (':');
57       Write_Info_Nat  (Nat (Loc.Col));
58    end Output_Source_Location;
59
60 --  Start of processing for Put_SCOs
61
62 begin
63    --  Loop through entries in SCO_Unit_Table
64
65    for U in 1 .. SCO_Unit_Table.Last loop
66       declare
67          SUT : SCO_Unit_Table_Entry renames SCO_Unit_Table.Table (U);
68
69          Start : Nat;
70          Stop  : Nat;
71
72       begin
73          Start := SUT.From;
74          Stop  := SUT.To;
75
76          --  Write unit header (omitted if no SCOs are generated for this unit)
77
78          if Start <= Stop then
79             Write_Info_Initiate ('C');
80             Write_Info_Char (' ');
81             Write_Info_Nat (SUT.Dep_Num);
82             Write_Info_Char (' ');
83
84             for N in SUT.File_Name'Range loop
85                Write_Info_Char (SUT.File_Name (N));
86             end loop;
87
88             Write_Info_Terminate;
89          end if;
90
91          --  Loop through SCO entries for this unit
92
93          loop
94             exit when Start = Stop + 1;
95             pragma Assert (Start <= Stop);
96
97             Output_SCO_Line : declare
98                T            : SCO_Table_Entry renames SCO_Table.Table (Start);
99                Continuation : Boolean;
100
101             begin
102                case T.C1 is
103
104                   --  Statements
105
106                   when 'S' =>
107                      Ctr := 0;
108                      Continuation := False;
109                      loop
110                         if SCO_Pragma_Disabled
111                              (SCO_Table.Table (Start).Pragma_Sloc)
112                         then
113                            goto Next_Statement;
114                         end if;
115
116                         if Ctr = 0 then
117                            Write_Info_Initiate ('C');
118                            if not Continuation then
119                               Write_Info_Char ('S');
120                               Continuation := True;
121                            else
122                               Write_Info_Char ('s');
123                            end if;
124                         end if;
125
126                         Write_Info_Char (' ');
127
128                         if SCO_Table.Table (Start).C2 /= ' ' then
129                            Write_Info_Char (SCO_Table.Table (Start).C2);
130                         end if;
131
132                         Output_Range (SCO_Table.Table (Start));
133
134                         --  Increment entry counter (up to 6 entries per line,
135                         --  continuation lines are marked Cs).
136
137                         Ctr := Ctr + 1;
138                         if Ctr = 6 then
139                            Write_Info_Terminate;
140                            Ctr := 0;
141                         end if;
142
143                      <<Next_Statement>>
144                         exit when SCO_Table.Table (Start).Last;
145                         Start := Start + 1;
146                         pragma Assert (SCO_Table.Table (Start).C1 = 's');
147                      end loop;
148
149                      Write_Info_Terminate;
150
151                   --  Statement continuations should not occur since they
152                   --  are supposed to have been handled in the loop above.
153
154                   when 's' =>
155                      raise Program_Error;
156
157                   --  Decision
158
159                   when 'E' | 'G' | 'I' | 'P' | 'W' | 'X' =>
160                      Start := Start + 1;
161
162                      --  For disabled pragma, or nested decision therein, skip
163                      --  decision output.
164
165                      if SCO_Pragma_Disabled (T.Pragma_Sloc) then
166                         while not SCO_Table.Table (Start).Last loop
167                            Start := Start + 1;
168                         end loop;
169
170                      --  For all other cases output decision line
171
172                      else
173                         Write_Info_Initiate ('C');
174                         Write_Info_Char (T.C1);
175
176                         if T.C1 /= 'X' then
177                            Write_Info_Char (' ');
178                            Output_Source_Location (T.From);
179                         end if;
180
181                         --  Loop through table entries for this decision
182
183                         loop
184                            declare
185                               T : SCO_Table_Entry
186                                     renames SCO_Table.Table (Start);
187
188                            begin
189                               Write_Info_Char (' ');
190
191                               if T.C1 = '!' or else
192                                  T.C1 = '&' or else
193                                  T.C1 = '|'
194                               then
195                                  Write_Info_Char (T.C1);
196                                  Output_Source_Location (T.From);
197
198                               else
199                                  Write_Info_Char (T.C2);
200                                  Output_Range (T);
201                               end if;
202
203                               exit when T.Last;
204                               Start := Start + 1;
205                            end;
206                         end loop;
207
208                         Write_Info_Terminate;
209                      end if;
210
211                   when others =>
212                      raise Program_Error;
213                end case;
214             end Output_SCO_Line;
215
216             Start := Start + 1;
217          end loop;
218       end;
219    end loop;
220 end Put_SCOs;