Skip to content

Commit 9cd54c4

Browse files
authored
libSyntax: encapsulate members of a struct declaration into MemberDeclBlock. (#13193)
1 parent 1dfba34 commit 9cd54c4

File tree

6 files changed

+314
-252
lines changed

6 files changed

+314
-252
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,7 @@ void Parser::diagnoseConsecutiveIDs(StringRef First, SourceLoc FirstLoc,
29272927
ParserStatus Parser::parseDeclItem(bool &PreviousHadSemi,
29282928
Parser::ParseDeclOptions Options,
29292929
llvm::function_ref<void(Decl*)> handler) {
2930+
SyntaxParsingContext DeclContext(SyntaxContext, SyntaxContextKind::Decl);
29302931
if (Tok.is(tok::semi)) {
29312932
// Consume ';' without preceding decl.
29322933
diagnose(Tok, diag::unexpected_separator, ";")
@@ -2971,15 +2972,17 @@ bool Parser::parseDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
29712972
llvm::function_ref<void(Decl*)> handler) {
29722973
ParserStatus Status;
29732974
bool PreviousHadSemi = true;
2974-
while (Tok.isNot(tok::r_brace)) {
2975-
Status |= parseDeclItem(PreviousHadSemi, Options, handler);
2976-
if (Tok.isAny(tok::eof, tok::pound_endif, tok::pound_else,
2977-
tok::pound_elseif)) {
2978-
IsInputIncomplete = true;
2979-
break;
2975+
{
2976+
SyntaxParsingContext ListContext(SyntaxContext, SyntaxKind::DeclList);
2977+
while (Tok.isNot(tok::r_brace)) {
2978+
Status |= parseDeclItem(PreviousHadSemi, Options, handler);
2979+
if (Tok.isAny(tok::eof, tok::pound_endif, tok::pound_else,
2980+
tok::pound_elseif)) {
2981+
IsInputIncomplete = true;
2982+
break;
2983+
}
29802984
}
29812985
}
2982-
29832986
parseMatchingToken(tok::r_brace, RBLoc, ErrorDiag, LBLoc);
29842987

29852988
// If we found the closing brace, then the caller should not care if there
@@ -5384,7 +5387,8 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
53845387
}
53855388

53865389
SD->setGenericParams(GenericParams);
5387-
5390+
// Make the entities of the struct as a code block.
5391+
SyntaxParsingContext BlockContext(SyntaxContext, SyntaxKind::MemberDeclBlock);
53885392
SourceLoc LBLoc, RBLoc;
53895393
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_struct)) {
53905394
LBLoc = PreviousLoc;

test/Syntax/Inputs/serialize_multiple_decls.json

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,42 @@
6363
"presence": "Present"
6464
},
6565
{
66-
"tokenKind": {
67-
"kind": "l_brace"
68-
},
69-
"leadingTrivia": [
66+
"kind": "MemberDeclBlock",
67+
"layout": [
68+
{
69+
"tokenKind": {
70+
"kind": "l_brace"
71+
},
72+
"leadingTrivia": [
7073

71-
],
72-
"trailingTrivia": [
74+
],
75+
"trailingTrivia": [
7376

74-
],
75-
"presence": "Present"
76-
},
77-
{
78-
"tokenKind": {
79-
"kind": "r_brace"
80-
},
81-
"leadingTrivia": [
77+
],
78+
"presence": "Present"
79+
},
8280
{
83-
"kind": "Newline",
84-
"value": 1
85-
}
86-
],
87-
"trailingTrivia": [
81+
"kind": "DeclList",
82+
"layout": [
8883

84+
],
85+
"presence": "Present"
86+
},
87+
{
88+
"tokenKind": {
89+
"kind": "r_brace"
90+
},
91+
"leadingTrivia": [
92+
{
93+
"kind": "Newline",
94+
"value": 1
95+
}
96+
],
97+
"trailingTrivia": [
98+
99+
],
100+
"presence": "Present"
101+
}
89102
],
90103
"presence": "Present"
91104
}
@@ -148,29 +161,42 @@
148161
"presence": "Present"
149162
},
150163
{
151-
"tokenKind": {
152-
"kind": "l_brace"
153-
},
154-
"leadingTrivia": [
164+
"kind": "MemberDeclBlock",
165+
"layout": [
166+
{
167+
"tokenKind": {
168+
"kind": "l_brace"
169+
},
170+
"leadingTrivia": [
155171

156-
],
157-
"trailingTrivia": [
172+
],
173+
"trailingTrivia": [
158174

159-
],
160-
"presence": "Present"
161-
},
162-
{
163-
"tokenKind": {
164-
"kind": "r_brace"
165-
},
166-
"leadingTrivia": [
175+
],
176+
"presence": "Present"
177+
},
167178
{
168-
"kind": "Newline",
169-
"value": 1
170-
}
171-
],
172-
"trailingTrivia": [
179+
"kind": "DeclList",
180+
"layout": [
173181

182+
],
183+
"presence": "Present"
184+
},
185+
{
186+
"tokenKind": {
187+
"kind": "r_brace"
188+
},
189+
"leadingTrivia": [
190+
{
191+
"kind": "Newline",
192+
"value": 1
193+
}
194+
],
195+
"trailingTrivia": [
196+
197+
],
198+
"presence": "Present"
199+
}
174200
],
175201
"presence": "Present"
176202
}

0 commit comments

Comments
 (0)