diff options
author | Iain Sandoe <iain@sandoe.co.uk> | 2020-10-31 20:53:34 +0000 |
---|---|---|
committer | Iain Sandoe <iain@sandoe.co.uk> | 2020-11-06 19:49:23 +0000 |
commit | 9a34a5cce6b50fc3527e7c7ab356808ed435883c (patch) | |
tree | a1b114d1c1f375371c8eb1cf69025a15d99dfb80 /gcc/c-family/c-objc.h | |
parent | 6c282c14d1be0bba2bf5d49acd074b349f28ad17 (diff) | |
download | gcc-9a34a5cce6b50fc3527e7c7ab356808ed435883c.zip gcc-9a34a5cce6b50fc3527e7c7ab356808ed435883c.tar.gz gcc-9a34a5cce6b50fc3527e7c7ab356808ed435883c.tar.bz2 |
Objective-C/C++ (parsers) : Update @property attribute parsing.
At present, we are missing parsing and checking for around
half of the property attributes in use. The existing ad hoc scheme
for the parser's communication with the Objective C validation
is not suitable for extending to cover all the missing cases.
Additionally:
1/ We were declaring errors in two cases that the reference
implementation warns (or is silent).
I've elected to warn for both those cases, (Wattributes) it
could be that we should implement Wobjc-xxx-property warning
masks (TODO).
2/ We were emitting spurious complaints about missing property
attributes when these were not being parsed because we gave
up on the first syntax error.
3/ The quality of the diagnostic locations was poor (that's
true for much of Objective-C, we will have to improve it as
we modernise areas).
We continue to attempt to keep the code, warning and error output
similar (preferably identical output) between the C and C++ front
ends.
The interface to the Objective-C-specific parts of the parsing is
simplified to a vector of parsed (but not fully-checked) property
attributes, this will simplify the addition of new attributes.
gcc/c-family/ChangeLog:
* c-objc.h (enum objc_property_attribute_group): New
(enum objc_property_attribute_kind): New.
(OBJC_PROPATTR_GROUP_MASK): New.
(struct property_attribute_info): Small class encapsulating
parser output from property attributes.
(objc_prop_attr_kind_for_rid): New
(objc_add_property_declaration): Simplify interface.
* stub-objc.c (enum rid): Dummy type.
(objc_add_property_declaration): Simplify interface.
(objc_prop_attr_kind_for_rid): New.
gcc/c/ChangeLog:
* c-parser.c (c_parser_objc_at_property_declaration):
Improve parsing fidelity. Associate better location info
with @property attributes. Clean up the interface to
objc_add_property_declaration ().
gcc/cp/ChangeLog:
* parser.c (cp_parser_objc_at_property_declaration):
Improve parsing fidelity. Associate better location info
with @property attributes. Clean up the interface to
objc_add_property_declaration ().
gcc/objc/ChangeLog:
* objc-act.c (objc_prop_attr_kind_for_rid): New.
(objc_add_property_declaration): Adjust to consume the
parser output using a vector of parsed attributes.
gcc/testsuite/ChangeLog:
* obj-c++.dg/property/at-property-1.mm: Adjust expected
diagnostics.
* obj-c++.dg/property/at-property-29.mm: Likewise.
* obj-c++.dg/property/at-property-4.mm: Likewise.
* obj-c++.dg/property/property-neg-2.mm: Likewise.
* objc.dg/property/at-property-1.m: Likewise.
* objc.dg/property/at-property-29.m: Likewise.
* objc.dg/property/at-property-4.m: Likewise.
* objc.dg/property/at-property-5.m: Likewise.
* objc.dg/property/property-neg-2.m: Likewise.
Diffstat (limited to 'gcc/c-family/c-objc.h')
-rw-r--r-- | gcc/c-family/c-objc.h | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/gcc/c-family/c-objc.h b/gcc/c-family/c-objc.h index 4577e4f..a2ca112 100644 --- a/gcc/c-family/c-objc.h +++ b/gcc/c-family/c-objc.h @@ -28,6 +28,67 @@ enum GTY(()) objc_ivar_visibility_kind { OBJC_IVAR_VIS_PACKAGE = 3 }; +/* ObjC property attribute kinds. + These have two fields; a unique value (that identifies which attribute) + and a group key that indicates membership of an exclusion group. + Only one member may be present from an exclusion group in a given attribute + list. + getters and setters have additional rules, since they are excluded from + non-overlapping group sets. */ + +enum objc_property_attribute_group +{ + OBJC_PROPATTR_GROUP_UNKNOWN = 0, + OBJC_PROPATTR_GROUP_GETTER, + OBJC_PROPATTR_GROUP_SETTER, + OBJC_PROPATTR_GROUP_READWRITE, + OBJC_PROPATTR_GROUP_ASSIGN, + OBJC_PROPATTR_GROUP_ATOMIC, + OBJC_PROPATTR_GROUP_MAX +}; + +enum objc_property_attribute_kind +{ + OBJC_PROPERTY_ATTR_UNKNOWN = 0|OBJC_PROPATTR_GROUP_UNKNOWN, + OBJC_PROPERTY_ATTR_GETTER = ( 1 << 8)|OBJC_PROPATTR_GROUP_GETTER, + OBJC_PROPERTY_ATTR_SETTER = ( 2 << 8)|OBJC_PROPATTR_GROUP_SETTER, + OBJC_PROPERTY_ATTR_READONLY = ( 3 << 8)|OBJC_PROPATTR_GROUP_READWRITE, + OBJC_PROPERTY_ATTR_READWRITE = ( 4 << 8)|OBJC_PROPATTR_GROUP_READWRITE, + OBJC_PROPERTY_ATTR_ASSIGN = ( 5 << 8)|OBJC_PROPATTR_GROUP_ASSIGN, + OBJC_PROPERTY_ATTR_RETAIN = ( 6 << 8)|OBJC_PROPATTR_GROUP_ASSIGN, + OBJC_PROPERTY_ATTR_COPY = ( 7 << 8)|OBJC_PROPATTR_GROUP_ASSIGN, + OBJC_PROPERTY_ATTR_ATOMIC = ( 8 << 8)|OBJC_PROPATTR_GROUP_ATOMIC, + OBJC_PROPERTY_ATTR_NONATOMIC = ( 9 << 8)|OBJC_PROPATTR_GROUP_ATOMIC, + OBJC_PROPERTY_ATTR_MAX = (255 << 8|OBJC_PROPATTR_GROUP_MAX) +}; + +#define OBJC_PROPATTR_GROUP_MASK 0x0f + +/* To contain parsed, but unverified, information about a single property + attribute. */ +struct property_attribute_info +{ + property_attribute_info () = default; + property_attribute_info (tree name, location_t loc, + enum objc_property_attribute_kind k) + : name (name), ident (NULL_TREE), prop_loc (loc), prop_kind (k), + parse_error (false) {} + + enum objc_property_attribute_group group () + { + return (enum objc_property_attribute_group) + ((unsigned)prop_kind & OBJC_PROPATTR_GROUP_MASK); + } + + tree name; /* Name of the attribute. */ + tree ident; /* For getter/setter cases, the method/selector name. */ + location_t prop_loc; /* Extended location covering the parsed attr. */ + enum objc_property_attribute_kind prop_kind : 16; + unsigned parse_error : 1; /* The C/C++ parser saw an error in this attr. */ +}; + +extern enum objc_property_attribute_kind objc_prop_attr_kind_for_rid (enum rid); + /* Objective-C / Objective-C++ entry points. */ /* The following ObjC/ObjC++ functions are called by the C and/or C++ @@ -90,8 +151,8 @@ extern tree objc_generate_write_barrier (tree, enum tree_code, tree); extern void objc_set_method_opt (bool); extern void objc_finish_foreach_loop (location_t, tree, tree, tree, tree, tree); extern bool objc_method_decl (enum tree_code); -extern void objc_add_property_declaration (location_t, tree, bool, bool, bool, - bool, bool, bool, tree, tree); +extern void objc_add_property_declaration (location_t, tree, + vec<property_attribute_info *>&); extern tree objc_maybe_build_component_ref (tree, tree); extern tree objc_build_class_component_ref (tree, tree); extern tree objc_maybe_build_modify_expr (tree, tree); |