2017-10-31 Nathan Sidwell <nathan@acm.org>
+ * cp-tree.h (ovl_op_identifier): New.
+ (assign_op_identifier, call_op_identifier): Adjust.
+ (cp_operator_id, cp_assignment_operator_ide): Delete.
+ (SET_OVERLOADED_OPERATOR_CODE): Delete.
+ (OVL_OP_INFO): New.
+ * call.c (op_error): Use OVL_OP_INFO.
+ (build_conditional_expr_1): Use ovl_op_identifier.
+ (build_new_op_1): Use OVL_OP_INFO & ovl_op_identifier.
+ (build_op_delete_call): Likewise.
+ * class.c (type_requires_array_cookie): Use ovl_op_identifier.
+ * decl.c (duplicate_decls): Directly copy operator code.
+ (builtin_function_1): Do not set operator code.
+ (build_library_fn): Directly set operator code.
+ (push_cp_library_fn): Use ovl_op_identifier.
+ (grok_op_properties): Directly set operator code.
+ * decl2.c (maybe_warn_sized_delete): Use ovl_op_identifier.
+ * error.c (dump_expr): Use OVL_OP_INFO.
+ (op_to_string): Add assop arg. Use OVL_OP_INFO.
+ (assop_to_string): Delete.
+ (args_to_string): Adjust.
+ * init.c (build_new_1): Use ovl_op_identifier.
+ * mangle.c (write_unqualified_name): Use OVL_OP_INFO.
+ (write_expression): Likewise.
+ * method.c (synthesized_method_walk): Use ovl_op_identifier.
+ (implicitly_declare_fn): Use assign_op_identifier. Directly set
+ operator code.
+ * name-lookup.c (get_class_binding): Use assign_op_identifier.
+ * parser.c (cp_parser_operator): Use ovl_op_identifier.
+ (cp_parser_omp_clause_reduction): Likewise.
+ * semantics.c (omp_reduction_id): Likewise.
+ * typeck.c (cxx_sizeof_or_alignof_type): Use OVL_OP_INFO.
+
* cp-tree.h (assign_op_identifier, call_op_identifier): Define.
(LAMBDA_FUNCTION_P): Use DECL_OVERLOADED_OPERATOR_IS.
(DECL_OVERLOADED_OPERATOR_P): Just retuurn true/false.
op_error (location_t loc, enum tree_code code, enum tree_code code2,
tree arg1, tree arg2, tree arg3, bool match)
{
- const char *opname;
-
- if (code == MODIFY_EXPR)
- opname = assignment_operator_name_info[code2].name;
- else
- opname = operator_name_info[code].name;
+ bool assop = code == MODIFY_EXPR;
+ const char *opname = OVL_OP_INFO (assop, assop ? code2 : code)->name;
switch (code)
{
add_builtin_candidates (&candidates,
COND_EXPR,
NOP_EXPR,
- cp_operator_id (COND_EXPR),
+ ovl_op_identifier (false, COND_EXPR),
args,
LOOKUP_NORMAL, complain);
{
struct z_candidate *candidates = 0, *cand;
vec<tree, va_gc> *arglist;
- tree fnname;
tree args[3];
tree result = NULL_TREE;
bool result_valid_p = false;
|| error_operand_p (arg3))
return error_mark_node;
- if (code == MODIFY_EXPR)
+ bool ismodop = code == MODIFY_EXPR;
+ if (ismodop)
{
code2 = TREE_CODE (arg3);
arg3 = NULL_TREE;
- fnname = cp_assignment_operator_id (code2);
}
- else
- fnname = cp_operator_id (code);
+ tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code);
arg1 = prep_operand (arg1);
? G_("no %<%D(int)%> declared for postfix %qs,"
" trying prefix operator instead")
: G_("no %<%D(int)%> declared for postfix %qs");
- permerror (loc, msg, fnname, operator_name_info[code].name);
+ permerror (loc, msg, fnname, OVL_OP_INFO (false, code)->name);
}
if (!flag_permissive)
type = strip_array_types (TREE_TYPE (TREE_TYPE (addr)));
- fnname = cp_operator_id (code);
+ fnname = ovl_op_identifier (false, code);
if (CLASS_TYPE_P (type)
&& COMPLETE_TYPE_P (complete_type (type))
if (complain & tf_error)
error ("no suitable %<operator %s%> for %qT",
- operator_name_info[(int)code].name, type);
+ OVL_OP_INFO (false, code)->name, type);
return error_mark_node;
}
the array to the deallocation function, so we will need to store
a cookie. */
fns = lookup_fnfields (TYPE_BINFO (type),
- cp_operator_id (VEC_DELETE_EXPR),
+ ovl_op_identifier (false, VEC_DELETE_EXPR),
/*protect=*/0);
/* If there are no `operator []' members, or the lookup is
ambiguous, then we don't need a cookie. */
then deletes the entire object. */
#define deleting_dtor_identifier cp_global_trees[CPTI_DELETING_DTOR_IDENTIFIER]
-#define assign_op_identifier (cp_assignment_operator_id (NOP_EXPR))
-#define call_op_identifier (cp_operator_id (CALL_EXPR))
+#define ovl_op_identifier(ISASS, CODE) (OVL_OP_INFO(ISASS, CODE)->identifier)
+#define assign_op_identifier (ovl_op_identifier (true, NOP_EXPR))
+#define call_op_identifier (ovl_op_identifier (false, CALL_EXPR))
/* The name used for conversion operators -- but note that actual
conversion functions use special identifiers outside the identifier
table. */
#define conv_op_identifier cp_global_trees[CPTI_CONV_OP_IDENTIFIER]
-/* The name of the identifier used internally to represent operator CODE. */
-#define cp_operator_id(CODE) \
- (operator_name_info[(int) (CODE)].identifier)
-
-/* The name of the identifier used to represent assignment operator CODE,
- both simple (i.e., operator= with CODE == NOP_EXPR) and compound (e.g.,
- operator+= with CODE == PLUS_EXPR). Includes copy and move assignment.
- Use copy_fn_p() to test specifically for copy assignment. */
-#define cp_assignment_operator_id(CODE) \
- (assignment_operator_name_info[(int) (CODE)].identifier)
-
#define delta_identifier cp_global_trees[CPTI_DELTA_IDENTIFIER]
#define in_charge_identifier cp_global_trees[CPTI_IN_CHARGE_IDENTIFIER]
/* The name of the parameter that contains a pointer to the VTT to use
#define SET_VAR_HAD_UNKNOWN_BOUND(NODE) \
(DECL_LANG_SPECIFIC (VAR_DECL_CHECK (NODE))->u.base.unknown_bound_p = true)
-/* Set the overloaded operator code for NODE to CODE. */
-#define SET_OVERLOADED_OPERATOR_CODE(NODE, CODE) \
- (LANG_DECL_FN_CHECK (NODE)->operator_code = (CODE))
-
/* True iff decl NODE is for an overloaded operator. */
#define DECL_OVERLOADED_OPERATOR_P(NODE) \
IDENTIFIER_ANY_OP_P (DECL_NAME (NODE))
extern GTY(()) operator_name_info_t assignment_operator_name_info
[(int) MAX_TREE_CODES];
+/* Given an ass_op_p boolean and a tree code, return a pointer to its
+ overloaded operator info. */
+#define OVL_OP_INFO(IS_ASS_P, TREE_CODE) \
+ (((IS_ASS_P) ? assignment_operator_name_info : operator_name_info) \
+ + (TREE_CODE))
+
/* A type-qualifier, or bitmask therefore, using the TYPE_QUAL
constants. */
DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
if (DECL_OVERLOADED_OPERATOR_P (olddecl))
- SET_OVERLOADED_OPERATOR_CODE
- (newdecl, DECL_OVERLOADED_OPERATOR_CODE (olddecl));
+ DECL_OVERLOADED_OPERATOR_CODE (newdecl)
+ = DECL_OVERLOADED_OPERATOR_CODE (olddecl);
new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
/* Optionally warn about more than one declaration for the same
retrofit_lang_decl (decl);
DECL_ARTIFICIAL (decl) = 1;
- SET_OVERLOADED_OPERATOR_CODE (decl, ERROR_MARK);
SET_DECL_LANGUAGE (decl, lang_c);
/* Runtime library routines are, by definition, available in an
external shared object. */
DECL_EXTERNAL (fn) = 1;
TREE_PUBLIC (fn) = 1;
DECL_ARTIFICIAL (fn) = 1;
- SET_OVERLOADED_OPERATOR_CODE (fn, operator_code);
+ DECL_OVERLOADED_OPERATOR_CODE (fn) = operator_code;
SET_DECL_LANGUAGE (fn, lang_c);
/* Runtime library routines are, by definition, available in an
external shared object. */
push_cp_library_fn (enum tree_code operator_code, tree type,
int ecf_flags)
{
- tree fn = build_cp_library_fn (cp_operator_id (operator_code),
- operator_code,
- type, ecf_flags);
+ tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
+ operator_code, type, ecf_flags);
pushdecl (fn);
if (flag_tm)
apply_tm_attr (fn, get_identifier ("transaction_safe"));
}
while (0);
gcc_assert (operator_code != MAX_TREE_CODES);
- SET_OVERLOADED_OPERATOR_CODE (decl, operator_code);
+ DECL_OVERLOADED_OPERATOR_CODE (decl) = operator_code;
if (operator_code == NEW_EXPR || operator_code == VEC_NEW_EXPR
|| operator_code == DELETE_EXPR || operator_code == VEC_DELETE_EXPR)
gcc_unreachable ();
}
- SET_OVERLOADED_OPERATOR_CODE (decl, operator_code);
+ DECL_OVERLOADED_OPERATOR_CODE (decl) = operator_code;
if ((operator_code == POSTINCREMENT_EXPR
|| operator_code == POSTDECREMENT_EXPR)
tree sized = NULL_TREE;
tree unsized = NULL_TREE;
- for (ovl_iterator iter (get_global_binding (cp_operator_id (code)));
+ for (ovl_iterator iter (get_global_binding (ovl_op_identifier (false, code)));
iter; ++iter)
{
tree fn = *iter;
# define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
static const char *args_to_string (tree, int);
-static const char *assop_to_string (enum tree_code);
static const char *code_to_string (enum tree_code);
static const char *cv_to_string (tree, int);
static const char *decl_to_string (tree, int);
static const char *expr_to_string (tree);
static const char *fndecl_to_string (tree, int);
-static const char *op_to_string (enum tree_code);
+static const char *op_to_string (bool, enum tree_code);
static const char *parm_to_string (int);
static const char *type_to_string (tree, int);
case INIT_EXPR:
case MODIFY_EXPR:
- dump_binary_op (pp, assignment_operator_name_info[NOP_EXPR].name,
- t, flags);
+ dump_binary_op (pp, OVL_OP_INFO (true, NOP_EXPR)->name, t, flags);
break;
case PLUS_EXPR:
case EQ_EXPR:
case NE_EXPR:
case EXACT_DIV_EXPR:
- dump_binary_op (pp, operator_name_info[TREE_CODE (t)].name, t, flags);
+ dump_binary_op (pp, OVL_OP_INFO (false, TREE_CODE (t))->name, t, flags);
break;
case CEIL_DIV_EXPR:
case TRUTH_NOT_EXPR:
case PREDECREMENT_EXPR:
case PREINCREMENT_EXPR:
- dump_unary_op (pp, operator_name_info [TREE_CODE (t)].name, t, flags);
+ dump_unary_op (pp, OVL_OP_INFO (false, TREE_CODE (t))->name, t, flags);
break;
case POSTDECREMENT_EXPR:
case POSTINCREMENT_EXPR:
pp_cxx_left_paren (pp);
dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
- pp_cxx_ws_string (pp, operator_name_info[TREE_CODE (t)].name);
+ pp_cxx_ws_string (pp, OVL_OP_INFO (false, TREE_CODE (t))->name);
pp_cxx_right_paren (pp);
break;
case REALPART_EXPR:
case IMAGPART_EXPR:
- pp_cxx_ws_string (pp, operator_name_info[TREE_CODE (t)].name);
+ pp_cxx_ws_string (pp, OVL_OP_INFO (false, TREE_CODE (t))->name);
pp_cxx_whitespace (pp);
dump_expr (pp, TREE_OPERAND (t, 0), flags);
break;
}
static const char *
-op_to_string (enum tree_code p)
+op_to_string (bool assop, enum tree_code p)
{
- tree id = operator_name_info[p].identifier;
+ tree id = ovl_op_identifier (assop, p);
return id ? IDENTIFIER_POINTER (id) : M_("<unknown>");
}
return pp_ggc_formatted_text (cxx_pp);
}
-static const char *
-assop_to_string (enum tree_code p)
-{
- tree id = assignment_operator_name_info[(int) p].identifier;
- return id ? IDENTIFIER_POINTER (id) : M_("{unknown}");
-}
-
static const char *
args_to_string (tree p, int verbose)
{
case 'E': result = expr_to_string (next_tree); break;
case 'F': result = fndecl_to_string (next_tree, verbose); break;
case 'L': result = language_to_string (next_lang); break;
- case 'O': result = op_to_string (next_tcode); break;
+ case 'O': result = op_to_string (false, next_tcode); break;
case 'P': result = parm_to_string (next_int); break;
- case 'Q': result = assop_to_string (next_tcode); break;
+ case 'Q': result = op_to_string (true, next_tcode); break;
case 'S': result = subst_to_string (next_tree); break;
case 'T': result = type_to_string (next_tree, verbose); break;
case 'V': result = cv_to_string (next_tree, verbose); break;
tree fnname;
tree fns;
- fnname = cp_operator_id (array_p ? VEC_NEW_EXPR : NEW_EXPR);
+ fnname = ovl_op_identifier (false, array_p ? VEC_NEW_EXPR : NEW_EXPR);
member_new_p = !globally_qualified_p
&& CLASS_TYPE_P (elt_type)
}
else if (DECL_OVERLOADED_OPERATOR_P (decl))
{
- operator_name_info_t *oni;
- if (DECL_ASSIGNMENT_OPERATOR_P (decl))
- oni = assignment_operator_name_info;
- else
- oni = operator_name_info;
-
- write_string (oni[DECL_OVERLOADED_OPERATOR_CODE (decl)].mangled_name);
+ const char *mangled_name
+ = (OVL_OP_INFO (DECL_ASSIGNMENT_OPERATOR_P (decl),
+ DECL_OVERLOADED_OPERATOR_CODE (decl))->mangled_name);
+ write_string (mangled_name);
}
else if (UDLIT_OPER_P (DECL_NAME (decl)))
write_literal_operator_name (DECL_NAME (decl));
else if (TREE_CODE (expr) == MODOP_EXPR)
{
enum tree_code subop = TREE_CODE (TREE_OPERAND (expr, 1));
- const char *name = (assignment_operator_name_info[(int) subop]
- .mangled_name);
+ const char *name = OVL_OP_INFO (true, subop)->mangled_name;
+
write_string (name);
write_expression (TREE_OPERAND (expr, 0));
write_expression (TREE_OPERAND (expr, 2));
if (NEW_EXPR_USE_GLOBAL (expr))
write_string ("gs");
- write_string (operator_name_info[(int) code].mangled_name);
+ write_string (OVL_OP_INFO (false, code)->mangled_name);
for (t = placement; t; t = TREE_CHAIN (t))
write_expression (TREE_VALUE (t));
if (DELETE_EXPR_USE_GLOBAL (expr))
write_string ("gs");
- write_string (operator_name_info[(int) code].mangled_name);
+ write_string (OVL_OP_INFO (false, code)->mangled_name);
write_expression (TREE_OPERAND (expr, 0));
}
if (TREE_CODE (ob) == ARROW_EXPR)
{
- write_string (operator_name_info[(int)code].mangled_name);
+ write_string (OVL_OP_INFO (false, code)->mangled_name);
ob = TREE_OPERAND (ob, 0);
write_expression (ob);
}
}
/* If it wasn't any of those, recursively expand the expression. */
- name = operator_name_info[(int) code].mangled_name;
+ name = OVL_OP_INFO (false, code)->mangled_name;
/* We used to mangle const_cast and static_cast like a C cast. */
if (code == CONST_CAST_EXPR
if (abi_warn_or_compat_version_crosses (6))
G.need_abi_warning = 1;
if (!abi_version_at_least (6))
- name = operator_name_info[CAST_EXPR].mangled_name;
+ name = OVL_OP_INFO (false, CAST_EXPR)->mangled_name;
}
if (name == NULL)
if (i == 0)
{
int fcode = TREE_INT_CST_LOW (operand);
- write_string (operator_name_info[fcode].mangled_name);
+ write_string (OVL_OP_INFO (false, fcode)->mangled_name);
continue;
}
else if (code == BINARY_LEFT_FOLD_EXPR)
{
/* Unlike for base ctor/op=/dtor, for operator delete it's fine
to have a null fn (no class-specific op delete). */
- fn = locate_fn_flags (ctype, cp_operator_id (DELETE_EXPR),
+ fn = locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
ptr_type_node, flags, tf_none);
if (fn && fn == error_mark_node)
{
if (complain & tf_error)
- locate_fn_flags (ctype, cp_operator_id (DELETE_EXPR),
+ locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
ptr_type_node, flags, complain);
if (deleted_p)
*deleted_p = true;
|| kind == sfk_move_assignment)
{
return_type = build_reference_type (type);
- name = cp_assignment_operator_id (NOP_EXPR);
+ name = assign_op_identifier;
}
else
name = ctor_identifier;
if (!IDENTIFIER_CDTOR_P (name))
/* Assignment operator. */
- SET_OVERLOADED_OPERATOR_CODE (fn, NOP_EXPR);
+ DECL_OVERLOADED_OPERATOR_CODE (fn) = NOP_EXPR;
else if (IDENTIFIER_CTOR_P (name))
DECL_CXX_CONSTRUCTOR_P (fn) = true;
else
if (CLASSTYPE_LAZY_DESTRUCTOR (klass))
lazily_declare_fn (sfk_destructor, klass);
}
- else if (name == cp_assignment_operator_id (NOP_EXPR))
+ else if (name == assign_op_identifier)
{
if (CLASSTYPE_LAZY_COPY_ASSIGN (klass))
lazily_declare_fn (sfk_copy_assignment, klass);
operator token. */
if (op != ERROR_MARK)
{
- id = assop ? cp_assignment_operator_id (op) : cp_operator_id (op);
+ id = ovl_op_identifier (assop, op);
if (!consumed)
cp_lexer_consume_token (parser->lexer);
}
code = MIN_EXPR;
else if (strcmp (p, "max") == 0)
code = MAX_EXPR;
- else if (id == cp_operator_id (PLUS_EXPR))
+ else if (id == ovl_op_identifier (false, PLUS_EXPR))
code = PLUS_EXPR;
- else if (id == cp_operator_id (MULT_EXPR))
+ else if (id == ovl_op_identifier (false, MULT_EXPR))
code = MULT_EXPR;
- else if (id == cp_operator_id (MINUS_EXPR))
+ else if (id == ovl_op_identifier (false, MINUS_EXPR))
code = MINUS_EXPR;
- else if (id == cp_operator_id (BIT_AND_EXPR))
+ else if (id == ovl_op_identifier (false, BIT_AND_EXPR))
code = BIT_AND_EXPR;
- else if (id == cp_operator_id (BIT_IOR_EXPR))
+ else if (id == ovl_op_identifier (false, BIT_IOR_EXPR))
code = BIT_IOR_EXPR;
- else if (id == cp_operator_id (BIT_XOR_EXPR))
+ else if (id == ovl_op_identifier (false, BIT_XOR_EXPR))
code = BIT_XOR_EXPR;
- else if (id == cp_operator_id (TRUTH_ANDIF_EXPR))
+ else if (id == ovl_op_identifier (false, TRUTH_ANDIF_EXPR))
code = TRUTH_ANDIF_EXPR;
- else if (id == cp_operator_id (TRUTH_ORIF_EXPR))
+ else if (id == ovl_op_identifier (false, TRUTH_ORIF_EXPR))
code = TRUTH_ORIF_EXPR;
id = omp_reduction_id (code, id, NULL_TREE);
tree scope = parser->scope;
case BIT_IOR_EXPR:
case TRUTH_ANDIF_EXPR:
case TRUTH_ORIF_EXPR:
- reduction_id = cp_operator_id (reduction_code);
+ reduction_id = ovl_op_identifier (false, reduction_code);
break;
case MIN_EXPR:
p = "min";
if (complain)
pedwarn (input_location, OPT_Wpointer_arith,
"invalid application of %qs to a member function",
- operator_name_info[(int) op].name);
+ OVL_OP_INFO (false, op)->name);
else
return error_mark_node;
value = size_one_node;
+2017-10-31 Nathan Sidwell <nathan@acm.org>
+
+ * libcp1plugin.cc (plugin_build_decl): Use ovl_op_identifier.
+ Directly set operator code.
+ (plugin_build_dependent_expr): Use ovl_op_identifier.
+
2017-10-04 Nathan Sidwell <nathan@acm.org>
* libcp1plugin.cc (supplement_binding): Don't use
}
if (opcode != ERROR_MARK)
- {
- if (assop)
- identifier = cp_assignment_operator_id (opcode);
- else
- identifier = cp_operator_id (opcode);
- }
+ identifier = ovl_op_identifier (assop, opcode);
}
decl = build_lang_decl_loc (loc, code, identifier, sym_type);
/* FIXME: current_lang_name is lang_name_c while compiling an
DECL_DECLARED_INLINE_P (decl) = 1;
DECL_INITIAL (decl) = error_mark_node;
}
- if (ctor || dtor)
- {
- if (ctor)
- DECL_CXX_CONSTRUCTOR_P (decl) = 1;
- if (dtor)
- DECL_CXX_DESTRUCTOR_P (decl) = 1;
- }
- else
- {
- if ((sym_flags & GCC_CP_FLAG_SPECIAL_FUNCTION)
- && opcode != ERROR_MARK)
- SET_OVERLOADED_OPERATOR_CODE (decl, opcode);
- }
+
+ if (ctor)
+ DECL_CXX_CONSTRUCTOR_P (decl) = 1;
+ else if (dtor)
+ DECL_CXX_DESTRUCTOR_P (decl) = 1;
+ else if ((sym_flags & GCC_CP_FLAG_SPECIAL_FUNCTION)
+ && opcode != ERROR_MARK)
+ DECL_OVERLOADED_OPERATOR_CODE (decl) = opcode;
}
else if (RECORD_OR_UNION_CODE_P (code))
{
gcc_assert (convop || !conv_type);
if (opcode != ERROR_MARK)
- {
- if (assop)
- identifier = cp_assignment_operator_id (opcode);
- else
- identifier = cp_operator_id (opcode);
- }
+ identifier = ovl_op_identifier (assop, opcode);
gcc_assert (identifier);
}