1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/* Some code common to C++ and ObjC++ front ends.
Copyright (C) 2004 Free Software Foundation, Inc.
Contributed by Ziemowit Laski <zlaski@apple.com>
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#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"
/* Special routine to get the alias set for C++. */
HOST_WIDE_INT
cxx_get_alias_set (tree t)
{
if (IS_FAKE_BASE_TYPE (t))
/* The base variant of a type must be in the same alias set as the
complete type. */
return get_alias_set (TYPE_CONTEXT (t));
/* Punt on PMFs until we canonicalize functions properly. */
if (TYPE_PTRMEMFUNC_P (t))
return 0;
return c_common_get_alias_set (t);
}
/* Called from check_global_declarations. */
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;
/* Const variables take the place of #defines in C++. */
if (TREE_CODE (decl) == VAR_DECL && TREE_READONLY (decl))
return false;
return true;
}
/* Langhook for expr_size: Tell the backend that the value of an expression
of non-POD class type does not include any tail padding; a derived class
might have allocated something there. */
tree
cp_expr_size (tree exp)
{
if (CLASS_TYPE_P (TREE_TYPE (exp)))
{
/* The backend should not be interested in the size of an expression
of a type with both of these set; all copies of such types must go
through a constructor or assignment op. */
gcc_assert (!TYPE_HAS_COMPLEX_INIT_REF (TREE_TYPE (exp))
|| !TYPE_HAS_COMPLEX_ASSIGN_REF (TREE_TYPE (exp))
/* But storing a CONSTRUCTOR isn't a copy. */
|| TREE_CODE (exp) == CONSTRUCTOR);
/* This would be wrong for a type with virtual bases, but they are
caught by the assert above. */
return (is_empty_class (TREE_TYPE (exp))
? size_zero_node
: CLASSTYPE_SIZE_UNIT (TREE_TYPE (exp)));
}
else
/* Use the default code. */
return lhd_expr_size (exp);
}
/* Langhook for tree_size: determine size of our 'x' and 'c' nodes. */
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 ();
}
/* NOTREACHED */
}
/* Returns true if T is a variably modified type, in the sense of C99.
FN is as passed to variably_modified_p.
This routine needs only check cases that cannot be handled by the
language-independent logic in tree.c. */
bool
cp_var_mod_type_p (tree type, tree fn)
{
/* If TYPE is a pointer-to-member, it is variably modified if either
the class or the member are variably modified. */
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));
/* All other types are not variably modified. */
return false;
}
/* Construct a C++-aware pretty-printer for CONTEXT. It is assumed
that CONTEXT->printer is an already constructed basic pretty_printer. */
void
cxx_initialize_diagnostics (diagnostic_context *context)
{
pretty_printer *base = context->printer;
cxx_pretty_printer *pp = xmalloc (sizeof (cxx_pretty_printer));
memcpy (pp_base (pp), base, sizeof (pretty_printer));
pp_cxx_pretty_printer_init (pp);
context->printer = (pretty_printer *) pp;
/* It is safe to free this object because it was previously malloc()'d. */
free (base);
}
/* Stubs to keep c-opts.c happy. */
void
push_file_scope (void)
{
}
void
pop_file_scope (void)
{
}
/* c-pragma.c needs to query whether a decl has extern "C" linkage. */
bool
has_c_linkage (tree decl)
{
return DECL_EXTERN_C_P (decl);
}
|