ada: Fix renaming of predefined equality operator for unchecked union types
[official-gcc.git] / gcc / ada / scans.adb
blob6eca5f5363c967fa0ec6c569b5d566a277802a4a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S C A N S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2023, 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 ------------------------------------------------------------------------------
26 with Snames; use Snames;
28 package body Scans is
30 -----------------------------
31 -- Initialize_Ada_Keywords --
32 -----------------------------
34 procedure Initialize_Ada_Keywords is
35 procedure Set_Reserved (N : Name_Id; T : Token_Type);
36 pragma Inline (Set_Reserved);
37 -- Set given name as a reserved word (T is the corresponding token)
39 ------------------
40 -- Set_Reserved --
41 ------------------
43 procedure Set_Reserved (N : Name_Id; T : Token_Type) is
44 begin
45 -- Set up Token_Type values in Names table entries for reserved
46 -- words. We use the Pos value of the Token_Type value. Note that
47 -- Is_Keyword_Name relies on the fact that Token_Type'Val (0) is not
48 -- a reserved word.
50 Set_Name_Table_Byte (N, Token_Type'Pos (T));
51 end Set_Reserved;
53 -- Start of processing for Initialize_Ada_Keywords
55 begin
56 -- Establish reserved words
58 Set_Reserved (Name_Abort, Tok_Abort);
59 Set_Reserved (Name_Abs, Tok_Abs);
60 Set_Reserved (Name_Abstract, Tok_Abstract);
61 Set_Reserved (Name_Accept, Tok_Accept);
62 Set_Reserved (Name_Access, Tok_Access);
63 Set_Reserved (Name_And, Tok_And);
64 Set_Reserved (Name_Aliased, Tok_Aliased);
65 Set_Reserved (Name_All, Tok_All);
66 Set_Reserved (Name_Array, Tok_Array);
67 Set_Reserved (Name_At, Tok_At);
68 Set_Reserved (Name_Begin, Tok_Begin);
69 Set_Reserved (Name_Body, Tok_Body);
70 Set_Reserved (Name_Case, Tok_Case);
71 Set_Reserved (Name_Constant, Tok_Constant);
72 Set_Reserved (Name_Declare, Tok_Declare);
73 Set_Reserved (Name_Delay, Tok_Delay);
74 Set_Reserved (Name_Delta, Tok_Delta);
75 Set_Reserved (Name_Digits, Tok_Digits);
76 Set_Reserved (Name_Do, Tok_Do);
77 Set_Reserved (Name_Else, Tok_Else);
78 Set_Reserved (Name_Elsif, Tok_Elsif);
79 Set_Reserved (Name_End, Tok_End);
80 Set_Reserved (Name_Entry, Tok_Entry);
81 Set_Reserved (Name_Exception, Tok_Exception);
82 Set_Reserved (Name_Exit, Tok_Exit);
83 Set_Reserved (Name_For, Tok_For);
84 Set_Reserved (Name_Function, Tok_Function);
85 Set_Reserved (Name_Generic, Tok_Generic);
86 Set_Reserved (Name_Goto, Tok_Goto);
87 Set_Reserved (Name_If, Tok_If);
88 Set_Reserved (Name_In, Tok_In);
89 Set_Reserved (Name_Is, Tok_Is);
90 Set_Reserved (Name_Limited, Tok_Limited);
91 Set_Reserved (Name_Loop, Tok_Loop);
92 Set_Reserved (Name_Mod, Tok_Mod);
93 Set_Reserved (Name_New, Tok_New);
94 Set_Reserved (Name_Not, Tok_Not);
95 Set_Reserved (Name_Null, Tok_Null);
96 Set_Reserved (Name_Of, Tok_Of);
97 Set_Reserved (Name_Or, Tok_Or);
98 Set_Reserved (Name_Others, Tok_Others);
99 Set_Reserved (Name_Out, Tok_Out);
100 Set_Reserved (Name_Package, Tok_Package);
101 Set_Reserved (Name_Pragma, Tok_Pragma);
102 Set_Reserved (Name_Private, Tok_Private);
103 Set_Reserved (Name_Procedure, Tok_Procedure);
104 Set_Reserved (Name_Protected, Tok_Protected);
105 Set_Reserved (Name_Raise, Tok_Raise);
106 Set_Reserved (Name_Range, Tok_Range);
107 Set_Reserved (Name_Record, Tok_Record);
108 Set_Reserved (Name_Rem, Tok_Rem);
109 Set_Reserved (Name_Renames, Tok_Renames);
110 Set_Reserved (Name_Requeue, Tok_Requeue);
111 Set_Reserved (Name_Return, Tok_Return);
112 Set_Reserved (Name_Reverse, Tok_Reverse);
113 Set_Reserved (Name_Select, Tok_Select);
114 Set_Reserved (Name_Separate, Tok_Separate);
115 Set_Reserved (Name_Subtype, Tok_Subtype);
116 Set_Reserved (Name_Tagged, Tok_Tagged);
117 Set_Reserved (Name_Task, Tok_Task);
118 Set_Reserved (Name_Terminate, Tok_Terminate);
119 Set_Reserved (Name_Then, Tok_Then);
120 Set_Reserved (Name_Type, Tok_Type);
121 Set_Reserved (Name_Until, Tok_Until);
122 Set_Reserved (Name_Use, Tok_Use);
123 Set_Reserved (Name_When, Tok_When);
124 Set_Reserved (Name_While, Tok_While);
125 Set_Reserved (Name_With, Tok_With);
126 Set_Reserved (Name_Xor, Tok_Xor);
128 -- Ada 2005 reserved words
130 Set_Reserved (Name_Interface, Tok_Interface);
131 Set_Reserved (Name_Overriding, Tok_Overriding);
132 Set_Reserved (Name_Synchronized, Tok_Synchronized);
134 -- Ada 2012 reserved words
136 Set_Reserved (Name_Some, Tok_Some);
137 end Initialize_Ada_Keywords;
139 ------------------
140 -- Keyword_Name --
141 ------------------
143 function Keyword_Name (Token : Token_Type) return Name_Id is
144 Tok : String := Token'Img;
145 pragma Assert (Tok (1 .. 4) = "TOK_");
146 Name : String renames Tok (5 .. Tok'Last);
148 begin
149 -- Convert to lower case. We don't want to add a dependence on a
150 -- general-purpose To_Lower routine, so we convert "by hand" here.
151 -- All keywords use 7-bit ASCII letters only, so this works.
153 for J in Name'Range loop
154 pragma Assert (Name (J) in 'A' .. 'Z');
155 Name (J) :=
156 Character'Val (Character'Pos (Name (J)) +
157 (Character'Pos ('a') - Character'Pos ('A')));
158 end loop;
160 return Name_Find (Name);
161 end Keyword_Name;
163 ------------------------
164 -- Restore_Scan_State --
165 ------------------------
167 procedure Restore_Scan_State (Saved_State : Saved_Scan_State) is
168 begin
169 Scan_Ptr := Saved_State.Save_Scan_Ptr;
170 Token := Saved_State.Save_Token;
171 Token_Ptr := Saved_State.Save_Token_Ptr;
172 Current_Line_Start := Saved_State.Save_Current_Line_Start;
173 Start_Column := Saved_State.Save_Start_Column;
174 Checksum := Saved_State.Save_Checksum;
175 First_Non_Blank_Location := Saved_State.Save_First_Non_Blank_Location;
176 Token_Node := Saved_State.Save_Token_Node;
177 Token_Name := Saved_State.Save_Token_Name;
178 Prev_Token := Saved_State.Save_Prev_Token;
179 Prev_Token_Ptr := Saved_State.Save_Prev_Token_Ptr;
180 end Restore_Scan_State;
182 ---------------------
183 -- Save_Scan_State --
184 ---------------------
186 procedure Save_Scan_State (Saved_State : out Saved_Scan_State) is
187 begin
188 Saved_State.Save_Scan_Ptr := Scan_Ptr;
189 Saved_State.Save_Token := Token;
190 Saved_State.Save_Token_Ptr := Token_Ptr;
191 Saved_State.Save_Current_Line_Start := Current_Line_Start;
192 Saved_State.Save_Start_Column := Start_Column;
193 Saved_State.Save_Checksum := Checksum;
194 Saved_State.Save_First_Non_Blank_Location := First_Non_Blank_Location;
195 Saved_State.Save_Token_Node := Token_Node;
196 Saved_State.Save_Token_Name := Token_Name;
197 Saved_State.Save_Prev_Token := Prev_Token;
198 Saved_State.Save_Prev_Token_Ptr := Prev_Token_Ptr;
199 end Save_Scan_State;
201 end Scans;