@@ -251,16 +251,16 @@ void PackElementTypeAttr::printImpl(ASTPrinter &printer,
251251// / of the 'unowned(unsafe)' attribute, the string passed in is 'unowned'.
252252// /
253253// / Also note that this recognizes both attributes like '@inline' (with no @)
254- // / and decl modifiers like 'final'. This returns DeclAttrKind::Count on
255- // / failure.
254+ // / and decl modifiers like 'final'.
256255// /
257- DeclAttrKind DeclAttribute::getAttrKindFromString (StringRef Str) {
258- return llvm::StringSwitch<DeclAttrKind>(Str)
256+ llvm::Optional<DeclAttrKind>
257+ DeclAttribute::getAttrKindFromString (StringRef Str) {
258+ return llvm::StringSwitch<llvm::Optional<DeclAttrKind>>(Str)
259259#define DECL_ATTR (X, CLASS, ...) .Case(#X, DeclAttrKind::CLASS)
260260#define DECL_ATTR_ALIAS (X, CLASS ) .Case(#X, DeclAttrKind::CLASS)
261261#include " swift/AST/DeclAttr.def"
262262 .Case (SPI_AVAILABLE_ATTRNAME, DeclAttrKind::Available)
263- .Default (DeclAttrKind::Count );
263+ .Default (llvm::None );
264264}
265265
266266DeclAttribute *DeclAttribute::createSimple (const ASTContext &context,
@@ -277,8 +277,6 @@ DeclAttribute *DeclAttribute::createSimple(const ASTContext &context,
277277 case DeclAttrKind::CLASS: \
278278 return new (context) CLASS##Attr (atLoc, attrLoc);
279279#include " swift/AST/DeclAttr.def"
280- case DeclAttrKind::Count:
281- llvm_unreachable (" bad decl attribute kind" );
282280 }
283281 llvm_unreachable (" bad decl attribute kind" );
284282}
@@ -1703,9 +1701,6 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
17031701 break ;
17041702 }
17051703
1706- case DeclAttrKind::Count:
1707- llvm_unreachable (" exceed declaration attribute kinds" );
1708-
17091704#define SIMPLE_DECL_ATTR (X, CLASS, ...) case DeclAttrKind::CLASS:
17101705#include " swift/AST/DeclAttr.def"
17111706 llvm_unreachable (" handled above" );
@@ -1737,8 +1732,6 @@ void DeclAttribute::print(llvm::raw_ostream &OS, const Decl *D) const {
17371732
17381733uint64_t DeclAttribute::getOptions (DeclAttrKind DK) {
17391734 switch (DK) {
1740- case DeclAttrKind::Count:
1741- llvm_unreachable (" getOptions needs a valid attribute" );
17421735#define DECL_ATTR (_, CLASS, OPTIONS, ...) \
17431736 case DeclAttrKind::CLASS: \
17441737 return OPTIONS;
@@ -1749,8 +1742,6 @@ uint64_t DeclAttribute::getOptions(DeclAttrKind DK) {
17491742
17501743StringRef DeclAttribute::getAttrName () const {
17511744 switch (getKind ()) {
1752- case DeclAttrKind::Count:
1753- llvm_unreachable (" getAttrName needs a valid attribute" );
17541745#define SIMPLE_DECL_ATTR (NAME, CLASS, ...) \
17551746 case DeclAttrKind::CLASS: \
17561747 return #NAME;
@@ -2890,19 +2881,20 @@ void swift::simple_display(llvm::raw_ostream &out, const DeclAttribute *attr) {
28902881
28912882bool swift::hasAttribute (
28922883 const LangOptions &langOpts, llvm::StringRef attributeName) {
2893- DeclAttrKind kind = DeclAttribute::getAttrKindFromString (attributeName);
2894- if (kind == DeclAttrKind::Count)
2884+ llvm::Optional<DeclAttrKind> kind =
2885+ DeclAttribute::getAttrKindFromString (attributeName);
2886+ if (!kind)
28952887 return false ;
28962888
2897- if (DeclAttribute::isUserInaccessible (kind))
2889+ if (DeclAttribute::isUserInaccessible (* kind))
28982890 return false ;
2899- if (DeclAttribute::isDeclModifier (kind))
2891+ if (DeclAttribute::isDeclModifier (* kind))
29002892 return false ;
2901- if (DeclAttribute::shouldBeRejectedByParser (kind))
2893+ if (DeclAttribute::shouldBeRejectedByParser (* kind))
29022894 return false ;
2903- if (DeclAttribute::isSilOnly (kind))
2895+ if (DeclAttribute::isSilOnly (* kind))
29042896 return false ;
2905- if (DeclAttribute::isConcurrencyOnly (kind))
2897+ if (DeclAttribute::isConcurrencyOnly (* kind))
29062898 return false ;
29072899
29082900 return true ;
0 commit comments