1 |
281 |
jeremybenn |
------------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- GNAT COMPILER COMPONENTS --
|
4 |
|
|
-- --
|
5 |
|
|
-- P A R . C H 2 --
|
6 |
|
|
-- --
|
7 |
|
|
-- B o d y --
|
8 |
|
|
-- --
|
9 |
|
|
-- Copyright (C) 1992-2009, 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 |
|
|
separate (Par)
|
31 |
|
|
package body Ch2 is
|
32 |
|
|
|
33 |
|
|
-- Local functions, used only in this chapter
|
34 |
|
|
|
35 |
|
|
procedure Scan_Pragma_Argument_Association
|
36 |
|
|
(Identifier_Seen : in out Boolean;
|
37 |
|
|
Association : out Node_Id);
|
38 |
|
|
-- Scans out a pragma argument association. Identifier_Seen is true on
|
39 |
|
|
-- entry if a previous association had an identifier, and gets set True if
|
40 |
|
|
-- the scanned association has an identifier (this is used to check the
|
41 |
|
|
-- rule that no associations without identifiers can follow an association
|
42 |
|
|
-- which has an identifier). The result is returned in Association.
|
43 |
|
|
|
44 |
|
|
---------------------
|
45 |
|
|
-- 2.3 Identifier --
|
46 |
|
|
---------------------
|
47 |
|
|
|
48 |
|
|
-- IDENTIFIER ::= LETTER {[UNDERLINE] LETTER_OR_DIGIT}
|
49 |
|
|
|
50 |
|
|
-- LETTER_OR_DIGIT ::= IDENTIFIER_LETTER | DIGIT
|
51 |
|
|
|
52 |
|
|
-- An IDENTIFIER shall not be a reserved word
|
53 |
|
|
|
54 |
|
|
-- Error recovery: can raise Error_Resync (cannot return Error)
|
55 |
|
|
|
56 |
|
|
function P_Identifier (C : Id_Check := None) return Node_Id is
|
57 |
|
|
Ident_Node : Node_Id;
|
58 |
|
|
|
59 |
|
|
begin
|
60 |
|
|
-- All set if we do indeed have an identifier
|
61 |
|
|
|
62 |
|
|
if Token = Tok_Identifier then
|
63 |
|
|
|
64 |
|
|
-- Ada 2005 (AI-284): Compiling in Ada95 mode we warn that INTERFACE,
|
65 |
|
|
-- OVERRIDING, and SYNCHRONIZED are new reserved words.
|
66 |
|
|
|
67 |
|
|
if Ada_Version = Ada_95
|
68 |
|
|
and then Warn_On_Ada_2005_Compatibility
|
69 |
|
|
then
|
70 |
|
|
if Token_Name = Name_Overriding
|
71 |
|
|
or else Token_Name = Name_Synchronized
|
72 |
|
|
or else (Token_Name = Name_Interface
|
73 |
|
|
and then Prev_Token /= Tok_Pragma)
|
74 |
|
|
then
|
75 |
|
|
Error_Msg_N ("& is a reserved word in Ada 2005?", Token_Node);
|
76 |
|
|
end if;
|
77 |
|
|
end if;
|
78 |
|
|
|
79 |
|
|
Ident_Node := Token_Node;
|
80 |
|
|
Scan; -- past Identifier
|
81 |
|
|
return Ident_Node;
|
82 |
|
|
|
83 |
|
|
-- If we have a reserved identifier, manufacture an identifier with
|
84 |
|
|
-- a corresponding name after posting an appropriate error message
|
85 |
|
|
|
86 |
|
|
elsif Is_Reserved_Identifier (C) then
|
87 |
|
|
Scan_Reserved_Identifier (Force_Msg => False);
|
88 |
|
|
Ident_Node := Token_Node;
|
89 |
|
|
Scan; -- past the node
|
90 |
|
|
return Ident_Node;
|
91 |
|
|
|
92 |
|
|
-- Otherwise we have junk that cannot be interpreted as an identifier
|
93 |
|
|
|
94 |
|
|
else
|
95 |
|
|
T_Identifier; -- to give message
|
96 |
|
|
raise Error_Resync;
|
97 |
|
|
end if;
|
98 |
|
|
end P_Identifier;
|
99 |
|
|
|
100 |
|
|
--------------------------
|
101 |
|
|
-- 2.3 Letter Or Digit --
|
102 |
|
|
--------------------------
|
103 |
|
|
|
104 |
|
|
-- Parsed by P_Identifier (2.3)
|
105 |
|
|
|
106 |
|
|
--------------------------
|
107 |
|
|
-- 2.4 Numeric Literal --
|
108 |
|
|
--------------------------
|
109 |
|
|
|
110 |
|
|
-- NUMERIC_LITERAL ::= DECIMAL_LITERAL | BASED_LITERAL
|
111 |
|
|
|
112 |
|
|
-- Numeric literal is returned by the scanner as either
|
113 |
|
|
-- Tok_Integer_Literal or Tok_Real_Literal
|
114 |
|
|
|
115 |
|
|
----------------------------
|
116 |
|
|
-- 2.4.1 Decimal Literal --
|
117 |
|
|
----------------------------
|
118 |
|
|
|
119 |
|
|
-- DECIMAL_LITERAL ::= NUMERAL [.NUMERAL] [EXPONENT]
|
120 |
|
|
|
121 |
|
|
-- Handled by scanner as part of numeric literal handing (see 2.4)
|
122 |
|
|
|
123 |
|
|
--------------------
|
124 |
|
|
-- 2.4.1 Numeral --
|
125 |
|
|
--------------------
|
126 |
|
|
|
127 |
|
|
-- NUMERAL ::= DIGIT {[UNDERLINE] DIGIT}
|
128 |
|
|
|
129 |
|
|
-- Handled by scanner as part of numeric literal handling (see 2.4)
|
130 |
|
|
|
131 |
|
|
---------------------
|
132 |
|
|
-- 2.4.1 Exponent --
|
133 |
|
|
---------------------
|
134 |
|
|
|
135 |
|
|
-- EXPONENT ::= E [+] NUMERAL | E - NUMERAL
|
136 |
|
|
|
137 |
|
|
-- Handled by scanner as part of numeric literal handling (see 2.4)
|
138 |
|
|
|
139 |
|
|
--------------------------
|
140 |
|
|
-- 2.4.2 Based Literal --
|
141 |
|
|
--------------------------
|
142 |
|
|
|
143 |
|
|
-- BASED_LITERAL ::=
|
144 |
|
|
-- BASE # BASED_NUMERAL [.BASED_NUMERAL] # [EXPONENT]
|
145 |
|
|
|
146 |
|
|
-- Handled by scanner as part of numeric literal handling (see 2.4)
|
147 |
|
|
|
148 |
|
|
-----------------
|
149 |
|
|
-- 2.4.2 Base --
|
150 |
|
|
-----------------
|
151 |
|
|
|
152 |
|
|
-- BASE ::= NUMERAL
|
153 |
|
|
|
154 |
|
|
-- Handled by scanner as part of numeric literal handling (see 2.4)
|
155 |
|
|
|
156 |
|
|
--------------------------
|
157 |
|
|
-- 2.4.2 Based Numeral --
|
158 |
|
|
--------------------------
|
159 |
|
|
|
160 |
|
|
-- BASED_NUMERAL ::=
|
161 |
|
|
-- EXTENDED_DIGIT {[UNDERLINE] EXTENDED_DIGIT}
|
162 |
|
|
|
163 |
|
|
-- Handled by scanner as part of numeric literal handling (see 2.4)
|
164 |
|
|
|
165 |
|
|
---------------------------
|
166 |
|
|
-- 2.4.2 Extended Digit --
|
167 |
|
|
---------------------------
|
168 |
|
|
|
169 |
|
|
-- EXTENDED_DIGIT ::= DIGIT | A | B | C | D | E | F
|
170 |
|
|
|
171 |
|
|
-- Handled by scanner as part of numeric literal handling (see 2.4)
|
172 |
|
|
|
173 |
|
|
----------------------------
|
174 |
|
|
-- 2.5 Character Literal --
|
175 |
|
|
----------------------------
|
176 |
|
|
|
177 |
|
|
-- CHARACTER_LITERAL ::= ' GRAPHIC_CHARACTER '
|
178 |
|
|
|
179 |
|
|
-- Handled by the scanner and returned as Tok_Char_Literal
|
180 |
|
|
|
181 |
|
|
-------------------------
|
182 |
|
|
-- 2.6 String Literal --
|
183 |
|
|
-------------------------
|
184 |
|
|
|
185 |
|
|
-- STRING LITERAL ::= "{STRING_ELEMENT}"
|
186 |
|
|
|
187 |
|
|
-- Handled by the scanner and returned as Tok_String_Literal
|
188 |
|
|
-- or if the string looks like an operator as Tok_Operator_Symbol.
|
189 |
|
|
|
190 |
|
|
-------------------------
|
191 |
|
|
-- 2.6 String Element --
|
192 |
|
|
-------------------------
|
193 |
|
|
|
194 |
|
|
-- STRING_ELEMENT ::= "" | non-quotation_mark_GRAPHIC_CHARACTER
|
195 |
|
|
|
196 |
|
|
-- A STRING_ELEMENT is either a pair of quotation marks ("),
|
197 |
|
|
-- or a single GRAPHIC_CHARACTER other than a quotation mark.
|
198 |
|
|
|
199 |
|
|
-- Handled by scanner as part of string literal handling (see 2.4)
|
200 |
|
|
|
201 |
|
|
------------------
|
202 |
|
|
-- 2.7 Comment --
|
203 |
|
|
------------------
|
204 |
|
|
|
205 |
|
|
-- A COMMENT starts with two adjacent hyphens and extends up to the
|
206 |
|
|
-- end of the line. A COMMENT may appear on any line of a program.
|
207 |
|
|
|
208 |
|
|
-- Handled by the scanner which simply skips past encountered comments
|
209 |
|
|
|
210 |
|
|
-----------------
|
211 |
|
|
-- 2.8 Pragma --
|
212 |
|
|
-----------------
|
213 |
|
|
|
214 |
|
|
-- PRAGMA ::= pragma IDENTIFIER
|
215 |
|
|
-- [(PRAGMA_ARGUMENT_ASSOCIATION {, PRAGMA_ARGUMENT_ASSOCIATION})];
|
216 |
|
|
|
217 |
|
|
-- The caller has checked that the initial token is PRAGMA
|
218 |
|
|
|
219 |
|
|
-- Error recovery: cannot raise Error_Resync
|
220 |
|
|
|
221 |
|
|
-- One special piece of processing is needed in this routine. As described
|
222 |
|
|
-- in the section on "Handling semicolon used in place of IS" in module
|
223 |
|
|
-- Parse, the parser detects the case of missing subprogram bodies to
|
224 |
|
|
-- allow recovery from this syntactic error. Pragma INTERFACE (and, for
|
225 |
|
|
-- Ada 95, pragma IMPORT) can appear in place of the body. The parser must
|
226 |
|
|
-- recognize the use of these two pragmas in this context, otherwise it
|
227 |
|
|
-- will think there are missing bodies, and try to change ; to IS, when
|
228 |
|
|
-- in fact the bodies ARE present, supplied by these pragmas.
|
229 |
|
|
|
230 |
|
|
function P_Pragma (Skipping : Boolean := False) return Node_Id is
|
231 |
|
|
Interface_Check_Required : Boolean := False;
|
232 |
|
|
-- Set True if check of pragma INTERFACE is required
|
233 |
|
|
|
234 |
|
|
Import_Check_Required : Boolean := False;
|
235 |
|
|
-- Set True if check of pragma IMPORT is required
|
236 |
|
|
|
237 |
|
|
Arg_Count : Int := 0;
|
238 |
|
|
-- Number of argument associations processed
|
239 |
|
|
|
240 |
|
|
Identifier_Seen : Boolean := False;
|
241 |
|
|
-- Set True if an identifier is encountered for a pragma argument. Used
|
242 |
|
|
-- to check that there are no more arguments without identifiers.
|
243 |
|
|
|
244 |
|
|
Prag_Node : Node_Id;
|
245 |
|
|
Prag_Name : Name_Id;
|
246 |
|
|
Semicolon_Loc : Source_Ptr;
|
247 |
|
|
Ident_Node : Node_Id;
|
248 |
|
|
Assoc_Node : Node_Id;
|
249 |
|
|
Result : Node_Id;
|
250 |
|
|
|
251 |
|
|
procedure Skip_Pragma_Semicolon;
|
252 |
|
|
-- Skip past semicolon at end of pragma
|
253 |
|
|
|
254 |
|
|
---------------------------
|
255 |
|
|
-- Skip_Pragma_Semicolon --
|
256 |
|
|
---------------------------
|
257 |
|
|
|
258 |
|
|
procedure Skip_Pragma_Semicolon is
|
259 |
|
|
begin
|
260 |
|
|
if Token /= Tok_Semicolon then
|
261 |
|
|
|
262 |
|
|
-- If skipping the pragma, ignore a missing semicolon
|
263 |
|
|
|
264 |
|
|
if Skipping then
|
265 |
|
|
null;
|
266 |
|
|
|
267 |
|
|
-- Otherwise demand a semicolon
|
268 |
|
|
|
269 |
|
|
else
|
270 |
|
|
T_Semicolon;
|
271 |
|
|
end if;
|
272 |
|
|
|
273 |
|
|
-- Scan past semicolon if present
|
274 |
|
|
|
275 |
|
|
else
|
276 |
|
|
Scan;
|
277 |
|
|
end if;
|
278 |
|
|
end Skip_Pragma_Semicolon;
|
279 |
|
|
|
280 |
|
|
-- Start of processing for P_Pragma
|
281 |
|
|
|
282 |
|
|
begin
|
283 |
|
|
Prag_Node := New_Node (N_Pragma, Token_Ptr);
|
284 |
|
|
Scan; -- past PRAGMA
|
285 |
|
|
Prag_Name := Token_Name;
|
286 |
|
|
|
287 |
|
|
if Style_Check then
|
288 |
|
|
Style.Check_Pragma_Name;
|
289 |
|
|
end if;
|
290 |
|
|
|
291 |
|
|
-- Ada 2005 (AI-284): INTERFACE is a new reserved word but it is
|
292 |
|
|
-- allowed as a pragma name.
|
293 |
|
|
|
294 |
|
|
if Ada_Version >= Ada_05
|
295 |
|
|
and then Token = Tok_Interface
|
296 |
|
|
then
|
297 |
|
|
Prag_Name := Name_Interface;
|
298 |
|
|
Ident_Node := Make_Identifier (Token_Ptr, Name_Interface);
|
299 |
|
|
Scan; -- past INTERFACE
|
300 |
|
|
else
|
301 |
|
|
Ident_Node := P_Identifier;
|
302 |
|
|
end if;
|
303 |
|
|
|
304 |
|
|
Set_Pragma_Identifier (Prag_Node, Ident_Node);
|
305 |
|
|
|
306 |
|
|
-- See if special INTERFACE/IMPORT check is required
|
307 |
|
|
|
308 |
|
|
if SIS_Entry_Active then
|
309 |
|
|
Interface_Check_Required := (Prag_Name = Name_Interface);
|
310 |
|
|
Import_Check_Required := (Prag_Name = Name_Import);
|
311 |
|
|
else
|
312 |
|
|
Interface_Check_Required := False;
|
313 |
|
|
Import_Check_Required := False;
|
314 |
|
|
end if;
|
315 |
|
|
|
316 |
|
|
-- Scan arguments. We assume that arguments are present if there is
|
317 |
|
|
-- a left paren, or if a semicolon is missing and there is another
|
318 |
|
|
-- token on the same line as the pragma name.
|
319 |
|
|
|
320 |
|
|
if Token = Tok_Left_Paren
|
321 |
|
|
or else (Token /= Tok_Semicolon
|
322 |
|
|
and then not Token_Is_At_Start_Of_Line)
|
323 |
|
|
then
|
324 |
|
|
Set_Pragma_Argument_Associations (Prag_Node, New_List);
|
325 |
|
|
T_Left_Paren;
|
326 |
|
|
|
327 |
|
|
loop
|
328 |
|
|
Arg_Count := Arg_Count + 1;
|
329 |
|
|
Scan_Pragma_Argument_Association (Identifier_Seen, Assoc_Node);
|
330 |
|
|
|
331 |
|
|
if Arg_Count = 2
|
332 |
|
|
and then (Interface_Check_Required or else Import_Check_Required)
|
333 |
|
|
then
|
334 |
|
|
-- Here is where we cancel the SIS active status if this pragma
|
335 |
|
|
-- supplies a body for the currently active subprogram spec.
|
336 |
|
|
|
337 |
|
|
if Nkind (Expression (Assoc_Node)) in N_Direct_Name
|
338 |
|
|
and then Chars (Expression (Assoc_Node)) = Chars (SIS_Labl)
|
339 |
|
|
then
|
340 |
|
|
SIS_Entry_Active := False;
|
341 |
|
|
end if;
|
342 |
|
|
end if;
|
343 |
|
|
|
344 |
|
|
Append (Assoc_Node, Pragma_Argument_Associations (Prag_Node));
|
345 |
|
|
exit when Token /= Tok_Comma;
|
346 |
|
|
Scan; -- past comma
|
347 |
|
|
end loop;
|
348 |
|
|
|
349 |
|
|
-- If we have := for pragma Debug, it is worth special casing the
|
350 |
|
|
-- error message (it is easy to think of pragma Debug as taking a
|
351 |
|
|
-- statement, and an assignment statement is the most likely
|
352 |
|
|
-- candidate for this error)
|
353 |
|
|
|
354 |
|
|
if Token = Tok_Colon_Equal and then Prag_Name = Name_Debug then
|
355 |
|
|
Error_Msg_SC ("argument for pragma Debug must be procedure call");
|
356 |
|
|
Resync_To_Semicolon;
|
357 |
|
|
|
358 |
|
|
-- Normal case, we expect a right paren here
|
359 |
|
|
|
360 |
|
|
else
|
361 |
|
|
T_Right_Paren;
|
362 |
|
|
end if;
|
363 |
|
|
end if;
|
364 |
|
|
|
365 |
|
|
Semicolon_Loc := Token_Ptr;
|
366 |
|
|
|
367 |
|
|
-- Now we have two tasks left, we need to scan out the semicolon
|
368 |
|
|
-- following the pragma, and we have to call Par.Prag to process
|
369 |
|
|
-- the pragma. Normally we do them in this order, however, there
|
370 |
|
|
-- is one exception namely pragma Style_Checks where we like to
|
371 |
|
|
-- skip the semicolon after processing the pragma, since that way
|
372 |
|
|
-- the style checks for the scanning of the semicolon follow the
|
373 |
|
|
-- settings of the pragma.
|
374 |
|
|
|
375 |
|
|
-- You might think we could just unconditionally do things in
|
376 |
|
|
-- the opposite order, but there are other pragmas, notably the
|
377 |
|
|
-- case of pragma Source_File_Name, which assume the semicolon
|
378 |
|
|
-- is already scanned out.
|
379 |
|
|
|
380 |
|
|
if Prag_Name = Name_Style_Checks then
|
381 |
|
|
Result := Par.Prag (Prag_Node, Semicolon_Loc);
|
382 |
|
|
Skip_Pragma_Semicolon;
|
383 |
|
|
return Result;
|
384 |
|
|
else
|
385 |
|
|
Skip_Pragma_Semicolon;
|
386 |
|
|
return Par.Prag (Prag_Node, Semicolon_Loc);
|
387 |
|
|
end if;
|
388 |
|
|
|
389 |
|
|
exception
|
390 |
|
|
when Error_Resync =>
|
391 |
|
|
Resync_Past_Semicolon;
|
392 |
|
|
return Error;
|
393 |
|
|
|
394 |
|
|
end P_Pragma;
|
395 |
|
|
|
396 |
|
|
-- This routine is called if a pragma is encountered in an inappropriate
|
397 |
|
|
-- position, the pragma is scanned out and control returns to continue.
|
398 |
|
|
|
399 |
|
|
-- The caller has checked that the initial token is pragma
|
400 |
|
|
|
401 |
|
|
-- Error recovery: cannot raise Error_Resync
|
402 |
|
|
|
403 |
|
|
procedure P_Pragmas_Misplaced is
|
404 |
|
|
begin
|
405 |
|
|
while Token = Tok_Pragma loop
|
406 |
|
|
Error_Msg_SC ("pragma not allowed here");
|
407 |
|
|
Discard_Junk_Node (P_Pragma (Skipping => True));
|
408 |
|
|
end loop;
|
409 |
|
|
end P_Pragmas_Misplaced;
|
410 |
|
|
|
411 |
|
|
-- This function is called to scan out an optional sequence of pragmas.
|
412 |
|
|
-- If no pragmas are found, then No_List is returned.
|
413 |
|
|
|
414 |
|
|
-- Error recovery: Cannot raise Error_Resync
|
415 |
|
|
|
416 |
|
|
function P_Pragmas_Opt return List_Id is
|
417 |
|
|
L : List_Id;
|
418 |
|
|
|
419 |
|
|
begin
|
420 |
|
|
if Token = Tok_Pragma then
|
421 |
|
|
L := New_List;
|
422 |
|
|
P_Pragmas_Opt (L);
|
423 |
|
|
return L;
|
424 |
|
|
|
425 |
|
|
else
|
426 |
|
|
return No_List;
|
427 |
|
|
end if;
|
428 |
|
|
end P_Pragmas_Opt;
|
429 |
|
|
|
430 |
|
|
-- This procedure is called to scan out an optional sequence of pragmas.
|
431 |
|
|
-- Any pragmas found are appended to the list provided as an argument.
|
432 |
|
|
|
433 |
|
|
-- Error recovery: Cannot raise Error_Resync
|
434 |
|
|
|
435 |
|
|
procedure P_Pragmas_Opt (List : List_Id) is
|
436 |
|
|
P : Node_Id;
|
437 |
|
|
|
438 |
|
|
begin
|
439 |
|
|
while Token = Tok_Pragma loop
|
440 |
|
|
P := P_Pragma;
|
441 |
|
|
|
442 |
|
|
if Nkind (P) /= N_Error
|
443 |
|
|
and then (Pragma_Name (P) = Name_Assert
|
444 |
|
|
or else
|
445 |
|
|
Pragma_Name (P) = Name_Debug)
|
446 |
|
|
then
|
447 |
|
|
Error_Msg_Name_1 := Pragma_Name (P);
|
448 |
|
|
Error_Msg_N
|
449 |
|
|
("pragma% must be in declaration/statement context", P);
|
450 |
|
|
else
|
451 |
|
|
Append (P, List);
|
452 |
|
|
end if;
|
453 |
|
|
end loop;
|
454 |
|
|
end P_Pragmas_Opt;
|
455 |
|
|
|
456 |
|
|
--------------------------------------
|
457 |
|
|
-- 2.8 Pragma_Argument Association --
|
458 |
|
|
--------------------------------------
|
459 |
|
|
|
460 |
|
|
-- PRAGMA_ARGUMENT_ASSOCIATION ::=
|
461 |
|
|
-- [pragma_argument_IDENTIFIER =>] NAME
|
462 |
|
|
-- | [pragma_argument_IDENTIFIER =>] EXPRESSION
|
463 |
|
|
|
464 |
|
|
-- Error recovery: cannot raise Error_Resync
|
465 |
|
|
|
466 |
|
|
procedure Scan_Pragma_Argument_Association
|
467 |
|
|
(Identifier_Seen : in out Boolean;
|
468 |
|
|
Association : out Node_Id)
|
469 |
|
|
is
|
470 |
|
|
Scan_State : Saved_Scan_State;
|
471 |
|
|
Identifier_Node : Node_Id;
|
472 |
|
|
Id_Present : Boolean;
|
473 |
|
|
|
474 |
|
|
begin
|
475 |
|
|
Association := New_Node (N_Pragma_Argument_Association, Token_Ptr);
|
476 |
|
|
Set_Chars (Association, No_Name);
|
477 |
|
|
|
478 |
|
|
-- Argument starts with identifier
|
479 |
|
|
|
480 |
|
|
if Token = Tok_Identifier then
|
481 |
|
|
Identifier_Node := Token_Node;
|
482 |
|
|
Save_Scan_State (Scan_State); -- at Identifier
|
483 |
|
|
Scan; -- past Identifier
|
484 |
|
|
|
485 |
|
|
if Token = Tok_Arrow then
|
486 |
|
|
Identifier_Seen := True;
|
487 |
|
|
Scan; -- past arrow
|
488 |
|
|
Set_Chars (Association, Chars (Identifier_Node));
|
489 |
|
|
Id_Present := True;
|
490 |
|
|
|
491 |
|
|
-- Case of argument with no identifier
|
492 |
|
|
|
493 |
|
|
else
|
494 |
|
|
Restore_Scan_State (Scan_State); -- to Identifier
|
495 |
|
|
Id_Present := False;
|
496 |
|
|
end if;
|
497 |
|
|
|
498 |
|
|
-- Argument does not start with identifier
|
499 |
|
|
|
500 |
|
|
else
|
501 |
|
|
Id_Present := False;
|
502 |
|
|
end if;
|
503 |
|
|
|
504 |
|
|
if Identifier_Seen and not Id_Present then
|
505 |
|
|
Error_Msg_SC
|
506 |
|
|
("|pragma argument identifier required here (RM 2.8(4))");
|
507 |
|
|
end if;
|
508 |
|
|
|
509 |
|
|
if Id_Present then
|
510 |
|
|
Set_Expression (Association, P_Expression);
|
511 |
|
|
else
|
512 |
|
|
Set_Expression (Association, P_Expression_If_OK);
|
513 |
|
|
end if;
|
514 |
|
|
end Scan_Pragma_Argument_Association;
|
515 |
|
|
|
516 |
|
|
end Ch2;
|