@@ -208,8 +208,24 @@ struct NodeMatcher {
208
208
virtual ~NodeMatcher () = default ;
209
209
};
210
210
211
- #define KEY (NAME ) static const char * Key_##NAME = #NAME;
211
+ enum class KeyKind {
212
+ #define KEY (NAME ) KK_##NAME,
212
213
#include " DigesterEnums.def"
214
+ };
215
+
216
+ static KeyKind parseKeyKind (StringRef Content) {
217
+ return llvm::StringSwitch<KeyKind>(Content)
218
+ #define KEY (NAME ) .Case(#NAME, KeyKind::KK_##NAME)
219
+ #include " DigesterEnums.def"
220
+ ;
221
+ }
222
+
223
+ static StringRef getKeyContent (KeyKind Kind) {
224
+ switch (Kind) {
225
+ #define KEY (NAME ) case KeyKind::KK_##NAME: return InsertToBuffer(#NAME);
226
+ #include " DigesterEnums.def"
227
+ }
228
+ }
213
229
214
230
// The node kind appearing in the tree that describes the content of the SDK
215
231
enum class SDKNodeKind {
@@ -751,36 +767,49 @@ NodeUniquePtr SDKNode::constructSDKNode(llvm::yaml::MappingNode *Node) {
751
767
NodeOwnedVector Children;
752
768
753
769
for (auto Pair : *Node) {
754
- auto Key = GetScalarString (Pair.getKey ());
755
- if (Key == Key_kind) {
770
+ switch ( parseKeyKind ( GetScalarString (Pair.getKey ()))) {
771
+ case KeyKind::KK_kind:
756
772
Kind = llvm::StringSwitch<SDKNodeKind>(GetScalarString (Pair.getValue ()))
757
773
#define NODE_KIND (NAME ) .Case(#NAME, SDKNodeKind::NAME)
758
774
#include " DigesterEnums.def"
759
775
;
760
- } else if (Key == Key_name) {
776
+ break ;
777
+ case KeyKind::KK_name:
761
778
Info.Name = GetScalarString (Pair.getValue ());
762
- } else if (Key == Key_selfIndex) {
779
+ break ;
780
+ case KeyKind::KK_selfIndex:
763
781
Info.SelfIndex = std::stoi (cast<llvm::yaml::ScalarNode>(Pair.getValue ())->
764
782
getRawValue ());
765
- } else if (Key == Key_usr) {
783
+ break ;
784
+ case KeyKind::KK_usr:
766
785
Info.USR = GetScalarString (Pair.getValue ());
767
- } else if (Key == Key_location) {
786
+ break ;
787
+
788
+ case KeyKind::KK_location:
768
789
Info.Location = GetScalarString (Pair.getValue ());
769
- } else if (Key == Key_children) {
790
+ break ;
791
+ case KeyKind::KK_children:
770
792
for (auto &Mapping : *cast<llvm::yaml::SequenceNode>(Pair.getValue ())) {
771
793
Children.push_back (constructSDKNode (cast<llvm::yaml::MappingNode>(&Mapping)));
772
794
}
773
- } else if (Key == Key_printedName) {
795
+ break ;
796
+ case KeyKind::KK_printedName:
774
797
Info.PrintedName = GetScalarString (Pair.getValue ());
775
- } else if (Key == Key_moduleName) {
798
+ break ;
799
+ case KeyKind::KK_moduleName:
776
800
Info.ModuleName = GetScalarString (Pair.getValue ());
777
- } else if (Key == Key_throwing) {
801
+ break ;
802
+ case KeyKind::KK_throwing:
778
803
Info.IsThrowing = true ;
779
- } else if (Key == Key_mutating) {
804
+ break ;
805
+ case KeyKind::KK_mutating:
780
806
Info.IsMutating = true ;
781
- } else if (Key == Key_static) {
807
+ break ;
808
+ case KeyKind::KK_static:
782
809
Info.IsStatic = true ;
783
- } else if (Key == Key_typeAttributes) {
810
+ break ;
811
+
812
+ case KeyKind::KK_typeAttributes: {
784
813
auto *Seq = cast<llvm::yaml::SequenceNode>(Pair.getValue ());
785
814
for (auto It = Seq->begin (); It != Seq->end (); ++ It) {
786
815
Info.TypeAttrs .push_back (
@@ -789,7 +818,9 @@ NodeUniquePtr SDKNode::constructSDKNode(llvm::yaml::MappingNode *Node) {
789
818
#include " swift/AST/Attr.def"
790
819
.Case (" Count" , TypeAttrKind::TAK_Count));
791
820
}
792
- } else if (Key == Key_declAttributes) {
821
+ break ;
822
+ }
823
+ case KeyKind::KK_declAttributes: {
793
824
auto *Seq = cast<llvm::yaml::SequenceNode>(Pair.getValue ());
794
825
for (auto It = Seq->begin (); It != Seq->end (); ++ It) {
795
826
Info.DeclAttrs .push_back (
@@ -798,13 +829,14 @@ NodeUniquePtr SDKNode::constructSDKNode(llvm::yaml::MappingNode *Node) {
798
829
#include " DigesterEnums.def"
799
830
);
800
831
}
801
- } else if (Key == Key_declKind) {
832
+ break ;
833
+ }
834
+ case KeyKind::KK_declKind:
802
835
Info.DKind = llvm::StringSwitch<DeclKind>(GetScalarString (Pair.getValue ()))
803
836
#define DECL (X, PARENT ) .Case(#X, DeclKind::X)
804
837
#include " swift/AST/DeclNodes.def"
805
838
;
806
- } else {
807
- llvm_unreachable (" Cannot parse key." );
839
+ break ;
808
840
}
809
841
};
810
842
NodeUniquePtr Result = Info.createSDKNode (Kind);
@@ -1315,44 +1347,51 @@ namespace swift {
1315
1347
auto Name = value->getName ();
1316
1348
auto PrintedName = value->getPrintedName ();
1317
1349
1318
- out.mapRequired (Key_kind, Kind);
1319
- out.mapRequired (Key_name, Name);
1320
- out.mapRequired (Key_printedName, PrintedName);
1350
+ out.mapRequired (getKeyContent (KeyKind::KK_kind).data (), Kind);
1351
+ out.mapRequired (getKeyContent (KeyKind::KK_name).data (), Name);
1352
+ out.mapRequired (getKeyContent (KeyKind::KK_printedName).data (),
1353
+ PrintedName);
1321
1354
1322
1355
if (auto D = dyn_cast<SDKNodeDecl>(value.get ())) {
1323
1356
DeclKind DK = D->getDeclKind ();
1324
1357
StringRef Usr = D->getUsr ();
1325
1358
StringRef Location = D->getLocation ();
1326
1359
StringRef ModuleName = D->getModuleName ();
1327
1360
1328
- out.mapRequired (Key_declKind, DK);
1329
- out.mapRequired (Key_usr, Usr);
1330
- out.mapRequired (Key_location, Location);
1331
- out.mapRequired (Key_moduleName, ModuleName);
1361
+ out.mapRequired (getKeyContent (KeyKind::KK_declKind).data (), DK);
1362
+ out.mapRequired (getKeyContent (KeyKind::KK_usr).data (), Usr);
1363
+ out.mapRequired (getKeyContent (KeyKind::KK_location).data (), Location);
1364
+ out.mapRequired (getKeyContent (KeyKind::KK_moduleName).data (),
1365
+ ModuleName);
1332
1366
if (auto isStatic = D->isStatic ())
1333
- out.mapRequired (Key_static , isStatic);
1367
+ out.mapRequired (getKeyContent (KeyKind::KK_static). data () , isStatic);
1334
1368
1335
1369
if (auto F = dyn_cast<SDKNodeAbstractFunc>(value.get ())) {
1336
1370
if (bool isThrowing = F->isThrowing ())
1337
- out.mapRequired (Key_throwing, isThrowing);
1371
+ out.mapRequired (getKeyContent (KeyKind::KK_throwing).data (),
1372
+ isThrowing);
1338
1373
if (bool isMutating = F->isMutating ())
1339
- out.mapRequired (Key_mutating, isMutating);
1374
+ out.mapRequired (getKeyContent (KeyKind::KK_mutating).data (),
1375
+ isMutating);
1340
1376
if (F->hasSelfIndex ()) {
1341
1377
auto Index = F->getSelfIndex ();
1342
- out.mapRequired (Key_selfIndex, Index);
1378
+ out.mapRequired (getKeyContent (KeyKind::KK_selfIndex).data (),
1379
+ Index);
1343
1380
}
1344
1381
}
1345
1382
auto Attributes = D->getDeclAttributes ();
1346
1383
if (!Attributes.empty ())
1347
- out.mapRequired (Key_declAttributes, Attributes);
1384
+ out.mapRequired (getKeyContent (KeyKind::KK_declAttributes).data (),
1385
+ Attributes);
1348
1386
} else if (auto T = dyn_cast<SDKNodeType>(value.get ())) {
1349
1387
auto Attributes = T->getTypeAttributes ();
1350
1388
if (!Attributes.empty ())
1351
- out.mapRequired (Key_typeAttributes, Attributes);
1389
+ out.mapRequired (getKeyContent (KeyKind::KK_typeAttributes).data (),
1390
+ Attributes);
1352
1391
}
1353
1392
if (!value->isLeaf ()) {
1354
1393
ArrayRef<NodeUniquePtr> Children = value->getChildren ();
1355
- out.mapRequired (Key_children , Children);
1394
+ out.mapRequired (getKeyContent (KeyKind::KK_children). data () , Children);
1356
1395
}
1357
1396
}
1358
1397
};
0 commit comments