OSDN Git Service

2002-03-06 Dan Nicolaescu <dann@ics.uci.edu>
[pf3gnuchains/gcc-fork.git] / gcc / cp / cp-lang.c
1 /* Language-dependent hooks for C++.
2    Copyright 2001 Free Software Foundation, Inc.
3    Contributed by Alexandre Oliva  <aoliva@redhat.com>
4
5 This file is part of GNU CC.
6
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)
10 any later version.
11
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.
16
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.  */
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
31 static HOST_WIDE_INT cxx_get_alias_set PARAMS ((tree));
32 static bool ok_to_generate_alias_set_for_type 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 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_SAFE_FROM_P
53 #define LANG_HOOKS_SAFE_FROM_P c_safe_from_p
54 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
55 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL cxx_dup_lang_specific_decl
56 #undef LANG_HOOKS_UNSAVE_EXPR_NOW
57 #define LANG_HOOKS_UNSAVE_EXPR_NOW cxx_unsave_expr_now
58 #undef LANG_HOOKS_PRINT_STATISTICS
59 #define LANG_HOOKS_PRINT_STATISTICS cxx_print_statistics
60 #undef LANG_HOOKS_PRINT_XNODE
61 #define LANG_HOOKS_PRINT_XNODE cxx_print_xnode
62 #undef LANG_HOOKS_PRINT_DECL
63 #define LANG_HOOKS_PRINT_DECL cxx_print_decl
64 #undef LANG_HOOKS_PRINT_TYPE
65 #define LANG_HOOKS_PRINT_TYPE cxx_print_type
66 #undef LANG_HOOKS_PRINT_IDENTIFIER
67 #define LANG_HOOKS_PRINT_IDENTIFIER cxx_print_identifier
68 #undef LANG_HOOKS_SET_YYDEBUG
69 #define LANG_HOOKS_SET_YYDEBUG cxx_set_yydebug
70
71 #undef LANG_HOOKS_TREE_INLINING_WALK_SUBTREES
72 #define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES \
73   cp_walk_subtrees
74 #undef LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN
75 #define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \
76   cp_cannot_inline_tree_fn
77 #undef LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS
78 #define LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS \
79   cp_add_pending_fn_decls
80 #undef LANG_HOOKS_TREE_INLINING_TREE_CHAIN_MATTERS_P
81 #define LANG_HOOKS_TREE_INLINING_TREE_CHAIN_MATTERS_P \
82   cp_is_overload_p
83 #undef LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P
84 #define LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P \
85   cp_auto_var_in_fn_p
86 #undef LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING
87 #define LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING \
88   cp_copy_res_decl_for_inlining
89 #undef LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P
90 #define LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P anon_aggr_type_p
91 #undef LANG_HOOKS_TREE_INLINING_START_INLINING
92 #define LANG_HOOKS_TREE_INLINING_START_INLINING cp_start_inlining
93 #undef LANG_HOOKS_TREE_INLINING_END_INLINING
94 #define LANG_HOOKS_TREE_INLINING_END_INLINING cp_end_inlining
95 #undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN
96 #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN cp_dump_tree
97 #undef LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN
98 #define LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN cp_type_quals
99
100 /* Each front end provides its own hooks, for toplev.c.  */
101 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
102
103 /* Check if a C++ type is safe for aliasing.
104    Return TRUE if T safe for aliasing FALSE otherwise.  */
105
106 static bool
107 ok_to_generate_alias_set_for_type (t)
108      tree t;
109 {
110   if (TYPE_PTRMEMFUNC_P (t))
111     return true;
112   if (AGGREGATE_TYPE_P (t))
113     {
114       if ((TREE_CODE (t) == RECORD_TYPE) || (TREE_CODE (t) == UNION_TYPE))
115         {
116           tree fields;
117           /* PODs are safe.  */
118           if (! CLASSTYPE_NON_POD_P(t))
119             return true;
120           /* Classes with virtual baseclasses are not.  */
121           if (TYPE_USES_VIRTUAL_BASECLASSES (t))
122             return false;
123           /* Recursively check the base classes.  */
124           if (TYPE_BINFO (t) != NULL && TYPE_BINFO_BASETYPES (t) != NULL)
125             {
126               int i;
127               for (i = 0; i < TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (t)); i++)
128                 {
129                   tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), i);
130                   if (!ok_to_generate_alias_set_for_type (BINFO_TYPE (binfo)))
131                     return false;
132                 }
133             }
134           /* Check all the fields.  */
135           for (fields = TYPE_FIELDS (t); fields; fields = TREE_CHAIN (fields))
136             {
137               if (TREE_CODE (fields) != FIELD_DECL)
138                 continue;
139               if (! ok_to_generate_alias_set_for_type (TREE_TYPE (fields)))
140                 return false;
141             }
142           return true;
143         }
144       else if (TREE_CODE (t) == ARRAY_TYPE)
145         return ok_to_generate_alias_set_for_type (TREE_TYPE (t));
146       else
147         /* This should never happen, we dealt with all the aggregate
148            types that can appear in C++ above.  */
149         abort ();
150     }
151   else
152     return true;
153 }
154
155 /* Special routine to get the alias set for C++.  */
156
157 static HOST_WIDE_INT
158 cxx_get_alias_set (t)
159      tree t;
160 {
161   /* It's not yet safe to use alias sets for classes in C++.  */
162   if (!ok_to_generate_alias_set_for_type(t))
163     return 0;
164
165   return c_common_get_alias_set (t);
166 }