1 /* Library interface to C++ front end.
2 Copyright (C) 2014-2022 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
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
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>
25 #undef PACKAGE_TARNAME
26 #undef PACKAGE_VERSION
28 #include "../gcc/config.h"
32 #undef PACKAGE_TARNAME
33 #undef PACKAGE_VERSION
35 #include "gcc-plugin.h"
37 #include "coretypes.h"
38 #include "stringpool.h"
40 #include "gcc-interface.h"
43 #include "double-int.h"
51 #include "fold-const.h"
52 #include "stor-layout.h"
56 #include "hash-table.h"
58 #include "c-family/c-pragma.h"
59 // #include "c-lang.h"
60 #include "diagnostic.h"
61 #include "langhooks.h"
62 #include "langhooks-def.h"
65 #undef cfun // we want to assign to it, and function.h won't let us
67 #include "callbacks.hh"
68 #include "connection.hh"
69 #include "marshall-cp.hh"
75 using namespace cc1_plugin
;
79 static_assert (GCC_CP_SYMBOL_MASK
>= GCC_CP_SYMBOL_END
,
80 "GCC_CP_SYMBOL_MASK >= GCC_CP_SYMBOL_END");
85 plugin_binding_oracle (enum cp_oracle_request kind
, tree identifier
)
87 enum gcc_cp_oracle_request request
;
89 gcc_assert (current_context
!= NULL
);
93 case CP_ORACLE_IDENTIFIER
:
94 request
= GCC_CP_ORACLE_IDENTIFIER
;
101 cc1_plugin::call (current_context
, "binding_oracle", &ignore
,
102 request
, IDENTIFIER_POINTER (identifier
));
105 static int push_count
;
107 /* at_function_scope_p () tests cfun, indicating we're actually
108 compiling the function, but we don't even set it when pretending to
109 enter a function scope. We use this distinction to tell these two
110 cases apart: we don't want to define e.g. class names in the user
111 expression function's scope, when they're local to the original
112 function, because they'd get the wrong linkage name. */
115 at_fake_function_scope_p ()
117 return (!cfun
|| cfun
->decl
!= current_function_decl
)
118 && current_scope () == current_function_decl
;
122 push_fake_function (tree fndecl
, scope_kind kind
= sk_function_parms
)
124 current_function_decl
= fndecl
;
125 begin_scope (kind
, fndecl
);
127 begin_scope (sk_block
, NULL
);
133 if (toplevel_bindings_p () && current_namespace
== global_namespace
)
134 pop_from_top_level ();
135 else if (at_namespace_scope_p ())
137 else if (at_class_scope_p ())
141 gcc_assert (at_fake_function_scope_p ());
142 gcc_assert (!at_function_scope_p ());
143 gcc_assert (current_binding_level
->kind
== sk_block
144 && current_binding_level
->this_entity
== NULL
);
147 gcc_assert (current_binding_level
->this_entity
148 == current_function_decl
);
150 current_function_decl
= NULL
;
151 for (cp_binding_level
*scope
= current_binding_level
;
152 scope
; scope
= scope
->level_chain
)
153 if (scope
->kind
== sk_function_parms
)
155 current_function_decl
= scope
->this_entity
;
162 supplement_binding (cxx_binding
*binding
, tree decl
)
164 /* FIXME: this is pretty much a copy of supplement_binding_1 in
165 ../gcc/cp/name-lookup.c; the few replaced/removed bits are marked
167 tree bval
= binding
->value
;
169 tree target_bval
= strip_using_decl (bval
);
170 tree target_decl
= strip_using_decl (decl
);
172 if (TREE_CODE (target_decl
) == TYPE_DECL
&& DECL_ARTIFICIAL (target_decl
)
173 && target_decl
!= target_bval
174 && (TREE_CODE (target_bval
) != TYPE_DECL
175 /* We allow pushing an enum multiple times in a class
176 template in order to handle late matching of underlying
177 type on an opaque-enum-declaration followed by an
179 || (processing_template_decl
180 && TREE_CODE (TREE_TYPE (target_decl
)) == ENUMERAL_TYPE
181 && TREE_CODE (TREE_TYPE (target_bval
)) == ENUMERAL_TYPE
182 && (dependent_type_p (ENUM_UNDERLYING_TYPE
183 (TREE_TYPE (target_decl
)))
184 || dependent_type_p (ENUM_UNDERLYING_TYPE
185 (TREE_TYPE (target_bval
)))))))
186 /* The new name is the type name. */
187 binding
->type
= decl
;
188 else if (/* TARGET_BVAL is null when push_class_level_binding moves
189 an inherited type-binding out of the way to make room
190 for a new value binding. */
192 /* TARGET_BVAL is error_mark_node when TARGET_DECL's name
193 has been used in a non-class scope prior declaration.
194 In that case, we should have already issued a
195 diagnostic; for graceful error recovery purpose, pretend
196 this was the intended declaration for that name. */
197 || target_bval
== error_mark_node
198 /* If TARGET_BVAL is anticipated but has not yet been
199 declared, pretend it is not there at all. */
200 || (TREE_CODE (target_bval
) == FUNCTION_DECL
201 && DECL_IS_UNDECLARED_BUILTIN (target_bval
)))
202 binding
->value
= decl
;
203 else if (TREE_CODE (target_bval
) == TYPE_DECL
204 && DECL_ARTIFICIAL (target_bval
)
205 && target_decl
!= target_bval
206 && (TREE_CODE (target_decl
) != TYPE_DECL
207 || same_type_p (TREE_TYPE (target_decl
),
208 TREE_TYPE (target_bval
))))
210 /* The old binding was a type name. It was placed in
211 VALUE field because it was thought, at the point it was
212 declared, to be the only entity with such a name. Move the
213 type name into the type slot; it is now hidden by the new
215 binding
->type
= bval
;
216 binding
->value
= decl
;
217 binding
->value_is_inherited
= false;
219 else if (TREE_CODE (target_bval
) == TYPE_DECL
220 && TREE_CODE (target_decl
) == TYPE_DECL
221 && DECL_NAME (target_decl
) == DECL_NAME (target_bval
)
222 && binding
->scope
->kind
!= sk_class
223 && (same_type_p (TREE_TYPE (target_decl
), TREE_TYPE (target_bval
))
224 /* If either type involves template parameters, we must
225 wait until instantiation. */
226 || uses_template_parms (TREE_TYPE (target_decl
))
227 || uses_template_parms (TREE_TYPE (target_bval
))))
228 /* We have two typedef-names, both naming the same type to have
229 the same name. In general, this is OK because of:
233 In a given scope, a typedef specifier can be used to redefine
234 the name of any type declared in that scope to refer to the
235 type to which it already refers.
237 However, in class scopes, this rule does not apply due to the
238 stricter language in [class.mem] prohibiting redeclarations of
241 /* There can be two block-scope declarations of the same variable,
242 so long as they are `extern' declarations. However, there cannot
243 be two declarations of the same static data member:
247 A member shall not be declared twice in the
248 member-specification. */
249 else if (VAR_P (target_decl
)
250 && VAR_P (target_bval
)
251 && DECL_EXTERNAL (target_decl
) && DECL_EXTERNAL (target_bval
)
252 && !DECL_CLASS_SCOPE_P (target_decl
))
254 duplicate_decls (decl
, binding
->value
);
257 else if (TREE_CODE (decl
) == NAMESPACE_DECL
258 && TREE_CODE (bval
) == NAMESPACE_DECL
259 && DECL_NAMESPACE_ALIAS (decl
)
260 && DECL_NAMESPACE_ALIAS (bval
)
261 && ORIGINAL_NAMESPACE (bval
) == ORIGINAL_NAMESPACE (decl
))
264 In a declarative region, a namespace-alias-definition can be
265 used to redefine a namespace-alias declared in that declarative
266 region to refer only to the namespace to which it already
271 // _1: diagnose_name_conflict (decl, bval);
275 gcc_assert (ok
); // _1: return ok;
279 reactivate_decl (tree decl
, cp_binding_level
*b
)
281 bool in_function_p
= TREE_CODE (b
->this_entity
) == FUNCTION_DECL
;
282 gcc_assert (in_function_p
283 || (b
== current_binding_level
284 && !at_class_scope_p ()));
286 tree id
= DECL_NAME (decl
);
287 tree type
= NULL_TREE
;
288 if (TREE_CODE (decl
) == TYPE_DECL
)
289 type
= TREE_TYPE (decl
);
291 if (type
&& TYPE_NAME (type
) == decl
292 && (RECORD_OR_UNION_CODE_P (TREE_CODE (type
))
293 || TREE_CODE (type
) == ENUMERAL_TYPE
))
295 gcc_assert (in_function_p
&& DECL_CONTEXT (decl
) == b
->this_entity
);
296 type
= TREE_TYPE (decl
);
300 gcc_assert (DECL_CONTEXT (decl
) == b
->this_entity
301 || DECL_CONTEXT (decl
) == global_namespace
302 || TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
);
306 /* Adjust IDENTIFIER_BINDING to what it would have been if we were
307 at binding level B. Save the binding chain up to that point in
308 [binding, *chainp), and take note of the outermost bindings found
310 cxx_binding
*binding
= IDENTIFIER_BINDING (id
), **chainp
= NULL
;
311 tree
*shadowing_type_p
= NULL
;
314 cp_binding_level
*bc
= current_binding_level
;
315 for (cxx_binding
*prev_binding
= binding
;
316 prev_binding
; prev_binding
= prev_binding
->previous
)
318 while (bc
!= b
&& bc
!= prev_binding
->scope
)
319 bc
= bc
->level_chain
;
326 chainp
= &prev_binding
->previous
;
328 for (tree tshadow
= prev_binding
->scope
->type_shadowed
;
329 tshadow
; tshadow
= TREE_CHAIN (tshadow
))
330 if (TREE_PURPOSE (tshadow
) == id
)
332 shadowing_type_p
= &TREE_VALUE (tshadow
);
339 IDENTIFIER_BINDING (id
) = *chainp
;
343 /* Like push_local_binding, supplement or add a binding to the
345 if (IDENTIFIER_BINDING (id
) && IDENTIFIER_BINDING (id
)->scope
== b
)
346 supplement_binding (IDENTIFIER_BINDING (id
), decl
);
348 push_binding (id
, decl
, b
);
350 /* Now restore the binding chain we'd temporarily removed. */
353 *chainp
= IDENTIFIER_BINDING (id
);
354 IDENTIFIER_BINDING (id
) = binding
;
358 /* Insert the new type binding in the shadowing_type_p
360 tree shadowed_type
= NULL_TREE
;
361 if (shadowing_type_p
)
363 shadowed_type
= *shadowing_type_p
;
364 *shadowing_type_p
= type
;
367 b
->type_shadowed
= tree_cons (id
, shadowed_type
, b
->type_shadowed
);
368 TREE_TYPE (b
->type_shadowed
) = type
;
373 /* Our new binding is the active one, so shadow the earlier
375 b
->type_shadowed
= tree_cons (id
, REAL_IDENTIFIER_TYPE_VALUE (id
),
377 TREE_TYPE (b
->type_shadowed
) = type
;
378 SET_IDENTIFIER_TYPE_VALUE (id
, type
);
381 /* Record that we have a binding for ID, like add_decl_to_level. */
382 tree node
= build_tree_list (NULL_TREE
, decl
);
383 TREE_CHAIN (node
) = b
->names
;
388 plugin_pragma_push_user_expression (cpp_reader
*)
393 gcc_assert (!current_class_ptr
);
394 gcc_assert (!current_class_ref
);
396 gcc_assert (!cp_binding_oracle
);
397 cp_binding_oracle
= plugin_binding_oracle
;
399 /* Make the function containing the user expression a global
400 friend, so as to bypass access controls in it. */
401 if (at_function_scope_p ())
402 set_global_friend (current_function_decl
);
404 gcc_assert (at_function_scope_p ());
405 function
*save_cfun
= cfun
;
406 cp_binding_level
*orig_binding_level
= current_binding_level
;
409 cc1_plugin::call (current_context
, "enter_scope", &success
);
411 gcc_assert (at_fake_function_scope_p () || at_function_scope_p ());
413 function
*unchanged_cfun
= cfun
;
414 tree changed_func_decl
= current_function_decl
;
416 gcc_assert (current_class_type
== DECL_CONTEXT (current_function_decl
)
417 || !(RECORD_OR_UNION_CODE_P
418 (TREE_CODE (DECL_CONTEXT (current_function_decl
)))));
419 push_fake_function (save_cfun
->decl
, sk_block
);
420 current_class_type
= NULL_TREE
;
423 /* If we get here, GDB did NOT change the context. */
424 gcc_assert (cfun
== save_cfun
);
425 gcc_assert (at_function_scope_p ());
426 gcc_assert (orig_binding_level
427 == current_binding_level
->level_chain
->level_chain
);
432 gcc_assert (at_function_scope_p ());
434 cp_binding_level
*b
= current_binding_level
->level_chain
;
435 gcc_assert (b
->this_entity
== cfun
->decl
);
437 /* Reactivate local names from the previous context. Use
438 IDENTIFIER_MARKED to avoid reactivating shadowed names. */
439 for (cp_binding_level
*level
= orig_binding_level
;;)
441 for (tree name
= level
->names
;
442 name
; name
= TREE_CHAIN (name
))
445 if (TREE_CODE (decl
) == TREE_LIST
)
446 decl
= TREE_VALUE (decl
);
447 if (IDENTIFIER_MARKED (DECL_NAME (decl
)))
449 IDENTIFIER_MARKED (DECL_NAME (decl
)) = 1;
450 reactivate_decl (decl
, b
);
452 if (level
->kind
== sk_function_parms
453 && level
->this_entity
== cfun
->decl
)
455 gcc_assert (!level
->this_entity
);
456 level
= level
->level_chain
;
459 /* Now, clear the markers. */
460 for (tree name
= b
->names
; name
; name
= TREE_CHAIN (name
))
463 if (TREE_CODE (decl
) == TREE_LIST
)
464 decl
= TREE_VALUE (decl
);
465 gcc_assert (IDENTIFIER_MARKED (DECL_NAME (decl
)));
466 IDENTIFIER_MARKED (DECL_NAME (decl
)) = 0;
470 if (unchanged_cfun
|| DECL_NONSTATIC_MEMBER_FUNCTION_P (changed_func_decl
))
472 /* Check whether the oracle supplies us with a "this", and if
473 so, arrange for data members and this itself to be
475 tree this_val
= lookup_name (get_identifier ("this"));
476 current_class_ref
= !this_val
? NULL_TREE
477 : cp_build_indirect_ref (input_location
, this_val
, RO_NULL
,
478 tf_warning_or_error
);
479 current_class_ptr
= this_val
;
484 plugin_pragma_pop_user_expression (cpp_reader
*)
489 gcc_assert (cp_binding_oracle
);
491 gcc_assert (at_function_scope_p ());
492 function
*save_cfun
= cfun
;
493 current_class_ptr
= NULL_TREE
;
494 current_class_ref
= NULL_TREE
;
498 if (RECORD_OR_UNION_CODE_P (TREE_CODE (DECL_CONTEXT (current_function_decl
))))
499 current_class_type
= DECL_CONTEXT (current_function_decl
);
502 cc1_plugin::call (current_context
, "leave_scope", &success
);
507 gcc_assert (cfun
== save_cfun
);
509 cp_binding_oracle
= NULL
;
510 gcc_assert (at_function_scope_p ());
514 plugin_init_extra_pragmas (void *, void *)
516 c_register_pragma ("GCC", "push_user_expression", plugin_pragma_push_user_expression
);
517 c_register_pragma ("GCC", "pop_user_expression", plugin_pragma_pop_user_expression
);
518 /* FIXME: this one should go once we get GDB to use push and pop. */
519 c_register_pragma ("GCC", "user_expression", plugin_pragma_push_user_expression
);
524 static decl_addr_value
525 build_decl_addr_value (tree decl
, gcc_address address
)
527 decl_addr_value value
= {
529 build_int_cst_type (ptr_type_node
, address
)
534 static decl_addr_value
*
535 record_decl_address (plugin_context
*ctx
, decl_addr_value value
)
537 decl_addr_value
**slot
= ctx
->address_map
.find_slot (&value
, INSERT
);
538 gcc_assert (*slot
== NULL
);
540 = static_cast<decl_addr_value
*> (xmalloc (sizeof (decl_addr_value
)));
542 /* We don't want GCC to warn about e.g. static functions
543 without a code definition. */
544 suppress_warning (value
.decl
);
548 // Maybe rewrite a decl to its address.
550 address_rewriter (tree
*in
, int *walk_subtrees
, void *arg
)
552 plugin_context
*ctx
= (plugin_context
*) arg
;
555 || TREE_CODE (*in
) == NAMESPACE_DECL
556 || DECL_NAME (*in
) == NULL_TREE
)
559 decl_addr_value value
;
561 decl_addr_value
*found_value
= ctx
->address_map
.find (&value
);
562 if (found_value
!= NULL
)
564 else if (HAS_DECL_ASSEMBLER_NAME_P (*in
))
568 if (!cc1_plugin::call (ctx
, "address_oracle", &address
,
569 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (*in
))))
574 // Insert the decl into the address map in case it is referenced
576 value
= build_decl_addr_value (value
.decl
, address
);
577 found_value
= record_decl_address (ctx
, value
);
582 if (found_value
->address
!= error_mark_node
)
584 // We have an address for the decl, so rewrite the tree.
585 tree ptr_type
= build_pointer_type (TREE_TYPE (*in
));
586 *in
= fold_build1 (INDIRECT_REF
, TREE_TYPE (*in
),
587 fold_build1 (CONVERT_EXPR
, ptr_type
,
588 found_value
->address
));
596 // When generating code for gdb, we want to be able to use absolute
597 // addresses to refer to otherwise external objects that gdb knows
598 // about. gdb passes in these addresses when building decls, and then
599 // before gimplification we go through the trees, rewriting uses to
600 // the equivalent of "*(TYPE *) ADDR".
602 rewrite_decls_to_addresses (void *function_in
, void *)
604 tree function
= (tree
) function_in
;
606 // Do nothing if we're not in gdb.
607 if (current_context
== NULL
)
610 walk_tree (&DECL_SAVED_TREE (function
), address_rewriter
, current_context
,
617 safe_push_template_decl (tree decl
)
619 void (*save_oracle
) (enum cp_oracle_request
, tree identifier
);
621 save_oracle
= cp_binding_oracle
;
622 cp_binding_oracle
= NULL
;
624 tree ret
= push_template_decl (decl
);
626 cp_binding_oracle
= save_oracle
;
632 safe_pushtag (tree name
, tree type
)
634 void (*save_oracle
) (enum cp_oracle_request
, tree identifier
);
636 save_oracle
= cp_binding_oracle
;
637 cp_binding_oracle
= NULL
;
639 tree ret
= pushtag (name
, type
);
641 cp_binding_oracle
= save_oracle
;
647 safe_pushdecl (tree decl
)
649 void (*save_oracle
) (enum cp_oracle_request
, tree identifier
);
651 save_oracle
= cp_binding_oracle
;
652 cp_binding_oracle
= NULL
;
654 tree ret
= pushdecl (decl
);
656 cp_binding_oracle
= save_oracle
;
664 plugin_push_namespace (cc1_plugin::connection
*,
668 push_to_top_level ();
670 push_namespace (name
? get_identifier (name
) : NULL
);
676 plugin_push_class (cc1_plugin::connection
*,
679 tree type
= convert_in (type_in
);
680 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (type
)));
681 gcc_assert (TYPE_CONTEXT (type
) == FROB_CONTEXT (current_scope ()));
689 plugin_push_function (cc1_plugin::connection
*,
690 gcc_decl function_decl_in
)
692 tree fndecl
= convert_in (function_decl_in
);
693 gcc_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
);
694 gcc_assert (DECL_CONTEXT (fndecl
) == FROB_CONTEXT (current_scope ()));
696 push_fake_function (fndecl
);
702 plugin_pop_binding_level (cc1_plugin::connection
*)
709 plugin_reactivate_decl (cc1_plugin::connection
*,
713 tree decl
= convert_in (decl_in
);
714 tree scope
= convert_in (scope_in
);
715 gcc_assert (TREE_CODE (decl
) == VAR_DECL
716 || TREE_CODE (decl
) == FUNCTION_DECL
717 || TREE_CODE (decl
) == TYPE_DECL
);
721 gcc_assert (TREE_CODE (scope
) == FUNCTION_DECL
);
722 for (b
= current_binding_level
;
723 b
->this_entity
!= scope
;
725 gcc_assert (b
->this_entity
!= global_namespace
);
729 gcc_assert (!at_class_scope_p ());
730 b
= current_binding_level
;
733 reactivate_decl (decl
, b
);
742 if (at_namespace_scope_p ())
743 decl
= current_namespace
;
744 else if (at_class_scope_p ())
745 decl
= TYPE_NAME (current_class_type
);
746 else if (at_fake_function_scope_p () || at_function_scope_p ())
747 decl
= current_function_decl
;
755 plugin_get_current_binding_level_decl (cc1_plugin::connection
*)
757 tree decl
= get_current_scope ();
759 return convert_out (decl
);
763 plugin_make_namespace_inline (cc1_plugin::connection
*)
765 tree inline_ns
= current_namespace
;
767 gcc_assert (toplevel_bindings_p ());
768 gcc_assert (inline_ns
!= global_namespace
);
770 tree parent_ns
= CP_DECL_CONTEXT (inline_ns
);
772 if (DECL_NAMESPACE_INLINE_P (inline_ns
))
775 DECL_NAMESPACE_INLINE_P (inline_ns
) = true;
776 vec_safe_push (DECL_NAMESPACE_INLINEES (parent_ns
), inline_ns
);
782 plugin_add_using_namespace (cc1_plugin::connection
*,
785 tree used_ns
= convert_in (used_ns_in
);
787 gcc_assert (TREE_CODE (used_ns
) == NAMESPACE_DECL
);
789 finish_using_directive (used_ns
, NULL_TREE
);
795 plugin_add_namespace_alias (cc1_plugin::connection
*,
799 tree name
= get_identifier (id
);
800 tree target
= convert_in (target_in
);
802 do_namespace_alias (name
, target
);
808 set_access_flags (tree decl
, enum gcc_cp_symbol_kind flags
)
810 gcc_assert (!(flags
& GCC_CP_ACCESS_MASK
) == !DECL_CLASS_SCOPE_P (decl
));
812 switch (flags
& GCC_CP_ACCESS_MASK
)
814 case GCC_CP_ACCESS_PRIVATE
:
815 TREE_PRIVATE (decl
) = true;
816 current_access_specifier
= access_private_node
;
819 case GCC_CP_ACCESS_PROTECTED
:
820 TREE_PROTECTED (decl
) = true;
821 current_access_specifier
= access_protected_node
;
824 case GCC_CP_ACCESS_PUBLIC
:
825 current_access_specifier
= access_public_node
;
834 plugin_add_using_decl (cc1_plugin::connection
*,
835 enum gcc_cp_symbol_kind flags
,
838 tree target
= convert_in (target_in
);
839 gcc_assert ((flags
& GCC_CP_SYMBOL_MASK
) == GCC_CP_SYMBOL_USING
);
840 gcc_assert (!(flags
& GCC_CP_FLAG_MASK
));
841 enum gcc_cp_symbol_kind acc_flags
;
842 acc_flags
= (enum gcc_cp_symbol_kind
) (flags
& GCC_CP_ACCESS_MASK
);
844 gcc_assert (!template_parm_scope_p ());
846 bool class_member_p
= at_class_scope_p ();
847 gcc_assert (!(acc_flags
& GCC_CP_ACCESS_MASK
) == !class_member_p
);
849 tree identifier
= DECL_NAME (target
);
850 tree tcontext
= DECL_CONTEXT (target
);
852 if (UNSCOPED_ENUM_P (tcontext
))
853 tcontext
= CP_TYPE_CONTEXT (tcontext
);
857 tree decl
= do_class_using_decl (tcontext
, identifier
);
859 set_access_flags (decl
, flags
);
861 finish_member_declaration (decl
);
865 /* We can't be at local scope. */
866 gcc_assert (at_namespace_scope_p ());
867 finish_nonmember_using_decl (tcontext
, identifier
);
874 build_named_class_type (enum tree_code code
,
878 /* See at_fake_function_scope_p. */
879 gcc_assert (!at_function_scope_p ());
880 tree type
= make_class_type (code
);
881 tree type_decl
= build_decl (loc
, TYPE_DECL
, id
, type
);
882 TYPE_NAME (type
) = type_decl
;
883 TYPE_STUB_DECL (type
) = type_decl
;
884 DECL_CONTEXT (type_decl
) = TYPE_CONTEXT (type
);
889 /* Abuse an unused field of the dummy template parms entry to hold the
891 #define TP_PARM_LIST TREE_TYPE (current_template_parms)
894 plugin_build_decl (cc1_plugin::connection
*self
,
896 enum gcc_cp_symbol_kind sym_kind
,
897 gcc_type sym_type_in
,
898 const char *substitution_name
,
900 const char *filename
,
901 unsigned int line_number
)
903 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
904 gcc_assert (!name
|| !strchr (name
, ':')); // FIXME: this can go eventually.
908 tree sym_type
= convert_in (sym_type_in
);
909 enum gcc_cp_symbol_kind sym_flags
;
910 sym_flags
= (enum gcc_cp_symbol_kind
) (sym_kind
& GCC_CP_FLAG_MASK
);
911 enum gcc_cp_symbol_kind acc_flags
;
912 acc_flags
= (enum gcc_cp_symbol_kind
) (sym_kind
& GCC_CP_ACCESS_MASK
);
913 sym_kind
= (enum gcc_cp_symbol_kind
) (sym_kind
& GCC_CP_SYMBOL_MASK
);
917 case GCC_CP_SYMBOL_FUNCTION
:
918 code
= FUNCTION_DECL
;
919 gcc_assert (!(sym_flags
& ~GCC_CP_FLAG_MASK_FUNCTION
));
922 case GCC_CP_SYMBOL_VARIABLE
:
924 gcc_assert (!(sym_flags
& ~GCC_CP_FLAG_MASK_VARIABLE
));
927 case GCC_CP_SYMBOL_TYPEDEF
:
929 gcc_assert (!sym_flags
);
932 case GCC_CP_SYMBOL_CLASS
:
934 gcc_assert (!(sym_flags
& ~GCC_CP_FLAG_MASK_CLASS
));
935 gcc_assert (!sym_type
);
938 case GCC_CP_SYMBOL_UNION
:
940 gcc_assert (!sym_flags
);
941 gcc_assert (!sym_type
);
948 bool template_decl_p
= template_parm_scope_p ();
952 gcc_assert (code
== FUNCTION_DECL
|| code
== RECORD_TYPE
953 || code
== TYPE_DECL
);
955 /* Finish the template parm list that started this template parm. */
956 end_template_parm_list (TP_PARM_LIST
);
958 gcc_assert (!address
);
959 gcc_assert (!substitution_name
);
962 location_t loc
= ctx
->get_location_t (filename
, line_number
);
963 bool class_member_p
= at_class_scope_p ();
964 bool ctor
= false, dtor
= false, assop
= false;
965 tree_code opcode
= ERROR_MARK
;
967 gcc_assert (!(acc_flags
& GCC_CP_ACCESS_MASK
) == !class_member_p
);
970 if (code
!= FUNCTION_DECL
971 || !(sym_flags
& GCC_CP_FLAG_SPECIAL_FUNCTION
))
974 identifier
= get_identifier (name
);
977 gcc_assert (RECORD_OR_UNION_CODE_P (code
));
978 identifier
= make_anon_name ();
982 if (code
== FUNCTION_DECL
)
984 if (sym_flags
& GCC_CP_FLAG_SPECIAL_FUNCTION
)
986 #define CHARS2(f,s) (((unsigned char)f << CHAR_BIT) | (unsigned char)s)
987 switch (CHARS2 (name
[0], name
[1]))
989 case CHARS2 ('C', 0x0): // ctor base declaration
990 case CHARS2 ('C', ' '):
991 case CHARS2 ('C', '1'):
992 case CHARS2 ('C', '2'):
993 case CHARS2 ('C', '4'):
996 gcc_assert (!address
);
997 gcc_assert (!substitution_name
);
998 identifier
= DECL_NAME (TYPE_NAME (current_class_type
));
1000 case CHARS2 ('D', 0x0): // dtor base declaration
1001 case CHARS2 ('D', ' '):
1002 case CHARS2 ('D', '0'):
1003 case CHARS2 ('D', '1'):
1004 case CHARS2 ('D', '2'):
1005 case CHARS2 ('D', '4'):
1006 gcc_assert (!template_decl_p
);
1009 case CHARS2 ('n', 'w'): // operator new
1012 case CHARS2 ('n', 'a'): // operator new[]
1013 opcode
= VEC_NEW_EXPR
;
1015 case CHARS2 ('d', 'l'): // operator delete
1016 opcode
= DELETE_EXPR
;
1018 case CHARS2 ('d', 'a'): // operator delete[]
1019 opcode
= VEC_DELETE_EXPR
;
1021 case CHARS2 ('p', 's'): // operator + (unary)
1024 case CHARS2 ('n', 'g'): // operator - (unary)
1025 opcode
= MINUS_EXPR
;
1027 case CHARS2 ('a', 'd'): // operator & (unary)
1028 opcode
= BIT_AND_EXPR
;
1030 case CHARS2 ('d', 'e'): // operator * (unary)
1033 case CHARS2 ('c', 'o'): // operator ~
1034 opcode
= BIT_NOT_EXPR
;
1036 case CHARS2 ('p', 'l'): // operator +
1039 case CHARS2 ('m', 'i'): // operator -
1040 opcode
= MINUS_EXPR
;
1042 case CHARS2 ('m', 'l'): // operator *
1045 case CHARS2 ('d', 'v'): // operator /
1046 opcode
= TRUNC_DIV_EXPR
;
1048 case CHARS2 ('r', 'm'): // operator %
1049 opcode
= TRUNC_MOD_EXPR
;
1051 case CHARS2 ('a', 'n'): // operator &
1052 opcode
= BIT_AND_EXPR
;
1054 case CHARS2 ('o', 'r'): // operator |
1055 opcode
= BIT_IOR_EXPR
;
1057 case CHARS2 ('e', 'o'): // operator ^
1058 opcode
= BIT_XOR_EXPR
;
1060 case CHARS2 ('a', 'S'): // operator =
1064 case CHARS2 ('p', 'L'): // operator +=
1068 case CHARS2 ('m', 'I'): // operator -=
1069 opcode
= MINUS_EXPR
;
1072 case CHARS2 ('m', 'L'): // operator *=
1076 case CHARS2 ('d', 'V'): // operator /=
1077 opcode
= TRUNC_DIV_EXPR
;
1080 case CHARS2 ('r', 'M'): // operator %=
1081 opcode
= TRUNC_MOD_EXPR
;
1084 case CHARS2 ('a', 'N'): // operator &=
1085 opcode
= BIT_AND_EXPR
;
1088 case CHARS2 ('o', 'R'): // operator |=
1089 opcode
= BIT_IOR_EXPR
;
1092 case CHARS2 ('e', 'O'): // operator ^=
1093 opcode
= BIT_XOR_EXPR
;
1096 case CHARS2 ('l', 's'): // operator <<
1097 opcode
= LSHIFT_EXPR
;
1099 case CHARS2 ('r', 's'): // operator >>
1100 opcode
= RSHIFT_EXPR
;
1102 case CHARS2 ('l', 'S'): // operator <<=
1103 opcode
= LSHIFT_EXPR
;
1106 case CHARS2 ('r', 'S'): // operator >>=
1107 opcode
= RSHIFT_EXPR
;
1110 case CHARS2 ('e', 'q'): // operator ==
1113 case CHARS2 ('n', 'e'): // operator !=
1116 case CHARS2 ('l', 't'): // operator <
1119 case CHARS2 ('g', 't'): // operator >
1122 case CHARS2 ('l', 'e'): // operator <=
1125 case CHARS2 ('g', 'e'): // operator >=
1128 case CHARS2 ('n', 't'): // operator !
1129 opcode
= TRUTH_NOT_EXPR
;
1131 case CHARS2 ('a', 'a'): // operator &&
1132 opcode
= TRUTH_ANDIF_EXPR
;
1134 case CHARS2 ('o', 'o'): // operator ||
1135 opcode
= TRUTH_ORIF_EXPR
;
1137 case CHARS2 ('p', 'p'): // operator ++
1138 opcode
= POSTINCREMENT_EXPR
;
1140 case CHARS2 ('m', 'm'): // operator --
1141 /* This stands for either one as an operator name, and
1142 "pp" and "mm" stand for POST??CREMENT, but for some
1143 reason the parser uses this opcode name for
1144 operator--; let's follow their practice. */
1145 opcode
= PREDECREMENT_EXPR
;
1147 case CHARS2 ('c', 'm'): // operator ,
1148 opcode
= COMPOUND_EXPR
;
1150 case CHARS2 ('p', 'm'): // operator ->*
1151 opcode
= MEMBER_REF
;
1153 case CHARS2 ('p', 't'): // operator ->
1154 opcode
= COMPONENT_REF
;
1156 case CHARS2 ('c', 'l'): // operator ()
1159 case CHARS2 ('i', 'x'): // operator []
1162 case CHARS2 ('c', 'v'): // operator <T> (conversion operator)
1163 identifier
= make_conv_op_name (TREE_TYPE (sym_type
));
1166 case CHARS2 ('l', 'i'): // operator "" <id>
1168 char *id
= (char *)name
+ 2;
1169 bool freeid
= false;
1170 if (*id
>= '0' && *id
<= '9')
1179 while (*id
&& *id
>= '0' && *id
<= '9');
1180 id
= xstrndup (id
, len
);
1183 identifier
= cp_literal_operator_id (id
);
1188 case CHARS2 ('q', 'u'): // ternary operator, not overloadable.
1193 if (opcode
!= ERROR_MARK
)
1194 identifier
= ovl_op_identifier (assop
, opcode
);
1196 decl
= build_lang_decl_loc (loc
, code
, identifier
, sym_type
);
1197 /* FIXME: current_lang_name is lang_name_c while compiling an
1198 extern "C" function, and we haven't switched to a global
1199 context at this point, and this breaks function
1201 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
1202 if (TREE_CODE (sym_type
) == METHOD_TYPE
)
1203 DECL_ARGUMENTS (decl
) = build_this_parm (decl
, current_class_type
,
1204 cp_type_quals (sym_type
));
1205 for (tree arg
= TREE_CODE (sym_type
) == METHOD_TYPE
1206 ? TREE_CHAIN (TYPE_ARG_TYPES (sym_type
))
1207 : TYPE_ARG_TYPES (sym_type
);
1208 arg
&& arg
!= void_list_node
;
1209 arg
= TREE_CHAIN (arg
))
1211 tree parm
= cp_build_parm_decl (decl
, NULL_TREE
, TREE_VALUE (arg
));
1212 DECL_CHAIN (parm
) = DECL_ARGUMENTS (decl
);
1213 DECL_ARGUMENTS (decl
) = parm
;
1215 DECL_ARGUMENTS (decl
) = nreverse (DECL_ARGUMENTS (decl
));
1218 if (TREE_CODE (sym_type
) == FUNCTION_TYPE
)
1219 DECL_STATIC_FUNCTION_P (decl
) = 1;
1220 if (sym_flags
& GCC_CP_FLAG_VIRTUAL_FUNCTION
)
1222 DECL_VIRTUAL_P (decl
) = 1;
1223 if (sym_flags
& GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION
)
1224 DECL_PURE_VIRTUAL_P (decl
) = 1;
1225 if (sym_flags
& GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION
)
1226 DECL_FINAL_P (decl
) = 1;
1229 gcc_assert (!(sym_flags
& (GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION
1230 | GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION
)));
1234 gcc_assert (!(sym_flags
& (GCC_CP_FLAG_VIRTUAL_FUNCTION
1235 | GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION
1236 | GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION
)));
1237 gcc_assert (!ctor
&& !dtor
&& !assop
);
1239 if (sym_flags
& GCC_CP_FLAG_EXPLICIT_FUNCTION
)
1240 DECL_NONCONVERTING_P (decl
) = 1;
1241 if (sym_flags
& GCC_CP_FLAG_DEFAULTED_FUNCTION
)
1243 DECL_INITIAL (decl
) = ridpointers
[(int)RID_DEFAULT
];
1244 DECL_DEFAULTED_FN (decl
) = 1;
1246 if (sym_flags
& GCC_CP_FLAG_DELETED_FUNCTION
)
1248 // DECL_INITIAL (decl) = ridpointers[(int)RID_DELETE];
1249 DECL_DELETED_FN (decl
) = 1;
1250 DECL_DECLARED_INLINE_P (decl
) = 1;
1251 DECL_INITIAL (decl
) = error_mark_node
;
1255 DECL_CXX_CONSTRUCTOR_P (decl
) = 1;
1257 DECL_CXX_DESTRUCTOR_P (decl
) = 1;
1258 else if ((sym_flags
& GCC_CP_FLAG_SPECIAL_FUNCTION
)
1259 && opcode
!= ERROR_MARK
)
1260 DECL_OVERLOADED_OPERATOR_CODE_RAW (decl
) = ovl_op_mapping
[opcode
];
1262 else if (RECORD_OR_UNION_CODE_P (code
))
1264 decl
= build_named_class_type (code
, identifier
, loc
);
1265 tree type
= TREE_TYPE (decl
);
1267 if (code
== RECORD_TYPE
1268 && !(sym_flags
& GCC_CP_FLAG_CLASS_IS_STRUCT
))
1269 CLASSTYPE_DECLARED_CLASS (type
) = true;
1271 else if (class_member_p
)
1273 decl
= build_lang_decl_loc (loc
, code
, identifier
, sym_type
);
1275 if (TREE_CODE (decl
) == VAR_DECL
)
1277 DECL_THIS_STATIC (decl
) = 1;
1278 // The remainder of this block does the same as:
1279 // set_linkage_for_static_data_member (decl);
1280 TREE_PUBLIC (decl
) = 1;
1281 TREE_STATIC (decl
) = 1;
1282 DECL_INTERFACE_KNOWN (decl
) = 1;
1284 // FIXME: sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
1285 gcc_assert (!(sym_flags
& GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
));
1287 if (sym_flags
& GCC_CP_FLAG_CONSTEXPR_VARIABLE
)
1288 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
1293 decl
= build_decl (loc
, code
, identifier
, sym_type
);
1295 if (TREE_CODE (decl
) == VAR_DECL
)
1297 // FIXME: sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
1298 gcc_assert (!(sym_flags
& GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
));
1300 if (sym_flags
& GCC_CP_FLAG_CONSTEXPR_VARIABLE
)
1301 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
1304 TREE_USED (decl
) = 1;
1305 TREE_ADDRESSABLE (decl
) = 1;
1308 DECL_CONTEXT (decl
) = FROB_CONTEXT (current_class_type
);
1309 else if (at_namespace_scope_p ())
1310 DECL_CONTEXT (decl
) = FROB_CONTEXT (current_decl_namespace ());
1312 set_access_flags (decl
, acc_flags
);
1314 /* If this is the typedef that names an otherwise anonymous type,
1315 propagate the typedef name to the type. In normal compilation,
1316 this is done in grokdeclarator. */
1317 if (sym_kind
== GCC_CP_SYMBOL_TYPEDEF
1319 && DECL_CONTEXT (decl
) == TYPE_CONTEXT (sym_type
)
1320 && TYPE_UNNAMED_P (sym_type
))
1321 name_unnamed_type (sym_type
, decl
);
1323 if (sym_kind
!= GCC_CP_SYMBOL_TYPEDEF
1324 && sym_kind
!= GCC_CP_SYMBOL_CLASS
1325 && sym_kind
!= GCC_CP_SYMBOL_UNION
1326 && !template_decl_p
&& !ctor
&& !dtor
)
1328 decl_addr_value value
;
1330 DECL_EXTERNAL (decl
) = 1;
1332 if (substitution_name
!= NULL
)
1334 // If the translator gave us a name without a binding,
1335 // we can just substitute error_mark_node, since we know the
1336 // translator will be reporting an error anyhow.
1338 = lookup_name (get_identifier (substitution_name
));
1339 if (value
.address
== NULL_TREE
)
1340 value
.address
= error_mark_node
;
1343 value
.address
= build_int_cst_type (ptr_type_node
, address
);
1345 value
.address
= NULL
;
1347 record_decl_address (ctx
, value
);
1350 if (class_member_p
&& code
== FUNCTION_DECL
)
1353 maybe_retrofit_in_chrg (decl
);
1355 grok_special_member_properties (decl
);
1358 if (template_decl_p
)
1360 if (RECORD_OR_UNION_CODE_P (code
))
1361 safe_pushtag (identifier
, TREE_TYPE (decl
));
1363 decl
= safe_push_template_decl (decl
);
1365 tree tdecl
= NULL_TREE
;
1367 tdecl
= finish_member_template_decl (decl
);
1369 end_template_decl ();
1371 /* We only support one level of templates, because we only
1372 support declaring generics; actual definitions are only of
1374 gcc_assert (!template_parm_scope_p ());
1377 finish_member_declaration (tdecl
);
1379 else if (RECORD_OR_UNION_CODE_P (code
))
1380 safe_pushtag (identifier
, TREE_TYPE (decl
));
1381 else if (class_member_p
)
1382 finish_member_declaration (decl
);
1384 decl
= safe_pushdecl (decl
);
1387 /* Don't crash after a duplicate declaration of a cdtor. */
1388 && TYPE_FIELDS (current_class_type
) == decl
)
1390 /* ctors and dtors clones are chained after DECL.
1391 However, we create the clones before TYPE_METHODS is
1392 reversed. We test for cloned methods after reversal,
1393 however, and the test requires the clones to follow
1394 DECL. So, we reverse the chain of clones now, so
1395 that it will come out in the right order after
1397 tree save
= DECL_CHAIN (decl
);
1398 DECL_CHAIN (decl
) = NULL_TREE
;
1399 clone_cdtor (decl
, /*update_methods=*/true);
1400 gcc_assert (TYPE_FIELDS (current_class_type
) == decl
);
1401 TYPE_FIELDS (current_class_type
)
1402 = nreverse (TYPE_FIELDS (current_class_type
));
1403 DECL_CHAIN (decl
) = save
;
1406 rest_of_decl_compilation (decl
, toplevel_bindings_p (), 0);
1408 return convert_out (ctx
->preserve (decl
));
1412 plugin_define_cdtor_clone (cc1_plugin::connection
*self
,
1415 gcc_address address
)
1417 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1418 tree decl
= convert_in (cdtor_in
);
1423 switch (CHARS2 (name
[0], name
[1]))
1425 case CHARS2 ('C', '1'): // in-charge constructor
1426 identifier
= complete_ctor_identifier
;
1429 case CHARS2 ('C', '2'): // not-in-charge constructor
1430 identifier
= base_ctor_identifier
;
1433 case CHARS2 ('C', '4'):
1434 identifier
= ctor_identifier
; // unified constructor
1437 case CHARS2 ('D', '0'): // deleting destructor
1438 identifier
= deleting_dtor_identifier
;
1441 case CHARS2 ('D', '1'): // in-charge destructor
1442 identifier
= complete_dtor_identifier
;
1445 case CHARS2 ('D', '2'): // not-in-charge destructor
1446 identifier
= base_dtor_identifier
;
1449 case CHARS2 ('D', '4'):
1450 identifier
= dtor_identifier
; // unified destructor
1458 gcc_assert (!ctor
!= !dtor
);
1460 ? (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl
)
1461 && DECL_NAME (decl
) == ctor_identifier
)
1462 : (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl
)
1463 && DECL_NAME (decl
) == dtor_identifier
));
1465 while (decl
&& DECL_NAME (decl
) != identifier
)
1467 decl
= DECL_CHAIN (decl
);
1468 if (decl
&& !DECL_CLONED_FUNCTION_P (decl
))
1473 record_decl_address (ctx
, build_decl_addr_value (decl
, address
));
1475 return convert_out (decl
);
1479 plugin_add_friend (cc1_plugin::connection
* /* self */,
1483 tree decl
= convert_in (decl_in
);
1484 tree type
= convert_in (type_in
);
1486 gcc_assert (type
|| at_class_scope_p ());
1489 type
= current_class_type
;
1491 gcc_assert (TREE_CODE (type
) == RECORD_TYPE
);
1494 make_friend_class (type
, TREE_TYPE (decl
), true);
1497 DECL_UNIQUE_FRIEND_P (decl
) = true;
1498 add_friend (type
, decl
, true);
1505 plugin_build_pointer_type (cc1_plugin::connection
*,
1508 // No need to preserve a pointer type as the base type is preserved.
1509 return convert_out (build_pointer_type (convert_in (base_type
)));
1513 plugin_build_reference_type (cc1_plugin::connection
*,
1514 gcc_type base_type_in
,
1515 enum gcc_cp_ref_qualifiers rquals
)
1521 case GCC_CP_REF_QUAL_LVALUE
:
1524 case GCC_CP_REF_QUAL_RVALUE
:
1527 case GCC_CP_REF_QUAL_NONE
:
1532 tree rtype
= cp_build_reference_type (convert_in (base_type_in
), rval
);
1534 return convert_out (rtype
);
1538 start_class_def (tree type
,
1539 const gcc_vbase_array
*base_classes
)
1544 for (int i
= 0; i
< base_classes
->n_elements
; i
++)
1548 gcc_assert ((base_classes
->flags
[i
] & GCC_CP_SYMBOL_MASK
)
1549 == GCC_CP_SYMBOL_BASECLASS
);
1551 switch (base_classes
->flags
[i
] & GCC_CP_ACCESS_MASK
)
1553 case GCC_CP_ACCESS_PRIVATE
:
1554 access
= ridpointers
[(int)RID_PRIVATE
];
1557 case GCC_CP_ACCESS_PROTECTED
:
1558 access
= ridpointers
[(int)RID_PROTECTED
];
1561 case GCC_CP_ACCESS_PUBLIC
:
1562 access
= ridpointers
[(int)RID_PUBLIC
];
1569 tree base
= finish_base_specifier
1570 (convert_in (base_classes
->elements
[i
]), access
,
1571 (base_classes
->flags
[i
] & GCC_CP_FLAG_BASECLASS_VIRTUAL
) != 0);
1572 TREE_CHAIN (base
) = bases
;
1575 bases
= nreverse (bases
);
1577 xref_basetypes (type
, bases
);
1578 begin_class_definition (type
);
1583 plugin_start_class_type (cc1_plugin::connection
*self
,
1584 gcc_decl typedecl_in
,
1585 const gcc_vbase_array
*base_classes
,
1586 const char *filename
,
1587 unsigned int line_number
)
1589 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1590 location_t loc
= ctx
->get_location_t (filename
, line_number
);
1591 tree typedecl
= convert_in (typedecl_in
);
1592 tree type
= TREE_TYPE (typedecl
);
1594 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (type
)));
1595 gcc_assert (!COMPLETE_TYPE_P (type
));
1597 DECL_SOURCE_LOCATION (typedecl
) = loc
;
1599 tree result
= start_class_def (type
, base_classes
);
1601 return convert_out (ctx
->preserve (result
));
1605 plugin_start_closure_class_type (cc1_plugin::connection
*self
,
1607 gcc_decl extra_scope_in
,
1608 enum gcc_cp_symbol_kind flags
,
1609 const char *filename
,
1610 unsigned int line_number
)
1612 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1613 tree extra_scope
= convert_in (extra_scope_in
);
1615 gcc_assert ((flags
& GCC_CP_SYMBOL_MASK
) == GCC_CP_SYMBOL_LAMBDA_CLOSURE
);
1616 gcc_assert ((flags
& (~(GCC_CP_SYMBOL_MASK
| GCC_CP_ACCESS_MASK
))) == 0);
1618 gcc_assert (!(flags
& GCC_CP_ACCESS_MASK
) == !at_class_scope_p ());
1620 /* See at_fake_function_scope_p. */
1621 gcc_assert (!at_function_scope_p ());
1625 if (TREE_CODE (extra_scope
) == PARM_DECL
)
1627 gcc_assert (at_fake_function_scope_p ());
1628 /* Check that the given extra_scope is one of the parameters of
1629 the current function. */
1630 for (tree parm
= DECL_ARGUMENTS (current_function_decl
);
1631 ; parm
= DECL_CHAIN (parm
))
1634 if (parm
== extra_scope
)
1638 else if (TREE_CODE (extra_scope
) == FIELD_DECL
)
1640 gcc_assert (at_class_scope_p ());
1641 gcc_assert (DECL_CONTEXT (extra_scope
) == current_class_type
);
1644 /* FIXME: does this ever really occur? */
1645 gcc_assert (TREE_CODE (extra_scope
) == VAR_DECL
);
1648 tree lambda_expr
= build_lambda_expr ();
1650 LAMBDA_EXPR_LOCATION (lambda_expr
) = ctx
->get_location_t (filename
,
1653 tree type
= begin_lambda_type (lambda_expr
);
1655 /* Instead of calling record_lambda_scope, do this: */
1656 LAMBDA_EXPR_EXTRA_SCOPE (lambda_expr
) = extra_scope
;
1657 LAMBDA_EXPR_DISCRIMINATOR (lambda_expr
) = discriminator
;
1659 tree decl
= TYPE_NAME (type
);
1660 determine_visibility (decl
);
1661 set_access_flags (decl
, flags
);
1663 return convert_out (ctx
->preserve (type
));
1667 plugin_build_lambda_expr (cc1_plugin::connection
*self
,
1668 gcc_type closure_type_in
)
1670 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1671 tree closure_type
= convert_in (closure_type_in
);
1673 gcc_assert (LAMBDA_TYPE_P (closure_type
));
1675 tree lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure_type
);
1677 tree lambda_object
= build_lambda_object (lambda_expr
);
1679 return convert_out (ctx
->preserve (lambda_object
));
1683 plugin_build_field (cc1_plugin::connection
*,
1684 const char *field_name
,
1685 gcc_type field_type_in
,
1686 enum gcc_cp_symbol_kind flags
,
1687 unsigned long bitsize
,
1688 unsigned long bitpos
)
1690 tree record_or_union_type
= current_class_type
;
1691 tree field_type
= convert_in (field_type_in
);
1693 gcc_assert (at_class_scope_p ());
1694 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (record_or_union_type
)));
1695 gcc_assert ((flags
& GCC_CP_SYMBOL_MASK
) == GCC_CP_SYMBOL_FIELD
);
1696 gcc_assert ((flags
& (~(GCC_CP_SYMBOL_MASK
| GCC_CP_ACCESS_MASK
1697 | GCC_CP_FLAG_MASK_FIELD
))) == 0);
1698 gcc_assert ((flags
& GCC_CP_ACCESS_MASK
));
1700 /* Note that gdb does not preserve the location of field decls, so
1701 we can't provide a decent location here. */
1702 tree decl
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
,
1703 get_identifier (field_name
), field_type
);
1704 DECL_FIELD_CONTEXT (decl
) = record_or_union_type
;
1706 set_access_flags (decl
, flags
);
1708 if ((flags
& GCC_CP_FLAG_FIELD_MUTABLE
) != 0)
1709 DECL_MUTABLE_P (decl
) = 1;
1711 if (TREE_CODE (field_type
) == INTEGER_TYPE
1712 && TYPE_PRECISION (field_type
) != bitsize
)
1714 DECL_BIT_FIELD_TYPE (decl
) = field_type
;
1716 = c_build_bitfield_integer_type (bitsize
, TYPE_UNSIGNED (field_type
));
1719 SET_DECL_MODE (decl
, TYPE_MODE (TREE_TYPE (decl
)));
1721 // There's no way to recover this from DWARF.
1722 SET_DECL_OFFSET_ALIGN (decl
, TYPE_PRECISION (pointer_sized_int_node
));
1724 tree pos
= bitsize_int (bitpos
);
1725 pos_from_bit (&DECL_FIELD_OFFSET (decl
), &DECL_FIELD_BIT_OFFSET (decl
),
1726 DECL_OFFSET_ALIGN (decl
), pos
);
1728 DECL_SIZE (decl
) = bitsize_int (bitsize
);
1729 DECL_SIZE_UNIT (decl
) = size_int ((bitsize
+ BITS_PER_UNIT
- 1)
1732 DECL_CHAIN (decl
) = TYPE_FIELDS (record_or_union_type
);
1733 TYPE_FIELDS (record_or_union_type
) = decl
;
1735 return convert_out (decl
);
1739 plugin_finish_class_type (cc1_plugin::connection
*,
1740 unsigned long size_in_bytes
)
1742 tree record_or_union_type
= current_class_type
;
1744 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (record_or_union_type
)));
1746 finish_struct (record_or_union_type
, NULL
);
1748 gcc_assert (compare_tree_int (TYPE_SIZE_UNIT (record_or_union_type
),
1749 size_in_bytes
) == 0);
1755 plugin_start_enum_type (cc1_plugin::connection
*self
,
1757 gcc_type underlying_int_type_in
,
1758 enum gcc_cp_symbol_kind flags
,
1759 const char *filename
,
1760 unsigned int line_number
)
1762 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1763 tree underlying_int_type
= convert_in (underlying_int_type_in
);
1765 gcc_assert ((flags
& GCC_CP_SYMBOL_MASK
) == GCC_CP_SYMBOL_ENUM
);
1766 gcc_assert ((flags
& (~(GCC_CP_SYMBOL_MASK
| GCC_CP_ACCESS_MASK
1767 | GCC_CP_FLAG_MASK_ENUM
))) == 0);
1768 gcc_assert (!(flags
& GCC_CP_ACCESS_MASK
) == !at_class_scope_p ());
1770 if (underlying_int_type
== error_mark_node
)
1771 return convert_out (error_mark_node
);
1773 bool is_new_type
= false;
1775 tree id
= name
? get_identifier (name
) : make_anon_name ();
1777 tree type
= start_enum (id
, NULL_TREE
,
1778 underlying_int_type
,
1779 /* attributes = */ NULL_TREE
,
1780 !!(flags
& GCC_CP_FLAG_ENUM_SCOPED
), &is_new_type
);
1782 gcc_assert (is_new_type
);
1784 location_t loc
= ctx
->get_location_t (filename
, line_number
);
1785 tree type_decl
= TYPE_NAME (type
);
1786 DECL_SOURCE_LOCATION (type_decl
) = loc
;
1787 SET_OPAQUE_ENUM_P (type
, false);
1789 set_access_flags (type_decl
, flags
);
1791 return convert_out (ctx
->preserve (type
));
1795 plugin_build_enum_constant (cc1_plugin::connection
*,
1796 gcc_type enum_type_in
,
1798 unsigned long value
)
1800 tree enum_type
= convert_in (enum_type_in
);
1802 gcc_assert (TREE_CODE (enum_type
) == ENUMERAL_TYPE
);
1804 build_enumerator (get_identifier (name
), build_int_cst (enum_type
, value
),
1805 enum_type
, NULL_TREE
, BUILTINS_LOCATION
);
1807 return convert_out (TREE_VALUE (TYPE_VALUES (enum_type
)));
1811 plugin_finish_enum_type (cc1_plugin::connection
*,
1812 gcc_type enum_type_in
)
1814 tree enum_type
= convert_in (enum_type_in
);
1816 finish_enum_value_list (enum_type
);
1817 finish_enum (enum_type
);
1823 plugin_build_function_type (cc1_plugin::connection
*self
,
1824 gcc_type return_type_in
,
1825 const struct gcc_type_array
*argument_types_in
,
1828 tree return_type
= convert_in (return_type_in
);
1831 std::vector
<tree
> argument_types (argument_types_in
->n_elements
);
1832 for (int i
= 0; i
< argument_types_in
->n_elements
; ++i
)
1833 argument_types
[i
] = convert_in (argument_types_in
->elements
[i
]);
1836 result
= build_varargs_function_type_array (return_type
,
1837 argument_types_in
->n_elements
,
1838 argument_types
.data ());
1840 result
= build_function_type_array (return_type
,
1841 argument_types_in
->n_elements
,
1842 argument_types
.data ());
1844 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1845 return convert_out (ctx
->preserve (result
));
1851 plugin_add_function_default_args (cc1_plugin::connection
*self
,
1852 gcc_type function_type_in
,
1853 const struct gcc_cp_function_args
*defaults
)
1855 tree function_type
= convert_in (function_type_in
);
1857 gcc_assert (TREE_CODE (function_type
) == FUNCTION_TYPE
);
1859 if (!defaults
|| !defaults
->n_elements
)
1860 return function_type_in
;
1862 tree pargs
= TYPE_ARG_TYPES (function_type
);
1863 tree nargs
= NULL_TREE
;
1865 /* Build a reversed copy of the list of default-less arguments in
1866 NARGS. At the end of the loop, PARGS will point to the end of
1867 the argument list, or to the first argument that had a default
1869 while (pargs
&& TREE_VALUE (pargs
) != void_list_node
1870 && !TREE_PURPOSE (pargs
))
1872 nargs
= tree_cons (NULL_TREE
, TREE_VALUE (pargs
), nargs
);
1873 pargs
= TREE_CHAIN (pargs
);
1876 /* Set the defaults in the now-leading NARGS, taking into account
1877 that NARGS is reversed but DEFAULTS->elements isn't. */
1878 tree ndargs
= nargs
;
1879 int i
= defaults
->n_elements
;
1882 gcc_assert (ndargs
);
1883 tree deflt
= convert_in (defaults
->elements
[i
]);
1885 deflt
= error_mark_node
;
1886 TREE_PURPOSE (ndargs
) = deflt
;
1887 ndargs
= TREE_CHAIN (ndargs
);
1890 /* Finally, reverse NARGS, and append the remaining PARGS that
1891 already had defaults. */
1892 nargs
= nreverse (nargs
);
1893 nargs
= chainon (nargs
, pargs
);
1895 tree result
= build_function_type (TREE_TYPE (function_type
), nargs
);
1897 /* Copy exceptions, attributes and whatnot. */
1898 result
= build_exception_variant (result
,
1899 TYPE_RAISES_EXCEPTIONS (function_type
));
1900 result
= cp_build_type_attribute_variant (result
,
1901 TYPE_ATTRIBUTES (function_type
));
1903 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1904 return convert_out (ctx
->preserve (result
));
1908 plugin_set_deferred_function_default_args (cc1_plugin::connection
*,
1909 gcc_decl function_in
,
1910 const struct gcc_cp_function_args
1913 tree function
= convert_in (function_in
);
1915 gcc_assert (TREE_CODE (function
) == FUNCTION_DECL
);
1917 if (!defaults
|| !defaults
->n_elements
)
1920 tree arg
= FUNCTION_FIRST_USER_PARMTYPE (function
);
1922 for (int i
= 0; i
< defaults
->n_elements
; i
++)
1924 while (arg
&& TREE_PURPOSE (arg
) != error_mark_node
)
1925 arg
= TREE_CHAIN (arg
);
1930 TREE_PURPOSE (arg
) = convert_in (defaults
->elements
[i
]);
1931 arg
= TREE_CHAIN (arg
);
1940 plugin_get_function_parameter_decl (cc1_plugin::connection
*,
1941 gcc_decl function_in
,
1944 tree function
= convert_in (function_in
);
1946 gcc_assert (TREE_CODE (function
) == FUNCTION_DECL
);
1950 gcc_assert (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
);
1952 return convert_out (DECL_ARGUMENTS (function
));
1955 gcc_assert (index
>= 0);
1957 tree args
= FUNCTION_FIRST_USER_PARM (function
);
1959 for (int i
= 0; args
&& i
< index
; i
++)
1960 args
= DECL_CHAIN (args
);
1962 return convert_out (args
);
1966 plugin_build_exception_spec_variant (cc1_plugin::connection
*self
,
1967 gcc_type function_type_in
,
1968 const struct gcc_type_array
*except_types_in
)
1970 tree function_type
= convert_in (function_type_in
);
1971 tree except_types
= NULL_TREE
;
1973 if (!except_types_in
)
1974 except_types
= noexcept_false_spec
;
1975 else if (!except_types_in
->n_elements
)
1976 except_types
= empty_except_spec
;
1978 for (int i
= 0; i
< except_types_in
->n_elements
; i
++)
1979 except_types
= add_exception_specifier (except_types
,
1981 (except_types_in
->elements
[i
]),
1984 function_type
= build_exception_variant (function_type
,
1987 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1988 return convert_out (ctx
->preserve (function_type
));
1992 plugin_build_method_type (cc1_plugin::connection
*self
,
1993 gcc_type class_type_in
,
1994 gcc_type func_type_in
,
1995 enum gcc_cp_qualifiers quals_in
,
1996 enum gcc_cp_ref_qualifiers rquals_in
)
1998 tree class_type
= convert_in (class_type_in
);
1999 tree func_type
= convert_in (func_type_in
);
2000 cp_cv_quals quals
= 0;
2001 cp_ref_qualifier rquals
;
2003 if ((quals_in
& GCC_CP_QUALIFIER_CONST
) != 0)
2004 quals
|= TYPE_QUAL_CONST
;
2005 if ((quals_in
& GCC_CP_QUALIFIER_VOLATILE
) != 0)
2006 quals
|= TYPE_QUAL_VOLATILE
;
2007 gcc_assert ((quals_in
& GCC_CP_QUALIFIER_RESTRICT
) == 0);
2011 case GCC_CP_REF_QUAL_NONE
:
2012 rquals
= REF_QUAL_NONE
;
2014 case GCC_CP_REF_QUAL_LVALUE
:
2015 rquals
= REF_QUAL_LVALUE
;
2017 case GCC_CP_REF_QUAL_RVALUE
:
2018 rquals
= REF_QUAL_RVALUE
;
2024 tree method_type
= class_type
2025 ? build_memfn_type (func_type
, class_type
, quals
, rquals
)
2026 : apply_memfn_quals (func_type
, quals
, rquals
);
2028 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2029 return convert_out (ctx
->preserve (method_type
));
2033 plugin_build_pointer_to_member_type (cc1_plugin::connection
*self
,
2034 gcc_type class_type_in
,
2035 gcc_type member_type_in
)
2037 tree class_type
= convert_in (class_type_in
);
2038 tree member_type
= convert_in (member_type_in
);
2040 tree memptr_type
= build_ptrmem_type (class_type
, member_type
);
2042 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2043 return convert_out (ctx
->preserve (memptr_type
));
2047 plugin_start_template_decl (cc1_plugin::connection
*)
2049 begin_template_parm_list ();
2051 TP_PARM_LIST
= NULL_TREE
;
2057 plugin_get_type_decl (cc1_plugin::connection
*,
2060 tree type
= convert_in (type_in
);
2062 tree name
= TYPE_NAME (type
);
2065 return convert_out (name
);
2069 plugin_get_decl_type (cc1_plugin::connection
*,
2072 tree decl
= convert_in (decl_in
);
2074 tree type
= TREE_TYPE (decl
);
2077 return convert_out (type
);
2081 plugin_build_type_template_parameter (cc1_plugin::connection
*self
,
2083 int /* bool */ pack_p
,
2084 gcc_type default_type
,
2085 const char *filename
,
2086 unsigned int line_number
)
2088 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2089 location_t loc
= ctx
->get_location_t (filename
, line_number
);
2091 gcc_assert (template_parm_scope_p ());
2093 tree parm
= finish_template_type_parm (class_type_node
, get_identifier (id
));
2094 parm
= build_tree_list (convert_in (default_type
), parm
);
2096 gcc_assert (!(pack_p
&& default_type
));
2098 /* Create a type and a decl for the type parm, and add the decl to
2100 TP_PARM_LIST
= process_template_parm (TP_PARM_LIST
, loc
, parm
,
2101 /* is_non_type = */ false, pack_p
);
2103 /* Locate the decl of the newly-added, processed template parm. */
2104 parm
= TREE_VALUE (tree_last (TP_PARM_LIST
));
2106 /* Return its type. */
2107 return convert_out (ctx
->preserve (TREE_TYPE (parm
)));
2111 plugin_build_template_template_parameter (cc1_plugin::connection
*self
,
2113 int /* bool */ pack_p
,
2114 gcc_utempl default_templ
,
2115 const char *filename
,
2116 unsigned int line_number
)
2118 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2119 location_t loc
= ctx
->get_location_t (filename
, line_number
);
2121 gcc_assert (template_parm_scope_p ());
2123 /* Finish the template parm list that started this template parm. */
2124 end_template_parm_list (TP_PARM_LIST
);
2126 gcc_assert (template_parm_scope_p ());
2128 tree parm
= finish_template_template_parm (class_type_node
,
2129 get_identifier (id
));
2130 parm
= build_tree_list (convert_in (default_templ
), parm
);
2132 gcc_assert (!(pack_p
&& default_templ
));
2134 /* Create a type and a decl for the template parm, and add the decl
2136 TP_PARM_LIST
= process_template_parm (TP_PARM_LIST
, loc
, parm
,
2137 /* is_non_type = */ false, pack_p
);
2139 /* Locate the decl of the newly-added, processed template parm. */
2140 parm
= TREE_VALUE (tree_last (TP_PARM_LIST
));
2142 return convert_out (ctx
->preserve (parm
));
2146 plugin_build_value_template_parameter (cc1_plugin::connection
*self
,
2149 gcc_expr default_value
,
2150 const char *filename
,
2151 unsigned int line_number
)
2153 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2154 location_t loc
= ctx
->get_location_t (filename
, line_number
);
2156 gcc_assert (template_parm_scope_p ());
2158 cp_declarator declarator
;
2159 memset (&declarator
, 0, sizeof (declarator
));
2160 // &declarator = make_id_declarator (NULL, get_identifier (id), sfk_none):
2161 declarator
.kind
= cdk_id
;
2162 declarator
.u
.id
.qualifying_scope
= NULL
;
2163 declarator
.u
.id
.unqualified_name
= get_identifier (id
);
2164 declarator
.u
.id
.sfk
= sfk_none
;
2166 cp_decl_specifier_seq declspec
;
2167 memset (&declspec
, 0, sizeof (declspec
));
2168 // cp_parser_set_decl_spec_type (&declspec, convert_in (type), -token-, false):
2169 declspec
.any_specifiers_p
= declspec
.any_type_specifiers_p
= true;
2170 declspec
.type
= convert_in (type
);
2171 declspec
.locations
[ds_type_spec
] = loc
;
2173 tree parm
= grokdeclarator (&declarator
, &declspec
, TPARM
, 0, 0);
2174 parm
= build_tree_list (convert_in (default_value
), parm
);
2176 /* Create a type and a decl for the template parm, and add the decl
2178 TP_PARM_LIST
= process_template_parm (TP_PARM_LIST
, loc
, parm
,
2179 /* is_non_type = */ true, false);
2181 /* Locate the decl of the newly-added, processed template parm. */
2182 parm
= TREE_VALUE (tree_last (TP_PARM_LIST
));
2184 return convert_out (ctx
->preserve (parm
));
2188 targlist (const gcc_cp_template_args
*targs
)
2190 int n
= targs
->n_elements
;
2191 tree vec
= make_tree_vec (n
);
2194 switch (targs
->kinds
[n
])
2196 case GCC_CP_TPARG_VALUE
:
2197 TREE_VEC_ELT (vec
, n
) = convert_in (targs
->elements
[n
].value
);
2199 case GCC_CP_TPARG_CLASS
:
2200 TREE_VEC_ELT (vec
, n
) = convert_in (targs
->elements
[n
].type
);
2202 case GCC_CP_TPARG_TEMPL
:
2203 TREE_VEC_ELT (vec
, n
) = convert_in (targs
->elements
[n
].templ
);
2205 case GCC_CP_TPARG_PACK
:
2206 TREE_VEC_ELT (vec
, n
) = convert_in (targs
->elements
[n
].pack
);
2216 plugin_build_dependent_typename (cc1_plugin::connection
*self
,
2217 gcc_type enclosing_type
,
2219 const gcc_cp_template_args
*targs
)
2221 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2222 tree type
= convert_in (enclosing_type
);
2223 tree name
= get_identifier (id
);
2225 name
= build_min_nt_loc (/*loc=*/0, TEMPLATE_ID_EXPR
,
2226 name
, targlist (targs
));
2227 tree res
= make_typename_type (type
, name
, typename_type
,
2228 /*complain=*/tf_error
);
2229 return convert_out (ctx
->preserve (res
));
2233 plugin_build_dependent_class_template (cc1_plugin::connection
*self
,
2234 gcc_type enclosing_type
,
2237 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2238 tree type
= convert_in (enclosing_type
);
2239 tree name
= get_identifier (id
);
2240 tree res
= make_unbound_class_template (type
, name
, NULL_TREE
,
2241 /*complain=*/tf_error
);
2242 return convert_out (ctx
->preserve (res
));
2246 plugin_build_dependent_type_template_id (cc1_plugin::connection
*self
,
2247 gcc_utempl template_decl
,
2248 const gcc_cp_template_args
*targs
)
2250 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2251 tree type
= convert_in (template_decl
);
2252 tree decl
= finish_template_type (type
, targlist (targs
),
2253 /*entering_scope=*/false);
2254 return convert_out (ctx
->preserve (TREE_TYPE (decl
)));
2258 plugin_build_dependent_expr (cc1_plugin::connection
*self
,
2259 gcc_decl enclosing_scope
,
2260 enum gcc_cp_symbol_kind flags
,
2262 gcc_type conv_type_in
,
2263 const gcc_cp_template_args
*targs
)
2265 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2266 tree scope
= convert_in (enclosing_scope
);
2267 tree conv_type
= convert_in (conv_type_in
);
2270 if (TREE_CODE (scope
) != NAMESPACE_DECL
)
2272 tree type
= TREE_TYPE (scope
);
2273 gcc_assert (TYPE_NAME (type
) == scope
);
2277 if (flags
== (GCC_CP_SYMBOL_FUNCTION
| GCC_CP_FLAG_SPECIAL_FUNCTION
))
2279 bool assop
= false, convop
= false;
2280 tree_code opcode
= ERROR_MARK
;
2282 switch (CHARS2 (name
[0], name
[1]))
2284 case CHARS2 ('C', 0x0): // ctor base declaration
2285 case CHARS2 ('C', ' '):
2286 case CHARS2 ('C', '1'):
2287 case CHARS2 ('C', '2'):
2288 case CHARS2 ('C', '4'):
2289 identifier
= ctor_identifier
;
2291 case CHARS2 ('D', 0x0): // dtor base declaration
2292 case CHARS2 ('D', ' '):
2293 case CHARS2 ('D', '0'):
2294 case CHARS2 ('D', '1'):
2295 case CHARS2 ('D', '2'):
2296 case CHARS2 ('D', '4'):
2297 gcc_assert (!targs
);
2298 identifier
= dtor_identifier
;
2300 case CHARS2 ('n', 'w'): // operator new
2303 case CHARS2 ('n', 'a'): // operator new[]
2304 opcode
= VEC_NEW_EXPR
;
2306 case CHARS2 ('d', 'l'): // operator delete
2307 opcode
= DELETE_EXPR
;
2309 case CHARS2 ('d', 'a'): // operator delete[]
2310 opcode
= VEC_DELETE_EXPR
;
2312 case CHARS2 ('p', 's'): // operator + (unary)
2315 case CHARS2 ('n', 'g'): // operator - (unary)
2316 opcode
= MINUS_EXPR
;
2318 case CHARS2 ('a', 'd'): // operator & (unary)
2319 opcode
= BIT_AND_EXPR
;
2321 case CHARS2 ('d', 'e'): // operator * (unary)
2324 case CHARS2 ('c', 'o'): // operator ~
2325 opcode
= BIT_NOT_EXPR
;
2327 case CHARS2 ('p', 'l'): // operator +
2330 case CHARS2 ('m', 'i'): // operator -
2331 opcode
= MINUS_EXPR
;
2333 case CHARS2 ('m', 'l'): // operator *
2336 case CHARS2 ('d', 'v'): // operator /
2337 opcode
= TRUNC_DIV_EXPR
;
2339 case CHARS2 ('r', 'm'): // operator %
2340 opcode
= TRUNC_MOD_EXPR
;
2342 case CHARS2 ('a', 'n'): // operator &
2343 opcode
= BIT_AND_EXPR
;
2345 case CHARS2 ('o', 'r'): // operator |
2346 opcode
= BIT_IOR_EXPR
;
2348 case CHARS2 ('e', 'o'): // operator ^
2349 opcode
= BIT_XOR_EXPR
;
2351 case CHARS2 ('a', 'S'): // operator =
2355 case CHARS2 ('p', 'L'): // operator +=
2359 case CHARS2 ('m', 'I'): // operator -=
2360 opcode
= MINUS_EXPR
;
2363 case CHARS2 ('m', 'L'): // operator *=
2367 case CHARS2 ('d', 'V'): // operator /=
2368 opcode
= TRUNC_DIV_EXPR
;
2371 case CHARS2 ('r', 'M'): // operator %=
2372 opcode
= TRUNC_MOD_EXPR
;
2375 case CHARS2 ('a', 'N'): // operator &=
2376 opcode
= BIT_AND_EXPR
;
2379 case CHARS2 ('o', 'R'): // operator |=
2380 opcode
= BIT_IOR_EXPR
;
2383 case CHARS2 ('e', 'O'): // operator ^=
2384 opcode
= BIT_XOR_EXPR
;
2387 case CHARS2 ('l', 's'): // operator <<
2388 opcode
= LSHIFT_EXPR
;
2390 case CHARS2 ('r', 's'): // operator >>
2391 opcode
= RSHIFT_EXPR
;
2393 case CHARS2 ('l', 'S'): // operator <<=
2394 opcode
= LSHIFT_EXPR
;
2397 case CHARS2 ('r', 'S'): // operator >>=
2398 opcode
= RSHIFT_EXPR
;
2401 case CHARS2 ('e', 'q'): // operator ==
2404 case CHARS2 ('n', 'e'): // operator !=
2407 case CHARS2 ('l', 't'): // operator <
2410 case CHARS2 ('g', 't'): // operator >
2413 case CHARS2 ('l', 'e'): // operator <=
2416 case CHARS2 ('g', 'e'): // operator >=
2419 case CHARS2 ('n', 't'): // operator !
2420 opcode
= TRUTH_NOT_EXPR
;
2422 case CHARS2 ('a', 'a'): // operator &&
2423 opcode
= TRUTH_ANDIF_EXPR
;
2425 case CHARS2 ('o', 'o'): // operator ||
2426 opcode
= TRUTH_ORIF_EXPR
;
2428 case CHARS2 ('p', 'p'): // operator ++
2429 opcode
= POSTINCREMENT_EXPR
;
2431 case CHARS2 ('m', 'm'): // operator --
2432 opcode
= PREDECREMENT_EXPR
;
2434 case CHARS2 ('c', 'm'): // operator ,
2435 opcode
= COMPOUND_EXPR
;
2437 case CHARS2 ('p', 'm'): // operator ->*
2438 opcode
= MEMBER_REF
;
2440 case CHARS2 ('p', 't'): // operator ->
2441 opcode
= COMPONENT_REF
;
2443 case CHARS2 ('c', 'l'): // operator ()
2446 case CHARS2 ('i', 'x'): // operator []
2449 case CHARS2 ('c', 'v'): // operator <T> (conversion operator)
2451 identifier
= make_conv_op_name (conv_type
);
2454 case CHARS2 ('l', 'i'): // operator "" <id>
2456 char *id
= (char *)name
+ 2;
2457 bool freeid
= false;
2458 if (*id
>= '0' && *id
<= '9')
2467 while (*id
&& *id
>= '0' && *id
<= '9');
2468 id
= xstrndup (id
, len
);
2471 identifier
= cp_literal_operator_id (id
);
2476 case CHARS2 ('q', 'u'): // ternary operator, not overloadable.
2481 gcc_assert (convop
|| !conv_type
);
2483 if (opcode
!= ERROR_MARK
)
2484 identifier
= ovl_op_identifier (assop
, opcode
);
2486 gcc_assert (identifier
);
2490 gcc_assert (flags
== GCC_CP_SYMBOL_MASK
);
2491 gcc_assert (!conv_type
);
2492 identifier
= get_identifier (name
);
2494 tree res
= identifier
;
2496 res
= lookup_name (res
, LOOK_where::BLOCK_NAMESPACE
);
2497 else if (!TYPE_P (scope
) || !dependent_scope_p (scope
))
2499 res
= lookup_qualified_name (scope
, res
, LOOK_want::NORMAL
, true);
2500 /* We've already resolved the name in the scope, so skip the
2501 build_qualified_name call below. */
2505 res
= lookup_template_function (res
, targlist (targs
));
2507 res
= build_qualified_name (NULL_TREE
, scope
, res
, !!targs
);
2508 return convert_out (ctx
->preserve (res
));
2512 plugin_build_literal_expr (cc1_plugin::connection
*self
,
2513 gcc_type type
, unsigned long value
)
2515 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2516 tree t
= convert_in (type
);
2517 tree val
= build_int_cst_type (t
, (unsigned HOST_WIDE_INT
) value
);
2518 return convert_out (ctx
->preserve (val
));
2522 plugin_build_decl_expr (cc1_plugin::connection
*self
,
2526 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2527 tree decl
= convert_in (decl_in
);
2528 gcc_assert (DECL_P (decl
));
2532 gcc_assert (DECL_CLASS_SCOPE_P (decl
));
2533 result
= build_offset_ref (DECL_CONTEXT (decl
), decl
,
2534 /*address_p=*/true, tf_error
);
2536 return convert_out (ctx
->preserve (result
));
2540 plugin_build_unary_expr (cc1_plugin::connection
*self
,
2541 const char *unary_op
,
2544 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2545 tree op0
= convert_in (operand
);
2546 tree_code opcode
= ERROR_MARK
;
2547 bool global_scope_p
= false;
2550 switch (CHARS2 (unary_op
[0], unary_op
[1]))
2552 case CHARS2 ('p', 's'): // operator + (unary)
2553 opcode
= UNARY_PLUS_EXPR
;
2555 case CHARS2 ('n', 'g'): // operator - (unary)
2556 opcode
= NEGATE_EXPR
;
2558 case CHARS2 ('a', 'd'): // operator & (unary)
2561 case CHARS2 ('d', 'e'): // operator * (unary)
2562 opcode
= INDIRECT_REF
;
2564 case CHARS2 ('c', 'o'): // operator ~
2565 opcode
= BIT_NOT_EXPR
;
2567 case CHARS2 ('n', 't'): // operator !
2568 opcode
= TRUTH_NOT_EXPR
;
2570 case CHARS2 ('p', 'p'): // operator ++
2571 opcode
= unary_op
[2] == '_' ? PREINCREMENT_EXPR
: POSTINCREMENT_EXPR
;
2573 case CHARS2 ('m', 'm'): // operator --
2574 opcode
= unary_op
[2] == '_' ? PREDECREMENT_EXPR
: POSTDECREMENT_EXPR
;
2576 case CHARS2 ('n', 'x'): // noexcept
2577 opcode
= NOEXCEPT_EXPR
;
2579 case CHARS2 ('t', 'w'): // throw
2581 opcode
= THROW_EXPR
;
2583 case CHARS2 ('t', 'r'): // rethrow
2585 opcode
= THROW_EXPR
;
2587 case CHARS2 ('t', 'e'): // typeid (value)
2588 opcode
= TYPEID_EXPR
;
2590 case CHARS2 ('s', 'z'): // sizeof (value)
2591 opcode
= SIZEOF_EXPR
;
2593 case CHARS2 ('a', 'z'): // alignof (value)
2594 opcode
= ALIGNOF_EXPR
;
2596 case CHARS2 ('g', 's'): // global scope (for delete, delete[])
2597 gcc_assert (!global_scope_p
);
2598 global_scope_p
= true;
2601 case CHARS2 ('d', 'l'): // delete
2602 opcode
= DELETE_EXPR
;
2604 case CHARS2 ('d', 'a'): // delete[]
2605 opcode
= VEC_DELETE_EXPR
;
2607 case CHARS2 ('s', 'p'): // pack...
2608 opcode
= EXPR_PACK_EXPANSION
;
2610 case CHARS2 ('s', 'Z'): // sizeof...(pack)
2611 opcode
= TYPE_PACK_EXPANSION
; // Not really, but let's use its code.
2614 /* FIXME: __real__, __imag__? */
2620 gcc_assert (!global_scope_p
2621 || opcode
== DELETE_EXPR
|| opcode
== VEC_DELETE_EXPR
);
2623 processing_template_decl
++;
2624 bool template_dependent_p
= op0
2625 && (type_dependent_expression_p (op0
)
2626 || value_dependent_expression_p (op0
));
2627 if (!template_dependent_p
)
2628 processing_template_decl
--;
2632 gcc_assert (op0
|| opcode
== THROW_EXPR
);
2637 result
= finish_noexcept_expr (op0
, tf_error
);
2641 result
= build_throw (input_location
, op0
);
2645 result
= build_typeid (op0
, tf_error
);
2650 result
= cxx_sizeof_or_alignof_expr (input_location
,
2651 op0
, opcode
, true, true);
2655 case VEC_DELETE_EXPR
:
2656 result
= delete_sanity (input_location
, op0
, NULL_TREE
,
2657 opcode
== VEC_DELETE_EXPR
,
2658 global_scope_p
, tf_error
);
2661 case EXPR_PACK_EXPANSION
:
2662 result
= make_pack_expansion (op0
);
2665 // We're using this for sizeof...(pack). */
2666 case TYPE_PACK_EXPANSION
:
2667 result
= make_pack_expansion (op0
);
2668 PACK_EXPANSION_SIZEOF_P (result
) = true;
2672 result
= build_x_unary_op (/*loc=*/0, opcode
, op0
, NULL_TREE
, tf_error
);
2676 if (template_dependent_p
)
2677 processing_template_decl
--;
2679 return convert_out (ctx
->preserve (result
));
2683 plugin_build_binary_expr (cc1_plugin::connection
*self
,
2684 const char *binary_op
,
2688 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2689 tree op0
= convert_in (operand1
);
2690 tree op1
= convert_in (operand2
);
2691 tree_code opcode
= ERROR_MARK
;
2693 switch (CHARS2 (binary_op
[0], binary_op
[1]))
2695 case CHARS2 ('p', 'l'): // operator +
2698 case CHARS2 ('m', 'i'): // operator -
2699 opcode
= MINUS_EXPR
;
2701 case CHARS2 ('m', 'l'): // operator *
2704 case CHARS2 ('d', 'v'): // operator /
2705 opcode
= TRUNC_DIV_EXPR
;
2707 case CHARS2 ('r', 'm'): // operator %
2708 opcode
= TRUNC_MOD_EXPR
;
2710 case CHARS2 ('a', 'n'): // operator &
2711 opcode
= BIT_AND_EXPR
;
2713 case CHARS2 ('o', 'r'): // operator |
2714 opcode
= BIT_IOR_EXPR
;
2716 case CHARS2 ('e', 'o'): // operator ^
2717 opcode
= BIT_XOR_EXPR
;
2719 case CHARS2 ('l', 's'): // operator <<
2720 opcode
= LSHIFT_EXPR
;
2722 case CHARS2 ('r', 's'): // operator >>
2723 opcode
= RSHIFT_EXPR
;
2725 case CHARS2 ('e', 'q'): // operator ==
2728 case CHARS2 ('n', 'e'): // operator !=
2731 case CHARS2 ('l', 't'): // operator <
2734 case CHARS2 ('g', 't'): // operator >
2737 case CHARS2 ('l', 'e'): // operator <=
2740 case CHARS2 ('g', 'e'): // operator >=
2743 case CHARS2 ('a', 'a'): // operator &&
2744 opcode
= TRUTH_ANDIF_EXPR
;
2746 case CHARS2 ('o', 'o'): // operator ||
2747 opcode
= TRUTH_ORIF_EXPR
;
2749 case CHARS2 ('c', 'm'): // operator ,
2750 opcode
= COMPOUND_EXPR
;
2752 case CHARS2 ('p', 'm'): // operator ->*
2753 opcode
= MEMBER_REF
;
2755 case CHARS2 ('p', 't'): // operator ->
2756 opcode
= INDIRECT_REF
; // Not really! This will stand for
2757 // INDIRECT_REF followed by COMPONENT_REF
2760 case CHARS2 ('i', 'x'): // operator []
2763 case CHARS2 ('d', 's'): // operator .*
2764 opcode
= DOTSTAR_EXPR
;
2766 case CHARS2 ('d', 't'): // operator .
2767 opcode
= COMPONENT_REF
;
2774 processing_template_decl
++;
2775 bool template_dependent_p
= type_dependent_expression_p (op0
)
2776 || value_dependent_expression_p (op0
)
2777 || type_dependent_expression_p (op1
)
2778 || value_dependent_expression_p (op1
);
2779 if (!template_dependent_p
)
2780 processing_template_decl
--;
2786 case INDIRECT_REF
: // This is actually a "->".
2787 op0
= build_x_arrow (/*loc=*/0, op0
, tf_error
);
2790 result
= finish_class_member_access_expr (op0
, op1
,
2791 /*template_p=*/false,
2796 result
= build_x_binary_op (/*loc=*/0, opcode
, op0
, ERROR_MARK
,
2797 op1
, ERROR_MARK
, NULL_TREE
, NULL
, tf_error
);
2801 if (template_dependent_p
)
2802 processing_template_decl
--;
2804 return convert_out (ctx
->preserve (result
));
2808 plugin_build_ternary_expr (cc1_plugin::connection
*self
,
2809 const char *ternary_op
,
2814 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2815 tree op0
= convert_in (operand1
);
2816 tree op1
= convert_in (operand2
);
2817 tree op2
= convert_in (operand3
);
2818 gcc_assert (CHARS2 (ternary_op
[0], ternary_op
[1])
2819 == CHARS2 ('q', 'u')); // ternary operator
2821 processing_template_decl
++;
2822 bool template_dependent_p
= type_dependent_expression_p (op0
)
2823 || value_dependent_expression_p (op0
)
2824 || type_dependent_expression_p (op1
)
2825 || value_dependent_expression_p (op1
)
2826 || type_dependent_expression_p (op2
)
2827 || value_dependent_expression_p (op2
);
2828 if (!template_dependent_p
)
2829 processing_template_decl
--;
2831 tree val
= build_x_conditional_expr (/*loc=*/0, op0
, op1
, op2
, tf_error
);
2833 if (template_dependent_p
)
2834 processing_template_decl
--;
2836 return convert_out (ctx
->preserve (val
));
2840 plugin_build_unary_type_expr (cc1_plugin::connection
*self
,
2841 const char *unary_op
,
2844 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2845 tree type
= convert_in (operand
);
2846 tree_code opcode
= ERROR_MARK
;
2848 switch (CHARS2 (unary_op
[0], unary_op
[1]))
2850 case CHARS2 ('t', 'i'): // typeid (type)
2851 opcode
= TYPEID_EXPR
;
2854 case CHARS2 ('s', 't'): // sizeof (type)
2855 opcode
= SIZEOF_EXPR
;
2857 case CHARS2 ('a', 't'): // alignof (type)
2858 opcode
= ALIGNOF_EXPR
;
2861 case CHARS2 ('s', 'Z'): // sizeof...(pack)
2862 opcode
= TYPE_PACK_EXPANSION
; // Not really, but let's use its code.
2865 // FIXME: do we have to handle "sp", for the size of a captured
2866 // template parameter pack from an alias template, taking
2867 // multiple template arguments?
2873 processing_template_decl
++;
2874 bool template_dependent_p
= dependent_type_p (type
);
2875 if (!template_dependent_p
)
2876 processing_template_decl
--;
2883 result
= get_typeid (type
, tf_error
);
2886 // We're using this for sizeof...(pack). */
2887 case TYPE_PACK_EXPANSION
:
2888 result
= make_pack_expansion (type
);
2889 PACK_EXPANSION_SIZEOF_P (result
) = true;
2893 /* Use the C++11 alignof semantics. */
2894 result
= cxx_sizeof_or_alignof_type (input_location
, type
,
2895 opcode
, true, true);
2898 if (template_dependent_p
)
2899 processing_template_decl
--;
2901 return convert_out (ctx
->preserve (result
));
2905 plugin_build_cast_expr (cc1_plugin::connection
*self
,
2906 const char *binary_op
,
2910 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2911 tree (*build_cast
)(location_t loc
, tree type
, tree expr
,
2912 tsubst_flags_t complain
) = NULL
;
2913 tree type
= convert_in (operand1
);
2914 tree expr
= convert_in (operand2
);
2916 switch (CHARS2 (binary_op
[0], binary_op
[1]))
2918 case CHARS2 ('d', 'c'): // dynamic_cast
2919 build_cast
= build_dynamic_cast
;
2922 case CHARS2 ('s', 'c'): // static_cast
2923 build_cast
= build_static_cast
;
2926 case CHARS2 ('c', 'c'): // const_cast
2927 build_cast
= build_const_cast
;
2930 case CHARS2 ('r', 'c'): // reinterpret_cast
2931 build_cast
= build_reinterpret_cast
;
2934 case CHARS2 ('c', 'v'): // C cast, conversion with one argument
2935 build_cast
= cp_build_c_cast
;
2942 processing_template_decl
++;
2943 bool template_dependent_p
= dependent_type_p (type
)
2944 || type_dependent_expression_p (expr
)
2945 || value_dependent_expression_p (expr
);
2946 if (!template_dependent_p
)
2947 processing_template_decl
--;
2949 tree val
= build_cast (input_location
, type
, expr
, tf_error
);
2951 if (template_dependent_p
)
2952 processing_template_decl
--;
2954 return convert_out (ctx
->preserve (val
));
2957 static inline vec
<tree
, va_gc
> *
2958 args_to_tree_vec (const struct gcc_cp_function_args
*args_in
)
2960 vec
<tree
, va_gc
> *args
= make_tree_vector ();
2961 for (int i
= 0; i
< args_in
->n_elements
; i
++)
2962 vec_safe_push (args
, convert_in (args_in
->elements
[i
]));
2967 args_to_tree_list (const struct gcc_cp_function_args
*args_in
)
2969 tree args
, *tail
= &args
;
2970 for (int i
= 0; i
< args_in
->n_elements
; i
++)
2972 *tail
= build_tree_list (NULL
, convert_in (args_in
->elements
[i
]));
2973 tail
= &TREE_CHAIN (*tail
);
2978 static inline vec
<constructor_elt
, va_gc
> *
2979 args_to_ctor_elts (const struct gcc_cp_function_args
*args_in
)
2981 vec
<constructor_elt
, va_gc
> *args
= NULL
;
2982 for (int i
= 0; i
< args_in
->n_elements
; i
++)
2983 CONSTRUCTOR_APPEND_ELT (args
, NULL_TREE
, convert_in (args_in
->elements
[i
]));
2988 plugin_build_expression_list_expr (cc1_plugin::connection
*self
,
2989 const char *conv_op
,
2991 const struct gcc_cp_function_args
*values_in
)
2993 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2994 tree type
= convert_in (type_in
);
2998 switch (CHARS2 (conv_op
[0], conv_op
[1]))
3000 case CHARS2 ('c', 'v'): // conversion with parenthesized expression list
3001 gcc_assert (TYPE_P (type
));
3002 args
= args_to_tree_list (values_in
);
3003 result
= build_functional_cast (input_location
, type
, args
, tf_error
);
3006 case CHARS2 ('t', 'l'): // conversion with braced expression list
3008 gcc_assert (TYPE_P (type
));
3009 args
= make_node (CONSTRUCTOR
);
3010 CONSTRUCTOR_ELTS (args
) = args_to_ctor_elts (values_in
);
3011 CONSTRUCTOR_IS_DIRECT_INIT (args
) = 1;
3012 result
= finish_compound_literal (type
, args
, tf_error
);
3015 case CHARS2 ('i', 'l'): // untyped braced expression list
3017 result
= make_node (CONSTRUCTOR
);
3018 CONSTRUCTOR_ELTS (result
) = args_to_ctor_elts (values_in
);
3025 return convert_out (ctx
->preserve (result
));
3029 plugin_build_new_expr (cc1_plugin::connection
*self
,
3031 const struct gcc_cp_function_args
*placement_in
,
3033 const struct gcc_cp_function_args
*initializer_in
)
3035 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3036 tree type
= convert_in (type_in
);
3037 vec
<tree
, va_gc
> *placement
= NULL
, *initializer
= NULL
;
3038 bool global_scope_p
= false;
3042 placement
= args_to_tree_vec (placement_in
);
3044 initializer
= args_to_tree_vec (initializer_in
);
3046 gcc_assert (TYPE_P (type
));
3049 switch (CHARS2 (new_op
[0], new_op
[1]))
3051 case CHARS2 ('g', 's'):
3052 gcc_assert (!global_scope_p
);
3053 global_scope_p
= true;
3057 case CHARS2 ('n', 'w'): // non-array new
3058 gcc_assert (TREE_CODE (type
) != ARRAY_TYPE
);
3061 case CHARS2 ('n', 'a'): // array new
3062 gcc_assert (TREE_CODE (type
) == ARRAY_TYPE
);
3063 gcc_assert (TYPE_DOMAIN (type
));
3065 // Compute the length of the outermost array type, then discard it.
3066 tree maxelt
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
3067 tree eltype
= TREE_TYPE (maxelt
);
3068 tree onecst
= integer_one_node
;
3070 processing_template_decl
++;
3071 bool template_dependent_p
= value_dependent_expression_p (maxelt
)
3072 || type_dependent_expression_p (maxelt
);
3073 if (!template_dependent_p
)
3075 processing_template_decl
--;
3076 onecst
= fold_convert (eltype
, onecst
);
3079 nelts
= fold_build2 (PLUS_EXPR
, eltype
, nelts
, onecst
);
3081 if (template_dependent_p
)
3082 processing_template_decl
--;
3084 type
= TREE_TYPE (type
);
3092 processing_template_decl
++;
3093 bool template_dependent_p
= dependent_type_p (type
)
3094 || value_dependent_expression_p (nelts
)
3096 && any_type_dependent_arguments_p (placement
))
3098 && any_type_dependent_arguments_p (initializer
));
3099 if (!template_dependent_p
)
3100 processing_template_decl
--;
3102 tree result
= build_new (input_location
, &placement
, type
, nelts
,
3103 &initializer
, global_scope_p
, tf_error
);
3105 if (template_dependent_p
)
3106 processing_template_decl
--;
3108 if (placement
!= NULL
)
3109 release_tree_vector (placement
);
3110 if (initializer
!= NULL
)
3111 release_tree_vector (initializer
);
3113 return convert_out (ctx
->preserve (result
));
3117 plugin_build_call_expr (cc1_plugin::connection
*self
,
3118 gcc_expr callable_in
, int qualified_p
,
3119 const struct gcc_cp_function_args
*args_in
)
3121 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3122 tree callable
= convert_in (callable_in
);
3125 vec
<tree
, va_gc
> *args
= args_to_tree_vec (args_in
);
3127 bool koenig_p
= false;
3128 if (!qualified_p
&& !args
->is_empty ())
3130 if (identifier_p (callable
))
3132 else if (is_overloaded_fn (callable
))
3134 tree fn
= get_first_fn (callable
);
3135 fn
= STRIP_TEMPLATE (fn
);
3137 if (!DECL_FUNCTION_MEMBER_P (fn
)
3138 && !DECL_LOCAL_DECL_P (fn
))
3143 if (koenig_p
&& !any_type_dependent_arguments_p (args
))
3144 callable
= perform_koenig_lookup (callable
, args
, tf_none
);
3146 if (TREE_CODE (callable
) == COMPONENT_REF
)
3148 tree object
= TREE_OPERAND (callable
, 0);
3149 tree memfn
= TREE_OPERAND (callable
, 1);
3151 if (type_dependent_expression_p (object
)
3152 || (!BASELINK_P (memfn
) && TREE_CODE (memfn
) != FIELD_DECL
)
3153 || type_dependent_expression_p (memfn
)
3154 || any_type_dependent_arguments_p (args
))
3155 call_expr
= build_nt_call_vec (callable
, args
);
3156 else if (BASELINK_P (memfn
))
3157 call_expr
= build_new_method_call (object
, memfn
, &args
, NULL_TREE
,
3159 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
3163 call_expr
= finish_call_expr (callable
, &args
, false, false, tf_none
);
3165 else if (TREE_CODE (callable
) == OFFSET_REF
3166 || TREE_CODE (callable
) == MEMBER_REF
3167 || TREE_CODE (callable
) == DOTSTAR_EXPR
)
3168 call_expr
= build_offset_ref_call_from_tree (callable
, &args
, tf_none
);
3170 call_expr
= finish_call_expr (callable
, &args
,
3171 !!qualified_p
, koenig_p
, tf_none
);
3173 release_tree_vector (args
);
3174 return convert_out (ctx
->preserve (call_expr
));
3178 plugin_get_expr_type (cc1_plugin::connection
*self
,
3181 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3182 tree op0
= convert_in (operand
);
3185 type
= TREE_TYPE (op0
);
3187 type
= make_decltype_auto ();
3188 return convert_out (ctx
->preserve (type
));
3192 plugin_build_function_template_specialization (cc1_plugin::connection
*self
,
3193 gcc_decl template_decl
,
3194 const gcc_cp_template_args
*targs
,
3195 gcc_address address
,
3196 const char *filename
,
3197 unsigned int line_number
)
3199 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3200 location_t loc
= ctx
->get_location_t (filename
, line_number
);
3201 tree name
= convert_in (template_decl
);
3202 tree targsl
= targlist (targs
);
3204 tree decl
= tsubst (name
, targsl
, tf_error
, NULL_TREE
);
3205 DECL_SOURCE_LOCATION (decl
) = loc
;
3207 record_decl_address (ctx
, build_decl_addr_value (decl
, address
));
3209 return convert_out (ctx
->preserve (decl
));
3213 plugin_build_class_template_specialization (cc1_plugin::connection
*self
,
3214 gcc_decl template_decl
,
3215 const gcc_cp_template_args
*args
,
3216 const char *filename
,
3217 unsigned int line_number
)
3219 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3220 location_t loc
= ctx
->get_location_t (filename
, line_number
);
3221 tree name
= convert_in (template_decl
);
3223 tree tdecl
= finish_template_type (name
, targlist (args
), false);;
3224 DECL_SOURCE_LOCATION (tdecl
) = loc
;
3226 return convert_out (ctx
->preserve (tdecl
));
3229 /* Return a builtin type associated with BUILTIN_NAME. */
3232 safe_lookup_builtin_type (const char *builtin_name
)
3234 tree result
= NULL_TREE
;
3239 result
= identifier_global_value (get_identifier (builtin_name
));
3244 gcc_assert (TREE_CODE (result
) == TYPE_DECL
);
3245 result
= TREE_TYPE (result
);
3250 plugin_get_int_type (cc1_plugin::connection
*self
,
3251 int is_unsigned
, unsigned long size_in_bytes
,
3252 const char *builtin_name
)
3258 result
= safe_lookup_builtin_type (builtin_name
);
3259 gcc_assert (!result
|| TREE_CODE (result
) == INTEGER_TYPE
);
3262 result
= c_common_type_for_size (BITS_PER_UNIT
* size_in_bytes
,
3265 if (result
== NULL_TREE
)
3266 result
= error_mark_node
;
3269 gcc_assert (!TYPE_UNSIGNED (result
) == !is_unsigned
);
3270 gcc_assert (TREE_CODE (TYPE_SIZE (result
)) == INTEGER_CST
);
3271 gcc_assert (TYPE_PRECISION (result
) == BITS_PER_UNIT
* size_in_bytes
);
3273 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3274 ctx
->preserve (result
);
3276 return convert_out (result
);
3280 plugin_get_char_type (cc1_plugin::connection
*)
3282 return convert_out (char_type_node
);
3286 plugin_get_float_type (cc1_plugin::connection
*,
3287 unsigned long size_in_bytes
,
3288 const char *builtin_name
)
3292 tree result
= safe_lookup_builtin_type (builtin_name
);
3295 return convert_out (error_mark_node
);
3297 gcc_assert (TREE_CODE (result
) == REAL_TYPE
);
3298 gcc_assert (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (result
));
3300 return convert_out (result
);
3303 if (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (float_type_node
))
3304 return convert_out (float_type_node
);
3305 if (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (double_type_node
))
3306 return convert_out (double_type_node
);
3307 if (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (long_double_type_node
))
3308 return convert_out (long_double_type_node
);
3309 return convert_out (error_mark_node
);
3313 plugin_get_void_type (cc1_plugin::connection
*)
3315 return convert_out (void_type_node
);
3319 plugin_get_bool_type (cc1_plugin::connection
*)
3321 return convert_out (boolean_type_node
);
3325 plugin_get_nullptr_type (cc1_plugin::connection
*)
3327 return convert_out (nullptr_type_node
);
3331 plugin_get_nullptr_constant (cc1_plugin::connection
*)
3333 return convert_out (nullptr_node
);
3337 plugin_build_array_type (cc1_plugin::connection
*self
,
3338 gcc_type element_type_in
, int num_elements
)
3340 tree element_type
= convert_in (element_type_in
);
3343 if (num_elements
== -1)
3344 result
= build_array_type (element_type
, NULL_TREE
);
3346 result
= build_array_type_nelts (element_type
, num_elements
);
3348 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3349 return convert_out (ctx
->preserve (result
));
3353 plugin_build_dependent_array_type (cc1_plugin::connection
*self
,
3354 gcc_type element_type_in
,
3355 gcc_expr num_elements_in
)
3357 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3358 tree element_type
= convert_in (element_type_in
);
3359 tree size
= convert_in (num_elements_in
);
3360 tree name
= get_identifier ("dependent array type");
3362 processing_template_decl
++;
3363 bool template_dependent_p
= dependent_type_p (element_type
)
3364 || type_dependent_expression_p (size
)
3365 || value_dependent_expression_p (size
);
3366 if (!template_dependent_p
)
3367 processing_template_decl
--;
3369 tree itype
= compute_array_index_type (name
, size
, tf_error
);
3370 tree type
= build_cplus_array_type (element_type
, itype
);
3372 if (template_dependent_p
)
3373 processing_template_decl
--;
3375 return convert_out (ctx
->preserve (type
));
3379 plugin_build_vla_array_type (cc1_plugin::connection
*self
,
3380 gcc_type element_type_in
,
3381 const char *upper_bound_name
)
3383 tree element_type
= convert_in (element_type_in
);
3384 tree upper_bound
= lookup_name (get_identifier (upper_bound_name
));
3385 tree size
= fold_build2 (PLUS_EXPR
, TREE_TYPE (upper_bound
), upper_bound
,
3386 build_one_cst (TREE_TYPE (upper_bound
)));
3387 tree range
= compute_array_index_type (NULL_TREE
, size
,
3390 tree result
= build_cplus_array_type (element_type
, range
);
3392 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3393 return convert_out (ctx
->preserve (result
));
3397 plugin_build_qualified_type (cc1_plugin::connection
*,
3398 gcc_type unqualified_type_in
,
3399 enum gcc_cp_qualifiers qualifiers
)
3401 tree unqualified_type
= convert_in (unqualified_type_in
);
3402 cp_cv_quals quals
= 0;
3404 if ((qualifiers
& GCC_CP_QUALIFIER_CONST
) != 0)
3405 quals
|= TYPE_QUAL_CONST
;
3406 if ((qualifiers
& GCC_CP_QUALIFIER_VOLATILE
) != 0)
3407 quals
|= TYPE_QUAL_VOLATILE
;
3408 if ((qualifiers
& GCC_CP_QUALIFIER_RESTRICT
) != 0)
3409 quals
|= TYPE_QUAL_RESTRICT
;
3411 gcc_assert ((TREE_CODE (unqualified_type
) != METHOD_TYPE
3412 && TREE_CODE (unqualified_type
) != REFERENCE_TYPE
)
3415 return convert_out (build_qualified_type (unqualified_type
, quals
));
3419 plugin_build_complex_type (cc1_plugin::connection
*self
,
3422 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3423 return convert_out (ctx
->preserve (build_complex_type (convert_in (base_type
))));
3427 plugin_build_vector_type (cc1_plugin::connection
*self
,
3428 gcc_type base_type
, int nunits
)
3430 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3431 return convert_out (ctx
->preserve (build_vector_type (convert_in (base_type
),
3436 plugin_build_constant (cc1_plugin::connection
*self
, gcc_type type_in
,
3437 const char *name
, unsigned long value
,
3438 const char *filename
, unsigned int line_number
)
3440 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3442 tree type
= convert_in (type_in
);
3444 cst
= build_int_cst (type
, value
);
3445 if (!TYPE_READONLY (type
))
3446 type
= build_qualified_type (type
, TYPE_QUAL_CONST
);
3447 decl
= build_decl (ctx
->get_location_t (filename
, line_number
),
3448 VAR_DECL
, get_identifier (name
), type
);
3449 TREE_STATIC (decl
) = 1;
3450 TREE_READONLY (decl
) = 1;
3451 cp_finish_decl (decl
, cst
, true, NULL
, LOOKUP_ONLYCONVERTING
);
3452 safe_pushdecl (decl
);
3458 plugin_error (cc1_plugin::connection
*,
3459 const char *message
)
3461 error ("%s", message
);
3462 return convert_out (error_mark_node
);
3466 plugin_add_static_assert (cc1_plugin::connection
*self
,
3467 gcc_expr condition_in
,
3468 const char *errormsg
,
3469 const char *filename
,
3470 unsigned int line_number
)
3472 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3473 tree condition
= convert_in (condition_in
);
3478 tree message
= build_string (strlen (errormsg
) + 1, errormsg
);
3480 TREE_TYPE (message
) = char_array_type_node
;
3481 fix_string_type (message
);
3483 location_t loc
= ctx
->get_location_t (filename
, line_number
);
3485 bool member_p
= at_class_scope_p ();
3487 finish_static_assert (condition
, message
, loc
, member_p
, false);
3495 #pragma GCC visibility push(default)
3499 plugin_init (struct plugin_name_args
*plugin_info
,
3500 struct plugin_gcc_version
*)
3502 generic_plugin_init (plugin_info
, GCC_CP_FE_VERSION_0
);
3504 register_callback (plugin_info
->base_name
, PLUGIN_PRAGMAS
,
3505 plugin_init_extra_pragmas
, NULL
);
3506 register_callback (plugin_info
->base_name
, PLUGIN_PRE_GENERICIZE
,
3507 rewrite_decls_to_addresses
, NULL
);
3509 #define GCC_METHOD0(R, N) \
3511 cc1_plugin::callback_ftype *fun \
3512 = cc1_plugin::invoker<R>::invoke<plugin_ ## N>; \
3513 current_context->add_callback (# N, fun); \
3515 #define GCC_METHOD1(R, N, A) \
3517 cc1_plugin::callback_ftype *fun \
3518 = cc1_plugin::invoker<R, A>::invoke<plugin_ ## N>; \
3519 current_context->add_callback (# N, fun); \
3521 #define GCC_METHOD2(R, N, A, B) \
3523 cc1_plugin::callback_ftype *fun \
3524 = cc1_plugin::invoker<R, A, B>::invoke<plugin_ ## N>; \
3525 current_context->add_callback (# N, fun); \
3527 #define GCC_METHOD3(R, N, A, B, C) \
3529 cc1_plugin::callback_ftype *fun \
3530 = cc1_plugin::invoker<R, A, B, C>::invoke<plugin_ ## N>; \
3531 current_context->add_callback (# N, fun); \
3533 #define GCC_METHOD4(R, N, A, B, C, D) \
3535 cc1_plugin::callback_ftype *fun \
3536 = cc1_plugin::invoker<R, A, B, C, \
3537 D>::invoke<plugin_ ## N>; \
3538 current_context->add_callback (# N, fun); \
3540 #define GCC_METHOD5(R, N, A, B, C, D, E) \
3542 cc1_plugin::callback_ftype *fun \
3543 = cc1_plugin::invoker<R, A, B, C, \
3544 D, E>::invoke<plugin_ ## N>; \
3545 current_context->add_callback (# N, fun); \
3547 #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
3549 cc1_plugin::callback_ftype *fun \
3550 = cc1_plugin::invoker<R, A, B, C, \
3551 D, E, F, G>::invoke<plugin_ ## N>; \
3552 current_context->add_callback (# N, fun); \
3555 #include "gcc-cp-fe.def"