diff options
author | Alex Samuel <samuel@codesourcery.com> | 2000-05-28 02:58:19 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2000-05-28 02:58:19 +0000 |
commit | 596ea4e574aa9177437b95dcb2412e0673df8c0a (patch) | |
tree | e69d1900e45d7c20303ea928d731e1f70c7ec263 /gcc/cp/method.c | |
parent | 4f1c5cce901c4d53fb9130183ca275ef1d04fe8a (diff) | |
download | gcc-596ea4e574aa9177437b95dcb2412e0673df8c0a.tar.gz |
cp-tree.h (ansi_opname): Make it a macro.
2000-05-27 Alex Samuel <samuel@codesourcery.com>
Mark Mitchell <mark@codesourcery.com>
* cp-tree.h (ansi_opname): Make it a macro.
(ansi_assopname): Likewise.
(struct lang_decl_flags): Add assignment_operator_p.
(struct lang_decl): Add operator_code.
(DECL_VTT_PARM): Adjust.
(DECL_OVERLOADED_OPERATOR_P): Return the operator_code for an
overloaded operator.
(SET_OVERLOADED_OPERATOR_CODE): New macro.
(DECL_ASSIGNMENT_OPERATOR_P): New macro.
(DECL_ARRAY_DELETE_OPERATOR_P): Adjust.
(opname_tab): Remove.
(assignop_tab): Likewise.
(operator_name_info_t): New type.
(operator_name_info): New variable.
(assignment_operator_name_info): Likewise.
(build_cp_library_fn): Remove declaration.
(push_cp_library_fn): Likewise.
(operator_name_string): Likewise.
(build_decl_overload): Likewise.
* call.c (print_z_candidates): Simplify.
(build_object_call): Adjust usage of ansi_opname. Use
DECL_OVERLOADED_OPERATOR_P.
(op_error): Adjust operator name lookup.
(build_conditional_expr): Adjust usage of ansi_opname.
(build_new_op): Likewise.
(build_op_delete_call): Likewise.
(build_over_call): Likewise.
(joust): Use DECL_OVERLOADED_OPERATOR_P.
* decl.c (duplicate_decls): Copy operator_code.
(init_decl_processing): Adjust parameters to push_cp_library_fn.
(builtin_function): Adjust parameters to build_library_fn_1.
(build_library_fn_1): Accept an overloaded operator code.
(build_library_fn): Pass ERROR_MARK.
(build_cp_library_fn): Accept an overloaded operator code.
(push_cp_library_fn): Likewise.
(grokfndecl): Tweak.
(grokdeclarator): Simplify code to compute names of overloaded
operators. Adjust use of ansi_opname.
(ambi_op_p): Work on tree_codes, not identifiers.
(unary_op_p): Likewise.
(grok_op_properties): Likewise.
(start_function): Use DECL_OVERLOADED_OPERATOR_P.
(lang_mark_tree): Don't try to mark the operator_code.
* decl2.c (grok_function_init): Use DECL_OVERLOADED_OPERATOR_P.
* error.c (dump_decl): Remove special handling for operator
names.
(dump_function_name): Likewise.
(dump_expr): Adjust name lookup of operators.
(op_to_string): Simplify.
(assop_to_string): Likewise.
* init.c (build_new_1): Adjust use of ansi_opname.
* lex.c (opname_tab): Remove.
(assignop_tab): Likewise.
(ansi_opname): Likewise.
(ansi_assopname): Likewise.
(operator_name_string): Likewise.
(reinit_lang_specific): Likewise.
(operator_name_info): New variable.
(assignment_operator_name_info): Likewise.
(init_operators): New function.
(init_parse): Use it.
(do_identifier): Adjust use of ansi_opname.
* method.c (mangle_expression): Don't use ansi_opname for
mangling.
(build_decl_overload_real): Use DECL_OVERLOADED_OPERATOR_P.
(build_decl_overload): Remove.
(build_typename_overload): Use OPERATOR_TYPENAME_FORMAT directly.
(do_build_assign_ref): Adjust use of ansi_opname.
(synthesize_method): Likewise.
(implicitly_declare_fn): Likewise.
* operators.def: New file.
* parse.y (operator): Adjust use of ansi_opname.
* pt.c (tsubst_decl): Use IDENTIFIER_OPNAME_P.
(set_mangled_name_for_template_decl): Don't play games with
current_namespace.
(special_function_p): Adjust use of ansi_opname.
* typeck.c (check_return_expr): Likewise.
* Make-lang.in (cc1plus): Depend on operators.def.
* Makefile.in (lex.o): Likewise.
(decl.o): Likewise.
Co-Authored-By: Mark Mitchell <mark@codesourcery.com>
From-SVN: r34223
Diffstat (limited to 'gcc/cp/method.c')
-rw-r--r-- | gcc/cp/method.c | 105 |
1 files changed, 48 insertions, 57 deletions
diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 1f595e05015..13d627ad17b 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -520,12 +520,10 @@ mangle_expression (value) { int i; int operands = TREE_CODE_LENGTH (TREE_CODE (value)); - tree id; const char *name; - id = ansi_opname [(int) TREE_CODE (value)]; - my_friendly_assert (id != NULL_TREE, 0); - name = IDENTIFIER_POINTER (id); + name = operator_name_info[TREE_CODE (value)].mangled_name; + my_friendly_assert (name != NULL, 0); if (name[0] != '_' || name[1] != '_') /* On some erroneous inputs, we can get here with VALUE a LOOKUP_EXPR. In that case, the NAME will be the @@ -1576,31 +1574,47 @@ build_static_name (context, name) of a class (including a static member) and 2 if the declaration is for a constructor. */ tree -build_decl_overload_real (dname, parms, ret_type, tparms, targs, +build_decl_overload_real (decl, parms, ret_type, tparms, targs, for_method) - tree dname; + tree decl; tree parms; tree ret_type; tree tparms; tree targs; int for_method; { - const char *name = IDENTIFIER_POINTER (dname); + const char *name; + enum tree_code operator_code; + + operator_code = DECL_OVERLOADED_OPERATOR_P (decl); + if (!DECL_CONV_FN_P (decl) && operator_code) + { + /* member operators new and delete look like methods at this + point. */ + if (! for_method && CP_DECL_CONTEXT (decl) == global_namespace + && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST + && TREE_CHAIN (parms) == void_list_node) + switch (operator_code) + { + case DELETE_EXPR: + return get_identifier ("__builtin_delete"); + case VEC_DELETE_EXPR: + return get_identifier ("__builtin_vec_delete"); + case NEW_EXPR: + return get_identifier ("__builtin_new"); + case VEC_NEW_EXPR: + return get_identifier ("__builtin_vec_new"); + default: + break; + } - /* member operators new and delete look like methods at this point. */ - if (! for_method && current_namespace == global_namespace - && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST - && TREE_CHAIN (parms) == void_list_node) - { - if (dname == ansi_opname[(int) DELETE_EXPR]) - return get_identifier ("__builtin_delete"); - else if (dname == ansi_opname[(int) VEC_DELETE_EXPR]) - return get_identifier ("__builtin_vec_delete"); - if (dname == ansi_opname[(int) NEW_EXPR]) - return get_identifier ("__builtin_new"); - else if (dname == ansi_opname[(int) VEC_NEW_EXPR]) - return get_identifier ("__builtin_vec_new"); + if (DECL_ASSIGNMENT_OPERATOR_P (decl)) + name = assignment_operator_name_info[(int) operator_code].mangled_name; + else + name = operator_name_info[(int) operator_code].mangled_name; } + else + name = IDENTIFIER_POINTER (DECL_NAME (decl)); start_squangling (); OB_INIT (); @@ -1618,15 +1632,12 @@ build_decl_overload_real (dname, parms, ret_type, tparms, targs, build_template_parm_names (tparms, targs); OB_PUTC ('_'); } - else if (!for_method && current_namespace == global_namespace) - /* XXX this works only if we call this in the same namespace - as the declaration. Unfortunately, we don't have the _DECL, - only its name */ + else if (!for_method && CP_DECL_CONTEXT (decl) == global_namespace) OB_PUTC ('F'); - if (!for_method && current_namespace != global_namespace) + if (!for_method && CP_DECL_CONTEXT (decl) != global_namespace) /* qualify with namespace */ - build_qualified_name (current_namespace); + build_qualified_name (CP_DECL_CONTEXT (decl)); if (parms == NULL_TREE) OB_PUTC ('e'); @@ -1639,7 +1650,7 @@ build_decl_overload_real (dname, parms, ret_type, tparms, targs, /* Allocate typevec array. */ size_t typevec_size = list_length (parms); maxtype = 0; - if (!for_method && current_namespace != global_namespace) + if (!for_method && CP_DECL_CONTEXT (decl) != global_namespace) /* The namespace of a global function needs one slot. */ typevec_size++; VARRAY_TREE_INIT (typevec, typevec_size, "typevec"); @@ -1668,11 +1679,11 @@ build_decl_overload_real (dname, parms, ret_type, tparms, targs, { /* the namespace qualifier for a global function will count as type */ - if (current_namespace != global_namespace + if (CP_DECL_CONTEXT (decl) != global_namespace && !flag_do_squangling) { my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387); - VARRAY_TREE (typevec, maxtype) = current_namespace; + VARRAY_TREE (typevec, maxtype) = CP_DECL_CONTEXT (decl); maxtype++; } build_mangled_name (parms, 0, 0); @@ -1694,31 +1705,10 @@ build_decl_overload_real (dname, parms, ret_type, tparms, targs, end_squangling (); { tree n = get_identifier (obstack_base (&scratch_obstack)); - if (IDENTIFIER_OPNAME_P (dname)) - IDENTIFIER_OPNAME_P (n) = 1; return n; } } -/* Change the name of a function definition so that it may be - overloaded. NAME is the name of the function to overload, - PARMS is the parameter list (which determines what name the - final function obtains). - - FOR_METHOD is 1 if this overload is being performed - for a method, rather than a function type. It is 2 if - this overload is being performed for a constructor. */ - -tree -build_decl_overload (dname, parms, for_method) - tree dname; - tree parms; - int for_method; -{ - return build_decl_overload_real (dname, parms, NULL_TREE, NULL_TREE, - NULL_TREE, for_method); -} - /* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */ void @@ -1746,9 +1736,10 @@ set_mangled_name_for_decl (decl) 0); DECL_ASSEMBLER_NAME (decl) - = build_decl_overload (DECL_NAME (decl), parm_types, - DECL_FUNCTION_MEMBER_P (decl) - + DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl)); + = build_decl_overload_real (decl, parm_types, NULL_TREE, + NULL_TREE, NULL_TREE, + DECL_FUNCTION_MEMBER_P (decl) + + DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl)); } /* Build an overload name for the type expression TYPE. */ @@ -1760,7 +1751,7 @@ build_typename_overload (type) tree id; OB_INIT (); - OB_PUTID (ansi_opname[(int) TYPE_EXPR]); + OB_PUTS (OPERATOR_TYPENAME_FORMAT); nofold = 1; start_squangling (); build_mangled_name (type, 0, 1); @@ -2367,7 +2358,7 @@ do_build_assign_ref (fndecl) (build_reference_type (basetype), parm, CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE); p = convert_from_reference (p); - p = build_member_call (basetype, ansi_opname [MODIFY_EXPR], + p = build_member_call (basetype, ansi_assopname (NOP_EXPR), build_tree_list (NULL_TREE, p)); finish_expr_stmt (p); } @@ -2467,7 +2458,7 @@ synthesize_method (fndecl) store_parm_decls (); clear_last_expr (); - if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR]) + if (DECL_OVERLOADED_OPERATOR_P (fndecl) == NOP_EXPR) { do_build_assign_ref (fndecl); need_body = 0; @@ -2550,7 +2541,7 @@ implicitly_declare_fn (kind, type, const_p) if (const_p) type = build_qualified_type (type, TYPE_QUAL_CONST); - name = ansi_opname [(int) MODIFY_EXPR]; + name = ansi_assopname (NOP_EXPR); argtype = build_reference_type (type); args = tree_cons (NULL_TREE, |