@@ -239,6 +239,12 @@ namespace {
239
239
SmallVector<ValueDecl *, 4 > values;
240
240
return parseSILDottedPath (Decl, values);
241
241
}
242
+ bool parseSILDottedPathWithoutPound (ValueDecl *&Decl,
243
+ SmallVectorImpl<ValueDecl *> &values);
244
+ bool parseSILDottedPathWithoutPound (ValueDecl *&Decl) {
245
+ SmallVector<ValueDecl *, 4 > values;
246
+ return parseSILDottedPathWithoutPound (Decl, values);
247
+ }
242
248
// / At the time of calling this function, we may not have the type of the
243
249
// / Decl yet. So we return a SILDeclRef on the first lookup result and also
244
250
// / return all the lookup results. After parsing the expected type, the
@@ -676,75 +682,83 @@ static bool parseDeclSILOptional(bool *isTransparent, bool *isFragile,
676
682
Inline_t *inlineStrategy, bool *isLet,
677
683
SmallVectorImpl<std::string> *Semantics,
678
684
SmallVectorImpl<ParsedSpecAttr> *SpecAttrs,
679
- EffectsKind *MRK, Parser &P) {
680
- while (P.consumeIf (tok::l_square)) {
681
- if (isLet && P.Tok .is (tok::kw_let)) {
685
+ ValueDecl **ClangDecl,
686
+ EffectsKind *MRK, SILParser &SP) {
687
+ while (SP.P .consumeIf (tok::l_square)) {
688
+ if (isLet && SP.P .Tok .is (tok::kw_let)) {
682
689
*isLet = true ;
683
- P.consumeToken (tok::kw_let);
684
- P.parseToken (tok::r_square, diag::expected_in_attribute_list);
690
+ SP. P .consumeToken (tok::kw_let);
691
+ SP. P .parseToken (tok::r_square, diag::expected_in_attribute_list);
685
692
continue ;
686
693
}
687
- else if (P.Tok .isNot (tok::identifier)) {
688
- P.diagnose (P.Tok , diag::expected_in_attribute_list);
694
+ else if (SP. P .Tok .isNot (tok::identifier)) {
695
+ SP. P .diagnose (SP. P .Tok , diag::expected_in_attribute_list);
689
696
return true ;
690
- } else if (isTransparent && P.Tok .getText () == " transparent" )
697
+ } else if (isTransparent && SP. P .Tok .getText () == " transparent" )
691
698
*isTransparent = true ;
692
- else if (isFragile && P.Tok .getText () == " fragile" )
699
+ else if (isFragile && SP. P .Tok .getText () == " fragile" )
693
700
*isFragile = true ;
694
- else if (isThunk && P.Tok .getText () == " thunk" )
701
+ else if (isThunk && SP. P .Tok .getText () == " thunk" )
695
702
*isThunk = IsThunk;
696
- else if (isThunk && P.Tok .getText () == " reabstraction_thunk" )
703
+ else if (isThunk && SP. P .Tok .getText () == " reabstraction_thunk" )
697
704
*isThunk = IsReabstractionThunk;
698
- else if (isGlobalInit && P.Tok .getText () == " global_init" )
705
+ else if (isGlobalInit && SP. P .Tok .getText () == " global_init" )
699
706
*isGlobalInit = true ;
700
- else if (inlineStrategy && P.Tok .getText () == " noinline" )
707
+ else if (inlineStrategy && SP. P .Tok .getText () == " noinline" )
701
708
*inlineStrategy = NoInline;
702
- else if (inlineStrategy && P.Tok .getText () == " always_inline" )
709
+ else if (inlineStrategy && SP. P .Tok .getText () == " always_inline" )
703
710
*inlineStrategy = AlwaysInline;
704
- else if (MRK && P.Tok .getText () == " readnone" )
711
+ else if (MRK && SP. P .Tok .getText () == " readnone" )
705
712
*MRK = EffectsKind::ReadNone;
706
- else if (MRK && P.Tok .getText () == " readonly" )
713
+ else if (MRK && SP. P .Tok .getText () == " readonly" )
707
714
*MRK = EffectsKind::ReadOnly;
708
- else if (MRK && P.Tok .getText () == " readwrite" )
715
+ else if (MRK && SP. P .Tok .getText () == " readwrite" )
709
716
*MRK = EffectsKind::ReadWrite;
710
- else if (Semantics && P.Tok .getText () == " _semantics" ) {
711
- P.consumeToken (tok::identifier);
712
- if (P.Tok .getKind () != tok::string_literal) {
713
- P.diagnose (P.Tok , diag::expected_in_attribute_list);
717
+ else if (Semantics && SP. P .Tok .getText () == " _semantics" ) {
718
+ SP. P .consumeToken (tok::identifier);
719
+ if (SP. P .Tok .getKind () != tok::string_literal) {
720
+ SP. P .diagnose (SP. P .Tok , diag::expected_in_attribute_list);
714
721
return true ;
715
722
}
716
723
717
724
// Drop the double quotes.
718
- StringRef rawString = P.Tok .getText ().drop_front ().drop_back ();
725
+ StringRef rawString = SP. P .Tok .getText ().drop_front ().drop_back ();
719
726
Semantics->push_back (rawString);
720
- P.consumeToken (tok::string_literal);
727
+ SP. P .consumeToken (tok::string_literal);
721
728
722
- P.parseToken (tok::r_square, diag::expected_in_attribute_list);
729
+ SP. P .parseToken (tok::r_square, diag::expected_in_attribute_list);
723
730
continue ;
724
731
}
725
- else if (SpecAttrs && P.Tok .getText () == " _specialize" ) {
726
- P.consumeToken (tok::identifier);
732
+ else if (SpecAttrs && SP. P .Tok .getText () == " _specialize" ) {
733
+ SP. P .consumeToken (tok::identifier);
727
734
728
735
// / Parse a specialized attributed, building a parsed substitution list
729
736
// / and pushing a new ParsedSpecAttr on the SpecAttrs list. Conformances
730
737
// / cannot be generated until the function declaration is fully parsed so
731
738
// / that the function's generic signature can be consulted.
732
- SILParser SpecAttrState (P);
733
739
ParsedSpecAttr SpecAttr;
734
- if (SpecAttrState .parseApplySubstitutions (SpecAttr.subs ))
740
+ if (SP .parseApplySubstitutions (SpecAttr.subs ))
735
741
return true ;
736
742
737
743
SpecAttrs->emplace_back (SpecAttr);
738
744
739
- P.parseToken (tok::r_square, diag::expected_in_attribute_list);
745
+ SP.P .parseToken (tok::r_square, diag::expected_in_attribute_list);
746
+ continue ;
747
+ }
748
+ else if (ClangDecl && SP.P .Tok .getText () == " clang" ) {
749
+ SP.P .consumeToken (tok::identifier);
750
+ if (SP.parseSILDottedPathWithoutPound (*ClangDecl))
751
+ return true ;
752
+
753
+ SP.P .parseToken (tok::r_square, diag::expected_in_attribute_list);
740
754
continue ;
741
755
}
742
756
else {
743
- P.diagnose (P.Tok , diag::expected_in_attribute_list);
757
+ SP. P .diagnose (SP. P .Tok , diag::expected_in_attribute_list);
744
758
return true ;
745
759
}
746
- P.consumeToken (tok::identifier);
747
- P.parseToken (tok::r_square, diag::expected_in_attribute_list);
760
+ SP. P .consumeToken (tok::identifier);
761
+ SP. P .parseToken (tok::r_square, diag::expected_in_attribute_list);
748
762
}
749
763
return false ;
750
764
}
@@ -875,7 +889,11 @@ bool SILParser::parseSILDottedPath(ValueDecl *&Decl,
875
889
SmallVectorImpl<ValueDecl *> &values) {
876
890
if (P.parseToken (tok::pound, diag::expected_sil_constant))
877
891
return true ;
892
+ return parseSILDottedPathWithoutPound (Decl, values);
893
+ }
878
894
895
+ bool SILParser::parseSILDottedPathWithoutPound (ValueDecl *&Decl,
896
+ SmallVectorImpl<ValueDecl *> &values) {
879
897
// Handle sil-dotted-path.
880
898
Identifier Id;
881
899
SmallVector<Identifier, 4 > FullName;
@@ -3858,11 +3876,12 @@ bool Parser::parseDeclSIL() {
3858
3876
Inline_t inlineStrategy = InlineDefault;
3859
3877
SmallVector<std::string, 1 > Semantics;
3860
3878
SmallVector<ParsedSpecAttr, 4 > SpecAttrs;
3879
+ ValueDecl *ClangDecl = nullptr ;
3861
3880
EffectsKind MRK = EffectsKind::Unspecified;
3862
3881
if (parseSILLinkage (FnLinkage, *this ) ||
3863
3882
parseDeclSILOptional (&isTransparent, &isFragile, &isThunk, &isGlobalInit,
3864
3883
&inlineStrategy, nullptr , &Semantics, &SpecAttrs,
3865
- &MRK, * this ) ||
3884
+ &ClangDecl, & MRK, FunctionState ) ||
3866
3885
parseToken (tok::at_sign, diag::expected_sil_function_name) ||
3867
3886
parseIdentifier (FnName, FnNameLoc, diag::expected_sil_function_name) ||
3868
3887
parseToken (tok::colon, diag::expected_sil_type))
@@ -3889,6 +3908,8 @@ bool Parser::parseDeclSIL() {
3889
3908
FunctionState.F ->setGlobalInit (isGlobalInit);
3890
3909
FunctionState.F ->setInlineStrategy (inlineStrategy);
3891
3910
FunctionState.F ->setEffectsKind (MRK);
3911
+ if (ClangDecl)
3912
+ FunctionState.F ->setClangNodeOwner (ClangDecl);
3892
3913
for (auto &Attr : Semantics) {
3893
3914
FunctionState.F ->addSemanticsAttr (Attr);
3894
3915
}
@@ -3997,15 +4018,16 @@ bool Parser::parseSILGlobal() {
3997
4018
// Inform the lexer that we're lexing the body of the SIL declaration.
3998
4019
Lexer::SILBodyRAII Tmp (*L);
3999
4020
Scope S (this , ScopeKind::TopLevel);
4021
+ SILParser State (*this );
4000
4022
if (parseSILLinkage (GlobalLinkage, *this ) ||
4001
4023
parseDeclSILOptional (nullptr , &isFragile, nullptr , nullptr ,
4002
- nullptr , &isLet, nullptr , nullptr , nullptr , *this ) ||
4024
+ nullptr , &isLet, nullptr , nullptr , nullptr ,
4025
+ nullptr , State) ||
4003
4026
parseToken (tok::at_sign, diag::expected_sil_value_name) ||
4004
4027
parseIdentifier (GlobalName, NameLoc, diag::expected_sil_value_name) ||
4005
4028
parseToken (tok::colon, diag::expected_sil_type))
4006
4029
return true ;
4007
4030
4008
- SILParser State (*this );
4009
4031
if (State.parseSILType (GlobalType))
4010
4032
return true ;
4011
4033
@@ -4342,7 +4364,8 @@ bool Parser::parseSILWitnessTable() {
4342
4364
4343
4365
bool isFragile = false ;
4344
4366
if (parseDeclSILOptional (nullptr , &isFragile, nullptr , nullptr ,
4345
- nullptr , nullptr , nullptr , nullptr , nullptr , *this ))
4367
+ nullptr , nullptr , nullptr , nullptr , nullptr ,
4368
+ nullptr , WitnessState))
4346
4369
return true ;
4347
4370
4348
4371
Scope S (this , ScopeKind::TopLevel);
0 commit comments