* config/xtensa/linux.h (TARGET_OS_CPP_BUILTINS): Remove definition of
[official-gcc.git] / gcc / ada / par-sync.adb
bloba9646b0f7c3603efe1c58d03b3a5ba5d93056cd5
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P A R . S Y N C --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2001 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 separate (Par)
28 package body Sync is
30 procedure Resync_Init;
31 -- This routine is called on initiating a resynchronization action
33 procedure Resync_Resume;
34 -- This routine is called on completing a resynchronization action
36 -------------------
37 -- Resync_Choice --
38 -------------------
40 procedure Resync_Choice is
41 begin
42 Resync_Init;
44 -- Loop till we get a token that terminates a choice. Note that EOF is
45 -- one such token, so we are sure to get out of this loop eventually!
47 while Token not in Token_Class_Cterm loop
48 Scan;
49 end loop;
51 Resync_Resume;
52 end Resync_Choice;
54 ------------------
55 -- Resync_Cunit --
56 ------------------
58 procedure Resync_Cunit is
59 begin
60 Resync_Init;
62 while Token not in Token_Class_Cunit
63 and then Token /= Tok_EOF
64 loop
65 Scan;
66 end loop;
68 Resync_Resume;
69 end Resync_Cunit;
71 -----------------------
72 -- Resync_Expression --
73 -----------------------
75 procedure Resync_Expression is
76 Paren_Count : Int;
78 begin
79 Resync_Init;
80 Paren_Count := 0;
82 loop
83 -- Terminating tokens are those in class Eterm and also RANGE,
84 -- DIGITS or DELTA if not preceded by an apostrophe (if they are
85 -- preceded by an apostrophe, then they are attributes). In addiion,
86 -- at the outer parentheses level only, we also consider a comma,
87 -- right parenthesis or vertical bar to terminate an expression.
89 if Token in Token_Class_Eterm
91 or else (Token in Token_Class_Atkwd
92 and then Prev_Token /= Tok_Apostrophe)
94 or else (Paren_Count = 0
95 and then
96 (Token = Tok_Comma
97 or else Token = Tok_Right_Paren
98 or else Token = Tok_Vertical_Bar))
99 then
100 -- A special check: if we stop on the ELSE of OR ELSE or the
101 -- THEN of AND THEN, keep going, because this is not really an
102 -- expression terminator after all. Also, keep going past WITH
103 -- since this can be part of an extension aggregate
105 if (Token = Tok_Else and then Prev_Token = Tok_Or)
106 or else (Token = Tok_Then and then Prev_Token = Tok_And)
107 or else Token = Tok_With
108 then
109 null;
110 else
111 exit;
112 end if;
113 end if;
115 if Token = Tok_Left_Paren then
116 Paren_Count := Paren_Count + 1;
118 elsif Token = Tok_Right_Paren then
119 Paren_Count := Paren_Count - 1;
121 end if;
123 Scan; -- past token to be skipped
124 end loop;
126 Resync_Resume;
127 end Resync_Expression;
129 -----------------
130 -- Resync_Init --
131 -----------------
133 procedure Resync_Init is
134 begin
135 -- The following check makes sure we do not get stuck in an infinite
136 -- loop resynchonizing and getting nowhere. If we are called to do a
137 -- resynchronize and we are exactly at the same point that we left off
138 -- on the last resynchronize call, then we force at least one token to
139 -- be skipped so that we make progress!
141 if Token_Ptr = Last_Resync_Point then
142 Scan; -- to skip at least one token
143 end if;
145 -- Output extra error message if debug R flag is set
147 if Debug_Flag_R then
148 Error_Msg_SC ("resynchronizing!");
149 end if;
150 end Resync_Init;
152 ---------------------------
153 -- Resync_Past_Semicolon --
154 ---------------------------
156 procedure Resync_Past_Semicolon is
157 begin
158 Resync_Init;
160 loop
161 -- Done if we are at a semicolon
163 if Token = Tok_Semicolon then
164 Scan; -- past semicolon
165 exit;
167 -- Done if we are at a token which normally appears only after
168 -- a semicolon. One special glitch is that the keyword private is
169 -- in this category only if it does NOT appear after WITH.
171 elsif Token in Token_Class_After_SM
172 and then (Token /= Tok_Private or else Prev_Token /= Tok_With)
173 then
174 exit;
176 -- Otherwise keep going
178 else
179 Scan;
180 end if;
181 end loop;
183 -- Fall out of loop with resyncrhonization complete
185 Resync_Resume;
186 end Resync_Past_Semicolon;
188 ----------------------------------------------
189 -- Resync_Past_Semicolon_Or_To_Loop_Or_Then --
190 ----------------------------------------------
192 procedure Resync_Past_Semicolon_Or_To_Loop_Or_Then is
193 begin
194 Resync_Init;
196 loop
197 -- Done if at semicolon
199 if Token = Tok_Semicolon then
200 Scan; -- past the semicolon
201 exit;
203 -- Done if we are at a token which normally appears only after
204 -- a semicolon. One special glitch is that the keyword private is
205 -- in this category only if it does NOT appear after WITH.
207 elsif (Token in Token_Class_After_SM
208 and then (Token /= Tok_Private
209 or else Prev_Token /= Tok_With))
210 then
211 exit;
213 -- Done if we are at THEN or LOOP
215 elsif Token = Tok_Then or else Token = Tok_Loop then
216 exit;
218 -- Otherwise keep going
220 else
221 Scan;
222 end if;
223 end loop;
225 -- Fall out of loop with resyncrhonization complete
227 Resync_Resume;
228 end Resync_Past_Semicolon_Or_To_Loop_Or_Then;
230 -------------------
231 -- Resync_Resume --
232 -------------------
234 procedure Resync_Resume is
235 begin
236 -- Save resync point (see special test in Resync_Init)
238 Last_Resync_Point := Token_Ptr;
240 if Debug_Flag_R then
241 Error_Msg_SC ("resuming here!");
242 end if;
243 end Resync_Resume;
245 --------------------
246 -- Resync_To_When --
247 --------------------
249 procedure Resync_To_When is
250 begin
251 Resync_Init;
253 loop
254 -- Done if at semicolon, WHEN or IS
256 if Token = Tok_Semicolon
257 or else Token = Tok_When
258 or else Token = Tok_Is
259 then
260 exit;
262 -- Otherwise keep going
264 else
265 Scan;
266 end if;
267 end loop;
269 -- Fall out of loop with resyncrhonization complete
271 Resync_Resume;
272 end Resync_To_When;
274 ---------------------------
275 -- Resync_Semicolon_List --
276 ---------------------------
278 procedure Resync_Semicolon_List is
279 Paren_Count : Int;
281 begin
282 Resync_Init;
283 Paren_Count := 0;
285 loop
286 if Token = Tok_EOF
287 or else Token = Tok_Semicolon
288 or else Token = Tok_Is
289 or else Token in Token_Class_After_SM
290 then
291 exit;
293 elsif Token = Tok_Left_Paren then
294 Paren_Count := Paren_Count + 1;
296 elsif Token = Tok_Right_Paren then
297 if Paren_Count = 0 then
298 exit;
299 else
300 Paren_Count := Paren_Count - 1;
301 end if;
302 end if;
304 Scan;
305 end loop;
307 Resync_Resume;
308 end Resync_Semicolon_List;
310 end Sync;