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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [ada/] [par-ch11.adb] - Blame information for rev 747

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

Line No. Rev Author Line
1 706 jeremybenn
------------------------------------------------------------------------------
2
--                                                                          --
3
--                         GNAT COMPILER COMPONENTS                         --
4
--                                                                          --
5
--                             P A R . C H 1 1                              --
6
--                                                                          --
7
--                                 B o d y                                  --
8
--                                                                          --
9
--          Copyright (C) 1992-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
pragma Style_Checks (All_Checks);
27
--  Turn off subprogram body ordering check. Subprograms are in order
28
--  by RM section rather than alphabetical
29
 
30
with Sinfo.CN; use Sinfo.CN;
31
 
32
separate (Par)
33
package body Ch11 is
34
 
35
   --  Local functions, used only in this chapter
36
 
37
   function P_Exception_Handler  return Node_Id;
38
   function P_Exception_Choice   return Node_Id;
39
 
40
   ---------------------------------
41
   -- 11.1  Exception Declaration --
42
   ---------------------------------
43
 
44
   --  Parsed by P_Identifier_Declaration (3.3.1)
45
 
46
   ------------------------------------------
47
   -- 11.2  Handled Sequence Of Statements --
48
   ------------------------------------------
49
 
50
   --  HANDLED_SEQUENCE_OF_STATEMENTS ::=
51
   --      SEQUENCE_OF_STATEMENTS
52
   --    [exception
53
   --      EXCEPTION_HANDLER
54
   --      {EXCEPTION_HANDLER}]
55
 
56
   --  Error_Recovery : Cannot raise Error_Resync
57
 
58
   function P_Handled_Sequence_Of_Statements return Node_Id is
59
      Handled_Stmt_Seq_Node  : Node_Id;
60
      Seq_Is_Hidden_In_SPARK : Boolean;
61
      Hidden_Region_Start    : Source_Ptr;
62
 
63
   begin
64
      Handled_Stmt_Seq_Node :=
65
        New_Node (N_Handled_Sequence_Of_Statements, Token_Ptr);
66
 
67
      --  In SPARK, a HIDE directive can be placed at the beginning of a
68
      --  package initialization, thus hiding the sequence of statements (and
69
      --  possible exception handlers) from SPARK tool-set. No violation of the
70
      --  SPARK restriction should be issued on nodes in a hidden part, which
71
      --  is obtained by marking such hidden parts.
72
 
73
      if Token = Tok_SPARK_Hide then
74
         Seq_Is_Hidden_In_SPARK := True;
75
         Hidden_Region_Start    := Token_Ptr;
76
         Scan; -- past HIDE directive
77
      else
78
         Seq_Is_Hidden_In_SPARK := False;
79
      end if;
80
 
81
      Set_Statements
82
        (Handled_Stmt_Seq_Node, P_Sequence_Of_Statements (SS_Extm_Sreq));
83
 
84
      if Token = Tok_Exception then
85
         Scan; -- past EXCEPTION
86
         Set_Exception_Handlers
87
           (Handled_Stmt_Seq_Node, Parse_Exception_Handlers);
88
      end if;
89
 
90
      if Seq_Is_Hidden_In_SPARK then
91
         Set_Hidden_Part_In_SPARK (Hidden_Region_Start, Token_Ptr);
92
      end if;
93
 
94
      return Handled_Stmt_Seq_Node;
95
   end P_Handled_Sequence_Of_Statements;
96
 
97
   -----------------------------
98
   -- 11.2  Exception Handler --
99
   -----------------------------
100
 
101
   --  EXCEPTION_HANDLER ::=
102
   --    when [CHOICE_PARAMETER_SPECIFICATION :]
103
   --      EXCEPTION_CHOICE {| EXCEPTION_CHOICE} =>
104
   --        SEQUENCE_OF_STATEMENTS
105
 
106
   --  CHOICE_PARAMETER_SPECIFICATION ::= DEFINING_IDENTIFIER
107
 
108
   --  Error recovery: cannot raise Error_Resync
109
 
110
   function P_Exception_Handler return Node_Id is
111
      Scan_State        : Saved_Scan_State;
112
      Handler_Node      : Node_Id;
113
      Choice_Param_Node : Node_Id;
114
 
115
   begin
116
      Exception_Handler_Encountered := True;
117
      Handler_Node := New_Node (N_Exception_Handler, Token_Ptr);
118
      Set_Local_Raise_Statements (Handler_Node, No_Elist);
119
 
120
      if Style_Check then
121
         Style.Check_Indentation;
122
      end if;
123
 
124
      T_When;
125
 
126
      --  Test for possible choice parameter present
127
 
128
      if Token = Tok_Identifier then
129
         Choice_Param_Node := Token_Node;
130
         Save_Scan_State (Scan_State); -- at identifier
131
         Scan; -- past identifier
132
 
133
         if Token = Tok_Colon then
134
            if Ada_Version = Ada_83 then
135
               Error_Msg_SP ("(Ada 83) choice parameter not allowed!");
136
            end if;
137
 
138
            Scan; -- past :
139
            Change_Identifier_To_Defining_Identifier (Choice_Param_Node);
140
            Set_Choice_Parameter (Handler_Node, Choice_Param_Node);
141
 
142
         elsif Token = Tok_Others then
143
            Error_Msg_AP -- CODEFIX
144
              ("missing "":""");
145
            Change_Identifier_To_Defining_Identifier (Choice_Param_Node);
146
            Set_Choice_Parameter (Handler_Node, Choice_Param_Node);
147
 
148
         else
149
            Restore_Scan_State (Scan_State); -- to identifier
150
         end if;
151
      end if;
152
 
153
      --  Loop through exception choices
154
 
155
      Set_Exception_Choices (Handler_Node, New_List);
156
 
157
      loop
158
         Append (P_Exception_Choice, Exception_Choices (Handler_Node));
159
         exit when Token /= Tok_Vertical_Bar;
160
         Scan; -- past vertical bar
161
      end loop;
162
 
163
      TF_Arrow;
164
      Set_Statements (Handler_Node, P_Sequence_Of_Statements (SS_Sreq_Whtm));
165
      return Handler_Node;
166
   end P_Exception_Handler;
167
 
168
   ------------------------------------------
169
   -- 11.2  Choice Parameter Specification --
170
   ------------------------------------------
171
 
172
   --  Parsed by P_Exception_Handler (11.2)
173
 
174
   ----------------------------
175
   -- 11.2  Exception Choice --
176
   ----------------------------
177
 
178
   --  EXCEPTION_CHOICE ::= exception_NAME | others
179
 
180
   --  Error recovery: cannot raise Error_Resync. If an error occurs, then the
181
   --  scan pointer is advanced to the next arrow or vertical bar or semicolon.
182
 
183
   function P_Exception_Choice return Node_Id is
184
   begin
185
 
186
      if Token = Tok_Others then
187
         Scan; -- past OTHERS
188
         return New_Node (N_Others_Choice, Prev_Token_Ptr);
189
 
190
      else
191
         return P_Name; -- exception name
192
      end if;
193
 
194
   exception
195
      when Error_Resync =>
196
         Resync_Choice;
197
         return Error;
198
   end P_Exception_Choice;
199
 
200
   ---------------------------
201
   -- 11.3  Raise Statement --
202
   ---------------------------
203
 
204
   --  RAISE_STATEMENT ::= raise [exception_NAME];
205
 
206
   --  The caller has verified that the initial token is RAISE
207
 
208
   --  Error recovery: can raise Error_Resync
209
 
210
   function P_Raise_Statement return Node_Id is
211
      Raise_Node : Node_Id;
212
 
213
   begin
214
      Raise_Node := New_Node (N_Raise_Statement, Token_Ptr);
215
      Scan; -- past RAISE
216
 
217
      if Token /= Tok_Semicolon then
218
         Set_Name (Raise_Node, P_Name);
219
      end if;
220
 
221
      if Token = Tok_With then
222
         if Ada_Version < Ada_2005 then
223
            Error_Msg_SC ("string expression in raise is Ada 2005 extension");
224
            Error_Msg_SC ("\unit must be compiled with -gnat05 switch");
225
         end if;
226
 
227
         Scan; -- past WITH
228
         Set_Expression (Raise_Node, P_Expression);
229
      end if;
230
 
231
      TF_Semicolon;
232
      return Raise_Node;
233
   end P_Raise_Statement;
234
 
235
   ------------------------------
236
   -- Parse_Exception_Handlers --
237
   ------------------------------
238
 
239
   --  This routine scans out a list of exception handlers appearing in a
240
   --  construct as:
241
 
242
   --    exception
243
   --      EXCEPTION_HANDLER {EXCEPTION_HANDLER}
244
 
245
   --  The caller has scanned out the EXCEPTION keyword
246
 
247
   --  Control returns after scanning the last exception handler, presumably
248
   --  at the keyword END, but this is not checked in this routine.
249
 
250
   --  Error recovery: cannot raise Error_Resync
251
 
252
   function Parse_Exception_Handlers return List_Id is
253
      Handler                    : Node_Id;
254
      Handlers_List              : List_Id;
255
      Handler_Is_Hidden_In_SPARK : Boolean;
256
      Hidden_Region_Start        : Source_Ptr;
257
 
258
   begin
259
      --  In SPARK, a HIDE directive can be placed at the beginning of a
260
      --  sequence of exception handlers for a subprogram implementation, thus
261
      --  hiding the exception handlers from SPARK tool-set. No violation of
262
      --  the SPARK restriction should be issued on nodes in a hidden part,
263
      --  which is obtained by marking such hidden parts.
264
 
265
      if Token = Tok_SPARK_Hide then
266
         Handler_Is_Hidden_In_SPARK := True;
267
         Hidden_Region_Start        := Token_Ptr;
268
         Scan; -- past HIDE directive
269
      else
270
         Handler_Is_Hidden_In_SPARK := False;
271
      end if;
272
 
273
      Handlers_List := New_List;
274
      P_Pragmas_Opt (Handlers_List);
275
 
276
      if Token = Tok_End then
277
         Error_Msg_SC ("must have at least one exception handler!");
278
 
279
      else
280
         loop
281
            Handler := P_Exception_Handler;
282
            Append (Handler, Handlers_List);
283
 
284
            --  Note: no need to check for pragmas here. Although the
285
            --  syntax officially allows them in this position, they
286
            --  will have been swallowed up as part of the statement
287
            --  sequence of the handler we just scanned out.
288
 
289
            exit when Token /= Tok_When;
290
         end loop;
291
      end if;
292
 
293
      if Handler_Is_Hidden_In_SPARK then
294
         Set_Hidden_Part_In_SPARK (Hidden_Region_Start, Token_Ptr);
295
      end if;
296
 
297
      return Handlers_List;
298
   end Parse_Exception_Handlers;
299
 
300
end Ch11;

powered by: WebSVN 2.1.0

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