cp-lang.c revision 102780
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));
33
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 c_common_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_SAFE_FROM_P
53#define LANG_HOOKS_SAFE_FROM_P c_safe_from_p
54#undef LANG_HOOKS_PRINT_STATISTICS
55#define LANG_HOOKS_PRINT_STATISTICS cxx_print_statistics
56#undef LANG_HOOKS_PRINT_XNODE
57#define LANG_HOOKS_PRINT_XNODE cxx_print_xnode
58#undef LANG_HOOKS_PRINT_DECL
59#define LANG_HOOKS_PRINT_DECL cxx_print_decl
60#undef LANG_HOOKS_PRINT_TYPE
61#define LANG_HOOKS_PRINT_TYPE cxx_print_type
62#undef LANG_HOOKS_PRINT_IDENTIFIER
63#define LANG_HOOKS_PRINT_IDENTIFIER cxx_print_identifier
64#undef LANG_HOOKS_SET_YYDEBUG
65#define LANG_HOOKS_SET_YYDEBUG cxx_set_yydebug
66
67#undef LANG_HOOKS_TREE_INLINING_WALK_SUBTREES
68#define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES \
69  cp_walk_subtrees
70#undef LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN
71#define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \
72  cp_cannot_inline_tree_fn
73#undef LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS
74#define LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS \
75  cp_add_pending_fn_decls
76#undef LANG_HOOKS_TREE_INLINING_TREE_CHAIN_MATTERS_P
77#define LANG_HOOKS_TREE_INLINING_TREE_CHAIN_MATTERS_P \
78  cp_is_overload_p
79#undef LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P
80#define LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P \
81  cp_auto_var_in_fn_p
82#undef LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING
83#define LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING \
84  cp_copy_res_decl_for_inlining
85#undef LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P
86#define LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P anon_aggr_type_p
87#undef LANG_HOOKS_TREE_INLINING_START_INLINING
88#define LANG_HOOKS_TREE_INLINING_START_INLINING cp_start_inlining
89#undef LANG_HOOKS_TREE_INLINING_END_INLINING
90#define LANG_HOOKS_TREE_INLINING_END_INLINING cp_end_inlining
91#undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN
92#define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN cp_dump_tree
93#undef LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN
94#define LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN cp_type_quals
95#undef LANG_HOOKS_EXPR_SIZE
96#define LANG_HOOKS_EXPR_SIZE cp_expr_size
97
98/* Each front end provides its own hooks, for toplev.c.  */
99const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
100
101/* Special routine to get the alias set for C++.  */
102
103static HOST_WIDE_INT
104cxx_get_alias_set (t)
105     tree t;
106{
107  /* It's not yet safe to use alias sets for classes in C++ because
108     the TYPE_FIELDs list for a class doesn't mention base classes.  */
109  if (AGGREGATE_TYPE_P (t))
110    return 0;
111
112  return c_common_get_alias_set (t);
113}
114
115/* Langhook for expr_size: Tell the backend that the value of an expression
116   of non-POD class type does not include any tail padding; a derived class
117   might have allocated something there.  */
118
119static tree
120cp_expr_size (exp)
121     tree exp;
122{
123  if (CLASS_TYPE_P (TREE_TYPE (exp)))
124    {
125      /* The backend should not be interested in the size of an expression
126	 of a type with both of these set; all copies of such types must go
127	 through a constructor or assignment op.  */
128      if (TYPE_HAS_COMPLEX_INIT_REF (TREE_TYPE (exp))
129	  && TYPE_HAS_COMPLEX_ASSIGN_REF (TREE_TYPE (exp)))
130	abort ();
131      /* This would be wrong for a type with virtual bases, but they are
132	 caught by the abort above.  */
133      return CLASSTYPE_SIZE_UNIT (TREE_TYPE (exp));
134    }
135  else
136    /* Use the default code.  */
137    return lhd_expr_size (exp);
138}
139