00001 /* Some code common to C++ and ObjC++ front ends. 00002 Copyright (C) 2004 Free Software Foundation, Inc. 00003 Contributed by Ziemowit Laski <zlaski@apple.com> 00004 00005 This file is part of GCC. 00006 00007 GCC is free software; you can redistribute it and/or modify it under 00008 the terms of the GNU General Public License as published by the Free 00009 Software Foundation; either version 2, or (at your option) any later 00010 version. 00011 00012 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 00013 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with GCC; see the file COPYING. If not, write to the Free 00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 00020 02111-1307, USA. */ 00021 00022 #include "config.h" 00023 #include "system.h" 00024 #include "coretypes.h" 00025 #include "tm.h" 00026 #include "tree.h" 00027 #include "cp-tree.h" 00028 #include "c-common.h" 00029 #include "toplev.h" 00030 #include "langhooks.h" 00031 #include "langhooks-def.h" 00032 #include "diagnostic.h" 00033 #include "debug.h" 00034 #include "cxx-pretty-print.h" 00035 #include "cp-objcp-common.h" 00036 00037 /* Special routine to get the alias set for C++. */ 00038 00039 HOST_WIDE_INT 00040 cxx_get_alias_set (tree t) 00041 { 00042 if (IS_FAKE_BASE_TYPE (t)) 00043 /* The base variant of a type must be in the same alias set as the 00044 complete type. */ 00045 return get_alias_set (TYPE_CONTEXT (t)); 00046 00047 /* Punt on PMFs until we canonicalize functions properly. */ 00048 if (TYPE_PTRMEMFUNC_P (t)) 00049 return 0; 00050 00051 return c_common_get_alias_set (t); 00052 } 00053 00054 /* Called from check_global_declarations. */ 00055 00056 bool 00057 cxx_warn_unused_global_decl (tree decl) 00058 { 00059 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl)) 00060 return false; 00061 if (DECL_IN_SYSTEM_HEADER (decl)) 00062 return false; 00063 00064 /* Const variables take the place of #defines in C++. */ 00065 if (TREE_CODE (decl) == VAR_DECL && TREE_READONLY (decl)) 00066 return false; 00067 00068 return true; 00069 } 00070 00071 /* Langhook for expr_size: Tell the backend that the value of an expression 00072 of non-POD class type does not include any tail padding; a derived class 00073 might have allocated something there. */ 00074 00075 tree 00076 cp_expr_size (tree exp) 00077 { 00078 tree type = TREE_TYPE (exp); 00079 00080 if (CLASS_TYPE_P (type)) 00081 { 00082 /* The backend should not be interested in the size of an expression 00083 of a type with both of these set; all copies of such types must go 00084 through a constructor or assignment op. */ 00085 gcc_assert (!TYPE_HAS_COMPLEX_INIT_REF (type) 00086 || !TYPE_HAS_COMPLEX_ASSIGN_REF (type) 00087 /* But storing a CONSTRUCTOR isn't a copy. */ 00088 || TREE_CODE (exp) == CONSTRUCTOR 00089 /* And, the gimplifier will sometimes make a copy of 00090 an aggregate. In particular, for a case like: 00091 00092 struct S { S(); }; 00093 struct X { int a; S s; }; 00094 X x = { 0 }; 00095 00096 the gimplifier will create a temporary with 00097 static storage duration, perform static 00098 initialization of the temporary, and then copy 00099 the result. Since the "s" subobject is never 00100 constructed, this is a valid transformation. */ 00101 || CP_AGGREGATE_TYPE_P (type)); 00102 00103 /* This would be wrong for a type with virtual bases, but they are 00104 caught by the assert above. */ 00105 return (is_empty_class (type) 00106 ? size_zero_node 00107 : CLASSTYPE_SIZE_UNIT (type)); 00108 } 00109 else 00110 /* Use the default code. */ 00111 return lhd_expr_size (exp); 00112 } 00113 00114 /* Langhook for tree_size: determine size of our 'x' and 'c' nodes. */ 00115 size_t 00116 cp_tree_size (enum tree_code code) 00117 { 00118 switch (code) 00119 { 00120 case TINST_LEVEL: return sizeof (struct tinst_level_s); 00121 case PTRMEM_CST: return sizeof (struct ptrmem_cst); 00122 case BASELINK: return sizeof (struct tree_baselink); 00123 case TEMPLATE_PARM_INDEX: return sizeof (template_parm_index); 00124 case DEFAULT_ARG: return sizeof (struct tree_default_arg); 00125 case OVERLOAD: return sizeof (struct tree_overload); 00126 default: 00127 gcc_unreachable (); 00128 } 00129 /* NOTREACHED */ 00130 } 00131 00132 /* Returns true if T is a variably modified type, in the sense of C99. 00133 FN is as passed to variably_modified_p. 00134 This routine needs only check cases that cannot be handled by the 00135 language-independent logic in tree.c. */ 00136 00137 bool 00138 cp_var_mod_type_p (tree type, tree fn) 00139 { 00140 /* If TYPE is a pointer-to-member, it is variably modified if either 00141 the class or the member are variably modified. */ 00142 if (TYPE_PTR_TO_MEMBER_P (type)) 00143 return (variably_modified_type_p (TYPE_PTRMEM_CLASS_TYPE (type), fn) 00144 || variably_modified_type_p (TYPE_PTRMEM_POINTED_TO_TYPE (type), 00145 fn)); 00146 00147 /* All other types are not variably modified. */ 00148 return false; 00149 } 00150 00151 /* Construct a C++-aware pretty-printer for CONTEXT. It is assumed 00152 that CONTEXT->printer is an already constructed basic pretty_printer. */ 00153 void 00154 cxx_initialize_diagnostics (diagnostic_context *context) 00155 { 00156 pretty_printer *base = context->printer; 00157 cxx_pretty_printer *pp = xmalloc (sizeof (cxx_pretty_printer)); 00158 memcpy (pp_base (pp), base, sizeof (pretty_printer)); 00159 pp_cxx_pretty_printer_init (pp); 00160 context->printer = (pretty_printer *) pp; 00161 00162 /* It is safe to free this object because it was previously malloc()'d. */ 00163 free (base); 00164 } 00165 00166 /* This compares two types for equivalence ("compatible" in C-based languages). 00167 This routine should only return 1 if it is sure. It should not be used 00168 in contexts where erroneously returning 0 causes problems. */ 00169 00170 int 00171 cxx_types_compatible_p (tree x, tree y) 00172 { 00173 if (same_type_ignoring_top_level_qualifiers_p (x, y)) 00174 return 1; 00175 00176 /* Once we get to the middle-end, references and pointers are 00177 interchangeable. FIXME should we try to replace all references with 00178 pointers? */ 00179 if (POINTER_TYPE_P (x) && POINTER_TYPE_P (y) 00180 && TYPE_MODE (x) == TYPE_MODE (y) 00181 && TYPE_REF_CAN_ALIAS_ALL (x) == TYPE_REF_CAN_ALIAS_ALL (y) 00182 && same_type_p (TREE_TYPE (x), TREE_TYPE (y))) 00183 return 1; 00184 00185 return 0; 00186 } 00187 00188 /* Stubs to keep c-opts.c happy. */ 00189 void 00190 push_file_scope (void) 00191 { 00192 } 00193 00194 void 00195 pop_file_scope (void) 00196 { 00197 } 00198 00199 /* c-pragma.c needs to query whether a decl has extern "C" linkage. */ 00200 bool 00201 has_c_linkage (tree decl) 00202 { 00203 return DECL_EXTERN_C_P (decl); 00204 }
1.5.6