diff options
author | zlaski <zlaski@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-08-31 18:51:08 +0000 |
---|---|---|
committer | zlaski <zlaski@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-08-31 18:51:08 +0000 |
commit | 5dd72fac96c929241cb29234116abbb5b30e1bb4 (patch) | |
tree | dff740e6130eb0b1821f2508cf868efe2cd89df2 /gcc/cp/cp-objcp-common.c | |
parent | 70e7a6995f7814387608da040bf9eca670652453 (diff) | |
download | gcc-5dd72fac96c929241cb29234116abbb5b30e1bb4.tar.gz |
2004-08-31 Ziemowit Laski <zlaski@apple.com>
* Make-lang.in (CXX_AND_OBJCXX_OBJS): Add cp/cp-objcp-common.o.
(cp/cp-lang.o): Depend on debug.h, gtype-cp.h and cp/cp-objcp-common.h.
(cp/cp-decl.c): Do not depend on gtype-cp.h.
(cp/cp-objcp-common.o): New target.
* cp-lang.c: Include debug.h, cp-objcp-common.h and gtype-cp.h.
(cxx_get_alias_set, cxx_warn_unused_global_decl, cp_expr_size,
cp_tree_size, cp_var_mod_type_p, cxx_initialize_diagnostics): Move
prototypes and definitions to cp-objcp-common.h and cp-objcp-common.c,
respectively.
(LANG_HOOKS_TREE_SIZE, LANG_HOOKS_FINISH,
LANG_HOOKS_CLEAR_BINDING_STACK, LANG_HOOKS_INIT_OPTIONS,
LANG_HOOKS_INITIALIZE_DIAGNOSTICS, LANG_HOOKS_HANDLE_OPTION,
LANG_HOOKS_HANDLE_FILENAME, LANG_HOOKS_MISSING_ARGUMENT,
LANG_HOOKS_POST_OPTIONS, LANG_HOOKS_GET_ALIAS_SET,
LANG_HOOKS_EXPAND_CONSTANT, LANG_HOOKS_EXPAND_EXPR,
LANG_HOOKS_EXPAND_DECL, LANG_HOOKS_PARSE_FILE,
LANG_HOOKS_DUP_LANG_SPECIFIC_DECL, LANG_HOOKS_TRUTHVALUE_CONVERSION,
LANG_HOOKS_SET_DECL_ASSEMBLER_NAME, LANG_HOOKS_MARK_ADDRESSABLE,
LANG_HOOKS_PRINT_STATISTICS, LANG_HOOKS_PRINT_XNODE,
LANG_HOOKS_PRINT_DECL, LANG_HOOKS_PRINT_TYPE,
LANG_HOOKS_PRINT_IDENTIFIER, LANG_HOOKS_PRINT_ERROR_FUNCTION,
LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL, LANG_HOOKS_WRITE_GLOBALS,
LANG_HOOKS_FUNCTION_INIT, LANG_HOOKS_FUNCTION_FINAL,
LANG_HOOKS_FUNCTION_MISSING_NORETURN_OK_P,
LANG_HOOKS_COMMON_ATTRIBUTE_TABLE, LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE,
LANG_HOOKS_ATTRIBUTE_TABLE, LANG_HOOKS_TREE_INLINING_WALK_SUBTREES,
LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN,
LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS,
LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P,
LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P,
LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P,
LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN,
LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN, LANG_HOOKS_EXPR_SIZE,
LANG_HOOKS_CALLGRAPH_ANALYZE_EXPR,
LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION, LANG_HOOKS_MAKE_TYPE,
LANG_HOOKS_TYPE_FOR_MODE, LANG_HOOKS_TYPE_FOR_SIZE,
LANG_HOOKS_SIGNED_TYPE, LANG_HOOKS_UNSIGNED_TYPE,
LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE, LANG_HOOKS_INCOMPLETE_TYPE_ERROR,
LANG_HOOKS_TYPE_PROMOTES_TO, LANG_HOOKS_REGISTER_BUILTIN_TYPE,
LANG_HOOKS_GIMPLIFY_EXPR, LANG_HOOKS_FOLD_OBJ_TYPE_REF): Move
hooks to cp-objcp-common.h.
(finish_file): New function.
* cp-objcp-common.c: New file.
* cp-objcp-common.h: New file.
* cp-tree.h (cp_finish_file): New prototype.
* decl.c: Do not include gtype-cp.h.
* decl2.c (finish_file): Rename to cp_finish_file.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@86837 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/cp-objcp-common.c')
-rw-r--r-- | gcc/cp/cp-objcp-common.c | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c new file mode 100644 index 00000000000..b8b8bad6a86 --- /dev/null +++ b/gcc/cp/cp-objcp-common.c @@ -0,0 +1,167 @@ +/* Some code common to C++ and ObjC++ front ends. + Copyright (C) 2004 Free Software Foundation, Inc. + Contributed by Ziemowit Laski <zlaski@apple.com> + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "tree.h" +#include "cp-tree.h" +#include "c-common.h" +#include "toplev.h" +#include "langhooks.h" +#include "langhooks-def.h" +#include "diagnostic.h" +#include "debug.h" +#include "cxx-pretty-print.h" +#include "cp-objcp-common.h" + +/* Special routine to get the alias set for C++. */ + +HOST_WIDE_INT +cxx_get_alias_set (tree t) +{ + if (IS_FAKE_BASE_TYPE (t)) + /* The base variant of a type must be in the same alias set as the + complete type. */ + return get_alias_set (TYPE_CONTEXT (t)); + + /* Punt on PMFs until we canonicalize functions properly. */ + if (TYPE_PTRMEMFUNC_P (t)) + return 0; + + return c_common_get_alias_set (t); +} + +/* Called from check_global_declarations. */ + +bool +cxx_warn_unused_global_decl (tree decl) +{ + if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl)) + return false; + if (DECL_IN_SYSTEM_HEADER (decl)) + return false; + + /* Const variables take the place of #defines in C++. */ + if (TREE_CODE (decl) == VAR_DECL && TREE_READONLY (decl)) + return false; + + return true; +} + +/* Langhook for expr_size: Tell the backend that the value of an expression + of non-POD class type does not include any tail padding; a derived class + might have allocated something there. */ + +tree +cp_expr_size (tree exp) +{ + if (CLASS_TYPE_P (TREE_TYPE (exp))) + { + /* The backend should not be interested in the size of an expression + of a type with both of these set; all copies of such types must go + through a constructor or assignment op. */ + gcc_assert (!TYPE_HAS_COMPLEX_INIT_REF (TREE_TYPE (exp)) + || !TYPE_HAS_COMPLEX_ASSIGN_REF (TREE_TYPE (exp)) + /* But storing a CONSTRUCTOR isn't a copy. */ + || TREE_CODE (exp) == CONSTRUCTOR); + + /* This would be wrong for a type with virtual bases, but they are + caught by the assert above. */ + return (is_empty_class (TREE_TYPE (exp)) + ? size_zero_node + : CLASSTYPE_SIZE_UNIT (TREE_TYPE (exp))); + } + else + /* Use the default code. */ + return lhd_expr_size (exp); +} + +/* Langhook for tree_size: determine size of our 'x' and 'c' nodes. */ +size_t +cp_tree_size (enum tree_code code) +{ + switch (code) + { + case TINST_LEVEL: return sizeof (struct tinst_level_s); + case PTRMEM_CST: return sizeof (struct ptrmem_cst); + case BASELINK: return sizeof (struct tree_baselink); + case TEMPLATE_PARM_INDEX: return sizeof (template_parm_index); + case DEFAULT_ARG: return sizeof (struct tree_default_arg); + case OVERLOAD: return sizeof (struct tree_overload); + default: + gcc_unreachable (); + } + /* NOTREACHED */ +} + +/* Returns true if T is a variably modified type, in the sense of C99. + FN is as passed to variably_modified_p. + This routine needs only check cases that cannot be handled by the + language-independent logic in tree.c. */ + +bool +cp_var_mod_type_p (tree type, tree fn) +{ + /* If TYPE is a pointer-to-member, it is variably modified if either + the class or the member are variably modified. */ + if (TYPE_PTR_TO_MEMBER_P (type)) + return (variably_modified_type_p (TYPE_PTRMEM_CLASS_TYPE (type), fn) + || variably_modified_type_p (TYPE_PTRMEM_POINTED_TO_TYPE (type), + fn)); + + /* All other types are not variably modified. */ + return false; +} + +/* Construct a C++-aware pretty-printer for CONTEXT. It is assumed + that CONTEXT->printer is an already constructed basic pretty_printer. */ +void +cxx_initialize_diagnostics (diagnostic_context *context) +{ + pretty_printer *base = context->printer; + cxx_pretty_printer *pp = xmalloc (sizeof (cxx_pretty_printer)); + memcpy (pp_base (pp), base, sizeof (pretty_printer)); + pp_cxx_pretty_printer_init (pp); + context->printer = (pretty_printer *) pp; + + /* It is safe to free this object because it was previously malloc()'d. */ + free (base); +} + +/* Stubs to keep c-opts.c happy. */ +void +push_file_scope (void) +{ +} + +void +pop_file_scope (void) +{ +} + +/* c-pragma.c needs to query whether a decl has extern "C" linkage. */ +bool +has_c_linkage (tree decl) +{ + return DECL_EXTERN_C_P (decl); +} |