annotate gcc/cp/lex.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Separate lexical analyzer for GNU C++.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 1987-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
9 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
10 any later version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
15 GNU General Public License for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 /* This file is the lexical analyzer for GNU C++. */
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 #include "config.h"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
25 /* For use with name_hint. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
26 #define INCLUDE_UNIQUE_PTR
111
kono
parents:
diff changeset
27 #include "system.h"
kono
parents:
diff changeset
28 #include "coretypes.h"
kono
parents:
diff changeset
29 #include "cp-tree.h"
kono
parents:
diff changeset
30 #include "stringpool.h"
kono
parents:
diff changeset
31 #include "c-family/c-pragma.h"
kono
parents:
diff changeset
32 #include "c-family/c-objc.h"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
33 #include "gcc-rich-location.h"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
34 #include "cp-name-hint.h"
111
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 static int interface_strcmp (const char *);
kono
parents:
diff changeset
37 static void init_cp_pragma (void);
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 static tree parse_strconst_pragma (const char *, int);
kono
parents:
diff changeset
40 static void handle_pragma_vtable (cpp_reader *);
kono
parents:
diff changeset
41 static void handle_pragma_unit (cpp_reader *);
kono
parents:
diff changeset
42 static void handle_pragma_interface (cpp_reader *);
kono
parents:
diff changeset
43 static void handle_pragma_implementation (cpp_reader *);
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 static void init_operators (void);
kono
parents:
diff changeset
46 static void copy_lang_type (tree);
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 /* A constraint that can be tested at compile time. */
kono
parents:
diff changeset
49 #define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1]
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 /* Functions and data structures for #pragma interface.
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 `#pragma implementation' means that the main file being compiled
kono
parents:
diff changeset
54 is considered to implement (provide) the classes that appear in
kono
parents:
diff changeset
55 its main body. I.e., if this is file "foo.cc", and class `bar'
kono
parents:
diff changeset
56 is defined in "foo.cc", then we say that "foo.cc implements bar".
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 All main input files "implement" themselves automagically.
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 `#pragma interface' means that unless this file (of the form "foo.h"
kono
parents:
diff changeset
61 is not presently being included by file "foo.cc", the
kono
parents:
diff changeset
62 CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none
kono
parents:
diff changeset
63 of the vtables nor any of the inline functions defined in foo.h
kono
parents:
diff changeset
64 will ever be output.
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 There are cases when we want to link files such as "defs.h" and
kono
parents:
diff changeset
67 "main.cc". In this case, we give "defs.h" a `#pragma interface',
kono
parents:
diff changeset
68 and "main.cc" has `#pragma implementation "defs.h"'. */
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 struct impl_files
kono
parents:
diff changeset
71 {
kono
parents:
diff changeset
72 const char *filename;
kono
parents:
diff changeset
73 struct impl_files *next;
kono
parents:
diff changeset
74 };
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 static struct impl_files *impl_file_chain;
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 void
kono
parents:
diff changeset
79 cxx_finish (void)
kono
parents:
diff changeset
80 {
kono
parents:
diff changeset
81 c_common_finish ();
kono
parents:
diff changeset
82 }
kono
parents:
diff changeset
83
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
84 ovl_op_info_t ovl_op_info[2][OVL_OP_MAX] =
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
85 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
86 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
87 {NULL_TREE, NULL, NULL, ERROR_MARK, OVL_OP_ERROR_MARK, 0},
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
88 {NULL_TREE, NULL, NULL, NOP_EXPR, OVL_OP_NOP_EXPR, 0},
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
89 #define DEF_OPERATOR(NAME, CODE, MANGLING, FLAGS) \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
90 {NULL_TREE, NAME, MANGLING, CODE, OVL_OP_##CODE, FLAGS},
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
91 #define OPERATOR_TRANSITION }, { \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
92 {NULL_TREE, NULL, NULL, ERROR_MARK, OVL_OP_ERROR_MARK, 0},
111
kono
parents:
diff changeset
93 #include "operators.def"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
94 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
95 };
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
96 unsigned char ovl_op_mapping[MAX_TREE_CODES];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
97 unsigned char ovl_op_alternate[OVL_OP_MAX];
111
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 /* Get the name of the kind of identifier T. */
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 const char *
kono
parents:
diff changeset
102 get_identifier_kind_name (tree id)
kono
parents:
diff changeset
103 {
kono
parents:
diff changeset
104 /* Keep in sync with cp_id_kind enumeration. */
kono
parents:
diff changeset
105 static const char *const names[cik_max] = {
kono
parents:
diff changeset
106 "normal", "keyword", "constructor", "destructor",
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
107 "simple-op", "assign-op", "conv-op", "<reserved>udlit-op"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
108 };
111
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 unsigned kind = 0;
kono
parents:
diff changeset
111 kind |= IDENTIFIER_KIND_BIT_2 (id) << 2;
kono
parents:
diff changeset
112 kind |= IDENTIFIER_KIND_BIT_1 (id) << 1;
kono
parents:
diff changeset
113 kind |= IDENTIFIER_KIND_BIT_0 (id) << 0;
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 return names[kind];
kono
parents:
diff changeset
116 }
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 /* Set the identifier kind, which we expect to currently be zero. */
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 void
kono
parents:
diff changeset
121 set_identifier_kind (tree id, cp_identifier_kind kind)
kono
parents:
diff changeset
122 {
kono
parents:
diff changeset
123 gcc_checking_assert (!IDENTIFIER_KIND_BIT_2 (id)
kono
parents:
diff changeset
124 & !IDENTIFIER_KIND_BIT_1 (id)
kono
parents:
diff changeset
125 & !IDENTIFIER_KIND_BIT_0 (id));
kono
parents:
diff changeset
126 IDENTIFIER_KIND_BIT_2 (id) |= (kind >> 2) & 1;
kono
parents:
diff changeset
127 IDENTIFIER_KIND_BIT_1 (id) |= (kind >> 1) & 1;
kono
parents:
diff changeset
128 IDENTIFIER_KIND_BIT_0 (id) |= (kind >> 0) & 1;
kono
parents:
diff changeset
129 }
kono
parents:
diff changeset
130
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
131 /* Create and tag the internal operator name for the overloaded
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
132 operator PTR describes. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
133
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
134 static tree
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
135 set_operator_ident (ovl_op_info_t *ptr)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
136 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
137 char buffer[32];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
138 size_t len = snprintf (buffer, sizeof (buffer), "operator%s%s",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
139 &" "[ptr->name[0] && ptr->name[0] != '_'
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
140 && !ISALPHA (ptr->name[0])],
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
141 ptr->name);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
142 gcc_checking_assert (len < sizeof (buffer));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
143
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
144 tree ident = get_identifier_with_length (buffer, len);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
145 ptr->identifier = ident;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
146
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
147 return ident;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
148 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
149
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
150 /* Initialize data structures that keep track of operator names. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
151
111
kono
parents:
diff changeset
152 static void
kono
parents:
diff changeset
153 init_operators (void)
kono
parents:
diff changeset
154 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
155 /* We rely on both these being zero. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
156 gcc_checking_assert (!OVL_OP_ERROR_MARK && !ERROR_MARK);
111
kono
parents:
diff changeset
157
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
158 /* This loop iterates backwards because we need to move the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
159 assignment operators down to their correct slots. I.e. morally
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
160 equivalent to an overlapping memmove where dest > src. Slot
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
161 zero is for error_mark, so hae no operator. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
162 for (unsigned ix = OVL_OP_MAX; --ix;)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
163 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
164 ovl_op_info_t *op_ptr = &ovl_op_info[false][ix];
111
kono
parents:
diff changeset
165
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
166 if (op_ptr->name)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
167 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
168 /* Make sure it fits in lang_decl_fn::operator_code. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
169 gcc_checking_assert (op_ptr->ovl_op_code < (1 << 6));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
170 tree ident = set_operator_ident (op_ptr);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
171 if (unsigned index = IDENTIFIER_CP_INDEX (ident))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
172 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
173 ovl_op_info_t *bin_ptr = &ovl_op_info[false][index];
111
kono
parents:
diff changeset
174
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
175 /* They should only differ in unary/binary ness. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
176 gcc_checking_assert ((op_ptr->flags ^ bin_ptr->flags)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
177 == OVL_OP_FLAG_AMBIARY);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
178 bin_ptr->flags |= op_ptr->flags;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
179 ovl_op_alternate[index] = ix;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
180 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
181 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
182 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
183 IDENTIFIER_CP_INDEX (ident) = ix;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
184 set_identifier_kind (ident, cik_simple_op);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
185 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
186 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
187 if (op_ptr->tree_code)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
188 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
189 gcc_checking_assert (op_ptr->ovl_op_code == ix
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
190 && !ovl_op_mapping[op_ptr->tree_code]);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
191 ovl_op_mapping[op_ptr->tree_code] = op_ptr->ovl_op_code;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
192 }
111
kono
parents:
diff changeset
193
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
194 ovl_op_info_t *as_ptr = &ovl_op_info[true][ix];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
195 if (as_ptr->name)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
196 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
197 /* These will be placed at the start of the array, move to
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
198 the correct slot and initialize. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
199 if (as_ptr->ovl_op_code != ix)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
200 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
201 ovl_op_info_t *dst_ptr = &ovl_op_info[true][as_ptr->ovl_op_code];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
202 gcc_assert (as_ptr->ovl_op_code > ix && !dst_ptr->tree_code);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
203 memcpy (dst_ptr, as_ptr, sizeof (*dst_ptr));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
204 memset (as_ptr, 0, sizeof (*as_ptr));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
205 as_ptr = dst_ptr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
206 }
111
kono
parents:
diff changeset
207
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
208 tree ident = set_operator_ident (as_ptr);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
209 gcc_checking_assert (!IDENTIFIER_CP_INDEX (ident));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
210 IDENTIFIER_CP_INDEX (ident) = as_ptr->ovl_op_code;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
211 set_identifier_kind (ident, cik_assign_op);
111
kono
parents:
diff changeset
212
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
213 gcc_checking_assert (!ovl_op_mapping[as_ptr->tree_code]
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
214 || (ovl_op_mapping[as_ptr->tree_code]
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
215 == as_ptr->ovl_op_code));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
216 ovl_op_mapping[as_ptr->tree_code] = as_ptr->ovl_op_code;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
217 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
218 }
111
kono
parents:
diff changeset
219 }
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 /* Initialize the reserved words. */
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 void
kono
parents:
diff changeset
224 init_reswords (void)
kono
parents:
diff changeset
225 {
kono
parents:
diff changeset
226 unsigned int i;
kono
parents:
diff changeset
227 tree id;
kono
parents:
diff changeset
228 int mask = 0;
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 if (cxx_dialect < cxx11)
kono
parents:
diff changeset
231 mask |= D_CXX11;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
232 if (cxx_dialect < cxx2a)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
233 mask |= D_CXX20;
111
kono
parents:
diff changeset
234 if (!flag_concepts)
kono
parents:
diff changeset
235 mask |= D_CXX_CONCEPTS;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
236 if (!flag_coroutines)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
237 mask |= D_CXX_COROUTINES;
111
kono
parents:
diff changeset
238 if (!flag_tm)
kono
parents:
diff changeset
239 mask |= D_TRANSMEM;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
240 if (!flag_char8_t)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
241 mask |= D_CXX_CHAR8_T;
111
kono
parents:
diff changeset
242 if (flag_no_asm)
kono
parents:
diff changeset
243 mask |= D_ASM | D_EXT;
kono
parents:
diff changeset
244 if (flag_no_gnu_keywords)
kono
parents:
diff changeset
245 mask |= D_EXT;
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 /* The Objective-C keywords are all context-dependent. */
kono
parents:
diff changeset
248 mask |= D_OBJC;
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
kono
parents:
diff changeset
251 for (i = 0; i < num_c_common_reswords; i++)
kono
parents:
diff changeset
252 {
kono
parents:
diff changeset
253 if (c_common_reswords[i].disable & D_CONLY)
kono
parents:
diff changeset
254 continue;
kono
parents:
diff changeset
255 id = get_identifier (c_common_reswords[i].word);
kono
parents:
diff changeset
256 C_SET_RID_CODE (id, c_common_reswords[i].rid);
kono
parents:
diff changeset
257 ridpointers [(int) c_common_reswords[i].rid] = id;
kono
parents:
diff changeset
258 if (! (c_common_reswords[i].disable & mask))
kono
parents:
diff changeset
259 set_identifier_kind (id, cik_keyword);
kono
parents:
diff changeset
260 }
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 for (i = 0; i < NUM_INT_N_ENTS; i++)
kono
parents:
diff changeset
263 {
kono
parents:
diff changeset
264 char name[50];
kono
parents:
diff changeset
265 sprintf (name, "__int%d", int_n_data[i].bitsize);
kono
parents:
diff changeset
266 id = get_identifier (name);
kono
parents:
diff changeset
267 C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
kono
parents:
diff changeset
268 set_identifier_kind (id, cik_keyword);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
269
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
270 sprintf (name, "__int%d__", int_n_data[i].bitsize);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
271 id = get_identifier (name);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
272 C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
273 set_identifier_kind (id, cik_keyword);
111
kono
parents:
diff changeset
274 }
kono
parents:
diff changeset
275 }
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 static void
kono
parents:
diff changeset
278 init_cp_pragma (void)
kono
parents:
diff changeset
279 {
kono
parents:
diff changeset
280 c_register_pragma (0, "vtable", handle_pragma_vtable);
kono
parents:
diff changeset
281 c_register_pragma (0, "unit", handle_pragma_unit);
kono
parents:
diff changeset
282 c_register_pragma (0, "interface", handle_pragma_interface);
kono
parents:
diff changeset
283 c_register_pragma (0, "implementation", handle_pragma_implementation);
kono
parents:
diff changeset
284 c_register_pragma ("GCC", "interface", handle_pragma_interface);
kono
parents:
diff changeset
285 c_register_pragma ("GCC", "implementation", handle_pragma_implementation);
kono
parents:
diff changeset
286 }
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 /* TRUE if a code represents a statement. */
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 bool statement_code_p[MAX_TREE_CODES];
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 /* Initialize the C++ front end. This function is very sensitive to
kono
parents:
diff changeset
293 the exact order that things are done here. It would be nice if the
kono
parents:
diff changeset
294 initialization done by this routine were moved to its subroutines,
kono
parents:
diff changeset
295 and the ordering dependencies clarified and reduced. */
kono
parents:
diff changeset
296 bool
kono
parents:
diff changeset
297 cxx_init (void)
kono
parents:
diff changeset
298 {
kono
parents:
diff changeset
299 location_t saved_loc;
kono
parents:
diff changeset
300 unsigned int i;
kono
parents:
diff changeset
301 static const enum tree_code stmt_codes[] = {
kono
parents:
diff changeset
302 CTOR_INITIALIZER, TRY_BLOCK, HANDLER,
kono
parents:
diff changeset
303 EH_SPEC_BLOCK, USING_STMT, TAG_DEFN,
kono
parents:
diff changeset
304 IF_STMT, CLEANUP_STMT, FOR_STMT,
kono
parents:
diff changeset
305 RANGE_FOR_STMT, WHILE_STMT, DO_STMT,
kono
parents:
diff changeset
306 BREAK_STMT, CONTINUE_STMT, SWITCH_STMT,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
307 EXPR_STMT, OMP_DEPOBJ
111
kono
parents:
diff changeset
308 };
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 memset (&statement_code_p, 0, sizeof (statement_code_p));
kono
parents:
diff changeset
311 for (i = 0; i < ARRAY_SIZE (stmt_codes); i++)
kono
parents:
diff changeset
312 statement_code_p[stmt_codes[i]] = true;
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 saved_loc = input_location;
kono
parents:
diff changeset
315 input_location = BUILTINS_LOCATION;
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 init_reswords ();
kono
parents:
diff changeset
318 init_tree ();
kono
parents:
diff changeset
319 init_cp_semantics ();
kono
parents:
diff changeset
320 init_operators ();
kono
parents:
diff changeset
321 init_method ();
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 current_function_decl = NULL;
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 class_type_node = ridpointers[(int) RID_CLASS];
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 cxx_init_decl_processing ();
kono
parents:
diff changeset
328
kono
parents:
diff changeset
329 if (c_common_init () == false)
kono
parents:
diff changeset
330 {
kono
parents:
diff changeset
331 input_location = saved_loc;
kono
parents:
diff changeset
332 return false;
kono
parents:
diff changeset
333 }
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 init_cp_pragma ();
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 input_location = saved_loc;
kono
parents:
diff changeset
338 return true;
kono
parents:
diff changeset
339 }
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 /* Return nonzero if S is not considered part of an
kono
parents:
diff changeset
342 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 static int
kono
parents:
diff changeset
345 interface_strcmp (const char* s)
kono
parents:
diff changeset
346 {
kono
parents:
diff changeset
347 /* Set the interface/implementation bits for this scope. */
kono
parents:
diff changeset
348 struct impl_files *ifiles;
kono
parents:
diff changeset
349 const char *s1;
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
kono
parents:
diff changeset
352 {
kono
parents:
diff changeset
353 const char *t1 = ifiles->filename;
kono
parents:
diff changeset
354 s1 = s;
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 if (*s1 == 0 || filename_ncmp (s1, t1, 1) != 0)
kono
parents:
diff changeset
357 continue;
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 while (*s1 != 0 && filename_ncmp (s1, t1, 1) == 0)
kono
parents:
diff changeset
360 s1++, t1++;
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 /* A match. */
kono
parents:
diff changeset
363 if (*s1 == *t1)
kono
parents:
diff changeset
364 return 0;
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
kono
parents:
diff changeset
367 if (strchr (s1, '.') || strchr (t1, '.'))
kono
parents:
diff changeset
368 continue;
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
kono
parents:
diff changeset
371 continue;
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 /* A match. */
kono
parents:
diff changeset
374 return 0;
kono
parents:
diff changeset
375 }
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 /* No matches. */
kono
parents:
diff changeset
378 return 1;
kono
parents:
diff changeset
379 }
kono
parents:
diff changeset
380
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 /* Parse a #pragma whose sole argument is a string constant.
kono
parents:
diff changeset
384 If OPT is true, the argument is optional. */
kono
parents:
diff changeset
385 static tree
kono
parents:
diff changeset
386 parse_strconst_pragma (const char* name, int opt)
kono
parents:
diff changeset
387 {
kono
parents:
diff changeset
388 tree result, x;
kono
parents:
diff changeset
389 enum cpp_ttype t;
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 t = pragma_lex (&result);
kono
parents:
diff changeset
392 if (t == CPP_STRING)
kono
parents:
diff changeset
393 {
kono
parents:
diff changeset
394 if (pragma_lex (&x) != CPP_EOF)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
395 warning (0, "junk at end of %<#pragma %s%>", name);
111
kono
parents:
diff changeset
396 return result;
kono
parents:
diff changeset
397 }
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 if (t == CPP_EOF && opt)
kono
parents:
diff changeset
400 return NULL_TREE;
kono
parents:
diff changeset
401
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
402 error ("invalid %<#pragma %s%>", name);
111
kono
parents:
diff changeset
403 return error_mark_node;
kono
parents:
diff changeset
404 }
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 static void
kono
parents:
diff changeset
407 handle_pragma_vtable (cpp_reader* /*dfile*/)
kono
parents:
diff changeset
408 {
kono
parents:
diff changeset
409 parse_strconst_pragma ("vtable", 0);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
410 sorry ("%<#pragma vtable%> no longer supported");
111
kono
parents:
diff changeset
411 }
kono
parents:
diff changeset
412
kono
parents:
diff changeset
413 static void
kono
parents:
diff changeset
414 handle_pragma_unit (cpp_reader* /*dfile*/)
kono
parents:
diff changeset
415 {
kono
parents:
diff changeset
416 /* Validate syntax, but don't do anything. */
kono
parents:
diff changeset
417 parse_strconst_pragma ("unit", 0);
kono
parents:
diff changeset
418 }
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 static void
kono
parents:
diff changeset
421 handle_pragma_interface (cpp_reader* /*dfile*/)
kono
parents:
diff changeset
422 {
kono
parents:
diff changeset
423 tree fname = parse_strconst_pragma ("interface", 1);
kono
parents:
diff changeset
424 struct c_fileinfo *finfo;
kono
parents:
diff changeset
425 const char *filename;
kono
parents:
diff changeset
426
kono
parents:
diff changeset
427 if (fname == error_mark_node)
kono
parents:
diff changeset
428 return;
kono
parents:
diff changeset
429 else if (fname == 0)
kono
parents:
diff changeset
430 filename = lbasename (LOCATION_FILE (input_location));
kono
parents:
diff changeset
431 else
kono
parents:
diff changeset
432 filename = TREE_STRING_POINTER (fname);
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 finfo = get_fileinfo (LOCATION_FILE (input_location));
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 if (impl_file_chain == 0)
kono
parents:
diff changeset
437 {
kono
parents:
diff changeset
438 /* If this is zero at this point, then we are
kono
parents:
diff changeset
439 auto-implementing. */
kono
parents:
diff changeset
440 if (main_input_filename == 0)
kono
parents:
diff changeset
441 main_input_filename = LOCATION_FILE (input_location);
kono
parents:
diff changeset
442 }
kono
parents:
diff changeset
443
kono
parents:
diff changeset
444 finfo->interface_only = interface_strcmp (filename);
kono
parents:
diff changeset
445 /* If MULTIPLE_SYMBOL_SPACES is set, we cannot assume that we can see
kono
parents:
diff changeset
446 a definition in another file. */
kono
parents:
diff changeset
447 if (!MULTIPLE_SYMBOL_SPACES || !finfo->interface_only)
kono
parents:
diff changeset
448 finfo->interface_unknown = 0;
kono
parents:
diff changeset
449 }
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
kono
parents:
diff changeset
452 We used to only allow this at toplevel, but that restriction was buggy
kono
parents:
diff changeset
453 in older compilers and it seems reasonable to allow it in the headers
kono
parents:
diff changeset
454 themselves, too. It only needs to precede the matching #p interface.
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 We don't touch finfo->interface_only or finfo->interface_unknown;
kono
parents:
diff changeset
457 the user must specify a matching #p interface for this to have
kono
parents:
diff changeset
458 any effect. */
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 static void
kono
parents:
diff changeset
461 handle_pragma_implementation (cpp_reader* /*dfile*/)
kono
parents:
diff changeset
462 {
kono
parents:
diff changeset
463 tree fname = parse_strconst_pragma ("implementation", 1);
kono
parents:
diff changeset
464 const char *filename;
kono
parents:
diff changeset
465 struct impl_files *ifiles = impl_file_chain;
kono
parents:
diff changeset
466
kono
parents:
diff changeset
467 if (fname == error_mark_node)
kono
parents:
diff changeset
468 return;
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 if (fname == 0)
kono
parents:
diff changeset
471 {
kono
parents:
diff changeset
472 if (main_input_filename)
kono
parents:
diff changeset
473 filename = main_input_filename;
kono
parents:
diff changeset
474 else
kono
parents:
diff changeset
475 filename = LOCATION_FILE (input_location);
kono
parents:
diff changeset
476 filename = lbasename (filename);
kono
parents:
diff changeset
477 }
kono
parents:
diff changeset
478 else
kono
parents:
diff changeset
479 {
kono
parents:
diff changeset
480 filename = TREE_STRING_POINTER (fname);
kono
parents:
diff changeset
481 if (cpp_included_before (parse_in, filename, input_location))
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
482 warning (0, "%<#pragma implementation%> for %qs appears after "
111
kono
parents:
diff changeset
483 "file is included", filename);
kono
parents:
diff changeset
484 }
kono
parents:
diff changeset
485
kono
parents:
diff changeset
486 for (; ifiles; ifiles = ifiles->next)
kono
parents:
diff changeset
487 {
kono
parents:
diff changeset
488 if (! filename_cmp (ifiles->filename, filename))
kono
parents:
diff changeset
489 break;
kono
parents:
diff changeset
490 }
kono
parents:
diff changeset
491 if (ifiles == 0)
kono
parents:
diff changeset
492 {
kono
parents:
diff changeset
493 ifiles = XNEW (struct impl_files);
kono
parents:
diff changeset
494 ifiles->filename = xstrdup (filename);
kono
parents:
diff changeset
495 ifiles->next = impl_file_chain;
kono
parents:
diff changeset
496 impl_file_chain = ifiles;
kono
parents:
diff changeset
497 }
kono
parents:
diff changeset
498 }
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 /* Issue an error message indicating that the lookup of NAME (an
kono
parents:
diff changeset
501 IDENTIFIER_NODE) failed. Returns the ERROR_MARK_NODE. */
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503 tree
kono
parents:
diff changeset
504 unqualified_name_lookup_error (tree name, location_t loc)
kono
parents:
diff changeset
505 {
kono
parents:
diff changeset
506 if (loc == UNKNOWN_LOCATION)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
507 loc = cp_expr_loc_or_input_loc (name);
111
kono
parents:
diff changeset
508
kono
parents:
diff changeset
509 if (IDENTIFIER_ANY_OP_P (name))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
510 error_at (loc, "%qD not defined", name);
111
kono
parents:
diff changeset
511 else
kono
parents:
diff changeset
512 {
kono
parents:
diff changeset
513 if (!objc_diagnose_private_ivar (name))
kono
parents:
diff changeset
514 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
515 auto_diagnostic_group d;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
516 name_hint hint = suggest_alternatives_for (loc, name, true);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
517 if (const char *suggestion = hint.suggestion ())
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
518 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
519 gcc_rich_location richloc (loc);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
520 richloc.add_fixit_replace (suggestion);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
521 error_at (&richloc,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
522 "%qD was not declared in this scope; did you mean %qs?",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
523 name, suggestion);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
524 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
525 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
526 error_at (loc, "%qD was not declared in this scope", name);
111
kono
parents:
diff changeset
527 }
kono
parents:
diff changeset
528 /* Prevent repeated error messages by creating a VAR_DECL with
kono
parents:
diff changeset
529 this NAME in the innermost block scope. */
kono
parents:
diff changeset
530 if (local_bindings_p ())
kono
parents:
diff changeset
531 {
kono
parents:
diff changeset
532 tree decl = build_decl (loc, VAR_DECL, name, error_mark_node);
kono
parents:
diff changeset
533 TREE_USED (decl) = true;
kono
parents:
diff changeset
534 pushdecl (decl);
kono
parents:
diff changeset
535 }
kono
parents:
diff changeset
536 }
kono
parents:
diff changeset
537
kono
parents:
diff changeset
538 return error_mark_node;
kono
parents:
diff changeset
539 }
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 /* Like unqualified_name_lookup_error, but NAME_EXPR is an unqualified-id
kono
parents:
diff changeset
542 NAME, encapsulated with its location in a CP_EXPR, used as a function.
kono
parents:
diff changeset
543 Returns an appropriate expression for NAME. */
kono
parents:
diff changeset
544
kono
parents:
diff changeset
545 tree
kono
parents:
diff changeset
546 unqualified_fn_lookup_error (cp_expr name_expr)
kono
parents:
diff changeset
547 {
kono
parents:
diff changeset
548 tree name = name_expr.get_value ();
kono
parents:
diff changeset
549 location_t loc = name_expr.get_location ();
kono
parents:
diff changeset
550 if (loc == UNKNOWN_LOCATION)
kono
parents:
diff changeset
551 loc = input_location;
kono
parents:
diff changeset
552
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
553 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
554 name = TREE_OPERAND (name, 0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
555
111
kono
parents:
diff changeset
556 if (processing_template_decl)
kono
parents:
diff changeset
557 {
kono
parents:
diff changeset
558 /* In a template, it is invalid to write "f()" or "f(3)" if no
kono
parents:
diff changeset
559 declaration of "f" is available. Historically, G++ and most
kono
parents:
diff changeset
560 other compilers accepted that usage since they deferred all name
kono
parents:
diff changeset
561 lookup until instantiation time rather than doing unqualified
kono
parents:
diff changeset
562 name lookup at template definition time; explain to the user what
kono
parents:
diff changeset
563 is going wrong.
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 Note that we have the exact wording of the following message in
kono
parents:
diff changeset
566 the manual (trouble.texi, node "Name lookup"), so they need to
kono
parents:
diff changeset
567 be kept in synch. */
kono
parents:
diff changeset
568 permerror (loc, "there are no arguments to %qD that depend on a template "
kono
parents:
diff changeset
569 "parameter, so a declaration of %qD must be available",
kono
parents:
diff changeset
570 name, name);
kono
parents:
diff changeset
571
kono
parents:
diff changeset
572 if (!flag_permissive)
kono
parents:
diff changeset
573 {
kono
parents:
diff changeset
574 static bool hint;
kono
parents:
diff changeset
575 if (!hint)
kono
parents:
diff changeset
576 {
kono
parents:
diff changeset
577 inform (loc, "(if you use %<-fpermissive%>, G++ will accept your "
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
578 "code, but allowing the use of an undeclared name is "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
579 "deprecated)");
111
kono
parents:
diff changeset
580 hint = true;
kono
parents:
diff changeset
581 }
kono
parents:
diff changeset
582 }
kono
parents:
diff changeset
583 return name;
kono
parents:
diff changeset
584 }
kono
parents:
diff changeset
585
kono
parents:
diff changeset
586 return unqualified_name_lookup_error (name, loc);
kono
parents:
diff changeset
587 }
kono
parents:
diff changeset
588
kono
parents:
diff changeset
589
kono
parents:
diff changeset
590 /* Hasher for the conversion operator name hash table. */
kono
parents:
diff changeset
591 struct conv_type_hasher : ggc_ptr_hash<tree_node>
kono
parents:
diff changeset
592 {
kono
parents:
diff changeset
593 /* Hash NODE, an identifier node in the table. TYPE_UID is
kono
parents:
diff changeset
594 suitable, as we're not concerned about matching canonicalness
kono
parents:
diff changeset
595 here. */
kono
parents:
diff changeset
596 static hashval_t hash (tree node)
kono
parents:
diff changeset
597 {
kono
parents:
diff changeset
598 return (hashval_t) TYPE_UID (TREE_TYPE (node));
kono
parents:
diff changeset
599 }
kono
parents:
diff changeset
600
kono
parents:
diff changeset
601 /* Compare NODE, an identifier node in the table, against TYPE, an
kono
parents:
diff changeset
602 incoming TYPE being looked up. */
kono
parents:
diff changeset
603 static bool equal (tree node, tree type)
kono
parents:
diff changeset
604 {
kono
parents:
diff changeset
605 return TREE_TYPE (node) == type;
kono
parents:
diff changeset
606 }
kono
parents:
diff changeset
607 };
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 /* This hash table maps TYPEs to the IDENTIFIER for a conversion
kono
parents:
diff changeset
610 operator to TYPE. The nodes are IDENTIFIERs whose TREE_TYPE is the
kono
parents:
diff changeset
611 TYPE. */
kono
parents:
diff changeset
612
kono
parents:
diff changeset
613 static GTY (()) hash_table<conv_type_hasher> *conv_type_names;
kono
parents:
diff changeset
614
kono
parents:
diff changeset
615 /* Return an identifier for a conversion operator to TYPE. We can get
kono
parents:
diff changeset
616 from the returned identifier to the type. We store TYPE, which is
kono
parents:
diff changeset
617 not necessarily the canonical type, which allows us to report the
kono
parents:
diff changeset
618 form the user used in error messages. All these identifiers are
kono
parents:
diff changeset
619 not in the identifier hash table, and have the same string name.
kono
parents:
diff changeset
620 These IDENTIFIERS are not in the identifier hash table, and all
kono
parents:
diff changeset
621 have the same IDENTIFIER_STRING. */
kono
parents:
diff changeset
622
kono
parents:
diff changeset
623 tree
kono
parents:
diff changeset
624 make_conv_op_name (tree type)
kono
parents:
diff changeset
625 {
kono
parents:
diff changeset
626 if (type == error_mark_node)
kono
parents:
diff changeset
627 return error_mark_node;
kono
parents:
diff changeset
628
kono
parents:
diff changeset
629 if (conv_type_names == NULL)
kono
parents:
diff changeset
630 conv_type_names = hash_table<conv_type_hasher>::create_ggc (31);
kono
parents:
diff changeset
631
kono
parents:
diff changeset
632 tree *slot = conv_type_names->find_slot_with_hash
kono
parents:
diff changeset
633 (type, (hashval_t) TYPE_UID (type), INSERT);
kono
parents:
diff changeset
634 tree identifier = *slot;
kono
parents:
diff changeset
635 if (!identifier)
kono
parents:
diff changeset
636 {
kono
parents:
diff changeset
637 /* Create a raw IDENTIFIER outside of the identifier hash
kono
parents:
diff changeset
638 table. */
kono
parents:
diff changeset
639 identifier = copy_node (conv_op_identifier);
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 /* Just in case something managed to bind. */
kono
parents:
diff changeset
642 IDENTIFIER_BINDING (identifier) = NULL;
kono
parents:
diff changeset
643
kono
parents:
diff changeset
644 /* Hang TYPE off the identifier so it can be found easily later
kono
parents:
diff changeset
645 when performing conversions. */
kono
parents:
diff changeset
646 TREE_TYPE (identifier) = type;
kono
parents:
diff changeset
647
kono
parents:
diff changeset
648 *slot = identifier;
kono
parents:
diff changeset
649 }
kono
parents:
diff changeset
650
kono
parents:
diff changeset
651 return identifier;
kono
parents:
diff changeset
652 }
kono
parents:
diff changeset
653
kono
parents:
diff changeset
654 /* Wrapper around build_lang_decl_loc(). Should gradually move to
kono
parents:
diff changeset
655 build_lang_decl_loc() and then rename build_lang_decl_loc() back to
kono
parents:
diff changeset
656 build_lang_decl(). */
kono
parents:
diff changeset
657
kono
parents:
diff changeset
658 tree
kono
parents:
diff changeset
659 build_lang_decl (enum tree_code code, tree name, tree type)
kono
parents:
diff changeset
660 {
kono
parents:
diff changeset
661 return build_lang_decl_loc (input_location, code, name, type);
kono
parents:
diff changeset
662 }
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 /* Build a decl from CODE, NAME, TYPE declared at LOC, and then add
kono
parents:
diff changeset
665 DECL_LANG_SPECIFIC info to the result. */
kono
parents:
diff changeset
666
kono
parents:
diff changeset
667 tree
kono
parents:
diff changeset
668 build_lang_decl_loc (location_t loc, enum tree_code code, tree name, tree type)
kono
parents:
diff changeset
669 {
kono
parents:
diff changeset
670 tree t;
kono
parents:
diff changeset
671
kono
parents:
diff changeset
672 t = build_decl (loc, code, name, type);
kono
parents:
diff changeset
673 retrofit_lang_decl (t);
kono
parents:
diff changeset
674
kono
parents:
diff changeset
675 return t;
kono
parents:
diff changeset
676 }
kono
parents:
diff changeset
677
kono
parents:
diff changeset
678 /* Maybe add a raw lang_decl to T, a decl. Return true if it needed
kono
parents:
diff changeset
679 one. */
kono
parents:
diff changeset
680
kono
parents:
diff changeset
681 static bool
kono
parents:
diff changeset
682 maybe_add_lang_decl_raw (tree t, bool decomp_p)
kono
parents:
diff changeset
683 {
kono
parents:
diff changeset
684 size_t size;
kono
parents:
diff changeset
685 lang_decl_selector sel;
kono
parents:
diff changeset
686
kono
parents:
diff changeset
687 if (decomp_p)
kono
parents:
diff changeset
688 sel = lds_decomp, size = sizeof (struct lang_decl_decomp);
kono
parents:
diff changeset
689 else if (TREE_CODE (t) == FUNCTION_DECL)
kono
parents:
diff changeset
690 sel = lds_fn, size = sizeof (struct lang_decl_fn);
kono
parents:
diff changeset
691 else if (TREE_CODE (t) == NAMESPACE_DECL)
kono
parents:
diff changeset
692 sel = lds_ns, size = sizeof (struct lang_decl_ns);
kono
parents:
diff changeset
693 else if (TREE_CODE (t) == PARM_DECL)
kono
parents:
diff changeset
694 sel = lds_parm, size = sizeof (struct lang_decl_parm);
kono
parents:
diff changeset
695 else if (LANG_DECL_HAS_MIN (t))
kono
parents:
diff changeset
696 sel = lds_min, size = sizeof (struct lang_decl_min);
kono
parents:
diff changeset
697 else
kono
parents:
diff changeset
698 return false;
kono
parents:
diff changeset
699
kono
parents:
diff changeset
700 struct lang_decl *ld
kono
parents:
diff changeset
701 = (struct lang_decl *) ggc_internal_cleared_alloc (size);
kono
parents:
diff changeset
702
kono
parents:
diff changeset
703 ld->u.base.selector = sel;
kono
parents:
diff changeset
704 DECL_LANG_SPECIFIC (t) = ld;
kono
parents:
diff changeset
705
kono
parents:
diff changeset
706 if (sel == lds_ns)
kono
parents:
diff changeset
707 /* Who'd create a namespace, only to put nothing in it? */
kono
parents:
diff changeset
708 ld->u.ns.bindings = hash_table<named_decl_hash>::create_ggc (499);
kono
parents:
diff changeset
709
kono
parents:
diff changeset
710 if (GATHER_STATISTICS)
kono
parents:
diff changeset
711 {
kono
parents:
diff changeset
712 tree_node_counts[(int)lang_decl] += 1;
kono
parents:
diff changeset
713 tree_node_sizes[(int)lang_decl] += size;
kono
parents:
diff changeset
714 }
kono
parents:
diff changeset
715 return true;
kono
parents:
diff changeset
716 }
kono
parents:
diff changeset
717
kono
parents:
diff changeset
718 /* T has just had a decl_lang_specific added. Initialize its
kono
parents:
diff changeset
719 linkage. */
kono
parents:
diff changeset
720
kono
parents:
diff changeset
721 static void
kono
parents:
diff changeset
722 set_decl_linkage (tree t)
kono
parents:
diff changeset
723 {
kono
parents:
diff changeset
724 if (current_lang_name == lang_name_cplusplus
kono
parents:
diff changeset
725 || decl_linkage (t) == lk_none)
kono
parents:
diff changeset
726 SET_DECL_LANGUAGE (t, lang_cplusplus);
kono
parents:
diff changeset
727 else if (current_lang_name == lang_name_c)
kono
parents:
diff changeset
728 SET_DECL_LANGUAGE (t, lang_c);
kono
parents:
diff changeset
729 else
kono
parents:
diff changeset
730 gcc_unreachable ();
kono
parents:
diff changeset
731 }
kono
parents:
diff changeset
732
kono
parents:
diff changeset
733 /* T is a VAR_DECL node that needs to be a decomposition of BASE. */
kono
parents:
diff changeset
734
kono
parents:
diff changeset
735 void
kono
parents:
diff changeset
736 fit_decomposition_lang_decl (tree t, tree base)
kono
parents:
diff changeset
737 {
kono
parents:
diff changeset
738 if (struct lang_decl *orig_ld = DECL_LANG_SPECIFIC (t))
kono
parents:
diff changeset
739 {
kono
parents:
diff changeset
740 if (orig_ld->u.base.selector == lds_min)
kono
parents:
diff changeset
741 {
kono
parents:
diff changeset
742 maybe_add_lang_decl_raw (t, true);
kono
parents:
diff changeset
743 memcpy (DECL_LANG_SPECIFIC (t), orig_ld,
kono
parents:
diff changeset
744 sizeof (struct lang_decl_min));
kono
parents:
diff changeset
745 /* Reset selector, which will have been bashed by the
kono
parents:
diff changeset
746 memcpy. */
kono
parents:
diff changeset
747 DECL_LANG_SPECIFIC (t)->u.base.selector = lds_decomp;
kono
parents:
diff changeset
748 }
kono
parents:
diff changeset
749 else
kono
parents:
diff changeset
750 gcc_checking_assert (orig_ld->u.base.selector == lds_decomp);
kono
parents:
diff changeset
751 }
kono
parents:
diff changeset
752 else
kono
parents:
diff changeset
753 {
kono
parents:
diff changeset
754 maybe_add_lang_decl_raw (t, true);
kono
parents:
diff changeset
755 set_decl_linkage (t);
kono
parents:
diff changeset
756 }
kono
parents:
diff changeset
757
kono
parents:
diff changeset
758 DECL_DECOMP_BASE (t) = base;
kono
parents:
diff changeset
759 }
kono
parents:
diff changeset
760
kono
parents:
diff changeset
761 /* Add DECL_LANG_SPECIFIC info to T, if it needs one. Generally
kono
parents:
diff changeset
762 every C++ decl needs one, but C builtins etc do not. */
kono
parents:
diff changeset
763
kono
parents:
diff changeset
764 void
kono
parents:
diff changeset
765 retrofit_lang_decl (tree t)
kono
parents:
diff changeset
766 {
kono
parents:
diff changeset
767 if (DECL_LANG_SPECIFIC (t))
kono
parents:
diff changeset
768 return;
kono
parents:
diff changeset
769
kono
parents:
diff changeset
770 if (maybe_add_lang_decl_raw (t, false))
kono
parents:
diff changeset
771 set_decl_linkage (t);
kono
parents:
diff changeset
772 }
kono
parents:
diff changeset
773
kono
parents:
diff changeset
774 void
kono
parents:
diff changeset
775 cxx_dup_lang_specific_decl (tree node)
kono
parents:
diff changeset
776 {
kono
parents:
diff changeset
777 int size;
kono
parents:
diff changeset
778
kono
parents:
diff changeset
779 if (! DECL_LANG_SPECIFIC (node))
kono
parents:
diff changeset
780 return;
kono
parents:
diff changeset
781
kono
parents:
diff changeset
782 switch (DECL_LANG_SPECIFIC (node)->u.base.selector)
kono
parents:
diff changeset
783 {
kono
parents:
diff changeset
784 case lds_min:
kono
parents:
diff changeset
785 size = sizeof (struct lang_decl_min);
kono
parents:
diff changeset
786 break;
kono
parents:
diff changeset
787 case lds_fn:
kono
parents:
diff changeset
788 size = sizeof (struct lang_decl_fn);
kono
parents:
diff changeset
789 break;
kono
parents:
diff changeset
790 case lds_ns:
kono
parents:
diff changeset
791 size = sizeof (struct lang_decl_ns);
kono
parents:
diff changeset
792 break;
kono
parents:
diff changeset
793 case lds_parm:
kono
parents:
diff changeset
794 size = sizeof (struct lang_decl_parm);
kono
parents:
diff changeset
795 break;
kono
parents:
diff changeset
796 case lds_decomp:
kono
parents:
diff changeset
797 size = sizeof (struct lang_decl_decomp);
kono
parents:
diff changeset
798 break;
kono
parents:
diff changeset
799 default:
kono
parents:
diff changeset
800 gcc_unreachable ();
kono
parents:
diff changeset
801 }
kono
parents:
diff changeset
802
kono
parents:
diff changeset
803 struct lang_decl *ld = (struct lang_decl *) ggc_internal_alloc (size);
kono
parents:
diff changeset
804 memcpy (ld, DECL_LANG_SPECIFIC (node), size);
kono
parents:
diff changeset
805 DECL_LANG_SPECIFIC (node) = ld;
kono
parents:
diff changeset
806
kono
parents:
diff changeset
807 if (GATHER_STATISTICS)
kono
parents:
diff changeset
808 {
kono
parents:
diff changeset
809 tree_node_counts[(int)lang_decl] += 1;
kono
parents:
diff changeset
810 tree_node_sizes[(int)lang_decl] += size;
kono
parents:
diff changeset
811 }
kono
parents:
diff changeset
812 }
kono
parents:
diff changeset
813
kono
parents:
diff changeset
814 /* Copy DECL, including any language-specific parts. */
kono
parents:
diff changeset
815
kono
parents:
diff changeset
816 tree
kono
parents:
diff changeset
817 copy_decl (tree decl MEM_STAT_DECL)
kono
parents:
diff changeset
818 {
kono
parents:
diff changeset
819 tree copy;
kono
parents:
diff changeset
820
kono
parents:
diff changeset
821 copy = copy_node (decl PASS_MEM_STAT);
kono
parents:
diff changeset
822 cxx_dup_lang_specific_decl (copy);
kono
parents:
diff changeset
823 return copy;
kono
parents:
diff changeset
824 }
kono
parents:
diff changeset
825
kono
parents:
diff changeset
826 /* Replace the shared language-specific parts of NODE with a new copy. */
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 static void
kono
parents:
diff changeset
829 copy_lang_type (tree node)
kono
parents:
diff changeset
830 {
kono
parents:
diff changeset
831 if (! TYPE_LANG_SPECIFIC (node))
kono
parents:
diff changeset
832 return;
kono
parents:
diff changeset
833
kono
parents:
diff changeset
834 struct lang_type *lt
kono
parents:
diff changeset
835 = (struct lang_type *) ggc_internal_alloc (sizeof (struct lang_type));
kono
parents:
diff changeset
836
kono
parents:
diff changeset
837 memcpy (lt, TYPE_LANG_SPECIFIC (node), (sizeof (struct lang_type)));
kono
parents:
diff changeset
838 TYPE_LANG_SPECIFIC (node) = lt;
kono
parents:
diff changeset
839
kono
parents:
diff changeset
840 if (GATHER_STATISTICS)
kono
parents:
diff changeset
841 {
kono
parents:
diff changeset
842 tree_node_counts[(int)lang_type] += 1;
kono
parents:
diff changeset
843 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
kono
parents:
diff changeset
844 }
kono
parents:
diff changeset
845 }
kono
parents:
diff changeset
846
kono
parents:
diff changeset
847 /* Copy TYPE, including any language-specific parts. */
kono
parents:
diff changeset
848
kono
parents:
diff changeset
849 tree
kono
parents:
diff changeset
850 copy_type (tree type MEM_STAT_DECL)
kono
parents:
diff changeset
851 {
kono
parents:
diff changeset
852 tree copy;
kono
parents:
diff changeset
853
kono
parents:
diff changeset
854 copy = copy_node (type PASS_MEM_STAT);
kono
parents:
diff changeset
855 copy_lang_type (copy);
kono
parents:
diff changeset
856 return copy;
kono
parents:
diff changeset
857 }
kono
parents:
diff changeset
858
kono
parents:
diff changeset
859 /* Add a raw lang_type to T, a type, should it need one. */
kono
parents:
diff changeset
860
kono
parents:
diff changeset
861 static bool
kono
parents:
diff changeset
862 maybe_add_lang_type_raw (tree t)
kono
parents:
diff changeset
863 {
kono
parents:
diff changeset
864 if (!RECORD_OR_UNION_CODE_P (TREE_CODE (t)))
kono
parents:
diff changeset
865 return false;
kono
parents:
diff changeset
866
kono
parents:
diff changeset
867 TYPE_LANG_SPECIFIC (t)
kono
parents:
diff changeset
868 = (struct lang_type *) (ggc_internal_cleared_alloc
kono
parents:
diff changeset
869 (sizeof (struct lang_type)));
kono
parents:
diff changeset
870
kono
parents:
diff changeset
871 if (GATHER_STATISTICS)
kono
parents:
diff changeset
872 {
kono
parents:
diff changeset
873 tree_node_counts[(int)lang_type] += 1;
kono
parents:
diff changeset
874 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
kono
parents:
diff changeset
875 }
kono
parents:
diff changeset
876
kono
parents:
diff changeset
877 return true;
kono
parents:
diff changeset
878 }
kono
parents:
diff changeset
879
kono
parents:
diff changeset
880 tree
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
881 cxx_make_type (enum tree_code code MEM_STAT_DECL)
111
kono
parents:
diff changeset
882 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
883 tree t = make_node (code PASS_MEM_STAT);
111
kono
parents:
diff changeset
884
kono
parents:
diff changeset
885 if (maybe_add_lang_type_raw (t))
kono
parents:
diff changeset
886 {
kono
parents:
diff changeset
887 /* Set up some flags that give proper default behavior. */
kono
parents:
diff changeset
888 struct c_fileinfo *finfo =
kono
parents:
diff changeset
889 get_fileinfo (LOCATION_FILE (input_location));
kono
parents:
diff changeset
890 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown);
kono
parents:
diff changeset
891 CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
kono
parents:
diff changeset
892 }
kono
parents:
diff changeset
893
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
894 if (code == RECORD_TYPE || code == UNION_TYPE)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
895 TYPE_CXX_ODR_P (t) = 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
896
111
kono
parents:
diff changeset
897 return t;
kono
parents:
diff changeset
898 }
kono
parents:
diff changeset
899
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
900 /* A wrapper without the memory stats for LANG_HOOKS_MAKE_TYPE. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
901
111
kono
parents:
diff changeset
902 tree
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
903 cxx_make_type_hook (enum tree_code code)
111
kono
parents:
diff changeset
904 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
905 return cxx_make_type (code);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
906 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
907
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
908 tree
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
909 make_class_type (enum tree_code code MEM_STAT_DECL)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
910 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
911 tree t = cxx_make_type (code PASS_MEM_STAT);
111
kono
parents:
diff changeset
912 SET_CLASS_TYPE_P (t, 1);
kono
parents:
diff changeset
913 return t;
kono
parents:
diff changeset
914 }
kono
parents:
diff changeset
915
kono
parents:
diff changeset
916 /* Returns true if we are currently in the main source file, or in a
kono
parents:
diff changeset
917 template instantiation started from the main source file. */
kono
parents:
diff changeset
918
kono
parents:
diff changeset
919 bool
kono
parents:
diff changeset
920 in_main_input_context (void)
kono
parents:
diff changeset
921 {
kono
parents:
diff changeset
922 struct tinst_level *tl = outermost_tinst_level();
kono
parents:
diff changeset
923
kono
parents:
diff changeset
924 if (tl)
kono
parents:
diff changeset
925 return filename_cmp (main_input_filename,
kono
parents:
diff changeset
926 LOCATION_FILE (tl->locus)) == 0;
kono
parents:
diff changeset
927 else
kono
parents:
diff changeset
928 return filename_cmp (main_input_filename, LOCATION_FILE (input_location)) == 0;
kono
parents:
diff changeset
929 }
kono
parents:
diff changeset
930
kono
parents:
diff changeset
931 #include "gt-cp-lex.h"