cp-lang.c revision 107590
1/* Language-dependent hooks for C++.
2   Copyright 2001, 2002 Free Software Foundation, Inc.
3   Contributed by Alexandre Oliva  <aoliva@redhat.com>
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING.  If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA.  */
21
22#include "config.h"
23#include "system.h"
24#include "tree.h"
25#include "cp-tree.h"
26#include "c-common.h"
27#include "toplev.h"
28#include "langhooks.h"
29#include "langhooks-def.h"
30
31static HOST_WIDE_INT cxx_get_alias_set		PARAMS ((tree));
32static tree cp_expr_size			PARAMS ((tree));
33static bool cp_var_mod_type_p			PARAMS ((tree));
34
35#undef LANG_HOOKS_NAME
36#define LANG_HOOKS_NAME "GNU C++"
37#undef LANG_HOOKS_INIT
38#define LANG_HOOKS_INIT cxx_init
39#undef LANG_HOOKS_FINISH
40#define LANG_HOOKS_FINISH cxx_finish
41#undef LANG_HOOKS_CLEAR_BINDING_STACK
42#define LANG_HOOKS_CLEAR_BINDING_STACK pop_everything
43#undef LANG_HOOKS_INIT_OPTIONS
44#define LANG_HOOKS_INIT_OPTIONS cxx_init_options
45#undef LANG_HOOKS_DECODE_OPTION
46#define LANG_HOOKS_DECODE_OPTION cxx_decode_option
47#undef LANG_HOOKS_POST_OPTIONS
48#define LANG_HOOKS_POST_OPTIONS c_common_post_options
49#undef LANG_HOOKS_GET_ALIAS_SET
50#define LANG_HOOKS_GET_ALIAS_SET cxx_get_alias_set
51#undef LANG_HOOKS_EXPAND_CONSTANT
52#define LANG_HOOKS_EXPAND_CONSTANT cplus_expand_constant
53#undef LANG_HOOKS_SAFE_FROM_P
54#define LANG_HOOKS_SAFE_FROM_P c_safe_from_p
55#undef LANG_HOOKS_PRINT_STATISTICS
56#define LANG_HOOKS_PRINT_STATISTICS cxx_print_statistics
57#undef LANG_HOOKS_PRINT_XNODE
58#define LANG_HOOKS_PRINT_XNODE cxx_print_xnode
59#undef LANG_HOOKS_PRINT_DECL
60#define LANG_HOOKS_PRINT_DECL cxx_print_decl
61#undef LANG_HOOKS_PRINT_TYPE
62#define LANG_HOOKS_PRINT_TYPE cxx_print_type
63#undef LANG_HOOKS_PRINT_IDENTIFIER
64#define LANG_HOOKS_PRINT_IDENTIFIER cxx_print_identifier
65#undef LANG_HOOKS_SET_YYDEBUG
66#define LANG_HOOKS_SET_YYDEBUG cxx_set_yydebug
67
68#undef LANG_HOOKS_TREE_INLINING_WALK_SUBTREES
69#define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES \
70  cp_walk_subtrees
71#undef LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN
72#define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \
73  cp_cannot_inline_tree_fn
74#undef LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS
75#define LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS \
76  cp_add_pending_fn_decls
77#undef LANG_HOOKS_TREE_INLINING_TREE_CHAIN_MATTERS_P
78#define LANG_HOOKS_TREE_INLINING_TREE_CHAIN_MATTERS_P \
79  cp_is_overload_p
80#undef LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P
81#define LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P \
82  cp_auto_var_in_fn_p
83#undef LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING
84#define LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING \
85  cp_copy_res_decl_for_inlining
86#undef LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P
87#define LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P anon_aggr_type_p
88#undef LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P
89#define LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P cp_var_mod_type_p
90#undef LANG_HOOKS_TREE_INLINING_START_INLINING
91#define LANG_HOOKS_TREE_INLINING_START_INLINING cp_start_inlining
92#undef LANG_HOOKS_TREE_INLINING_END_INLINING
93#define LANG_HOOKS_TREE_INLINING_END_INLINING cp_end_inlining
94#undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN
95#define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN cp_dump_tree
96#undef LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN
97#define LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN cp_type_quals
98#undef LANG_HOOKS_EXPR_SIZE
99#define LANG_HOOKS_EXPR_SIZE cp_expr_size
100
101/* Each front end provides its own hooks, for toplev.c.  */
102const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
103
104/* Special routine to get the alias set for C++.  */
105
106static HOST_WIDE_INT
107cxx_get_alias_set (t)
108     tree t;
109{
110  /* It's not yet safe to use alias sets for classes in C++ because
111     the TYPE_FIELDs list for a class doesn't mention base classes.  */
112  if (AGGREGATE_TYPE_P (t))
113    return 0;
114
115  return c_common_get_alias_set (t);
116}
117
118/* Langhook for expr_size: Tell the backend that the value of an expression
119   of non-POD class type does not include any tail padding; a derived class
120   might have allocated something there.  */
121
122static tree
123cp_expr_size (exp)
124     tree exp;
125{
126  if (CLASS_TYPE_P (TREE_TYPE (exp)))
127    {
128      /* This would be wrong for a type with virtual bases, but they should
129	 not get here.  */
130      return CLASSTYPE_SIZE_UNIT (TREE_TYPE (exp));
131    }
132  else
133    /* Use the default code.  */
134    return lhd_expr_size (exp);
135}
136
137/* Returns true if T is a variably modified type, in the sense of C99.
138   This routine needs only check cases that cannot be handled by the
139   language-independent logic in tree-inline.c.  */
140
141static bool
142cp_var_mod_type_p (tree type)
143{
144  /* If TYPE is a pointer-to-member, it is variably modified if either
145     the class or the member are variably modified.  */
146  if (TYPE_PTRMEM_P (type) || TYPE_PTRMEMFUNC_P (type))
147    return (variably_modified_type_p (TYPE_PTRMEM_CLASS_TYPE (type))
148	    || variably_modified_type_p (TYPE_PTRMEM_POINTED_TO_TYPE (type)));
149
150  /* All other types are not variably modified.  */
151  return false;
152}
153
154