1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2002 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 pragma Style_Checks (All_Checks);
30 -- Turn off subprogram body ordering check. Subprograms are in order
31 -- by RM section rather than alphabetical
36 -- Local functions, used only in this chapter
38 function P_Pragma_Argument_Association return Node_Id;
44 -- IDENTIFIER ::= LETTER {[UNDERLINE] LETTER_OR_DIGIT}
46 -- LETTER_OR_DIGIT ::= IDENTIFIER_LETTER | DIGIT
48 -- An IDENTIFIER shall not be a reserved word
50 -- Error recovery: can raise Error_Resync (cannot return Error)
52 function P_Identifier return Node_Id is
56 -- All set if we do indeed have an identifier
58 if Token = Tok_Identifier then
59 Ident_Node := Token_Node;
60 Scan; -- past Identifier
63 -- If we have a reserved identifier, manufacture an identifier with
64 -- a corresponding name after posting an appropriate error message
66 elsif Is_Reserved_Identifier then
67 Scan_Reserved_Identifier (Force_Msg => False);
68 Ident_Node := Token_Node;
69 Scan; -- past the node
72 -- Otherwise we have junk that cannot be interpreted as an identifier
75 T_Identifier; -- to give message
80 --------------------------
81 -- 2.3 Letter Or Digit --
82 --------------------------
84 -- Parsed by P_Identifier (2.3)
86 --------------------------
87 -- 2.4 Numeric Literal --
88 --------------------------
90 -- NUMERIC_LITERAL ::= DECIMAL_LITERAL | BASED_LITERAL
92 -- Numeric literal is returned by the scanner as either
93 -- Tok_Integer_Literal or Tok_Real_Literal
95 ----------------------------
96 -- 2.4.1 Decimal Literal --
97 ----------------------------
99 -- DECIMAL_LITERAL ::= NUMERAL [.NUMERAL] [EXPONENT]
101 -- Handled by scanner as part of numeric lIteral handing (see 2.4)
107 -- NUMERAL ::= DIGIT {[UNDERLINE] DIGIT}
109 -- Handled by scanner as part of numeric literal handling (see 2.4)
111 ---------------------
113 ---------------------
115 -- EXPONENT ::= E [+] NUMERAL | E - NUMERAL
117 -- Handled by scanner as part of numeric literal handling (see 2.4)
119 --------------------------
120 -- 2.4.2 Based Literal --
121 --------------------------
124 -- BASE # BASED_NUMERAL [.BASED_NUMERAL] # [EXPONENT]
126 -- Handled by scanner as part of numeric literal handling (see 2.4)
134 -- Handled by scanner as part of numeric literal handling (see 2.4)
136 --------------------------
137 -- 2.4.2 Based Numeral --
138 --------------------------
141 -- EXTENDED_DIGIT {[UNDERLINE] EXTENDED_DIGIT}
143 -- Handled by scanner as part of numeric literal handling (see 2.4)
145 ---------------------------
146 -- 2.4.2 Extended Digit --
147 ---------------------------
149 -- EXTENDED_DIGIT ::= DIGIT | A | B | C | D | E | F
151 -- Handled by scanner as part of numeric literal handling (see 2.4)
153 ----------------------------
154 -- 2.5 Character Literal --
155 ----------------------------
157 -- CHARACTER_LITERAL ::= ' GRAPHIC_CHARACTER '
159 -- Handled by the scanner and returned as Tok_Character_Literal
161 -------------------------
162 -- 2.6 String Literal --
163 -------------------------
165 -- STRING LITERAL ::= "{STRING_ELEMENT}"
167 -- Handled by the scanner and returned as Tok_Character_Literal
168 -- or if the string looks like an operator as Tok_Operator_Symbol.
170 -------------------------
171 -- 2.6 String Element --
172 -------------------------
174 -- STRING_ELEMENT ::= "" | non-quotation_mark_GRAPHIC_CHARACTER
176 -- A STRING_ELEMENT is either a pair of quotation marks ("),
177 -- or a single GRAPHIC_CHARACTER other than a quotation mark.
179 -- Handled by scanner as part of string literal handling (see 2.4)
185 -- A COMMENT starts with two adjacent hyphens and extends up to the
186 -- end of the line. A COMMENT may appear on any line of a program.
188 -- Handled by the scanner which simply skips past encountered comments
194 -- PRAGMA ::= pragma IDENTIFIER
195 -- [(PRAGMA_ARGUMENT_ASSOCIATION {, PRAGMA_ARGUMENT_ASSOCIATION})];
197 -- The caller has checked that the initial token is PRAGMA
199 -- Error recovery: cannot raise Error_Resync
201 -- One special piece of processing is needed in this routine. As described
202 -- in the section on "Handling semicolon used in place of IS" in module
203 -- Parse, the parser detects the case of missing subprogram bodies to
204 -- allow recovery from this syntactic error. Pragma INTERFACE (and, for
205 -- Ada 95, pragma IMPORT) can appear in place of the body. The parser must
206 -- recognize the use of these two pragmas in this context, otherwise it
207 -- will think there are missing bodies, and try to change ; to IS, when
208 -- in fact the bodies ARE present, supplied by these pragmas.
210 function P_Pragma return Node_Id is
212 Interface_Check_Required : Boolean := False;
213 -- Set True if check of pragma INTERFACE is required
215 Import_Check_Required : Boolean := False;
216 -- Set True if check of pragma IMPORT is required
218 Arg_Count : Int := 0;
219 -- Number of argument associations processed
221 Pragma_Node : Node_Id;
222 Pragma_Name : Name_Id;
223 Semicolon_Loc : Source_Ptr;
224 Ident_Node : Node_Id;
225 Assoc_Node : Node_Id;
228 procedure Skip_Pragma_Semicolon;
229 -- Skip past semicolon at end of pragma
231 ---------------------------
232 -- Skip_Pragma_Semicolon --
233 ---------------------------
235 procedure Skip_Pragma_Semicolon is
237 if Token /= Tok_Semicolon then
239 Resync_Past_Semicolon;
241 Scan; -- past semicolon
243 end Skip_Pragma_Semicolon;
245 -- Start of processing for P_Pragma
248 Pragma_Node := New_Node (N_Pragma, Token_Ptr);
250 Pragma_Name := Token_Name;
253 Style.Check_Pragma_Name;
256 Ident_Node := P_Identifier;
257 Set_Chars (Pragma_Node, Pragma_Name);
258 Delete_Node (Ident_Node);
260 -- See if special INTERFACE/IMPORT check is required
262 if SIS_Entry_Active then
263 Interface_Check_Required := (Pragma_Name = Name_Interface);
264 Import_Check_Required := (Pragma_Name = Name_Import);
266 Interface_Check_Required := False;
267 Import_Check_Required := False;
270 -- Scan arguments. We assume that arguments are present if there is
271 -- a left paren, or if a semicolon is missing and there is another
272 -- token on the same line as the pragma name.
274 if Token = Tok_Left_Paren
275 or else (Token /= Tok_Semicolon
276 and then not Token_Is_At_Start_Of_Line)
278 Set_Pragma_Argument_Associations (Pragma_Node, New_List);
282 Arg_Count := Arg_Count + 1;
283 Assoc_Node := P_Pragma_Argument_Association;
286 and then (Interface_Check_Required or else Import_Check_Required)
288 -- Here is where we cancel the SIS active status if this pragma
289 -- supplies a body for the currently active subprogram spec.
291 if Nkind (Expression (Assoc_Node)) in N_Direct_Name
292 and then Chars (Expression (Assoc_Node)) = Chars (SIS_Labl)
294 SIS_Entry_Active := False;
298 Append (Assoc_Node, Pragma_Argument_Associations (Pragma_Node));
299 exit when Token /= Tok_Comma;
306 Semicolon_Loc := Token_Ptr;
308 -- Now we have two tasks left, we need to scan out the semicolon
309 -- following the pragma, and we have to call Par.Prag to process
310 -- the pragma. Normally we do them in this order, however, there
311 -- is one exception namely pragma Style_Checks where we like to
312 -- skip the semicolon after processing the pragma, since that way
313 -- the style checks for the scanning of the semicolon follow the
314 -- settings of the pragma.
316 -- You might think we could just unconditionally do things in
317 -- the opposite order, but there are other pragmas, notably the
318 -- case of pragma Source_File_Name, which assume the semicolon
319 -- is already scanned out.
321 if Chars (Pragma_Node) = Name_Style_Checks then
322 Result := Par.Prag (Pragma_Node, Semicolon_Loc);
323 Skip_Pragma_Semicolon;
326 Skip_Pragma_Semicolon;
327 return Par.Prag (Pragma_Node, Semicolon_Loc);
332 Resync_Past_Semicolon;
337 -- This routine is called if a pragma is encountered in an inappropriate
338 -- position, the pragma is scanned out and control returns to continue.
340 -- The caller has checked that the initial token is pragma
342 -- Error recovery: cannot raise Error_Resync
344 procedure P_Pragmas_Misplaced is
346 while Token = Tok_Pragma loop
347 Error_Msg_SC ("pragma not allowed here");
348 Discard_Junk_Node (P_Pragma);
350 end P_Pragmas_Misplaced;
352 -- This function is called to scan out an optional sequence of pragmas.
353 -- If no pragmas are found, then No_List is returned.
355 -- Error recovery: Cannot raise Error_Resync
357 function P_Pragmas_Opt return List_Id is
361 if Token = Tok_Pragma then
371 -- This procedure is called to scan out an optional sequence of pragmas.
372 -- Any pragmas found are appended to the list provided as an argument.
374 -- Error recovery: Cannot raise Error_Resync
376 procedure P_Pragmas_Opt (List : List_Id) is
380 while Token = Tok_Pragma loop
383 if Chars (P) = Name_Assert or else Chars (P) = Name_Debug then
384 Error_Msg_Name_1 := Chars (P);
386 ("pragma% must be in declaration/statement context", P);
393 --------------------------------------
394 -- 2.8 Pragma_Argument Association --
395 --------------------------------------
397 -- PRAGMA_ARGUMENT_ASSOCIATION ::=
398 -- [pragma_argument_IDENTIFIER =>] NAME
399 -- | [pragma_argument_IDENTIFIER =>] EXPRESSION
401 -- Error recovery: cannot raise Error_Resync
403 function P_Pragma_Argument_Association return Node_Id is
404 Scan_State : Saved_Scan_State;
405 Pragma_Arg_Node : Node_Id;
406 Identifier_Node : Node_Id;
409 Pragma_Arg_Node := New_Node (N_Pragma_Argument_Association, Token_Ptr);
410 Set_Chars (Pragma_Arg_Node, No_Name);
412 if Token = Tok_Identifier then
413 Identifier_Node := Token_Node;
414 Save_Scan_State (Scan_State); -- at Identifier
415 Scan; -- past Identifier
417 if Token = Tok_Arrow then
419 Set_Chars (Pragma_Arg_Node, Chars (Identifier_Node));
420 Delete_Node (Identifier_Node);
422 Restore_Scan_State (Scan_State); -- to Identifier
426 Set_Expression (Pragma_Arg_Node, P_Expression);
427 return Pragma_Arg_Node;
429 end P_Pragma_Argument_Association;