1 /* Library interface to C++ front end.
2 Copyright (C) 2014-2019 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"
44 #include "double-int.h"
52 #include "fold-const.h"
53 #include "stor-layout.h"
57 #include "hash-table.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"
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"
74 #pragma GCC visibility push(default)
76 int plugin_is_GPL_compatible
;
78 #pragma GCC visibility pop
83 static int ATTRIBUTE_UNUSED
84 check_symbol_mask
[GCC_CP_SYMBOL_MASK
>= GCC_CP_SYMBOL_END
? 1 : -1];
86 // This is put into the lang hooks when the plugin starts.
89 plugin_print_error_function (diagnostic_context
*context
, const char *file
,
90 diagnostic_info
*diagnostic
)
92 if (current_function_decl
!= NULL_TREE
93 && DECL_NAME (current_function_decl
) != NULL_TREE
94 && strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)),
95 GCC_FE_WRAPPER_FUNCTION
) == 0)
97 lhd_print_error_function (context
, file
, diagnostic
);
102 static unsigned long long
105 return (unsigned long long) (uintptr_t) t
;
109 convert_in (unsigned long long v
)
111 return (tree
) (uintptr_t) v
;
116 struct decl_addr_value
122 struct decl_addr_hasher
: free_ptr_hash
<decl_addr_value
>
124 static inline hashval_t
hash (const decl_addr_value
*);
125 static inline bool equal (const decl_addr_value
*, const decl_addr_value
*);
129 decl_addr_hasher::hash (const decl_addr_value
*e
)
131 return DECL_UID (e
->decl
);
135 decl_addr_hasher::equal (const decl_addr_value
*p1
, const decl_addr_value
*p2
)
137 return p1
->decl
== p2
->decl
;
142 struct string_hasher
: nofree_ptr_hash
<const char>
144 static inline hashval_t
hash (const char *s
)
146 return htab_hash_string (s
);
149 static inline bool equal (const char *p1
, const char *p2
)
151 return strcmp (p1
, p2
) == 0;
157 struct plugin_context
: public cc1_plugin::connection
159 plugin_context (int fd
);
161 // Map decls to addresses.
162 hash_table
<decl_addr_hasher
> address_map
;
164 // A collection of trees that are preserved for the GC.
165 hash_table
< nofree_ptr_hash
<tree_node
> > preserved
;
168 hash_table
<string_hasher
> file_names
;
170 // Perform GC marking.
173 // Preserve a tree during the plugin's operation.
174 tree
preserve (tree t
)
176 tree_node
**slot
= preserved
.find_slot (t
, INSERT
);
181 location_t
get_location_t (const char *filename
,
182 unsigned int line_number
)
184 if (filename
== NULL
)
185 return UNKNOWN_LOCATION
;
187 filename
= intern_filename (filename
);
188 linemap_add (line_table
, LC_ENTER
, false, filename
, line_number
);
189 location_t loc
= linemap_line_start (line_table
, line_number
, 0);
190 linemap_add (line_table
, LC_LEAVE
, false, NULL
, 0);
196 // Add a file name to FILE_NAMES and return the canonical copy.
197 const char *intern_filename (const char *filename
)
199 const char **slot
= file_names
.find_slot (filename
, INSERT
);
202 /* The file name must live as long as the line map, which
203 effectively means as long as this compilation. So, we copy
204 the string here but never free it. */
205 *slot
= xstrdup (filename
);
211 static plugin_context
*current_context
;
215 plugin_context::plugin_context (int fd
)
216 : cc1_plugin::connection (fd
),
224 plugin_context::mark ()
226 for (hash_table
<decl_addr_hasher
>::iterator it
= address_map
.begin ();
227 it
!= address_map
.end ();
230 ggc_mark ((*it
)->decl
);
231 ggc_mark ((*it
)->address
);
234 for (hash_table
< nofree_ptr_hash
<tree_node
> >::iterator
235 it
= preserved
.begin (); it
!= preserved
.end (); ++it
)
240 plugin_binding_oracle (enum cp_oracle_request kind
, tree identifier
)
242 enum gcc_cp_oracle_request request
;
244 gcc_assert (current_context
!= NULL
);
248 case CP_ORACLE_IDENTIFIER
:
249 request
= GCC_CP_ORACLE_IDENTIFIER
;
256 cc1_plugin::call (current_context
, "binding_oracle", &ignore
,
257 request
, IDENTIFIER_POINTER (identifier
));
260 static int push_count
;
262 /* at_function_scope_p () tests cfun, indicating we're actually
263 compiling the function, but we don't even set it when pretending to
264 enter a function scope. We use this distinction to tell these two
265 cases apart: we don't want to define e.g. class names in the user
266 expression function's scope, when they're local to the original
267 function, because they'd get the wrong linkage name. */
270 at_fake_function_scope_p ()
272 return (!cfun
|| cfun
->decl
!= current_function_decl
)
273 && current_scope () == current_function_decl
;
277 push_fake_function (tree fndecl
, scope_kind kind
= sk_function_parms
)
279 current_function_decl
= fndecl
;
280 begin_scope (kind
, fndecl
);
282 begin_scope (sk_block
, NULL
);
288 if (toplevel_bindings_p () && current_namespace
== global_namespace
)
289 pop_from_top_level ();
290 else if (at_namespace_scope_p ())
292 else if (at_class_scope_p ())
296 gcc_assert (at_fake_function_scope_p ());
297 gcc_assert (!at_function_scope_p ());
298 gcc_assert (current_binding_level
->kind
== sk_block
299 && current_binding_level
->this_entity
== NULL
);
302 gcc_assert (current_binding_level
->this_entity
303 == current_function_decl
);
305 current_function_decl
= NULL
;
306 for (cp_binding_level
*scope
= current_binding_level
;
307 scope
; scope
= scope
->level_chain
)
308 if (scope
->kind
== sk_function_parms
)
310 current_function_decl
= scope
->this_entity
;
317 supplement_binding (cxx_binding
*binding
, tree decl
)
319 /* FIXME: this is pretty much a copy of supplement_binding_1 in
320 ../gcc/cp/name-lookup.c; the few replaced/removed bits are marked
322 tree bval
= binding
->value
;
324 tree target_bval
= strip_using_decl (bval
);
325 tree target_decl
= strip_using_decl (decl
);
327 if (TREE_CODE (target_decl
) == TYPE_DECL
&& DECL_ARTIFICIAL (target_decl
)
328 && target_decl
!= target_bval
329 && (TREE_CODE (target_bval
) != TYPE_DECL
330 /* We allow pushing an enum multiple times in a class
331 template in order to handle late matching of underlying
332 type on an opaque-enum-declaration followed by an
334 || (processing_template_decl
335 && TREE_CODE (TREE_TYPE (target_decl
)) == ENUMERAL_TYPE
336 && TREE_CODE (TREE_TYPE (target_bval
)) == ENUMERAL_TYPE
337 && (dependent_type_p (ENUM_UNDERLYING_TYPE
338 (TREE_TYPE (target_decl
)))
339 || dependent_type_p (ENUM_UNDERLYING_TYPE
340 (TREE_TYPE (target_bval
)))))))
341 /* The new name is the type name. */
342 binding
->type
= decl
;
343 else if (/* TARGET_BVAL is null when push_class_level_binding moves
344 an inherited type-binding out of the way to make room
345 for a new value binding. */
347 /* TARGET_BVAL is error_mark_node when TARGET_DECL's name
348 has been used in a non-class scope prior declaration.
349 In that case, we should have already issued a
350 diagnostic; for graceful error recovery purpose, pretend
351 this was the intended declaration for that name. */
352 || target_bval
== error_mark_node
353 /* If TARGET_BVAL is anticipated but has not yet been
354 declared, pretend it is not there at all. */
355 || (TREE_CODE (target_bval
) == FUNCTION_DECL
356 && DECL_ANTICIPATED (target_bval
)
357 && !DECL_HIDDEN_FRIEND_P (target_bval
)))
358 binding
->value
= decl
;
359 else if (TREE_CODE (target_bval
) == TYPE_DECL
360 && DECL_ARTIFICIAL (target_bval
)
361 && target_decl
!= target_bval
362 && (TREE_CODE (target_decl
) != TYPE_DECL
363 || same_type_p (TREE_TYPE (target_decl
),
364 TREE_TYPE (target_bval
))))
366 /* The old binding was a type name. It was placed in
367 VALUE field because it was thought, at the point it was
368 declared, to be the only entity with such a name. Move the
369 type name into the type slot; it is now hidden by the new
371 binding
->type
= bval
;
372 binding
->value
= decl
;
373 binding
->value_is_inherited
= false;
375 else if (TREE_CODE (target_bval
) == TYPE_DECL
376 && TREE_CODE (target_decl
) == TYPE_DECL
377 && DECL_NAME (target_decl
) == DECL_NAME (target_bval
)
378 && binding
->scope
->kind
!= sk_class
379 && (same_type_p (TREE_TYPE (target_decl
), TREE_TYPE (target_bval
))
380 /* If either type involves template parameters, we must
381 wait until instantiation. */
382 || uses_template_parms (TREE_TYPE (target_decl
))
383 || uses_template_parms (TREE_TYPE (target_bval
))))
384 /* We have two typedef-names, both naming the same type to have
385 the same name. In general, this is OK because of:
389 In a given scope, a typedef specifier can be used to redefine
390 the name of any type declared in that scope to refer to the
391 type to which it already refers.
393 However, in class scopes, this rule does not apply due to the
394 stricter language in [class.mem] prohibiting redeclarations of
397 /* There can be two block-scope declarations of the same variable,
398 so long as they are `extern' declarations. However, there cannot
399 be two declarations of the same static data member:
403 A member shall not be declared twice in the
404 member-specification. */
405 else if (VAR_P (target_decl
)
406 && VAR_P (target_bval
)
407 && DECL_EXTERNAL (target_decl
) && DECL_EXTERNAL (target_bval
)
408 && !DECL_CLASS_SCOPE_P (target_decl
))
410 duplicate_decls (decl
, binding
->value
, /*newdecl_is_friend=*/false);
413 else if (TREE_CODE (decl
) == NAMESPACE_DECL
414 && TREE_CODE (bval
) == NAMESPACE_DECL
415 && DECL_NAMESPACE_ALIAS (decl
)
416 && DECL_NAMESPACE_ALIAS (bval
)
417 && ORIGINAL_NAMESPACE (bval
) == ORIGINAL_NAMESPACE (decl
))
420 In a declarative region, a namespace-alias-definition can be
421 used to redefine a namespace-alias declared in that declarative
422 region to refer only to the namespace to which it already
427 // _1: diagnose_name_conflict (decl, bval);
431 gcc_assert (ok
); // _1: return ok;
435 reactivate_decl (tree decl
, cp_binding_level
*b
)
437 bool in_function_p
= TREE_CODE (b
->this_entity
) == FUNCTION_DECL
;
438 gcc_assert (in_function_p
439 || (b
== current_binding_level
440 && !at_class_scope_p ()));
442 tree id
= DECL_NAME (decl
);
443 tree type
= NULL_TREE
;
444 if (TREE_CODE (decl
) == TYPE_DECL
)
445 type
= TREE_TYPE (decl
);
447 if (type
&& TYPE_NAME (type
) == decl
448 && (RECORD_OR_UNION_CODE_P (TREE_CODE (type
))
449 || TREE_CODE (type
) == ENUMERAL_TYPE
))
451 gcc_assert (in_function_p
&& DECL_CONTEXT (decl
) == b
->this_entity
);
452 type
= TREE_TYPE (decl
);
456 gcc_assert (DECL_CONTEXT (decl
) == b
->this_entity
457 || DECL_CONTEXT (decl
) == global_namespace
458 || TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
);
462 /* Adjust IDENTIFIER_BINDING to what it would have been if we were
463 at binding level B. Save the binding chain up to that point in
464 [binding, *chainp), and take note of the outermost bindings found
466 cxx_binding
*binding
= IDENTIFIER_BINDING (id
), **chainp
= NULL
;
467 tree
*shadowing_type_p
= NULL
;
470 cp_binding_level
*bc
= current_binding_level
;
471 for (cxx_binding
*prev_binding
= binding
;
472 prev_binding
; prev_binding
= prev_binding
->previous
)
474 while (bc
!= b
&& bc
!= prev_binding
->scope
)
475 bc
= bc
->level_chain
;
482 chainp
= &prev_binding
->previous
;
484 for (tree tshadow
= prev_binding
->scope
->type_shadowed
;
485 tshadow
; tshadow
= TREE_CHAIN (tshadow
))
486 if (TREE_PURPOSE (tshadow
) == id
)
488 shadowing_type_p
= &TREE_VALUE (tshadow
);
495 IDENTIFIER_BINDING (id
) = *chainp
;
499 /* Like push_local_binding, supplement or add a binding to the
501 if (IDENTIFIER_BINDING (id
) && IDENTIFIER_BINDING (id
)->scope
== b
)
502 supplement_binding (IDENTIFIER_BINDING (id
), decl
);
504 push_binding (id
, decl
, b
);
506 /* Now restore the binding chain we'd temporarily removed. */
509 *chainp
= IDENTIFIER_BINDING (id
);
510 IDENTIFIER_BINDING (id
) = binding
;
514 /* Insert the new type binding in the shadowing_type_p
516 tree shadowed_type
= NULL_TREE
;
517 if (shadowing_type_p
)
519 shadowed_type
= *shadowing_type_p
;
520 *shadowing_type_p
= type
;
523 b
->type_shadowed
= tree_cons (id
, shadowed_type
, b
->type_shadowed
);
524 TREE_TYPE (b
->type_shadowed
) = type
;
529 /* Our new binding is the active one, so shadow the earlier
531 b
->type_shadowed
= tree_cons (id
, REAL_IDENTIFIER_TYPE_VALUE (id
),
533 TREE_TYPE (b
->type_shadowed
) = type
;
534 SET_IDENTIFIER_TYPE_VALUE (id
, type
);
537 /* Record that we have a binding for ID, like add_decl_to_level. */
538 tree node
= build_tree_list (NULL_TREE
, decl
);
539 TREE_CHAIN (node
) = b
->names
;
544 plugin_pragma_push_user_expression (cpp_reader
*)
549 gcc_assert (!current_class_ptr
);
550 gcc_assert (!current_class_ref
);
552 gcc_assert (!cp_binding_oracle
);
553 cp_binding_oracle
= plugin_binding_oracle
;
555 /* Make the function containing the user expression a global
556 friend, so as to bypass access controls in it. */
557 if (at_function_scope_p ())
558 set_global_friend (current_function_decl
);
560 gcc_assert (at_function_scope_p ());
561 function
*save_cfun
= cfun
;
562 cp_binding_level
*orig_binding_level
= current_binding_level
;
565 cc1_plugin::call (current_context
, "enter_scope", &success
);
567 gcc_assert (at_fake_function_scope_p () || at_function_scope_p ());
569 function
*unchanged_cfun
= cfun
;
570 tree changed_func_decl
= current_function_decl
;
572 gcc_assert (current_class_type
== DECL_CONTEXT (current_function_decl
)
573 || !(RECORD_OR_UNION_CODE_P
574 (TREE_CODE (DECL_CONTEXT (current_function_decl
)))));
575 push_fake_function (save_cfun
->decl
, sk_block
);
576 current_class_type
= NULL_TREE
;
579 /* If we get here, GDB did NOT change the context. */
580 gcc_assert (cfun
== save_cfun
);
581 gcc_assert (at_function_scope_p ());
582 gcc_assert (orig_binding_level
583 == current_binding_level
->level_chain
->level_chain
);
588 gcc_assert (at_function_scope_p ());
590 cp_binding_level
*b
= current_binding_level
->level_chain
;
591 gcc_assert (b
->this_entity
== cfun
->decl
);
593 /* Reactivate local names from the previous context. Use
594 IDENTIFIER_MARKED to avoid reactivating shadowed names. */
595 for (cp_binding_level
*level
= orig_binding_level
;;)
597 for (tree name
= level
->names
;
598 name
; name
= TREE_CHAIN (name
))
601 if (TREE_CODE (decl
) == TREE_LIST
)
602 decl
= TREE_VALUE (decl
);
603 if (IDENTIFIER_MARKED (DECL_NAME (decl
)))
605 IDENTIFIER_MARKED (DECL_NAME (decl
)) = 1;
606 reactivate_decl (decl
, b
);
608 if (level
->kind
== sk_function_parms
609 && level
->this_entity
== cfun
->decl
)
611 gcc_assert (!level
->this_entity
);
612 level
= level
->level_chain
;
615 /* Now, clear the markers. */
616 for (tree name
= b
->names
; name
; name
= TREE_CHAIN (name
))
619 if (TREE_CODE (decl
) == TREE_LIST
)
620 decl
= TREE_VALUE (decl
);
621 gcc_assert (IDENTIFIER_MARKED (DECL_NAME (decl
)));
622 IDENTIFIER_MARKED (DECL_NAME (decl
)) = 0;
626 if (unchanged_cfun
|| DECL_NONSTATIC_MEMBER_FUNCTION_P (changed_func_decl
))
628 /* Check whether the oracle supplies us with a "this", and if
629 so, arrange for data members and this itself to be
631 tree this_val
= lookup_name (get_identifier ("this"));
632 current_class_ref
= !this_val
? NULL_TREE
633 : cp_build_indirect_ref (this_val
, RO_NULL
, tf_warning_or_error
);
634 current_class_ptr
= this_val
;
639 plugin_pragma_pop_user_expression (cpp_reader
*)
644 gcc_assert (cp_binding_oracle
);
646 gcc_assert (at_function_scope_p ());
647 function
*save_cfun
= cfun
;
648 current_class_ptr
= NULL_TREE
;
649 current_class_ref
= NULL_TREE
;
653 if (RECORD_OR_UNION_CODE_P (TREE_CODE (DECL_CONTEXT (current_function_decl
))))
654 current_class_type
= DECL_CONTEXT (current_function_decl
);
657 cc1_plugin::call (current_context
, "leave_scope", &success
);
662 gcc_assert (cfun
== save_cfun
);
664 cp_binding_oracle
= NULL
;
665 gcc_assert (at_function_scope_p ());
669 plugin_init_extra_pragmas (void *, void *)
671 c_register_pragma ("GCC", "push_user_expression", plugin_pragma_push_user_expression
);
672 c_register_pragma ("GCC", "pop_user_expression", plugin_pragma_pop_user_expression
);
673 /* FIXME: this one should go once we get GDB to use push and pop. */
674 c_register_pragma ("GCC", "user_expression", plugin_pragma_push_user_expression
);
679 static decl_addr_value
680 build_decl_addr_value (tree decl
, gcc_address address
)
682 decl_addr_value value
= {
684 build_int_cst_type (ptr_type_node
, address
)
689 static decl_addr_value
*
690 record_decl_address (plugin_context
*ctx
, decl_addr_value value
)
692 decl_addr_value
**slot
= ctx
->address_map
.find_slot (&value
, INSERT
);
693 gcc_assert (*slot
== NULL
);
695 = static_cast<decl_addr_value
*> (xmalloc (sizeof (decl_addr_value
)));
697 /* We don't want GCC to warn about e.g. static functions
698 without a code definition. */
699 TREE_NO_WARNING (value
.decl
) = 1;
703 // Maybe rewrite a decl to its address.
705 address_rewriter (tree
*in
, int *walk_subtrees
, void *arg
)
707 plugin_context
*ctx
= (plugin_context
*) arg
;
710 || TREE_CODE (*in
) == NAMESPACE_DECL
711 || DECL_NAME (*in
) == NULL_TREE
)
714 decl_addr_value value
;
716 decl_addr_value
*found_value
= ctx
->address_map
.find (&value
);
717 if (found_value
!= NULL
)
719 else if (HAS_DECL_ASSEMBLER_NAME_P (*in
))
723 if (!cc1_plugin::call (ctx
, "address_oracle", &address
,
724 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (*in
))))
729 // Insert the decl into the address map in case it is referenced
731 value
= build_decl_addr_value (value
.decl
, address
);
732 found_value
= record_decl_address (ctx
, value
);
737 if (found_value
->address
!= error_mark_node
)
739 // We have an address for the decl, so rewrite the tree.
740 tree ptr_type
= build_pointer_type (TREE_TYPE (*in
));
741 *in
= fold_build1 (INDIRECT_REF
, TREE_TYPE (*in
),
742 fold_build1 (CONVERT_EXPR
, ptr_type
,
743 found_value
->address
));
751 // When generating code for gdb, we want to be able to use absolute
752 // addresses to refer to otherwise external objects that gdb knows
753 // about. gdb passes in these addresses when building decls, and then
754 // before gimplification we go through the trees, rewriting uses to
755 // the equivalent of "*(TYPE *) ADDR".
757 rewrite_decls_to_addresses (void *function_in
, void *)
759 tree function
= (tree
) function_in
;
761 // Do nothing if we're not in gdb.
762 if (current_context
== NULL
)
765 walk_tree (&DECL_SAVED_TREE (function
), address_rewriter
, current_context
,
772 safe_push_template_decl (tree decl
)
774 void (*save_oracle
) (enum cp_oracle_request
, tree identifier
);
776 save_oracle
= cp_binding_oracle
;
777 cp_binding_oracle
= NULL
;
779 tree ret
= push_template_decl (decl
);
781 cp_binding_oracle
= save_oracle
;
787 safe_pushtag (tree name
, tree type
, tag_scope scope
)
789 void (*save_oracle
) (enum cp_oracle_request
, tree identifier
);
791 save_oracle
= cp_binding_oracle
;
792 cp_binding_oracle
= NULL
;
794 tree ret
= pushtag (name
, type
, scope
);
796 cp_binding_oracle
= save_oracle
;
802 safe_pushdecl_maybe_friend (tree decl
, bool is_friend
)
804 void (*save_oracle
) (enum cp_oracle_request
, tree identifier
);
806 save_oracle
= cp_binding_oracle
;
807 cp_binding_oracle
= NULL
;
809 tree ret
= pushdecl (decl
, is_friend
);
811 cp_binding_oracle
= save_oracle
;
819 plugin_push_namespace (cc1_plugin::connection
*,
823 push_to_top_level ();
825 push_namespace (name
? get_identifier (name
) : NULL
);
831 plugin_push_class (cc1_plugin::connection
*,
834 tree type
= convert_in (type_in
);
835 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (type
)));
836 gcc_assert (TYPE_CONTEXT (type
) == FROB_CONTEXT (current_scope ()));
844 plugin_push_function (cc1_plugin::connection
*,
845 gcc_decl function_decl_in
)
847 tree fndecl
= convert_in (function_decl_in
);
848 gcc_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
);
849 gcc_assert (DECL_CONTEXT (fndecl
) == FROB_CONTEXT (current_scope ()));
851 push_fake_function (fndecl
);
857 plugin_pop_binding_level (cc1_plugin::connection
*)
864 plugin_reactivate_decl (cc1_plugin::connection
*,
868 tree decl
= convert_in (decl_in
);
869 tree scope
= convert_in (scope_in
);
870 gcc_assert (TREE_CODE (decl
) == VAR_DECL
871 || TREE_CODE (decl
) == FUNCTION_DECL
872 || TREE_CODE (decl
) == TYPE_DECL
);
876 gcc_assert (TREE_CODE (scope
) == FUNCTION_DECL
);
877 for (b
= current_binding_level
;
878 b
->this_entity
!= scope
;
880 gcc_assert (b
->this_entity
!= global_namespace
);
884 gcc_assert (!at_class_scope_p ());
885 b
= current_binding_level
;
888 reactivate_decl (decl
, b
);
897 if (at_namespace_scope_p ())
898 decl
= current_namespace
;
899 else if (at_class_scope_p ())
900 decl
= TYPE_NAME (current_class_type
);
901 else if (at_fake_function_scope_p () || at_function_scope_p ())
902 decl
= current_function_decl
;
910 plugin_get_current_binding_level_decl (cc1_plugin::connection
*)
912 tree decl
= get_current_scope ();
914 return convert_out (decl
);
918 plugin_make_namespace_inline (cc1_plugin::connection
*)
920 tree inline_ns
= current_namespace
;
922 gcc_assert (toplevel_bindings_p ());
923 gcc_assert (inline_ns
!= global_namespace
);
925 tree parent_ns
= CP_DECL_CONTEXT (inline_ns
);
927 if (DECL_NAMESPACE_INLINE_P (inline_ns
))
930 DECL_NAMESPACE_INLINE_P (inline_ns
) = true;
931 vec_safe_push (DECL_NAMESPACE_INLINEES (parent_ns
), inline_ns
);
937 plugin_add_using_namespace (cc1_plugin::connection
*,
940 tree used_ns
= convert_in (used_ns_in
);
942 gcc_assert (TREE_CODE (used_ns
) == NAMESPACE_DECL
);
944 finish_using_directive (used_ns
, NULL_TREE
);
950 plugin_add_namespace_alias (cc1_plugin::connection
*,
954 tree name
= get_identifier (id
);
955 tree target
= convert_in (target_in
);
957 do_namespace_alias (name
, target
);
963 set_access_flags (tree decl
, enum gcc_cp_symbol_kind flags
)
965 gcc_assert (!(flags
& GCC_CP_ACCESS_MASK
) == !DECL_CLASS_SCOPE_P (decl
));
967 switch (flags
& GCC_CP_ACCESS_MASK
)
969 case GCC_CP_ACCESS_PRIVATE
:
970 TREE_PRIVATE (decl
) = true;
971 current_access_specifier
= access_private_node
;
974 case GCC_CP_ACCESS_PROTECTED
:
975 TREE_PROTECTED (decl
) = true;
976 current_access_specifier
= access_protected_node
;
979 case GCC_CP_ACCESS_PUBLIC
:
980 current_access_specifier
= access_public_node
;
989 plugin_add_using_decl (cc1_plugin::connection
*,
990 enum gcc_cp_symbol_kind flags
,
993 tree target
= convert_in (target_in
);
994 gcc_assert ((flags
& GCC_CP_SYMBOL_MASK
) == GCC_CP_SYMBOL_USING
);
995 gcc_assert (!(flags
& GCC_CP_FLAG_MASK
));
996 enum gcc_cp_symbol_kind acc_flags
;
997 acc_flags
= (enum gcc_cp_symbol_kind
) (flags
& GCC_CP_ACCESS_MASK
);
999 gcc_assert (!template_parm_scope_p ());
1001 bool class_member_p
= at_class_scope_p ();
1002 gcc_assert (!(acc_flags
& GCC_CP_ACCESS_MASK
) == !class_member_p
);
1004 tree identifier
= DECL_NAME (target
);
1005 tree tcontext
= DECL_CONTEXT (target
);
1007 if (UNSCOPED_ENUM_P (tcontext
))
1008 tcontext
= CP_TYPE_CONTEXT (tcontext
);
1012 tree decl
= do_class_using_decl (tcontext
, identifier
);
1014 set_access_flags (decl
, flags
);
1016 finish_member_declaration (decl
);
1020 /* We can't be at local scope. */
1021 gcc_assert (at_namespace_scope_p ());
1022 finish_nonmember_using_decl (tcontext
, identifier
);
1029 build_named_class_type (enum tree_code code
,
1033 /* See at_fake_function_scope_p. */
1034 gcc_assert (!at_function_scope_p ());
1035 tree type
= make_class_type (code
);
1036 tree type_decl
= build_decl (loc
, TYPE_DECL
, id
, type
);
1037 TYPE_NAME (type
) = type_decl
;
1038 TYPE_STUB_DECL (type
) = type_decl
;
1039 DECL_CONTEXT (type_decl
) = TYPE_CONTEXT (type
);
1044 /* Abuse an unused field of the dummy template parms entry to hold the
1046 #define TP_PARM_LIST TREE_TYPE (current_template_parms)
1049 plugin_build_decl (cc1_plugin::connection
*self
,
1051 enum gcc_cp_symbol_kind sym_kind
,
1052 gcc_type sym_type_in
,
1053 const char *substitution_name
,
1054 gcc_address address
,
1055 const char *filename
,
1056 unsigned int line_number
)
1058 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1059 gcc_assert (!name
|| !strchr (name
, ':')); // FIXME: this can go eventually.
1061 enum tree_code code
;
1063 tree sym_type
= convert_in (sym_type_in
);
1064 enum gcc_cp_symbol_kind sym_flags
;
1065 sym_flags
= (enum gcc_cp_symbol_kind
) (sym_kind
& GCC_CP_FLAG_MASK
);
1066 enum gcc_cp_symbol_kind acc_flags
;
1067 acc_flags
= (enum gcc_cp_symbol_kind
) (sym_kind
& GCC_CP_ACCESS_MASK
);
1068 sym_kind
= (enum gcc_cp_symbol_kind
) (sym_kind
& GCC_CP_SYMBOL_MASK
);
1072 case GCC_CP_SYMBOL_FUNCTION
:
1073 code
= FUNCTION_DECL
;
1074 gcc_assert (!(sym_flags
& ~GCC_CP_FLAG_MASK_FUNCTION
));
1077 case GCC_CP_SYMBOL_VARIABLE
:
1079 gcc_assert (!(sym_flags
& ~GCC_CP_FLAG_MASK_VARIABLE
));
1082 case GCC_CP_SYMBOL_TYPEDEF
:
1084 gcc_assert (!sym_flags
);
1087 case GCC_CP_SYMBOL_CLASS
:
1089 gcc_assert (!(sym_flags
& ~GCC_CP_FLAG_MASK_CLASS
));
1090 gcc_assert (!sym_type
);
1093 case GCC_CP_SYMBOL_UNION
:
1095 gcc_assert (!sym_flags
);
1096 gcc_assert (!sym_type
);
1103 bool template_decl_p
= template_parm_scope_p ();
1105 if (template_decl_p
)
1107 gcc_assert (code
== FUNCTION_DECL
|| code
== RECORD_TYPE
1108 || code
== TYPE_DECL
);
1110 /* Finish the template parm list that started this template parm. */
1111 end_template_parm_list (TP_PARM_LIST
);
1113 gcc_assert (!address
);
1114 gcc_assert (!substitution_name
);
1117 location_t loc
= ctx
->get_location_t (filename
, line_number
);
1118 bool class_member_p
= at_class_scope_p ();
1119 bool ctor
= false, dtor
= false, assop
= false;
1120 tree_code opcode
= ERROR_MARK
;
1122 gcc_assert (!(acc_flags
& GCC_CP_ACCESS_MASK
) == !class_member_p
);
1125 if (code
!= FUNCTION_DECL
1126 || !(sym_flags
& GCC_CP_FLAG_SPECIAL_FUNCTION
))
1129 identifier
= get_identifier (name
);
1132 gcc_assert (RECORD_OR_UNION_CODE_P (code
));
1133 identifier
= make_anon_name ();
1137 if (code
== FUNCTION_DECL
)
1139 if (sym_flags
& GCC_CP_FLAG_SPECIAL_FUNCTION
)
1141 #define CHARS2(f,s) (((unsigned char)f << CHAR_BIT) | (unsigned char)s)
1142 switch (CHARS2 (name
[0], name
[1]))
1144 case CHARS2 ('C', 0x0): // ctor base declaration
1145 case CHARS2 ('C', ' '):
1146 case CHARS2 ('C', '1'):
1147 case CHARS2 ('C', '2'):
1148 case CHARS2 ('C', '4'):
1151 gcc_assert (!address
);
1152 gcc_assert (!substitution_name
);
1153 identifier
= DECL_NAME (TYPE_NAME (current_class_type
));
1155 case CHARS2 ('D', 0x0): // dtor base declaration
1156 case CHARS2 ('D', ' '):
1157 case CHARS2 ('D', '0'):
1158 case CHARS2 ('D', '1'):
1159 case CHARS2 ('D', '2'):
1160 case CHARS2 ('D', '4'):
1161 gcc_assert (!template_decl_p
);
1164 case CHARS2 ('n', 'w'): // operator new
1167 case CHARS2 ('n', 'a'): // operator new[]
1168 opcode
= VEC_NEW_EXPR
;
1170 case CHARS2 ('d', 'l'): // operator delete
1171 opcode
= DELETE_EXPR
;
1173 case CHARS2 ('d', 'a'): // operator delete[]
1174 opcode
= VEC_DELETE_EXPR
;
1176 case CHARS2 ('p', 's'): // operator + (unary)
1179 case CHARS2 ('n', 'g'): // operator - (unary)
1180 opcode
= MINUS_EXPR
;
1182 case CHARS2 ('a', 'd'): // operator & (unary)
1183 opcode
= BIT_AND_EXPR
;
1185 case CHARS2 ('d', 'e'): // operator * (unary)
1188 case CHARS2 ('c', 'o'): // operator ~
1189 opcode
= BIT_NOT_EXPR
;
1191 case CHARS2 ('p', 'l'): // operator +
1194 case CHARS2 ('m', 'i'): // operator -
1195 opcode
= MINUS_EXPR
;
1197 case CHARS2 ('m', 'l'): // operator *
1200 case CHARS2 ('d', 'v'): // operator /
1201 opcode
= TRUNC_DIV_EXPR
;
1203 case CHARS2 ('r', 'm'): // operator %
1204 opcode
= TRUNC_MOD_EXPR
;
1206 case CHARS2 ('a', 'n'): // operator &
1207 opcode
= BIT_AND_EXPR
;
1209 case CHARS2 ('o', 'r'): // operator |
1210 opcode
= BIT_IOR_EXPR
;
1212 case CHARS2 ('e', 'o'): // operator ^
1213 opcode
= BIT_XOR_EXPR
;
1215 case CHARS2 ('a', 'S'): // operator =
1219 case CHARS2 ('p', 'L'): // operator +=
1223 case CHARS2 ('m', 'I'): // operator -=
1224 opcode
= MINUS_EXPR
;
1227 case CHARS2 ('m', 'L'): // operator *=
1231 case CHARS2 ('d', 'V'): // operator /=
1232 opcode
= TRUNC_DIV_EXPR
;
1235 case CHARS2 ('r', 'M'): // operator %=
1236 opcode
= TRUNC_MOD_EXPR
;
1239 case CHARS2 ('a', 'N'): // operator &=
1240 opcode
= BIT_AND_EXPR
;
1243 case CHARS2 ('o', 'R'): // operator |=
1244 opcode
= BIT_IOR_EXPR
;
1247 case CHARS2 ('e', 'O'): // operator ^=
1248 opcode
= BIT_XOR_EXPR
;
1251 case CHARS2 ('l', 's'): // operator <<
1252 opcode
= LSHIFT_EXPR
;
1254 case CHARS2 ('r', 's'): // operator >>
1255 opcode
= RSHIFT_EXPR
;
1257 case CHARS2 ('l', 'S'): // operator <<=
1258 opcode
= LSHIFT_EXPR
;
1261 case CHARS2 ('r', 'S'): // operator >>=
1262 opcode
= RSHIFT_EXPR
;
1265 case CHARS2 ('e', 'q'): // operator ==
1268 case CHARS2 ('n', 'e'): // operator !=
1271 case CHARS2 ('l', 't'): // operator <
1274 case CHARS2 ('g', 't'): // operator >
1277 case CHARS2 ('l', 'e'): // operator <=
1280 case CHARS2 ('g', 'e'): // operator >=
1283 case CHARS2 ('n', 't'): // operator !
1284 opcode
= TRUTH_NOT_EXPR
;
1286 case CHARS2 ('a', 'a'): // operator &&
1287 opcode
= TRUTH_ANDIF_EXPR
;
1289 case CHARS2 ('o', 'o'): // operator ||
1290 opcode
= TRUTH_ORIF_EXPR
;
1292 case CHARS2 ('p', 'p'): // operator ++
1293 opcode
= POSTINCREMENT_EXPR
;
1295 case CHARS2 ('m', 'm'): // operator --
1296 /* This stands for either one as an operator name, and
1297 "pp" and "mm" stand for POST??CREMENT, but for some
1298 reason the parser uses this opcode name for
1299 operator--; let's follow their practice. */
1300 opcode
= PREDECREMENT_EXPR
;
1302 case CHARS2 ('c', 'm'): // operator ,
1303 opcode
= COMPOUND_EXPR
;
1305 case CHARS2 ('p', 'm'): // operator ->*
1306 opcode
= MEMBER_REF
;
1308 case CHARS2 ('p', 't'): // operator ->
1309 opcode
= COMPONENT_REF
;
1311 case CHARS2 ('c', 'l'): // operator ()
1314 case CHARS2 ('i', 'x'): // operator []
1317 case CHARS2 ('c', 'v'): // operator <T> (conversion operator)
1318 identifier
= make_conv_op_name (TREE_TYPE (sym_type
));
1321 case CHARS2 ('l', 'i'): // operator "" <id>
1323 char *id
= (char *)name
+ 2;
1324 bool freeid
= false;
1325 if (*id
>= '0' && *id
<= '9')
1334 while (*id
&& *id
>= '0' && *id
<= '9');
1335 id
= xstrndup (id
, len
);
1338 identifier
= cp_literal_operator_id (id
);
1343 case CHARS2 ('q', 'u'): // ternary operator, not overloadable.
1348 if (opcode
!= ERROR_MARK
)
1349 identifier
= ovl_op_identifier (assop
, opcode
);
1351 decl
= build_lang_decl_loc (loc
, code
, identifier
, sym_type
);
1352 /* FIXME: current_lang_name is lang_name_c while compiling an
1353 extern "C" function, and we haven't switched to a global
1354 context at this point, and this breaks function
1356 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
1357 if (TREE_CODE (sym_type
) == METHOD_TYPE
)
1358 DECL_ARGUMENTS (decl
) = build_this_parm (decl
, current_class_type
,
1359 cp_type_quals (sym_type
));
1360 for (tree arg
= TREE_CODE (sym_type
) == METHOD_TYPE
1361 ? TREE_CHAIN (TYPE_ARG_TYPES (sym_type
))
1362 : TYPE_ARG_TYPES (sym_type
);
1363 arg
&& arg
!= void_list_node
;
1364 arg
= TREE_CHAIN (arg
))
1366 tree parm
= cp_build_parm_decl (decl
, NULL_TREE
, TREE_VALUE (arg
));
1367 DECL_CHAIN (parm
) = DECL_ARGUMENTS (decl
);
1368 DECL_ARGUMENTS (decl
) = parm
;
1370 DECL_ARGUMENTS (decl
) = nreverse (DECL_ARGUMENTS (decl
));
1373 if (TREE_CODE (sym_type
) == FUNCTION_TYPE
)
1374 DECL_STATIC_FUNCTION_P (decl
) = 1;
1375 if (sym_flags
& GCC_CP_FLAG_VIRTUAL_FUNCTION
)
1377 DECL_VIRTUAL_P (decl
) = 1;
1378 if (sym_flags
& GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION
)
1379 DECL_PURE_VIRTUAL_P (decl
) = 1;
1380 if (sym_flags
& GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION
)
1381 DECL_FINAL_P (decl
) = 1;
1384 gcc_assert (!(sym_flags
& (GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION
1385 | GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION
)));
1389 gcc_assert (!(sym_flags
& (GCC_CP_FLAG_VIRTUAL_FUNCTION
1390 | GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION
1391 | GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION
)));
1392 gcc_assert (!ctor
&& !dtor
&& !assop
);
1394 if (sym_flags
& GCC_CP_FLAG_EXPLICIT_FUNCTION
)
1395 DECL_NONCONVERTING_P (decl
) = 1;
1396 if (sym_flags
& GCC_CP_FLAG_DEFAULTED_FUNCTION
)
1398 DECL_INITIAL (decl
) = ridpointers
[(int)RID_DEFAULT
];
1399 DECL_DEFAULTED_FN (decl
) = 1;
1401 if (sym_flags
& GCC_CP_FLAG_DELETED_FUNCTION
)
1403 // DECL_INITIAL (decl) = ridpointers[(int)RID_DELETE];
1404 DECL_DELETED_FN (decl
) = 1;
1405 DECL_DECLARED_INLINE_P (decl
) = 1;
1406 DECL_INITIAL (decl
) = error_mark_node
;
1410 DECL_CXX_CONSTRUCTOR_P (decl
) = 1;
1412 DECL_CXX_DESTRUCTOR_P (decl
) = 1;
1413 else if ((sym_flags
& GCC_CP_FLAG_SPECIAL_FUNCTION
)
1414 && opcode
!= ERROR_MARK
)
1415 DECL_OVERLOADED_OPERATOR_CODE_RAW (decl
) = ovl_op_mapping
[opcode
];
1417 else if (RECORD_OR_UNION_CODE_P (code
))
1419 decl
= build_named_class_type (code
, identifier
, loc
);
1420 tree type
= TREE_TYPE (decl
);
1422 if (code
== RECORD_TYPE
1423 && !(sym_flags
& GCC_CP_FLAG_CLASS_IS_STRUCT
))
1424 CLASSTYPE_DECLARED_CLASS (type
) = true;
1426 else if (class_member_p
)
1428 decl
= build_lang_decl_loc (loc
, code
, identifier
, sym_type
);
1430 if (TREE_CODE (decl
) == VAR_DECL
)
1432 DECL_THIS_STATIC (decl
) = 1;
1433 // The remainder of this block does the same as:
1434 // set_linkage_for_static_data_member (decl);
1435 TREE_PUBLIC (decl
) = 1;
1436 TREE_STATIC (decl
) = 1;
1437 DECL_INTERFACE_KNOWN (decl
) = 1;
1439 // FIXME: sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
1440 gcc_assert (!(sym_flags
& GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
));
1442 if (sym_flags
& GCC_CP_FLAG_CONSTEXPR_VARIABLE
)
1443 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
1448 decl
= build_decl (loc
, code
, identifier
, sym_type
);
1450 if (TREE_CODE (decl
) == VAR_DECL
)
1452 // FIXME: sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
1453 gcc_assert (!(sym_flags
& GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
));
1455 if (sym_flags
& GCC_CP_FLAG_CONSTEXPR_VARIABLE
)
1456 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
1459 TREE_USED (decl
) = 1;
1460 TREE_ADDRESSABLE (decl
) = 1;
1463 DECL_CONTEXT (decl
) = FROB_CONTEXT (current_class_type
);
1464 else if (at_namespace_scope_p ())
1465 DECL_CONTEXT (decl
) = FROB_CONTEXT (current_decl_namespace ());
1467 set_access_flags (decl
, acc_flags
);
1469 /* If this is the typedef that names an otherwise anonymous type,
1470 propagate the typedef name to the type. In normal compilation,
1471 this is done in grokdeclarator. */
1472 if (sym_kind
== GCC_CP_SYMBOL_TYPEDEF
1474 && DECL_CONTEXT (decl
) == TYPE_CONTEXT (sym_type
)
1475 && TYPE_UNNAMED_P (sym_type
))
1476 name_unnamed_type (sym_type
, decl
);
1478 if (sym_kind
!= GCC_CP_SYMBOL_TYPEDEF
1479 && sym_kind
!= GCC_CP_SYMBOL_CLASS
1480 && sym_kind
!= GCC_CP_SYMBOL_UNION
1481 && !template_decl_p
&& !ctor
&& !dtor
)
1483 decl_addr_value value
;
1485 DECL_EXTERNAL (decl
) = 1;
1487 if (substitution_name
!= NULL
)
1489 // If the translator gave us a name without a binding,
1490 // we can just substitute error_mark_node, since we know the
1491 // translator will be reporting an error anyhow.
1493 = lookup_name (get_identifier (substitution_name
));
1494 if (value
.address
== NULL_TREE
)
1495 value
.address
= error_mark_node
;
1498 value
.address
= build_int_cst_type (ptr_type_node
, address
);
1500 value
.address
= NULL
;
1502 record_decl_address (ctx
, value
);
1505 if (class_member_p
&& code
== FUNCTION_DECL
)
1508 maybe_retrofit_in_chrg (decl
);
1510 grok_special_member_properties (decl
);
1513 if (template_decl_p
)
1515 if (RECORD_OR_UNION_CODE_P (code
))
1516 safe_pushtag (identifier
, TREE_TYPE (decl
), ts_current
);
1518 decl
= safe_push_template_decl (decl
);
1520 tree tdecl
= NULL_TREE
;
1522 tdecl
= finish_member_template_decl (decl
);
1524 end_template_decl ();
1526 /* We only support one level of templates, because we only
1527 support declaring generics; actual definitions are only of
1529 gcc_assert (!template_parm_scope_p ());
1532 finish_member_declaration (tdecl
);
1534 else if (RECORD_OR_UNION_CODE_P (code
))
1535 safe_pushtag (identifier
, TREE_TYPE (decl
), ts_current
);
1536 else if (class_member_p
)
1537 finish_member_declaration (decl
);
1539 decl
= safe_pushdecl_maybe_friend (decl
, false);
1542 /* Don't crash after a duplicate declaration of a cdtor. */
1543 && TYPE_FIELDS (current_class_type
) == decl
)
1545 /* ctors and dtors clones are chained after DECL.
1546 However, we create the clones before TYPE_METHODS is
1547 reversed. We test for cloned methods after reversal,
1548 however, and the test requires the clones to follow
1549 DECL. So, we reverse the chain of clones now, so
1550 that it will come out in the right order after
1552 tree save
= DECL_CHAIN (decl
);
1553 DECL_CHAIN (decl
) = NULL_TREE
;
1554 clone_function_decl (decl
, /*update_methods=*/true);
1555 gcc_assert (TYPE_FIELDS (current_class_type
) == decl
);
1556 TYPE_FIELDS (current_class_type
)
1557 = nreverse (TYPE_FIELDS (current_class_type
));
1558 DECL_CHAIN (decl
) = save
;
1561 rest_of_decl_compilation (decl
, toplevel_bindings_p (), 0);
1563 return convert_out (ctx
->preserve (decl
));
1567 plugin_define_cdtor_clone (cc1_plugin::connection
*self
,
1570 gcc_address address
)
1572 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1573 tree decl
= convert_in (cdtor_in
);
1578 switch (CHARS2 (name
[0], name
[1]))
1580 case CHARS2 ('C', '1'): // in-charge constructor
1581 identifier
= complete_ctor_identifier
;
1584 case CHARS2 ('C', '2'): // not-in-charge constructor
1585 identifier
= base_ctor_identifier
;
1588 case CHARS2 ('C', '4'):
1589 identifier
= ctor_identifier
; // unified constructor
1592 case CHARS2 ('D', '0'): // deleting destructor
1593 identifier
= deleting_dtor_identifier
;
1596 case CHARS2 ('D', '1'): // in-charge destructor
1597 identifier
= complete_dtor_identifier
;
1600 case CHARS2 ('D', '2'): // not-in-charge destructor
1601 identifier
= base_dtor_identifier
;
1604 case CHARS2 ('D', '4'):
1605 identifier
= dtor_identifier
; // unified destructor
1613 gcc_assert (!ctor
!= !dtor
);
1615 ? (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl
)
1616 && DECL_NAME (decl
) == ctor_identifier
)
1617 : (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl
)
1618 && DECL_NAME (decl
) == dtor_identifier
));
1620 while (decl
&& DECL_NAME (decl
) != identifier
)
1622 decl
= DECL_CHAIN (decl
);
1623 if (decl
&& !DECL_CLONED_FUNCTION_P (decl
))
1628 record_decl_address (ctx
, build_decl_addr_value (decl
, address
));
1630 return convert_out (decl
);
1634 plugin_add_friend (cc1_plugin::connection
* /* self */,
1638 tree decl
= convert_in (decl_in
);
1639 tree type
= convert_in (type_in
);
1641 gcc_assert (type
|| at_class_scope_p ());
1644 type
= current_class_type
;
1646 gcc_assert (TREE_CODE (type
) == RECORD_TYPE
);
1649 make_friend_class (type
, TREE_TYPE (decl
), true);
1652 DECL_FRIEND_P (decl
) = true;
1653 add_friend (type
, decl
, true);
1660 plugin_build_pointer_type (cc1_plugin::connection
*,
1663 // No need to preserve a pointer type as the base type is preserved.
1664 return convert_out (build_pointer_type (convert_in (base_type
)));
1668 plugin_build_reference_type (cc1_plugin::connection
*,
1669 gcc_type base_type_in
,
1670 enum gcc_cp_ref_qualifiers rquals
)
1676 case GCC_CP_REF_QUAL_LVALUE
:
1679 case GCC_CP_REF_QUAL_RVALUE
:
1682 case GCC_CP_REF_QUAL_NONE
:
1687 tree rtype
= cp_build_reference_type (convert_in (base_type_in
), rval
);
1689 return convert_out (rtype
);
1693 start_class_def (tree type
,
1694 const gcc_vbase_array
*base_classes
)
1699 for (int i
= 0; i
< base_classes
->n_elements
; i
++)
1703 gcc_assert ((base_classes
->flags
[i
] & GCC_CP_SYMBOL_MASK
)
1704 == GCC_CP_SYMBOL_BASECLASS
);
1706 switch (base_classes
->flags
[i
] & GCC_CP_ACCESS_MASK
)
1708 case GCC_CP_ACCESS_PRIVATE
:
1709 access
= ridpointers
[(int)RID_PRIVATE
];
1712 case GCC_CP_ACCESS_PROTECTED
:
1713 access
= ridpointers
[(int)RID_PROTECTED
];
1716 case GCC_CP_ACCESS_PUBLIC
:
1717 access
= ridpointers
[(int)RID_PUBLIC
];
1724 tree base
= finish_base_specifier
1725 (convert_in (base_classes
->elements
[i
]), access
,
1726 (base_classes
->flags
[i
] & GCC_CP_FLAG_BASECLASS_VIRTUAL
) != 0);
1727 TREE_CHAIN (base
) = bases
;
1730 bases
= nreverse (bases
);
1732 xref_basetypes (type
, bases
);
1733 begin_class_definition (type
);
1738 plugin_start_class_type (cc1_plugin::connection
*self
,
1739 gcc_decl typedecl_in
,
1740 const gcc_vbase_array
*base_classes
,
1741 const char *filename
,
1742 unsigned int line_number
)
1744 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1745 location_t loc
= ctx
->get_location_t (filename
, line_number
);
1746 tree typedecl
= convert_in (typedecl_in
);
1747 tree type
= TREE_TYPE (typedecl
);
1749 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (type
)));
1750 gcc_assert (!COMPLETE_TYPE_P (type
));
1752 DECL_SOURCE_LOCATION (typedecl
) = loc
;
1754 tree result
= start_class_def (type
, base_classes
);
1756 return convert_out (ctx
->preserve (result
));
1760 plugin_start_closure_class_type (cc1_plugin::connection
*self
,
1762 gcc_decl extra_scope_in
,
1763 enum gcc_cp_symbol_kind flags
,
1764 const char *filename
,
1765 unsigned int line_number
)
1767 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1768 tree extra_scope
= convert_in (extra_scope_in
);
1770 gcc_assert ((flags
& GCC_CP_SYMBOL_MASK
) == GCC_CP_SYMBOL_LAMBDA_CLOSURE
);
1771 gcc_assert ((flags
& (~(GCC_CP_SYMBOL_MASK
| GCC_CP_ACCESS_MASK
))) == 0);
1773 gcc_assert (!(flags
& GCC_CP_ACCESS_MASK
) == !at_class_scope_p ());
1775 /* See at_fake_function_scope_p. */
1776 gcc_assert (!at_function_scope_p ());
1780 if (TREE_CODE (extra_scope
) == PARM_DECL
)
1782 gcc_assert (at_fake_function_scope_p ());
1783 /* Check that the given extra_scope is one of the parameters of
1784 the current function. */
1785 for (tree parm
= DECL_ARGUMENTS (current_function_decl
);
1786 ; parm
= DECL_CHAIN (parm
))
1789 if (parm
== extra_scope
)
1793 else if (TREE_CODE (extra_scope
) == FIELD_DECL
)
1795 gcc_assert (at_class_scope_p ());
1796 gcc_assert (DECL_CONTEXT (extra_scope
) == current_class_type
);
1799 /* FIXME: does this ever really occur? */
1800 gcc_assert (TREE_CODE (extra_scope
) == VAR_DECL
);
1803 tree lambda_expr
= build_lambda_expr ();
1805 LAMBDA_EXPR_LOCATION (lambda_expr
) = ctx
->get_location_t (filename
,
1808 tree type
= begin_lambda_type (lambda_expr
);
1810 /* Instead of calling record_lambda_scope, do this: */
1811 LAMBDA_EXPR_EXTRA_SCOPE (lambda_expr
) = extra_scope
;
1812 LAMBDA_EXPR_DISCRIMINATOR (lambda_expr
) = discriminator
;
1814 tree decl
= TYPE_NAME (type
);
1815 determine_visibility (decl
);
1816 set_access_flags (decl
, flags
);
1818 return convert_out (ctx
->preserve (type
));
1822 plugin_build_lambda_expr (cc1_plugin::connection
*self
,
1823 gcc_type closure_type_in
)
1825 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1826 tree closure_type
= convert_in (closure_type_in
);
1828 gcc_assert (LAMBDA_TYPE_P (closure_type
));
1830 tree lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure_type
);
1832 tree lambda_object
= build_lambda_object (lambda_expr
);
1834 return convert_out (ctx
->preserve (lambda_object
));
1838 plugin_build_field (cc1_plugin::connection
*,
1839 const char *field_name
,
1840 gcc_type field_type_in
,
1841 enum gcc_cp_symbol_kind flags
,
1842 unsigned long bitsize
,
1843 unsigned long bitpos
)
1845 tree record_or_union_type
= current_class_type
;
1846 tree field_type
= convert_in (field_type_in
);
1848 gcc_assert (at_class_scope_p ());
1849 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (record_or_union_type
)));
1850 gcc_assert ((flags
& GCC_CP_SYMBOL_MASK
) == GCC_CP_SYMBOL_FIELD
);
1851 gcc_assert ((flags
& (~(GCC_CP_SYMBOL_MASK
| GCC_CP_ACCESS_MASK
1852 | GCC_CP_FLAG_MASK_FIELD
))) == 0);
1853 gcc_assert ((flags
& GCC_CP_ACCESS_MASK
));
1855 /* Note that gdb does not preserve the location of field decls, so
1856 we can't provide a decent location here. */
1857 tree decl
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
,
1858 get_identifier (field_name
), field_type
);
1859 DECL_FIELD_CONTEXT (decl
) = record_or_union_type
;
1861 set_access_flags (decl
, flags
);
1863 if ((flags
& GCC_CP_FLAG_FIELD_MUTABLE
) != 0)
1864 DECL_MUTABLE_P (decl
) = 1;
1866 if (TREE_CODE (field_type
) == INTEGER_TYPE
1867 && TYPE_PRECISION (field_type
) != bitsize
)
1869 DECL_BIT_FIELD_TYPE (decl
) = field_type
;
1871 = c_build_bitfield_integer_type (bitsize
, TYPE_UNSIGNED (field_type
));
1874 SET_DECL_MODE (decl
, TYPE_MODE (TREE_TYPE (decl
)));
1876 // There's no way to recover this from DWARF.
1877 SET_DECL_OFFSET_ALIGN (decl
, TYPE_PRECISION (pointer_sized_int_node
));
1879 tree pos
= bitsize_int (bitpos
);
1880 pos_from_bit (&DECL_FIELD_OFFSET (decl
), &DECL_FIELD_BIT_OFFSET (decl
),
1881 DECL_OFFSET_ALIGN (decl
), pos
);
1883 DECL_SIZE (decl
) = bitsize_int (bitsize
);
1884 DECL_SIZE_UNIT (decl
) = size_int ((bitsize
+ BITS_PER_UNIT
- 1)
1887 DECL_CHAIN (decl
) = TYPE_FIELDS (record_or_union_type
);
1888 TYPE_FIELDS (record_or_union_type
) = decl
;
1890 return convert_out (decl
);
1894 plugin_finish_class_type (cc1_plugin::connection
*,
1895 unsigned long size_in_bytes
)
1897 tree record_or_union_type
= current_class_type
;
1899 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (record_or_union_type
)));
1901 finish_struct (record_or_union_type
, NULL
);
1903 gcc_assert (compare_tree_int (TYPE_SIZE_UNIT (record_or_union_type
),
1904 size_in_bytes
) == 0);
1910 plugin_start_enum_type (cc1_plugin::connection
*self
,
1912 gcc_type underlying_int_type_in
,
1913 enum gcc_cp_symbol_kind flags
,
1914 const char *filename
,
1915 unsigned int line_number
)
1917 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1918 tree underlying_int_type
= convert_in (underlying_int_type_in
);
1920 gcc_assert ((flags
& GCC_CP_SYMBOL_MASK
) == GCC_CP_SYMBOL_ENUM
);
1921 gcc_assert ((flags
& (~(GCC_CP_SYMBOL_MASK
| GCC_CP_ACCESS_MASK
1922 | GCC_CP_FLAG_MASK_ENUM
))) == 0);
1923 gcc_assert (!(flags
& GCC_CP_ACCESS_MASK
) == !at_class_scope_p ());
1925 if (underlying_int_type
== error_mark_node
)
1926 return convert_out (error_mark_node
);
1928 bool is_new_type
= false;
1930 tree id
= name
? get_identifier (name
) : make_anon_name ();
1932 tree type
= start_enum (id
, NULL_TREE
,
1933 underlying_int_type
,
1934 /* attributes = */ NULL_TREE
,
1935 !!(flags
& GCC_CP_FLAG_ENUM_SCOPED
), &is_new_type
);
1937 gcc_assert (is_new_type
);
1939 location_t loc
= ctx
->get_location_t (filename
, line_number
);
1940 tree type_decl
= TYPE_NAME (type
);
1941 DECL_SOURCE_LOCATION (type_decl
) = loc
;
1942 SET_OPAQUE_ENUM_P (type
, false);
1944 set_access_flags (type_decl
, flags
);
1946 return convert_out (ctx
->preserve (type
));
1950 plugin_build_enum_constant (cc1_plugin::connection
*,
1951 gcc_type enum_type_in
,
1953 unsigned long value
)
1955 tree enum_type
= convert_in (enum_type_in
);
1957 gcc_assert (TREE_CODE (enum_type
) == ENUMERAL_TYPE
);
1959 build_enumerator (get_identifier (name
), build_int_cst (enum_type
, value
),
1960 enum_type
, NULL_TREE
, BUILTINS_LOCATION
);
1962 return convert_out (TREE_VALUE (TYPE_VALUES (enum_type
)));
1966 plugin_finish_enum_type (cc1_plugin::connection
*,
1967 gcc_type enum_type_in
)
1969 tree enum_type
= convert_in (enum_type_in
);
1971 finish_enum_value_list (enum_type
);
1972 finish_enum (enum_type
);
1978 plugin_build_function_type (cc1_plugin::connection
*self
,
1979 gcc_type return_type_in
,
1980 const struct gcc_type_array
*argument_types_in
,
1983 tree
*argument_types
;
1984 tree return_type
= convert_in (return_type_in
);
1987 argument_types
= new tree
[argument_types_in
->n_elements
];
1988 for (int i
= 0; i
< argument_types_in
->n_elements
; ++i
)
1989 argument_types
[i
] = convert_in (argument_types_in
->elements
[i
]);
1992 result
= build_varargs_function_type_array (return_type
,
1993 argument_types_in
->n_elements
,
1996 result
= build_function_type_array (return_type
,
1997 argument_types_in
->n_elements
,
2000 delete[] argument_types
;
2002 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2003 return convert_out (ctx
->preserve (result
));
2009 plugin_add_function_default_args (cc1_plugin::connection
*self
,
2010 gcc_type function_type_in
,
2011 const struct gcc_cp_function_args
*defaults
)
2013 tree function_type
= convert_in (function_type_in
);
2015 gcc_assert (TREE_CODE (function_type
) == FUNCTION_TYPE
);
2017 if (!defaults
|| !defaults
->n_elements
)
2018 return function_type_in
;
2020 tree pargs
= TYPE_ARG_TYPES (function_type
);
2021 tree nargs
= NULL_TREE
;
2023 /* Build a reversed copy of the list of default-less arguments in
2024 NARGS. At the end of the loop, PARGS will point to the end of
2025 the argument list, or to the first argument that had a default
2027 while (pargs
&& TREE_VALUE (pargs
) != void_list_node
2028 && !TREE_PURPOSE (pargs
))
2030 nargs
= tree_cons (NULL_TREE
, TREE_VALUE (pargs
), nargs
);
2031 pargs
= TREE_CHAIN (pargs
);
2034 /* Set the defaults in the now-leading NARGS, taking into account
2035 that NARGS is reversed but DEFAULTS->elements isn't. */
2036 tree ndargs
= nargs
;
2037 int i
= defaults
->n_elements
;
2040 gcc_assert (ndargs
);
2041 tree deflt
= convert_in (defaults
->elements
[i
]);
2043 deflt
= error_mark_node
;
2044 TREE_PURPOSE (ndargs
) = deflt
;
2045 ndargs
= TREE_CHAIN (ndargs
);
2048 /* Finally, reverse NARGS, and append the remaining PARGS that
2049 already had defaults. */
2050 nargs
= nreverse (nargs
);
2051 nargs
= chainon (nargs
, pargs
);
2053 tree result
= build_function_type (TREE_TYPE (function_type
), nargs
);
2055 /* Copy exceptions, attributes and whatnot. */
2056 result
= build_exception_variant (result
,
2057 TYPE_RAISES_EXCEPTIONS (function_type
));
2058 result
= cp_build_type_attribute_variant (result
,
2059 TYPE_ATTRIBUTES (function_type
));
2061 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2062 return convert_out (ctx
->preserve (result
));
2066 plugin_set_deferred_function_default_args (cc1_plugin::connection
*,
2067 gcc_decl function_in
,
2068 const struct gcc_cp_function_args
2071 tree function
= convert_in (function_in
);
2073 gcc_assert (TREE_CODE (function
) == FUNCTION_DECL
);
2075 if (!defaults
|| !defaults
->n_elements
)
2078 tree arg
= FUNCTION_FIRST_USER_PARMTYPE (function
);
2080 for (int i
= 0; i
< defaults
->n_elements
; i
++)
2082 while (arg
&& TREE_PURPOSE (arg
) != error_mark_node
)
2083 arg
= TREE_CHAIN (arg
);
2088 TREE_PURPOSE (arg
) = convert_in (defaults
->elements
[i
]);
2089 arg
= TREE_CHAIN (arg
);
2098 plugin_get_function_parameter_decl (cc1_plugin::connection
*,
2099 gcc_decl function_in
,
2102 tree function
= convert_in (function_in
);
2104 gcc_assert (TREE_CODE (function
) == FUNCTION_DECL
);
2108 gcc_assert (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
);
2110 return convert_out (DECL_ARGUMENTS (function
));
2113 gcc_assert (index
>= 0);
2115 tree args
= FUNCTION_FIRST_USER_PARM (function
);
2117 for (int i
= 0; args
&& i
< index
; i
++)
2118 args
= DECL_CHAIN (args
);
2120 return convert_out (args
);
2124 plugin_build_exception_spec_variant (cc1_plugin::connection
*self
,
2125 gcc_type function_type_in
,
2126 const struct gcc_type_array
*except_types_in
)
2128 tree function_type
= convert_in (function_type_in
);
2129 tree except_types
= NULL_TREE
;
2131 if (!except_types_in
)
2132 except_types
= noexcept_false_spec
;
2133 else if (!except_types_in
->n_elements
)
2134 except_types
= empty_except_spec
;
2136 for (int i
= 0; i
< except_types_in
->n_elements
; i
++)
2137 except_types
= add_exception_specifier (except_types
,
2139 (except_types_in
->elements
[i
]),
2142 function_type
= build_exception_variant (function_type
,
2145 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2146 return convert_out (ctx
->preserve (function_type
));
2150 plugin_build_method_type (cc1_plugin::connection
*self
,
2151 gcc_type class_type_in
,
2152 gcc_type func_type_in
,
2153 enum gcc_cp_qualifiers quals_in
,
2154 enum gcc_cp_ref_qualifiers rquals_in
)
2156 tree class_type
= convert_in (class_type_in
);
2157 tree func_type
= convert_in (func_type_in
);
2158 cp_cv_quals quals
= 0;
2159 cp_ref_qualifier rquals
;
2161 if ((quals_in
& GCC_CP_QUALIFIER_CONST
) != 0)
2162 quals
|= TYPE_QUAL_CONST
;
2163 if ((quals_in
& GCC_CP_QUALIFIER_VOLATILE
) != 0)
2164 quals
|= TYPE_QUAL_VOLATILE
;
2165 gcc_assert ((quals_in
& GCC_CP_QUALIFIER_RESTRICT
) == 0);
2169 case GCC_CP_REF_QUAL_NONE
:
2170 rquals
= REF_QUAL_NONE
;
2172 case GCC_CP_REF_QUAL_LVALUE
:
2173 rquals
= REF_QUAL_LVALUE
;
2175 case GCC_CP_REF_QUAL_RVALUE
:
2176 rquals
= REF_QUAL_RVALUE
;
2182 tree method_type
= class_type
2183 ? build_memfn_type (func_type
, class_type
, quals
, rquals
)
2184 : apply_memfn_quals (func_type
, quals
, rquals
);
2186 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2187 return convert_out (ctx
->preserve (method_type
));
2191 plugin_build_pointer_to_member_type (cc1_plugin::connection
*self
,
2192 gcc_type class_type_in
,
2193 gcc_type member_type_in
)
2195 tree class_type
= convert_in (class_type_in
);
2196 tree member_type
= convert_in (member_type_in
);
2198 tree memptr_type
= build_ptrmem_type (class_type
, member_type
);
2200 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2201 return convert_out (ctx
->preserve (memptr_type
));
2205 plugin_start_template_decl (cc1_plugin::connection
*)
2207 begin_template_parm_list ();
2209 TP_PARM_LIST
= NULL_TREE
;
2215 plugin_get_type_decl (cc1_plugin::connection
*,
2218 tree type
= convert_in (type_in
);
2220 tree name
= TYPE_NAME (type
);
2223 return convert_out (name
);
2227 plugin_get_decl_type (cc1_plugin::connection
*,
2230 tree decl
= convert_in (decl_in
);
2232 tree type
= TREE_TYPE (decl
);
2235 return convert_out (type
);
2239 plugin_build_type_template_parameter (cc1_plugin::connection
*self
,
2241 int /* bool */ pack_p
,
2242 gcc_type default_type
,
2243 const char *filename
,
2244 unsigned int line_number
)
2246 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2247 location_t loc
= ctx
->get_location_t (filename
, line_number
);
2249 gcc_assert (template_parm_scope_p ());
2251 tree parm
= finish_template_type_parm (class_type_node
, get_identifier (id
));
2252 parm
= build_tree_list (convert_in (default_type
), parm
);
2254 gcc_assert (!(pack_p
&& default_type
));
2256 /* Create a type and a decl for the type parm, and add the decl to
2258 TP_PARM_LIST
= process_template_parm (TP_PARM_LIST
, loc
, parm
,
2259 /* is_non_type = */ false, pack_p
);
2261 /* Locate the decl of the newly-added, processed template parm. */
2262 parm
= TREE_VALUE (tree_last (TP_PARM_LIST
));
2264 /* Return its type. */
2265 return convert_out (ctx
->preserve (TREE_TYPE (parm
)));
2269 plugin_build_template_template_parameter (cc1_plugin::connection
*self
,
2271 int /* bool */ pack_p
,
2272 gcc_utempl default_templ
,
2273 const char *filename
,
2274 unsigned int line_number
)
2276 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2277 location_t loc
= ctx
->get_location_t (filename
, line_number
);
2279 gcc_assert (template_parm_scope_p ());
2281 /* Finish the template parm list that started this template parm. */
2282 end_template_parm_list (TP_PARM_LIST
);
2284 gcc_assert (template_parm_scope_p ());
2286 tree parm
= finish_template_template_parm (class_type_node
,
2287 get_identifier (id
));
2288 parm
= build_tree_list (convert_in (default_templ
), parm
);
2290 gcc_assert (!(pack_p
&& default_templ
));
2292 /* Create a type and a decl for the template parm, and add the decl
2294 TP_PARM_LIST
= process_template_parm (TP_PARM_LIST
, loc
, parm
,
2295 /* is_non_type = */ false, pack_p
);
2297 /* Locate the decl of the newly-added, processed template parm. */
2298 parm
= TREE_VALUE (tree_last (TP_PARM_LIST
));
2300 return convert_out (ctx
->preserve (parm
));
2304 plugin_build_value_template_parameter (cc1_plugin::connection
*self
,
2307 gcc_expr default_value
,
2308 const char *filename
,
2309 unsigned int line_number
)
2311 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2312 location_t loc
= ctx
->get_location_t (filename
, line_number
);
2314 gcc_assert (template_parm_scope_p ());
2316 cp_declarator declarator
;
2317 memset (&declarator
, 0, sizeof (declarator
));
2318 // &declarator = make_id_declarator (NULL, get_identifier (id), sfk_none):
2319 declarator
.kind
= cdk_id
;
2320 declarator
.u
.id
.qualifying_scope
= NULL
;
2321 declarator
.u
.id
.unqualified_name
= get_identifier (id
);
2322 declarator
.u
.id
.sfk
= sfk_none
;
2324 cp_decl_specifier_seq declspec
;
2325 memset (&declspec
, 0, sizeof (declspec
));
2326 // cp_parser_set_decl_spec_type (&declspec, convert_in (type), -token-, false):
2327 declspec
.any_specifiers_p
= declspec
.any_type_specifiers_p
= true;
2328 declspec
.type
= convert_in (type
);
2329 declspec
.locations
[ds_type_spec
] = loc
;
2331 tree parm
= grokdeclarator (&declarator
, &declspec
, TPARM
, 0, 0);
2332 parm
= build_tree_list (convert_in (default_value
), parm
);
2334 /* Create a type and a decl for the template parm, and add the decl
2336 TP_PARM_LIST
= process_template_parm (TP_PARM_LIST
, loc
, parm
,
2337 /* is_non_type = */ true, false);
2339 /* Locate the decl of the newly-added, processed template parm. */
2340 parm
= TREE_VALUE (tree_last (TP_PARM_LIST
));
2342 return convert_out (ctx
->preserve (parm
));
2346 targlist (const gcc_cp_template_args
*targs
)
2348 int n
= targs
->n_elements
;
2349 tree vec
= make_tree_vec (n
);
2352 switch (targs
->kinds
[n
])
2354 case GCC_CP_TPARG_VALUE
:
2355 TREE_VEC_ELT (vec
, n
) = convert_in (targs
->elements
[n
].value
);
2357 case GCC_CP_TPARG_CLASS
:
2358 TREE_VEC_ELT (vec
, n
) = convert_in (targs
->elements
[n
].type
);
2360 case GCC_CP_TPARG_TEMPL
:
2361 TREE_VEC_ELT (vec
, n
) = convert_in (targs
->elements
[n
].templ
);
2363 case GCC_CP_TPARG_PACK
:
2364 TREE_VEC_ELT (vec
, n
) = convert_in (targs
->elements
[n
].pack
);
2374 plugin_build_dependent_typename (cc1_plugin::connection
*self
,
2375 gcc_type enclosing_type
,
2377 const gcc_cp_template_args
*targs
)
2379 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2380 tree type
= convert_in (enclosing_type
);
2381 tree name
= get_identifier (id
);
2383 name
= build_min_nt_loc (/*loc=*/0, TEMPLATE_ID_EXPR
,
2384 name
, targlist (targs
));
2385 tree res
= make_typename_type (type
, name
, typename_type
,
2386 /*complain=*/tf_error
);
2387 return convert_out (ctx
->preserve (res
));
2391 plugin_build_dependent_class_template (cc1_plugin::connection
*self
,
2392 gcc_type enclosing_type
,
2395 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2396 tree type
= convert_in (enclosing_type
);
2397 tree name
= get_identifier (id
);
2398 tree res
= make_unbound_class_template (type
, name
, NULL_TREE
,
2399 /*complain=*/tf_error
);
2400 return convert_out (ctx
->preserve (res
));
2404 plugin_build_dependent_type_template_id (cc1_plugin::connection
*self
,
2405 gcc_utempl template_decl
,
2406 const gcc_cp_template_args
*targs
)
2408 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2409 tree type
= convert_in (template_decl
);
2410 tree decl
= finish_template_type (type
, targlist (targs
),
2411 /*entering_scope=*/false);
2412 return convert_out (ctx
->preserve (TREE_TYPE (decl
)));
2416 plugin_build_dependent_expr (cc1_plugin::connection
*self
,
2417 gcc_decl enclosing_scope
,
2418 enum gcc_cp_symbol_kind flags
,
2420 gcc_type conv_type_in
,
2421 const gcc_cp_template_args
*targs
)
2423 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2424 tree scope
= convert_in (enclosing_scope
);
2425 tree conv_type
= convert_in (conv_type_in
);
2428 if (TREE_CODE (scope
) != NAMESPACE_DECL
)
2430 tree type
= TREE_TYPE (scope
);
2431 gcc_assert (TYPE_NAME (type
) == scope
);
2435 if (flags
== (GCC_CP_SYMBOL_FUNCTION
| GCC_CP_FLAG_SPECIAL_FUNCTION
))
2437 bool assop
= false, convop
= false;
2438 tree_code opcode
= ERROR_MARK
;
2440 switch (CHARS2 (name
[0], name
[1]))
2442 case CHARS2 ('C', 0x0): // ctor base declaration
2443 case CHARS2 ('C', ' '):
2444 case CHARS2 ('C', '1'):
2445 case CHARS2 ('C', '2'):
2446 case CHARS2 ('C', '4'):
2447 identifier
= ctor_identifier
;
2449 case CHARS2 ('D', 0x0): // dtor base declaration
2450 case CHARS2 ('D', ' '):
2451 case CHARS2 ('D', '0'):
2452 case CHARS2 ('D', '1'):
2453 case CHARS2 ('D', '2'):
2454 case CHARS2 ('D', '4'):
2455 gcc_assert (!targs
);
2456 identifier
= dtor_identifier
;
2458 case CHARS2 ('n', 'w'): // operator new
2461 case CHARS2 ('n', 'a'): // operator new[]
2462 opcode
= VEC_NEW_EXPR
;
2464 case CHARS2 ('d', 'l'): // operator delete
2465 opcode
= DELETE_EXPR
;
2467 case CHARS2 ('d', 'a'): // operator delete[]
2468 opcode
= VEC_DELETE_EXPR
;
2470 case CHARS2 ('p', 's'): // operator + (unary)
2473 case CHARS2 ('n', 'g'): // operator - (unary)
2474 opcode
= MINUS_EXPR
;
2476 case CHARS2 ('a', 'd'): // operator & (unary)
2477 opcode
= BIT_AND_EXPR
;
2479 case CHARS2 ('d', 'e'): // operator * (unary)
2482 case CHARS2 ('c', 'o'): // operator ~
2483 opcode
= BIT_NOT_EXPR
;
2485 case CHARS2 ('p', 'l'): // operator +
2488 case CHARS2 ('m', 'i'): // operator -
2489 opcode
= MINUS_EXPR
;
2491 case CHARS2 ('m', 'l'): // operator *
2494 case CHARS2 ('d', 'v'): // operator /
2495 opcode
= TRUNC_DIV_EXPR
;
2497 case CHARS2 ('r', 'm'): // operator %
2498 opcode
= TRUNC_MOD_EXPR
;
2500 case CHARS2 ('a', 'n'): // operator &
2501 opcode
= BIT_AND_EXPR
;
2503 case CHARS2 ('o', 'r'): // operator |
2504 opcode
= BIT_IOR_EXPR
;
2506 case CHARS2 ('e', 'o'): // operator ^
2507 opcode
= BIT_XOR_EXPR
;
2509 case CHARS2 ('a', 'S'): // operator =
2513 case CHARS2 ('p', 'L'): // operator +=
2517 case CHARS2 ('m', 'I'): // operator -=
2518 opcode
= MINUS_EXPR
;
2521 case CHARS2 ('m', 'L'): // operator *=
2525 case CHARS2 ('d', 'V'): // operator /=
2526 opcode
= TRUNC_DIV_EXPR
;
2529 case CHARS2 ('r', 'M'): // operator %=
2530 opcode
= TRUNC_MOD_EXPR
;
2533 case CHARS2 ('a', 'N'): // operator &=
2534 opcode
= BIT_AND_EXPR
;
2537 case CHARS2 ('o', 'R'): // operator |=
2538 opcode
= BIT_IOR_EXPR
;
2541 case CHARS2 ('e', 'O'): // operator ^=
2542 opcode
= BIT_XOR_EXPR
;
2545 case CHARS2 ('l', 's'): // operator <<
2546 opcode
= LSHIFT_EXPR
;
2548 case CHARS2 ('r', 's'): // operator >>
2549 opcode
= RSHIFT_EXPR
;
2551 case CHARS2 ('l', 'S'): // operator <<=
2552 opcode
= LSHIFT_EXPR
;
2555 case CHARS2 ('r', 'S'): // operator >>=
2556 opcode
= RSHIFT_EXPR
;
2559 case CHARS2 ('e', 'q'): // operator ==
2562 case CHARS2 ('n', 'e'): // operator !=
2565 case CHARS2 ('l', 't'): // operator <
2568 case CHARS2 ('g', 't'): // operator >
2571 case CHARS2 ('l', 'e'): // operator <=
2574 case CHARS2 ('g', 'e'): // operator >=
2577 case CHARS2 ('n', 't'): // operator !
2578 opcode
= TRUTH_NOT_EXPR
;
2580 case CHARS2 ('a', 'a'): // operator &&
2581 opcode
= TRUTH_ANDIF_EXPR
;
2583 case CHARS2 ('o', 'o'): // operator ||
2584 opcode
= TRUTH_ORIF_EXPR
;
2586 case CHARS2 ('p', 'p'): // operator ++
2587 opcode
= POSTINCREMENT_EXPR
;
2589 case CHARS2 ('m', 'm'): // operator --
2590 opcode
= PREDECREMENT_EXPR
;
2592 case CHARS2 ('c', 'm'): // operator ,
2593 opcode
= COMPOUND_EXPR
;
2595 case CHARS2 ('p', 'm'): // operator ->*
2596 opcode
= MEMBER_REF
;
2598 case CHARS2 ('p', 't'): // operator ->
2599 opcode
= COMPONENT_REF
;
2601 case CHARS2 ('c', 'l'): // operator ()
2604 case CHARS2 ('i', 'x'): // operator []
2607 case CHARS2 ('c', 'v'): // operator <T> (conversion operator)
2609 identifier
= make_conv_op_name (conv_type
);
2612 case CHARS2 ('l', 'i'): // operator "" <id>
2614 char *id
= (char *)name
+ 2;
2615 bool freeid
= false;
2616 if (*id
>= '0' && *id
<= '9')
2625 while (*id
&& *id
>= '0' && *id
<= '9');
2626 id
= xstrndup (id
, len
);
2629 identifier
= cp_literal_operator_id (id
);
2634 case CHARS2 ('q', 'u'): // ternary operator, not overloadable.
2639 gcc_assert (convop
|| !conv_type
);
2641 if (opcode
!= ERROR_MARK
)
2642 identifier
= ovl_op_identifier (assop
, opcode
);
2644 gcc_assert (identifier
);
2648 gcc_assert (flags
== GCC_CP_SYMBOL_MASK
);
2649 gcc_assert (!conv_type
);
2650 identifier
= get_identifier (name
);
2652 tree res
= identifier
;
2654 res
= lookup_name_real (res
, 0, 0, true, 0, 0);
2655 else if (!TYPE_P (scope
) || !dependent_scope_p (scope
))
2657 res
= lookup_qualified_name (scope
, res
, false, true);
2658 /* We've already resolved the name in the scope, so skip the
2659 build_qualified_name call below. */
2663 res
= lookup_template_function (res
, targlist (targs
));
2665 res
= build_qualified_name (NULL_TREE
, scope
, res
, !!targs
);
2666 return convert_out (ctx
->preserve (res
));
2670 plugin_build_literal_expr (cc1_plugin::connection
*self
,
2671 gcc_type type
, unsigned long value
)
2673 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2674 tree t
= convert_in (type
);
2675 tree val
= build_int_cst_type (t
, (unsigned HOST_WIDE_INT
) value
);
2676 return convert_out (ctx
->preserve (val
));
2680 plugin_build_decl_expr (cc1_plugin::connection
*self
,
2684 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2685 tree decl
= convert_in (decl_in
);
2686 gcc_assert (DECL_P (decl
));
2690 gcc_assert (DECL_CLASS_SCOPE_P (decl
));
2691 result
= build_offset_ref (DECL_CONTEXT (decl
), decl
,
2692 /*address_p=*/true, tf_error
);
2694 return convert_out (ctx
->preserve (result
));
2698 plugin_build_unary_expr (cc1_plugin::connection
*self
,
2699 const char *unary_op
,
2702 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2703 tree op0
= convert_in (operand
);
2704 tree_code opcode
= ERROR_MARK
;
2705 bool global_scope_p
= false;
2708 switch (CHARS2 (unary_op
[0], unary_op
[1]))
2710 case CHARS2 ('p', 's'): // operator + (unary)
2711 opcode
= UNARY_PLUS_EXPR
;
2713 case CHARS2 ('n', 'g'): // operator - (unary)
2714 opcode
= NEGATE_EXPR
;
2716 case CHARS2 ('a', 'd'): // operator & (unary)
2719 case CHARS2 ('d', 'e'): // operator * (unary)
2720 opcode
= INDIRECT_REF
;
2722 case CHARS2 ('c', 'o'): // operator ~
2723 opcode
= BIT_NOT_EXPR
;
2725 case CHARS2 ('n', 't'): // operator !
2726 opcode
= TRUTH_NOT_EXPR
;
2728 case CHARS2 ('p', 'p'): // operator ++
2729 opcode
= unary_op
[2] == '_' ? PREINCREMENT_EXPR
: POSTINCREMENT_EXPR
;
2731 case CHARS2 ('m', 'm'): // operator --
2732 opcode
= unary_op
[2] == '_' ? PREDECREMENT_EXPR
: POSTDECREMENT_EXPR
;
2734 case CHARS2 ('n', 'x'): // noexcept
2735 opcode
= NOEXCEPT_EXPR
;
2737 case CHARS2 ('t', 'w'): // throw
2739 opcode
= THROW_EXPR
;
2741 case CHARS2 ('t', 'r'): // rethrow
2743 opcode
= THROW_EXPR
;
2745 case CHARS2 ('t', 'e'): // typeid (value)
2746 opcode
= TYPEID_EXPR
;
2748 case CHARS2 ('s', 'z'): // sizeof (value)
2749 opcode
= SIZEOF_EXPR
;
2751 case CHARS2 ('a', 'z'): // alignof (value)
2752 opcode
= ALIGNOF_EXPR
;
2754 case CHARS2 ('g', 's'): // global scope (for delete, delete[])
2755 gcc_assert (!global_scope_p
);
2756 global_scope_p
= true;
2759 case CHARS2 ('d', 'l'): // delete
2760 opcode
= DELETE_EXPR
;
2762 case CHARS2 ('d', 'a'): // delete[]
2763 opcode
= VEC_DELETE_EXPR
;
2765 case CHARS2 ('s', 'p'): // pack...
2766 opcode
= EXPR_PACK_EXPANSION
;
2768 case CHARS2 ('s', 'Z'): // sizeof...(pack)
2769 opcode
= TYPE_PACK_EXPANSION
; // Not really, but let's use its code.
2772 /* FIXME: __real__, __imag__? */
2778 gcc_assert (!global_scope_p
2779 || opcode
== DELETE_EXPR
|| opcode
== VEC_DELETE_EXPR
);
2781 processing_template_decl
++;
2782 bool template_dependent_p
= op0
2783 && (type_dependent_expression_p (op0
)
2784 || value_dependent_expression_p (op0
));
2785 if (!template_dependent_p
)
2786 processing_template_decl
--;
2790 gcc_assert (op0
|| opcode
== THROW_EXPR
);
2795 result
= finish_noexcept_expr (op0
, tf_error
);
2799 result
= build_throw (op0
);
2803 result
= build_typeid (op0
, tf_error
);
2808 result
= cxx_sizeof_or_alignof_expr (op0
, opcode
, true);
2812 case VEC_DELETE_EXPR
:
2813 result
= delete_sanity (op0
, NULL_TREE
, opcode
== VEC_DELETE_EXPR
,
2814 global_scope_p
, tf_error
);
2817 case EXPR_PACK_EXPANSION
:
2818 result
= make_pack_expansion (op0
);
2821 // We're using this for sizeof...(pack). */
2822 case TYPE_PACK_EXPANSION
:
2823 result
= make_pack_expansion (op0
);
2824 PACK_EXPANSION_SIZEOF_P (result
) = true;
2828 result
= build_x_unary_op (/*loc=*/0, opcode
, op0
, tf_error
);
2832 if (template_dependent_p
)
2833 processing_template_decl
--;
2835 return convert_out (ctx
->preserve (result
));
2839 plugin_build_binary_expr (cc1_plugin::connection
*self
,
2840 const char *binary_op
,
2844 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2845 tree op0
= convert_in (operand1
);
2846 tree op1
= convert_in (operand2
);
2847 tree_code opcode
= ERROR_MARK
;
2849 switch (CHARS2 (binary_op
[0], binary_op
[1]))
2851 case CHARS2 ('p', 'l'): // operator +
2854 case CHARS2 ('m', 'i'): // operator -
2855 opcode
= MINUS_EXPR
;
2857 case CHARS2 ('m', 'l'): // operator *
2860 case CHARS2 ('d', 'v'): // operator /
2861 opcode
= TRUNC_DIV_EXPR
;
2863 case CHARS2 ('r', 'm'): // operator %
2864 opcode
= TRUNC_MOD_EXPR
;
2866 case CHARS2 ('a', 'n'): // operator &
2867 opcode
= BIT_AND_EXPR
;
2869 case CHARS2 ('o', 'r'): // operator |
2870 opcode
= BIT_IOR_EXPR
;
2872 case CHARS2 ('e', 'o'): // operator ^
2873 opcode
= BIT_XOR_EXPR
;
2875 case CHARS2 ('l', 's'): // operator <<
2876 opcode
= LSHIFT_EXPR
;
2878 case CHARS2 ('r', 's'): // operator >>
2879 opcode
= RSHIFT_EXPR
;
2881 case CHARS2 ('e', 'q'): // operator ==
2884 case CHARS2 ('n', 'e'): // operator !=
2887 case CHARS2 ('l', 't'): // operator <
2890 case CHARS2 ('g', 't'): // operator >
2893 case CHARS2 ('l', 'e'): // operator <=
2896 case CHARS2 ('g', 'e'): // operator >=
2899 case CHARS2 ('a', 'a'): // operator &&
2900 opcode
= TRUTH_ANDIF_EXPR
;
2902 case CHARS2 ('o', 'o'): // operator ||
2903 opcode
= TRUTH_ORIF_EXPR
;
2905 case CHARS2 ('c', 'm'): // operator ,
2906 opcode
= COMPOUND_EXPR
;
2908 case CHARS2 ('p', 'm'): // operator ->*
2909 opcode
= MEMBER_REF
;
2911 case CHARS2 ('p', 't'): // operator ->
2912 opcode
= INDIRECT_REF
; // Not really! This will stand for
2913 // INDIRECT_REF followed by COMPONENT_REF
2916 case CHARS2 ('i', 'x'): // operator []
2919 case CHARS2 ('d', 's'): // operator .*
2920 opcode
= DOTSTAR_EXPR
;
2922 case CHARS2 ('d', 't'): // operator .
2923 opcode
= COMPONENT_REF
;
2930 processing_template_decl
++;
2931 bool template_dependent_p
= type_dependent_expression_p (op0
)
2932 || value_dependent_expression_p (op0
)
2933 || type_dependent_expression_p (op1
)
2934 || value_dependent_expression_p (op1
);
2935 if (!template_dependent_p
)
2936 processing_template_decl
--;
2942 case INDIRECT_REF
: // This is actually a "->".
2943 op0
= build_x_arrow (/*loc=*/0, op0
, tf_error
);
2946 result
= finish_class_member_access_expr (op0
, op1
,
2947 /*template_p=*/false,
2952 result
= build_x_binary_op (/*loc=*/0, opcode
, op0
, ERROR_MARK
,
2953 op1
, ERROR_MARK
, NULL
, tf_error
);
2957 if (template_dependent_p
)
2958 processing_template_decl
--;
2960 return convert_out (ctx
->preserve (result
));
2964 plugin_build_ternary_expr (cc1_plugin::connection
*self
,
2965 const char *ternary_op
,
2970 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2971 tree op0
= convert_in (operand1
);
2972 tree op1
= convert_in (operand2
);
2973 tree op2
= convert_in (operand3
);
2974 gcc_assert (CHARS2 (ternary_op
[0], ternary_op
[1])
2975 == CHARS2 ('q', 'u')); // ternary operator
2977 processing_template_decl
++;
2978 bool template_dependent_p
= type_dependent_expression_p (op0
)
2979 || value_dependent_expression_p (op0
)
2980 || type_dependent_expression_p (op1
)
2981 || value_dependent_expression_p (op1
)
2982 || type_dependent_expression_p (op2
)
2983 || value_dependent_expression_p (op2
);
2984 if (!template_dependent_p
)
2985 processing_template_decl
--;
2987 tree val
= build_x_conditional_expr (/*loc=*/0, op0
, op1
, op2
, tf_error
);
2989 if (template_dependent_p
)
2990 processing_template_decl
--;
2992 return convert_out (ctx
->preserve (val
));
2996 plugin_build_unary_type_expr (cc1_plugin::connection
*self
,
2997 const char *unary_op
,
3000 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3001 tree type
= convert_in (operand
);
3002 tree_code opcode
= ERROR_MARK
;
3004 switch (CHARS2 (unary_op
[0], unary_op
[1]))
3006 case CHARS2 ('t', 'i'): // typeid (type)
3007 opcode
= TYPEID_EXPR
;
3010 case CHARS2 ('s', 't'): // sizeof (type)
3011 opcode
= SIZEOF_EXPR
;
3013 case CHARS2 ('a', 't'): // alignof (type)
3014 opcode
= ALIGNOF_EXPR
;
3017 case CHARS2 ('s', 'Z'): // sizeof...(pack)
3018 opcode
= TYPE_PACK_EXPANSION
; // Not really, but let's use its code.
3021 // FIXME: do we have to handle "sp", for the size of a captured
3022 // template parameter pack from an alias template, taking
3023 // multiple template arguments?
3029 processing_template_decl
++;
3030 bool template_dependent_p
= dependent_type_p (type
);
3031 if (!template_dependent_p
)
3032 processing_template_decl
--;
3039 result
= get_typeid (type
, tf_error
);
3042 // We're using this for sizeof...(pack). */
3043 case TYPE_PACK_EXPANSION
:
3044 result
= make_pack_expansion (type
);
3045 PACK_EXPANSION_SIZEOF_P (result
) = true;
3049 /* Use the C++11 alignof semantics. */
3050 result
= cxx_sizeof_or_alignof_type (type
, opcode
, true, true);
3053 if (template_dependent_p
)
3054 processing_template_decl
--;
3056 return convert_out (ctx
->preserve (result
));
3060 plugin_build_cast_expr (cc1_plugin::connection
*self
,
3061 const char *binary_op
,
3065 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3066 tree (*build_cast
)(tree type
, tree expr
, tsubst_flags_t complain
) = NULL
;
3067 tree type
= convert_in (operand1
);
3068 tree expr
= convert_in (operand2
);
3070 switch (CHARS2 (binary_op
[0], binary_op
[1]))
3072 case CHARS2 ('d', 'c'): // dynamic_cast
3073 build_cast
= build_dynamic_cast
;
3076 case CHARS2 ('s', 'c'): // static_cast
3077 build_cast
= build_static_cast
;
3080 case CHARS2 ('c', 'c'): // const_cast
3081 build_cast
= build_const_cast
;
3084 case CHARS2 ('r', 'c'): // reinterpret_cast
3085 build_cast
= build_reinterpret_cast
;
3088 case CHARS2 ('c', 'v'): // C cast, conversion with one argument
3089 build_cast
= cp_build_c_cast
;
3096 processing_template_decl
++;
3097 bool template_dependent_p
= dependent_type_p (type
)
3098 || type_dependent_expression_p (expr
)
3099 || value_dependent_expression_p (expr
);
3100 if (!template_dependent_p
)
3101 processing_template_decl
--;
3103 tree val
= build_cast (type
, expr
, tf_error
);
3105 if (template_dependent_p
)
3106 processing_template_decl
--;
3108 return convert_out (ctx
->preserve (val
));
3111 static inline vec
<tree
, va_gc
> *
3112 args_to_tree_vec (const struct gcc_cp_function_args
*args_in
)
3114 vec
<tree
, va_gc
> *args
= make_tree_vector ();
3115 for (int i
= 0; i
< args_in
->n_elements
; i
++)
3116 vec_safe_push (args
, convert_in (args_in
->elements
[i
]));
3121 args_to_tree_list (const struct gcc_cp_function_args
*args_in
)
3123 tree args
, *tail
= &args
;
3124 for (int i
= 0; i
< args_in
->n_elements
; i
++)
3126 *tail
= build_tree_list (NULL
, convert_in (args_in
->elements
[i
]));
3127 tail
= &TREE_CHAIN (*tail
);
3132 static inline vec
<constructor_elt
, va_gc
> *
3133 args_to_ctor_elts (const struct gcc_cp_function_args
*args_in
)
3135 vec
<constructor_elt
, va_gc
> *args
= NULL
;
3136 for (int i
= 0; i
< args_in
->n_elements
; i
++)
3137 CONSTRUCTOR_APPEND_ELT (args
, NULL_TREE
, convert_in (args_in
->elements
[i
]));
3142 plugin_build_expression_list_expr (cc1_plugin::connection
*self
,
3143 const char *conv_op
,
3145 const struct gcc_cp_function_args
*values_in
)
3147 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3148 tree type
= convert_in (type_in
);
3152 switch (CHARS2 (conv_op
[0], conv_op
[1]))
3154 case CHARS2 ('c', 'v'): // conversion with parenthesized expression list
3155 gcc_assert (TYPE_P (type
));
3156 args
= args_to_tree_list (values_in
);
3157 result
= build_functional_cast (type
, args
, tf_error
);
3160 case CHARS2 ('t', 'l'): // conversion with braced expression list
3162 gcc_assert (TYPE_P (type
));
3163 args
= make_node (CONSTRUCTOR
);
3164 CONSTRUCTOR_ELTS (args
) = args_to_ctor_elts (values_in
);
3165 CONSTRUCTOR_IS_DIRECT_INIT (args
) = 1;
3166 result
= finish_compound_literal (type
, args
, tf_error
);
3169 case CHARS2 ('i', 'l'): // untyped braced expression list
3171 result
= make_node (CONSTRUCTOR
);
3172 CONSTRUCTOR_ELTS (result
) = args_to_ctor_elts (values_in
);
3179 return convert_out (ctx
->preserve (result
));
3183 plugin_build_new_expr (cc1_plugin::connection
*self
,
3185 const struct gcc_cp_function_args
*placement_in
,
3187 const struct gcc_cp_function_args
*initializer_in
)
3189 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3190 tree type
= convert_in (type_in
);
3191 vec
<tree
, va_gc
> *placement
= NULL
, *initializer
= NULL
;
3192 bool global_scope_p
= false;
3196 placement
= args_to_tree_vec (placement_in
);
3198 initializer
= args_to_tree_vec (initializer_in
);
3200 gcc_assert (TYPE_P (type
));
3203 switch (CHARS2 (new_op
[0], new_op
[1]))
3205 case CHARS2 ('g', 's'):
3206 gcc_assert (!global_scope_p
);
3207 global_scope_p
= true;
3211 case CHARS2 ('n', 'w'): // non-array new
3212 gcc_assert (TREE_CODE (type
) != ARRAY_TYPE
);
3215 case CHARS2 ('n', 'a'): // array new
3216 gcc_assert (TREE_CODE (type
) == ARRAY_TYPE
);
3217 gcc_assert (TYPE_DOMAIN (type
));
3219 // Compute the length of the outermost array type, then discard it.
3220 tree maxelt
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
3221 tree eltype
= TREE_TYPE (maxelt
);
3222 tree onecst
= integer_one_node
;
3224 processing_template_decl
++;
3225 bool template_dependent_p
= value_dependent_expression_p (maxelt
)
3226 || type_dependent_expression_p (maxelt
);
3227 if (!template_dependent_p
)
3229 processing_template_decl
--;
3230 onecst
= fold_convert (eltype
, onecst
);
3233 nelts
= fold_build2 (PLUS_EXPR
, eltype
, nelts
, onecst
);
3235 if (template_dependent_p
)
3236 processing_template_decl
--;
3238 type
= TREE_TYPE (type
);
3246 processing_template_decl
++;
3247 bool template_dependent_p
= dependent_type_p (type
)
3248 || value_dependent_expression_p (nelts
)
3250 && any_type_dependent_arguments_p (placement
))
3252 && any_type_dependent_arguments_p (initializer
));
3253 if (!template_dependent_p
)
3254 processing_template_decl
--;
3256 tree result
= build_new (&placement
, type
, nelts
, &initializer
,
3257 global_scope_p
, tf_error
);
3259 if (template_dependent_p
)
3260 processing_template_decl
--;
3262 if (placement
!= NULL
)
3263 release_tree_vector (placement
);
3264 if (initializer
!= NULL
)
3265 release_tree_vector (initializer
);
3267 return convert_out (ctx
->preserve (result
));
3271 plugin_build_call_expr (cc1_plugin::connection
*self
,
3272 gcc_expr callable_in
, int qualified_p
,
3273 const struct gcc_cp_function_args
*args_in
)
3275 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3276 tree callable
= convert_in (callable_in
);
3279 vec
<tree
, va_gc
> *args
= args_to_tree_vec (args_in
);
3281 bool koenig_p
= false;
3282 if (!qualified_p
&& !args
->is_empty ())
3284 if (identifier_p (callable
))
3286 else if (is_overloaded_fn (callable
))
3288 tree fn
= get_first_fn (callable
);
3289 fn
= STRIP_TEMPLATE (fn
);
3291 if (!DECL_FUNCTION_MEMBER_P (fn
)
3292 && !DECL_LOCAL_FUNCTION_P (fn
))
3297 if (koenig_p
&& !any_type_dependent_arguments_p (args
))
3298 callable
= perform_koenig_lookup (callable
, args
, tf_none
);
3300 if (TREE_CODE (callable
) == COMPONENT_REF
)
3302 tree object
= TREE_OPERAND (callable
, 0);
3303 tree memfn
= TREE_OPERAND (callable
, 1);
3305 if (type_dependent_expression_p (object
)
3306 || (!BASELINK_P (memfn
) && TREE_CODE (memfn
) != FIELD_DECL
)
3307 || type_dependent_expression_p (memfn
)
3308 || any_type_dependent_arguments_p (args
))
3309 call_expr
= build_nt_call_vec (callable
, args
);
3310 else if (BASELINK_P (memfn
))
3311 call_expr
= build_new_method_call (object
, memfn
, &args
, NULL_TREE
,
3313 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
3317 call_expr
= finish_call_expr (callable
, &args
, false, false, tf_none
);
3319 else if (TREE_CODE (callable
) == OFFSET_REF
3320 || TREE_CODE (callable
) == MEMBER_REF
3321 || TREE_CODE (callable
) == DOTSTAR_EXPR
)
3322 call_expr
= build_offset_ref_call_from_tree (callable
, &args
, tf_none
);
3324 call_expr
= finish_call_expr (callable
, &args
,
3325 !!qualified_p
, koenig_p
, tf_none
);
3327 release_tree_vector (args
);
3328 return convert_out (ctx
->preserve (call_expr
));
3332 plugin_get_expr_type (cc1_plugin::connection
*self
,
3335 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3336 tree op0
= convert_in (operand
);
3339 type
= TREE_TYPE (op0
);
3342 type
= make_decltype_auto ();
3343 AUTO_IS_DECLTYPE (type
) = true;
3345 return convert_out (ctx
->preserve (type
));
3349 plugin_build_function_template_specialization (cc1_plugin::connection
*self
,
3350 gcc_decl template_decl
,
3351 const gcc_cp_template_args
*targs
,
3352 gcc_address address
,
3353 const char *filename
,
3354 unsigned int line_number
)
3356 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3357 location_t loc
= ctx
->get_location_t (filename
, line_number
);
3358 tree name
= convert_in (template_decl
);
3359 tree targsl
= targlist (targs
);
3361 tree decl
= tsubst (name
, targsl
, tf_error
, NULL_TREE
);
3362 DECL_SOURCE_LOCATION (decl
) = loc
;
3364 record_decl_address (ctx
, build_decl_addr_value (decl
, address
));
3366 return convert_out (ctx
->preserve (decl
));
3370 plugin_build_class_template_specialization (cc1_plugin::connection
*self
,
3371 gcc_decl template_decl
,
3372 const gcc_cp_template_args
*args
,
3373 const char *filename
,
3374 unsigned int line_number
)
3376 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3377 location_t loc
= ctx
->get_location_t (filename
, line_number
);
3378 tree name
= convert_in (template_decl
);
3380 tree tdecl
= finish_template_type (name
, targlist (args
), false);;
3381 DECL_SOURCE_LOCATION (tdecl
) = loc
;
3383 return convert_out (ctx
->preserve (tdecl
));
3386 /* Return a builtin type associated with BUILTIN_NAME. */
3389 safe_lookup_builtin_type (const char *builtin_name
)
3391 tree result
= NULL_TREE
;
3396 result
= identifier_global_value (get_identifier (builtin_name
));
3401 gcc_assert (TREE_CODE (result
) == TYPE_DECL
);
3402 result
= TREE_TYPE (result
);
3407 plugin_get_int_type (cc1_plugin::connection
*self
,
3408 int is_unsigned
, unsigned long size_in_bytes
,
3409 const char *builtin_name
)
3415 result
= safe_lookup_builtin_type (builtin_name
);
3416 gcc_assert (!result
|| TREE_CODE (result
) == INTEGER_TYPE
);
3419 result
= c_common_type_for_size (BITS_PER_UNIT
* size_in_bytes
,
3422 if (result
== NULL_TREE
)
3423 result
= error_mark_node
;
3426 gcc_assert (!TYPE_UNSIGNED (result
) == !is_unsigned
);
3427 gcc_assert (TREE_CODE (TYPE_SIZE (result
)) == INTEGER_CST
);
3428 gcc_assert (TYPE_PRECISION (result
) == BITS_PER_UNIT
* size_in_bytes
);
3430 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3431 ctx
->preserve (result
);
3433 return convert_out (result
);
3437 plugin_get_char_type (cc1_plugin::connection
*)
3439 return convert_out (char_type_node
);
3443 plugin_get_float_type (cc1_plugin::connection
*,
3444 unsigned long size_in_bytes
,
3445 const char *builtin_name
)
3449 tree result
= safe_lookup_builtin_type (builtin_name
);
3452 return convert_out (error_mark_node
);
3454 gcc_assert (TREE_CODE (result
) == REAL_TYPE
);
3455 gcc_assert (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (result
));
3457 return convert_out (result
);
3460 if (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (float_type_node
))
3461 return convert_out (float_type_node
);
3462 if (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (double_type_node
))
3463 return convert_out (double_type_node
);
3464 if (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (long_double_type_node
))
3465 return convert_out (long_double_type_node
);
3466 return convert_out (error_mark_node
);
3470 plugin_get_void_type (cc1_plugin::connection
*)
3472 return convert_out (void_type_node
);
3476 plugin_get_bool_type (cc1_plugin::connection
*)
3478 return convert_out (boolean_type_node
);
3482 plugin_get_nullptr_type (cc1_plugin::connection
*)
3484 return convert_out (nullptr_type_node
);
3488 plugin_get_nullptr_constant (cc1_plugin::connection
*)
3490 return convert_out (nullptr_node
);
3494 plugin_build_array_type (cc1_plugin::connection
*self
,
3495 gcc_type element_type_in
, int num_elements
)
3497 tree element_type
= convert_in (element_type_in
);
3500 if (num_elements
== -1)
3501 result
= build_array_type (element_type
, NULL_TREE
);
3503 result
= build_array_type_nelts (element_type
, num_elements
);
3505 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3506 return convert_out (ctx
->preserve (result
));
3510 plugin_build_dependent_array_type (cc1_plugin::connection
*self
,
3511 gcc_type element_type_in
,
3512 gcc_expr num_elements_in
)
3514 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3515 tree element_type
= convert_in (element_type_in
);
3516 tree size
= convert_in (num_elements_in
);
3517 tree name
= get_identifier ("dependent array type");
3519 processing_template_decl
++;
3520 bool template_dependent_p
= dependent_type_p (element_type
)
3521 || type_dependent_expression_p (size
)
3522 || value_dependent_expression_p (size
);
3523 if (!template_dependent_p
)
3524 processing_template_decl
--;
3526 tree itype
= compute_array_index_type (name
, size
, tf_error
);
3527 tree type
= build_cplus_array_type (element_type
, itype
);
3529 if (template_dependent_p
)
3530 processing_template_decl
--;
3532 return convert_out (ctx
->preserve (type
));
3536 plugin_build_vla_array_type (cc1_plugin::connection
*self
,
3537 gcc_type element_type_in
,
3538 const char *upper_bound_name
)
3540 tree element_type
= convert_in (element_type_in
);
3541 tree upper_bound
= lookup_name (get_identifier (upper_bound_name
));
3542 tree size
= fold_build2 (PLUS_EXPR
, TREE_TYPE (upper_bound
), upper_bound
,
3543 build_one_cst (TREE_TYPE (upper_bound
)));
3544 tree range
= compute_array_index_type (NULL_TREE
, size
,
3547 tree result
= build_cplus_array_type (element_type
, range
);
3549 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3550 return convert_out (ctx
->preserve (result
));
3554 plugin_build_qualified_type (cc1_plugin::connection
*,
3555 gcc_type unqualified_type_in
,
3556 enum gcc_cp_qualifiers qualifiers
)
3558 tree unqualified_type
= convert_in (unqualified_type_in
);
3559 cp_cv_quals quals
= 0;
3561 if ((qualifiers
& GCC_CP_QUALIFIER_CONST
) != 0)
3562 quals
|= TYPE_QUAL_CONST
;
3563 if ((qualifiers
& GCC_CP_QUALIFIER_VOLATILE
) != 0)
3564 quals
|= TYPE_QUAL_VOLATILE
;
3565 if ((qualifiers
& GCC_CP_QUALIFIER_RESTRICT
) != 0)
3566 quals
|= TYPE_QUAL_RESTRICT
;
3568 gcc_assert ((TREE_CODE (unqualified_type
) != METHOD_TYPE
3569 && TREE_CODE (unqualified_type
) != REFERENCE_TYPE
)
3572 return convert_out (build_qualified_type (unqualified_type
, quals
));
3576 plugin_build_complex_type (cc1_plugin::connection
*self
,
3579 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3580 return convert_out (ctx
->preserve (build_complex_type (convert_in (base_type
))));
3584 plugin_build_vector_type (cc1_plugin::connection
*self
,
3585 gcc_type base_type
, int nunits
)
3587 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3588 return convert_out (ctx
->preserve (build_vector_type (convert_in (base_type
),
3593 plugin_build_constant (cc1_plugin::connection
*self
, gcc_type type_in
,
3594 const char *name
, unsigned long value
,
3595 const char *filename
, unsigned int line_number
)
3597 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3599 tree type
= convert_in (type_in
);
3601 cst
= build_int_cst (type
, value
);
3602 if (!TYPE_READONLY (type
))
3603 type
= build_qualified_type (type
, TYPE_QUAL_CONST
);
3604 decl
= build_decl (ctx
->get_location_t (filename
, line_number
),
3605 VAR_DECL
, get_identifier (name
), type
);
3606 TREE_STATIC (decl
) = 1;
3607 TREE_READONLY (decl
) = 1;
3608 cp_finish_decl (decl
, cst
, true, NULL
, LOOKUP_ONLYCONVERTING
);
3609 safe_pushdecl_maybe_friend (decl
, false);
3615 plugin_error (cc1_plugin::connection
*,
3616 const char *message
)
3618 error ("%s", message
);
3619 return convert_out (error_mark_node
);
3623 plugin_add_static_assert (cc1_plugin::connection
*self
,
3624 gcc_expr condition_in
,
3625 const char *errormsg
,
3626 const char *filename
,
3627 unsigned int line_number
)
3629 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3630 tree condition
= convert_in (condition_in
);
3635 tree message
= build_string (strlen (errormsg
) + 1, errormsg
);
3637 TREE_TYPE (message
) = char_array_type_node
;
3638 fix_string_type (message
);
3640 location_t loc
= ctx
->get_location_t (filename
, line_number
);
3642 bool member_p
= at_class_scope_p ();
3644 finish_static_assert (condition
, message
, loc
, member_p
);
3651 // Perform GC marking.
3654 gc_mark (void *, void *)
3656 if (current_context
!= NULL
)
3657 current_context
->mark ();
3661 #pragma GCC visibility push(default)
3665 plugin_init (struct plugin_name_args
*plugin_info
,
3666 struct plugin_gcc_version
*)
3669 for (int i
= 0; i
< plugin_info
->argc
; ++i
)
3671 if (strcmp (plugin_info
->argv
[i
].key
, "fd") == 0)
3675 fd
= strtol (plugin_info
->argv
[i
].value
, &tail
, 0);
3676 if (*tail
!= '\0' || errno
!= 0)
3677 fatal_error (input_location
,
3678 "%s: invalid file descriptor argument to plugin",
3679 plugin_info
->base_name
);
3684 fatal_error (input_location
,
3685 "%s: required plugin argument %<fd%> is missing",
3686 plugin_info
->base_name
);
3688 current_context
= new plugin_context (fd
);
3691 cc1_plugin::protocol_int version
;
3692 if (!current_context
->require ('H')
3693 || ! ::cc1_plugin::unmarshall (current_context
, &version
))
3694 fatal_error (input_location
,
3695 "%s: handshake failed", plugin_info
->base_name
);
3696 if (version
!= GCC_CP_FE_VERSION_0
)
3697 fatal_error (input_location
,
3698 "%s: unknown version in handshake", plugin_info
->base_name
);
3700 register_callback (plugin_info
->base_name
, PLUGIN_PRAGMAS
,
3701 plugin_init_extra_pragmas
, NULL
);
3702 register_callback (plugin_info
->base_name
, PLUGIN_PRE_GENERICIZE
,
3703 rewrite_decls_to_addresses
, NULL
);
3704 register_callback (plugin_info
->base_name
, PLUGIN_GGC_MARKING
,
3707 lang_hooks
.print_error_function
= plugin_print_error_function
;
3709 #define GCC_METHOD0(R, N) \
3711 cc1_plugin::callback_ftype *fun \
3712 = cc1_plugin::callback<R, plugin_ ## N>; \
3713 current_context->add_callback (# N, fun); \
3715 #define GCC_METHOD1(R, N, A) \
3717 cc1_plugin::callback_ftype *fun \
3718 = cc1_plugin::callback<R, A, plugin_ ## N>; \
3719 current_context->add_callback (# N, fun); \
3721 #define GCC_METHOD2(R, N, A, B) \
3723 cc1_plugin::callback_ftype *fun \
3724 = cc1_plugin::callback<R, A, B, plugin_ ## N>; \
3725 current_context->add_callback (# N, fun); \
3727 #define GCC_METHOD3(R, N, A, B, C) \
3729 cc1_plugin::callback_ftype *fun \
3730 = cc1_plugin::callback<R, A, B, C, plugin_ ## N>; \
3731 current_context->add_callback (# N, fun); \
3733 #define GCC_METHOD4(R, N, A, B, C, D) \
3735 cc1_plugin::callback_ftype *fun \
3736 = cc1_plugin::callback<R, A, B, C, D, \
3738 current_context->add_callback (# N, fun); \
3740 #define GCC_METHOD5(R, N, A, B, C, D, E) \
3742 cc1_plugin::callback_ftype *fun \
3743 = cc1_plugin::callback<R, A, B, C, D, E, \
3745 current_context->add_callback (# N, fun); \
3747 #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
3749 cc1_plugin::callback_ftype *fun \
3750 = cc1_plugin::callback<R, A, B, C, D, E, F, G, \
3752 current_context->add_callback (# N, fun); \
3755 #include "gcc-cp-fe.def"