]> gcc.gnu.org Git - gcc.git/blob - gcc/ada/scn.adb
[Ada] Minor reformattings
[gcc.git] / gcc / ada / scn.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S C N --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2021, 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 with Atree; use Atree;
27 with Csets; use Csets;
28 with Namet; use Namet;
29 with Opt; use Opt;
30 with Restrict; use Restrict;
31 with Rident; use Rident;
32 with Scans; use Scans;
33 with Sinfo; use Sinfo;
34 with Sinfo.Nodes; use Sinfo.Nodes;
35 with Sinput; use Sinput;
36 with Uintp; use Uintp;
37
38 package body Scn is
39
40 Used_As_Identifier : array (Token_Type) of Boolean;
41 -- Flags set True if a given keyword is used as an identifier (used to
42 -- make sure that we only post an error message for incorrect use of a
43 -- keyword as an identifier once for a given keyword).
44
45 ----------------------------
46 -- Determine_Token_Casing --
47 ----------------------------
48
49 function Determine_Token_Casing return Casing_Type is
50 begin
51 return Scanner.Determine_Token_Casing;
52 end Determine_Token_Casing;
53
54 ------------------------
55 -- Initialize_Scanner --
56 ------------------------
57
58 procedure Initialize_Scanner
59 (Unit : Unit_Number_Type;
60 Index : Source_File_Index) is
61 begin
62 Scanner.Initialize_Scanner (Index);
63 Set_Unit (Index, Unit);
64
65 Current_Source_Unit := Unit;
66
67 -- Set default for Comes_From_Source. All nodes built now until we
68 -- reenter the analyzer will have Comes_From_Source set to True
69
70 Set_Comes_From_Source_Default (True);
71
72 Check_For_BOM;
73
74 -- Because of the License stuff above, Scng.Initialize_Scanner cannot
75 -- call Scan. Scan initial token (note this initializes Prev_Token,
76 -- Prev_Token_Ptr).
77
78 Scan;
79
80 -- Clear flags for reserved words used as identifiers
81
82 Used_As_Identifier := (others => False);
83 end Initialize_Scanner;
84
85 ---------------
86 -- Post_Scan --
87 ---------------
88
89 procedure Post_Scan is
90 procedure Check_Obsolescent_Features_Restriction (S : Source_Ptr);
91 -- This checks for Obsolescent_Features restriction being active, and
92 -- if so, flags the restriction as occurring at the given scan location.
93
94 procedure Check_Obsolete_Base_Char;
95 -- Check for numeric literal using ':' instead of '#' for based case
96
97 --------------------------------------------
98 -- Check_Obsolescent_Features_Restriction --
99 --------------------------------------------
100
101 procedure Check_Obsolescent_Features_Restriction (S : Source_Ptr) is
102 begin
103 -- Normally we have a node handy for posting restrictions. We don't
104 -- have such a node here, so construct a dummy one with the right
105 -- scan pointer. This is only used to get the Sloc value anyway.
106
107 Check_Restriction (No_Obsolescent_Features, New_Node (N_Empty, S));
108 end Check_Obsolescent_Features_Restriction;
109
110 ------------------------------
111 -- Check_Obsolete_Base_Char --
112 ------------------------------
113
114 procedure Check_Obsolete_Base_Char is
115 S : Source_Ptr;
116
117 begin
118 if Based_Literal_Uses_Colon then
119
120 -- Find the : for the restriction or warning message
121
122 S := Token_Ptr;
123 while Source (S) /= ':' loop
124 S := S + 1;
125 end loop;
126
127 Check_Obsolescent_Features_Restriction (S);
128
129 if Warn_On_Obsolescent_Feature then
130 Error_Msg
131 ("?j?use of "":"" is an obsolescent feature (RM J.2(3))", S);
132 Error_Msg
133 ("\?j?use ""'#"" instead", S);
134 end if;
135 end if;
136 end Check_Obsolete_Base_Char;
137
138 -- Start of processing for Post_Scan
139
140 begin
141 case Token is
142 when Tok_Char_Literal =>
143 Token_Node := New_Node (N_Character_Literal, Token_Ptr);
144 Set_Char_Literal_Value (Token_Node, UI_From_CC (Character_Code));
145 Set_Chars (Token_Node, Token_Name);
146
147 when Tok_Identifier =>
148 Token_Node := New_Node (N_Identifier, Token_Ptr);
149 Set_Chars (Token_Node, Token_Name);
150
151 when Tok_Real_Literal =>
152 Token_Node := New_Node (N_Real_Literal, Token_Ptr);
153 Set_Realval (Token_Node, Real_Literal_Value);
154 Check_Obsolete_Base_Char;
155
156 when Tok_Integer_Literal =>
157 Token_Node := New_Node (N_Integer_Literal, Token_Ptr);
158 Set_Intval (Token_Node, Int_Literal_Value);
159 Check_Obsolete_Base_Char;
160
161 when Tok_String_Literal =>
162 Token_Node := New_Node (N_String_Literal, Token_Ptr);
163 Set_Has_Wide_Character
164 (Token_Node, Wide_Character_Found);
165 Set_Has_Wide_Wide_Character
166 (Token_Node, Wide_Wide_Character_Found);
167 Set_Strval (Token_Node, String_Literal_Id);
168
169 if Source (Token_Ptr) = '%' then
170 Check_Obsolescent_Features_Restriction (Token_Ptr);
171
172 if Warn_On_Obsolescent_Feature then
173 Error_Msg_SC
174 ("?j?use of ""'%"" is an obsolescent feature (RM J.2(4))");
175 Error_Msg_SC ("\?j?use """""" instead");
176 end if;
177 end if;
178
179 when Tok_Operator_Symbol =>
180 Token_Node := New_Node (N_Operator_Symbol, Token_Ptr);
181 Set_Chars (Token_Node, Token_Name);
182 Set_Strval (Token_Node, String_Literal_Id);
183
184 when Tok_Vertical_Bar =>
185 if Source (Token_Ptr) = '!' then
186 Check_Obsolescent_Features_Restriction (Token_Ptr);
187
188 if Warn_On_Obsolescent_Feature then
189 Error_Msg_SC
190 ("?j?use of ""'!"" is an obsolescent feature (RM J.2(2))");
191 Error_Msg_SC ("\?j?use ""'|"" instead");
192 end if;
193 end if;
194
195 when others =>
196 null;
197 end case;
198 end Post_Scan;
199
200 ------------------------------
201 -- Scan_Reserved_Identifier --
202 ------------------------------
203
204 procedure Scan_Reserved_Identifier (Force_Msg : Boolean) is
205 Token_Chars : String := Token_Type'Image (Token);
206 Len : Natural := 0;
207
208 begin
209 -- AI12-0125 : '@' denotes the target_name, i.e. serves as an
210 -- abbreviation for the LHS of an assignment.
211
212 if Token = Tok_At_Sign then
213 Token_Node := New_Node (N_Target_Name, Token_Ptr);
214 return;
215 end if;
216
217 -- We have in Token_Chars the image of the Token name, i.e. Tok_xxx.
218 -- This code extracts the xxx and makes an identifier out of it.
219
220 for J in 5 .. Token_Chars'Length loop
221 Len := Len + 1;
222 Token_Chars (Len) := Fold_Lower (Token_Chars (J));
223 end loop;
224
225 Token_Name := Name_Find (Token_Chars (1 .. Len));
226
227 -- If Inside_Pragma is True, we don't give an error. This is to allow
228 -- things like "pragma Ignore_Pragma (Interface)", where "Interface" is
229 -- a reserved word. There is no danger of missing errors, because any
230 -- misuse must have been preceded by an illegal declaration. For
231 -- example, in "pragma Pack (Begin);", either Begin is not declared,
232 -- which is an error, or it is declared, which will be an error on that
233 -- declaration.
234
235 if (not Used_As_Identifier (Token) or else Force_Msg)
236 and then not Inside_Pragma
237 then
238 Error_Msg_Name_1 := Token_Name;
239 Error_Msg_SC ("reserved word* cannot be used as identifier!");
240 Used_As_Identifier (Token) := True;
241 end if;
242
243 Token := Tok_Identifier;
244 Token_Node := New_Node (N_Identifier, Token_Ptr);
245 Set_Chars (Token_Node, Token_Name);
246 end Scan_Reserved_Identifier;
247
248 end Scn;
This page took 0.045394 seconds and 5 git commands to generate.