libstdc++: testsuite: Enhance codecvt_unicode with tests for length()
[official-gcc.git] / libcc1 / libcp1plugin.cc
blob3c8e9e8b436713ea3bf0151f9acb742123d7c0d7
1 /* Library interface to C++ front end.
2 Copyright (C) 2014-2023 Free Software Foundation, Inc.
4 This file is part of GCC. As it interacts with GDB through libcc1,
5 they all become a single program as regards the GNU GPL's requirements.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include <cc1plugin-config.h>
23 #undef PACKAGE_NAME
24 #undef PACKAGE_STRING
25 #undef PACKAGE_TARNAME
26 #undef PACKAGE_VERSION
28 #include "../gcc/config.h"
30 #undef PACKAGE_NAME
31 #undef PACKAGE_STRING
32 #undef PACKAGE_TARNAME
33 #undef PACKAGE_VERSION
35 #define INCLUDE_MEMORY
36 #include "gcc-plugin.h"
37 #include "system.h"
38 #include "coretypes.h"
39 #include "stringpool.h"
41 #include "gcc-interface.h"
42 #include "machmode.h"
43 #include "vec.h"
44 #include "double-int.h"
45 #include "input.h"
46 #include "alias.h"
47 #include "symtab.h"
48 #include "options.h"
49 #include "wide-int.h"
50 #include "inchash.h"
51 #include "tree.h"
52 #include "fold-const.h"
53 #include "stor-layout.h"
54 #include "cp-tree.h"
55 #include "toplev.h"
56 #include "timevar.h"
57 #include "hash-table.h"
58 #include "tm.h"
59 #include "c-family/c-pragma.h"
60 // #include "c-lang.h"
61 #include "diagnostic.h"
62 #include "langhooks.h"
63 #include "langhooks-def.h"
64 #include "decl.h"
65 #include "function.h"
66 #undef cfun // we want to assign to it, and function.h won't let us
68 #include "callbacks.hh"
69 #include "connection.hh"
70 #include "marshall-cp.hh"
71 #include "rpc.hh"
72 #include "context.hh"
74 #include <vector>
76 using namespace cc1_plugin;
80 static_assert (GCC_CP_SYMBOL_MASK >= GCC_CP_SYMBOL_END,
81 "GCC_CP_SYMBOL_MASK >= GCC_CP_SYMBOL_END");
85 static void
86 plugin_binding_oracle (enum cp_oracle_request kind, tree identifier)
88 enum gcc_cp_oracle_request request;
90 gcc_assert (current_context != NULL);
92 switch (kind)
94 case CP_ORACLE_IDENTIFIER:
95 request = GCC_CP_ORACLE_IDENTIFIER;
96 break;
97 default:
98 abort ();
101 int ignore;
102 cc1_plugin::call (current_context, "binding_oracle", &ignore,
103 request, IDENTIFIER_POINTER (identifier));
106 static int push_count;
108 /* at_function_scope_p () tests cfun, indicating we're actually
109 compiling the function, but we don't even set it when pretending to
110 enter a function scope. We use this distinction to tell these two
111 cases apart: we don't want to define e.g. class names in the user
112 expression function's scope, when they're local to the original
113 function, because they'd get the wrong linkage name. */
115 static bool
116 at_fake_function_scope_p ()
118 return (!cfun || cfun->decl != current_function_decl)
119 && current_scope () == current_function_decl;
122 static void
123 push_fake_function (tree fndecl, scope_kind kind = sk_function_parms)
125 current_function_decl = fndecl;
126 begin_scope (kind, fndecl);
127 ++function_depth;
128 begin_scope (sk_block, NULL);
131 static void
132 pop_scope ()
134 if (toplevel_bindings_p () && current_namespace == global_namespace)
135 pop_from_top_level ();
136 else if (at_namespace_scope_p ())
137 pop_namespace ();
138 else if (at_class_scope_p ())
139 popclass ();
140 else
142 gcc_assert (at_fake_function_scope_p ());
143 gcc_assert (!at_function_scope_p ());
144 gcc_assert (current_binding_level->kind == sk_block
145 && current_binding_level->this_entity == NULL);
146 leave_scope ();
147 --function_depth;
148 gcc_assert (current_binding_level->this_entity
149 == current_function_decl);
150 leave_scope ();
151 current_function_decl = NULL;
152 for (cp_binding_level *scope = current_binding_level;
153 scope; scope = scope->level_chain)
154 if (scope->kind == sk_function_parms)
156 current_function_decl = scope->this_entity;
157 break;
162 static void
163 supplement_binding (cxx_binding *binding, tree decl)
165 /* FIXME: this is pretty much a copy of supplement_binding_1 in
166 ../gcc/cp/name-lookup.c; the few replaced/removed bits are marked
167 with "// _1:". */
168 tree bval = binding->value;
169 bool ok = true;
170 tree target_bval = strip_using_decl (bval);
171 tree target_decl = strip_using_decl (decl);
173 if (TREE_CODE (target_decl) == TYPE_DECL && DECL_ARTIFICIAL (target_decl)
174 && target_decl != target_bval
175 && (TREE_CODE (target_bval) != TYPE_DECL
176 /* We allow pushing an enum multiple times in a class
177 template in order to handle late matching of underlying
178 type on an opaque-enum-declaration followed by an
179 enum-specifier. */
180 || (processing_template_decl
181 && TREE_CODE (TREE_TYPE (target_decl)) == ENUMERAL_TYPE
182 && TREE_CODE (TREE_TYPE (target_bval)) == ENUMERAL_TYPE
183 && (dependent_type_p (ENUM_UNDERLYING_TYPE
184 (TREE_TYPE (target_decl)))
185 || dependent_type_p (ENUM_UNDERLYING_TYPE
186 (TREE_TYPE (target_bval)))))))
187 /* The new name is the type name. */
188 binding->type = decl;
189 else if (/* TARGET_BVAL is null when push_class_level_binding moves
190 an inherited type-binding out of the way to make room
191 for a new value binding. */
192 !target_bval
193 /* TARGET_BVAL is error_mark_node when TARGET_DECL's name
194 has been used in a non-class scope prior declaration.
195 In that case, we should have already issued a
196 diagnostic; for graceful error recovery purpose, pretend
197 this was the intended declaration for that name. */
198 || target_bval == error_mark_node
199 /* If TARGET_BVAL is anticipated but has not yet been
200 declared, pretend it is not there at all. */
201 || (TREE_CODE (target_bval) == FUNCTION_DECL
202 && DECL_IS_UNDECLARED_BUILTIN (target_bval)))
203 binding->value = decl;
204 else if (TREE_CODE (target_bval) == TYPE_DECL
205 && DECL_ARTIFICIAL (target_bval)
206 && target_decl != target_bval
207 && (TREE_CODE (target_decl) != TYPE_DECL
208 || same_type_p (TREE_TYPE (target_decl),
209 TREE_TYPE (target_bval))))
211 /* The old binding was a type name. It was placed in
212 VALUE field because it was thought, at the point it was
213 declared, to be the only entity with such a name. Move the
214 type name into the type slot; it is now hidden by the new
215 binding. */
216 binding->type = bval;
217 binding->value = decl;
218 binding->value_is_inherited = false;
220 else if (TREE_CODE (target_bval) == TYPE_DECL
221 && TREE_CODE (target_decl) == TYPE_DECL
222 && DECL_NAME (target_decl) == DECL_NAME (target_bval)
223 && binding->scope->kind != sk_class
224 && (same_type_p (TREE_TYPE (target_decl), TREE_TYPE (target_bval))
225 /* If either type involves template parameters, we must
226 wait until instantiation. */
227 || uses_template_parms (TREE_TYPE (target_decl))
228 || uses_template_parms (TREE_TYPE (target_bval))))
229 /* We have two typedef-names, both naming the same type to have
230 the same name. In general, this is OK because of:
232 [dcl.typedef]
234 In a given scope, a typedef specifier can be used to redefine
235 the name of any type declared in that scope to refer to the
236 type to which it already refers.
238 However, in class scopes, this rule does not apply due to the
239 stricter language in [class.mem] prohibiting redeclarations of
240 members. */
241 ok = false;
242 /* There can be two block-scope declarations of the same variable,
243 so long as they are `extern' declarations. However, there cannot
244 be two declarations of the same static data member:
246 [class.mem]
248 A member shall not be declared twice in the
249 member-specification. */
250 else if (VAR_P (target_decl)
251 && VAR_P (target_bval)
252 && DECL_EXTERNAL (target_decl) && DECL_EXTERNAL (target_bval)
253 && !DECL_CLASS_SCOPE_P (target_decl))
255 duplicate_decls (decl, binding->value);
256 ok = false;
258 else if (TREE_CODE (decl) == NAMESPACE_DECL
259 && TREE_CODE (bval) == NAMESPACE_DECL
260 && DECL_NAMESPACE_ALIAS (decl)
261 && DECL_NAMESPACE_ALIAS (bval)
262 && ORIGINAL_NAMESPACE (bval) == ORIGINAL_NAMESPACE (decl))
263 /* [namespace.alias]
265 In a declarative region, a namespace-alias-definition can be
266 used to redefine a namespace-alias declared in that declarative
267 region to refer only to the namespace to which it already
268 refers. */
269 ok = false;
270 else
272 // _1: diagnose_name_conflict (decl, bval);
273 ok = false;
276 gcc_assert (ok); // _1: return ok;
279 static void
280 reactivate_decl (tree decl, cp_binding_level *b)
282 bool in_function_p = TREE_CODE (b->this_entity) == FUNCTION_DECL;
283 gcc_assert (in_function_p
284 || (b == current_binding_level
285 && !at_class_scope_p ()));
287 tree id = DECL_NAME (decl);
288 tree type = NULL_TREE;
289 if (TREE_CODE (decl) == TYPE_DECL)
290 type = TREE_TYPE (decl);
292 if (type && TYPE_NAME (type) == decl
293 && (RECORD_OR_UNION_CODE_P (TREE_CODE (type))
294 || TREE_CODE (type) == ENUMERAL_TYPE))
296 gcc_assert (in_function_p && DECL_CONTEXT (decl) == b->this_entity);
297 type = TREE_TYPE (decl);
299 else
301 gcc_assert (DECL_CONTEXT (decl) == b->this_entity
302 || DECL_CONTEXT (decl) == global_namespace
303 || TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL);
304 type = NULL_TREE;
307 /* Adjust IDENTIFIER_BINDING to what it would have been if we were
308 at binding level B. Save the binding chain up to that point in
309 [binding, *chainp), and take note of the outermost bindings found
310 before B. */
311 cxx_binding *binding = IDENTIFIER_BINDING (id), **chainp = NULL;
312 tree *shadowing_type_p = NULL;
313 if (binding)
315 cp_binding_level *bc = current_binding_level;
316 for (cxx_binding *prev_binding = binding;
317 prev_binding; prev_binding = prev_binding->previous)
319 while (bc != b && bc != prev_binding->scope)
320 bc = bc->level_chain;
321 if (bc == b)
323 if (!chainp)
324 binding = NULL;
325 break;
327 chainp = &prev_binding->previous;
328 if (type)
329 for (tree tshadow = prev_binding->scope->type_shadowed;
330 tshadow; tshadow = TREE_CHAIN (tshadow))
331 if (TREE_PURPOSE (tshadow) == id)
333 shadowing_type_p = &TREE_VALUE (tshadow);
334 break;
338 if (chainp)
340 IDENTIFIER_BINDING (id) = *chainp;
341 *chainp = NULL;
344 /* Like push_local_binding, supplement or add a binding to the
345 desired level. */
346 if (IDENTIFIER_BINDING (id) && IDENTIFIER_BINDING (id)->scope == b)
347 supplement_binding (IDENTIFIER_BINDING (id), decl);
348 else
349 push_binding (id, decl, b);
351 /* Now restore the binding chain we'd temporarily removed. */
352 if (chainp)
354 *chainp = IDENTIFIER_BINDING (id);
355 IDENTIFIER_BINDING (id) = binding;
357 if (type)
359 /* Insert the new type binding in the shadowing_type_p
360 TREE_VALUE chain. */
361 tree shadowed_type = NULL_TREE;
362 if (shadowing_type_p)
364 shadowed_type = *shadowing_type_p;
365 *shadowing_type_p = type;
368 b->type_shadowed = tree_cons (id, shadowed_type, b->type_shadowed);
369 TREE_TYPE (b->type_shadowed) = type;
372 else if (type)
374 /* Our new binding is the active one, so shadow the earlier
375 binding. */
376 b->type_shadowed = tree_cons (id, REAL_IDENTIFIER_TYPE_VALUE (id),
377 b->type_shadowed);
378 TREE_TYPE (b->type_shadowed) = type;
379 SET_IDENTIFIER_TYPE_VALUE (id, type);
382 /* Record that we have a binding for ID, like add_decl_to_level. */
383 tree node = build_tree_list (NULL_TREE, decl);
384 TREE_CHAIN (node) = b->names;
385 b->names = node;
388 static void
389 plugin_pragma_push_user_expression (cpp_reader *)
391 if (push_count++)
392 return;
394 gcc_assert (!current_class_ptr);
395 gcc_assert (!current_class_ref);
397 gcc_assert (!cp_binding_oracle);
398 cp_binding_oracle = plugin_binding_oracle;
400 /* Make the function containing the user expression a global
401 friend, so as to bypass access controls in it. */
402 if (at_function_scope_p ())
403 set_global_friend (current_function_decl);
405 gcc_assert (at_function_scope_p ());
406 function *save_cfun = cfun;
407 cp_binding_level *orig_binding_level = current_binding_level;
409 int success;
410 cc1_plugin::call (current_context, "enter_scope", &success);
412 gcc_assert (at_fake_function_scope_p () || at_function_scope_p ());
414 function *unchanged_cfun = cfun;
415 tree changed_func_decl = current_function_decl;
417 gcc_assert (current_class_type == DECL_CONTEXT (current_function_decl)
418 || !(RECORD_OR_UNION_CODE_P
419 (TREE_CODE (DECL_CONTEXT (current_function_decl)))));
420 push_fake_function (save_cfun->decl, sk_block);
421 current_class_type = NULL_TREE;
422 if (unchanged_cfun)
424 /* If we get here, GDB did NOT change the context. */
425 gcc_assert (cfun == save_cfun);
426 gcc_assert (at_function_scope_p ());
427 gcc_assert (orig_binding_level
428 == current_binding_level->level_chain->level_chain);
430 else
432 cfun = save_cfun;
433 gcc_assert (at_function_scope_p ());
435 cp_binding_level *b = current_binding_level->level_chain;
436 gcc_assert (b->this_entity == cfun->decl);
438 /* Reactivate local names from the previous context. Use
439 IDENTIFIER_MARKED to avoid reactivating shadowed names. */
440 for (cp_binding_level *level = orig_binding_level;;)
442 for (tree name = level->names;
443 name; name = TREE_CHAIN (name))
445 tree decl = name;
446 if (TREE_CODE (decl) == TREE_LIST)
447 decl = TREE_VALUE (decl);
448 if (IDENTIFIER_MARKED (DECL_NAME (decl)))
449 continue;
450 IDENTIFIER_MARKED (DECL_NAME (decl)) = 1;
451 reactivate_decl (decl, b);
453 if (level->kind == sk_function_parms
454 && level->this_entity == cfun->decl)
455 break;
456 gcc_assert (!level->this_entity);
457 level = level->level_chain;
460 /* Now, clear the markers. */
461 for (tree name = b->names; name; name = TREE_CHAIN (name))
463 tree decl = name;
464 if (TREE_CODE (decl) == TREE_LIST)
465 decl = TREE_VALUE (decl);
466 gcc_assert (IDENTIFIER_MARKED (DECL_NAME (decl)));
467 IDENTIFIER_MARKED (DECL_NAME (decl)) = 0;
471 if (unchanged_cfun || DECL_NONSTATIC_MEMBER_FUNCTION_P (changed_func_decl))
473 /* Check whether the oracle supplies us with a "this", and if
474 so, arrange for data members and this itself to be
475 usable. */
476 tree this_val = lookup_name (get_identifier ("this"));
477 current_class_ref = !this_val ? NULL_TREE
478 : cp_build_indirect_ref (input_location, this_val, RO_NULL,
479 tf_warning_or_error);
480 current_class_ptr = this_val;
484 static void
485 plugin_pragma_pop_user_expression (cpp_reader *)
487 if (--push_count)
488 return;
490 gcc_assert (cp_binding_oracle);
492 gcc_assert (at_function_scope_p ());
493 function *save_cfun = cfun;
494 current_class_ptr = NULL_TREE;
495 current_class_ref = NULL_TREE;
497 cfun = NULL;
498 pop_scope ();
499 if (RECORD_OR_UNION_CODE_P (TREE_CODE (DECL_CONTEXT (current_function_decl))))
500 current_class_type = DECL_CONTEXT (current_function_decl);
502 int success;
503 cc1_plugin::call (current_context, "leave_scope", &success);
505 if (!cfun)
506 cfun = save_cfun;
507 else
508 gcc_assert (cfun == save_cfun);
510 cp_binding_oracle = NULL;
511 gcc_assert (at_function_scope_p ());
514 static void
515 plugin_init_extra_pragmas (void *, void *)
517 c_register_pragma ("GCC", "push_user_expression", plugin_pragma_push_user_expression);
518 c_register_pragma ("GCC", "pop_user_expression", plugin_pragma_pop_user_expression);
519 /* FIXME: this one should go once we get GDB to use push and pop. */
520 c_register_pragma ("GCC", "user_expression", plugin_pragma_push_user_expression);
525 static decl_addr_value
526 build_decl_addr_value (tree decl, gcc_address address)
528 decl_addr_value value = {
529 decl,
530 build_int_cst_type (ptr_type_node, address)
532 return value;
535 static decl_addr_value *
536 record_decl_address (plugin_context *ctx, decl_addr_value value)
538 decl_addr_value **slot = ctx->address_map.find_slot (&value, INSERT);
539 gcc_assert (*slot == NULL);
540 *slot
541 = static_cast<decl_addr_value *> (xmalloc (sizeof (decl_addr_value)));
542 **slot = value;
543 /* We don't want GCC to warn about e.g. static functions
544 without a code definition. */
545 suppress_warning (value.decl);
546 return *slot;
549 // Maybe rewrite a decl to its address.
550 static tree
551 address_rewriter (tree *in, int *walk_subtrees, void *arg)
553 plugin_context *ctx = (plugin_context *) arg;
555 if (!DECL_P (*in)
556 || TREE_CODE (*in) == NAMESPACE_DECL
557 || DECL_NAME (*in) == NULL_TREE)
558 return NULL_TREE;
560 decl_addr_value value;
561 value.decl = *in;
562 decl_addr_value *found_value = ctx->address_map.find (&value);
563 if (found_value != NULL)
565 else if (HAS_DECL_ASSEMBLER_NAME_P (*in))
567 gcc_address address;
569 if (!cc1_plugin::call (ctx, "address_oracle", &address,
570 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (*in))))
571 return NULL_TREE;
572 if (address == 0)
573 return NULL_TREE;
575 // Insert the decl into the address map in case it is referenced
576 // again.
577 value = build_decl_addr_value (value.decl, address);
578 found_value = record_decl_address (ctx, value);
580 else
581 return NULL_TREE;
583 if (found_value->address != error_mark_node)
585 // We have an address for the decl, so rewrite the tree.
586 tree ptr_type = build_pointer_type (TREE_TYPE (*in));
587 *in = fold_build1 (INDIRECT_REF, TREE_TYPE (*in),
588 fold_build1 (CONVERT_EXPR, ptr_type,
589 found_value->address));
592 *walk_subtrees = 0;
594 return NULL_TREE;
597 // When generating code for gdb, we want to be able to use absolute
598 // addresses to refer to otherwise external objects that gdb knows
599 // about. gdb passes in these addresses when building decls, and then
600 // before gimplification we go through the trees, rewriting uses to
601 // the equivalent of "*(TYPE *) ADDR".
602 static void
603 rewrite_decls_to_addresses (void *function_in, void *)
605 tree function = (tree) function_in;
607 // Do nothing if we're not in gdb.
608 if (current_context == NULL)
609 return;
611 walk_tree (&DECL_SAVED_TREE (function), address_rewriter, current_context,
612 NULL);
617 static inline tree
618 safe_push_template_decl (tree decl)
620 void (*save_oracle) (enum cp_oracle_request, tree identifier);
622 save_oracle = cp_binding_oracle;
623 cp_binding_oracle = NULL;
625 tree ret = push_template_decl (decl);
627 cp_binding_oracle = save_oracle;
629 return ret;
632 static inline tree
633 safe_pushtag (tree name, tree type)
635 void (*save_oracle) (enum cp_oracle_request, tree identifier);
637 save_oracle = cp_binding_oracle;
638 cp_binding_oracle = NULL;
640 tree ret = pushtag (name, type);
642 cp_binding_oracle = save_oracle;
644 return ret;
647 static inline tree
648 safe_pushdecl (tree decl)
650 void (*save_oracle) (enum cp_oracle_request, tree identifier);
652 save_oracle = cp_binding_oracle;
653 cp_binding_oracle = NULL;
655 tree ret = pushdecl (decl);
657 cp_binding_oracle = save_oracle;
659 return ret;
665 plugin_push_namespace (cc1_plugin::connection *,
666 const char *name)
668 if (name && !*name)
669 push_to_top_level ();
670 else
671 push_namespace (name ? get_identifier (name) : NULL);
673 return 1;
677 plugin_push_class (cc1_plugin::connection *,
678 gcc_type type_in)
680 tree type = convert_in (type_in);
681 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (type)));
682 gcc_assert (TYPE_CONTEXT (type) == FROB_CONTEXT (current_scope ()));
684 pushclass (type);
686 return 1;
690 plugin_push_function (cc1_plugin::connection *,
691 gcc_decl function_decl_in)
693 tree fndecl = convert_in (function_decl_in);
694 gcc_assert (TREE_CODE (fndecl) == FUNCTION_DECL);
695 gcc_assert (DECL_CONTEXT (fndecl) == FROB_CONTEXT (current_scope ()));
697 push_fake_function (fndecl);
699 return 1;
703 plugin_pop_binding_level (cc1_plugin::connection *)
705 pop_scope ();
706 return 1;
710 plugin_reactivate_decl (cc1_plugin::connection *,
711 gcc_decl decl_in,
712 gcc_decl scope_in)
714 tree decl = convert_in (decl_in);
715 tree scope = convert_in (scope_in);
716 gcc_assert (VAR_P (decl)
717 || TREE_CODE (decl) == FUNCTION_DECL
718 || TREE_CODE (decl) == TYPE_DECL);
719 cp_binding_level *b;
720 if (scope)
722 gcc_assert (TREE_CODE (scope) == FUNCTION_DECL);
723 for (b = current_binding_level;
724 b->this_entity != scope;
725 b = b->level_chain)
726 gcc_assert (b->this_entity != global_namespace);
728 else
730 gcc_assert (!at_class_scope_p ());
731 b = current_binding_level;
734 reactivate_decl (decl, b);
735 return 1;
738 static tree
739 get_current_scope ()
741 tree decl;
743 if (at_namespace_scope_p ())
744 decl = current_namespace;
745 else if (at_class_scope_p ())
746 decl = TYPE_NAME (current_class_type);
747 else if (at_fake_function_scope_p () || at_function_scope_p ())
748 decl = current_function_decl;
749 else
750 gcc_unreachable ();
752 return decl;
755 gcc_decl
756 plugin_get_current_binding_level_decl (cc1_plugin::connection *)
758 tree decl = get_current_scope ();
760 return convert_out (decl);
764 plugin_make_namespace_inline (cc1_plugin::connection *)
766 tree inline_ns = current_namespace;
768 gcc_assert (toplevel_bindings_p ());
769 gcc_assert (inline_ns != global_namespace);
771 tree parent_ns = CP_DECL_CONTEXT (inline_ns);
773 if (DECL_NAMESPACE_INLINE_P (inline_ns))
774 return 0;
776 DECL_NAMESPACE_INLINE_P (inline_ns) = true;
777 vec_safe_push (DECL_NAMESPACE_INLINEES (parent_ns), inline_ns);
779 return 1;
783 plugin_add_using_namespace (cc1_plugin::connection *,
784 gcc_decl used_ns_in)
786 tree used_ns = convert_in (used_ns_in);
788 gcc_assert (TREE_CODE (used_ns) == NAMESPACE_DECL);
790 finish_using_directive (used_ns, NULL_TREE);
792 return 1;
796 plugin_add_namespace_alias (cc1_plugin::connection *,
797 const char *id,
798 gcc_decl target_in)
800 tree name = get_identifier (id);
801 tree target = convert_in (target_in);
803 do_namespace_alias (name, target);
805 return 1;
808 static inline void
809 set_access_flags (tree decl, enum gcc_cp_symbol_kind flags)
811 gcc_assert (!(flags & GCC_CP_ACCESS_MASK) == !DECL_CLASS_SCOPE_P (decl));
813 switch (flags & GCC_CP_ACCESS_MASK)
815 case GCC_CP_ACCESS_PRIVATE:
816 TREE_PRIVATE (decl) = true;
817 current_access_specifier = access_private_node;
818 break;
820 case GCC_CP_ACCESS_PROTECTED:
821 TREE_PROTECTED (decl) = true;
822 current_access_specifier = access_protected_node;
823 break;
825 case GCC_CP_ACCESS_PUBLIC:
826 current_access_specifier = access_public_node;
827 break;
829 default:
830 break;
835 plugin_add_using_decl (cc1_plugin::connection *,
836 enum gcc_cp_symbol_kind flags,
837 gcc_decl target_in)
839 tree target = convert_in (target_in);
840 gcc_assert ((flags & GCC_CP_SYMBOL_MASK) == GCC_CP_SYMBOL_USING);
841 gcc_assert (!(flags & GCC_CP_FLAG_MASK));
842 enum gcc_cp_symbol_kind acc_flags;
843 acc_flags = (enum gcc_cp_symbol_kind) (flags & GCC_CP_ACCESS_MASK);
845 gcc_assert (!template_parm_scope_p ());
847 bool class_member_p = at_class_scope_p ();
848 gcc_assert (!(acc_flags & GCC_CP_ACCESS_MASK) == !class_member_p);
850 tree identifier = DECL_NAME (target);
851 tree tcontext = DECL_CONTEXT (target);
853 if (UNSCOPED_ENUM_P (tcontext))
854 tcontext = CP_TYPE_CONTEXT (tcontext);
856 if (class_member_p)
858 tree decl = do_class_using_decl (tcontext, identifier);
860 set_access_flags (decl, flags);
862 finish_member_declaration (decl);
864 else
866 /* We can't be at local scope. */
867 gcc_assert (at_namespace_scope_p ());
868 finish_nonmember_using_decl (tcontext, identifier);
871 return 1;
874 static tree
875 build_named_class_type (enum tree_code code,
876 tree id,
877 location_t loc)
879 /* See at_fake_function_scope_p. */
880 gcc_assert (!at_function_scope_p ());
881 tree type = make_class_type (code);
882 tree type_decl = build_decl (loc, TYPE_DECL, id, type);
883 TYPE_NAME (type) = type_decl;
884 TYPE_STUB_DECL (type) = type_decl;
885 DECL_CONTEXT (type_decl) = TYPE_CONTEXT (type);
887 return type_decl;
890 /* Abuse an unused field of the dummy template parms entry to hold the
891 parm list. */
892 #define TP_PARM_LIST TREE_TYPE (current_template_parms)
894 gcc_decl
895 plugin_build_decl (cc1_plugin::connection *self,
896 const char *name,
897 enum gcc_cp_symbol_kind sym_kind,
898 gcc_type sym_type_in,
899 const char *substitution_name,
900 gcc_address address,
901 const char *filename,
902 unsigned int line_number)
904 plugin_context *ctx = static_cast<plugin_context *> (self);
905 gcc_assert (!name || !strchr (name, ':')); // FIXME: this can go eventually.
907 enum tree_code code;
908 tree decl;
909 tree sym_type = convert_in (sym_type_in);
910 enum gcc_cp_symbol_kind sym_flags;
911 sym_flags = (enum gcc_cp_symbol_kind) (sym_kind & GCC_CP_FLAG_MASK);
912 enum gcc_cp_symbol_kind acc_flags;
913 acc_flags = (enum gcc_cp_symbol_kind) (sym_kind & GCC_CP_ACCESS_MASK);
914 sym_kind = (enum gcc_cp_symbol_kind) (sym_kind & GCC_CP_SYMBOL_MASK);
916 switch (sym_kind)
918 case GCC_CP_SYMBOL_FUNCTION:
919 code = FUNCTION_DECL;
920 gcc_assert (!(sym_flags & ~GCC_CP_FLAG_MASK_FUNCTION));
921 break;
923 case GCC_CP_SYMBOL_VARIABLE:
924 code = VAR_DECL;
925 gcc_assert (!(sym_flags & ~GCC_CP_FLAG_MASK_VARIABLE));
926 break;
928 case GCC_CP_SYMBOL_TYPEDEF:
929 code = TYPE_DECL;
930 gcc_assert (!sym_flags);
931 break;
933 case GCC_CP_SYMBOL_CLASS:
934 code = RECORD_TYPE;
935 gcc_assert (!(sym_flags & ~GCC_CP_FLAG_MASK_CLASS));
936 gcc_assert (!sym_type);
937 break;
939 case GCC_CP_SYMBOL_UNION:
940 code = UNION_TYPE;
941 gcc_assert (!sym_flags);
942 gcc_assert (!sym_type);
943 break;
945 default:
946 gcc_unreachable ();
949 bool template_decl_p = template_parm_scope_p ();
951 if (template_decl_p)
953 gcc_assert (code == FUNCTION_DECL || code == RECORD_TYPE
954 || code == TYPE_DECL);
956 /* Finish the template parm list that started this template parm. */
957 end_template_parm_list (TP_PARM_LIST);
959 gcc_assert (!address);
960 gcc_assert (!substitution_name);
963 location_t loc = ctx->get_location_t (filename, line_number);
964 bool class_member_p = at_class_scope_p ();
965 bool ctor = false, dtor = false, assop = false;
966 tree_code opcode = ERROR_MARK;
968 gcc_assert (!(acc_flags & GCC_CP_ACCESS_MASK) == !class_member_p);
970 tree identifier;
971 if (code != FUNCTION_DECL
972 || !(sym_flags & GCC_CP_FLAG_SPECIAL_FUNCTION))
974 if (name)
975 identifier = get_identifier (name);
976 else
978 gcc_assert (RECORD_OR_UNION_CODE_P (code));
979 identifier = make_anon_name ();
983 if (code == FUNCTION_DECL)
985 if (sym_flags & GCC_CP_FLAG_SPECIAL_FUNCTION)
987 #define CHARS2(f,s) (((unsigned char)f << CHAR_BIT) | (unsigned char)s)
988 switch (CHARS2 (name[0], name[1]))
990 case CHARS2 ('C', 0x0): // ctor base declaration
991 case CHARS2 ('C', ' '):
992 case CHARS2 ('C', '1'):
993 case CHARS2 ('C', '2'):
994 case CHARS2 ('C', '4'):
995 ctor = true;
996 cdtor:
997 gcc_assert (!address);
998 gcc_assert (!substitution_name);
999 identifier = DECL_NAME (TYPE_NAME (current_class_type));
1000 break;
1001 case CHARS2 ('D', 0x0): // dtor base declaration
1002 case CHARS2 ('D', ' '):
1003 case CHARS2 ('D', '0'):
1004 case CHARS2 ('D', '1'):
1005 case CHARS2 ('D', '2'):
1006 case CHARS2 ('D', '4'):
1007 gcc_assert (!template_decl_p);
1008 dtor = true;
1009 goto cdtor;
1010 case CHARS2 ('n', 'w'): // operator new
1011 opcode = NEW_EXPR;
1012 break;
1013 case CHARS2 ('n', 'a'): // operator new[]
1014 opcode = VEC_NEW_EXPR;
1015 break;
1016 case CHARS2 ('d', 'l'): // operator delete
1017 opcode = DELETE_EXPR;
1018 break;
1019 case CHARS2 ('d', 'a'): // operator delete[]
1020 opcode = VEC_DELETE_EXPR;
1021 break;
1022 case CHARS2 ('p', 's'): // operator + (unary)
1023 opcode = PLUS_EXPR;
1024 break;
1025 case CHARS2 ('n', 'g'): // operator - (unary)
1026 opcode = MINUS_EXPR;
1027 break;
1028 case CHARS2 ('a', 'd'): // operator & (unary)
1029 opcode = BIT_AND_EXPR;
1030 break;
1031 case CHARS2 ('d', 'e'): // operator * (unary)
1032 opcode = MULT_EXPR;
1033 break;
1034 case CHARS2 ('c', 'o'): // operator ~
1035 opcode = BIT_NOT_EXPR;
1036 break;
1037 case CHARS2 ('p', 'l'): // operator +
1038 opcode = PLUS_EXPR;
1039 break;
1040 case CHARS2 ('m', 'i'): // operator -
1041 opcode = MINUS_EXPR;
1042 break;
1043 case CHARS2 ('m', 'l'): // operator *
1044 opcode = MULT_EXPR;
1045 break;
1046 case CHARS2 ('d', 'v'): // operator /
1047 opcode = TRUNC_DIV_EXPR;
1048 break;
1049 case CHARS2 ('r', 'm'): // operator %
1050 opcode = TRUNC_MOD_EXPR;
1051 break;
1052 case CHARS2 ('a', 'n'): // operator &
1053 opcode = BIT_AND_EXPR;
1054 break;
1055 case CHARS2 ('o', 'r'): // operator |
1056 opcode = BIT_IOR_EXPR;
1057 break;
1058 case CHARS2 ('e', 'o'): // operator ^
1059 opcode = BIT_XOR_EXPR;
1060 break;
1061 case CHARS2 ('a', 'S'): // operator =
1062 opcode = NOP_EXPR;
1063 assop = true;
1064 break;
1065 case CHARS2 ('p', 'L'): // operator +=
1066 opcode = PLUS_EXPR;
1067 assop = true;
1068 break;
1069 case CHARS2 ('m', 'I'): // operator -=
1070 opcode = MINUS_EXPR;
1071 assop = true;
1072 break;
1073 case CHARS2 ('m', 'L'): // operator *=
1074 opcode = MULT_EXPR;
1075 assop = true;
1076 break;
1077 case CHARS2 ('d', 'V'): // operator /=
1078 opcode = TRUNC_DIV_EXPR;
1079 assop = true;
1080 break;
1081 case CHARS2 ('r', 'M'): // operator %=
1082 opcode = TRUNC_MOD_EXPR;
1083 assop = true;
1084 break;
1085 case CHARS2 ('a', 'N'): // operator &=
1086 opcode = BIT_AND_EXPR;
1087 assop = true;
1088 break;
1089 case CHARS2 ('o', 'R'): // operator |=
1090 opcode = BIT_IOR_EXPR;
1091 assop = true;
1092 break;
1093 case CHARS2 ('e', 'O'): // operator ^=
1094 opcode = BIT_XOR_EXPR;
1095 assop = true;
1096 break;
1097 case CHARS2 ('l', 's'): // operator <<
1098 opcode = LSHIFT_EXPR;
1099 break;
1100 case CHARS2 ('r', 's'): // operator >>
1101 opcode = RSHIFT_EXPR;
1102 break;
1103 case CHARS2 ('l', 'S'): // operator <<=
1104 opcode = LSHIFT_EXPR;
1105 assop = true;
1106 break;
1107 case CHARS2 ('r', 'S'): // operator >>=
1108 opcode = RSHIFT_EXPR;
1109 assop = true;
1110 break;
1111 case CHARS2 ('e', 'q'): // operator ==
1112 opcode = EQ_EXPR;
1113 break;
1114 case CHARS2 ('n', 'e'): // operator !=
1115 opcode = NE_EXPR;
1116 break;
1117 case CHARS2 ('l', 't'): // operator <
1118 opcode = LT_EXPR;
1119 break;
1120 case CHARS2 ('g', 't'): // operator >
1121 opcode = GT_EXPR;
1122 break;
1123 case CHARS2 ('l', 'e'): // operator <=
1124 opcode = LE_EXPR;
1125 break;
1126 case CHARS2 ('g', 'e'): // operator >=
1127 opcode = GE_EXPR;
1128 break;
1129 case CHARS2 ('n', 't'): // operator !
1130 opcode = TRUTH_NOT_EXPR;
1131 break;
1132 case CHARS2 ('a', 'a'): // operator &&
1133 opcode = TRUTH_ANDIF_EXPR;
1134 break;
1135 case CHARS2 ('o', 'o'): // operator ||
1136 opcode = TRUTH_ORIF_EXPR;
1137 break;
1138 case CHARS2 ('p', 'p'): // operator ++
1139 opcode = POSTINCREMENT_EXPR;
1140 break;
1141 case CHARS2 ('m', 'm'): // operator --
1142 /* This stands for either one as an operator name, and
1143 "pp" and "mm" stand for POST??CREMENT, but for some
1144 reason the parser uses this opcode name for
1145 operator--; let's follow their practice. */
1146 opcode = PREDECREMENT_EXPR;
1147 break;
1148 case CHARS2 ('c', 'm'): // operator ,
1149 opcode = COMPOUND_EXPR;
1150 break;
1151 case CHARS2 ('p', 'm'): // operator ->*
1152 opcode = MEMBER_REF;
1153 break;
1154 case CHARS2 ('p', 't'): // operator ->
1155 opcode = COMPONENT_REF;
1156 break;
1157 case CHARS2 ('c', 'l'): // operator ()
1158 opcode = CALL_EXPR;
1159 break;
1160 case CHARS2 ('i', 'x'): // operator []
1161 opcode = ARRAY_REF;
1162 break;
1163 case CHARS2 ('c', 'v'): // operator <T> (conversion operator)
1164 identifier = make_conv_op_name (TREE_TYPE (sym_type));
1165 break;
1166 // C++11-only:
1167 case CHARS2 ('l', 'i'): // operator "" <id>
1169 char *id = (char *)name + 2;
1170 bool freeid = false;
1171 if (*id >= '0' && *id <= '9')
1173 unsigned len = 0;
1176 len *= 10;
1177 len += id[0] - '0';
1178 id++;
1180 while (*id && *id >= '0' && *id <= '9');
1181 id = xstrndup (id, len);
1182 freeid = true;
1184 identifier = cp_literal_operator_id (id);
1185 if (freeid)
1186 free (id);
1188 break;
1189 case CHARS2 ('q', 'u'): // ternary operator, not overloadable.
1190 default:
1191 gcc_unreachable ();
1194 if (opcode != ERROR_MARK)
1195 identifier = ovl_op_identifier (assop, opcode);
1197 decl = build_lang_decl_loc (loc, code, identifier, sym_type);
1198 /* FIXME: current_lang_name is lang_name_c while compiling an
1199 extern "C" function, and we haven't switched to a global
1200 context at this point, and this breaks function
1201 overloading. */
1202 SET_DECL_LANGUAGE (decl, lang_cplusplus);
1203 if (TREE_CODE (sym_type) == METHOD_TYPE)
1204 DECL_ARGUMENTS (decl) = build_this_parm (decl, current_class_type,
1205 cp_type_quals (sym_type));
1206 for (tree arg = TREE_CODE (sym_type) == METHOD_TYPE
1207 ? TREE_CHAIN (TYPE_ARG_TYPES (sym_type))
1208 : TYPE_ARG_TYPES (sym_type);
1209 arg && arg != void_list_node;
1210 arg = TREE_CHAIN (arg))
1212 tree parm = cp_build_parm_decl (decl, NULL_TREE, TREE_VALUE (arg));
1213 DECL_CHAIN (parm) = DECL_ARGUMENTS (decl);
1214 DECL_ARGUMENTS (decl) = parm;
1216 DECL_ARGUMENTS (decl) = nreverse (DECL_ARGUMENTS (decl));
1217 if (class_member_p)
1219 if (TREE_CODE (sym_type) == FUNCTION_TYPE)
1220 DECL_STATIC_FUNCTION_P (decl) = 1;
1221 if (sym_flags & GCC_CP_FLAG_VIRTUAL_FUNCTION)
1223 DECL_VIRTUAL_P (decl) = 1;
1224 if (sym_flags & GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION)
1225 DECL_PURE_VIRTUAL_P (decl) = 1;
1226 if (sym_flags & GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION)
1227 DECL_FINAL_P (decl) = 1;
1229 else
1230 gcc_assert (!(sym_flags & (GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION
1231 | GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION)));
1233 else
1235 gcc_assert (!(sym_flags & (GCC_CP_FLAG_VIRTUAL_FUNCTION
1236 | GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION
1237 | GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION)));
1238 gcc_assert (!ctor && !dtor && !assop);
1240 if (sym_flags & GCC_CP_FLAG_EXPLICIT_FUNCTION)
1241 DECL_NONCONVERTING_P (decl) = 1;
1242 if (sym_flags & GCC_CP_FLAG_DEFAULTED_FUNCTION)
1244 DECL_INITIAL (decl) = ridpointers[(int)RID_DEFAULT];
1245 DECL_DEFAULTED_FN (decl) = 1;
1247 if (sym_flags & GCC_CP_FLAG_DELETED_FUNCTION)
1249 // DECL_INITIAL (decl) = ridpointers[(int)RID_DELETE];
1250 DECL_DELETED_FN (decl) = 1;
1251 DECL_DECLARED_INLINE_P (decl) = 1;
1252 DECL_INITIAL (decl) = error_mark_node;
1255 if (ctor)
1256 DECL_CXX_CONSTRUCTOR_P (decl) = 1;
1257 else if (dtor)
1258 DECL_CXX_DESTRUCTOR_P (decl) = 1;
1259 else if ((sym_flags & GCC_CP_FLAG_SPECIAL_FUNCTION)
1260 && opcode != ERROR_MARK)
1261 DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op_mapping[opcode];
1263 else if (RECORD_OR_UNION_CODE_P (code))
1265 decl = build_named_class_type (code, identifier, loc);
1266 tree type = TREE_TYPE (decl);
1268 if (code == RECORD_TYPE
1269 && !(sym_flags & GCC_CP_FLAG_CLASS_IS_STRUCT))
1270 CLASSTYPE_DECLARED_CLASS (type) = true;
1272 else if (class_member_p)
1274 decl = build_lang_decl_loc (loc, code, identifier, sym_type);
1276 if (TREE_CODE (decl) == VAR_DECL)
1278 DECL_THIS_STATIC (decl) = 1;
1279 // The remainder of this block does the same as:
1280 // set_linkage_for_static_data_member (decl);
1281 TREE_PUBLIC (decl) = 1;
1282 TREE_STATIC (decl) = 1;
1283 DECL_INTERFACE_KNOWN (decl) = 1;
1285 // FIXME: sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
1286 gcc_assert (!(sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE));
1288 if (sym_flags & GCC_CP_FLAG_CONSTEXPR_VARIABLE)
1289 DECL_DECLARED_CONSTEXPR_P (decl) = true;
1292 else
1294 decl = build_decl (loc, code, identifier, sym_type);
1296 if (TREE_CODE (decl) == VAR_DECL)
1298 // FIXME: sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
1299 gcc_assert (!(sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE));
1301 if (sym_flags & GCC_CP_FLAG_CONSTEXPR_VARIABLE)
1302 DECL_DECLARED_CONSTEXPR_P (decl) = true;
1305 TREE_USED (decl) = 1;
1306 TREE_ADDRESSABLE (decl) = 1;
1308 if (class_member_p)
1309 DECL_CONTEXT (decl) = FROB_CONTEXT (current_class_type);
1310 else if (at_namespace_scope_p ())
1311 DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
1313 set_access_flags (decl, acc_flags);
1315 /* If this is the typedef that names an otherwise anonymous type,
1316 propagate the typedef name to the type. In normal compilation,
1317 this is done in grokdeclarator. */
1318 if (sym_kind == GCC_CP_SYMBOL_TYPEDEF
1319 && !template_decl_p
1320 && DECL_CONTEXT (decl) == TYPE_CONTEXT (sym_type)
1321 && TYPE_UNNAMED_P (sym_type))
1322 name_unnamed_type (sym_type, decl);
1324 if (sym_kind != GCC_CP_SYMBOL_TYPEDEF
1325 && sym_kind != GCC_CP_SYMBOL_CLASS
1326 && sym_kind != GCC_CP_SYMBOL_UNION
1327 && !template_decl_p && !ctor && !dtor)
1329 decl_addr_value value;
1331 DECL_EXTERNAL (decl) = 1;
1332 value.decl = decl;
1333 if (substitution_name != NULL)
1335 // If the translator gave us a name without a binding,
1336 // we can just substitute error_mark_node, since we know the
1337 // translator will be reporting an error anyhow.
1338 value.address
1339 = lookup_name (get_identifier (substitution_name));
1340 if (value.address == NULL_TREE)
1341 value.address = error_mark_node;
1343 else if (address)
1344 value.address = build_int_cst_type (ptr_type_node, address);
1345 else
1346 value.address = NULL;
1347 if (value.address)
1348 record_decl_address (ctx, value);
1351 if (class_member_p && code == FUNCTION_DECL)
1353 if (ctor || dtor)
1354 maybe_retrofit_in_chrg (decl);
1356 grok_special_member_properties (decl);
1359 if (template_decl_p)
1361 if (RECORD_OR_UNION_CODE_P (code))
1362 safe_pushtag (identifier, TREE_TYPE (decl));
1363 else
1364 decl = safe_push_template_decl (decl);
1366 tree tdecl = NULL_TREE;
1367 if (class_member_p)
1368 tdecl = finish_member_template_decl (decl);
1370 end_template_decl ();
1372 /* We only support one level of templates, because we only
1373 support declaring generics; actual definitions are only of
1374 specializations. */
1375 gcc_assert (!template_parm_scope_p ());
1377 if (class_member_p)
1378 finish_member_declaration (tdecl);
1380 else if (RECORD_OR_UNION_CODE_P (code))
1381 safe_pushtag (identifier, TREE_TYPE (decl));
1382 else if (class_member_p)
1383 finish_member_declaration (decl);
1384 else
1385 decl = safe_pushdecl (decl);
1387 if ((ctor || dtor)
1388 /* Don't crash after a duplicate declaration of a cdtor. */
1389 && TYPE_FIELDS (current_class_type) == decl)
1391 /* ctors and dtors clones are chained after DECL.
1392 However, we create the clones before TYPE_METHODS is
1393 reversed. We test for cloned methods after reversal,
1394 however, and the test requires the clones to follow
1395 DECL. So, we reverse the chain of clones now, so
1396 that it will come out in the right order after
1397 reversal. */
1398 tree save = DECL_CHAIN (decl);
1399 DECL_CHAIN (decl) = NULL_TREE;
1400 clone_cdtor (decl, /*update_methods=*/true);
1401 gcc_assert (TYPE_FIELDS (current_class_type) == decl);
1402 TYPE_FIELDS (current_class_type)
1403 = nreverse (TYPE_FIELDS (current_class_type));
1404 DECL_CHAIN (decl) = save;
1407 rest_of_decl_compilation (decl, toplevel_bindings_p (), 0);
1409 return convert_out (ctx->preserve (decl));
1412 gcc_decl
1413 plugin_define_cdtor_clone (cc1_plugin::connection *self,
1414 const char *name,
1415 gcc_decl cdtor_in,
1416 gcc_address address)
1418 plugin_context *ctx = static_cast<plugin_context *> (self);
1419 tree decl = convert_in (cdtor_in);
1420 bool ctor = false;
1421 bool dtor = false;
1422 tree identifier;
1424 switch (CHARS2 (name[0], name[1]))
1426 case CHARS2 ('C', '1'): // in-charge constructor
1427 identifier = complete_ctor_identifier;
1428 ctor = true;
1429 break;
1430 case CHARS2 ('C', '2'): // not-in-charge constructor
1431 identifier = base_ctor_identifier;
1432 ctor = true;
1433 break;
1434 case CHARS2 ('C', '4'):
1435 identifier = ctor_identifier; // unified constructor
1436 ctor = true;
1437 break;
1438 case CHARS2 ('D', '0'): // deleting destructor
1439 identifier = deleting_dtor_identifier;
1440 dtor = true;
1441 break;
1442 case CHARS2 ('D', '1'): // in-charge destructor
1443 identifier = complete_dtor_identifier;
1444 dtor = true;
1445 break;
1446 case CHARS2 ('D', '2'): // not-in-charge destructor
1447 identifier = base_dtor_identifier;
1448 dtor = true;
1449 break;
1450 case CHARS2 ('D', '4'):
1451 identifier = dtor_identifier; // unified destructor
1452 dtor = true;
1453 break;
1455 default:
1456 gcc_unreachable ();
1459 gcc_assert (!ctor != !dtor);
1460 gcc_assert (ctor
1461 ? (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl)
1462 && DECL_NAME (decl) == ctor_identifier)
1463 : (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl)
1464 && DECL_NAME (decl) == dtor_identifier));
1466 while (decl && DECL_NAME (decl) != identifier)
1468 decl = DECL_CHAIN (decl);
1469 if (decl && !DECL_CLONED_FUNCTION_P (decl))
1470 decl = NULL_TREE;
1472 gcc_assert (decl);
1474 record_decl_address (ctx, build_decl_addr_value (decl, address));
1476 return convert_out (decl);
1480 plugin_add_friend (cc1_plugin::connection * /* self */,
1481 gcc_decl decl_in,
1482 gcc_type type_in)
1484 tree decl = convert_in (decl_in);
1485 tree type = convert_in (type_in);
1487 gcc_assert (type || at_class_scope_p ());
1489 if (!type)
1490 type = current_class_type;
1491 else
1492 gcc_assert (TREE_CODE (type) == RECORD_TYPE);
1494 if (TYPE_P (decl))
1495 make_friend_class (type, TREE_TYPE (decl), true);
1496 else
1498 DECL_UNIQUE_FRIEND_P (decl) = true;
1499 add_friend (type, decl, true);
1502 return 1;
1505 gcc_type
1506 plugin_build_pointer_type (cc1_plugin::connection *,
1507 gcc_type base_type)
1509 // No need to preserve a pointer type as the base type is preserved.
1510 return convert_out (build_pointer_type (convert_in (base_type)));
1513 gcc_type
1514 plugin_build_reference_type (cc1_plugin::connection *,
1515 gcc_type base_type_in,
1516 enum gcc_cp_ref_qualifiers rquals)
1518 bool rval;
1520 switch (rquals)
1522 case GCC_CP_REF_QUAL_LVALUE:
1523 rval = false;
1524 break;
1525 case GCC_CP_REF_QUAL_RVALUE:
1526 rval = true;
1527 break;
1528 case GCC_CP_REF_QUAL_NONE:
1529 default:
1530 gcc_unreachable ();
1533 tree rtype = cp_build_reference_type (convert_in (base_type_in), rval);
1535 return convert_out (rtype);
1538 static tree
1539 start_class_def (tree type,
1540 const gcc_vbase_array *base_classes)
1542 tree bases = NULL;
1543 if (base_classes)
1545 for (int i = 0; i < base_classes->n_elements; i++)
1547 tree access;
1549 gcc_assert ((base_classes->flags[i] & GCC_CP_SYMBOL_MASK)
1550 == GCC_CP_SYMBOL_BASECLASS);
1552 switch (base_classes->flags[i] & GCC_CP_ACCESS_MASK)
1554 case GCC_CP_ACCESS_PRIVATE:
1555 access = ridpointers[(int)RID_PRIVATE];
1556 break;
1558 case GCC_CP_ACCESS_PROTECTED:
1559 access = ridpointers[(int)RID_PROTECTED];
1560 break;
1562 case GCC_CP_ACCESS_PUBLIC:
1563 access = ridpointers[(int)RID_PUBLIC];
1564 break;
1566 default:
1567 gcc_unreachable ();
1570 tree base = finish_base_specifier
1571 (convert_in (base_classes->elements[i]), access,
1572 (base_classes->flags[i] & GCC_CP_FLAG_BASECLASS_VIRTUAL) != 0);
1573 TREE_CHAIN (base) = bases;
1574 bases = base;
1576 bases = nreverse (bases);
1578 xref_basetypes (type, bases);
1579 begin_class_definition (type);
1580 return type;
1583 gcc_type
1584 plugin_start_class_type (cc1_plugin::connection *self,
1585 gcc_decl typedecl_in,
1586 const gcc_vbase_array *base_classes,
1587 const char *filename,
1588 unsigned int line_number)
1590 plugin_context *ctx = static_cast<plugin_context *> (self);
1591 location_t loc = ctx->get_location_t (filename, line_number);
1592 tree typedecl = convert_in (typedecl_in);
1593 tree type = TREE_TYPE (typedecl);
1595 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (type)));
1596 gcc_assert (!COMPLETE_TYPE_P (type));
1598 DECL_SOURCE_LOCATION (typedecl) = loc;
1600 tree result = start_class_def (type, base_classes);
1602 return convert_out (ctx->preserve (result));
1605 gcc_type
1606 plugin_start_closure_class_type (cc1_plugin::connection *self,
1607 int discriminator,
1608 gcc_decl extra_scope_in,
1609 enum gcc_cp_symbol_kind flags,
1610 const char *filename,
1611 unsigned int line_number)
1613 plugin_context *ctx = static_cast<plugin_context *> (self);
1614 tree extra_scope = convert_in (extra_scope_in);
1616 gcc_assert ((flags & GCC_CP_SYMBOL_MASK) == GCC_CP_SYMBOL_LAMBDA_CLOSURE);
1617 gcc_assert ((flags & (~(GCC_CP_SYMBOL_MASK | GCC_CP_ACCESS_MASK))) == 0);
1619 gcc_assert (!(flags & GCC_CP_ACCESS_MASK) == !at_class_scope_p ());
1621 /* See at_fake_function_scope_p. */
1622 gcc_assert (!at_function_scope_p ());
1624 if (extra_scope)
1626 if (TREE_CODE (extra_scope) == PARM_DECL)
1628 gcc_assert (at_fake_function_scope_p ());
1629 /* Check that the given extra_scope is one of the parameters of
1630 the current function. */
1631 for (tree parm = DECL_ARGUMENTS (current_function_decl);
1632 ; parm = DECL_CHAIN (parm))
1634 gcc_assert (parm);
1635 if (parm == extra_scope)
1636 break;
1639 else if (TREE_CODE (extra_scope) == FIELD_DECL)
1641 gcc_assert (at_class_scope_p ());
1642 gcc_assert (DECL_CONTEXT (extra_scope) == current_class_type);
1644 else
1645 /* FIXME: does this ever really occur? */
1646 gcc_assert (TREE_CODE (extra_scope) == VAR_DECL);
1649 tree lambda_expr = build_lambda_expr ();
1651 LAMBDA_EXPR_LOCATION (lambda_expr) = ctx->get_location_t (filename,
1652 line_number);
1654 tree type = begin_lambda_type (lambda_expr);
1656 /* Instead of calling record_lambda_scope, do this: */
1657 LAMBDA_EXPR_EXTRA_SCOPE (lambda_expr) = extra_scope;
1658 LAMBDA_EXPR_SCOPE_ONLY_DISCRIMINATOR (lambda_expr) = discriminator;
1659 LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR (lambda_expr) = discriminator;
1661 tree decl = TYPE_NAME (type);
1662 determine_visibility (decl);
1663 set_access_flags (decl, flags);
1665 return convert_out (ctx->preserve (type));
1668 gcc_expr
1669 plugin_build_lambda_expr (cc1_plugin::connection *self,
1670 gcc_type closure_type_in)
1672 plugin_context *ctx = static_cast<plugin_context *> (self);
1673 tree closure_type = convert_in (closure_type_in);
1675 gcc_assert (LAMBDA_TYPE_P (closure_type));
1677 tree lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure_type);
1679 tree lambda_object = build_lambda_object (lambda_expr);
1681 return convert_out (ctx->preserve (lambda_object));
1684 gcc_decl
1685 plugin_build_field (cc1_plugin::connection *,
1686 const char *field_name,
1687 gcc_type field_type_in,
1688 enum gcc_cp_symbol_kind flags,
1689 unsigned long bitsize,
1690 unsigned long bitpos)
1692 tree record_or_union_type = current_class_type;
1693 tree field_type = convert_in (field_type_in);
1695 gcc_assert (at_class_scope_p ());
1696 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (record_or_union_type)));
1697 gcc_assert ((flags & GCC_CP_SYMBOL_MASK) == GCC_CP_SYMBOL_FIELD);
1698 gcc_assert ((flags & (~(GCC_CP_SYMBOL_MASK | GCC_CP_ACCESS_MASK
1699 | GCC_CP_FLAG_MASK_FIELD))) == 0);
1700 gcc_assert ((flags & GCC_CP_ACCESS_MASK));
1702 /* Note that gdb does not preserve the location of field decls, so
1703 we can't provide a decent location here. */
1704 tree decl = build_decl (BUILTINS_LOCATION, FIELD_DECL,
1705 get_identifier (field_name), field_type);
1706 DECL_FIELD_CONTEXT (decl) = record_or_union_type;
1708 set_access_flags (decl, flags);
1710 if ((flags & GCC_CP_FLAG_FIELD_MUTABLE) != 0)
1711 DECL_MUTABLE_P (decl) = 1;
1713 if (TREE_CODE (field_type) == INTEGER_TYPE
1714 && TYPE_PRECISION (field_type) != bitsize)
1716 DECL_BIT_FIELD_TYPE (decl) = field_type;
1717 TREE_TYPE (decl)
1718 = c_build_bitfield_integer_type (bitsize, TYPE_UNSIGNED (field_type));
1721 SET_DECL_MODE (decl, TYPE_MODE (TREE_TYPE (decl)));
1723 // There's no way to recover this from DWARF.
1724 SET_DECL_OFFSET_ALIGN (decl, TYPE_PRECISION (pointer_sized_int_node));
1726 tree pos = bitsize_int (bitpos);
1727 pos_from_bit (&DECL_FIELD_OFFSET (decl), &DECL_FIELD_BIT_OFFSET (decl),
1728 DECL_OFFSET_ALIGN (decl), pos);
1730 DECL_SIZE (decl) = bitsize_int (bitsize);
1731 DECL_SIZE_UNIT (decl) = size_int ((bitsize + BITS_PER_UNIT - 1)
1732 / BITS_PER_UNIT);
1734 DECL_CHAIN (decl) = TYPE_FIELDS (record_or_union_type);
1735 TYPE_FIELDS (record_or_union_type) = decl;
1737 return convert_out (decl);
1741 plugin_finish_class_type (cc1_plugin::connection *,
1742 unsigned long size_in_bytes)
1744 tree record_or_union_type = current_class_type;
1746 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (record_or_union_type)));
1748 finish_struct (record_or_union_type, NULL);
1750 gcc_assert (compare_tree_int (TYPE_SIZE_UNIT (record_or_union_type),
1751 size_in_bytes) == 0);
1753 return 1;
1756 gcc_type
1757 plugin_start_enum_type (cc1_plugin::connection *self,
1758 const char *name,
1759 gcc_type underlying_int_type_in,
1760 enum gcc_cp_symbol_kind flags,
1761 const char *filename,
1762 unsigned int line_number)
1764 plugin_context *ctx = static_cast<plugin_context *> (self);
1765 tree underlying_int_type = convert_in (underlying_int_type_in);
1767 gcc_assert ((flags & GCC_CP_SYMBOL_MASK) == GCC_CP_SYMBOL_ENUM);
1768 gcc_assert ((flags & (~(GCC_CP_SYMBOL_MASK | GCC_CP_ACCESS_MASK
1769 | GCC_CP_FLAG_MASK_ENUM))) == 0);
1770 gcc_assert (!(flags & GCC_CP_ACCESS_MASK) == !at_class_scope_p ());
1772 if (underlying_int_type == error_mark_node)
1773 return convert_out (error_mark_node);
1775 bool is_new_type = false;
1777 tree id = name ? get_identifier (name) : make_anon_name ();
1779 tree type = start_enum (id, NULL_TREE,
1780 underlying_int_type,
1781 /* attributes = */ NULL_TREE,
1782 !!(flags & GCC_CP_FLAG_ENUM_SCOPED), &is_new_type);
1784 gcc_assert (is_new_type);
1786 location_t loc = ctx->get_location_t (filename, line_number);
1787 tree type_decl = TYPE_NAME (type);
1788 DECL_SOURCE_LOCATION (type_decl) = loc;
1789 SET_OPAQUE_ENUM_P (type, false);
1791 set_access_flags (type_decl, flags);
1793 return convert_out (ctx->preserve (type));
1796 gcc_decl
1797 plugin_build_enum_constant (cc1_plugin::connection *,
1798 gcc_type enum_type_in,
1799 const char *name,
1800 unsigned long value)
1802 tree enum_type = convert_in (enum_type_in);
1804 gcc_assert (TREE_CODE (enum_type) == ENUMERAL_TYPE);
1806 build_enumerator (get_identifier (name), build_int_cst (enum_type, value),
1807 enum_type, NULL_TREE, BUILTINS_LOCATION);
1809 return convert_out (TREE_VALUE (TYPE_VALUES (enum_type)));
1813 plugin_finish_enum_type (cc1_plugin::connection *,
1814 gcc_type enum_type_in)
1816 tree enum_type = convert_in (enum_type_in);
1818 finish_enum_value_list (enum_type);
1819 finish_enum (enum_type);
1821 return 1;
1824 gcc_type
1825 plugin_build_function_type (cc1_plugin::connection *self,
1826 gcc_type return_type_in,
1827 const struct gcc_type_array *argument_types_in,
1828 int is_varargs)
1830 tree return_type = convert_in (return_type_in);
1831 tree result;
1833 std::vector<tree> argument_types (argument_types_in->n_elements);
1834 for (int i = 0; i < argument_types_in->n_elements; ++i)
1835 argument_types[i] = convert_in (argument_types_in->elements[i]);
1837 if (is_varargs)
1838 result = build_varargs_function_type_array (return_type,
1839 argument_types_in->n_elements,
1840 argument_types.data ());
1841 else
1842 result = build_function_type_array (return_type,
1843 argument_types_in->n_elements,
1844 argument_types.data ());
1846 plugin_context *ctx = static_cast<plugin_context *> (self);
1847 return convert_out (ctx->preserve (result));
1850 #if 0
1852 gcc_type
1853 plugin_add_function_default_args (cc1_plugin::connection *self,
1854 gcc_type function_type_in,
1855 const struct gcc_cp_function_args *defaults)
1857 tree function_type = convert_in (function_type_in);
1859 gcc_assert (TREE_CODE (function_type) == FUNCTION_TYPE);
1861 if (!defaults || !defaults->n_elements)
1862 return function_type_in;
1864 tree pargs = TYPE_ARG_TYPES (function_type);
1865 tree nargs = NULL_TREE;
1867 /* Build a reversed copy of the list of default-less arguments in
1868 NARGS. At the end of the loop, PARGS will point to the end of
1869 the argument list, or to the first argument that had a default
1870 value. */
1871 while (pargs && TREE_VALUE (pargs) != void_list_node
1872 && !TREE_PURPOSE (pargs))
1874 nargs = tree_cons (NULL_TREE, TREE_VALUE (pargs), nargs);
1875 pargs = TREE_CHAIN (pargs);
1878 /* Set the defaults in the now-leading NARGS, taking into account
1879 that NARGS is reversed but DEFAULTS->elements isn't. */
1880 tree ndargs = nargs;
1881 int i = defaults->n_elements;
1882 while (i--)
1884 gcc_assert (ndargs);
1885 tree deflt = convert_in (defaults->elements[i]);
1886 if (!deflt)
1887 deflt = error_mark_node;
1888 TREE_PURPOSE (ndargs) = deflt;
1889 ndargs = TREE_CHAIN (ndargs);
1892 /* Finally, reverse NARGS, and append the remaining PARGS that
1893 already had defaults. */
1894 nargs = nreverse (nargs);
1895 nargs = chainon (nargs, pargs);
1897 tree result = build_function_type (TREE_TYPE (function_type), nargs);
1899 /* Copy exceptions, attributes and whatnot. */
1900 result = build_exception_variant (result,
1901 TYPE_RAISES_EXCEPTIONS (function_type));
1902 result = cp_build_type_attribute_variant (result,
1903 TYPE_ATTRIBUTES (function_type));
1905 plugin_context *ctx = static_cast<plugin_context *> (self);
1906 return convert_out (ctx->preserve (result));
1910 plugin_set_deferred_function_default_args (cc1_plugin::connection *,
1911 gcc_decl function_in,
1912 const struct gcc_cp_function_args
1913 *defaults)
1915 tree function = convert_in (function_in);
1917 gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
1919 if (!defaults || !defaults->n_elements)
1920 return 1;
1922 tree arg = FUNCTION_FIRST_USER_PARMTYPE (function);
1924 for (int i = 0; i < defaults->n_elements; i++)
1926 while (arg && TREE_PURPOSE (arg) != error_mark_node)
1927 arg = TREE_CHAIN (arg);
1929 if (!arg)
1930 return 0;
1932 TREE_PURPOSE (arg) = convert_in (defaults->elements[i]);
1933 arg = TREE_CHAIN (arg);
1936 return 1;
1939 #endif
1941 gcc_decl
1942 plugin_get_function_parameter_decl (cc1_plugin::connection *,
1943 gcc_decl function_in,
1944 int index)
1946 tree function = convert_in (function_in);
1948 gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
1950 if (index == -1)
1952 gcc_assert (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE);
1954 return convert_out (DECL_ARGUMENTS (function));
1957 gcc_assert (index >= 0);
1959 tree args = FUNCTION_FIRST_USER_PARM (function);
1961 for (int i = 0; args && i < index; i++)
1962 args = DECL_CHAIN (args);
1964 return convert_out (args);
1967 gcc_type
1968 plugin_build_exception_spec_variant (cc1_plugin::connection *self,
1969 gcc_type function_type_in,
1970 const struct gcc_type_array *except_types_in)
1972 tree function_type = convert_in (function_type_in);
1973 tree except_types = NULL_TREE;
1975 if (!except_types_in)
1976 except_types = noexcept_false_spec;
1977 else if (!except_types_in->n_elements)
1978 except_types = empty_except_spec;
1979 else
1980 for (int i = 0; i < except_types_in->n_elements; i++)
1981 except_types = add_exception_specifier (except_types,
1982 convert_in
1983 (except_types_in->elements[i]),
1986 function_type = build_exception_variant (function_type,
1987 except_types);
1989 plugin_context *ctx = static_cast<plugin_context *> (self);
1990 return convert_out (ctx->preserve (function_type));
1993 gcc_type
1994 plugin_build_method_type (cc1_plugin::connection *self,
1995 gcc_type class_type_in,
1996 gcc_type func_type_in,
1997 enum gcc_cp_qualifiers quals_in,
1998 enum gcc_cp_ref_qualifiers rquals_in)
2000 tree class_type = convert_in (class_type_in);
2001 tree func_type = convert_in (func_type_in);
2002 cp_cv_quals quals = 0;
2003 cp_ref_qualifier rquals;
2005 if ((quals_in & GCC_CP_QUALIFIER_CONST) != 0)
2006 quals |= TYPE_QUAL_CONST;
2007 if ((quals_in & GCC_CP_QUALIFIER_VOLATILE) != 0)
2008 quals |= TYPE_QUAL_VOLATILE;
2009 gcc_assert ((quals_in & GCC_CP_QUALIFIER_RESTRICT) == 0);
2011 switch (rquals_in)
2013 case GCC_CP_REF_QUAL_NONE:
2014 rquals = REF_QUAL_NONE;
2015 break;
2016 case GCC_CP_REF_QUAL_LVALUE:
2017 rquals = REF_QUAL_LVALUE;
2018 break;
2019 case GCC_CP_REF_QUAL_RVALUE:
2020 rquals = REF_QUAL_RVALUE;
2021 break;
2022 default:
2023 gcc_unreachable ();
2026 tree method_type = class_type
2027 ? build_memfn_type (func_type, class_type, quals, rquals)
2028 : apply_memfn_quals (func_type, quals, rquals);
2030 plugin_context *ctx = static_cast<plugin_context *> (self);
2031 return convert_out (ctx->preserve (method_type));
2034 gcc_type
2035 plugin_build_pointer_to_member_type (cc1_plugin::connection *self,
2036 gcc_type class_type_in,
2037 gcc_type member_type_in)
2039 tree class_type = convert_in (class_type_in);
2040 tree member_type = convert_in (member_type_in);
2042 tree memptr_type = build_ptrmem_type (class_type, member_type);
2044 plugin_context *ctx = static_cast<plugin_context *> (self);
2045 return convert_out (ctx->preserve (memptr_type));
2049 plugin_start_template_decl (cc1_plugin::connection *)
2051 begin_template_parm_list ();
2053 TP_PARM_LIST = NULL_TREE;
2055 return 1;
2058 gcc_decl
2059 plugin_get_type_decl (cc1_plugin::connection *,
2060 gcc_type type_in)
2062 tree type = convert_in (type_in);
2064 tree name = TYPE_NAME (type);
2065 gcc_assert (name);
2067 return convert_out (name);
2070 gcc_type
2071 plugin_get_decl_type (cc1_plugin::connection *,
2072 gcc_decl decl_in)
2074 tree decl = convert_in (decl_in);
2076 tree type = TREE_TYPE (decl);
2077 gcc_assert (type);
2079 return convert_out (type);
2082 gcc_type
2083 plugin_build_type_template_parameter (cc1_plugin::connection *self,
2084 const char *id,
2085 int /* bool */ pack_p,
2086 gcc_type default_type,
2087 const char *filename,
2088 unsigned int line_number)
2090 plugin_context *ctx = static_cast<plugin_context *> (self);
2091 location_t loc = ctx->get_location_t (filename, line_number);
2093 gcc_assert (template_parm_scope_p ());
2095 tree parm = finish_template_type_parm (class_type_node, get_identifier (id));
2096 parm = build_tree_list (convert_in (default_type), parm);
2098 gcc_assert (!(pack_p && default_type));
2100 /* Create a type and a decl for the type parm, and add the decl to
2101 TP_PARM_LIST. */
2102 TP_PARM_LIST = process_template_parm (TP_PARM_LIST, loc, parm,
2103 /* is_non_type = */ false, pack_p);
2105 /* Locate the decl of the newly-added, processed template parm. */
2106 parm = TREE_VALUE (tree_last (TP_PARM_LIST));
2108 /* Return its type. */
2109 return convert_out (ctx->preserve (TREE_TYPE (parm)));
2112 gcc_utempl
2113 plugin_build_template_template_parameter (cc1_plugin::connection *self,
2114 const char *id,
2115 int /* bool */ pack_p,
2116 gcc_utempl default_templ,
2117 const char *filename,
2118 unsigned int line_number)
2120 plugin_context *ctx = static_cast<plugin_context *> (self);
2121 location_t loc = ctx->get_location_t (filename, line_number);
2123 gcc_assert (template_parm_scope_p ());
2125 /* Finish the template parm list that started this template parm. */
2126 end_template_parm_list (TP_PARM_LIST);
2128 gcc_assert (template_parm_scope_p ());
2130 tree parm = finish_template_template_parm (class_type_node,
2131 get_identifier (id));
2132 parm = build_tree_list (convert_in (default_templ), parm);
2134 gcc_assert (!(pack_p && default_templ));
2136 /* Create a type and a decl for the template parm, and add the decl
2137 to TP_PARM_LIST. */
2138 TP_PARM_LIST = process_template_parm (TP_PARM_LIST, loc, parm,
2139 /* is_non_type = */ false, pack_p);
2141 /* Locate the decl of the newly-added, processed template parm. */
2142 parm = TREE_VALUE (tree_last (TP_PARM_LIST));
2144 return convert_out (ctx->preserve (parm));
2147 gcc_decl
2148 plugin_build_value_template_parameter (cc1_plugin::connection *self,
2149 gcc_type type,
2150 const char *id,
2151 gcc_expr default_value,
2152 const char *filename,
2153 unsigned int line_number)
2155 plugin_context *ctx = static_cast<plugin_context *> (self);
2156 location_t loc = ctx->get_location_t (filename, line_number);
2158 gcc_assert (template_parm_scope_p ());
2160 cp_declarator declarator;
2161 memset (&declarator, 0, sizeof (declarator));
2162 // &declarator = make_id_declarator (NULL, get_identifier (id), sfk_none):
2163 declarator.kind = cdk_id;
2164 declarator.u.id.qualifying_scope = NULL;
2165 declarator.u.id.unqualified_name = get_identifier (id);
2166 declarator.u.id.sfk = sfk_none;
2168 cp_decl_specifier_seq declspec;
2169 memset (&declspec, 0, sizeof (declspec));
2170 // cp_parser_set_decl_spec_type (&declspec, convert_in (type), -token-, false):
2171 declspec.any_specifiers_p = declspec.any_type_specifiers_p = true;
2172 declspec.type = convert_in (type);
2173 declspec.locations[ds_type_spec] = loc;
2175 tree parm = grokdeclarator (&declarator, &declspec, TPARM, 0, 0);
2176 parm = build_tree_list (convert_in (default_value), parm);
2178 /* Create a type and a decl for the template parm, and add the decl
2179 to TP_PARM_LIST. */
2180 TP_PARM_LIST = process_template_parm (TP_PARM_LIST, loc, parm,
2181 /* is_non_type = */ true, false);
2183 /* Locate the decl of the newly-added, processed template parm. */
2184 parm = TREE_VALUE (tree_last (TP_PARM_LIST));
2186 return convert_out (ctx->preserve (parm));
2189 static tree
2190 targlist (const gcc_cp_template_args *targs)
2192 int n = targs->n_elements;
2193 tree vec = make_tree_vec (n);
2194 while (n--)
2196 switch (targs->kinds[n])
2198 case GCC_CP_TPARG_VALUE:
2199 TREE_VEC_ELT (vec, n) = convert_in (targs->elements[n].value);
2200 break;
2201 case GCC_CP_TPARG_CLASS:
2202 TREE_VEC_ELT (vec, n) = convert_in (targs->elements[n].type);
2203 break;
2204 case GCC_CP_TPARG_TEMPL:
2205 TREE_VEC_ELT (vec, n) = convert_in (targs->elements[n].templ);
2206 break;
2207 case GCC_CP_TPARG_PACK:
2208 TREE_VEC_ELT (vec, n) = convert_in (targs->elements[n].pack);
2209 break;
2210 default:
2211 gcc_unreachable ();
2214 return vec;
2217 gcc_type
2218 plugin_build_dependent_typename (cc1_plugin::connection *self,
2219 gcc_type enclosing_type,
2220 const char *id,
2221 const gcc_cp_template_args *targs)
2223 plugin_context *ctx = static_cast<plugin_context *> (self);
2224 tree type = convert_in (enclosing_type);
2225 tree name = get_identifier (id);
2226 if (targs)
2227 name = build_min_nt_loc (/*loc=*/0, TEMPLATE_ID_EXPR,
2228 name, targlist (targs));
2229 tree res = make_typename_type (type, name, typename_type,
2230 /*complain=*/tf_error);
2231 return convert_out (ctx->preserve (res));
2234 gcc_utempl
2235 plugin_build_dependent_class_template (cc1_plugin::connection *self,
2236 gcc_type enclosing_type,
2237 const char *id)
2239 plugin_context *ctx = static_cast<plugin_context *> (self);
2240 tree type = convert_in (enclosing_type);
2241 tree name = get_identifier (id);
2242 tree res = make_unbound_class_template (type, name, NULL_TREE,
2243 /*complain=*/tf_error);
2244 return convert_out (ctx->preserve (res));
2247 gcc_type
2248 plugin_build_dependent_type_template_id (cc1_plugin::connection *self,
2249 gcc_utempl template_decl,
2250 const gcc_cp_template_args *targs)
2252 plugin_context *ctx = static_cast<plugin_context *> (self);
2253 tree type = convert_in (template_decl);
2254 tree decl = finish_template_type (type, targlist (targs),
2255 /*entering_scope=*/false);
2256 return convert_out (ctx->preserve (TREE_TYPE (decl)));
2259 gcc_expr
2260 plugin_build_dependent_expr (cc1_plugin::connection *self,
2261 gcc_decl enclosing_scope,
2262 enum gcc_cp_symbol_kind flags,
2263 const char *name,
2264 gcc_type conv_type_in,
2265 const gcc_cp_template_args *targs)
2267 plugin_context *ctx = static_cast<plugin_context *> (self);
2268 tree scope = convert_in (enclosing_scope);
2269 tree conv_type = convert_in (conv_type_in);
2270 tree identifier;
2272 if (TREE_CODE (scope) != NAMESPACE_DECL)
2274 tree type = TREE_TYPE (scope);
2275 gcc_assert (TYPE_NAME (type) == scope);
2276 scope = type;
2279 if (flags == (GCC_CP_SYMBOL_FUNCTION | GCC_CP_FLAG_SPECIAL_FUNCTION))
2281 bool assop = false, convop = false;
2282 tree_code opcode = ERROR_MARK;
2284 switch (CHARS2 (name[0], name[1]))
2286 case CHARS2 ('C', 0x0): // ctor base declaration
2287 case CHARS2 ('C', ' '):
2288 case CHARS2 ('C', '1'):
2289 case CHARS2 ('C', '2'):
2290 case CHARS2 ('C', '4'):
2291 identifier = ctor_identifier;
2292 break;
2293 case CHARS2 ('D', 0x0): // dtor base declaration
2294 case CHARS2 ('D', ' '):
2295 case CHARS2 ('D', '0'):
2296 case CHARS2 ('D', '1'):
2297 case CHARS2 ('D', '2'):
2298 case CHARS2 ('D', '4'):
2299 gcc_assert (!targs);
2300 identifier = dtor_identifier;
2301 break;
2302 case CHARS2 ('n', 'w'): // operator new
2303 opcode = NEW_EXPR;
2304 break;
2305 case CHARS2 ('n', 'a'): // operator new[]
2306 opcode = VEC_NEW_EXPR;
2307 break;
2308 case CHARS2 ('d', 'l'): // operator delete
2309 opcode = DELETE_EXPR;
2310 break;
2311 case CHARS2 ('d', 'a'): // operator delete[]
2312 opcode = VEC_DELETE_EXPR;
2313 break;
2314 case CHARS2 ('p', 's'): // operator + (unary)
2315 opcode = PLUS_EXPR;
2316 break;
2317 case CHARS2 ('n', 'g'): // operator - (unary)
2318 opcode = MINUS_EXPR;
2319 break;
2320 case CHARS2 ('a', 'd'): // operator & (unary)
2321 opcode = BIT_AND_EXPR;
2322 break;
2323 case CHARS2 ('d', 'e'): // operator * (unary)
2324 opcode = MULT_EXPR;
2325 break;
2326 case CHARS2 ('c', 'o'): // operator ~
2327 opcode = BIT_NOT_EXPR;
2328 break;
2329 case CHARS2 ('p', 'l'): // operator +
2330 opcode = PLUS_EXPR;
2331 break;
2332 case CHARS2 ('m', 'i'): // operator -
2333 opcode = MINUS_EXPR;
2334 break;
2335 case CHARS2 ('m', 'l'): // operator *
2336 opcode = MULT_EXPR;
2337 break;
2338 case CHARS2 ('d', 'v'): // operator /
2339 opcode = TRUNC_DIV_EXPR;
2340 break;
2341 case CHARS2 ('r', 'm'): // operator %
2342 opcode = TRUNC_MOD_EXPR;
2343 break;
2344 case CHARS2 ('a', 'n'): // operator &
2345 opcode = BIT_AND_EXPR;
2346 break;
2347 case CHARS2 ('o', 'r'): // operator |
2348 opcode = BIT_IOR_EXPR;
2349 break;
2350 case CHARS2 ('e', 'o'): // operator ^
2351 opcode = BIT_XOR_EXPR;
2352 break;
2353 case CHARS2 ('a', 'S'): // operator =
2354 opcode = NOP_EXPR;
2355 assop = true;
2356 break;
2357 case CHARS2 ('p', 'L'): // operator +=
2358 opcode = PLUS_EXPR;
2359 assop = true;
2360 break;
2361 case CHARS2 ('m', 'I'): // operator -=
2362 opcode = MINUS_EXPR;
2363 assop = true;
2364 break;
2365 case CHARS2 ('m', 'L'): // operator *=
2366 opcode = MULT_EXPR;
2367 assop = true;
2368 break;
2369 case CHARS2 ('d', 'V'): // operator /=
2370 opcode = TRUNC_DIV_EXPR;
2371 assop = true;
2372 break;
2373 case CHARS2 ('r', 'M'): // operator %=
2374 opcode = TRUNC_MOD_EXPR;
2375 assop = true;
2376 break;
2377 case CHARS2 ('a', 'N'): // operator &=
2378 opcode = BIT_AND_EXPR;
2379 assop = true;
2380 break;
2381 case CHARS2 ('o', 'R'): // operator |=
2382 opcode = BIT_IOR_EXPR;
2383 assop = true;
2384 break;
2385 case CHARS2 ('e', 'O'): // operator ^=
2386 opcode = BIT_XOR_EXPR;
2387 assop = true;
2388 break;
2389 case CHARS2 ('l', 's'): // operator <<
2390 opcode = LSHIFT_EXPR;
2391 break;
2392 case CHARS2 ('r', 's'): // operator >>
2393 opcode = RSHIFT_EXPR;
2394 break;
2395 case CHARS2 ('l', 'S'): // operator <<=
2396 opcode = LSHIFT_EXPR;
2397 assop = true;
2398 break;
2399 case CHARS2 ('r', 'S'): // operator >>=
2400 opcode = RSHIFT_EXPR;
2401 assop = true;
2402 break;
2403 case CHARS2 ('e', 'q'): // operator ==
2404 opcode = EQ_EXPR;
2405 break;
2406 case CHARS2 ('n', 'e'): // operator !=
2407 opcode = NE_EXPR;
2408 break;
2409 case CHARS2 ('l', 't'): // operator <
2410 opcode = LT_EXPR;
2411 break;
2412 case CHARS2 ('g', 't'): // operator >
2413 opcode = GT_EXPR;
2414 break;
2415 case CHARS2 ('l', 'e'): // operator <=
2416 opcode = LE_EXPR;
2417 break;
2418 case CHARS2 ('g', 'e'): // operator >=
2419 opcode = GE_EXPR;
2420 break;
2421 case CHARS2 ('n', 't'): // operator !
2422 opcode = TRUTH_NOT_EXPR;
2423 break;
2424 case CHARS2 ('a', 'a'): // operator &&
2425 opcode = TRUTH_ANDIF_EXPR;
2426 break;
2427 case CHARS2 ('o', 'o'): // operator ||
2428 opcode = TRUTH_ORIF_EXPR;
2429 break;
2430 case CHARS2 ('p', 'p'): // operator ++
2431 opcode = POSTINCREMENT_EXPR;
2432 break;
2433 case CHARS2 ('m', 'm'): // operator --
2434 opcode = PREDECREMENT_EXPR;
2435 break;
2436 case CHARS2 ('c', 'm'): // operator ,
2437 opcode = COMPOUND_EXPR;
2438 break;
2439 case CHARS2 ('p', 'm'): // operator ->*
2440 opcode = MEMBER_REF;
2441 break;
2442 case CHARS2 ('p', 't'): // operator ->
2443 opcode = COMPONENT_REF;
2444 break;
2445 case CHARS2 ('c', 'l'): // operator ()
2446 opcode = CALL_EXPR;
2447 break;
2448 case CHARS2 ('i', 'x'): // operator []
2449 opcode = ARRAY_REF;
2450 break;
2451 case CHARS2 ('c', 'v'): // operator <T> (conversion operator)
2452 convop = true;
2453 identifier = make_conv_op_name (conv_type);
2454 break;
2455 // C++11-only:
2456 case CHARS2 ('l', 'i'): // operator "" <id>
2458 char *id = (char *)name + 2;
2459 bool freeid = false;
2460 if (*id >= '0' && *id <= '9')
2462 unsigned len = 0;
2465 len *= 10;
2466 len += id[0] - '0';
2467 id++;
2469 while (*id && *id >= '0' && *id <= '9');
2470 id = xstrndup (id, len);
2471 freeid = true;
2473 identifier = cp_literal_operator_id (id);
2474 if (freeid)
2475 free (id);
2477 break;
2478 case CHARS2 ('q', 'u'): // ternary operator, not overloadable.
2479 default:
2480 gcc_unreachable ();
2483 gcc_assert (convop || !conv_type);
2485 if (opcode != ERROR_MARK)
2486 identifier = ovl_op_identifier (assop, opcode);
2488 gcc_assert (identifier);
2490 else
2492 gcc_assert (flags == GCC_CP_SYMBOL_MASK);
2493 gcc_assert (!conv_type);
2494 identifier = get_identifier (name);
2496 tree res = identifier;
2497 if (!scope)
2498 res = lookup_name (res, LOOK_where::BLOCK_NAMESPACE);
2499 else if (!TYPE_P (scope) || !dependent_scope_p (scope))
2501 res = lookup_qualified_name (scope, res, LOOK_want::NORMAL, true);
2502 /* We've already resolved the name in the scope, so skip the
2503 build_qualified_name call below. */
2504 scope = NULL;
2506 if (targs)
2507 res = lookup_template_function (res, targlist (targs));
2508 if (scope)
2509 res = build_qualified_name (NULL_TREE, scope, res, !!targs);
2510 return convert_out (ctx->preserve (res));
2513 gcc_expr
2514 plugin_build_literal_expr (cc1_plugin::connection *self,
2515 gcc_type type, unsigned long value)
2517 plugin_context *ctx = static_cast<plugin_context *> (self);
2518 tree t = convert_in (type);
2519 tree val = build_int_cst_type (t, (unsigned HOST_WIDE_INT) value);
2520 return convert_out (ctx->preserve (val));
2523 gcc_expr
2524 plugin_build_decl_expr (cc1_plugin::connection *self,
2525 gcc_decl decl_in,
2526 int qualified_p)
2528 plugin_context *ctx = static_cast<plugin_context *> (self);
2529 tree decl = convert_in (decl_in);
2530 gcc_assert (DECL_P (decl));
2531 tree result = decl;
2532 if (qualified_p)
2534 gcc_assert (DECL_CLASS_SCOPE_P (decl));
2535 result = build_offset_ref (DECL_CONTEXT (decl), decl,
2536 /*address_p=*/true, tf_error);
2538 return convert_out (ctx->preserve (result));
2541 gcc_expr
2542 plugin_build_unary_expr (cc1_plugin::connection *self,
2543 const char *unary_op,
2544 gcc_expr operand)
2546 plugin_context *ctx = static_cast<plugin_context *> (self);
2547 tree op0 = convert_in (operand);
2548 tree_code opcode = ERROR_MARK;
2549 bool global_scope_p = false;
2551 once_more:
2552 switch (CHARS2 (unary_op[0], unary_op[1]))
2554 case CHARS2 ('p', 's'): // operator + (unary)
2555 opcode = UNARY_PLUS_EXPR;
2556 break;
2557 case CHARS2 ('n', 'g'): // operator - (unary)
2558 opcode = NEGATE_EXPR;
2559 break;
2560 case CHARS2 ('a', 'd'): // operator & (unary)
2561 opcode = ADDR_EXPR;
2562 break;
2563 case CHARS2 ('d', 'e'): // operator * (unary)
2564 opcode = INDIRECT_REF;
2565 break;
2566 case CHARS2 ('c', 'o'): // operator ~
2567 opcode = BIT_NOT_EXPR;
2568 break;
2569 case CHARS2 ('n', 't'): // operator !
2570 opcode = TRUTH_NOT_EXPR;
2571 break;
2572 case CHARS2 ('p', 'p'): // operator ++
2573 opcode = unary_op[2] == '_' ? PREINCREMENT_EXPR : POSTINCREMENT_EXPR;
2574 break;
2575 case CHARS2 ('m', 'm'): // operator --
2576 opcode = unary_op[2] == '_' ? PREDECREMENT_EXPR : POSTDECREMENT_EXPR;
2577 break;
2578 case CHARS2 ('n', 'x'): // noexcept
2579 opcode = NOEXCEPT_EXPR;
2580 break;
2581 case CHARS2 ('t', 'w'): // throw
2582 gcc_assert (op0);
2583 opcode = THROW_EXPR;
2584 break;
2585 case CHARS2 ('t', 'r'): // rethrow
2586 gcc_assert (!op0);
2587 opcode = THROW_EXPR;
2588 break;
2589 case CHARS2 ('t', 'e'): // typeid (value)
2590 opcode = TYPEID_EXPR;
2591 break;
2592 case CHARS2 ('s', 'z'): // sizeof (value)
2593 opcode = SIZEOF_EXPR;
2594 break;
2595 case CHARS2 ('a', 'z'): // alignof (value)
2596 opcode = ALIGNOF_EXPR;
2597 break;
2598 case CHARS2 ('g', 's'): // global scope (for delete, delete[])
2599 gcc_assert (!global_scope_p);
2600 global_scope_p = true;
2601 unary_op += 2;
2602 goto once_more;
2603 case CHARS2 ('d', 'l'): // delete
2604 opcode = DELETE_EXPR;
2605 break;
2606 case CHARS2 ('d', 'a'): // delete[]
2607 opcode = VEC_DELETE_EXPR;
2608 break;
2609 case CHARS2 ('s', 'p'): // pack...
2610 opcode = EXPR_PACK_EXPANSION;
2611 break;
2612 case CHARS2 ('s', 'Z'): // sizeof...(pack)
2613 opcode = TYPE_PACK_EXPANSION; // Not really, but let's use its code.
2614 break;
2616 /* FIXME: __real__, __imag__? */
2618 default:
2619 gcc_unreachable ();
2622 gcc_assert (!global_scope_p
2623 || opcode == DELETE_EXPR || opcode == VEC_DELETE_EXPR);
2625 processing_template_decl++;
2626 bool template_dependent_p = op0
2627 && (type_dependent_expression_p (op0)
2628 || value_dependent_expression_p (op0));
2629 if (!template_dependent_p)
2630 processing_template_decl--;
2632 tree result;
2634 gcc_assert (op0 || opcode == THROW_EXPR);
2636 switch (opcode)
2638 case NOEXCEPT_EXPR:
2639 result = finish_noexcept_expr (op0, tf_error);
2640 break;
2642 case THROW_EXPR:
2643 result = build_throw (input_location, op0);
2644 break;
2646 case TYPEID_EXPR:
2647 result = build_typeid (op0, tf_error);
2648 break;
2650 case SIZEOF_EXPR:
2651 case ALIGNOF_EXPR:
2652 result = cxx_sizeof_or_alignof_expr (input_location,
2653 op0, opcode, true, true);
2654 break;
2656 case DELETE_EXPR:
2657 case VEC_DELETE_EXPR:
2658 result = delete_sanity (input_location, op0, NULL_TREE,
2659 opcode == VEC_DELETE_EXPR,
2660 global_scope_p, tf_error);
2661 break;
2663 case EXPR_PACK_EXPANSION:
2664 result = make_pack_expansion (op0);
2665 break;
2667 // We're using this for sizeof...(pack). */
2668 case TYPE_PACK_EXPANSION:
2669 result = make_pack_expansion (op0);
2670 PACK_EXPANSION_SIZEOF_P (result) = true;
2671 break;
2673 default:
2674 result = build_x_unary_op (/*loc=*/0, opcode, op0, NULL_TREE, tf_error);
2675 break;
2678 if (template_dependent_p)
2679 processing_template_decl--;
2681 return convert_out (ctx->preserve (result));
2684 gcc_expr
2685 plugin_build_binary_expr (cc1_plugin::connection *self,
2686 const char *binary_op,
2687 gcc_expr operand1,
2688 gcc_expr operand2)
2690 plugin_context *ctx = static_cast<plugin_context *> (self);
2691 tree op0 = convert_in (operand1);
2692 tree op1 = convert_in (operand2);
2693 tree_code opcode = ERROR_MARK;
2695 switch (CHARS2 (binary_op[0], binary_op[1]))
2697 case CHARS2 ('p', 'l'): // operator +
2698 opcode = PLUS_EXPR;
2699 break;
2700 case CHARS2 ('m', 'i'): // operator -
2701 opcode = MINUS_EXPR;
2702 break;
2703 case CHARS2 ('m', 'l'): // operator *
2704 opcode = MULT_EXPR;
2705 break;
2706 case CHARS2 ('d', 'v'): // operator /
2707 opcode = TRUNC_DIV_EXPR;
2708 break;
2709 case CHARS2 ('r', 'm'): // operator %
2710 opcode = TRUNC_MOD_EXPR;
2711 break;
2712 case CHARS2 ('a', 'n'): // operator &
2713 opcode = BIT_AND_EXPR;
2714 break;
2715 case CHARS2 ('o', 'r'): // operator |
2716 opcode = BIT_IOR_EXPR;
2717 break;
2718 case CHARS2 ('e', 'o'): // operator ^
2719 opcode = BIT_XOR_EXPR;
2720 break;
2721 case CHARS2 ('l', 's'): // operator <<
2722 opcode = LSHIFT_EXPR;
2723 break;
2724 case CHARS2 ('r', 's'): // operator >>
2725 opcode = RSHIFT_EXPR;
2726 break;
2727 case CHARS2 ('e', 'q'): // operator ==
2728 opcode = EQ_EXPR;
2729 break;
2730 case CHARS2 ('n', 'e'): // operator !=
2731 opcode = NE_EXPR;
2732 break;
2733 case CHARS2 ('l', 't'): // operator <
2734 opcode = LT_EXPR;
2735 break;
2736 case CHARS2 ('g', 't'): // operator >
2737 opcode = GT_EXPR;
2738 break;
2739 case CHARS2 ('l', 'e'): // operator <=
2740 opcode = LE_EXPR;
2741 break;
2742 case CHARS2 ('g', 'e'): // operator >=
2743 opcode = GE_EXPR;
2744 break;
2745 case CHARS2 ('a', 'a'): // operator &&
2746 opcode = TRUTH_ANDIF_EXPR;
2747 break;
2748 case CHARS2 ('o', 'o'): // operator ||
2749 opcode = TRUTH_ORIF_EXPR;
2750 break;
2751 case CHARS2 ('c', 'm'): // operator ,
2752 opcode = COMPOUND_EXPR;
2753 break;
2754 case CHARS2 ('p', 'm'): // operator ->*
2755 opcode = MEMBER_REF;
2756 break;
2757 case CHARS2 ('p', 't'): // operator ->
2758 opcode = INDIRECT_REF; // Not really! This will stand for
2759 // INDIRECT_REF followed by COMPONENT_REF
2760 // later on.
2761 break;
2762 case CHARS2 ('i', 'x'): // operator []
2763 opcode = ARRAY_REF;
2764 break;
2765 case CHARS2 ('d', 's'): // operator .*
2766 opcode = DOTSTAR_EXPR;
2767 break;
2768 case CHARS2 ('d', 't'): // operator .
2769 opcode = COMPONENT_REF;
2770 break;
2772 default:
2773 gcc_unreachable ();
2776 processing_template_decl++;
2777 bool template_dependent_p = type_dependent_expression_p (op0)
2778 || value_dependent_expression_p (op0)
2779 || type_dependent_expression_p (op1)
2780 || value_dependent_expression_p (op1);
2781 if (!template_dependent_p)
2782 processing_template_decl--;
2784 tree result;
2786 switch (opcode)
2788 case INDIRECT_REF: // This is actually a "->".
2789 op0 = build_x_arrow (/*loc=*/0, op0, tf_error);
2790 /* Fall through. */
2791 case COMPONENT_REF:
2792 result = finish_class_member_access_expr (op0, op1,
2793 /*template_p=*/false,
2794 tf_error);
2795 break;
2797 default:
2798 result = build_x_binary_op (/*loc=*/0, opcode, op0, ERROR_MARK,
2799 op1, ERROR_MARK, NULL_TREE, NULL, tf_error);
2800 break;
2803 if (template_dependent_p)
2804 processing_template_decl--;
2806 return convert_out (ctx->preserve (result));
2809 gcc_expr
2810 plugin_build_ternary_expr (cc1_plugin::connection *self,
2811 const char *ternary_op,
2812 gcc_expr operand1,
2813 gcc_expr operand2,
2814 gcc_expr operand3)
2816 plugin_context *ctx = static_cast<plugin_context *> (self);
2817 tree op0 = convert_in (operand1);
2818 tree op1 = convert_in (operand2);
2819 tree op2 = convert_in (operand3);
2820 gcc_assert (CHARS2 (ternary_op[0], ternary_op[1])
2821 == CHARS2 ('q', 'u')); // ternary operator
2823 processing_template_decl++;
2824 bool template_dependent_p = type_dependent_expression_p (op0)
2825 || value_dependent_expression_p (op0)
2826 || type_dependent_expression_p (op1)
2827 || value_dependent_expression_p (op1)
2828 || type_dependent_expression_p (op2)
2829 || value_dependent_expression_p (op2);
2830 if (!template_dependent_p)
2831 processing_template_decl--;
2833 tree val = build_x_conditional_expr (/*loc=*/0, op0, op1, op2, tf_error);
2835 if (template_dependent_p)
2836 processing_template_decl--;
2838 return convert_out (ctx->preserve (val));
2841 gcc_expr
2842 plugin_build_unary_type_expr (cc1_plugin::connection *self,
2843 const char *unary_op,
2844 gcc_type operand)
2846 plugin_context *ctx = static_cast<plugin_context *> (self);
2847 tree type = convert_in (operand);
2848 tree_code opcode = ERROR_MARK;
2850 switch (CHARS2 (unary_op[0], unary_op[1]))
2852 case CHARS2 ('t', 'i'): // typeid (type)
2853 opcode = TYPEID_EXPR;
2854 break;
2856 case CHARS2 ('s', 't'): // sizeof (type)
2857 opcode = SIZEOF_EXPR;
2858 break;
2859 case CHARS2 ('a', 't'): // alignof (type)
2860 opcode = ALIGNOF_EXPR;
2861 break;
2863 case CHARS2 ('s', 'Z'): // sizeof...(pack)
2864 opcode = TYPE_PACK_EXPANSION; // Not really, but let's use its code.
2865 break;
2867 // FIXME: do we have to handle "sp", for the size of a captured
2868 // template parameter pack from an alias template, taking
2869 // multiple template arguments?
2871 default:
2872 gcc_unreachable ();
2875 processing_template_decl++;
2876 bool template_dependent_p = dependent_type_p (type);
2877 if (!template_dependent_p)
2878 processing_template_decl--;
2880 tree result;
2882 switch (opcode)
2884 case TYPEID_EXPR:
2885 result = get_typeid (type, tf_error);
2886 break;
2888 // We're using this for sizeof...(pack). */
2889 case TYPE_PACK_EXPANSION:
2890 result = make_pack_expansion (type);
2891 PACK_EXPANSION_SIZEOF_P (result) = true;
2892 break;
2894 default:
2895 /* Use the C++11 alignof semantics. */
2896 result = cxx_sizeof_or_alignof_type (input_location, type,
2897 opcode, true, true);
2900 if (template_dependent_p)
2901 processing_template_decl--;
2903 return convert_out (ctx->preserve (result));
2906 gcc_expr
2907 plugin_build_cast_expr (cc1_plugin::connection *self,
2908 const char *binary_op,
2909 gcc_type operand1,
2910 gcc_expr operand2)
2912 plugin_context *ctx = static_cast<plugin_context *> (self);
2913 tree (*build_cast)(location_t loc, tree type, tree expr,
2914 tsubst_flags_t complain) = NULL;
2915 tree type = convert_in (operand1);
2916 tree expr = convert_in (operand2);
2918 switch (CHARS2 (binary_op[0], binary_op[1]))
2920 case CHARS2 ('d', 'c'): // dynamic_cast
2921 build_cast = build_dynamic_cast;
2922 break;
2924 case CHARS2 ('s', 'c'): // static_cast
2925 build_cast = build_static_cast;
2926 break;
2928 case CHARS2 ('c', 'c'): // const_cast
2929 build_cast = build_const_cast;
2930 break;
2932 case CHARS2 ('r', 'c'): // reinterpret_cast
2933 build_cast = build_reinterpret_cast;
2934 break;
2936 case CHARS2 ('c', 'v'): // C cast, conversion with one argument
2937 build_cast = cp_build_c_cast;
2938 break;
2940 default:
2941 gcc_unreachable ();
2944 processing_template_decl++;
2945 bool template_dependent_p = dependent_type_p (type)
2946 || type_dependent_expression_p (expr)
2947 || value_dependent_expression_p (expr);
2948 if (!template_dependent_p)
2949 processing_template_decl--;
2951 tree val = build_cast (input_location, type, expr, tf_error);
2953 if (template_dependent_p)
2954 processing_template_decl--;
2956 return convert_out (ctx->preserve (val));
2959 static inline vec<tree, va_gc> *
2960 args_to_tree_vec (const struct gcc_cp_function_args *args_in)
2962 vec<tree, va_gc> *args = make_tree_vector ();
2963 for (int i = 0; i < args_in->n_elements; i++)
2964 vec_safe_push (args, convert_in (args_in->elements[i]));
2965 return args;
2968 static inline tree
2969 args_to_tree_list (const struct gcc_cp_function_args *args_in)
2971 tree args, *tail = &args;
2972 for (int i = 0; i < args_in->n_elements; i++)
2974 *tail = build_tree_list (NULL, convert_in (args_in->elements[i]));
2975 tail = &TREE_CHAIN (*tail);
2977 return args;
2980 static inline vec<constructor_elt, va_gc> *
2981 args_to_ctor_elts (const struct gcc_cp_function_args *args_in)
2983 vec<constructor_elt, va_gc> *args = NULL;
2984 for (int i = 0; i < args_in->n_elements; i++)
2985 CONSTRUCTOR_APPEND_ELT (args, NULL_TREE, convert_in (args_in->elements[i]));
2986 return args;
2989 gcc_expr
2990 plugin_build_expression_list_expr (cc1_plugin::connection *self,
2991 const char *conv_op,
2992 gcc_type type_in,
2993 const struct gcc_cp_function_args *values_in)
2995 plugin_context *ctx = static_cast<plugin_context *> (self);
2996 tree type = convert_in (type_in);
2997 tree args;
2998 tree result;
3000 switch (CHARS2 (conv_op[0], conv_op[1]))
3002 case CHARS2 ('c', 'v'): // conversion with parenthesized expression list
3003 gcc_assert (TYPE_P (type));
3004 args = args_to_tree_list (values_in);
3005 result = build_functional_cast (input_location, type, args, tf_error);
3006 break;
3008 case CHARS2 ('t', 'l'): // conversion with braced expression list
3009 gcc_assert (type);
3010 gcc_assert (TYPE_P (type));
3011 args = make_node (CONSTRUCTOR);
3012 CONSTRUCTOR_ELTS (args) = args_to_ctor_elts (values_in);
3013 CONSTRUCTOR_IS_DIRECT_INIT (args) = 1;
3014 result = finish_compound_literal (type, args, tf_error);
3015 break;
3017 case CHARS2 ('i', 'l'): // untyped braced expression list
3018 gcc_assert (!type);
3019 result = make_node (CONSTRUCTOR);
3020 CONSTRUCTOR_ELTS (result) = args_to_ctor_elts (values_in);
3021 break;
3023 default:
3024 gcc_unreachable ();
3027 return convert_out (ctx->preserve (result));
3030 gcc_expr
3031 plugin_build_new_expr (cc1_plugin::connection *self,
3032 const char *new_op,
3033 const struct gcc_cp_function_args *placement_in,
3034 gcc_type type_in,
3035 const struct gcc_cp_function_args *initializer_in)
3037 plugin_context *ctx = static_cast<plugin_context *> (self);
3038 tree type = convert_in (type_in);
3039 vec<tree, va_gc> *placement = NULL, *initializer = NULL;
3040 bool global_scope_p = false;
3041 tree nelts = NULL;
3043 if (placement_in)
3044 placement = args_to_tree_vec (placement_in);
3045 if (initializer_in)
3046 initializer = args_to_tree_vec (initializer_in);
3048 gcc_assert (TYPE_P (type));
3050 once_more:
3051 switch (CHARS2 (new_op[0], new_op[1]))
3053 case CHARS2 ('g', 's'):
3054 gcc_assert (!global_scope_p);
3055 global_scope_p = true;
3056 new_op += 2;
3057 goto once_more;
3059 case CHARS2 ('n', 'w'): // non-array new
3060 gcc_assert (TREE_CODE (type) != ARRAY_TYPE);
3061 break;
3063 case CHARS2 ('n', 'a'): // array new
3064 gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
3065 gcc_assert (TYPE_DOMAIN (type));
3067 // Compute the length of the outermost array type, then discard it.
3068 tree maxelt = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
3069 tree eltype = TREE_TYPE (maxelt);
3070 tree onecst = integer_one_node;
3072 processing_template_decl++;
3073 bool template_dependent_p = value_dependent_expression_p (maxelt)
3074 || type_dependent_expression_p (maxelt);
3075 if (!template_dependent_p)
3077 processing_template_decl--;
3078 onecst = fold_convert (eltype, onecst);
3081 nelts = fold_build2 (PLUS_EXPR, eltype, nelts, onecst);
3083 if (template_dependent_p)
3084 processing_template_decl--;
3086 type = TREE_TYPE (type);
3088 break;
3090 default:
3091 gcc_unreachable ();
3094 processing_template_decl++;
3095 bool template_dependent_p = dependent_type_p (type)
3096 || value_dependent_expression_p (nelts)
3097 || (placement
3098 && any_type_dependent_arguments_p (placement))
3099 || (initializer
3100 && any_type_dependent_arguments_p (initializer));
3101 if (!template_dependent_p)
3102 processing_template_decl--;
3104 tree result = build_new (input_location, &placement, type, nelts,
3105 &initializer, global_scope_p, tf_error);
3107 if (template_dependent_p)
3108 processing_template_decl--;
3110 if (placement != NULL)
3111 release_tree_vector (placement);
3112 if (initializer != NULL)
3113 release_tree_vector (initializer);
3115 return convert_out (ctx->preserve (result));
3118 gcc_expr
3119 plugin_build_call_expr (cc1_plugin::connection *self,
3120 gcc_expr callable_in, int qualified_p,
3121 const struct gcc_cp_function_args *args_in)
3123 plugin_context *ctx = static_cast<plugin_context *> (self);
3124 tree callable = convert_in (callable_in);
3125 tree call_expr;
3127 vec<tree, va_gc> *args = args_to_tree_vec (args_in);
3129 bool koenig_p = false;
3130 if (!qualified_p && !args->is_empty ())
3132 if (identifier_p (callable))
3133 koenig_p = true;
3134 else if (is_overloaded_fn (callable))
3136 tree fn = get_first_fn (callable);
3137 fn = STRIP_TEMPLATE (fn);
3139 if (!DECL_FUNCTION_MEMBER_P (fn)
3140 && !DECL_LOCAL_DECL_P (fn))
3141 koenig_p = true;
3145 if (koenig_p && !any_type_dependent_arguments_p (args))
3146 callable = perform_koenig_lookup (callable, args, tf_none);
3148 if (TREE_CODE (callable) == COMPONENT_REF)
3150 tree object = TREE_OPERAND (callable, 0);
3151 tree memfn = TREE_OPERAND (callable, 1);
3153 if (type_dependent_expression_p (object)
3154 || (!BASELINK_P (memfn) && TREE_CODE (memfn) != FIELD_DECL)
3155 || type_dependent_expression_p (memfn)
3156 || any_type_dependent_arguments_p (args))
3157 call_expr = build_nt_call_vec (callable, args);
3158 else if (BASELINK_P (memfn))
3159 call_expr = build_new_method_call (object, memfn, &args, NULL_TREE,
3160 qualified_p
3161 ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
3162 : LOOKUP_NORMAL,
3163 NULL, tf_none);
3164 else
3165 call_expr = finish_call_expr (callable, &args, false, false, tf_none);
3167 else if (TREE_CODE (callable) == OFFSET_REF
3168 || TREE_CODE (callable) == MEMBER_REF
3169 || TREE_CODE (callable) == DOTSTAR_EXPR)
3170 call_expr = build_offset_ref_call_from_tree (callable, &args, tf_none);
3171 else
3172 call_expr = finish_call_expr (callable, &args,
3173 !!qualified_p, koenig_p, tf_none);
3175 release_tree_vector (args);
3176 return convert_out (ctx->preserve (call_expr));
3179 gcc_type
3180 plugin_get_expr_type (cc1_plugin::connection *self,
3181 gcc_expr operand)
3183 plugin_context *ctx = static_cast<plugin_context *> (self);
3184 tree op0 = convert_in (operand);
3185 tree type;
3186 if (op0)
3187 type = TREE_TYPE (op0);
3188 else
3189 type = make_decltype_auto ();
3190 return convert_out (ctx->preserve (type));
3193 gcc_decl
3194 plugin_build_function_template_specialization (cc1_plugin::connection *self,
3195 gcc_decl template_decl,
3196 const gcc_cp_template_args *targs,
3197 gcc_address address,
3198 const char *filename,
3199 unsigned int line_number)
3201 plugin_context *ctx = static_cast<plugin_context *> (self);
3202 location_t loc = ctx->get_location_t (filename, line_number);
3203 tree name = convert_in (template_decl);
3204 tree targsl = targlist (targs);
3206 tree decl = tsubst (name, targsl, tf_error, NULL_TREE);
3207 DECL_SOURCE_LOCATION (decl) = loc;
3209 record_decl_address (ctx, build_decl_addr_value (decl, address));
3211 return convert_out (ctx->preserve (decl));
3214 gcc_decl
3215 plugin_build_class_template_specialization (cc1_plugin::connection *self,
3216 gcc_decl template_decl,
3217 const gcc_cp_template_args *args,
3218 const char *filename,
3219 unsigned int line_number)
3221 plugin_context *ctx = static_cast<plugin_context *> (self);
3222 location_t loc = ctx->get_location_t (filename, line_number);
3223 tree name = convert_in (template_decl);
3225 tree tdecl = finish_template_type (name, targlist (args), false);;
3226 DECL_SOURCE_LOCATION (tdecl) = loc;
3228 return convert_out (ctx->preserve (tdecl));
3231 /* Return a builtin type associated with BUILTIN_NAME. */
3233 static tree
3234 safe_lookup_builtin_type (const char *builtin_name)
3236 tree result = NULL_TREE;
3238 if (!builtin_name)
3239 return result;
3241 result = identifier_global_value (get_identifier (builtin_name));
3243 if (!result)
3244 return result;
3246 gcc_assert (TREE_CODE (result) == TYPE_DECL);
3247 result = TREE_TYPE (result);
3248 return result;
3251 gcc_type
3252 plugin_get_int_type (cc1_plugin::connection *self,
3253 int is_unsigned, unsigned long size_in_bytes,
3254 const char *builtin_name)
3256 tree result;
3258 if (builtin_name)
3260 result = safe_lookup_builtin_type (builtin_name);
3261 gcc_assert (!result || TREE_CODE (result) == INTEGER_TYPE);
3263 else
3264 result = c_common_type_for_size (BITS_PER_UNIT * size_in_bytes,
3265 is_unsigned);
3267 if (result == NULL_TREE)
3268 result = error_mark_node;
3269 else
3271 gcc_assert (!TYPE_UNSIGNED (result) == !is_unsigned);
3272 gcc_assert (TREE_CODE (TYPE_SIZE (result)) == INTEGER_CST);
3273 gcc_assert (TYPE_PRECISION (result) == BITS_PER_UNIT * size_in_bytes);
3275 plugin_context *ctx = static_cast<plugin_context *> (self);
3276 ctx->preserve (result);
3278 return convert_out (result);
3281 gcc_type
3282 plugin_get_char_type (cc1_plugin::connection *)
3284 return convert_out (char_type_node);
3287 gcc_type
3288 plugin_get_float_type (cc1_plugin::connection *,
3289 unsigned long size_in_bytes,
3290 const char *builtin_name)
3292 if (builtin_name)
3294 tree result = safe_lookup_builtin_type (builtin_name);
3296 if (!result)
3297 return convert_out (error_mark_node);
3299 gcc_assert (SCALAR_FLOAT_TYPE_P (result));
3300 gcc_assert (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (result));
3302 return convert_out (result);
3305 if (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (float_type_node))
3306 return convert_out (float_type_node);
3307 if (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (double_type_node))
3308 return convert_out (double_type_node);
3309 if (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (long_double_type_node))
3310 return convert_out (long_double_type_node);
3311 return convert_out (error_mark_node);
3314 gcc_type
3315 plugin_get_void_type (cc1_plugin::connection *)
3317 return convert_out (void_type_node);
3320 gcc_type
3321 plugin_get_bool_type (cc1_plugin::connection *)
3323 return convert_out (boolean_type_node);
3326 gcc_type
3327 plugin_get_nullptr_type (cc1_plugin::connection *)
3329 return convert_out (nullptr_type_node);
3332 gcc_expr
3333 plugin_get_nullptr_constant (cc1_plugin::connection *)
3335 return convert_out (nullptr_node);
3338 gcc_type
3339 plugin_build_array_type (cc1_plugin::connection *self,
3340 gcc_type element_type_in, int num_elements)
3342 tree element_type = convert_in (element_type_in);
3343 tree result;
3345 if (num_elements == -1)
3346 result = build_array_type (element_type, NULL_TREE);
3347 else
3348 result = build_array_type_nelts (element_type, num_elements);
3350 plugin_context *ctx = static_cast<plugin_context *> (self);
3351 return convert_out (ctx->preserve (result));
3354 gcc_type
3355 plugin_build_dependent_array_type (cc1_plugin::connection *self,
3356 gcc_type element_type_in,
3357 gcc_expr num_elements_in)
3359 plugin_context *ctx = static_cast<plugin_context *> (self);
3360 tree element_type = convert_in (element_type_in);
3361 tree size = convert_in (num_elements_in);
3362 tree name = get_identifier ("dependent array type");
3364 processing_template_decl++;
3365 bool template_dependent_p = dependent_type_p (element_type)
3366 || type_dependent_expression_p (size)
3367 || value_dependent_expression_p (size);
3368 if (!template_dependent_p)
3369 processing_template_decl--;
3371 tree itype = compute_array_index_type (name, size, tf_error);
3372 tree type = build_cplus_array_type (element_type, itype);
3374 if (template_dependent_p)
3375 processing_template_decl--;
3377 return convert_out (ctx->preserve (type));
3380 gcc_type
3381 plugin_build_vla_array_type (cc1_plugin::connection *self,
3382 gcc_type element_type_in,
3383 const char *upper_bound_name)
3385 tree element_type = convert_in (element_type_in);
3386 tree upper_bound = lookup_name (get_identifier (upper_bound_name));
3387 tree size = fold_build2 (PLUS_EXPR, TREE_TYPE (upper_bound), upper_bound,
3388 build_one_cst (TREE_TYPE (upper_bound)));
3389 tree range = compute_array_index_type (NULL_TREE, size,
3390 tf_error);
3392 tree result = build_cplus_array_type (element_type, range);
3394 plugin_context *ctx = static_cast<plugin_context *> (self);
3395 return convert_out (ctx->preserve (result));
3398 gcc_type
3399 plugin_build_qualified_type (cc1_plugin::connection *,
3400 gcc_type unqualified_type_in,
3401 enum gcc_cp_qualifiers qualifiers)
3403 tree unqualified_type = convert_in (unqualified_type_in);
3404 cp_cv_quals quals = 0;
3406 if ((qualifiers & GCC_CP_QUALIFIER_CONST) != 0)
3407 quals |= TYPE_QUAL_CONST;
3408 if ((qualifiers & GCC_CP_QUALIFIER_VOLATILE) != 0)
3409 quals |= TYPE_QUAL_VOLATILE;
3410 if ((qualifiers & GCC_CP_QUALIFIER_RESTRICT) != 0)
3411 quals |= TYPE_QUAL_RESTRICT;
3413 gcc_assert ((TREE_CODE (unqualified_type) != METHOD_TYPE
3414 && TREE_CODE (unqualified_type) != REFERENCE_TYPE)
3415 || quals == 0);
3417 return convert_out (build_qualified_type (unqualified_type, quals));
3420 gcc_type
3421 plugin_build_complex_type (cc1_plugin::connection *self,
3422 gcc_type base_type)
3424 plugin_context *ctx = static_cast<plugin_context *> (self);
3425 return convert_out (ctx->preserve (build_complex_type (convert_in (base_type))));
3428 gcc_type
3429 plugin_build_vector_type (cc1_plugin::connection *self,
3430 gcc_type base_type, int nunits)
3432 plugin_context *ctx = static_cast<plugin_context *> (self);
3433 return convert_out (ctx->preserve (build_vector_type (convert_in (base_type),
3434 nunits)));
3438 plugin_build_constant (cc1_plugin::connection *self, gcc_type type_in,
3439 const char *name, unsigned long value,
3440 const char *filename, unsigned int line_number)
3442 plugin_context *ctx = static_cast<plugin_context *> (self);
3443 tree cst, decl;
3444 tree type = convert_in (type_in);
3446 cst = build_int_cst (type, value);
3447 if (!TYPE_READONLY (type))
3448 type = build_qualified_type (type, TYPE_QUAL_CONST);
3449 decl = build_decl (ctx->get_location_t (filename, line_number),
3450 VAR_DECL, get_identifier (name), type);
3451 TREE_STATIC (decl) = 1;
3452 TREE_READONLY (decl) = 1;
3453 cp_finish_decl (decl, cst, true, NULL, LOOKUP_ONLYCONVERTING);
3454 safe_pushdecl (decl);
3456 return 1;
3459 gcc_type
3460 plugin_error (cc1_plugin::connection *,
3461 const char *message)
3463 error ("%s", message);
3464 return convert_out (error_mark_node);
3468 plugin_add_static_assert (cc1_plugin::connection *self,
3469 gcc_expr condition_in,
3470 const char *errormsg,
3471 const char *filename,
3472 unsigned int line_number)
3474 plugin_context *ctx = static_cast<plugin_context *> (self);
3475 tree condition = convert_in (condition_in);
3477 if (!errormsg)
3478 errormsg = "";
3480 tree message = build_string (strlen (errormsg) + 1, errormsg);
3482 TREE_TYPE (message) = char_array_type_node;
3483 fix_string_type (message);
3485 location_t loc = ctx->get_location_t (filename, line_number);
3487 bool member_p = at_class_scope_p ();
3489 finish_static_assert (condition, message, loc, member_p, false);
3491 return 1;
3496 #ifdef __GNUC__
3497 #pragma GCC visibility push(default)
3498 #endif
3501 plugin_init (struct plugin_name_args *plugin_info,
3502 struct plugin_gcc_version *)
3504 generic_plugin_init (plugin_info, GCC_CP_FE_VERSION_0);
3506 register_callback (plugin_info->base_name, PLUGIN_PRAGMAS,
3507 plugin_init_extra_pragmas, NULL);
3508 register_callback (plugin_info->base_name, PLUGIN_PRE_GENERICIZE,
3509 rewrite_decls_to_addresses, NULL);
3511 #define GCC_METHOD0(R, N) \
3513 cc1_plugin::callback_ftype *fun \
3514 = cc1_plugin::invoker<R>::invoke<plugin_ ## N>; \
3515 current_context->add_callback (# N, fun); \
3517 #define GCC_METHOD1(R, N, A) \
3519 cc1_plugin::callback_ftype *fun \
3520 = cc1_plugin::invoker<R, A>::invoke<plugin_ ## N>; \
3521 current_context->add_callback (# N, fun); \
3523 #define GCC_METHOD2(R, N, A, B) \
3525 cc1_plugin::callback_ftype *fun \
3526 = cc1_plugin::invoker<R, A, B>::invoke<plugin_ ## N>; \
3527 current_context->add_callback (# N, fun); \
3529 #define GCC_METHOD3(R, N, A, B, C) \
3531 cc1_plugin::callback_ftype *fun \
3532 = cc1_plugin::invoker<R, A, B, C>::invoke<plugin_ ## N>; \
3533 current_context->add_callback (# N, fun); \
3535 #define GCC_METHOD4(R, N, A, B, C, D) \
3537 cc1_plugin::callback_ftype *fun \
3538 = cc1_plugin::invoker<R, A, B, C, \
3539 D>::invoke<plugin_ ## N>; \
3540 current_context->add_callback (# N, fun); \
3542 #define GCC_METHOD5(R, N, A, B, C, D, E) \
3544 cc1_plugin::callback_ftype *fun \
3545 = cc1_plugin::invoker<R, A, B, C, \
3546 D, E>::invoke<plugin_ ## N>; \
3547 current_context->add_callback (# N, fun); \
3549 #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
3551 cc1_plugin::callback_ftype *fun \
3552 = cc1_plugin::invoker<R, A, B, C, \
3553 D, E, F, G>::invoke<plugin_ ## N>; \
3554 current_context->add_callback (# N, fun); \
3557 #include "gcc-cp-fe.def"
3559 #undef GCC_METHOD0
3560 #undef GCC_METHOD1
3561 #undef GCC_METHOD2
3562 #undef GCC_METHOD3
3563 #undef GCC_METHOD4
3564 #undef GCC_METHOD5
3565 #undef GCC_METHOD7
3567 return 0;