@@ -3693,6 +3693,25 @@ bool Parser::parseConventionAttributeInternal(
3693
3693
return false ;
3694
3694
}
3695
3695
3696
+ bool Parser::parseUUIDString (UUID &uuid, Diag<> diagnostic) {
3697
+ if (!Tok.is (tok::string_literal)) {
3698
+ diagnose (Tok, diagnostic);
3699
+ return true ;
3700
+ }
3701
+
3702
+ bool failed = true ;
3703
+ auto literalText = Tok.getText ().slice (1 , Tok.getText ().size () - 1 );
3704
+ llvm::SmallString<UUID::StringBufferSize> text (literalText);
3705
+ if (auto id = UUID::fromString (text.c_str ())) {
3706
+ uuid = *id;
3707
+ failed = false ;
3708
+ } else {
3709
+ diagnose (Tok, diagnostic);
3710
+ }
3711
+ consumeToken (tok::string_literal);
3712
+ return failed;
3713
+ }
3714
+
3696
3715
// / \verbatim
3697
3716
// / attribute-type:
3698
3717
// / 'noreturn'
@@ -3882,24 +3901,12 @@ ParserStatus Parser::parseTypeAttribute(TypeAttributes &Attributes,
3882
3901
// Parse the opened existential ID string in parens
3883
3902
SourceLoc beginLoc = Tok.getLoc (), idLoc, endLoc;
3884
3903
if (consumeIfNotAtStartOfLine (tok::l_paren)) {
3885
- if (Tok.is (tok::string_literal)) {
3886
- UUID openedID;
3887
- idLoc = Tok.getLoc ();
3888
- auto literalText = Tok.getText ().slice (1 , Tok.getText ().size () - 1 );
3889
- llvm::SmallString<UUID::StringBufferSize> text (literalText);
3890
- if (auto openedID = UUID::fromString (text.c_str ())) {
3891
- Attributes.OpenedID = openedID;
3892
- } else {
3893
- diagnose (Tok, diag::opened_attribute_id_value);
3894
- }
3895
- consumeToken ();
3896
- } else {
3897
- diagnose (Tok, diag::opened_attribute_id_value);
3898
- }
3899
-
3900
- if (Tok.is (tok::comma)) {
3901
- consumeToken (tok::comma);
3904
+ idLoc = Tok.getLoc ();
3905
+ UUID id;
3906
+ if (!parseUUIDString (id, diag::opened_attribute_id_value))
3907
+ Attributes.OpenedID = id;
3902
3908
3909
+ if (consumeIf (tok::comma)) {
3903
3910
auto constraintType = parseType (diag::expected_type);
3904
3911
if (constraintType.isNonNull ())
3905
3912
Attributes.ConstraintType = constraintType.getPtrOrNull ();
0 commit comments