1 /* Library interface to C++ front end.
2 Copyright (C) 2014-2017 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 source_location
get_source_location (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 source_location 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
425 else if (maybe_remove_implicit_alias (bval
))
427 /* There was a mangling compatibility alias using this mangled name,
428 but now we have a real decl that wants to use it instead. */
429 binding
->value
= decl
;
433 // _1: diagnose_name_conflict (decl, bval);
437 gcc_assert (ok
); // _1: return ok;
441 reactivate_decl (tree decl
, cp_binding_level
*b
)
443 bool in_function_p
= TREE_CODE (b
->this_entity
) == FUNCTION_DECL
;
444 gcc_assert (in_function_p
445 || (b
== current_binding_level
446 && !at_class_scope_p ()));
448 tree id
= DECL_NAME (decl
);
449 tree type
= NULL_TREE
;
450 if (TREE_CODE (decl
) == TYPE_DECL
)
451 type
= TREE_TYPE (decl
);
453 if (type
&& TYPE_NAME (type
) == decl
454 && (RECORD_OR_UNION_CODE_P (TREE_CODE (type
))
455 || TREE_CODE (type
) == ENUMERAL_TYPE
))
457 gcc_assert (in_function_p
&& DECL_CONTEXT (decl
) == b
->this_entity
);
458 type
= TREE_TYPE (decl
);
462 gcc_assert (DECL_CONTEXT (decl
) == b
->this_entity
463 || DECL_CONTEXT (decl
) == global_namespace
464 || TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
);
468 /* Adjust IDENTIFIER_BINDING to what it would have been if we were
469 at binding level B. Save the binding chain up to that point in
470 [binding, *chainp), and take note of the outermost bindings found
472 cxx_binding
*binding
= IDENTIFIER_BINDING (id
), **chainp
= NULL
;
473 tree
*shadowing_type_p
= NULL
;
476 cp_binding_level
*bc
= current_binding_level
;
477 for (cxx_binding
*prev_binding
= binding
;
478 prev_binding
; prev_binding
= prev_binding
->previous
)
480 while (bc
!= b
&& bc
!= prev_binding
->scope
)
481 bc
= bc
->level_chain
;
488 chainp
= &prev_binding
->previous
;
490 for (tree tshadow
= prev_binding
->scope
->type_shadowed
;
491 tshadow
; tshadow
= TREE_CHAIN (tshadow
))
492 if (TREE_PURPOSE (tshadow
) == id
)
494 shadowing_type_p
= &TREE_VALUE (tshadow
);
501 IDENTIFIER_BINDING (id
) = *chainp
;
505 /* Like push_local_binding, supplement or add a binding to the
507 if (IDENTIFIER_BINDING (id
) && IDENTIFIER_BINDING (id
)->scope
== b
)
508 supplement_binding (IDENTIFIER_BINDING (id
), decl
);
510 push_binding (id
, decl
, b
);
512 /* Now restore the binding chain we'd temporarily removed. */
515 *chainp
= IDENTIFIER_BINDING (id
);
516 IDENTIFIER_BINDING (id
) = binding
;
520 /* Insert the new type binding in the shadowing_type_p
522 tree shadowed_type
= NULL_TREE
;
523 if (shadowing_type_p
)
525 shadowed_type
= *shadowing_type_p
;
526 *shadowing_type_p
= type
;
529 b
->type_shadowed
= tree_cons (id
, shadowed_type
, b
->type_shadowed
);
530 TREE_TYPE (b
->type_shadowed
) = type
;
535 /* Our new binding is the active one, so shadow the earlier
537 b
->type_shadowed
= tree_cons (id
, REAL_IDENTIFIER_TYPE_VALUE (id
),
539 TREE_TYPE (b
->type_shadowed
) = type
;
540 SET_IDENTIFIER_TYPE_VALUE (id
, type
);
543 /* Record that we have a binding for ID, like add_decl_to_level. */
544 tree node
= build_tree_list (NULL_TREE
, decl
);
545 TREE_CHAIN (node
) = b
->names
;
550 plugin_pragma_push_user_expression (cpp_reader
*)
555 gcc_assert (!current_class_ptr
);
556 gcc_assert (!current_class_ref
);
558 gcc_assert (!cp_binding_oracle
);
559 cp_binding_oracle
= plugin_binding_oracle
;
561 /* Make the function containing the user expression a global
562 friend, so as to bypass access controls in it. */
563 if (at_function_scope_p ())
564 set_global_friend (current_function_decl
);
566 gcc_assert (at_function_scope_p ());
567 function
*save_cfun
= cfun
;
568 cp_binding_level
*orig_binding_level
= current_binding_level
;
571 cc1_plugin::call (current_context
, "enter_scope", &success
);
573 gcc_assert (at_fake_function_scope_p () || at_function_scope_p ());
575 function
*unchanged_cfun
= cfun
;
576 tree changed_func_decl
= current_function_decl
;
578 gcc_assert (current_class_type
== DECL_CONTEXT (current_function_decl
)
579 || !(RECORD_OR_UNION_CODE_P
580 (TREE_CODE (DECL_CONTEXT (current_function_decl
)))));
581 push_fake_function (save_cfun
->decl
, sk_block
);
582 current_class_type
= NULL_TREE
;
585 /* If we get here, GDB did NOT change the context. */
586 gcc_assert (cfun
== save_cfun
);
587 gcc_assert (at_function_scope_p ());
588 gcc_assert (orig_binding_level
589 == current_binding_level
->level_chain
->level_chain
);
594 gcc_assert (at_function_scope_p ());
596 cp_binding_level
*b
= current_binding_level
->level_chain
;
597 gcc_assert (b
->this_entity
== cfun
->decl
);
599 /* Reactivate local names from the previous context. Use
600 IDENTIFIER_MARKED to avoid reactivating shadowed names. */
601 for (cp_binding_level
*level
= orig_binding_level
;;)
603 for (tree name
= level
->names
;
604 name
; name
= TREE_CHAIN (name
))
607 if (TREE_CODE (decl
) == TREE_LIST
)
608 decl
= TREE_VALUE (decl
);
609 if (IDENTIFIER_MARKED (DECL_NAME (decl
)))
611 IDENTIFIER_MARKED (DECL_NAME (decl
)) = 1;
612 reactivate_decl (decl
, b
);
614 if (level
->kind
== sk_function_parms
615 && level
->this_entity
== cfun
->decl
)
617 gcc_assert (!level
->this_entity
);
618 level
= level
->level_chain
;
621 /* Now, clear the markers. */
622 for (tree name
= b
->names
; name
; name
= TREE_CHAIN (name
))
625 if (TREE_CODE (decl
) == TREE_LIST
)
626 decl
= TREE_VALUE (decl
);
627 gcc_assert (IDENTIFIER_MARKED (DECL_NAME (decl
)));
628 IDENTIFIER_MARKED (DECL_NAME (decl
)) = 0;
632 if (unchanged_cfun
|| DECL_NONSTATIC_MEMBER_FUNCTION_P (changed_func_decl
))
634 /* Check whether the oracle supplies us with a "this", and if
635 so, arrange for data members and this itself to be
637 tree this_val
= lookup_name (get_identifier ("this"));
638 current_class_ref
= !this_val
? NULL_TREE
639 : cp_build_indirect_ref (this_val
, RO_NULL
, tf_warning_or_error
);
640 current_class_ptr
= this_val
;
645 plugin_pragma_pop_user_expression (cpp_reader
*)
650 gcc_assert (cp_binding_oracle
);
652 gcc_assert (at_function_scope_p ());
653 function
*save_cfun
= cfun
;
654 current_class_ptr
= NULL_TREE
;
655 current_class_ref
= NULL_TREE
;
659 if (RECORD_OR_UNION_CODE_P (TREE_CODE (DECL_CONTEXT (current_function_decl
))))
660 current_class_type
= DECL_CONTEXT (current_function_decl
);
663 cc1_plugin::call (current_context
, "leave_scope", &success
);
668 gcc_assert (cfun
== save_cfun
);
670 cp_binding_oracle
= NULL
;
671 gcc_assert (at_function_scope_p ());
675 plugin_init_extra_pragmas (void *, void *)
677 c_register_pragma ("GCC", "push_user_expression", plugin_pragma_push_user_expression
);
678 c_register_pragma ("GCC", "pop_user_expression", plugin_pragma_pop_user_expression
);
679 /* FIXME: this one should go once we get GDB to use push and pop. */
680 c_register_pragma ("GCC", "user_expression", plugin_pragma_push_user_expression
);
685 static decl_addr_value
686 build_decl_addr_value (tree decl
, gcc_address address
)
688 decl_addr_value value
= {
690 build_int_cst_type (ptr_type_node
, address
)
695 static decl_addr_value
*
696 record_decl_address (plugin_context
*ctx
, decl_addr_value value
)
698 decl_addr_value
**slot
= ctx
->address_map
.find_slot (&value
, INSERT
);
699 gcc_assert (*slot
== NULL
);
701 = static_cast<decl_addr_value
*> (xmalloc (sizeof (decl_addr_value
)));
703 /* We don't want GCC to warn about e.g. static functions
704 without a code definition. */
705 TREE_NO_WARNING (value
.decl
) = 1;
709 // Maybe rewrite a decl to its address.
711 address_rewriter (tree
*in
, int *walk_subtrees
, void *arg
)
713 plugin_context
*ctx
= (plugin_context
*) arg
;
716 || TREE_CODE (*in
) == NAMESPACE_DECL
717 || DECL_NAME (*in
) == NULL_TREE
)
720 decl_addr_value value
;
722 decl_addr_value
*found_value
= ctx
->address_map
.find (&value
);
723 if (found_value
!= NULL
)
725 else if (HAS_DECL_ASSEMBLER_NAME_P (*in
))
729 if (!cc1_plugin::call (ctx
, "address_oracle", &address
,
730 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (*in
))))
735 // Insert the decl into the address map in case it is referenced
737 value
= build_decl_addr_value (value
.decl
, address
);
738 found_value
= record_decl_address (ctx
, value
);
743 if (found_value
->address
!= error_mark_node
)
745 // We have an address for the decl, so rewrite the tree.
746 tree ptr_type
= build_pointer_type (TREE_TYPE (*in
));
747 *in
= fold_build1 (INDIRECT_REF
, TREE_TYPE (*in
),
748 fold_build1 (CONVERT_EXPR
, ptr_type
,
749 found_value
->address
));
757 // When generating code for gdb, we want to be able to use absolute
758 // addresses to refer to otherwise external objects that gdb knows
759 // about. gdb passes in these addresses when building decls, and then
760 // before gimplification we go through the trees, rewriting uses to
761 // the equivalent of "*(TYPE *) ADDR".
763 rewrite_decls_to_addresses (void *function_in
, void *)
765 tree function
= (tree
) function_in
;
767 // Do nothing if we're not in gdb.
768 if (current_context
== NULL
)
771 walk_tree (&DECL_SAVED_TREE (function
), address_rewriter
, current_context
,
778 safe_push_template_decl (tree decl
)
780 void (*save_oracle
) (enum cp_oracle_request
, tree identifier
);
782 save_oracle
= cp_binding_oracle
;
783 cp_binding_oracle
= NULL
;
785 tree ret
= push_template_decl (decl
);
787 cp_binding_oracle
= save_oracle
;
793 safe_pushtag (tree name
, tree type
, tag_scope scope
)
795 void (*save_oracle
) (enum cp_oracle_request
, tree identifier
);
797 save_oracle
= cp_binding_oracle
;
798 cp_binding_oracle
= NULL
;
800 tree ret
= pushtag (name
, type
, scope
);
802 cp_binding_oracle
= save_oracle
;
808 safe_pushdecl_maybe_friend (tree decl
, bool is_friend
)
810 void (*save_oracle
) (enum cp_oracle_request
, tree identifier
);
812 save_oracle
= cp_binding_oracle
;
813 cp_binding_oracle
= NULL
;
815 tree ret
= pushdecl (decl
, is_friend
);
817 cp_binding_oracle
= save_oracle
;
825 plugin_push_namespace (cc1_plugin::connection
*,
829 push_to_top_level ();
831 push_namespace (name
? get_identifier (name
) : NULL
);
837 plugin_push_class (cc1_plugin::connection
*,
840 tree type
= convert_in (type_in
);
841 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (type
)));
842 gcc_assert (TYPE_CONTEXT (type
) == FROB_CONTEXT (current_scope ()));
850 plugin_push_function (cc1_plugin::connection
*,
851 gcc_decl function_decl_in
)
853 tree fndecl
= convert_in (function_decl_in
);
854 gcc_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
);
855 gcc_assert (DECL_CONTEXT (fndecl
) == FROB_CONTEXT (current_scope ()));
857 push_fake_function (fndecl
);
863 plugin_pop_binding_level (cc1_plugin::connection
*)
870 plugin_reactivate_decl (cc1_plugin::connection
*,
874 tree decl
= convert_in (decl_in
);
875 tree scope
= convert_in (scope_in
);
876 gcc_assert (TREE_CODE (decl
) == VAR_DECL
877 || TREE_CODE (decl
) == FUNCTION_DECL
878 || TREE_CODE (decl
) == TYPE_DECL
);
882 gcc_assert (TREE_CODE (scope
) == FUNCTION_DECL
);
883 for (b
= current_binding_level
;
884 b
->this_entity
!= scope
;
886 gcc_assert (b
->this_entity
!= global_namespace
);
890 gcc_assert (!at_class_scope_p ());
891 b
= current_binding_level
;
894 reactivate_decl (decl
, b
);
903 if (at_namespace_scope_p ())
904 decl
= current_namespace
;
905 else if (at_class_scope_p ())
906 decl
= TYPE_NAME (current_class_type
);
907 else if (at_fake_function_scope_p () || at_function_scope_p ())
908 decl
= current_function_decl
;
916 plugin_get_current_binding_level_decl (cc1_plugin::connection
*)
918 tree decl
= get_current_scope ();
920 return convert_out (decl
);
924 plugin_make_namespace_inline (cc1_plugin::connection
*)
926 tree inline_ns
= current_namespace
;
928 gcc_assert (toplevel_bindings_p ());
929 gcc_assert (inline_ns
!= global_namespace
);
931 tree parent_ns
= CP_DECL_CONTEXT (inline_ns
);
933 if (DECL_NAMESPACE_INLINE_P (inline_ns
))
936 DECL_NAMESPACE_INLINE_P (inline_ns
) = true;
937 vec_safe_push (DECL_NAMESPACE_INLINEES (parent_ns
), inline_ns
);
943 plugin_add_using_namespace (cc1_plugin::connection
*,
946 tree used_ns
= convert_in (used_ns_in
);
948 gcc_assert (TREE_CODE (used_ns
) == NAMESPACE_DECL
);
950 finish_namespace_using_directive (used_ns
, NULL_TREE
);
956 plugin_add_namespace_alias (cc1_plugin::connection
*,
960 tree name
= get_identifier (id
);
961 tree target
= convert_in (target_in
);
963 do_namespace_alias (name
, target
);
969 set_access_flags (tree decl
, enum gcc_cp_symbol_kind flags
)
971 gcc_assert (!(flags
& GCC_CP_ACCESS_MASK
) == !DECL_CLASS_SCOPE_P (decl
));
973 switch (flags
& GCC_CP_ACCESS_MASK
)
975 case GCC_CP_ACCESS_PRIVATE
:
976 TREE_PRIVATE (decl
) = true;
977 current_access_specifier
= access_private_node
;
980 case GCC_CP_ACCESS_PROTECTED
:
981 TREE_PROTECTED (decl
) = true;
982 current_access_specifier
= access_protected_node
;
985 case GCC_CP_ACCESS_PUBLIC
:
986 current_access_specifier
= access_public_node
;
995 plugin_add_using_decl (cc1_plugin::connection
*,
996 enum gcc_cp_symbol_kind flags
,
999 tree target
= convert_in (target_in
);
1000 gcc_assert ((flags
& GCC_CP_SYMBOL_MASK
) == GCC_CP_SYMBOL_USING
);
1001 gcc_assert (!(flags
& GCC_CP_FLAG_MASK
));
1002 enum gcc_cp_symbol_kind acc_flags
;
1003 acc_flags
= (enum gcc_cp_symbol_kind
) (flags
& GCC_CP_ACCESS_MASK
);
1005 gcc_assert (!template_parm_scope_p ());
1007 bool class_member_p
= at_class_scope_p ();
1008 gcc_assert (!(acc_flags
& GCC_CP_ACCESS_MASK
) == !class_member_p
);
1010 tree identifier
= DECL_NAME (target
);
1011 tree tcontext
= DECL_CONTEXT (target
);
1013 if (UNSCOPED_ENUM_P (tcontext
))
1014 tcontext
= CP_TYPE_CONTEXT (tcontext
);
1018 tree decl
= do_class_using_decl (tcontext
, identifier
);
1020 set_access_flags (decl
, flags
);
1022 finish_member_declaration (decl
);
1026 /* We can't be at local scope. */
1027 gcc_assert (at_namespace_scope_p ());
1028 finish_namespace_using_decl (target
, tcontext
, identifier
);
1035 build_named_class_type (enum tree_code code
,
1037 source_location loc
)
1039 /* See at_fake_function_scope_p. */
1040 gcc_assert (!at_function_scope_p ());
1041 tree type
= make_class_type (code
);
1042 tree type_decl
= build_decl (loc
, TYPE_DECL
, id
, type
);
1043 TYPE_NAME (type
) = type_decl
;
1044 TYPE_STUB_DECL (type
) = type_decl
;
1045 DECL_CONTEXT (type_decl
) = TYPE_CONTEXT (type
);
1050 /* Abuse an unused field of the dummy template parms entry to hold the
1052 #define TP_PARM_LIST TREE_TYPE (current_template_parms)
1055 plugin_build_decl (cc1_plugin::connection
*self
,
1057 enum gcc_cp_symbol_kind sym_kind
,
1058 gcc_type sym_type_in
,
1059 const char *substitution_name
,
1060 gcc_address address
,
1061 const char *filename
,
1062 unsigned int line_number
)
1064 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1065 gcc_assert (!name
|| !strchr (name
, ':')); // FIXME: this can go eventually.
1067 enum tree_code code
;
1069 tree sym_type
= convert_in (sym_type_in
);
1070 enum gcc_cp_symbol_kind sym_flags
;
1071 sym_flags
= (enum gcc_cp_symbol_kind
) (sym_kind
& GCC_CP_FLAG_MASK
);
1072 enum gcc_cp_symbol_kind acc_flags
;
1073 acc_flags
= (enum gcc_cp_symbol_kind
) (sym_kind
& GCC_CP_ACCESS_MASK
);
1074 sym_kind
= (enum gcc_cp_symbol_kind
) (sym_kind
& GCC_CP_SYMBOL_MASK
);
1078 case GCC_CP_SYMBOL_FUNCTION
:
1079 code
= FUNCTION_DECL
;
1080 gcc_assert (!(sym_flags
& ~GCC_CP_FLAG_MASK_FUNCTION
));
1083 case GCC_CP_SYMBOL_VARIABLE
:
1085 gcc_assert (!(sym_flags
& ~GCC_CP_FLAG_MASK_VARIABLE
));
1088 case GCC_CP_SYMBOL_TYPEDEF
:
1090 gcc_assert (!sym_flags
);
1093 case GCC_CP_SYMBOL_CLASS
:
1095 gcc_assert (!(sym_flags
& ~GCC_CP_FLAG_MASK_CLASS
));
1096 gcc_assert (!sym_type
);
1099 case GCC_CP_SYMBOL_UNION
:
1101 gcc_assert (!sym_flags
);
1102 gcc_assert (!sym_type
);
1109 bool template_decl_p
= template_parm_scope_p ();
1111 if (template_decl_p
)
1113 gcc_assert (code
== FUNCTION_DECL
|| code
== RECORD_TYPE
1114 || code
== TYPE_DECL
);
1116 /* Finish the template parm list that started this template parm. */
1117 end_template_parm_list (TP_PARM_LIST
);
1119 gcc_assert (!address
);
1120 gcc_assert (!substitution_name
);
1123 source_location loc
= ctx
->get_source_location (filename
, line_number
);
1124 bool class_member_p
= at_class_scope_p ();
1125 bool ctor
= false, dtor
= false, assop
= false;
1126 tree_code opcode
= ERROR_MARK
;
1128 gcc_assert (!(acc_flags
& GCC_CP_ACCESS_MASK
) == !class_member_p
);
1131 if (code
!= FUNCTION_DECL
1132 || !(sym_flags
& GCC_CP_FLAG_SPECIAL_FUNCTION
))
1135 identifier
= get_identifier (name
);
1138 gcc_assert (RECORD_OR_UNION_CODE_P (code
));
1139 identifier
= make_anon_name ();
1143 if (code
== FUNCTION_DECL
)
1145 if (sym_flags
& GCC_CP_FLAG_SPECIAL_FUNCTION
)
1147 #define CHARS2(f,s) (((unsigned char)f << CHAR_BIT) | (unsigned char)s)
1148 switch (CHARS2 (name
[0], name
[1]))
1150 case CHARS2 ('C', 0x0): // ctor base declaration
1151 case CHARS2 ('C', ' '):
1152 case CHARS2 ('C', '1'):
1153 case CHARS2 ('C', '2'):
1154 case CHARS2 ('C', '4'):
1157 gcc_assert (!address
);
1158 gcc_assert (!substitution_name
);
1159 identifier
= DECL_NAME (TYPE_NAME (current_class_type
));
1161 case CHARS2 ('D', 0x0): // dtor base declaration
1162 case CHARS2 ('D', ' '):
1163 case CHARS2 ('D', '0'):
1164 case CHARS2 ('D', '1'):
1165 case CHARS2 ('D', '2'):
1166 case CHARS2 ('D', '4'):
1167 gcc_assert (!template_decl_p
);
1170 case CHARS2 ('n', 'w'): // operator new
1173 case CHARS2 ('n', 'a'): // operator new[]
1174 opcode
= VEC_NEW_EXPR
;
1176 case CHARS2 ('d', 'l'): // operator delete
1177 opcode
= DELETE_EXPR
;
1179 case CHARS2 ('d', 'a'): // operator delete[]
1180 opcode
= VEC_DELETE_EXPR
;
1182 case CHARS2 ('p', 's'): // operator + (unary)
1185 case CHARS2 ('n', 'g'): // operator - (unary)
1186 opcode
= MINUS_EXPR
;
1188 case CHARS2 ('a', 'd'): // operator & (unary)
1189 opcode
= BIT_AND_EXPR
;
1191 case CHARS2 ('d', 'e'): // operator * (unary)
1194 case CHARS2 ('c', 'o'): // operator ~
1195 opcode
= BIT_NOT_EXPR
;
1197 case CHARS2 ('p', 'l'): // operator +
1200 case CHARS2 ('m', 'i'): // operator -
1201 opcode
= MINUS_EXPR
;
1203 case CHARS2 ('m', 'l'): // operator *
1206 case CHARS2 ('d', 'v'): // operator /
1207 opcode
= TRUNC_DIV_EXPR
;
1209 case CHARS2 ('r', 'm'): // operator %
1210 opcode
= TRUNC_MOD_EXPR
;
1212 case CHARS2 ('a', 'n'): // operator &
1213 opcode
= BIT_AND_EXPR
;
1215 case CHARS2 ('o', 'r'): // operator |
1216 opcode
= BIT_IOR_EXPR
;
1218 case CHARS2 ('e', 'o'): // operator ^
1219 opcode
= BIT_XOR_EXPR
;
1221 case CHARS2 ('a', 'S'): // operator =
1225 case CHARS2 ('p', 'L'): // operator +=
1229 case CHARS2 ('m', 'I'): // operator -=
1230 opcode
= MINUS_EXPR
;
1233 case CHARS2 ('m', 'L'): // operator *=
1237 case CHARS2 ('d', 'V'): // operator /=
1238 opcode
= TRUNC_DIV_EXPR
;
1241 case CHARS2 ('r', 'M'): // operator %=
1242 opcode
= TRUNC_MOD_EXPR
;
1245 case CHARS2 ('a', 'N'): // operator &=
1246 opcode
= BIT_AND_EXPR
;
1249 case CHARS2 ('o', 'R'): // operator |=
1250 opcode
= BIT_IOR_EXPR
;
1253 case CHARS2 ('e', 'O'): // operator ^=
1254 opcode
= BIT_XOR_EXPR
;
1257 case CHARS2 ('l', 's'): // operator <<
1258 opcode
= LSHIFT_EXPR
;
1260 case CHARS2 ('r', 's'): // operator >>
1261 opcode
= RSHIFT_EXPR
;
1263 case CHARS2 ('l', 'S'): // operator <<=
1264 opcode
= LSHIFT_EXPR
;
1267 case CHARS2 ('r', 'S'): // operator >>=
1268 opcode
= RSHIFT_EXPR
;
1271 case CHARS2 ('e', 'q'): // operator ==
1274 case CHARS2 ('n', 'e'): // operator !=
1277 case CHARS2 ('l', 't'): // operator <
1280 case CHARS2 ('g', 't'): // operator >
1283 case CHARS2 ('l', 'e'): // operator <=
1286 case CHARS2 ('g', 'e'): // operator >=
1289 case CHARS2 ('n', 't'): // operator !
1290 opcode
= TRUTH_NOT_EXPR
;
1292 case CHARS2 ('a', 'a'): // operator &&
1293 opcode
= TRUTH_ANDIF_EXPR
;
1295 case CHARS2 ('o', 'o'): // operator ||
1296 opcode
= TRUTH_ORIF_EXPR
;
1298 case CHARS2 ('p', 'p'): // operator ++
1299 opcode
= POSTINCREMENT_EXPR
;
1301 case CHARS2 ('m', 'm'): // operator --
1302 /* This stands for either one as an operator name, and
1303 "pp" and "mm" stand for POST??CREMENT, but for some
1304 reason the parser uses this opcode name for
1305 operator--; let's follow their practice. */
1306 opcode
= PREDECREMENT_EXPR
;
1308 case CHARS2 ('c', 'm'): // operator ,
1309 opcode
= COMPOUND_EXPR
;
1311 case CHARS2 ('p', 'm'): // operator ->*
1312 opcode
= MEMBER_REF
;
1314 case CHARS2 ('p', 't'): // operator ->
1315 opcode
= COMPONENT_REF
;
1317 case CHARS2 ('c', 'l'): // operator ()
1320 case CHARS2 ('i', 'x'): // operator []
1323 case CHARS2 ('c', 'v'): // operator <T> (conversion operator)
1324 identifier
= mangle_conv_op_name_for_type (TREE_TYPE (sym_type
));
1327 case CHARS2 ('l', 'i'): // operator "" <id>
1329 char *id
= (char *)name
+ 2;
1330 bool freeid
= false;
1331 if (*id
>= '0' && *id
<= '9')
1340 while (*id
&& *id
>= '0' && *id
<= '9');
1341 id
= xstrndup (id
, len
);
1344 identifier
= cp_literal_operator_id (id
);
1349 case CHARS2 ('q', 'u'): // ternary operator, not overloadable.
1354 if (opcode
!= ERROR_MARK
)
1357 identifier
= cp_assignment_operator_id (opcode
);
1359 identifier
= cp_operator_id (opcode
);
1362 decl
= build_lang_decl_loc (loc
, code
, identifier
, sym_type
);
1363 /* FIXME: current_lang_name is lang_name_c while compiling an
1364 extern "C" function, and we haven't switched to a global
1365 context at this point, and this breaks function
1367 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
1368 if (TREE_CODE (sym_type
) == METHOD_TYPE
)
1369 DECL_ARGUMENTS (decl
) = build_this_parm (current_class_type
,
1370 cp_type_quals (sym_type
));
1371 for (tree arg
= TREE_CODE (sym_type
) == METHOD_TYPE
1372 ? TREE_CHAIN (TYPE_ARG_TYPES (sym_type
))
1373 : TYPE_ARG_TYPES (sym_type
);
1374 arg
&& arg
!= void_list_node
;
1375 arg
= TREE_CHAIN (arg
))
1377 tree parm
= cp_build_parm_decl (NULL_TREE
, TREE_VALUE (arg
));
1378 DECL_CHAIN (parm
) = DECL_ARGUMENTS (decl
);
1379 DECL_ARGUMENTS (decl
) = parm
;
1381 DECL_ARGUMENTS (decl
) = nreverse (DECL_ARGUMENTS (decl
));
1384 if (TREE_CODE (sym_type
) == FUNCTION_TYPE
)
1385 DECL_STATIC_FUNCTION_P (decl
) = 1;
1386 if (sym_flags
& GCC_CP_FLAG_VIRTUAL_FUNCTION
)
1388 DECL_VIRTUAL_P (decl
) = 1;
1389 if (sym_flags
& GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION
)
1390 DECL_PURE_VIRTUAL_P (decl
) = 1;
1391 if (sym_flags
& GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION
)
1392 DECL_FINAL_P (decl
) = 1;
1395 gcc_assert (!(sym_flags
& (GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION
1396 | GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION
)));
1400 gcc_assert (!(sym_flags
& (GCC_CP_FLAG_VIRTUAL_FUNCTION
1401 | GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION
1402 | GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION
)));
1403 gcc_assert (!ctor
&& !dtor
&& !assop
);
1405 if (sym_flags
& GCC_CP_FLAG_EXPLICIT_FUNCTION
)
1406 DECL_NONCONVERTING_P (decl
) = 1;
1407 if (sym_flags
& GCC_CP_FLAG_DEFAULTED_FUNCTION
)
1409 DECL_INITIAL (decl
) = ridpointers
[(int)RID_DEFAULT
];
1410 DECL_DEFAULTED_FN (decl
) = 1;
1412 if (sym_flags
& GCC_CP_FLAG_DELETED_FUNCTION
)
1414 // DECL_INITIAL (decl) = ridpointers[(int)RID_DELETE];
1415 DECL_DELETED_FN (decl
) = 1;
1416 DECL_DECLARED_INLINE_P (decl
) = 1;
1417 DECL_INITIAL (decl
) = error_mark_node
;
1422 DECL_CONSTRUCTOR_P (decl
) = 1;
1424 DECL_DESTRUCTOR_P (decl
) = 1;
1428 if ((sym_flags
& GCC_CP_FLAG_SPECIAL_FUNCTION
)
1429 && opcode
!= ERROR_MARK
)
1430 SET_OVERLOADED_OPERATOR_CODE (decl
, opcode
);
1432 DECL_ASSIGNMENT_OPERATOR_P (decl
) = true;
1435 else if (RECORD_OR_UNION_CODE_P (code
))
1437 decl
= build_named_class_type (code
, identifier
, loc
);
1438 tree type
= TREE_TYPE (decl
);
1440 if (code
== RECORD_TYPE
1441 && !(sym_flags
& GCC_CP_FLAG_CLASS_IS_STRUCT
))
1442 CLASSTYPE_DECLARED_CLASS (type
) = true;
1444 else if (class_member_p
)
1446 decl
= build_lang_decl_loc (loc
, code
, identifier
, sym_type
);
1448 if (TREE_CODE (decl
) == VAR_DECL
)
1450 DECL_THIS_STATIC (decl
) = 1;
1451 // The remainder of this block does the same as:
1452 // set_linkage_for_static_data_member (decl);
1453 TREE_PUBLIC (decl
) = 1;
1454 TREE_STATIC (decl
) = 1;
1455 DECL_INTERFACE_KNOWN (decl
) = 1;
1457 // FIXME: sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
1458 gcc_assert (!(sym_flags
& GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
));
1460 if (sym_flags
& GCC_CP_FLAG_CONSTEXPR_VARIABLE
)
1461 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
1466 decl
= build_decl (loc
, code
, identifier
, sym_type
);
1468 if (TREE_CODE (decl
) == VAR_DECL
)
1470 // FIXME: sym_flags & GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
1471 gcc_assert (!(sym_flags
& GCC_CP_FLAG_THREAD_LOCAL_VARIABLE
));
1473 if (sym_flags
& GCC_CP_FLAG_CONSTEXPR_VARIABLE
)
1474 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
1477 TREE_USED (decl
) = 1;
1478 TREE_ADDRESSABLE (decl
) = 1;
1481 DECL_CONTEXT (decl
) = FROB_CONTEXT (current_class_type
);
1482 else if (at_namespace_scope_p ())
1483 DECL_CONTEXT (decl
) = FROB_CONTEXT (current_decl_namespace ());
1485 set_access_flags (decl
, acc_flags
);
1487 /* If this is the typedef that names an otherwise anonymous type,
1488 propagate the typedef name to the type. In normal compilation,
1489 this is done in grokdeclarator. */
1490 if (sym_kind
== GCC_CP_SYMBOL_TYPEDEF
1492 && DECL_CONTEXT (decl
) == TYPE_CONTEXT (sym_type
)
1493 && TYPE_UNNAMED_P (sym_type
))
1494 name_unnamed_type (sym_type
, decl
);
1496 if (sym_kind
!= GCC_CP_SYMBOL_TYPEDEF
1497 && sym_kind
!= GCC_CP_SYMBOL_CLASS
1498 && sym_kind
!= GCC_CP_SYMBOL_UNION
1499 && !template_decl_p
&& !ctor
&& !dtor
)
1501 decl_addr_value value
;
1503 DECL_EXTERNAL (decl
) = 1;
1505 if (substitution_name
!= NULL
)
1507 // If the translator gave us a name without a binding,
1508 // we can just substitute error_mark_node, since we know the
1509 // translator will be reporting an error anyhow.
1511 = lookup_name (get_identifier (substitution_name
));
1512 if (value
.address
== NULL_TREE
)
1513 value
.address
= error_mark_node
;
1516 value
.address
= build_int_cst_type (ptr_type_node
, address
);
1518 value
.address
= NULL
;
1520 record_decl_address (ctx
, value
);
1523 if (class_member_p
&& code
== FUNCTION_DECL
)
1526 maybe_retrofit_in_chrg (decl
);
1528 grok_special_member_properties (decl
);
1531 if (template_decl_p
)
1533 if (RECORD_OR_UNION_CODE_P (code
))
1534 safe_pushtag (identifier
, TREE_TYPE (decl
), ts_current
);
1536 decl
= safe_push_template_decl (decl
);
1538 tree tdecl
= NULL_TREE
;
1540 tdecl
= finish_member_template_decl (decl
);
1542 end_template_decl ();
1544 /* We only support one level of templates, because we only
1545 support declaring generics; actual definitions are only of
1547 gcc_assert (!template_parm_scope_p ());
1550 finish_member_declaration (tdecl
);
1552 else if (RECORD_OR_UNION_CODE_P (code
))
1553 safe_pushtag (identifier
, TREE_TYPE (decl
), ts_current
);
1554 else if (class_member_p
)
1555 finish_member_declaration (decl
);
1557 decl
= safe_pushdecl_maybe_friend (decl
, false);
1560 /* Don't crash after a duplicate declaration of a cdtor. */
1561 && TYPE_METHODS (current_class_type
) == decl
)
1563 /* ctors and dtors clones are chained after DECL.
1564 However, we create the clones before TYPE_METHODS is
1565 reversed. We test for cloned methods after reversal,
1566 however, and the test requires the clones to follow
1567 DECL. So, we reverse the chain of clones now, so
1568 that it will come out in the right order after
1570 tree save
= DECL_CHAIN (decl
);
1571 DECL_CHAIN (decl
) = NULL_TREE
;
1572 clone_function_decl (decl
, /*update_methods=*/true);
1573 gcc_assert (TYPE_METHODS (current_class_type
) == decl
);
1574 TYPE_METHODS (current_class_type
)
1575 = nreverse (TYPE_METHODS (current_class_type
));
1576 DECL_CHAIN (decl
) = save
;
1579 rest_of_decl_compilation (decl
, toplevel_bindings_p (), 0);
1581 return convert_out (ctx
->preserve (decl
));
1585 plugin_define_cdtor_clone (cc1_plugin::connection
*self
,
1588 gcc_address address
)
1590 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1591 tree decl
= convert_in (cdtor_in
);
1596 switch (CHARS2 (name
[0], name
[1]))
1598 case CHARS2 ('C', '1'): // in-charge constructor
1599 identifier
= complete_ctor_identifier
;
1602 case CHARS2 ('C', '2'): // not-in-charge constructor
1603 identifier
= base_ctor_identifier
;
1606 case CHARS2 ('C', '4'):
1607 identifier
= ctor_identifier
; // unified constructor
1610 case CHARS2 ('D', '0'): // deleting destructor
1611 identifier
= deleting_dtor_identifier
;
1614 case CHARS2 ('D', '1'): // in-charge destructor
1615 identifier
= complete_dtor_identifier
;
1618 case CHARS2 ('D', '2'): // not-in-charge destructor
1619 identifier
= base_dtor_identifier
;
1622 case CHARS2 ('D', '4'):
1623 identifier
= dtor_identifier
; // unified destructor
1631 gcc_assert (!ctor
!= !dtor
);
1633 ? (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl
)
1634 && DECL_NAME (decl
) == ctor_identifier
)
1635 : (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl
)
1636 && DECL_NAME (decl
) == dtor_identifier
));
1638 while (decl
&& DECL_NAME (decl
) != identifier
)
1640 decl
= DECL_CHAIN (decl
);
1641 if (decl
&& !DECL_CLONED_FUNCTION_P (decl
))
1646 record_decl_address (ctx
, build_decl_addr_value (decl
, address
));
1648 return convert_out (decl
);
1652 plugin_add_friend (cc1_plugin::connection
* /* self */,
1656 tree decl
= convert_in (decl_in
);
1657 tree type
= convert_in (type_in
);
1659 gcc_assert (type
|| at_class_scope_p ());
1662 type
= current_class_type
;
1664 gcc_assert (TREE_CODE (type
) == RECORD_TYPE
);
1667 make_friend_class (type
, TREE_TYPE (decl
), true);
1670 DECL_FRIEND_P (decl
) = true;
1671 add_friend (type
, decl
, true);
1678 plugin_build_pointer_type (cc1_plugin::connection
*,
1681 // No need to preserve a pointer type as the base type is preserved.
1682 return convert_out (build_pointer_type (convert_in (base_type
)));
1686 plugin_build_reference_type (cc1_plugin::connection
*,
1687 gcc_type base_type_in
,
1688 enum gcc_cp_ref_qualifiers rquals
)
1694 case GCC_CP_REF_QUAL_LVALUE
:
1697 case GCC_CP_REF_QUAL_RVALUE
:
1700 case GCC_CP_REF_QUAL_NONE
:
1705 tree rtype
= cp_build_reference_type (convert_in (base_type_in
), rval
);
1707 return convert_out (rtype
);
1711 start_class_def (tree type
,
1712 const gcc_vbase_array
*base_classes
)
1717 for (int i
= 0; i
< base_classes
->n_elements
; i
++)
1721 gcc_assert ((base_classes
->flags
[i
] & GCC_CP_SYMBOL_MASK
)
1722 == GCC_CP_SYMBOL_BASECLASS
);
1724 switch (base_classes
->flags
[i
] & GCC_CP_ACCESS_MASK
)
1726 case GCC_CP_ACCESS_PRIVATE
:
1727 access
= ridpointers
[(int)RID_PRIVATE
];
1730 case GCC_CP_ACCESS_PROTECTED
:
1731 access
= ridpointers
[(int)RID_PROTECTED
];
1734 case GCC_CP_ACCESS_PUBLIC
:
1735 access
= ridpointers
[(int)RID_PUBLIC
];
1742 tree base
= finish_base_specifier
1743 (convert_in (base_classes
->elements
[i
]), access
,
1744 (base_classes
->flags
[i
] & GCC_CP_FLAG_BASECLASS_VIRTUAL
) != 0);
1745 TREE_CHAIN (base
) = bases
;
1748 bases
= nreverse (bases
);
1750 xref_basetypes (type
, bases
);
1751 begin_class_definition (type
);
1756 plugin_start_class_type (cc1_plugin::connection
*self
,
1757 gcc_decl typedecl_in
,
1758 const gcc_vbase_array
*base_classes
,
1759 const char *filename
,
1760 unsigned int line_number
)
1762 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1763 source_location loc
= ctx
->get_source_location (filename
, line_number
);
1764 tree typedecl
= convert_in (typedecl_in
);
1765 tree type
= TREE_TYPE (typedecl
);
1767 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (type
)));
1768 gcc_assert (!COMPLETE_TYPE_P (type
));
1770 DECL_SOURCE_LOCATION (typedecl
) = loc
;
1772 tree result
= start_class_def (type
, base_classes
);
1774 return convert_out (ctx
->preserve (result
));
1778 plugin_start_closure_class_type (cc1_plugin::connection
*self
,
1780 gcc_decl extra_scope_in
,
1781 enum gcc_cp_symbol_kind flags
,
1782 const char *filename
,
1783 unsigned int line_number
)
1785 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1786 tree extra_scope
= convert_in (extra_scope_in
);
1788 gcc_assert ((flags
& GCC_CP_SYMBOL_MASK
) == GCC_CP_SYMBOL_LAMBDA_CLOSURE
);
1789 gcc_assert ((flags
& (~(GCC_CP_SYMBOL_MASK
| GCC_CP_ACCESS_MASK
))) == 0);
1791 gcc_assert (!(flags
& GCC_CP_ACCESS_MASK
) == !at_class_scope_p ());
1793 /* See at_fake_function_scope_p. */
1794 gcc_assert (!at_function_scope_p ());
1798 if (TREE_CODE (extra_scope
) == PARM_DECL
)
1800 gcc_assert (at_fake_function_scope_p ());
1801 /* Check that the given extra_scope is one of the parameters of
1802 the current function. */
1803 for (tree parm
= DECL_ARGUMENTS (current_function_decl
);
1804 ; parm
= DECL_CHAIN (parm
))
1807 if (parm
== extra_scope
)
1811 else if (TREE_CODE (extra_scope
) == FIELD_DECL
)
1813 gcc_assert (at_class_scope_p ());
1814 gcc_assert (DECL_CONTEXT (extra_scope
) == current_class_type
);
1817 /* FIXME: does this ever really occur? */
1818 gcc_assert (TREE_CODE (extra_scope
) == VAR_DECL
);
1821 tree lambda_expr
= build_lambda_expr ();
1823 LAMBDA_EXPR_LOCATION (lambda_expr
) = ctx
->get_source_location (filename
,
1826 tree type
= begin_lambda_type (lambda_expr
);
1828 /* Instead of calling record_lambda_scope, do this: */
1829 LAMBDA_EXPR_EXTRA_SCOPE (lambda_expr
) = extra_scope
;
1830 LAMBDA_EXPR_DISCRIMINATOR (lambda_expr
) = discriminator
;
1832 tree decl
= TYPE_NAME (type
);
1833 determine_visibility (decl
);
1834 set_access_flags (decl
, flags
);
1836 return convert_out (ctx
->preserve (type
));
1840 plugin_build_lambda_expr (cc1_plugin::connection
*self
,
1841 gcc_type closure_type_in
)
1843 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1844 tree closure_type
= convert_in (closure_type_in
);
1846 gcc_assert (LAMBDA_TYPE_P (closure_type
));
1848 tree lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure_type
);
1850 tree lambda_object
= build_lambda_object (lambda_expr
);
1852 return convert_out (ctx
->preserve (lambda_object
));
1856 plugin_build_field (cc1_plugin::connection
*,
1857 const char *field_name
,
1858 gcc_type field_type_in
,
1859 enum gcc_cp_symbol_kind flags
,
1860 unsigned long bitsize
,
1861 unsigned long bitpos
)
1863 tree record_or_union_type
= current_class_type
;
1864 tree field_type
= convert_in (field_type_in
);
1866 gcc_assert (at_class_scope_p ());
1867 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (record_or_union_type
)));
1868 gcc_assert ((flags
& GCC_CP_SYMBOL_MASK
) == GCC_CP_SYMBOL_FIELD
);
1869 gcc_assert ((flags
& (~(GCC_CP_SYMBOL_MASK
| GCC_CP_ACCESS_MASK
1870 | GCC_CP_FLAG_MASK_FIELD
))) == 0);
1871 gcc_assert ((flags
& GCC_CP_ACCESS_MASK
));
1873 /* Note that gdb does not preserve the location of field decls, so
1874 we can't provide a decent location here. */
1875 tree decl
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
,
1876 get_identifier (field_name
), field_type
);
1877 DECL_FIELD_CONTEXT (decl
) = record_or_union_type
;
1879 set_access_flags (decl
, flags
);
1881 if ((flags
& GCC_CP_FLAG_FIELD_MUTABLE
) != 0)
1882 DECL_MUTABLE_P (decl
) = 1;
1884 if (TREE_CODE (field_type
) == INTEGER_TYPE
1885 && TYPE_PRECISION (field_type
) != bitsize
)
1887 DECL_BIT_FIELD_TYPE (decl
) = field_type
;
1889 = c_build_bitfield_integer_type (bitsize
, TYPE_UNSIGNED (field_type
));
1892 DECL_MODE (decl
) = TYPE_MODE (TREE_TYPE (decl
));
1894 // There's no way to recover this from DWARF.
1895 SET_DECL_OFFSET_ALIGN (decl
, TYPE_PRECISION (pointer_sized_int_node
));
1897 tree pos
= bitsize_int (bitpos
);
1898 pos_from_bit (&DECL_FIELD_OFFSET (decl
), &DECL_FIELD_BIT_OFFSET (decl
),
1899 DECL_OFFSET_ALIGN (decl
), pos
);
1901 DECL_SIZE (decl
) = bitsize_int (bitsize
);
1902 DECL_SIZE_UNIT (decl
) = size_int ((bitsize
+ BITS_PER_UNIT
- 1)
1905 DECL_CHAIN (decl
) = TYPE_FIELDS (record_or_union_type
);
1906 TYPE_FIELDS (record_or_union_type
) = decl
;
1908 return convert_out (decl
);
1912 plugin_finish_class_type (cc1_plugin::connection
*,
1913 unsigned long size_in_bytes
)
1915 tree record_or_union_type
= current_class_type
;
1917 gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (record_or_union_type
)));
1919 finish_struct (record_or_union_type
, NULL
);
1921 gcc_assert (compare_tree_int (TYPE_SIZE_UNIT (record_or_union_type
),
1922 size_in_bytes
) == 0);
1928 plugin_start_enum_type (cc1_plugin::connection
*self
,
1930 gcc_type underlying_int_type_in
,
1931 enum gcc_cp_symbol_kind flags
,
1932 const char *filename
,
1933 unsigned int line_number
)
1935 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
1936 tree underlying_int_type
= convert_in (underlying_int_type_in
);
1938 gcc_assert ((flags
& GCC_CP_SYMBOL_MASK
) == GCC_CP_SYMBOL_ENUM
);
1939 gcc_assert ((flags
& (~(GCC_CP_SYMBOL_MASK
| GCC_CP_ACCESS_MASK
1940 | GCC_CP_FLAG_MASK_ENUM
))) == 0);
1941 gcc_assert (!(flags
& GCC_CP_ACCESS_MASK
) == !at_class_scope_p ());
1943 if (underlying_int_type
== error_mark_node
)
1944 return convert_out (error_mark_node
);
1946 bool is_new_type
= false;
1948 tree id
= name
? get_identifier (name
) : make_anon_name ();
1950 tree type
= start_enum (id
, NULL_TREE
,
1951 underlying_int_type
,
1952 /* attributes = */ NULL_TREE
,
1953 !!(flags
& GCC_CP_FLAG_ENUM_SCOPED
), &is_new_type
);
1955 gcc_assert (is_new_type
);
1957 source_location loc
= ctx
->get_source_location (filename
, line_number
);
1958 tree type_decl
= TYPE_NAME (type
);
1959 DECL_SOURCE_LOCATION (type_decl
) = loc
;
1960 SET_OPAQUE_ENUM_P (type
, false);
1962 set_access_flags (type_decl
, flags
);
1964 return convert_out (ctx
->preserve (type
));
1968 plugin_build_enum_constant (cc1_plugin::connection
*,
1969 gcc_type enum_type_in
,
1971 unsigned long value
)
1973 tree enum_type
= convert_in (enum_type_in
);
1975 gcc_assert (TREE_CODE (enum_type
) == ENUMERAL_TYPE
);
1977 build_enumerator (get_identifier (name
), build_int_cst (enum_type
, value
),
1978 enum_type
, NULL_TREE
, BUILTINS_LOCATION
);
1980 return convert_out (TREE_VALUE (TYPE_VALUES (enum_type
)));
1984 plugin_finish_enum_type (cc1_plugin::connection
*,
1985 gcc_type enum_type_in
)
1987 tree enum_type
= convert_in (enum_type_in
);
1989 finish_enum_value_list (enum_type
);
1990 finish_enum (enum_type
);
1996 plugin_build_function_type (cc1_plugin::connection
*self
,
1997 gcc_type return_type_in
,
1998 const struct gcc_type_array
*argument_types_in
,
2001 tree
*argument_types
;
2002 tree return_type
= convert_in (return_type_in
);
2005 argument_types
= new tree
[argument_types_in
->n_elements
];
2006 for (int i
= 0; i
< argument_types_in
->n_elements
; ++i
)
2007 argument_types
[i
] = convert_in (argument_types_in
->elements
[i
]);
2010 result
= build_varargs_function_type_array (return_type
,
2011 argument_types_in
->n_elements
,
2014 result
= build_function_type_array (return_type
,
2015 argument_types_in
->n_elements
,
2018 delete[] argument_types
;
2020 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2021 return convert_out (ctx
->preserve (result
));
2027 plugin_add_function_default_args (cc1_plugin::connection
*self
,
2028 gcc_type function_type_in
,
2029 const struct gcc_cp_function_args
*defaults
)
2031 tree function_type
= convert_in (function_type_in
);
2033 gcc_assert (TREE_CODE (function_type
) == FUNCTION_TYPE
);
2035 if (!defaults
|| !defaults
->n_elements
)
2036 return function_type_in
;
2038 tree pargs
= TYPE_ARG_TYPES (function_type
);
2039 tree nargs
= NULL_TREE
;
2041 /* Build a reversed copy of the list of default-less arguments in
2042 NARGS. At the end of the loop, PARGS will point to the end of
2043 the argument list, or to the first argument that had a default
2045 while (pargs
&& TREE_VALUE (pargs
) != void_list_node
2046 && !TREE_PURPOSE (pargs
))
2048 nargs
= tree_cons (NULL_TREE
, TREE_VALUE (pargs
), nargs
);
2049 pargs
= TREE_CHAIN (pargs
);
2052 /* Set the defaults in the now-leading NARGS, taking into account
2053 that NARGS is reversed but DEFAULTS->elements isn't. */
2054 tree ndargs
= nargs
;
2055 int i
= defaults
->n_elements
;
2058 gcc_assert (ndargs
);
2059 tree deflt
= convert_in (defaults
->elements
[i
]);
2061 deflt
= error_mark_node
;
2062 TREE_PURPOSE (ndargs
) = deflt
;
2063 ndargs
= TREE_CHAIN (ndargs
);
2066 /* Finally, reverse NARGS, and append the remaining PARGS that
2067 already had defaults. */
2068 nargs
= nreverse (nargs
);
2069 nargs
= chainon (nargs
, pargs
);
2071 tree result
= build_function_type (TREE_TYPE (function_type
), nargs
);
2073 /* Copy exceptions, attributes and whatnot. */
2074 result
= build_exception_variant (result
,
2075 TYPE_RAISES_EXCEPTIONS (function_type
));
2076 result
= cp_build_type_attribute_variant (result
,
2077 TYPE_ATTRIBUTES (function_type
));
2079 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2080 return convert_out (ctx
->preserve (result
));
2084 plugin_set_deferred_function_default_args (cc1_plugin::connection
*,
2085 gcc_decl function_in
,
2086 const struct gcc_cp_function_args
2089 tree function
= convert_in (function_in
);
2091 gcc_assert (TREE_CODE (function
) == FUNCTION_DECL
);
2093 if (!defaults
|| !defaults
->n_elements
)
2096 tree arg
= FUNCTION_FIRST_USER_PARMTYPE (function
);
2098 for (int i
= 0; i
< defaults
->n_elements
; i
++)
2100 while (arg
&& TREE_PURPOSE (arg
) != error_mark_node
)
2101 arg
= TREE_CHAIN (arg
);
2106 TREE_PURPOSE (arg
) = convert_in (defaults
->elements
[i
]);
2107 arg
= TREE_CHAIN (arg
);
2116 plugin_get_function_parameter_decl (cc1_plugin::connection
*,
2117 gcc_decl function_in
,
2120 tree function
= convert_in (function_in
);
2122 gcc_assert (TREE_CODE (function
) == FUNCTION_DECL
);
2126 gcc_assert (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
);
2128 return convert_out (DECL_ARGUMENTS (function
));
2131 gcc_assert (index
>= 0);
2133 tree args
= FUNCTION_FIRST_USER_PARM (function
);
2135 for (int i
= 0; args
&& i
< index
; i
++)
2136 args
= DECL_CHAIN (args
);
2138 return convert_out (args
);
2142 plugin_build_exception_spec_variant (cc1_plugin::connection
*self
,
2143 gcc_type function_type_in
,
2144 const struct gcc_type_array
*except_types_in
)
2146 tree function_type
= convert_in (function_type_in
);
2147 tree except_types
= NULL_TREE
;
2149 if (!except_types_in
)
2150 except_types
= noexcept_false_spec
;
2151 else if (!except_types_in
->n_elements
)
2152 except_types
= empty_except_spec
;
2154 for (int i
= 0; i
< except_types_in
->n_elements
; i
++)
2155 except_types
= add_exception_specifier (except_types
,
2157 (except_types_in
->elements
[i
]),
2160 function_type
= build_exception_variant (function_type
,
2163 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2164 return convert_out (ctx
->preserve (function_type
));
2168 plugin_build_method_type (cc1_plugin::connection
*self
,
2169 gcc_type class_type_in
,
2170 gcc_type func_type_in
,
2171 enum gcc_cp_qualifiers quals_in
,
2172 enum gcc_cp_ref_qualifiers rquals_in
)
2174 tree class_type
= convert_in (class_type_in
);
2175 tree func_type
= convert_in (func_type_in
);
2176 cp_cv_quals quals
= 0;
2177 cp_ref_qualifier rquals
;
2179 if ((quals_in
& GCC_CP_QUALIFIER_CONST
) != 0)
2180 quals
|= TYPE_QUAL_CONST
;
2181 if ((quals_in
& GCC_CP_QUALIFIER_VOLATILE
) != 0)
2182 quals
|= TYPE_QUAL_VOLATILE
;
2183 gcc_assert ((quals_in
& GCC_CP_QUALIFIER_RESTRICT
) == 0);
2187 case GCC_CP_REF_QUAL_NONE
:
2188 rquals
= REF_QUAL_NONE
;
2190 case GCC_CP_REF_QUAL_LVALUE
:
2191 rquals
= REF_QUAL_LVALUE
;
2193 case GCC_CP_REF_QUAL_RVALUE
:
2194 rquals
= REF_QUAL_RVALUE
;
2200 tree method_type
= class_type
2201 ? build_memfn_type (func_type
, class_type
, quals
, rquals
)
2202 : apply_memfn_quals (func_type
, quals
, rquals
);
2204 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2205 return convert_out (ctx
->preserve (method_type
));
2209 plugin_build_pointer_to_member_type (cc1_plugin::connection
*self
,
2210 gcc_type class_type_in
,
2211 gcc_type member_type_in
)
2213 tree class_type
= convert_in (class_type_in
);
2214 tree member_type
= convert_in (member_type_in
);
2216 tree memptr_type
= build_ptrmem_type (class_type
, member_type
);
2218 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2219 return convert_out (ctx
->preserve (memptr_type
));
2223 plugin_start_template_decl (cc1_plugin::connection
*)
2225 begin_template_parm_list ();
2227 TP_PARM_LIST
= NULL_TREE
;
2233 plugin_get_type_decl (cc1_plugin::connection
*,
2236 tree type
= convert_in (type_in
);
2238 tree name
= TYPE_NAME (type
);
2241 return convert_out (name
);
2245 plugin_get_decl_type (cc1_plugin::connection
*,
2248 tree decl
= convert_in (decl_in
);
2250 tree type
= TREE_TYPE (decl
);
2253 return convert_out (type
);
2257 plugin_build_type_template_parameter (cc1_plugin::connection
*self
,
2259 int /* bool */ pack_p
,
2260 gcc_type default_type
,
2261 const char *filename
,
2262 unsigned int line_number
)
2264 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2265 source_location loc
= ctx
->get_source_location (filename
, line_number
);
2267 gcc_assert (template_parm_scope_p ());
2269 tree parm
= finish_template_type_parm (class_type_node
, get_identifier (id
));
2270 parm
= build_tree_list (convert_in (default_type
), parm
);
2272 gcc_assert (!(pack_p
&& default_type
));
2274 /* Create a type and a decl for the type parm, and add the decl to
2276 TP_PARM_LIST
= process_template_parm (TP_PARM_LIST
, loc
, parm
,
2277 /* is_non_type = */ false, pack_p
);
2279 /* Locate the decl of the newly-added, processed template parm. */
2280 parm
= TREE_VALUE (tree_last (TP_PARM_LIST
));
2282 /* Return its type. */
2283 return convert_out (ctx
->preserve (TREE_TYPE (parm
)));
2287 plugin_build_template_template_parameter (cc1_plugin::connection
*self
,
2289 int /* bool */ pack_p
,
2290 gcc_utempl default_templ
,
2291 const char *filename
,
2292 unsigned int line_number
)
2294 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2295 source_location loc
= ctx
->get_source_location (filename
, line_number
);
2297 gcc_assert (template_parm_scope_p ());
2299 /* Finish the template parm list that started this template parm. */
2300 end_template_parm_list (TP_PARM_LIST
);
2302 gcc_assert (template_parm_scope_p ());
2304 tree parm
= finish_template_template_parm (class_type_node
,
2305 get_identifier (id
));
2306 parm
= build_tree_list (convert_in (default_templ
), parm
);
2308 gcc_assert (!(pack_p
&& default_templ
));
2310 /* Create a type and a decl for the template parm, and add the decl
2312 TP_PARM_LIST
= process_template_parm (TP_PARM_LIST
, loc
, parm
,
2313 /* is_non_type = */ false, pack_p
);
2315 /* Locate the decl of the newly-added, processed template parm. */
2316 parm
= TREE_VALUE (tree_last (TP_PARM_LIST
));
2318 return convert_out (ctx
->preserve (parm
));
2322 plugin_build_value_template_parameter (cc1_plugin::connection
*self
,
2325 gcc_expr default_value
,
2326 const char *filename
,
2327 unsigned int line_number
)
2329 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2330 source_location loc
= ctx
->get_source_location (filename
, line_number
);
2332 gcc_assert (template_parm_scope_p ());
2334 cp_declarator declarator
;
2335 memset (&declarator
, 0, sizeof (declarator
));
2336 // &declarator = make_id_declarator (NULL, get_identifier (id), sfk_none):
2337 declarator
.kind
= cdk_id
;
2338 declarator
.u
.id
.qualifying_scope
= NULL
;
2339 declarator
.u
.id
.unqualified_name
= get_identifier (id
);
2340 declarator
.u
.id
.sfk
= sfk_none
;
2342 cp_decl_specifier_seq declspec
;
2343 memset (&declspec
, 0, sizeof (declspec
));
2344 // cp_parser_set_decl_spec_type (&declspec, convert_in (type), -token-, false):
2345 declspec
.any_specifiers_p
= declspec
.any_type_specifiers_p
= true;
2346 declspec
.type
= convert_in (type
);
2347 declspec
.locations
[ds_type_spec
] = loc
;
2349 tree parm
= grokdeclarator (&declarator
, &declspec
, TPARM
, 0, 0);
2350 parm
= build_tree_list (convert_in (default_value
), parm
);
2352 /* Create a type and a decl for the template parm, and add the decl
2354 TP_PARM_LIST
= process_template_parm (TP_PARM_LIST
, loc
, parm
,
2355 /* is_non_type = */ true, false);
2357 /* Locate the decl of the newly-added, processed template parm. */
2358 parm
= TREE_VALUE (tree_last (TP_PARM_LIST
));
2360 return convert_out (ctx
->preserve (parm
));
2364 targlist (const gcc_cp_template_args
*targs
)
2366 int n
= targs
->n_elements
;
2367 tree vec
= make_tree_vec (n
);
2370 switch (targs
->kinds
[n
])
2372 case GCC_CP_TPARG_VALUE
:
2373 TREE_VEC_ELT (vec
, n
) = convert_in (targs
->elements
[n
].value
);
2375 case GCC_CP_TPARG_CLASS
:
2376 TREE_VEC_ELT (vec
, n
) = convert_in (targs
->elements
[n
].type
);
2378 case GCC_CP_TPARG_TEMPL
:
2379 TREE_VEC_ELT (vec
, n
) = convert_in (targs
->elements
[n
].templ
);
2381 case GCC_CP_TPARG_PACK
:
2382 TREE_VEC_ELT (vec
, n
) = convert_in (targs
->elements
[n
].pack
);
2392 plugin_build_dependent_typename (cc1_plugin::connection
*self
,
2393 gcc_type enclosing_type
,
2395 const gcc_cp_template_args
*targs
)
2397 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2398 tree type
= convert_in (enclosing_type
);
2399 tree name
= get_identifier (id
);
2401 name
= build_min_nt_loc (/*loc=*/0, TEMPLATE_ID_EXPR
,
2402 name
, targlist (targs
));
2403 tree res
= make_typename_type (type
, name
, typename_type
,
2404 /*complain=*/tf_error
);
2405 return convert_out (ctx
->preserve (res
));
2409 plugin_build_dependent_class_template (cc1_plugin::connection
*self
,
2410 gcc_type enclosing_type
,
2413 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2414 tree type
= convert_in (enclosing_type
);
2415 tree name
= get_identifier (id
);
2416 tree res
= make_unbound_class_template (type
, name
, NULL_TREE
,
2417 /*complain=*/tf_error
);
2418 return convert_out (ctx
->preserve (res
));
2422 plugin_build_dependent_type_template_id (cc1_plugin::connection
*self
,
2423 gcc_utempl template_decl
,
2424 const gcc_cp_template_args
*targs
)
2426 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2427 tree type
= convert_in (template_decl
);
2428 tree decl
= finish_template_type (type
, targlist (targs
),
2429 /*entering_scope=*/false);
2430 return convert_out (ctx
->preserve (TREE_TYPE (decl
)));
2434 plugin_build_dependent_expr (cc1_plugin::connection
*self
,
2435 gcc_decl enclosing_scope
,
2436 enum gcc_cp_symbol_kind flags
,
2438 gcc_type conv_type_in
,
2439 const gcc_cp_template_args
*targs
)
2441 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2442 tree scope
= convert_in (enclosing_scope
);
2443 tree conv_type
= convert_in (conv_type_in
);
2446 if (TREE_CODE (scope
) != NAMESPACE_DECL
)
2448 tree type
= TREE_TYPE (scope
);
2449 gcc_assert (TYPE_NAME (type
) == scope
);
2453 if (flags
== (GCC_CP_SYMBOL_FUNCTION
| GCC_CP_FLAG_SPECIAL_FUNCTION
))
2455 bool assop
= false, convop
= false;
2456 tree_code opcode
= ERROR_MARK
;
2458 switch (CHARS2 (name
[0], name
[1]))
2460 case CHARS2 ('C', 0x0): // ctor base declaration
2461 case CHARS2 ('C', ' '):
2462 case CHARS2 ('C', '1'):
2463 case CHARS2 ('C', '2'):
2464 case CHARS2 ('C', '4'):
2465 identifier
= ctor_identifier
;
2467 case CHARS2 ('D', 0x0): // dtor base declaration
2468 case CHARS2 ('D', ' '):
2469 case CHARS2 ('D', '0'):
2470 case CHARS2 ('D', '1'):
2471 case CHARS2 ('D', '2'):
2472 case CHARS2 ('D', '4'):
2473 gcc_assert (!targs
);
2474 identifier
= dtor_identifier
;
2476 case CHARS2 ('n', 'w'): // operator new
2479 case CHARS2 ('n', 'a'): // operator new[]
2480 opcode
= VEC_NEW_EXPR
;
2482 case CHARS2 ('d', 'l'): // operator delete
2483 opcode
= DELETE_EXPR
;
2485 case CHARS2 ('d', 'a'): // operator delete[]
2486 opcode
= VEC_DELETE_EXPR
;
2488 case CHARS2 ('p', 's'): // operator + (unary)
2491 case CHARS2 ('n', 'g'): // operator - (unary)
2492 opcode
= MINUS_EXPR
;
2494 case CHARS2 ('a', 'd'): // operator & (unary)
2495 opcode
= BIT_AND_EXPR
;
2497 case CHARS2 ('d', 'e'): // operator * (unary)
2500 case CHARS2 ('c', 'o'): // operator ~
2501 opcode
= BIT_NOT_EXPR
;
2503 case CHARS2 ('p', 'l'): // operator +
2506 case CHARS2 ('m', 'i'): // operator -
2507 opcode
= MINUS_EXPR
;
2509 case CHARS2 ('m', 'l'): // operator *
2512 case CHARS2 ('d', 'v'): // operator /
2513 opcode
= TRUNC_DIV_EXPR
;
2515 case CHARS2 ('r', 'm'): // operator %
2516 opcode
= TRUNC_MOD_EXPR
;
2518 case CHARS2 ('a', 'n'): // operator &
2519 opcode
= BIT_AND_EXPR
;
2521 case CHARS2 ('o', 'r'): // operator |
2522 opcode
= BIT_IOR_EXPR
;
2524 case CHARS2 ('e', 'o'): // operator ^
2525 opcode
= BIT_XOR_EXPR
;
2527 case CHARS2 ('a', 'S'): // operator =
2531 case CHARS2 ('p', 'L'): // operator +=
2535 case CHARS2 ('m', 'I'): // operator -=
2536 opcode
= MINUS_EXPR
;
2539 case CHARS2 ('m', 'L'): // operator *=
2543 case CHARS2 ('d', 'V'): // operator /=
2544 opcode
= TRUNC_DIV_EXPR
;
2547 case CHARS2 ('r', 'M'): // operator %=
2548 opcode
= TRUNC_MOD_EXPR
;
2551 case CHARS2 ('a', 'N'): // operator &=
2552 opcode
= BIT_AND_EXPR
;
2555 case CHARS2 ('o', 'R'): // operator |=
2556 opcode
= BIT_IOR_EXPR
;
2559 case CHARS2 ('e', 'O'): // operator ^=
2560 opcode
= BIT_XOR_EXPR
;
2563 case CHARS2 ('l', 's'): // operator <<
2564 opcode
= LSHIFT_EXPR
;
2566 case CHARS2 ('r', 's'): // operator >>
2567 opcode
= RSHIFT_EXPR
;
2569 case CHARS2 ('l', 'S'): // operator <<=
2570 opcode
= LSHIFT_EXPR
;
2573 case CHARS2 ('r', 'S'): // operator >>=
2574 opcode
= RSHIFT_EXPR
;
2577 case CHARS2 ('e', 'q'): // operator ==
2580 case CHARS2 ('n', 'e'): // operator !=
2583 case CHARS2 ('l', 't'): // operator <
2586 case CHARS2 ('g', 't'): // operator >
2589 case CHARS2 ('l', 'e'): // operator <=
2592 case CHARS2 ('g', 'e'): // operator >=
2595 case CHARS2 ('n', 't'): // operator !
2596 opcode
= TRUTH_NOT_EXPR
;
2598 case CHARS2 ('a', 'a'): // operator &&
2599 opcode
= TRUTH_ANDIF_EXPR
;
2601 case CHARS2 ('o', 'o'): // operator ||
2602 opcode
= TRUTH_ORIF_EXPR
;
2604 case CHARS2 ('p', 'p'): // operator ++
2605 opcode
= POSTINCREMENT_EXPR
;
2607 case CHARS2 ('m', 'm'): // operator --
2608 opcode
= PREDECREMENT_EXPR
;
2610 case CHARS2 ('c', 'm'): // operator ,
2611 opcode
= COMPOUND_EXPR
;
2613 case CHARS2 ('p', 'm'): // operator ->*
2614 opcode
= MEMBER_REF
;
2616 case CHARS2 ('p', 't'): // operator ->
2617 opcode
= COMPONENT_REF
;
2619 case CHARS2 ('c', 'l'): // operator ()
2622 case CHARS2 ('i', 'x'): // operator []
2625 case CHARS2 ('c', 'v'): // operator <T> (conversion operator)
2627 identifier
= mangle_conv_op_name_for_type (conv_type
);
2630 case CHARS2 ('l', 'i'): // operator "" <id>
2632 char *id
= (char *)name
+ 2;
2633 bool freeid
= false;
2634 if (*id
>= '0' && *id
<= '9')
2643 while (*id
&& *id
>= '0' && *id
<= '9');
2644 id
= xstrndup (id
, len
);
2647 identifier
= cp_literal_operator_id (id
);
2652 case CHARS2 ('q', 'u'): // ternary operator, not overloadable.
2657 gcc_assert (convop
|| !conv_type
);
2659 if (opcode
!= ERROR_MARK
)
2662 identifier
= cp_assignment_operator_id (opcode
);
2664 identifier
= cp_operator_id (opcode
);
2667 gcc_assert (identifier
);
2671 gcc_assert (flags
== GCC_CP_SYMBOL_MASK
);
2672 gcc_assert (!conv_type
);
2673 identifier
= get_identifier (name
);
2675 tree res
= identifier
;
2677 res
= lookup_name_real (res
, 0, 0, true, 0, 0);
2678 else if (!TYPE_P (scope
) || !dependent_scope_p (scope
))
2680 res
= lookup_qualified_name (scope
, res
, false, true);
2681 /* We've already resolved the name in the scope, so skip the
2682 build_qualified_name call below. */
2686 res
= lookup_template_function (res
, targlist (targs
));
2688 res
= build_qualified_name (NULL_TREE
, scope
, res
, !!targs
);
2689 return convert_out (ctx
->preserve (res
));
2693 plugin_build_literal_expr (cc1_plugin::connection
*self
,
2694 gcc_type type
, unsigned long value
)
2696 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2697 tree t
= convert_in (type
);
2698 tree val
= build_int_cst_type (t
, (unsigned HOST_WIDE_INT
) value
);
2699 return convert_out (ctx
->preserve (val
));
2703 plugin_build_decl_expr (cc1_plugin::connection
*self
,
2707 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2708 tree decl
= convert_in (decl_in
);
2709 gcc_assert (DECL_P (decl
));
2713 gcc_assert (DECL_CLASS_SCOPE_P (decl
));
2714 result
= build_offset_ref (DECL_CONTEXT (decl
), decl
,
2715 /*address_p=*/true, tf_error
);
2717 return convert_out (ctx
->preserve (result
));
2721 plugin_build_unary_expr (cc1_plugin::connection
*self
,
2722 const char *unary_op
,
2725 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2726 tree op0
= convert_in (operand
);
2727 tree_code opcode
= ERROR_MARK
;
2728 bool global_scope_p
= false;
2731 switch (CHARS2 (unary_op
[0], unary_op
[1]))
2733 case CHARS2 ('p', 's'): // operator + (unary)
2734 opcode
= UNARY_PLUS_EXPR
;
2736 case CHARS2 ('n', 'g'): // operator - (unary)
2737 opcode
= NEGATE_EXPR
;
2739 case CHARS2 ('a', 'd'): // operator & (unary)
2742 case CHARS2 ('d', 'e'): // operator * (unary)
2743 opcode
= INDIRECT_REF
;
2745 case CHARS2 ('c', 'o'): // operator ~
2746 opcode
= BIT_NOT_EXPR
;
2748 case CHARS2 ('n', 't'): // operator !
2749 opcode
= TRUTH_NOT_EXPR
;
2751 case CHARS2 ('p', 'p'): // operator ++
2752 opcode
= unary_op
[2] == '_' ? PREINCREMENT_EXPR
: POSTINCREMENT_EXPR
;
2754 case CHARS2 ('m', 'm'): // operator --
2755 opcode
= unary_op
[2] == '_' ? PREDECREMENT_EXPR
: POSTDECREMENT_EXPR
;
2757 case CHARS2 ('n', 'x'): // noexcept
2758 opcode
= NOEXCEPT_EXPR
;
2760 case CHARS2 ('t', 'w'): // throw
2762 opcode
= THROW_EXPR
;
2764 case CHARS2 ('t', 'r'): // rethrow
2766 opcode
= THROW_EXPR
;
2768 case CHARS2 ('t', 'e'): // typeid (value)
2769 opcode
= TYPEID_EXPR
;
2771 case CHARS2 ('s', 'z'): // sizeof (value)
2772 opcode
= SIZEOF_EXPR
;
2774 case CHARS2 ('a', 'z'): // alignof (value)
2775 opcode
= ALIGNOF_EXPR
;
2777 case CHARS2 ('g', 's'): // global scope (for delete, delete[])
2778 gcc_assert (!global_scope_p
);
2779 global_scope_p
= true;
2782 case CHARS2 ('d', 'l'): // delete
2783 opcode
= DELETE_EXPR
;
2785 case CHARS2 ('d', 'a'): // delete[]
2786 opcode
= VEC_DELETE_EXPR
;
2788 case CHARS2 ('s', 'p'): // pack...
2789 opcode
= EXPR_PACK_EXPANSION
;
2791 case CHARS2 ('s', 'Z'): // sizeof...(pack)
2792 opcode
= TYPE_PACK_EXPANSION
; // Not really, but let's use its code.
2795 /* FIXME: __real__, __imag__? */
2801 gcc_assert (!global_scope_p
2802 || opcode
== DELETE_EXPR
|| opcode
== VEC_DELETE_EXPR
);
2804 processing_template_decl
++;
2805 bool template_dependent_p
= op0
2806 && (type_dependent_expression_p (op0
)
2807 || value_dependent_expression_p (op0
));
2808 if (!template_dependent_p
)
2809 processing_template_decl
--;
2813 gcc_assert (op0
|| opcode
== THROW_EXPR
);
2818 result
= finish_noexcept_expr (op0
, tf_error
);
2822 result
= build_throw (op0
);
2826 result
= build_typeid (op0
, tf_error
);
2831 result
= cxx_sizeof_or_alignof_expr (op0
, opcode
, true);
2835 case VEC_DELETE_EXPR
:
2836 result
= delete_sanity (op0
, NULL_TREE
, opcode
== VEC_DELETE_EXPR
,
2837 global_scope_p
, tf_error
);
2840 case EXPR_PACK_EXPANSION
:
2841 result
= make_pack_expansion (op0
);
2844 // We're using this for sizeof...(pack). */
2845 case TYPE_PACK_EXPANSION
:
2846 result
= make_pack_expansion (op0
);
2847 PACK_EXPANSION_SIZEOF_P (result
) = true;
2851 result
= build_x_unary_op (/*loc=*/0, opcode
, op0
, tf_error
);
2855 if (template_dependent_p
)
2856 processing_template_decl
--;
2858 return convert_out (ctx
->preserve (result
));
2862 plugin_build_binary_expr (cc1_plugin::connection
*self
,
2863 const char *binary_op
,
2867 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2868 tree op0
= convert_in (operand1
);
2869 tree op1
= convert_in (operand2
);
2870 tree_code opcode
= ERROR_MARK
;
2872 switch (CHARS2 (binary_op
[0], binary_op
[1]))
2874 case CHARS2 ('p', 'l'): // operator +
2877 case CHARS2 ('m', 'i'): // operator -
2878 opcode
= MINUS_EXPR
;
2880 case CHARS2 ('m', 'l'): // operator *
2883 case CHARS2 ('d', 'v'): // operator /
2884 opcode
= TRUNC_DIV_EXPR
;
2886 case CHARS2 ('r', 'm'): // operator %
2887 opcode
= TRUNC_MOD_EXPR
;
2889 case CHARS2 ('a', 'n'): // operator &
2890 opcode
= BIT_AND_EXPR
;
2892 case CHARS2 ('o', 'r'): // operator |
2893 opcode
= BIT_IOR_EXPR
;
2895 case CHARS2 ('e', 'o'): // operator ^
2896 opcode
= BIT_XOR_EXPR
;
2898 case CHARS2 ('l', 's'): // operator <<
2899 opcode
= LSHIFT_EXPR
;
2901 case CHARS2 ('r', 's'): // operator >>
2902 opcode
= RSHIFT_EXPR
;
2904 case CHARS2 ('e', 'q'): // operator ==
2907 case CHARS2 ('n', 'e'): // operator !=
2910 case CHARS2 ('l', 't'): // operator <
2913 case CHARS2 ('g', 't'): // operator >
2916 case CHARS2 ('l', 'e'): // operator <=
2919 case CHARS2 ('g', 'e'): // operator >=
2922 case CHARS2 ('a', 'a'): // operator &&
2923 opcode
= TRUTH_ANDIF_EXPR
;
2925 case CHARS2 ('o', 'o'): // operator ||
2926 opcode
= TRUTH_ORIF_EXPR
;
2928 case CHARS2 ('c', 'm'): // operator ,
2929 opcode
= COMPOUND_EXPR
;
2931 case CHARS2 ('p', 'm'): // operator ->*
2932 opcode
= MEMBER_REF
;
2934 case CHARS2 ('p', 't'): // operator ->
2935 opcode
= INDIRECT_REF
; // Not really! This will stand for
2936 // INDIRECT_REF followed by COMPONENT_REF
2939 case CHARS2 ('i', 'x'): // operator []
2942 case CHARS2 ('d', 's'): // operator .*
2943 opcode
= DOTSTAR_EXPR
;
2945 case CHARS2 ('d', 't'): // operator .
2946 opcode
= COMPONENT_REF
;
2953 processing_template_decl
++;
2954 bool template_dependent_p
= type_dependent_expression_p (op0
)
2955 || value_dependent_expression_p (op0
)
2956 || type_dependent_expression_p (op1
)
2957 || value_dependent_expression_p (op1
);
2958 if (!template_dependent_p
)
2959 processing_template_decl
--;
2965 case INDIRECT_REF
: // This is actually a "->".
2966 op0
= build_x_arrow (/*loc=*/0, op0
, tf_error
);
2969 result
= finish_class_member_access_expr (op0
, op1
,
2970 /*template_p=*/false,
2975 result
= build_x_binary_op (/*loc=*/0, opcode
, op0
, ERROR_MARK
,
2976 op1
, ERROR_MARK
, NULL
, tf_error
);
2980 if (template_dependent_p
)
2981 processing_template_decl
--;
2983 return convert_out (ctx
->preserve (result
));
2987 plugin_build_ternary_expr (cc1_plugin::connection
*self
,
2988 const char *ternary_op
,
2993 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
2994 tree op0
= convert_in (operand1
);
2995 tree op1
= convert_in (operand2
);
2996 tree op2
= convert_in (operand3
);
2997 gcc_assert (CHARS2 (ternary_op
[0], ternary_op
[1])
2998 == CHARS2 ('q', 'u')); // ternary operator
3000 processing_template_decl
++;
3001 bool template_dependent_p
= type_dependent_expression_p (op0
)
3002 || value_dependent_expression_p (op0
)
3003 || type_dependent_expression_p (op1
)
3004 || value_dependent_expression_p (op1
)
3005 || type_dependent_expression_p (op2
)
3006 || value_dependent_expression_p (op2
);
3007 if (!template_dependent_p
)
3008 processing_template_decl
--;
3010 tree val
= build_x_conditional_expr (/*loc=*/0, op0
, op1
, op2
, tf_error
);
3012 if (template_dependent_p
)
3013 processing_template_decl
--;
3015 return convert_out (ctx
->preserve (val
));
3019 plugin_build_unary_type_expr (cc1_plugin::connection
*self
,
3020 const char *unary_op
,
3023 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3024 tree type
= convert_in (operand
);
3025 tree_code opcode
= ERROR_MARK
;
3027 switch (CHARS2 (unary_op
[0], unary_op
[1]))
3029 case CHARS2 ('t', 'i'): // typeid (type)
3030 opcode
= TYPEID_EXPR
;
3033 case CHARS2 ('s', 't'): // sizeof (type)
3034 opcode
= SIZEOF_EXPR
;
3036 case CHARS2 ('a', 't'): // alignof (type)
3037 opcode
= ALIGNOF_EXPR
;
3040 case CHARS2 ('s', 'Z'): // sizeof...(pack)
3041 opcode
= TYPE_PACK_EXPANSION
; // Not really, but let's use its code.
3044 // FIXME: do we have to handle "sp", for the size of a captured
3045 // template parameter pack from an alias template, taking
3046 // multiple template arguments?
3052 processing_template_decl
++;
3053 bool template_dependent_p
= dependent_type_p (type
);
3054 if (!template_dependent_p
)
3055 processing_template_decl
--;
3062 result
= get_typeid (type
, tf_error
);
3065 // We're using this for sizeof...(pack). */
3066 case TYPE_PACK_EXPANSION
:
3067 result
= make_pack_expansion (type
);
3068 PACK_EXPANSION_SIZEOF_P (result
) = true;
3072 result
= cxx_sizeof_or_alignof_type (type
, opcode
, true);
3075 if (template_dependent_p
)
3076 processing_template_decl
--;
3078 return convert_out (ctx
->preserve (result
));
3082 plugin_build_cast_expr (cc1_plugin::connection
*self
,
3083 const char *binary_op
,
3087 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3088 tree (*build_cast
)(tree type
, tree expr
, tsubst_flags_t complain
) = NULL
;
3089 tree type
= convert_in (operand1
);
3090 tree expr
= convert_in (operand2
);
3092 switch (CHARS2 (binary_op
[0], binary_op
[1]))
3094 case CHARS2 ('d', 'c'): // dynamic_cast
3095 build_cast
= build_dynamic_cast
;
3098 case CHARS2 ('s', 'c'): // static_cast
3099 build_cast
= build_static_cast
;
3102 case CHARS2 ('c', 'c'): // const_cast
3103 build_cast
= build_const_cast
;
3106 case CHARS2 ('r', 'c'): // reinterpret_cast
3107 build_cast
= build_reinterpret_cast
;
3110 case CHARS2 ('c', 'v'): // C cast, conversion with one argument
3111 build_cast
= cp_build_c_cast
;
3118 processing_template_decl
++;
3119 bool template_dependent_p
= dependent_type_p (type
)
3120 || type_dependent_expression_p (expr
)
3121 || value_dependent_expression_p (expr
);
3122 if (!template_dependent_p
)
3123 processing_template_decl
--;
3125 tree val
= build_cast (type
, expr
, tf_error
);
3127 if (template_dependent_p
)
3128 processing_template_decl
--;
3130 return convert_out (ctx
->preserve (val
));
3133 static inline vec
<tree
, va_gc
> *
3134 args_to_tree_vec (const struct gcc_cp_function_args
*args_in
)
3136 vec
<tree
, va_gc
> *args
= make_tree_vector ();
3137 for (int i
= 0; i
< args_in
->n_elements
; i
++)
3138 vec_safe_push (args
, convert_in (args_in
->elements
[i
]));
3143 args_to_tree_list (const struct gcc_cp_function_args
*args_in
)
3145 tree args
, *tail
= &args
;
3146 for (int i
= 0; i
< args_in
->n_elements
; i
++)
3148 *tail
= build_tree_list (NULL
, convert_in (args_in
->elements
[i
]));
3149 tail
= &TREE_CHAIN (*tail
);
3154 static inline vec
<constructor_elt
, va_gc
> *
3155 args_to_ctor_elts (const struct gcc_cp_function_args
*args_in
)
3157 vec
<constructor_elt
, va_gc
> *args
= NULL
;
3158 for (int i
= 0; i
< args_in
->n_elements
; i
++)
3159 CONSTRUCTOR_APPEND_ELT (args
, NULL_TREE
, convert_in (args_in
->elements
[i
]));
3164 plugin_build_expression_list_expr (cc1_plugin::connection
*self
,
3165 const char *conv_op
,
3167 const struct gcc_cp_function_args
*values_in
)
3169 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3170 tree type
= convert_in (type_in
);
3174 switch (CHARS2 (conv_op
[0], conv_op
[1]))
3176 case CHARS2 ('c', 'v'): // conversion with parenthesized expression list
3177 gcc_assert (TYPE_P (type
));
3178 args
= args_to_tree_list (values_in
);
3179 result
= build_functional_cast (type
, args
, tf_error
);
3182 case CHARS2 ('t', 'l'): // conversion with braced expression list
3184 gcc_assert (TYPE_P (type
));
3185 args
= make_node (CONSTRUCTOR
);
3186 CONSTRUCTOR_ELTS (args
) = args_to_ctor_elts (values_in
);
3187 CONSTRUCTOR_IS_DIRECT_INIT (args
) = 1;
3188 result
= finish_compound_literal (type
, args
, tf_error
);
3191 case CHARS2 ('i', 'l'): // untyped braced expression list
3193 result
= make_node (CONSTRUCTOR
);
3194 CONSTRUCTOR_ELTS (result
) = args_to_ctor_elts (values_in
);
3201 return convert_out (ctx
->preserve (result
));
3205 plugin_build_new_expr (cc1_plugin::connection
*self
,
3207 const struct gcc_cp_function_args
*placement_in
,
3209 const struct gcc_cp_function_args
*initializer_in
)
3211 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3212 tree type
= convert_in (type_in
);
3213 vec
<tree
, va_gc
> *placement
= NULL
, *initializer
= NULL
;
3214 bool global_scope_p
= false;
3218 placement
= args_to_tree_vec (placement_in
);
3220 initializer
= args_to_tree_vec (initializer_in
);
3222 gcc_assert (TYPE_P (type
));
3225 switch (CHARS2 (new_op
[0], new_op
[1]))
3227 case CHARS2 ('g', 's'):
3228 gcc_assert (!global_scope_p
);
3229 global_scope_p
= true;
3233 case CHARS2 ('n', 'w'): // non-array new
3234 gcc_assert (TREE_CODE (type
) != ARRAY_TYPE
);
3237 case CHARS2 ('n', 'a'): // array new
3238 gcc_assert (TREE_CODE (type
) == ARRAY_TYPE
);
3239 gcc_assert (TYPE_DOMAIN (type
));
3241 // Compute the length of the outermost array type, then discard it.
3242 tree maxelt
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
3243 tree eltype
= TREE_TYPE (maxelt
);
3244 tree onecst
= integer_one_node
;
3246 processing_template_decl
++;
3247 bool template_dependent_p
= value_dependent_expression_p (maxelt
)
3248 || type_dependent_expression_p (maxelt
);
3249 if (!template_dependent_p
)
3251 processing_template_decl
--;
3252 onecst
= fold_convert (eltype
, onecst
);
3255 nelts
= fold_build2 (PLUS_EXPR
, eltype
, nelts
, onecst
);
3257 if (template_dependent_p
)
3258 processing_template_decl
--;
3260 type
= TREE_TYPE (type
);
3268 processing_template_decl
++;
3269 bool template_dependent_p
= dependent_type_p (type
)
3270 || value_dependent_expression_p (nelts
)
3272 && any_type_dependent_arguments_p (placement
))
3274 && any_type_dependent_arguments_p (initializer
));
3275 if (!template_dependent_p
)
3276 processing_template_decl
--;
3278 tree result
= build_new (&placement
, type
, nelts
, &initializer
,
3279 global_scope_p
, tf_error
);
3281 if (template_dependent_p
)
3282 processing_template_decl
--;
3284 if (placement
!= NULL
)
3285 release_tree_vector (placement
);
3286 if (initializer
!= NULL
)
3287 release_tree_vector (initializer
);
3289 return convert_out (ctx
->preserve (result
));
3293 plugin_build_call_expr (cc1_plugin::connection
*self
,
3294 gcc_expr callable_in
, int qualified_p
,
3295 const struct gcc_cp_function_args
*args_in
)
3297 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3298 tree callable
= convert_in (callable_in
);
3301 vec
<tree
, va_gc
> *args
= args_to_tree_vec (args_in
);
3303 bool koenig_p
= false;
3304 if (!qualified_p
&& !args
->is_empty ())
3306 if (identifier_p (callable
))
3308 else if (is_overloaded_fn (callable
))
3310 tree fn
= get_first_fn (callable
);
3311 fn
= STRIP_TEMPLATE (fn
);
3313 if (!DECL_FUNCTION_MEMBER_P (fn
)
3314 && !DECL_LOCAL_FUNCTION_P (fn
))
3319 if (koenig_p
&& !any_type_dependent_arguments_p (args
))
3320 callable
= perform_koenig_lookup (callable
, args
, tf_none
);
3322 if (TREE_CODE (callable
) == COMPONENT_REF
)
3324 tree object
= TREE_OPERAND (callable
, 0);
3325 tree memfn
= TREE_OPERAND (callable
, 1);
3327 if (type_dependent_expression_p (object
)
3328 || (!BASELINK_P (memfn
) && TREE_CODE (memfn
) != FIELD_DECL
)
3329 || type_dependent_expression_p (memfn
)
3330 || any_type_dependent_arguments_p (args
))
3331 call_expr
= build_nt_call_vec (callable
, args
);
3332 else if (BASELINK_P (memfn
))
3333 call_expr
= build_new_method_call (object
, memfn
, &args
, NULL_TREE
,
3335 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
3339 call_expr
= finish_call_expr (callable
, &args
, false, false, tf_none
);
3341 else if (TREE_CODE (callable
) == OFFSET_REF
3342 || TREE_CODE (callable
) == MEMBER_REF
3343 || TREE_CODE (callable
) == DOTSTAR_EXPR
)
3344 call_expr
= build_offset_ref_call_from_tree (callable
, &args
, tf_none
);
3346 call_expr
= finish_call_expr (callable
, &args
,
3347 !!qualified_p
, koenig_p
, tf_none
);
3349 release_tree_vector (args
);
3350 return convert_out (ctx
->preserve (call_expr
));
3354 plugin_get_expr_type (cc1_plugin::connection
*self
,
3357 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3358 tree op0
= convert_in (operand
);
3361 type
= TREE_TYPE (op0
);
3364 type
= make_decltype_auto ();
3365 AUTO_IS_DECLTYPE (type
) = true;
3367 return convert_out (ctx
->preserve (type
));
3371 plugin_build_function_template_specialization (cc1_plugin::connection
*self
,
3372 gcc_decl template_decl
,
3373 const gcc_cp_template_args
*targs
,
3374 gcc_address address
,
3375 const char *filename
,
3376 unsigned int line_number
)
3378 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3379 source_location loc
= ctx
->get_source_location (filename
, line_number
);
3380 tree name
= convert_in (template_decl
);
3381 tree targsl
= targlist (targs
);
3383 tree decl
= tsubst (name
, targsl
, tf_error
, NULL_TREE
);
3384 DECL_SOURCE_LOCATION (decl
) = loc
;
3386 record_decl_address (ctx
, build_decl_addr_value (decl
, address
));
3388 return convert_out (ctx
->preserve (decl
));
3392 plugin_build_class_template_specialization (cc1_plugin::connection
*self
,
3393 gcc_decl template_decl
,
3394 const gcc_cp_template_args
*args
,
3395 const char *filename
,
3396 unsigned int line_number
)
3398 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3399 source_location loc
= ctx
->get_source_location (filename
, line_number
);
3400 tree name
= convert_in (template_decl
);
3402 tree tdecl
= finish_template_type (name
, targlist (args
), false);;
3403 DECL_SOURCE_LOCATION (tdecl
) = loc
;
3405 return convert_out (ctx
->preserve (tdecl
));
3408 /* Return a builtin type associated with BUILTIN_NAME. */
3411 safe_lookup_builtin_type (const char *builtin_name
)
3413 tree result
= NULL_TREE
;
3418 result
= identifier_global_value (get_identifier (builtin_name
));
3423 gcc_assert (TREE_CODE (result
) == TYPE_DECL
);
3424 result
= TREE_TYPE (result
);
3429 plugin_get_int_type (cc1_plugin::connection
*self
,
3430 int is_unsigned
, unsigned long size_in_bytes
,
3431 const char *builtin_name
)
3437 result
= safe_lookup_builtin_type (builtin_name
);
3438 gcc_assert (!result
|| TREE_CODE (result
) == INTEGER_TYPE
);
3441 result
= c_common_type_for_size (BITS_PER_UNIT
* size_in_bytes
,
3444 if (result
== NULL_TREE
)
3445 result
= error_mark_node
;
3448 gcc_assert (!TYPE_UNSIGNED (result
) == !is_unsigned
);
3449 gcc_assert (TREE_CODE (TYPE_SIZE (result
)) == INTEGER_CST
);
3450 gcc_assert (TYPE_PRECISION (result
) == BITS_PER_UNIT
* size_in_bytes
);
3452 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3453 ctx
->preserve (result
);
3455 return convert_out (result
);
3459 plugin_get_char_type (cc1_plugin::connection
*)
3461 return convert_out (char_type_node
);
3465 plugin_get_float_type (cc1_plugin::connection
*,
3466 unsigned long size_in_bytes
,
3467 const char *builtin_name
)
3471 tree result
= safe_lookup_builtin_type (builtin_name
);
3474 return convert_out (error_mark_node
);
3476 gcc_assert (TREE_CODE (result
) == REAL_TYPE
);
3477 gcc_assert (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (result
));
3479 return convert_out (result
);
3482 if (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (float_type_node
))
3483 return convert_out (float_type_node
);
3484 if (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (double_type_node
))
3485 return convert_out (double_type_node
);
3486 if (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (long_double_type_node
))
3487 return convert_out (long_double_type_node
);
3488 return convert_out (error_mark_node
);
3492 plugin_get_void_type (cc1_plugin::connection
*)
3494 return convert_out (void_type_node
);
3498 plugin_get_bool_type (cc1_plugin::connection
*)
3500 return convert_out (boolean_type_node
);
3504 plugin_get_nullptr_type (cc1_plugin::connection
*)
3506 return convert_out (nullptr_type_node
);
3510 plugin_get_nullptr_constant (cc1_plugin::connection
*)
3512 return convert_out (nullptr_node
);
3516 plugin_build_array_type (cc1_plugin::connection
*self
,
3517 gcc_type element_type_in
, int num_elements
)
3519 tree element_type
= convert_in (element_type_in
);
3522 if (num_elements
== -1)
3523 result
= build_array_type (element_type
, NULL_TREE
);
3525 result
= build_array_type_nelts (element_type
, num_elements
);
3527 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3528 return convert_out (ctx
->preserve (result
));
3532 plugin_build_dependent_array_type (cc1_plugin::connection
*self
,
3533 gcc_type element_type_in
,
3534 gcc_expr num_elements_in
)
3536 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3537 tree element_type
= convert_in (element_type_in
);
3538 tree size
= convert_in (num_elements_in
);
3539 tree name
= get_identifier ("dependent array type");
3541 processing_template_decl
++;
3542 bool template_dependent_p
= dependent_type_p (element_type
)
3543 || type_dependent_expression_p (size
)
3544 || value_dependent_expression_p (size
);
3545 if (!template_dependent_p
)
3546 processing_template_decl
--;
3548 tree itype
= compute_array_index_type (name
, size
, tf_error
);
3549 tree type
= build_cplus_array_type (element_type
, itype
);
3551 if (template_dependent_p
)
3552 processing_template_decl
--;
3554 return convert_out (ctx
->preserve (type
));
3558 plugin_build_vla_array_type (cc1_plugin::connection
*self
,
3559 gcc_type element_type_in
,
3560 const char *upper_bound_name
)
3562 tree element_type
= convert_in (element_type_in
);
3563 tree upper_bound
= lookup_name (get_identifier (upper_bound_name
));
3564 tree size
= fold_build2 (PLUS_EXPR
, TREE_TYPE (upper_bound
), upper_bound
,
3565 build_one_cst (TREE_TYPE (upper_bound
)));
3566 tree range
= compute_array_index_type (NULL_TREE
, size
,
3569 tree result
= build_cplus_array_type (element_type
, range
);
3571 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3572 return convert_out (ctx
->preserve (result
));
3576 plugin_build_qualified_type (cc1_plugin::connection
*,
3577 gcc_type unqualified_type_in
,
3578 enum gcc_cp_qualifiers qualifiers
)
3580 tree unqualified_type
= convert_in (unqualified_type_in
);
3581 cp_cv_quals quals
= 0;
3583 if ((qualifiers
& GCC_CP_QUALIFIER_CONST
) != 0)
3584 quals
|= TYPE_QUAL_CONST
;
3585 if ((qualifiers
& GCC_CP_QUALIFIER_VOLATILE
) != 0)
3586 quals
|= TYPE_QUAL_VOLATILE
;
3587 if ((qualifiers
& GCC_CP_QUALIFIER_RESTRICT
) != 0)
3588 quals
|= TYPE_QUAL_RESTRICT
;
3590 gcc_assert ((TREE_CODE (unqualified_type
) != METHOD_TYPE
3591 && TREE_CODE (unqualified_type
) != REFERENCE_TYPE
)
3594 return convert_out (build_qualified_type (unqualified_type
, quals
));
3598 plugin_build_complex_type (cc1_plugin::connection
*self
,
3601 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3602 return convert_out (ctx
->preserve (build_complex_type (convert_in (base_type
))));
3606 plugin_build_vector_type (cc1_plugin::connection
*self
,
3607 gcc_type base_type
, int nunits
)
3609 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3610 return convert_out (ctx
->preserve (build_vector_type (convert_in (base_type
),
3615 plugin_build_constant (cc1_plugin::connection
*self
, gcc_type type_in
,
3616 const char *name
, unsigned long value
,
3617 const char *filename
, unsigned int line_number
)
3619 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3621 tree type
= convert_in (type_in
);
3623 cst
= build_int_cst (type
, value
);
3624 if (!TYPE_READONLY (type
))
3625 type
= build_qualified_type (type
, TYPE_QUAL_CONST
);
3626 decl
= build_decl (ctx
->get_source_location (filename
, line_number
),
3627 VAR_DECL
, get_identifier (name
), type
);
3628 TREE_STATIC (decl
) = 1;
3629 TREE_READONLY (decl
) = 1;
3630 cp_finish_decl (decl
, cst
, true, NULL
, LOOKUP_ONLYCONVERTING
);
3631 safe_pushdecl_maybe_friend (decl
, false);
3637 plugin_error (cc1_plugin::connection
*,
3638 const char *message
)
3640 error ("%s", message
);
3641 return convert_out (error_mark_node
);
3645 plugin_add_static_assert (cc1_plugin::connection
*self
,
3646 gcc_expr condition_in
,
3647 const char *errormsg
,
3648 const char *filename
,
3649 unsigned int line_number
)
3651 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
3652 tree condition
= convert_in (condition_in
);
3657 tree message
= build_string (strlen (errormsg
) + 1, errormsg
);
3659 TREE_TYPE (message
) = char_array_type_node
;
3660 fix_string_type (message
);
3662 source_location loc
= ctx
->get_source_location (filename
, line_number
);
3664 bool member_p
= at_class_scope_p ();
3666 finish_static_assert (condition
, message
, loc
, member_p
);
3673 // Perform GC marking.
3676 gc_mark (void *, void *)
3678 if (current_context
!= NULL
)
3679 current_context
->mark ();
3683 #pragma GCC visibility push(default)
3687 plugin_init (struct plugin_name_args
*plugin_info
,
3688 struct plugin_gcc_version
*)
3691 for (int i
= 0; i
< plugin_info
->argc
; ++i
)
3693 if (strcmp (plugin_info
->argv
[i
].key
, "fd") == 0)
3697 fd
= strtol (plugin_info
->argv
[i
].value
, &tail
, 0);
3698 if (*tail
!= '\0' || errno
!= 0)
3699 fatal_error (input_location
,
3700 "%s: invalid file descriptor argument to plugin",
3701 plugin_info
->base_name
);
3706 fatal_error (input_location
,
3707 "%s: required plugin argument %<fd%> is missing",
3708 plugin_info
->base_name
);
3710 current_context
= new plugin_context (fd
);
3713 cc1_plugin::protocol_int version
;
3714 if (!current_context
->require ('H')
3715 || ! ::cc1_plugin::unmarshall (current_context
, &version
))
3716 fatal_error (input_location
,
3717 "%s: handshake failed", plugin_info
->base_name
);
3718 if (version
!= GCC_CP_FE_VERSION_0
)
3719 fatal_error (input_location
,
3720 "%s: unknown version in handshake", plugin_info
->base_name
);
3722 register_callback (plugin_info
->base_name
, PLUGIN_PRAGMAS
,
3723 plugin_init_extra_pragmas
, NULL
);
3724 register_callback (plugin_info
->base_name
, PLUGIN_PRE_GENERICIZE
,
3725 rewrite_decls_to_addresses
, NULL
);
3726 register_callback (plugin_info
->base_name
, PLUGIN_GGC_MARKING
,
3729 lang_hooks
.print_error_function
= plugin_print_error_function
;
3731 #define GCC_METHOD0(R, N) \
3733 cc1_plugin::callback_ftype *fun \
3734 = cc1_plugin::callback<R, plugin_ ## N>; \
3735 current_context->add_callback (# N, fun); \
3737 #define GCC_METHOD1(R, N, A) \
3739 cc1_plugin::callback_ftype *fun \
3740 = cc1_plugin::callback<R, A, plugin_ ## N>; \
3741 current_context->add_callback (# N, fun); \
3743 #define GCC_METHOD2(R, N, A, B) \
3745 cc1_plugin::callback_ftype *fun \
3746 = cc1_plugin::callback<R, A, B, plugin_ ## N>; \
3747 current_context->add_callback (# N, fun); \
3749 #define GCC_METHOD3(R, N, A, B, C) \
3751 cc1_plugin::callback_ftype *fun \
3752 = cc1_plugin::callback<R, A, B, C, plugin_ ## N>; \
3753 current_context->add_callback (# N, fun); \
3755 #define GCC_METHOD4(R, N, A, B, C, D) \
3757 cc1_plugin::callback_ftype *fun \
3758 = cc1_plugin::callback<R, A, B, C, D, \
3760 current_context->add_callback (# N, fun); \
3762 #define GCC_METHOD5(R, N, A, B, C, D, E) \
3764 cc1_plugin::callback_ftype *fun \
3765 = cc1_plugin::callback<R, A, B, C, D, E, \
3767 current_context->add_callback (# N, fun); \
3769 #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
3771 cc1_plugin::callback_ftype *fun \
3772 = cc1_plugin::callback<R, A, B, C, D, E, F, G, \
3774 current_context->add_callback (# N, fun); \
3777 #include "gcc-cp-fe.def"