aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl.c
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2017-06-22 18:40:56 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2017-06-22 18:40:56 +0000
commit84c0088f38ce49f390401d11a581cd1a57a008d5 (patch)
treecd6adfd3e1e3f4244a38c183860b2efd2b25593c /gcc/cp/decl.c
parent13f752b27354d0b8f7ff0148973c6b478e6fdd9e (diff)
downloadgcc-84c0088f38ce49f390401d11a581cd1a57a008d5.zip
gcc-84c0088f38ce49f390401d11a581cd1a57a008d5.tar.gz
gcc-84c0088f38ce49f390401d11a581cd1a57a008d5.tar.bz2
Reorder IDENTIFIER flags
Reorder IDENTIFIER flags gcc/cp/ * cp-tree.h (enum cp_identifier_kind): New. (IDENTIFIER_KIND_BIT_0, IDENTIFIER_KIND_BIT_1, IDENTIFIER_KIND_BIT_2): New. (IDENTIFIER_MARKED): Move to TREE_LANG_FLAG_4. (IDENTIFIER_VIRTUAL_P, IDENTIFIER_REPO_CHOSEN): Add IDENTIFIER_CHECK. (C_IS_RESERVED_WORD): Replace with ... (IDENTIFIER_KEYWORD_P): ... this. (IDENTIFIER_CTOR_OR_DTOR_P): Replace with ... (IDENTIFIER_CDTOR_P): ... this. (IDENTIFIER_CTOR_P, IDENTIFIER_DTOR_P): New. (IDENTIFIER_OPNAME_P): Replace with ... (IDENTIFIER_ANY_OP_P): ... this. (IDENTIFIER_ASSIGN_OP_P): New. (IDENTIFIER_TYPENAME_P): Replace with ... (IDENTIFIER_CONV_OP_P): ... this. (NEW_DELETE_OPNAME_P): Replace with ... (IDENTIFIER_NEWDEL_OP_P): ... this. (DECL_CONV_FN_P, DECL_OVERLOADED_OPERATOR_P): Adjust. (get_identifier_kind_name, set_identifier_kind): Declare. * lex.c (get_identifier_kind_name, set_identifier_kind): New. (init_operators): Adjust to avoid keywords, use set_identifier_kind. Copy TYPE_EXPR slot. (init_reswords): Call set_identifier_kind. (unqualified_name_lookup_error): Adjust. * operators.def (TYPE_EXPR): Remove. * decl.c (struct predefined_identifier): Move into ... (initialize_predefined_identifiers): ... here. Call set_identifier_kind. (grokfndecl, check_var_type, grokdeclarator): Adjust. (grok_op_properties): Use IDENTIFIER_ANY_ASSIGN_OP to halve search space. Adjust. * call.c (name_as_c_string): Adjust. (build_new_method_call_1): Likewise. * cp-cilkplus.c (is_conversion_operator_function_decl_p): Likewise. * cxx-pretty-print.c (pp_cxx_unqualified_id): Adjust. * dump.c (cp_dump_tree): Adjust. * error.c (dump_decl_name): Adjust. * mangle.c (write_unqualified_id, write_member_name) write_expression): Adjust. (mangle_conv_op_name_for_type): Use set_identifier_kind. * name-lookup.c (do_class_using_decl): Adjust. (lookup_name_fuzzy, lookup_name_real_1): Likewise. * parser.c (cp_lexer_get_preprocessor_token) cp_parser_direct_declarator): Likewise. * pt.c (push_template_decl_real, tsubst_decl, tsubst_baselink) tsubst_copy, tsubst_copy_and_build): Adjust. * ptree.c (cxx_print_identifier): Print identifier kind. * search.c (lookup_field_r, lookup_member) lookup_fnfields_idx_nolazy): Adjust. * semantics.c (finish_id_expression): Adjust.. * typeck.c (cp_build_addr_expr_1): Adjust. From-SVN: r249571
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r--gcc/cp/decl.c195
1 files changed, 90 insertions, 105 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7c34489..b0a34de 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -3948,62 +3948,56 @@ record_unknown_type (tree type, const char* name)
SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
}
-/* A string for which we should create an IDENTIFIER_NODE at
- startup. */
-
-struct predefined_identifier
-{
- /* The name of the identifier. */
- const char *const name;
- /* The place where the IDENTIFIER_NODE should be stored. */
- tree *const node;
- /* Nonzero if this is the name of a constructor or destructor. */
- const int ctor_or_dtor_p;
-};
-
/* Create all the predefined identifiers. */
static void
initialize_predefined_identifiers (void)
{
- const predefined_identifier *pid;
+ struct predefined_identifier
+ {
+ const char *name; /* Name. */
+ tree *node; /* Node to store it in. */
+ cp_identifier_kind kind; /* Kind of identifier. */
+ };
/* A table of identifiers to create at startup. */
static const predefined_identifier predefined_identifiers[] = {
- { "C++", &lang_name_cplusplus, 0 },
- { "C", &lang_name_c, 0 },
+ {"C++", &lang_name_cplusplus, cik_normal},
+ {"C", &lang_name_c, cik_normal},
/* Some of these names have a trailing space so that it is
impossible for them to conflict with names written by users. */
- { "__ct ", &ctor_identifier, 1 },
- { "__base_ctor ", &base_ctor_identifier, 1 },
- { "__comp_ctor ", &complete_ctor_identifier, 1 },
- { "__dt ", &dtor_identifier, 1 },
- { "__comp_dtor ", &complete_dtor_identifier, 1 },
- { "__base_dtor ", &base_dtor_identifier, 1 },
- { "__deleting_dtor ", &deleting_dtor_identifier, 1 },
- { IN_CHARGE_NAME, &in_charge_identifier, 0 },
- { THIS_NAME, &this_identifier, 0 },
- { VTABLE_DELTA_NAME, &delta_identifier, 0 },
- { VTABLE_PFN_NAME, &pfn_identifier, 0 },
- { "_vptr", &vptr_identifier, 0 },
- { "__vtt_parm", &vtt_parm_identifier, 0 },
- { "::", &global_identifier, 0 },
- { "std", &std_identifier, 0 },
+ {"__ct ", &ctor_identifier, cik_ctor},
+ {"__base_ctor ", &base_ctor_identifier, cik_ctor},
+ {"__comp_ctor ", &complete_ctor_identifier, cik_ctor},
+ {"__dt ", &dtor_identifier, cik_dtor},
+ {"__comp_dtor ", &complete_dtor_identifier, cik_dtor},
+ {"__base_dtor ", &base_dtor_identifier, cik_dtor},
+ {"__deleting_dtor ", &deleting_dtor_identifier, cik_dtor},
+ {IN_CHARGE_NAME, &in_charge_identifier, cik_normal},
+ {THIS_NAME, &this_identifier, cik_normal},
+ {VTABLE_DELTA_NAME, &delta_identifier, cik_normal},
+ {VTABLE_PFN_NAME, &pfn_identifier, cik_normal},
+ {"_vptr", &vptr_identifier, cik_normal},
+ {"__vtt_parm", &vtt_parm_identifier, cik_normal},
+ {"::", &global_identifier, cik_normal},
+ {"std", &std_identifier, cik_normal},
/* The demangler expects anonymous namespaces to be called
something starting with '_GLOBAL__N_'. It no longer needs
to be unique to the TU. */
- { "_GLOBAL__N_1", &anon_identifier, 0 },
- { "auto", &auto_identifier, 0 },
- { "decltype(auto)", &decltype_auto_identifier, 0 },
- { "initializer_list", &init_list_identifier, 0 },
- { NULL, NULL, 0 }
+ {"_GLOBAL__N_1", &anon_identifier, cik_normal},
+ {"auto", &auto_identifier, cik_normal},
+ {"decltype(auto)", &decltype_auto_identifier, cik_normal},
+ {"initializer_list", &init_list_identifier, cik_normal},
+ {NULL, NULL, cik_normal}
};
- for (pid = predefined_identifiers; pid->name; ++pid)
+ for (const predefined_identifier *pid = predefined_identifiers;
+ pid->name; ++pid)
{
*pid->node = get_identifier (pid->name);
- if (pid->ctor_or_dtor_p)
- IDENTIFIER_CTOR_OR_DTOR_P (*pid->node) = 1;
+ /* Some of these identifiers already have a special kind. */
+ if (pid->kind != cik_normal)
+ set_identifier_kind (*pid->node, pid->kind);
}
}
@@ -8721,7 +8715,7 @@ grokfndecl (tree ctype,
error_at (location,
"deduction guide %qD must not have a function body", decl);
}
- else if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))
+ else if (IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
&& !grok_op_properties (decl, /*complain=*/true))
return NULL_TREE;
else if (UDLIT_OPER_P (DECL_NAME (decl)))
@@ -9773,7 +9767,7 @@ check_var_type (tree identifier, tree type)
error ("unnamed variable or field declared void");
else if (identifier_p (identifier))
{
- gcc_assert (!IDENTIFIER_OPNAME_P (identifier));
+ gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
error ("variable or field %qE declared void", identifier);
}
else
@@ -10114,12 +10108,7 @@ grokdeclarator (const cp_declarator *declarator,
dname = fns;
if (!identifier_p (dname))
- {
- if (variable_template_p (dname))
- dname = DECL_NAME (dname);
- else
- dname = OVL_NAME (dname);
- }
+ dname = OVL_NAME (dname);
}
/* Fall through. */
@@ -10127,13 +10116,13 @@ grokdeclarator (const cp_declarator *declarator,
if (identifier_p (decl))
dname = decl;
- if (C_IS_RESERVED_WORD (dname))
+ if (IDENTIFIER_KEYWORD_P (dname))
{
error ("declarator-id missing; using reserved word %qD",
dname);
name = identifier_to_locale (IDENTIFIER_POINTER (dname));
}
- else if (!IDENTIFIER_TYPENAME_P (dname))
+ else if (!IDENTIFIER_CONV_OP_P (dname))
name = identifier_to_locale (IDENTIFIER_POINTER (dname));
else
{
@@ -10192,26 +10181,27 @@ grokdeclarator (const cp_declarator *declarator,
return error_mark_node;
}
- if (dname
- && identifier_p (dname)
- && UDLIT_OPER_P (dname)
- && innermost_code != cdk_function)
- {
- error ("declaration of %qD as non-function", dname);
- return error_mark_node;
- }
-
- if (dname && IDENTIFIER_OPNAME_P (dname))
+ if (dname && identifier_p (dname))
{
- if (typedef_p)
+ if (UDLIT_OPER_P (dname)
+ && innermost_code != cdk_function)
{
- error ("declaration of %qD as %<typedef%>", dname);
+ error ("declaration of %qD as non-function", dname);
return error_mark_node;
}
- else if (decl_context == PARM || decl_context == CATCHPARM)
+
+ if (IDENTIFIER_ANY_OP_P (dname))
{
- error ("declaration of %qD as parameter", dname);
- return error_mark_node;
+ if (typedef_p)
+ {
+ error ("declaration of %qD as %<typedef%>", dname);
+ return error_mark_node;
+ }
+ else if (decl_context == PARM || decl_context == CATCHPARM)
+ {
+ error ("declaration of %qD as parameter", dname);
+ return error_mark_node;
+ }
}
}
@@ -11708,22 +11698,20 @@ grokdeclarator (const cp_declarator *declarator,
return error_mark_node;
}
- /* Only functions may be declared using an operator-function-id. */
- if (unqualified_id
- && IDENTIFIER_OPNAME_P (unqualified_id)
- && TREE_CODE (type) != FUNCTION_TYPE
- && TREE_CODE (type) != METHOD_TYPE)
+ if (!FUNC_OR_METHOD_TYPE_P (type))
{
- error ("declaration of %qD as non-function", unqualified_id);
- return error_mark_node;
- }
+ /* Only functions may be declared using an operator-function-id. */
+ if (dname && IDENTIFIER_ANY_OP_P (dname))
+ {
+ error ("declaration of %qD as non-function", dname);
+ return error_mark_node;
+ }
- if (reqs
- && TREE_CODE (type) != FUNCTION_TYPE
- && TREE_CODE (type) != METHOD_TYPE)
- error_at (location_of (reqs),
- "requires-clause on declaration of non-function type %qT",
- type);
+ if (reqs)
+ error_at (location_of (reqs),
+ "requires-clause on declaration of non-function type %qT",
+ type);
+ }
/* We don't check parameter types here because we can emit a better
error message later. */
@@ -11768,7 +11756,8 @@ grokdeclarator (const cp_declarator *declarator,
}
if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
- && !NEW_DELETE_OPNAME_P (unqualified_id))
+ && !(identifier_p (unqualified_id)
+ && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
{
cp_cv_quals real_quals = memfn_quals;
if (cxx_dialect < cxx14 && constexpr_p
@@ -11879,15 +11868,13 @@ grokdeclarator (const cp_declarator *declarator,
return error_mark_node;
}
- if (NEW_DELETE_OPNAME_P (unqualified_id))
+ if (virtualp
+ && identifier_p (unqualified_id)
+ && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
{
- if (virtualp)
- {
- error ("%qD cannot be declared %<virtual%>, since it "
- "is always static",
- unqualified_id);
- virtualp = 0;
- }
+ error ("%qD cannot be declared %<virtual%>, since it "
+ "is always static", unqualified_id);
+ virtualp = 0;
}
}
@@ -12149,6 +12136,7 @@ grokdeclarator (const cp_declarator *declarator,
original_name = dname;
else
original_name = unqualified_id;
+ // FIXME:gcc_assert (original_name == dname);
if (storage_class == sc_auto)
error ("storage class %<auto%> invalid for function %qs", name);
@@ -12943,27 +12931,24 @@ grok_op_properties (tree decl, bool complain)
if (class_type && !CLASS_TYPE_P (class_type))
class_type = NULL_TREE;
- if (DECL_CONV_FN_P (decl))
+ if (IDENTIFIER_CONV_OP_P (name))
operator_code = TYPE_EXPR;
else
- do
- {
-#define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P) \
- if (cp_operator_id (CODE) == name) \
- { \
- operator_code = (CODE); \
- break; \
- } \
- else if (cp_assignment_operator_id (CODE) == name) \
- { \
- operator_code = (CODE); \
- DECL_ASSIGNMENT_OPERATOR_P (decl) = 1; \
- break; \
- }
-
+ {
+ /* It'd be nice to hang something else of the identifier to
+ find CODE more directly. */
+ const operator_name_info_t *oni
+ = (IDENTIFIER_ASSIGN_OP_P (name)
+ ? assignment_operator_name_info : operator_name_info);
+ DECL_ASSIGNMENT_OPERATOR_P (decl) = IDENTIFIER_ASSIGN_OP_P (name);
+ if (false)
+ ;
+#define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, KIND) \
+ else if (oni[int (CODE)].identifier == name) \
+ operator_code = (CODE);
#include "operators.def"
#undef DEF_OPERATOR
-
+ else
gcc_unreachable ();
}
while (0);
@@ -13082,7 +13067,7 @@ grok_op_properties (tree decl, bool complain)
return true;
/* Warn about conversion operators that will never be used. */
- if (IDENTIFIER_TYPENAME_P (name)
+ if (IDENTIFIER_CONV_OP_P (name)
&& ! DECL_TEMPLATE_INFO (decl)
&& warn_conversion
/* Warn only declaring the function; there is no need to