#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "cp-tree.h"
#include "c-common.h"
#include "toplev.h"
#include "langhooks.h"
#include "langhooks-def.h"
#include "diagnostic.h"
#include "debug.h"
#include "cxx-pretty-print.h"
#include "cp-objcp-common.h"
HOST_WIDE_INT
cxx_get_alias_set (tree t)
{
if (IS_FAKE_BASE_TYPE (t))
return get_alias_set (TYPE_CONTEXT (t));
if (TYPE_PTRMEMFUNC_P (t))
return 0;
return c_common_get_alias_set (t);
}
bool
cxx_warn_unused_global_decl (tree decl)
{
if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl))
return false;
if (DECL_IN_SYSTEM_HEADER (decl))
return false;
if (TREE_CODE (decl) == VAR_DECL && TREE_READONLY (decl))
return false;
return true;
}
tree
cp_expr_size (tree exp)
{
tree type = TREE_TYPE (exp);
if (CLASS_TYPE_P (type))
{
gcc_assert (!TYPE_HAS_COMPLEX_INIT_REF (type)
|| !TYPE_HAS_COMPLEX_ASSIGN_REF (type)
|| TREE_CODE (exp) == CONSTRUCTOR
|| CP_AGGREGATE_TYPE_P (type));
return (is_empty_class (type)
? size_zero_node
: CLASSTYPE_SIZE_UNIT (type));
}
else
return lhd_expr_size (exp);
}
int
cp_empty_type_p (tree exp)
{
gcc_assert(TYPE_P(exp));
if (VOID_TYPE_P(exp))
return 0;
if (CLASS_TYPE_P(exp)
&& (TYPE_HAS_COMPLEX_INIT_REF(exp)
|| TYPE_HAS_COMPLEX_ASSIGN_REF(exp)))
return 0;
return is_empty_class(exp);
}
size_t
cp_tree_size (enum tree_code code)
{
switch (code)
{
case TINST_LEVEL: return sizeof (struct tinst_level_s);
case PTRMEM_CST: return sizeof (struct ptrmem_cst);
case BASELINK: return sizeof (struct tree_baselink);
case TEMPLATE_PARM_INDEX: return sizeof (template_parm_index);
case DEFAULT_ARG: return sizeof (struct tree_default_arg);
case OVERLOAD: return sizeof (struct tree_overload);
default:
gcc_unreachable ();
}
}
bool
cp_var_mod_type_p (tree type, tree fn)
{
if (TYPE_PTR_TO_MEMBER_P (type))
return (variably_modified_type_p (TYPE_PTRMEM_CLASS_TYPE (type), fn)
|| variably_modified_type_p (TYPE_PTRMEM_POINTED_TO_TYPE (type),
fn));
return false;
}
void
cxx_initialize_diagnostics (diagnostic_context *context)
{
pretty_printer *base = context->printer;
cxx_pretty_printer *pp = XNEW (cxx_pretty_printer);
memcpy (pp_base (pp), base, sizeof (pretty_printer));
pp_cxx_pretty_printer_init (pp);
context->printer = (pretty_printer *) pp;
free (base);
}
int
cxx_types_compatible_p (tree x, tree y)
{
if (same_type_ignoring_top_level_qualifiers_p (x, y))
return 1;
if (POINTER_TYPE_P (x) && POINTER_TYPE_P (y)
&& TYPE_MODE (x) == TYPE_MODE (y)
&& TYPE_REF_CAN_ALIAS_ALL (x) == TYPE_REF_CAN_ALIAS_ALL (y)
&& same_type_p (TREE_TYPE (x), TREE_TYPE (y)))
return 1;
return 0;
}
tree
cxx_staticp (tree arg)
{
switch (TREE_CODE (arg))
{
case BASELINK:
return staticp (BASELINK_FUNCTIONS (arg));
default:
break;
}
return NULL_TREE;
}
void
push_file_scope (void)
{
}
void
pop_file_scope (void)
{
}
bool
has_c_linkage (tree decl)
{
return DECL_EXTERN_C_P (decl);
}
int
cp_vtable_p (tree t)
{
if (TREE_CODE (t) == VAR_DECL
&& TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
&& TREE_TYPE (TREE_TYPE (t)) == vtable_entry_type)
return 1;
return 0;
}
static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
htab_t shadowed_var_for_decl;
tree
decl_shadowed_for_var_lookup (tree from)
{
struct tree_map *h, in;
in.from = from;
h = (struct tree_map *) htab_find_with_hash (shadowed_var_for_decl, &in,
htab_hash_pointer (from));
if (h)
return h->to;
return NULL_TREE;
}
void
decl_shadowed_for_var_insert (tree from, tree to)
{
struct tree_map *h;
void **loc;
h = GGC_NEW (struct tree_map);
h->hash = htab_hash_pointer (from);
h->from = from;
h->to = to;
loc = htab_find_slot_with_hash (shadowed_var_for_decl, h, h->hash, INSERT);
*(struct tree_map **) loc = h;
}
void
init_shadowed_var_for_decl (void)
{
shadowed_var_for_decl = htab_create_ggc (512, tree_map_hash,
tree_map_eq, 0);
}
tree
c_return_interface_record_type (tree typename)
{
enum tree_code_class class;
enum tree_code code;
tree retval = NULL;
if (typename == NULL)
return retval;
code = TREE_CODE (typename);
class = TREE_CODE_CLASS (code);
if (code != IDENTIFIER_NODE
|| class != tcc_exceptional)
return retval;
if (TREE_TYPE (typename)
&& TREE_CODE (TREE_TYPE (typename)) == RECORD_TYPE)
retval = TREE_TYPE (typename);
if (retval
&& TREE_CODE (retval) != RECORD_TYPE)
retval = NULL;
return retval;
}
#include "gt-cp-cp-objcp-common.h"