1 /* Some code common to C++ and ObjC++ front ends.
2 Copyright (C) 2004-2017 Free Software Foundation, Inc.
3 Contributed by Ziemowit Laski <zlaski@apple.com>
5 This file is part of GCC.
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/>. */
23 #include "coretypes.h"
25 #include "cp-objcp-common.h"
28 /* Special routine to get the alias set for C++. */
31 cxx_get_alias_set (tree t
)
33 if (IS_FAKE_BASE_TYPE (t
))
34 /* The base variant of a type must be in the same alias set as the
36 return get_alias_set (TYPE_CONTEXT (t
));
38 /* Punt on PMFs until we canonicalize functions properly. */
39 if (TYPE_PTRMEMFUNC_P (t
)
40 || (POINTER_TYPE_P (t
)
41 && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
))))
44 return c_common_get_alias_set (t
);
47 /* Called from check_global_declaration. */
50 cxx_warn_unused_global_decl (const_tree decl
)
52 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (decl
))
54 if (DECL_IN_SYSTEM_HEADER (decl
))
60 /* Langhook for tree_size: determine size of our 'x' and 'c' nodes. */
62 cp_tree_size (enum tree_code code
)
66 case PTRMEM_CST
: return sizeof (struct ptrmem_cst
);
67 case BASELINK
: return sizeof (struct tree_baselink
);
68 case TEMPLATE_PARM_INDEX
: return sizeof (template_parm_index
);
69 case DEFAULT_ARG
: return sizeof (struct tree_default_arg
);
70 case DEFERRED_NOEXCEPT
: return sizeof (struct tree_deferred_noexcept
);
71 case OVERLOAD
: return sizeof (struct tree_overload
);
72 case STATIC_ASSERT
: return sizeof (struct tree_static_assert
);
73 case TYPE_ARGUMENT_PACK
:
74 case TYPE_PACK_EXPANSION
:
75 return sizeof (struct tree_common
);
77 case NONTYPE_ARGUMENT_PACK
:
78 case EXPR_PACK_EXPANSION
:
79 return sizeof (struct tree_exp
);
81 case ARGUMENT_PACK_SELECT
:
82 return sizeof (struct tree_argument_pack_select
);
85 return sizeof (struct tree_trait_expr
);
87 case LAMBDA_EXPR
: return sizeof (struct tree_lambda_expr
);
89 case TEMPLATE_INFO
: return sizeof (struct tree_template_info
);
91 case CONSTRAINT_INFO
: return sizeof (struct tree_constraint_info
);
93 case USERDEF_LITERAL
: return sizeof (struct tree_userdef_literal
);
95 case TEMPLATE_DECL
: return sizeof (struct tree_template_decl
);
98 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
99 return sizeof (struct tree_decl_non_common
);
105 /* Returns true if T is a variably modified type, in the sense of C99.
106 FN is as passed to variably_modified_p.
107 This routine needs only check cases that cannot be handled by the
108 language-independent logic in tree.c. */
111 cp_var_mod_type_p (tree type
, tree fn
)
113 /* If TYPE is a pointer-to-member, it is variably modified if either
114 the class or the member are variably modified. */
115 if (TYPE_PTRMEM_P (type
))
116 return (variably_modified_type_p (TYPE_PTRMEM_CLASS_TYPE (type
), fn
)
117 || variably_modified_type_p (TYPE_PTRMEM_POINTED_TO_TYPE (type
),
120 /* All other types are not variably modified. */
124 /* This compares two types for equivalence ("compatible" in C-based languages).
125 This routine should only return 1 if it is sure. It should not be used
126 in contexts where erroneously returning 0 causes problems. */
129 cxx_types_compatible_p (tree x
, tree y
)
131 return same_type_ignoring_top_level_qualifiers_p (x
, y
);
134 /* Return a type to use in the debug info instead of TYPE, or NULL_TREE to
138 cp_get_debug_type (const_tree type
)
140 if (TYPE_PTRMEMFUNC_P (type
) && !typedef_variant_p (type
))
141 return build_offset_type (TYPE_PTRMEMFUNC_OBJECT_TYPE (type
),
142 TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type
)));
147 /* Return -1 if dwarf ATTR shouldn't be added for DECL, or the attribute
150 cp_decl_dwarf_attribute (const_tree decl
, int attr
)
152 if (decl
== NULL_TREE
)
158 if (TREE_CODE (decl
) == FUNCTION_DECL
159 && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl
))
160 && DECL_NONCONVERTING_P (decl
))
165 if (TREE_CODE (decl
) == FUNCTION_DECL
166 && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl
))
167 && DECL_DELETED_FN (decl
))
171 case DW_AT_defaulted
:
172 if (TREE_CODE (decl
) == FUNCTION_DECL
173 && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl
))
174 && DECL_DEFAULTED_FN (decl
))
176 if (DECL_DEFAULTED_IN_CLASS_P (decl
))
177 return DW_DEFAULTED_in_class
;
179 if (DECL_DEFAULTED_OUTSIDE_CLASS_P (decl
))
180 return DW_DEFAULTED_out_of_class
;
184 case DW_AT_const_expr
:
185 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_DECLARED_CONSTEXPR_P (decl
))
189 case DW_AT_reference
:
190 if (TREE_CODE (decl
) == FUNCTION_DECL
191 && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl
)
192 && FUNCTION_REF_QUALIFIED (TREE_TYPE (decl
))
193 && !FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (decl
)))
197 case DW_AT_rvalue_reference
:
198 if (TREE_CODE (decl
) == FUNCTION_DECL
199 && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl
)
200 && FUNCTION_REF_QUALIFIED (TREE_TYPE (decl
))
201 && FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (decl
)))
206 if (VAR_P (decl
) && DECL_INLINE_VAR_P (decl
))
208 if (DECL_VAR_DECLARED_INLINE_P (decl
))
209 return DW_INL_declared_inlined
;
211 return DW_INL_inlined
;
222 /* Return -1 if dwarf ATTR shouldn't be added for TYPE, or the attribute
225 cp_type_dwarf_attribute (const_tree type
, int attr
)
227 if (type
== NULL_TREE
)
232 case DW_AT_reference
:
233 if ((TREE_CODE (type
) == FUNCTION_TYPE
234 || TREE_CODE (type
) == METHOD_TYPE
)
235 && FUNCTION_REF_QUALIFIED (type
)
236 && !FUNCTION_RVALUE_QUALIFIED (type
))
240 case DW_AT_rvalue_reference
:
241 if ((TREE_CODE (type
) == FUNCTION_TYPE
242 || TREE_CODE (type
) == METHOD_TYPE
)
243 && FUNCTION_REF_QUALIFIED (type
)
244 && FUNCTION_RVALUE_QUALIFIED (type
))
255 /* Return the unit size of TYPE without reusable tail padding. */
258 cp_unit_size_without_reusable_padding (tree type
)
260 if (CLASS_TYPE_P (type
))
261 return CLASSTYPE_SIZE_UNIT (type
);
262 return TYPE_SIZE_UNIT (type
);
265 /* Stubs to keep c-opts.c happy. */
267 push_file_scope (void)
272 pop_file_scope (void)
276 /* c-pragma.c needs to query whether a decl has extern "C" linkage. */
278 has_c_linkage (const_tree decl
)
280 return DECL_EXTERN_C_P (decl
);
284 hash_table
<tree_decl_map_cache_hasher
> *shadowed_var_for_decl
;
286 /* Lookup a shadowed var for FROM, and return it if we find one. */
289 decl_shadowed_for_var_lookup (tree from
)
291 struct tree_decl_map
*h
, in
;
294 h
= shadowed_var_for_decl
->find_with_hash (&in
, DECL_UID (from
));
300 /* Insert a mapping FROM->TO in the shadowed var hashtable. */
303 decl_shadowed_for_var_insert (tree from
, tree to
)
305 struct tree_decl_map
*h
;
307 h
= ggc_alloc
<tree_decl_map
> ();
310 *shadowed_var_for_decl
->find_slot_with_hash (h
, DECL_UID (from
), INSERT
) = h
;
314 init_shadowed_var_for_decl (void)
316 shadowed_var_for_decl
317 = hash_table
<tree_decl_map_cache_hasher
>::create_ggc (512);
320 /* Return true if stmt can fall through. Used by block_may_fallthru
324 cxx_block_may_fallthru (const_tree stmt
)
326 switch (TREE_CODE (stmt
))
329 return block_may_fallthru (EXPR_STMT_EXPR (stmt
));
339 /* Return the list of decls in the global namespace. */
342 cp_get_global_decls ()
344 return NAMESPACE_LEVEL (global_namespace
)->names
;
347 /* Push DECL into the current scope. */
350 cp_pushdecl (tree decl
)
352 return pushdecl (decl
);
355 /* Register c++-specific dumps. */
358 cp_register_dumps (gcc::dump_manager
*dumps
)
360 class_dump_id
= dumps
->dump_register
361 (".class", "lang-class", "lang-class", DK_lang
, OPTGROUP_NONE
, false);
363 raw_dump_id
= dumps
->dump_register
364 (".raw", "lang-raw", "lang-raw", DK_lang
, OPTGROUP_NONE
, false);
368 cp_common_init_ts (void)
370 MARK_TS_DECL_NON_COMMON (USING_DECL
);
371 MARK_TS_DECL_COMMON (TEMPLATE_DECL
);
372 MARK_TS_DECL_COMMON (WILDCARD_DECL
);
374 MARK_TS_COMMON (TEMPLATE_TEMPLATE_PARM
);
375 MARK_TS_COMMON (TEMPLATE_TYPE_PARM
);
376 MARK_TS_COMMON (TEMPLATE_PARM_INDEX
);
377 MARK_TS_COMMON (OVERLOAD
);
378 MARK_TS_COMMON (TEMPLATE_INFO
);
379 MARK_TS_COMMON (TYPENAME_TYPE
);
380 MARK_TS_COMMON (TYPEOF_TYPE
);
381 MARK_TS_COMMON (UNDERLYING_TYPE
);
382 MARK_TS_COMMON (BASELINK
);
383 MARK_TS_COMMON (TYPE_PACK_EXPANSION
);
384 MARK_TS_COMMON (TYPE_ARGUMENT_PACK
);
385 MARK_TS_COMMON (DECLTYPE_TYPE
);
386 MARK_TS_COMMON (BOUND_TEMPLATE_TEMPLATE_PARM
);
387 MARK_TS_COMMON (UNBOUND_CLASS_TEMPLATE
);
389 MARK_TS_TYPED (EXPR_PACK_EXPANSION
);
390 MARK_TS_TYPED (SWITCH_STMT
);
391 MARK_TS_TYPED (IF_STMT
);
392 MARK_TS_TYPED (FOR_STMT
);
393 MARK_TS_TYPED (RANGE_FOR_STMT
);
394 MARK_TS_TYPED (AGGR_INIT_EXPR
);
395 MARK_TS_TYPED (EXPR_STMT
);
396 MARK_TS_TYPED (EH_SPEC_BLOCK
);
397 MARK_TS_TYPED (CLEANUP_STMT
);
398 MARK_TS_TYPED (SCOPE_REF
);
399 MARK_TS_TYPED (CAST_EXPR
);
400 MARK_TS_TYPED (NON_DEPENDENT_EXPR
);
401 MARK_TS_TYPED (MODOP_EXPR
);
402 MARK_TS_TYPED (TRY_BLOCK
);
403 MARK_TS_TYPED (THROW_EXPR
);
404 MARK_TS_TYPED (HANDLER
);
405 MARK_TS_TYPED (REINTERPRET_CAST_EXPR
);
406 MARK_TS_TYPED (CONST_CAST_EXPR
);
407 MARK_TS_TYPED (STATIC_CAST_EXPR
);
408 MARK_TS_TYPED (DYNAMIC_CAST_EXPR
);
409 MARK_TS_TYPED (IMPLICIT_CONV_EXPR
);
410 MARK_TS_TYPED (TEMPLATE_ID_EXPR
);
411 MARK_TS_TYPED (ARROW_EXPR
);
412 MARK_TS_TYPED (SIZEOF_EXPR
);
413 MARK_TS_TYPED (ALIGNOF_EXPR
);
414 MARK_TS_TYPED (AT_ENCODE_EXPR
);
415 MARK_TS_TYPED (UNARY_PLUS_EXPR
);
416 MARK_TS_TYPED (TRAIT_EXPR
);
417 MARK_TS_TYPED (TYPE_ARGUMENT_PACK
);
418 MARK_TS_TYPED (NOEXCEPT_EXPR
);
419 MARK_TS_TYPED (NONTYPE_ARGUMENT_PACK
);
420 MARK_TS_TYPED (WHILE_STMT
);
421 MARK_TS_TYPED (NEW_EXPR
);
422 MARK_TS_TYPED (VEC_NEW_EXPR
);
423 MARK_TS_TYPED (BREAK_STMT
);
424 MARK_TS_TYPED (MEMBER_REF
);
425 MARK_TS_TYPED (DOTSTAR_EXPR
);
426 MARK_TS_TYPED (DO_STMT
);
427 MARK_TS_TYPED (DELETE_EXPR
);
428 MARK_TS_TYPED (VEC_DELETE_EXPR
);
429 MARK_TS_TYPED (CONTINUE_STMT
);
430 MARK_TS_TYPED (TAG_DEFN
);
431 MARK_TS_TYPED (PSEUDO_DTOR_EXPR
);
432 MARK_TS_TYPED (TYPEID_EXPR
);
433 MARK_TS_TYPED (MUST_NOT_THROW_EXPR
);
434 MARK_TS_TYPED (STMT_EXPR
);
435 MARK_TS_TYPED (OFFSET_REF
);
436 MARK_TS_TYPED (OFFSETOF_EXPR
);
437 MARK_TS_TYPED (ADDRESSOF_EXPR
);
438 MARK_TS_TYPED (PTRMEM_CST
);
439 MARK_TS_TYPED (EMPTY_CLASS_EXPR
);
440 MARK_TS_TYPED (VEC_INIT_EXPR
);
441 MARK_TS_TYPED (USING_STMT
);
442 MARK_TS_TYPED (LAMBDA_EXPR
);
443 MARK_TS_TYPED (CTOR_INITIALIZER
);
444 MARK_TS_TYPED (ARRAY_NOTATION_REF
);
445 MARK_TS_TYPED (REQUIRES_EXPR
);
446 MARK_TS_TYPED (UNARY_LEFT_FOLD_EXPR
);
447 MARK_TS_TYPED (UNARY_RIGHT_FOLD_EXPR
);
448 MARK_TS_TYPED (BINARY_LEFT_FOLD_EXPR
);
449 MARK_TS_TYPED (BINARY_RIGHT_FOLD_EXPR
);
452 #include "gt-cp-cp-objcp-common.h"