Skip to content

Commit 3257145

Browse files
authored
Merge pull request swiftlang#18111 from rjmccall/generalized-accessor-recording
Generalize the recording of parsed accessors
2 parents 79928ad + 06edd25 commit 3257145

File tree

7 files changed

+290
-303
lines changed

7 files changed

+290
-303
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,15 @@ ERROR(getset_nontrivial_pattern,none,
257257
"getter/setter can only be defined for a single variable", ())
258258
ERROR(expected_rbrace_in_getset,none,
259259
"expected '}' at end of variable get/set clause", ())
260-
ERROR(duplicate_property_accessor,none,
261-
"duplicate definition of %0", (StringRef))
260+
ERROR(duplicate_accessor,none,
261+
"%select{variable|subscript}0 already has %1", (unsigned, StringRef))
262+
ERROR(conflicting_accessor,none,
263+
"%select{variable|subscript}0 cannot provide both %1 and %2",
264+
(unsigned, StringRef, StringRef))
265+
ERROR(modify_mutatingness_different_from_setter,none,
266+
"mutating-ness of 'modify' accessor cannot differ from setter", ())
262267
NOTE(previous_accessor,none,
263-
"previous definition of %0 is here", (StringRef))
264-
ERROR(conflicting_property_addressor,none,
265-
"%select{variable|subscript}0 already has a "
266-
"%select{addressor|mutable addressor}1", (unsigned, unsigned))
268+
"%select{|previous definition of }1%0 %select{defined |}1here", (StringRef, bool))
267269
ERROR(expected_accessor_name,none,
268270
"expected %select{%error|setter|%error|willSet|didSet}0 parameter name",
269271
(unsigned))
@@ -278,32 +280,22 @@ ERROR(expected_lbrace_accessor,PointsToFirstBadToken,
278280
ERROR(expected_accessor_kw,none,
279281
"expected 'get', 'set', 'willSet', or 'didSet' keyword to "
280282
"start an accessor definition",())
281-
ERROR(var_set_without_get,none,
282-
"variable with a setter must also have a getter", ())
283-
ERROR(observingproperty_with_getset,none,
284-
"%select{willSet|didSet}0 variable must not also have a "
285-
"%select{get|set}1 specifier", (unsigned, unsigned))
286-
ERROR(observingproperty_with_address,none,
287-
"variable with addressor may not have %select{willSet|didSet}0",
288-
(unsigned))
289-
ERROR(observingproperty_in_subscript,none,
290-
"%select{willSet|didSet}0 is not allowed in subscripts", (unsigned))
283+
ERROR(missing_getter,none,
284+
"%select{variable|subscript}0 with %1 must also have a getter",
285+
(unsigned, StringRef))
286+
ERROR(missing_reading_accessor,none,
287+
"%select{variable|subscript}0 with %1 must also have "
288+
"a getter or an addressor",
289+
(unsigned, StringRef))
290+
ERROR(observing_accessor_conflicts_with_accessor,none,
291+
"%select{'willSet'|'didSet'}0 cannot be provided together with %1",
292+
(unsigned, StringRef))
293+
ERROR(observing_accessor_in_subscript,none,
294+
"%select{'willSet'|'didSet'}0 is not allowed in subscripts", (unsigned))
291295
ERROR(getset_init,none,
292296
"variable with getter/setter cannot have an initial value", ())
293297
ERROR(getset_cannot_be_implied,none,
294298
"variable with implied type cannot have implied getter/setter", ())
295-
ERROR(mutableaddressor_without_address,none,
296-
"%select{variable|subscript}0 must provide either a getter or "
297-
"'address' if it provides 'mutableAddress'", (unsigned))
298-
ERROR(mutableaddressor_with_setter,none,
299-
"%select{variable|subscript}0 cannot provide both 'mutableAddress' "
300-
" and a setter", (unsigned))
301-
ERROR(addressor_with_getter,none,
302-
"%select{variable|subscript}0 cannot provide both 'address' and "
303-
"a getter", (unsigned))
304-
ERROR(addressor_with_setter,none,
305-
"%select{variable|subscript}0 cannot provide both 'address' and "
306-
"a setter; use an ordinary getter instead", (unsigned))
307299
ERROR(behavior_multiple_vars,none,
308300
"applying property behavior with parameter to multiple variables is "
309301
"not supported", ())

include/swift/AST/StorageImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ class StorageImplInfo {
274274
return;
275275

276276
case WriteImplKind::Set:
277-
assert(readImpl == ReadImplKind::Get);
277+
assert(readImpl == ReadImplKind::Get ||
278+
readImpl == ReadImplKind::Address);
278279
assert(readWriteImpl == ReadWriteImplKind::MaterializeToTemporary ||
279280
readWriteImpl == ReadWriteImplKind::MaterializeForSet);
280281
return;

include/swift/Parse/Parser.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -876,33 +876,9 @@ class Parser {
876876

877877
void consumeGetSetBody(AbstractFunctionDecl *AFD, SourceLoc LBLoc);
878878

879-
struct ParsedAccessors {
880-
SourceLoc LBLoc, RBLoc;
881-
SmallVector<AccessorDecl*, 16> Accessors;
882-
883-
#define ACCESSOR(ID) AccessorDecl *ID = nullptr;
884-
#include "swift/AST/AccessorKinds.def"
885-
886-
void record(Parser &P, AbstractStorageDecl *storage, bool invalid,
887-
ParseDeclOptions flags, SourceLoc staticLoc,
888-
const DeclAttributes &attrs,
889-
TypeLoc elementTy, ParameterList *indices,
890-
SmallVectorImpl<Decl *> &decls);
891-
892-
StorageImplInfo
893-
classify(Parser &P, AbstractStorageDecl *storage, bool invalid,
894-
ParseDeclOptions flags, SourceLoc staticLoc,
895-
const DeclAttributes &attrs,
896-
TypeLoc elementTy, ParameterList *indices);
897-
898-
/// Add an accessor. If there's an existing accessor of this kind,
899-
/// return it. The new accessor is still remembered but will be
900-
/// ignored.
901-
AccessorDecl *add(AccessorDecl *accessor);
902-
};
903-
904879
void parseAccessorAttributes(DeclAttributes &Attributes);
905880

881+
struct ParsedAccessors;
906882
bool parseGetSetImpl(ParseDeclOptions Flags,
907883
GenericParamList *GenericParams,
908884
ParameterList *Indices,

0 commit comments

Comments
 (0)