@@ -596,36 +596,43 @@ void SILParser::setLocalValue(ValueBase *Value, StringRef Name,
596
596
// / 'hidden_external'
597
597
// / 'private_external'
598
598
static bool parseSILLinkage (Optional<SILLinkage> &Result, Parser &P) {
599
+ // Begin by initializing result to our base value of None.
600
+ Result = None;
601
+
602
+ // Unfortunate collision with access control keywords.
599
603
if (P.Tok .is (tok::kw_public)) {
600
- // Unfortunate collision with access control keywords.
601
604
Result = SILLinkage::Public;
602
605
P.consumeToken ();
603
- } else if (P.Tok .is (tok::kw_private)) {
606
+ return false ;
607
+ }
608
+
609
+ // Unfortunate collision with access control keywords.
610
+ if (P.Tok .is (tok::kw_private)) {
604
611
Result = SILLinkage::Private;
605
612
P.consumeToken ();
606
- } else if (P.Tok .isNot (tok::identifier)) {
607
- Result = None;
608
- } else if (P.Tok .getText () == " hidden" ) {
609
- Result = SILLinkage::Hidden;
610
- P.consumeToken (tok::identifier);
611
- } else if (P.Tok .getText () == " shared" ) {
612
- Result = SILLinkage::Shared;
613
- P.consumeToken (tok::identifier);
614
- } else if (P.Tok .getText () == " public_external" ) {
615
- Result = SILLinkage::PublicExternal;
616
- P.consumeToken (tok::identifier);
617
- } else if (P.Tok .getText () == " hidden_external" ) {
618
- Result = SILLinkage::HiddenExternal;
619
- P.consumeToken (tok::identifier);
620
- } else if (P.Tok .getText () == " shared_external" ) {
621
- Result = SILLinkage::SharedExternal;
622
- P.consumeToken (tok::identifier);
623
- } else if (P.Tok .getText () == " private_external" ) {
624
- Result = SILLinkage::PrivateExternal;
613
+ return false ;
614
+ }
615
+
616
+ // If we do not have an identifier, bail. All SILLinkages that we are parsing
617
+ // are identifiers.
618
+ if (P.Tok .isNot (tok::identifier))
619
+ return false ;
620
+
621
+ // Then use a string switch to try and parse the identifier.
622
+ Result = llvm::StringSwitch<Optional<SILLinkage>>(P.Tok .getText ())
623
+ .Case (" hidden" , SILLinkage::Hidden)
624
+ .Case (" shared" , SILLinkage::Shared)
625
+ .Case (" public_external" , SILLinkage::PublicExternal)
626
+ .Case (" hidden_external" , SILLinkage::HiddenExternal)
627
+ .Case (" shared_external" , SILLinkage::SharedExternal)
628
+ .Case (" private_external" , SILLinkage::PrivateExternal)
629
+ .Default (None);
630
+
631
+ // If we succeed, consume the token.
632
+ if (Result) {
625
633
P.consumeToken (tok::identifier);
626
- } else {
627
- Result = None;
628
634
}
635
+
629
636
return false ;
630
637
}
631
638
0 commit comments