1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- $Revision: 1.35 $ --
11 -- Copyright (C) 1992-2001 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 Pragma_Node := New_Node (N_Pragma, Token_Ptr);
230 Pragma_Name := Token_Name;
233 Style.Check_Pragma_Name;
236 Ident_Node := P_Identifier;
237 Set_Chars (Pragma_Node, Pragma_Name);
238 Delete_Node (Ident_Node);
240 -- See if special INTERFACE/IMPORT check is required
242 if SIS_Entry_Active then
243 Interface_Check_Required := (Pragma_Name = Name_Interface);
244 Import_Check_Required := (Pragma_Name = Name_Import);
246 Interface_Check_Required := False;
247 Import_Check_Required := False;
250 -- Scan arguments. We assume that arguments are present if there is
251 -- a left paren, or if a semicolon is missing and there is another
252 -- token on the same line as the pragma name.
254 if Token = Tok_Left_Paren
255 or else (Token /= Tok_Semicolon
256 and then not Token_Is_At_Start_Of_Line)
258 Set_Pragma_Argument_Associations (Pragma_Node, New_List);
262 Arg_Count := Arg_Count + 1;
263 Assoc_Node := P_Pragma_Argument_Association;
266 and then (Interface_Check_Required or else Import_Check_Required)
268 -- Here is where we cancel the SIS active status if this pragma
269 -- supplies a body for the currently active subprogram spec.
271 if Nkind (Expression (Assoc_Node)) in N_Direct_Name
272 and then Chars (Expression (Assoc_Node)) = Chars (SIS_Labl)
274 SIS_Entry_Active := False;
278 Append (Assoc_Node, Pragma_Argument_Associations (Pragma_Node));
279 exit when Token /= Tok_Comma;
286 Semicolon_Loc := Token_Ptr;
288 if Token /= Tok_Semicolon then
290 Resync_Past_Semicolon;
292 Scan; -- past semicolon
295 if Is_Pragma_Name (Chars (Pragma_Node)) then
296 return Par.Prag (Pragma_Node, Semicolon_Loc);
299 -- Unrecognized pragma, warning generated in Sem_Prag
306 Resync_Past_Semicolon;
311 -- This routine is called if a pragma is encountered in an inappropriate
312 -- position, the pragma is scanned out and control returns to continue.
314 -- The caller has checked that the initial token is pragma
316 -- Error recovery: cannot raise Error_Resync
318 procedure P_Pragmas_Misplaced is
320 while Token = Tok_Pragma loop
321 Error_Msg_SC ("pragma not allowed here");
322 Discard_Junk_Node (P_Pragma);
324 end P_Pragmas_Misplaced;
326 -- This function is called to scan out an optional sequence of pragmas.
327 -- If no pragmas are found, then No_List is returned.
329 -- Error recovery: Cannot raise Error_Resync
331 function P_Pragmas_Opt return List_Id is
335 if Token = Tok_Pragma then
345 -- This procedure is called to scan out an optional sequence of pragmas.
346 -- Any pragmas found are appended to the list provided as an argument.
348 -- Error recovery: Cannot raise Error_Resync
350 procedure P_Pragmas_Opt (List : List_Id) is
354 while Token = Tok_Pragma loop
357 if Chars (P) = Name_Assert or else Chars (P) = Name_Debug then
358 Error_Msg_Name_1 := Chars (P);
360 ("pragma% must be in declaration/statement context", P);
367 --------------------------------------
368 -- 2.8 Pragma_Argument Association --
369 --------------------------------------
371 -- PRAGMA_ARGUMENT_ASSOCIATION ::=
372 -- [pragma_argument_IDENTIFIER =>] NAME
373 -- | [pragma_argument_IDENTIFIER =>] EXPRESSION
375 -- Error recovery: cannot raise Error_Resync
377 function P_Pragma_Argument_Association return Node_Id is
378 Scan_State : Saved_Scan_State;
379 Pragma_Arg_Node : Node_Id;
380 Identifier_Node : Node_Id;
383 Pragma_Arg_Node := New_Node (N_Pragma_Argument_Association, Token_Ptr);
384 Set_Chars (Pragma_Arg_Node, No_Name);
386 if Token = Tok_Identifier then
387 Identifier_Node := Token_Node;
388 Save_Scan_State (Scan_State); -- at Identifier
389 Scan; -- past Identifier
391 if Token = Tok_Arrow then
393 Set_Chars (Pragma_Arg_Node, Chars (Identifier_Node));
394 Delete_Node (Identifier_Node);
396 Restore_Scan_State (Scan_State); -- to Identifier
400 Set_Expression (Pragma_Arg_Node, P_Expression);
401 return Pragma_Arg_Node;
403 end P_Pragma_Argument_Association;