@@ -251,16 +251,16 @@ void PackElementTypeAttr::printImpl(ASTPrinter &printer,
251
251
// / of the 'unowned(unsafe)' attribute, the string passed in is 'unowned'.
252
252
// /
253
253
// / 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'.
256
255
// /
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)
259
259
#define DECL_ATTR (X, CLASS, ...) .Case(#X, DeclAttrKind::CLASS)
260
260
#define DECL_ATTR_ALIAS (X, CLASS ) .Case(#X, DeclAttrKind::CLASS)
261
261
#include " swift/AST/DeclAttr.def"
262
262
.Case (SPI_AVAILABLE_ATTRNAME, DeclAttrKind::Available)
263
- .Default (DeclAttrKind::Count );
263
+ .Default (llvm::None );
264
264
}
265
265
266
266
DeclAttribute *DeclAttribute::createSimple (const ASTContext &context,
@@ -277,8 +277,6 @@ DeclAttribute *DeclAttribute::createSimple(const ASTContext &context,
277
277
case DeclAttrKind::CLASS: \
278
278
return new (context) CLASS##Attr (atLoc, attrLoc);
279
279
#include " swift/AST/DeclAttr.def"
280
- case DeclAttrKind::Count:
281
- llvm_unreachable (" bad decl attribute kind" );
282
280
}
283
281
llvm_unreachable (" bad decl attribute kind" );
284
282
}
@@ -1703,9 +1701,6 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
1703
1701
break ;
1704
1702
}
1705
1703
1706
- case DeclAttrKind::Count:
1707
- llvm_unreachable (" exceed declaration attribute kinds" );
1708
-
1709
1704
#define SIMPLE_DECL_ATTR (X, CLASS, ...) case DeclAttrKind::CLASS:
1710
1705
#include " swift/AST/DeclAttr.def"
1711
1706
llvm_unreachable (" handled above" );
@@ -1737,8 +1732,6 @@ void DeclAttribute::print(llvm::raw_ostream &OS, const Decl *D) const {
1737
1732
1738
1733
uint64_t DeclAttribute::getOptions (DeclAttrKind DK) {
1739
1734
switch (DK) {
1740
- case DeclAttrKind::Count:
1741
- llvm_unreachable (" getOptions needs a valid attribute" );
1742
1735
#define DECL_ATTR (_, CLASS, OPTIONS, ...) \
1743
1736
case DeclAttrKind::CLASS: \
1744
1737
return OPTIONS;
@@ -1749,8 +1742,6 @@ uint64_t DeclAttribute::getOptions(DeclAttrKind DK) {
1749
1742
1750
1743
StringRef DeclAttribute::getAttrName () const {
1751
1744
switch (getKind ()) {
1752
- case DeclAttrKind::Count:
1753
- llvm_unreachable (" getAttrName needs a valid attribute" );
1754
1745
#define SIMPLE_DECL_ATTR (NAME, CLASS, ...) \
1755
1746
case DeclAttrKind::CLASS: \
1756
1747
return #NAME;
@@ -2890,19 +2881,20 @@ void swift::simple_display(llvm::raw_ostream &out, const DeclAttribute *attr) {
2890
2881
2891
2882
bool swift::hasAttribute (
2892
2883
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)
2895
2887
return false ;
2896
2888
2897
- if (DeclAttribute::isUserInaccessible (kind))
2889
+ if (DeclAttribute::isUserInaccessible (* kind))
2898
2890
return false ;
2899
- if (DeclAttribute::isDeclModifier (kind))
2891
+ if (DeclAttribute::isDeclModifier (* kind))
2900
2892
return false ;
2901
- if (DeclAttribute::shouldBeRejectedByParser (kind))
2893
+ if (DeclAttribute::shouldBeRejectedByParser (* kind))
2902
2894
return false ;
2903
- if (DeclAttribute::isSilOnly (kind))
2895
+ if (DeclAttribute::isSilOnly (* kind))
2904
2896
return false ;
2905
- if (DeclAttribute::isConcurrencyOnly (kind))
2897
+ if (DeclAttribute::isConcurrencyOnly (* kind))
2906
2898
return false ;
2907
2899
2908
2900
return true ;
0 commit comments