This patch introduces a new helper for looking up annotations.
gcc/cp/ChangeLog:
* cp-tree.h (lookup_annotation): Declare.
* decl.cc (grokfndecl): Use lookup_annotation.
(grokdeclarator): Likewise.
* name-lookup.cc (push_local_extern_decl_alias): Likewise.
* parser.cc (cp_parser_decomposition_declaration): Likewise.
* reflect.cc (eval_annotations_of): Likewise.
* tree.cc (lookup_annotation): New.
Reviewed-by: Jason Merrill <jason@redhat.com>
extern void cxx_print_statistics (void);
extern bool maybe_warn_zero_as_null_pointer_constant (tree, location_t);
extern bool annotation_p (tree) ATTRIBUTE_PURE;
+extern tree lookup_annotation (tree);
/* in ptree.cc */
extern void cxx_print_xnode (FILE *, tree, int);
&& initialized == SD_INITIALIZED
&& DECL_ATTRIBUTES (t))
for (tree a = DECL_ATTRIBUTES (t);
- (a = lookup_attribute ("internal ", "annotation ", a));
+ (a = lookup_annotation (a));
a = TREE_CHAIN (a))
{
gcc_checking_assert (TREE_CODE (TREE_VALUE (a)) == TREE_LIST);
{
if (flag_reflection
&& declarator->std_attributes != error_mark_node
- && lookup_attribute ("internal ", "annotation ",
- declarator->std_attributes)
+ && lookup_annotation (declarator->std_attributes)
&& *attrlist != error_mark_node
- && lookup_attribute ("internal ", "annotation ", *attrlist))
+ && lookup_annotation (*attrlist))
/* If there are annotations in both lists, ensure
declarator->std_attributes go after *attrlist. See
PR124399. */
{
if (flag_reflection && !funcdef_flag && decl)
{
- if (attrlist
- && lookup_attribute ("internal ", "annotation ",
- *attrlist))
+ if (attrlist && lookup_annotation (*attrlist))
{
/* Remove the annotations to avoid spurious warning
below. */
}
for (tree arg = DECL_ARGUMENTS (decl);
arg; arg = DECL_CHAIN (arg))
- if (lookup_attribute ("internal ", "annotation ",
- DECL_ATTRIBUTES (arg)))
+ if (lookup_annotation (DECL_ATTRIBUTES (arg)))
error_at (DECL_SOURCE_LOCATION (arg),
"annotation applied to parameter %qD of "
"non-defining friend declaration", arg);
{
if (flag_reflection)
{
- if (lookup_attribute ("internal ", "annotation ",
- DECL_ATTRIBUTES (decl)))
+ if (lookup_annotation (DECL_ATTRIBUTES (decl)))
error_at (DECL_SOURCE_LOCATION (decl),
"annotation applied to block scope extern %qD",
decl);
if (TREE_CODE (decl) == FUNCTION_DECL)
for (tree arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
- if (lookup_attribute ("internal ", "annotation ",
- DECL_ATTRIBUTES (arg)))
+ if (lookup_annotation (DECL_ATTRIBUTES (arg)))
error_at (DECL_SOURCE_LOCATION (arg),
"annotation applied to parameter %qD of block scope "
"extern", arg);
attr = NULL_TREE;
if (attr && first_attr == -1)
first_attr = v.length ();
- if (lookup_attribute ("internal ", "annotation ", attr))
+ if (lookup_annotation (attr))
error ("annotation on structured binding");
}
v.safe_push (e);
else
gcc_unreachable ();
vec<constructor_elt, va_gc> *elts = nullptr;
- for (tree a = r; (a = lookup_attribute ("internal ", "annotation ", a));
+ for (tree a = r;
+ (a = lookup_annotation (a));
a = TREE_CHAIN (a))
{
gcc_checking_assert (TREE_CODE (TREE_VALUE (a)) == TREE_LIST);
return is_attribute_p ("annotation ", get_attribute_name (attr));
}
+/* Lookup the annotation in ATTR, if present. */
+
+tree
+lookup_annotation (tree attr)
+{
+ return lookup_attribute ("internal ", "annotation ", attr);
+}
+
\f
/* Release memory we no longer need after parsing. */
void