1010//
1111// ===----------------------------------------------------------------------===//
1212
13- #ifndef SWIFT_LIB_SEMA_INVERSEMARKING_H
14- #define SWIFT_LIB_SEMA_INVERSEMARKING_H
13+ #ifndef SWIFT_AST_INVERSEMARKING_H
14+ #define SWIFT_AST_INVERSEMARKING_H
1515
1616#include " swift/AST/KnownProtocols.h"
1717#include " swift/Basic/SourceLoc.h"
1818#include " swift/Basic/OptionalEnum.h"
1919
2020namespace swift {
2121
22+ class NoncopyableAnnotationRequest ;
23+
2224// / Describes the way an inverse and its corresponding positive contraint
2325// / appears on a TypeDecl, i.e., the way it was marked.
2426struct InverseMarking {
2527 enum class Kind : uint8_t {
2628 None, // No inverse marking is present
2729 Inferred, // Inverse is inferred based on generic parameters.
2830 Explicit, // Inverse is explicitly present.
29-
30- LAST = Explicit
31+ LegacyExplicit, // An equivalent, explicit legacy annotation is present.
3132 };
3233
3334 // Describes what kind of mark was found, if any.
@@ -43,15 +44,18 @@ struct InverseMarking {
4344 Mark (Kind k, SourceLoc l = SourceLoc())
4445 : kind(k), loc(l) {};
4546
46- // Is there an inferred or explicit marking?
47- bool isPresent () const {
48- return getKind () != Kind::None;
49- }
50- operator bool () { return isPresent (); }
51-
5247 Kind getKind () const {
5348 return kind.getValueOr (Kind::None);
5449 }
50+ bool is (Kind k) const {
51+ return getKind () == k;
52+ }
53+
54+ // Is there an inferred or explicit marking?
55+ bool isPresent () const {
56+ return !is (Kind::None);
57+ }
58+ operator bool () const { return isPresent (); }
5559
5660 SourceLoc getLoc () const { return loc; }
5761
@@ -68,34 +72,29 @@ struct InverseMarking {
6872 }
6973
7074 void setIfUnset (Mark other) {
71- if (kind.hasValue ())
75+ if (!other. kind .hasValue ())
7276 return ;
73- kind = other.kind ;
74- loc = other.loc ;
77+ setIfUnset (other.kind .getValue (), other.loc );
7578 }
7679
77- Mark with (Kind k) {
78- kind = k;
79- return *this ;
80+ Mark with (Kind k) const {
81+ return Mark (k, loc);
8082 }
8183 };
8284
8385private:
8486 Mark inverse;
8587 Mark positive;
88+
89+ // This friend initializes the marks.
90+ friend NoncopyableAnnotationRequest;
8691public:
8792
8893 // Creates an empty marking.
8994 InverseMarking () {}
9095
91- Mark &getInverse () { return inverse; }
92- Mark &getPositive () { return positive; }
93-
94- // Merge the results of another marking into this one.
95- void merge (InverseMarking other) const {
96- other.inverse .setIfUnset (other.inverse );
97- other.positive .setIfUnset (other.positive );
98- }
96+ Mark const & getInverse () const { return inverse; }
97+ Mark const & getPositive () const { return positive; }
9998
10099 static InverseMarking forInverse (Kind kind, SourceLoc loc = SourceLoc()) {
101100 InverseMarking marking;
@@ -107,4 +106,4 @@ struct InverseMarking {
107106
108107}
109108
110- #endif // SWIFT_LIB_SEMA_INVERSEMARKING_H
109+ #endif // SWIFT_AST_INVERSEMARKING_H
0 commit comments