@@ -3651,6 +3651,25 @@ bool Parser::parseConventionAttributeInternal(
3651
3651
return false ;
3652
3652
}
3653
3653
3654
+ bool Parser::parseUUIDString (UUID &uuid, Diag<> diagnostic) {
3655
+ if (!Tok.is (tok::string_literal)) {
3656
+ diagnose (Tok, diagnostic);
3657
+ return true ;
3658
+ }
3659
+
3660
+ bool failed = true ;
3661
+ auto literalText = Tok.getText ().slice (1 , Tok.getText ().size () - 1 );
3662
+ llvm::SmallString<UUID::StringBufferSize> text (literalText);
3663
+ if (auto id = UUID::fromString (text.c_str ())) {
3664
+ uuid = *id;
3665
+ failed = false ;
3666
+ } else {
3667
+ diagnose (Tok, diagnostic);
3668
+ }
3669
+ consumeToken (tok::string_literal);
3670
+ return failed;
3671
+ }
3672
+
3654
3673
// / \verbatim
3655
3674
// / attribute-type:
3656
3675
// / 'noreturn'
@@ -3840,24 +3859,12 @@ ParserStatus Parser::parseTypeAttribute(TypeAttributes &Attributes,
3840
3859
// Parse the opened existential ID string in parens
3841
3860
SourceLoc beginLoc = Tok.getLoc (), idLoc, endLoc;
3842
3861
if (consumeIfNotAtStartOfLine (tok::l_paren)) {
3843
- if (Tok.is (tok::string_literal)) {
3844
- UUID openedID;
3845
- idLoc = Tok.getLoc ();
3846
- auto literalText = Tok.getText ().slice (1 , Tok.getText ().size () - 1 );
3847
- llvm::SmallString<UUID::StringBufferSize> text (literalText);
3848
- if (auto openedID = UUID::fromString (text.c_str ())) {
3849
- Attributes.OpenedID = openedID;
3850
- } else {
3851
- diagnose (Tok, diag::opened_attribute_id_value);
3852
- }
3853
- consumeToken ();
3854
- } else {
3855
- diagnose (Tok, diag::opened_attribute_id_value);
3856
- }
3857
-
3858
- if (Tok.is (tok::comma)) {
3859
- consumeToken (tok::comma);
3862
+ idLoc = Tok.getLoc ();
3863
+ UUID id;
3864
+ if (!parseUUIDString (id, diag::opened_attribute_id_value))
3865
+ Attributes.OpenedID = id;
3860
3866
3867
+ if (consumeIf (tok::comma)) {
3861
3868
auto constraintType = parseType (diag::expected_type);
3862
3869
if (constraintType.isNonNull ())
3863
3870
Attributes.ConstraintType = constraintType.getPtrOrNull ();
0 commit comments