111
|
1 ------------------------------------------------------------------------------
|
|
2 -- --
|
|
3 -- GNAT COMPILER COMPONENTS --
|
|
4 -- --
|
|
5 -- P A R . U T I L --
|
|
6 -- --
|
|
7 -- B o d y --
|
|
8 -- --
|
145
|
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
|
111
|
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 Csets; use Csets;
|
|
27 with Namet.Sp; use Namet.Sp;
|
|
28 with Stylesw; use Stylesw;
|
|
29 with Uintp; use Uintp;
|
|
30 with Warnsw; use Warnsw;
|
|
31
|
|
32 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
|
|
33
|
|
34 separate (Par)
|
|
35 package body Util is
|
|
36
|
|
37 ---------------------
|
|
38 -- Bad_Spelling_Of --
|
|
39 ---------------------
|
|
40
|
|
41 function Bad_Spelling_Of (T : Token_Type) return Boolean is
|
|
42 Tname : constant String := Token_Type'Image (T);
|
|
43 -- Characters of token name
|
|
44
|
|
45 S : String (1 .. Tname'Last - 4);
|
|
46 -- Characters of token name folded to lower case, omitting TOK_ at start
|
|
47
|
|
48 M1 : String (1 .. 42) := "incorrect spelling of keyword ************";
|
|
49 M2 : String (1 .. 44) := "illegal abbreviation of keyword ************";
|
|
50 -- Buffers used to construct error message
|
|
51
|
|
52 P1 : constant := 30;
|
|
53 P2 : constant := 32;
|
|
54 -- Starting subscripts in M1, M2 for keyword name
|
|
55
|
|
56 SL : constant Natural := S'Length;
|
|
57 -- Length of expected token name excluding TOK_ at start
|
|
58
|
|
59 begin
|
|
60 if Token /= Tok_Identifier then
|
|
61 return False;
|
|
62 end if;
|
|
63
|
|
64 for J in S'Range loop
|
|
65 S (J) := Fold_Lower (Tname (J + 4));
|
|
66 end loop;
|
|
67
|
|
68 Get_Name_String (Token_Name);
|
|
69
|
|
70 -- A special check for case of PROGRAM used for PROCEDURE
|
|
71
|
|
72 if T = Tok_Procedure
|
|
73 and then Name_Len = 7
|
|
74 and then Name_Buffer (1 .. 7) = "program"
|
|
75 then
|
|
76 Error_Msg_SC -- CODEFIX
|
|
77 ("PROCEDURE expected");
|
|
78 Token := T;
|
|
79 return True;
|
|
80
|
|
81 -- A special check for an illegal abbreviation
|
|
82
|
|
83 elsif Name_Len < S'Length
|
|
84 and then Name_Len >= 4
|
|
85 and then Name_Buffer (1 .. Name_Len) = S (1 .. Name_Len)
|
|
86 then
|
|
87 for J in 1 .. S'Last loop
|
|
88 M2 (P2 + J - 1) := Fold_Upper (S (J));
|
|
89 end loop;
|
|
90
|
|
91 Error_Msg_SC (M2 (1 .. P2 - 1 + S'Last));
|
|
92 Token := T;
|
|
93 return True;
|
|
94 end if;
|
|
95
|
|
96 -- Now we go into the full circuit to check for a misspelling
|
|
97
|
|
98 -- Never consider something a misspelling if either the actual or
|
|
99 -- expected string is less than 3 characters (before this check we
|
|
100 -- used to consider i to be a misspelled if in some cases).
|
|
101
|
|
102 if SL < 3 or else Name_Len < 3 then
|
|
103 return False;
|
|
104
|
|
105 -- Special case: prefix matches, i.e. the leading characters of the
|
|
106 -- token that we have exactly match the required keyword. If there
|
|
107 -- are at least two characters left over, assume that we have a case
|
|
108 -- of two keywords joined together which should not be joined.
|
|
109
|
|
110 elsif Name_Len > SL + 1
|
|
111 and then S = Name_Buffer (1 .. SL)
|
|
112 then
|
|
113 Scan_Ptr := Token_Ptr + S'Length;
|
|
114 Error_Msg_S ("|missing space");
|
|
115 Token := T;
|
|
116 return True;
|
|
117 end if;
|
|
118
|
|
119 if Is_Bad_Spelling_Of (Name_Buffer (1 .. Name_Len), S) then
|
|
120 for J in 1 .. S'Last loop
|
|
121 M1 (P1 + J - 1) := Fold_Upper (S (J));
|
|
122 end loop;
|
|
123
|
|
124 Error_Msg_SC -- CODFIX
|
|
125 (M1 (1 .. P1 - 1 + S'Last));
|
|
126 Token := T;
|
|
127 return True;
|
|
128
|
|
129 else
|
|
130 return False;
|
|
131 end if;
|
|
132 end Bad_Spelling_Of;
|
|
133
|
|
134 ----------------------
|
|
135 -- Check_95_Keyword --
|
|
136 ----------------------
|
|
137
|
|
138 -- On entry, the caller has checked that current token is an identifier
|
|
139 -- whose name matches the name of the 95 keyword New_Tok.
|
|
140
|
|
141 procedure Check_95_Keyword (Token_95, Next : Token_Type) is
|
|
142 Scan_State : Saved_Scan_State;
|
|
143
|
|
144 begin
|
|
145 Save_Scan_State (Scan_State); -- at identifier/keyword
|
|
146 Scan; -- past identifier/keyword
|
|
147
|
|
148 if Token = Next then
|
|
149 Restore_Scan_State (Scan_State); -- to identifier
|
|
150 Error_Msg_Name_1 := Token_Name;
|
|
151 Error_Msg_SC ("(Ada 83) keyword* cannot be used!");
|
|
152 Token := Token_95;
|
|
153 else
|
|
154 Restore_Scan_State (Scan_State); -- to identifier
|
|
155 end if;
|
|
156 end Check_95_Keyword;
|
|
157
|
|
158 ----------------------
|
|
159 -- Check_Bad_Layout --
|
|
160 ----------------------
|
|
161
|
|
162 procedure Check_Bad_Layout is
|
|
163 begin
|
|
164 if RM_Column_Check and then Token_Is_At_Start_Of_Line
|
145
|
165 and then Start_Column <= Scopes (Scope.Last).Ecol
|
111
|
166 then
|
|
167 Error_Msg_BC -- CODEFIX
|
|
168 ("(style) incorrect layout");
|
|
169 end if;
|
|
170 end Check_Bad_Layout;
|
|
171
|
|
172 --------------------------
|
|
173 -- Check_Future_Keyword --
|
|
174 --------------------------
|
|
175
|
|
176 procedure Check_Future_Keyword is
|
|
177 begin
|
|
178 -- Ada 2005 (AI-284): Compiling in Ada 95 mode we warn that INTERFACE,
|
|
179 -- OVERRIDING, and SYNCHRONIZED are new reserved words.
|
|
180
|
|
181 if Ada_Version = Ada_95
|
|
182 and then Warn_On_Ada_2005_Compatibility
|
|
183 then
|
|
184 if Nam_In (Token_Name, Name_Overriding, Name_Synchronized)
|
|
185 or else (Token_Name = Name_Interface
|
|
186 and then Prev_Token /= Tok_Pragma)
|
|
187 then
|
|
188 Error_Msg_N ("& is a reserved word in Ada 2005?y?", Token_Node);
|
|
189 end if;
|
|
190 end if;
|
|
191
|
|
192 -- Similarly, warn about Ada 2012 reserved words
|
|
193
|
|
194 if Ada_Version in Ada_95 .. Ada_2005
|
|
195 and then Warn_On_Ada_2012_Compatibility
|
|
196 then
|
|
197 if Token_Name = Name_Some then
|
|
198 Error_Msg_N ("& is a reserved word in Ada 2012?y?", Token_Node);
|
|
199 end if;
|
|
200 end if;
|
|
201
|
|
202 -- Note: we deliberately do not emit these warnings when operating in
|
|
203 -- Ada 83 mode because in that case we assume the user is building
|
|
204 -- legacy code anyway and is not interested in updating Ada versions.
|
|
205
|
|
206 end Check_Future_Keyword;
|
|
207
|
|
208 --------------------------
|
|
209 -- Check_Misspelling_Of --
|
|
210 --------------------------
|
|
211
|
|
212 procedure Check_Misspelling_Of (T : Token_Type) is
|
|
213 begin
|
|
214 if Bad_Spelling_Of (T) then
|
|
215 null;
|
|
216 end if;
|
|
217 end Check_Misspelling_Of;
|
|
218
|
|
219 -----------------------------
|
|
220 -- Check_Simple_Expression --
|
|
221 -----------------------------
|
|
222
|
|
223 procedure Check_Simple_Expression (E : Node_Id) is
|
|
224 begin
|
|
225 if Expr_Form = EF_Non_Simple then
|
|
226 Error_Msg_N ("this expression must be parenthesized", E);
|
|
227 end if;
|
|
228 end Check_Simple_Expression;
|
|
229
|
|
230 ---------------------------------------
|
|
231 -- Check_Simple_Expression_In_Ada_83 --
|
|
232 ---------------------------------------
|
|
233
|
|
234 procedure Check_Simple_Expression_In_Ada_83 (E : Node_Id) is
|
|
235 begin
|
|
236 if Expr_Form = EF_Non_Simple then
|
|
237 if Ada_Version = Ada_83 then
|
|
238 Error_Msg_N ("(Ada 83) this expression must be parenthesized!", E);
|
|
239 end if;
|
|
240 end if;
|
|
241 end Check_Simple_Expression_In_Ada_83;
|
|
242
|
|
243 ------------------------
|
|
244 -- Check_Subtype_Mark --
|
|
245 ------------------------
|
|
246
|
|
247 function Check_Subtype_Mark (Mark : Node_Id) return Node_Id is
|
|
248 begin
|
|
249 if Nkind (Mark) = N_Identifier
|
|
250 or else Nkind (Mark) = N_Selected_Component
|
|
251 or else (Nkind (Mark) = N_Attribute_Reference
|
|
252 and then Is_Type_Attribute_Name (Attribute_Name (Mark)))
|
|
253 or else Mark = Error
|
|
254 then
|
|
255 return Mark;
|
|
256 else
|
|
257 Error_Msg ("subtype mark expected", Sloc (Mark));
|
|
258 return Error;
|
|
259 end if;
|
|
260 end Check_Subtype_Mark;
|
|
261
|
|
262 -------------------
|
|
263 -- Comma_Present --
|
|
264 -------------------
|
|
265
|
|
266 function Comma_Present return Boolean is
|
|
267 Scan_State : Saved_Scan_State;
|
|
268 Paren_Count : Nat;
|
|
269
|
|
270 begin
|
|
271 -- First check, if a comma is present, then a comma is present
|
|
272
|
|
273 if Token = Tok_Comma then
|
|
274 T_Comma;
|
|
275 return True;
|
|
276
|
|
277 -- If we have a right paren, then that is taken as ending the list
|
|
278 -- i.e. no comma is present.
|
145
|
279 -- Ditto for a right bracket in Ada2020.
|
111
|
280
|
145
|
281 elsif Token = Tok_Right_Paren
|
|
282 or else (Token = Tok_Right_Bracket and then Ada_Version >= Ada_2020)
|
|
283 then
|
111
|
284 return False;
|
|
285
|
|
286 -- If pragmas, then get rid of them and make a recursive call
|
|
287 -- to process what follows these pragmas.
|
|
288
|
|
289 elsif Token = Tok_Pragma then
|
|
290 P_Pragmas_Misplaced;
|
|
291 return Comma_Present;
|
|
292
|
|
293 -- At this stage we have an error, and the goal is to decide on whether
|
|
294 -- or not we should diagnose an error and report a (non-existent)
|
|
295 -- comma as being present, or simply to report no comma is present
|
|
296
|
|
297 -- If we are a semicolon, then the question is whether we have a missing
|
|
298 -- right paren, or whether the semicolon should have been a comma. To
|
|
299 -- guess the right answer, we scan ahead keeping track of the paren
|
|
300 -- level, looking for a clue that helps us make the right decision.
|
|
301
|
|
302 -- This approach is highly accurate in the single error case, and does
|
|
303 -- not make bad mistakes in the multiple error case (indeed we can't
|
|
304 -- really make a very bad decision at this point in any case).
|
|
305
|
|
306 elsif Token = Tok_Semicolon then
|
|
307 Save_Scan_State (Scan_State);
|
|
308 Scan; -- past semicolon
|
|
309
|
|
310 -- Check for being followed by identifier => which almost certainly
|
|
311 -- means we are still in a parameter list and the comma should have
|
|
312 -- been a semicolon (such a sequence could not follow a semicolon)
|
|
313
|
|
314 if Token = Tok_Identifier then
|
|
315 Scan;
|
|
316
|
|
317 if Token = Tok_Arrow then
|
|
318 goto Assume_Comma;
|
|
319 end if;
|
|
320 end if;
|
|
321
|
|
322 -- If that test didn't work, loop ahead looking for a comma or
|
|
323 -- semicolon at the same parenthesis level. Always remember that
|
|
324 -- we can't go badly wrong in an error situation like this.
|
|
325
|
|
326 Paren_Count := 0;
|
|
327
|
|
328 -- Here is the look ahead loop, Paren_Count tells us whether the
|
|
329 -- token we are looking at is at the same paren level as the
|
|
330 -- suspicious semicolon that we are trying to figure out.
|
|
331
|
|
332 loop
|
|
333
|
|
334 -- If we hit another semicolon or an end of file, and we have
|
|
335 -- not seen a right paren or another comma on the way, then
|
|
336 -- probably the semicolon did end the list. Indeed that is
|
|
337 -- certainly the only single error correction possible here.
|
|
338
|
|
339 if Token = Tok_Semicolon or else Token = Tok_EOF then
|
|
340 Restore_Scan_State (Scan_State);
|
|
341 return False;
|
|
342
|
|
343 -- A comma at the same paren level as the semicolon is a strong
|
|
344 -- indicator that the semicolon should have been a comma, indeed
|
|
345 -- again this is the only possible single error correction.
|
|
346
|
|
347 elsif Token = Tok_Comma then
|
|
348 exit when Paren_Count = 0;
|
|
349
|
|
350 -- A left paren just bumps the paren count
|
|
351
|
|
352 elsif Token = Tok_Left_Paren then
|
|
353 Paren_Count := Paren_Count + 1;
|
|
354
|
|
355 -- A right paren that is at the same paren level as the semicolon
|
|
356 -- also means that the only possible single error correction is
|
|
357 -- to assume that the semicolon should have been a comma. If we
|
|
358 -- are not at the same paren level, then adjust the paren level.
|
|
359
|
|
360 elsif Token = Tok_Right_Paren then
|
|
361 exit when Paren_Count = 0;
|
|
362 Paren_Count := Paren_Count - 1;
|
|
363 end if;
|
|
364
|
|
365 -- Keep going, we haven't made a decision yet
|
|
366
|
|
367 Scan;
|
|
368 end loop;
|
|
369
|
|
370 -- If we fall through the loop, it means that we found a terminating
|
|
371 -- right paren or another comma. In either case it is reasonable to
|
|
372 -- assume that the semicolon was really intended to be a comma. Also
|
|
373 -- come here for the identifier arrow case.
|
|
374
|
|
375 <<Assume_Comma>>
|
|
376 Restore_Scan_State (Scan_State);
|
|
377 Error_Msg_SC -- CODEFIX
|
|
378 ("|"";"" should be "",""");
|
|
379 Scan; -- past the semicolon
|
|
380 return True;
|
|
381
|
|
382 -- If we are not at semicolon or a right paren, then we base the
|
|
383 -- decision on whether or not the next token can be part of an
|
|
384 -- expression. If not, then decide that no comma is present (the
|
|
385 -- caller will eventually generate a missing right parent message)
|
|
386
|
|
387 elsif Token in Token_Class_Eterm then
|
|
388 return False;
|
|
389
|
|
390 -- Otherwise we assume a comma is present, even if none is present,
|
|
391 -- since the next token must be part of an expression, so if we were
|
|
392 -- at the end of the list, then there is more than one error present.
|
|
393
|
|
394 else
|
|
395 T_Comma; -- to give error
|
|
396 return True;
|
|
397 end if;
|
|
398 end Comma_Present;
|
|
399
|
|
400 -----------------------
|
|
401 -- Discard_Junk_List --
|
|
402 -----------------------
|
|
403
|
|
404 procedure Discard_Junk_List (L : List_Id) is
|
|
405 pragma Warnings (Off, L);
|
|
406 begin
|
|
407 null;
|
|
408 end Discard_Junk_List;
|
|
409
|
|
410 -----------------------
|
|
411 -- Discard_Junk_Node --
|
|
412 -----------------------
|
|
413
|
|
414 procedure Discard_Junk_Node (N : Node_Id) is
|
|
415 pragma Warnings (Off, N);
|
|
416 begin
|
|
417 null;
|
|
418 end Discard_Junk_Node;
|
|
419
|
|
420 ------------
|
|
421 -- Ignore --
|
|
422 ------------
|
|
423
|
|
424 procedure Ignore (T : Token_Type) is
|
|
425 begin
|
|
426 while Token = T loop
|
|
427 if T = Tok_Comma then
|
|
428 Error_Msg_SC -- CODEFIX
|
|
429 ("|extra "","" ignored");
|
|
430
|
|
431 elsif T = Tok_Left_Paren then
|
|
432 Error_Msg_SC -- CODEFIX
|
|
433 ("|extra ""("" ignored");
|
|
434
|
|
435 -- Note: the following error used to be labeled as a non-serious
|
|
436 -- error like the other similar messages here (with a | at the start
|
|
437 -- of the message). But this caused some annoying cascaded errors
|
|
438 -- that were confusing, as shown by this example:
|
|
439
|
|
440 -- A : array (1 .. 9) of Integer :=
|
|
441 -- ((1 .. 2) => 0,
|
|
442 -- 1 2 3
|
|
443 -- >>> positional aggregate cannot have one component
|
|
444 -- >>> named association cannot follow positional association
|
|
445 -- >>> extra ")" ignored
|
|
446
|
|
447 -- So we decided to label it as serious after all
|
|
448
|
|
449 elsif T = Tok_Right_Paren then
|
|
450 Error_Msg_SC -- CODEFIX
|
|
451 ("extra "")"" ignored");
|
|
452
|
|
453 elsif T = Tok_Semicolon then
|
|
454 Error_Msg_SC -- CODEFIX
|
|
455 ("|extra "";"" ignored");
|
|
456
|
|
457 elsif T = Tok_Colon then
|
|
458 Error_Msg_SC -- CODEFIX
|
|
459 ("|extra "":"" ignored");
|
|
460
|
|
461 else
|
|
462 declare
|
|
463 Tname : constant String := Token_Type'Image (Token);
|
|
464 begin
|
|
465 Error_Msg_SC ("|extra " & Tname (5 .. Tname'Last) & "ignored");
|
|
466 end;
|
|
467 end if;
|
|
468
|
|
469 Scan; -- Scan past ignored token
|
|
470 end loop;
|
|
471 end Ignore;
|
|
472
|
|
473 ----------------------------
|
|
474 -- Is_Reserved_Identifier --
|
|
475 ----------------------------
|
|
476
|
|
477 function Is_Reserved_Identifier (C : Id_Check := None) return Boolean is
|
|
478 begin
|
|
479 if not Is_Reserved_Keyword (Token) then
|
|
480 return False;
|
|
481
|
|
482 else
|
|
483 declare
|
|
484 Ident_Casing : constant Casing_Type :=
|
|
485 Identifier_Casing (Current_Source_File);
|
|
486 Key_Casing : constant Casing_Type :=
|
|
487 Keyword_Casing (Current_Source_File);
|
|
488
|
|
489 begin
|
|
490 -- If the casing of identifiers and keywords is different in
|
|
491 -- this source file, and the casing of this token matches the
|
|
492 -- keyword casing, then we return False, since it is pretty
|
|
493 -- clearly intended to be a keyword.
|
|
494
|
|
495 if Ident_Casing = Unknown
|
|
496 or else Key_Casing = Unknown
|
|
497 or else Ident_Casing = Key_Casing
|
|
498 or else Determine_Token_Casing /= Key_Casing
|
|
499 then
|
|
500 return True;
|
|
501
|
|
502 -- Here we have a keyword written clearly with keyword casing.
|
|
503 -- In default mode, we would not be willing to consider this as
|
|
504 -- a reserved identifier, but if C is set, we may still accept it
|
|
505
|
|
506 elsif C /= None then
|
|
507 declare
|
|
508 Scan_State : Saved_Scan_State;
|
|
509 OK_Next_Tok : Boolean;
|
|
510
|
|
511 begin
|
|
512 Save_Scan_State (Scan_State);
|
|
513 Scan;
|
|
514
|
|
515 if Token_Is_At_Start_Of_Line then
|
|
516 return False;
|
|
517 end if;
|
|
518
|
|
519 case C is
|
|
520 when None =>
|
|
521 raise Program_Error;
|
|
522
|
|
523 when C_Comma_Right_Paren =>
|
|
524 OK_Next_Tok :=
|
|
525 Token = Tok_Comma or else Token = Tok_Right_Paren;
|
|
526
|
|
527 when C_Comma_Colon =>
|
|
528 OK_Next_Tok :=
|
|
529 Token = Tok_Comma or else Token = Tok_Colon;
|
|
530
|
|
531 when C_Do =>
|
|
532 OK_Next_Tok :=
|
|
533 Token = Tok_Do;
|
|
534
|
|
535 when C_Dot =>
|
|
536 OK_Next_Tok :=
|
|
537 Token = Tok_Dot;
|
|
538
|
|
539 when C_Greater_Greater =>
|
|
540 OK_Next_Tok :=
|
|
541 Token = Tok_Greater_Greater;
|
|
542
|
|
543 when C_In =>
|
|
544 OK_Next_Tok :=
|
|
545 Token = Tok_In;
|
|
546
|
|
547 when C_Is =>
|
|
548 OK_Next_Tok :=
|
|
549 Token = Tok_Is;
|
|
550
|
|
551 when C_Left_Paren_Semicolon =>
|
|
552 OK_Next_Tok :=
|
|
553 Token = Tok_Left_Paren or else Token = Tok_Semicolon;
|
|
554
|
|
555 when C_Use =>
|
|
556 OK_Next_Tok :=
|
|
557 Token = Tok_Use;
|
|
558
|
|
559 when C_Vertical_Bar_Arrow =>
|
|
560 OK_Next_Tok :=
|
|
561 Token = Tok_Vertical_Bar or else Token = Tok_Arrow;
|
|
562 end case;
|
|
563
|
|
564 Restore_Scan_State (Scan_State);
|
|
565
|
|
566 if OK_Next_Tok then
|
|
567 return True;
|
|
568 end if;
|
|
569 end;
|
|
570 end if;
|
|
571 end;
|
|
572 end if;
|
|
573
|
|
574 -- If we fall through it is not a reserved identifier
|
|
575
|
|
576 return False;
|
|
577 end Is_Reserved_Identifier;
|
|
578
|
|
579 ----------------------
|
|
580 -- Merge_Identifier --
|
|
581 ----------------------
|
|
582
|
|
583 procedure Merge_Identifier (Prev : Node_Id; Nxt : Token_Type) is
|
|
584 begin
|
|
585 if Token /= Tok_Identifier then
|
|
586 return;
|
|
587 end if;
|
|
588
|
|
589 declare
|
|
590 S : Saved_Scan_State;
|
|
591 T : Token_Type;
|
|
592
|
|
593 begin
|
|
594 Save_Scan_State (S);
|
|
595 Scan;
|
|
596 T := Token;
|
|
597 Restore_Scan_State (S);
|
|
598
|
|
599 if T /= Nxt then
|
|
600 return;
|
|
601 end if;
|
|
602 end;
|
|
603
|
|
604 -- Check exactly one space between identifiers
|
|
605
|
|
606 if Source (Token_Ptr - 1) /= ' '
|
|
607 or else Int (Token_Ptr) /=
|
|
608 Int (Prev_Token_Ptr) + Length_Of_Name (Chars (Prev)) + 1
|
|
609 then
|
|
610 return;
|
|
611 end if;
|
|
612
|
|
613 -- Do the merge
|
|
614
|
|
615 Get_Name_String (Chars (Token_Node));
|
|
616
|
|
617 declare
|
|
618 Buf : constant String (1 .. Name_Len) :=
|
|
619 Name_Buffer (1 .. Name_Len);
|
|
620
|
|
621 begin
|
|
622 Get_Name_String (Chars (Prev));
|
|
623 Add_Char_To_Name_Buffer ('_');
|
|
624 Add_Str_To_Name_Buffer (Buf);
|
|
625 Set_Chars (Prev, Name_Find);
|
|
626 end;
|
|
627
|
|
628 Error_Msg_Node_1 := Prev;
|
|
629 Error_Msg_SC ("unexpected identifier, possibly & was meant here");
|
|
630 Scan;
|
|
631 end Merge_Identifier;
|
|
632
|
|
633 -------------------
|
|
634 -- Next_Token_Is --
|
|
635 -------------------
|
|
636
|
|
637 function Next_Token_Is (Tok : Token_Type) return Boolean is
|
|
638 Scan_State : Saved_Scan_State;
|
|
639 Result : Boolean;
|
|
640 begin
|
|
641 Save_Scan_State (Scan_State);
|
|
642 Scan;
|
|
643 Result := (Token = Tok);
|
|
644 Restore_Scan_State (Scan_State);
|
|
645 return Result;
|
|
646 end Next_Token_Is;
|
|
647
|
|
648 -------------------
|
|
649 -- No_Constraint --
|
|
650 -------------------
|
|
651
|
|
652 procedure No_Constraint is
|
|
653 begin
|
|
654 -- If we have a token that could start a constraint on the same line
|
|
655 -- then cnsider this an illegal constraint. It seems unlikely it could
|
|
656 -- be anything else if it is on the same line.
|
|
657
|
|
658 if Token in Token_Class_Consk then
|
|
659 Error_Msg_SC ("constraint not allowed here");
|
|
660 Discard_Junk_Node (P_Constraint_Opt);
|
|
661 end if;
|
|
662 end No_Constraint;
|
|
663
|
|
664 ---------------------
|
|
665 -- Pop_Scope_Stack --
|
|
666 ---------------------
|
|
667
|
|
668 procedure Pop_Scope_Stack is
|
|
669 begin
|
|
670 pragma Assert (Scope.Last > 0);
|
|
671 Scope.Decrement_Last;
|
|
672
|
131
|
673 if Include_Subprogram_In_Messages
|
145
|
674 and then Scopes (Scope.Last).Labl /= Error
|
131
|
675 then
|
145
|
676 Current_Node := Scopes (Scope.Last).Labl;
|
131
|
677 end if;
|
|
678
|
111
|
679 if Debug_Flag_P then
|
|
680 Error_Msg_Uint_1 := UI_From_Int (Scope.Last);
|
|
681 Error_Msg_SC ("decrement scope stack ptr, new value = ^!");
|
|
682 end if;
|
|
683 end Pop_Scope_Stack;
|
|
684
|
|
685 ----------------------
|
|
686 -- Push_Scope_Stack --
|
|
687 ----------------------
|
|
688
|
|
689 procedure Push_Scope_Stack is
|
|
690 begin
|
|
691 Scope.Increment_Last;
|
|
692
|
|
693 if Style_Check_Max_Nesting_Level
|
|
694 and then Scope.Last = Style_Max_Nesting_Level + 1
|
|
695 then
|
|
696 Error_Msg
|
|
697 ("(style) maximum nesting level exceeded",
|
|
698 First_Non_Blank_Location);
|
|
699 end if;
|
|
700
|
145
|
701 Scopes (Scope.Last).Junk := False;
|
|
702 Scopes (Scope.Last).Node := Empty;
|
111
|
703
|
|
704 if Debug_Flag_P then
|
|
705 Error_Msg_Uint_1 := UI_From_Int (Scope.Last);
|
|
706 Error_Msg_SC ("increment scope stack ptr, new value = ^!");
|
|
707 end if;
|
|
708 end Push_Scope_Stack;
|
|
709
|
|
710 ----------------------
|
|
711 -- Separate_Present --
|
|
712 ----------------------
|
|
713
|
|
714 function Separate_Present return Boolean is
|
|
715 Scan_State : Saved_Scan_State;
|
|
716
|
|
717 begin
|
|
718 if Token = Tok_Separate then
|
|
719 return True;
|
|
720
|
|
721 elsif Token /= Tok_Identifier then
|
|
722 return False;
|
|
723
|
|
724 else
|
|
725 Save_Scan_State (Scan_State);
|
|
726 Scan; -- past identifier
|
|
727
|
|
728 if Token = Tok_Semicolon then
|
|
729 Restore_Scan_State (Scan_State);
|
|
730 return Bad_Spelling_Of (Tok_Separate);
|
|
731
|
|
732 else
|
|
733 Restore_Scan_State (Scan_State);
|
|
734 return False;
|
|
735 end if;
|
|
736 end if;
|
|
737 end Separate_Present;
|
|
738
|
|
739 --------------------------
|
|
740 -- Signal_Bad_Attribute --
|
|
741 --------------------------
|
|
742
|
|
743 procedure Signal_Bad_Attribute is
|
|
744 begin
|
|
745 Bad_Attribute (Token_Node, Token_Name, Warn => False);
|
|
746 end Signal_Bad_Attribute;
|
|
747
|
|
748 -----------------------------
|
|
749 -- Token_Is_At_End_Of_Line --
|
|
750 -----------------------------
|
|
751
|
|
752 function Token_Is_At_End_Of_Line return Boolean is
|
|
753 S : Source_Ptr;
|
|
754
|
|
755 begin
|
|
756 -- Skip past blanks and horizontal tabs
|
|
757
|
|
758 S := Scan_Ptr;
|
|
759 while Source (S) = ' ' or else Source (S) = ASCII.HT loop
|
|
760 S := S + 1;
|
|
761 end loop;
|
|
762
|
|
763 -- We are at end of line if at a control character (CR/LF/VT/FF/EOF)
|
|
764 -- or if we are at the start of an end of line comment sequence.
|
|
765
|
|
766 return Source (S) < ' '
|
|
767 or else (Source (S) = '-' and then Source (S + 1) = '-');
|
|
768 end Token_Is_At_End_Of_Line;
|
|
769
|
|
770 -------------------------------
|
|
771 -- Token_Is_At_Start_Of_Line --
|
|
772 -------------------------------
|
|
773
|
|
774 function Token_Is_At_Start_Of_Line return Boolean is
|
|
775 begin
|
|
776 return (Token_Ptr = First_Non_Blank_Location or else Token = Tok_EOF);
|
|
777 end Token_Is_At_Start_Of_Line;
|
|
778
|
|
779 -----------------------------------
|
|
780 -- Warn_If_Standard_Redefinition --
|
|
781 -----------------------------------
|
|
782
|
|
783 procedure Warn_If_Standard_Redefinition (N : Node_Id) is
|
|
784 begin
|
|
785 if Warn_On_Standard_Redefinition then
|
|
786 declare
|
|
787 C : constant Entity_Id := Current_Entity (N);
|
|
788 begin
|
|
789 if Present (C) and then Sloc (C) = Standard_Location then
|
|
790 Error_Msg_N ("redefinition of entity& in Standard?K?", N);
|
|
791 end if;
|
|
792 end;
|
|
793 end if;
|
|
794 end Warn_If_Standard_Redefinition;
|
|
795
|
|
796 end Util;
|