1 /* Language-dependent hooks for C++.
2 Copyright 2001 Free Software Foundation, Inc.
3 Contributed by Alexandre Oliva <aoliva@redhat.com>
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 #include "langhooks.h"
29 #include "langhooks-def.h"
31 static HOST_WIDE_INT cxx_get_alias_set
PARAMS ((tree
));
32 static bool ok_to_generate_alias_set_for_type
PARAMS ((tree
));
34 #undef LANG_HOOKS_NAME
35 #define LANG_HOOKS_NAME "GNU C++"
36 #undef LANG_HOOKS_INIT
37 #define LANG_HOOKS_INIT cxx_init
38 #undef LANG_HOOKS_FINISH
39 #define LANG_HOOKS_FINISH cxx_finish
40 #undef LANG_HOOKS_CLEAR_BINDING_STACK
41 #define LANG_HOOKS_CLEAR_BINDING_STACK pop_everything
42 #undef LANG_HOOKS_INIT_OPTIONS
43 #define LANG_HOOKS_INIT_OPTIONS cxx_init_options
44 #undef LANG_HOOKS_DECODE_OPTION
45 #define LANG_HOOKS_DECODE_OPTION cxx_decode_option
46 #undef LANG_HOOKS_POST_OPTIONS
47 #define LANG_HOOKS_POST_OPTIONS cxx_post_options
48 #undef LANG_HOOKS_GET_ALIAS_SET
49 #define LANG_HOOKS_GET_ALIAS_SET cxx_get_alias_set
50 #undef LANG_HOOKS_EXPAND_CONSTANT
51 #define LANG_HOOKS_EXPAND_CONSTANT cplus_expand_constant
52 #undef LANG_HOOKS_EXPAND_EXPR
53 #define LANG_HOOKS_EXPAND_EXPR cxx_expand_expr
54 #undef LANG_HOOKS_SAFE_FROM_P
55 #define LANG_HOOKS_SAFE_FROM_P c_safe_from_p
56 #undef LANG_HOOKS_PARSE_FILE
57 #define LANG_HOOKS_PARSE_FILE c_common_parse_file
58 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
59 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL cxx_dup_lang_specific_decl
60 #undef LANG_HOOKS_UNSAVE_EXPR_NOW
61 #define LANG_HOOKS_UNSAVE_EXPR_NOW cxx_unsave_expr_now
62 #undef LANG_HOOKS_MAYBE_BUILD_CLEANUP
63 #define LANG_HOOKS_MAYBE_BUILD_CLEANUP cxx_maybe_build_cleanup
64 #undef LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES
65 #define LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES cxx_insert_default_attributes
66 #undef LANG_HOOKS_MARK_TREE
67 #define LANG_HOOKS_MARK_TREE cxx_mark_tree
68 #undef LANG_HOOKS_UNSAFE_FOR_REEVAL
69 #define LANG_HOOKS_UNSAFE_FOR_REEVAL c_common_unsafe_for_reeval
70 #undef LANG_HOOKS_PRINT_STATISTICS
71 #define LANG_HOOKS_PRINT_STATISTICS cxx_print_statistics
72 #undef LANG_HOOKS_PRINT_XNODE
73 #define LANG_HOOKS_PRINT_XNODE cxx_print_xnode
74 #undef LANG_HOOKS_PRINT_DECL
75 #define LANG_HOOKS_PRINT_DECL cxx_print_decl
76 #undef LANG_HOOKS_PRINT_TYPE
77 #define LANG_HOOKS_PRINT_TYPE cxx_print_type
78 #undef LANG_HOOKS_PRINT_IDENTIFIER
79 #define LANG_HOOKS_PRINT_IDENTIFIER cxx_print_identifier
80 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
81 #define LANG_HOOKS_DECL_PRINTABLE_NAME cxx_printable_name
82 #undef LANG_HOOKS_PRINT_ERROR_FUNCTION
83 #define LANG_HOOKS_PRINT_ERROR_FUNCTION cxx_print_error_function
84 #undef LANG_HOOKS_SET_YYDEBUG
85 #define LANG_HOOKS_SET_YYDEBUG cxx_set_yydebug
87 #undef LANG_HOOKS_TREE_INLINING_WALK_SUBTREES
88 #define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES \
90 #undef LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN
91 #define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \
92 cp_cannot_inline_tree_fn
93 #undef LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS
94 #define LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS \
95 cp_add_pending_fn_decls
96 #undef LANG_HOOKS_TREE_INLINING_TREE_CHAIN_MATTERS_P
97 #define LANG_HOOKS_TREE_INLINING_TREE_CHAIN_MATTERS_P \
99 #undef LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P
100 #define LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P \
102 #undef LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING
103 #define LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING \
104 cp_copy_res_decl_for_inlining
105 #undef LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P
106 #define LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P anon_aggr_type_p
107 #undef LANG_HOOKS_TREE_INLINING_START_INLINING
108 #define LANG_HOOKS_TREE_INLINING_START_INLINING cp_start_inlining
109 #undef LANG_HOOKS_TREE_INLINING_END_INLINING
110 #define LANG_HOOKS_TREE_INLINING_END_INLINING cp_end_inlining
111 #undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN
112 #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN cp_dump_tree
113 #undef LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN
114 #define LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN cp_type_quals
116 #undef LANG_HOOKS_MAKE_TYPE
117 #define LANG_HOOKS_MAKE_TYPE cxx_make_type
118 #undef LANG_HOOKS_TYPE_FOR_MODE
119 #define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode
120 #undef LANG_HOOKS_TYPE_FOR_SIZE
121 #define LANG_HOOKS_TYPE_FOR_SIZE c_common_type_for_size
122 #undef LANG_HOOKS_SIGNED_TYPE
123 #define LANG_HOOKS_SIGNED_TYPE c_common_signed_type
124 #undef LANG_HOOKS_UNSIGNED_TYPE
125 #define LANG_HOOKS_UNSIGNED_TYPE c_common_unsigned_type
126 #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
127 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE c_common_signed_or_unsigned_type
129 /* Each front end provides its own hooks, for toplev.c. */
130 const struct lang_hooks lang_hooks
= LANG_HOOKS_INITIALIZER
;
132 /* Check if a C++ type is safe for aliasing.
133 Return TRUE if T safe for aliasing FALSE otherwise. */
136 ok_to_generate_alias_set_for_type (t
)
139 if (TYPE_PTRMEMFUNC_P (t
))
141 if (AGGREGATE_TYPE_P (t
))
143 if ((TREE_CODE (t
) == RECORD_TYPE
) || (TREE_CODE (t
) == UNION_TYPE
))
147 if (! CLASSTYPE_NON_POD_P(t
))
149 /* Classes with virtual baseclasses are not. */
150 if (TYPE_USES_VIRTUAL_BASECLASSES (t
))
152 /* Recursively check the base classes. */
153 if (TYPE_BINFO (t
) != NULL
&& TYPE_BINFO_BASETYPES (t
) != NULL
)
156 for (i
= 0; i
< TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (t
)); i
++)
158 tree binfo
= TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t
), i
);
159 if (!ok_to_generate_alias_set_for_type (BINFO_TYPE (binfo
)))
163 /* Check all the fields. */
164 for (fields
= TYPE_FIELDS (t
); fields
; fields
= TREE_CHAIN (fields
))
166 if (TREE_CODE (fields
) != FIELD_DECL
)
168 if (! ok_to_generate_alias_set_for_type (TREE_TYPE (fields
)))
173 else if (TREE_CODE (t
) == ARRAY_TYPE
)
174 return ok_to_generate_alias_set_for_type (TREE_TYPE (t
));
176 /* This should never happen, we dealt with all the aggregate
177 types that can appear in C++ above. */
184 /* Tree code classes. */
186 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
188 const char tree_code_type
[] = {
191 #include "c-common.def"
193 #include "cp-tree.def"
197 /* Table indexed by tree code giving number of expression
198 operands beyond the fixed part of the node structure.
199 Not used for types or decls. */
201 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
203 const unsigned char tree_code_length
[] = {
206 #include "c-common.def"
208 #include "cp-tree.def"
212 /* Names of tree components.
213 Used for printing out the tree and error messages. */
214 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
216 const char *const tree_code_name
[] = {
219 #include "c-common.def"
221 #include "cp-tree.def"
225 /* Special routine to get the alias set for C++. */
228 cxx_get_alias_set (t
)
231 /* It's not yet safe to use alias sets for classes in C++. */
232 if (!ok_to_generate_alias_set_for_type(t
))
235 return c_common_get_alias_set (t
);