Skip to content

Commit 2f40f24

Browse files
committed
Revert "Merge pull request swiftlang#27565 from rintaro/syntaxparse-exprcollection"
This reverts commit 1724f5b, reversing changes made to bc1a3ea.
1 parent 0e8010d commit 2f40f24

17 files changed

+555
-736
lines changed

include/swift/AST/TypeRepr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ struct TupleTypeReprElement {
653653
TypeRepr *Type;
654654
SourceLoc TrailingCommaLoc;
655655

656-
TupleTypeReprElement(): Type(nullptr) {}
656+
TupleTypeReprElement() {}
657657
TupleTypeReprElement(TypeRepr *Type): Type(Type) {}
658658
};
659659

include/swift/Parse/ASTGen.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ class ASTGen {
3737

3838
// FIXME: remove when Syntax can represent all types and ASTGen can handle
3939
// them
40-
/// Exprs that cannot be represented by Syntax or generated by ASTGen.
41-
llvm::DenseMap<SourceLoc, Expr *> Exprs;
42-
4340
/// Decl attributes that cannot be represented by Syntax or generated by
4441
/// ASTGen.
4542
llvm::DenseMap<SourceLoc, DeclAttributes> ParsedDeclAttrs;
@@ -84,9 +81,6 @@ class ASTGen {
8481

8582
Expr *generate(const syntax::ExprSyntax &Expr, const SourceLoc Loc);
8683
Expr *generate(const syntax::IdentifierExprSyntax &Expr, const SourceLoc Loc);
87-
Expr *generate(const syntax::SuperRefExprSyntax &Expr, const SourceLoc Loc);
88-
Expr *generate(const syntax::ArrayExprSyntax &Expr, const SourceLoc Loc);
89-
Expr *generate(const syntax::DictionaryExprSyntax &Expr, const SourceLoc Loc);
9084
Expr *generate(const syntax::EditorPlaceholderExprSyntax &Expr,
9185
const SourceLoc Loc);
9286
Expr *generate(const syntax::SpecializeExprSyntax &Expr, const SourceLoc Loc);
@@ -113,7 +107,6 @@ class ASTGen {
113107
const SourceLoc Loc);
114108

115109
private:
116-
void validateCollectionElement(Expr *elementExpr);
117110

118111
Expr *generateMagicIdentifierLiteralExpression(
119112
const syntax::TokenSyntax &PoundToken, const SourceLoc Loc);
@@ -217,13 +210,6 @@ class ASTGen {
217210
static SourceLoc advanceLocBegin(const SourceLoc &Loc,
218211
const syntax::Syntax &Node);
219212

220-
/// Advance \p Loc to the last non-missing token of the \p Node or, if it
221-
/// doesn't contain any, the last non-missing token preceding it in the tree.
222-
/// \p Loc must be the leading trivia of the first token in the tree in which
223-
/// \p Node resides
224-
static SourceLoc advanceLocEnd(const SourceLoc &Loc,
225-
const syntax::Syntax &Node);
226-
227213
ValueDecl *lookupInScope(DeclName Name);
228214

229215
void addToScope(ValueDecl *D, bool diagnoseRedefinitions = true);
@@ -233,13 +219,9 @@ class ASTGen {
233219
TypeRepr *lookupType(syntax::TypeSyntax Type);
234220

235221
public:
236-
void addExpr(Expr *Expr, const SourceLoc Loc);
237-
bool hasExpr(const SourceLoc Loc) const;
238-
Expr *takeExpr(const SourceLoc Loc);
239-
240222
void addDeclAttributes(DeclAttributes attrs, const SourceLoc Loc);
241223
bool hasDeclAttributes(SourceLoc Loc) const;
242-
DeclAttributes takeDeclAttributes(const SourceLoc Loc);
224+
DeclAttributes getDeclAttributes(const SourceLoc Loc) const;
243225
};
244226
} // namespace swift
245227

include/swift/Parse/ParsedRawSyntaxNode.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class ParsedRawSyntaxNode {
5252
};
5353
struct DeferredLayoutNode {
5454
MutableArrayRef<ParsedRawSyntaxNode> Children;
55-
CharSourceRange Range;
5655
};
5756
struct DeferredTokenNode {
5857
const ParsedTriviaPiece *TriviaPieces;
@@ -73,9 +72,9 @@ class ParsedRawSyntaxNode {
7372
/// Primary used for capturing a deferred missing token.
7473
bool IsMissing = false;
7574

76-
ParsedRawSyntaxNode(syntax::SyntaxKind k, CharSourceRange r,
75+
ParsedRawSyntaxNode(syntax::SyntaxKind k,
7776
MutableArrayRef<ParsedRawSyntaxNode> deferredNodes)
78-
: DeferredLayout({deferredNodes, r}),
77+
: DeferredLayout({deferredNodes}),
7978
SynKind(uint16_t(k)), TokKind(uint16_t(tok::unknown)),
8079
DK(DataKind::DeferredLayout) {
8180
assert(getKind() == k && "Syntax kind with too large value!");
@@ -212,12 +211,14 @@ class ParsedRawSyntaxNode {
212211
return copy;
213212
}
214213

215-
CharSourceRange getDeferredRange() const {
214+
CharSourceRange getDeferredRange(bool includeTrivia) const {
216215
switch (DK) {
217216
case DataKind::DeferredLayout:
218-
return getDeferredLayoutRange();
217+
return getDeferredLayoutRange(includeTrivia);
219218
case DataKind::DeferredToken:
220-
return getDeferredTokenRangeWithTrivia();
219+
return includeTrivia
220+
? getDeferredTokenRangeWithTrivia()
221+
: getDeferredTokenRange();
221222
default:
222223
llvm_unreachable("node not deferred");
223224
}
@@ -242,9 +243,20 @@ class ParsedRawSyntaxNode {
242243

243244
// Deferred Layout Data ====================================================//
244245

245-
CharSourceRange getDeferredLayoutRange() const {
246+
CharSourceRange getDeferredLayoutRange(bool includeTrivia) const {
246247
assert(DK == DataKind::DeferredLayout);
247-
return DeferredLayout.Range;
248+
auto HasValidRange = [includeTrivia](const ParsedRawSyntaxNode &Child) {
249+
return !Child.isNull() && !Child.isMissing() &&
250+
Child.getDeferredRange(includeTrivia).isValid();
251+
};
252+
auto first = llvm::find_if(getDeferredChildren(), HasValidRange);
253+
if (first == getDeferredChildren().end())
254+
return CharSourceRange();
255+
auto last = llvm::find_if(llvm::reverse(getDeferredChildren()),
256+
HasValidRange);
257+
auto firstRange = first->getDeferredRange(includeTrivia);
258+
firstRange.widen(last->getDeferredRange(includeTrivia));
259+
return firstRange;
248260
}
249261
ArrayRef<ParsedRawSyntaxNode> getDeferredChildren() const {
250262
assert(DK == DataKind::DeferredLayout);

include/swift/Parse/ParsedSyntaxNodes.h.gyb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ namespace swift {
3232
% if not node.is_syntax_collection():
3333
class Parsed${node.name};
3434
% end
35-
% if node.is_buildable():
36-
class Parsed${node.name}Builder;
37-
% end
3835
% end
3936

4037
% for node in SYNTAX_NODES + PARSEONLY_NODES:
@@ -82,10 +79,6 @@ public:
8279
static bool classof(const ParsedSyntax *S) {
8380
return kindof(S->getKind());
8481
}
85-
86-
% if node.is_buildable():
87-
using Builder = Parsed${node.name}Builder;
88-
% end
8982
};
9083

9184
% end

include/swift/Parse/Parser.h

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -917,12 +917,12 @@ class Parser {
917917
bool AllowSepAfterLast, Diag<> ErrorDiag,
918918
syntax::SyntaxKind Kind,
919919
llvm::function_ref<ParserStatus()> callback);
920-
template <typename ParsedNode>
921-
ParserStatus parseListSyntax(
922-
SmallVectorImpl<ParsedNode> &elements, bool AllowEmpty,
923-
bool AllowSepAfterLast, llvm::function_ref<bool()> isAtCloseTok,
924-
llvm::function_ref<ParserStatus(typename ParsedNode::Builder &)>
925-
callback);
920+
ParserStatus parseListSyntax(tok RightK, SourceLoc LeftLoc,
921+
llvm::Optional<ParsedTokenSyntax> &LastComma,
922+
llvm::Optional<ParsedTokenSyntax> &Right,
923+
llvm::SmallVectorImpl<ParsedSyntax>& Junk,
924+
bool AllowSepAfterLast, Diag<> ErrorDiag,
925+
llvm::function_ref<ParserStatus()> callback);
926926

927927
void consumeTopLevelDecl(ParserPosition BeginParserPosition,
928928
TopLevelCodeDecl *TLCD);
@@ -1428,7 +1428,6 @@ class Parser {
14281428

14291429
//===--------------------------------------------------------------------===//
14301430
// Expression Parsing
1431-
ParsedSyntaxResult<ParsedExprSyntax> parseExpressionSyntax(Diag<> ID);
14321431
ParserResult<Expr> parseExpr(Diag<> ID) {
14331432
return parseExprImpl(ID, /*isExprBasic=*/false);
14341433
}
@@ -1455,7 +1454,6 @@ class Parser {
14551454
ParserResult<Expr> parseExprKeyPath();
14561455
ParserResult<Expr> parseExprSelector();
14571456
ParserResult<Expr> parseExprSuper();
1458-
ParsedSyntaxResult<ParsedExprSyntax> parseExprSuperSyntax();
14591457
ParserResult<Expr> parseExprStringLiteral();
14601458

14611459
// todo [gsoc]: create new result type for ParsedSyntax
@@ -1583,23 +1581,15 @@ class Parser {
15831581
ParserResult<Expr> parseExprCallSuffix(ParserResult<Expr> fn,
15841582
bool isExprBasic);
15851583
ParserResult<Expr> parseExprCollection();
1586-
ParsedSyntaxResult<ParsedExprSyntax> parseExprCollectionSyntax();
1587-
ParsedSyntaxResult<ParsedExprSyntax>
1588-
parseExprArraySyntax(ParsedTokenSyntax &&LSquare, SourceLoc LSquareLoc,
1589-
ParsedSyntaxResult<ParsedExprSyntax> &&firstExpr);
1590-
ParsedSyntaxResult<ParsedExprSyntax>
1591-
parseExprDictionarySyntax(ParsedTokenSyntax &&LSquare, SourceLoc LSquareLoc,
1592-
ParsedSyntaxResult<ParsedExprSyntax> &&firstExpr);
1593-
1584+
ParserResult<Expr> parseExprCollectionElement(Optional<bool> &isDictionary);
15941585
ParserResult<Expr> parseExprPoundUnknown(SourceLoc LSquareLoc);
1595-
ParsedSyntaxResult<ParsedExprSyntax>
1596-
parseExprPoundUnknownSyntax(Optional<ParsedTokenSyntax> &&LSquare,
1597-
SourceLoc LSquareLoc);
15981586
ParserResult<Expr>
15991587
parseExprPoundCodeCompletion(Optional<StmtKind> ParentKind);
16001588

16011589
UnresolvedDeclRefExpr *parseExprOperator();
16021590

1591+
void validateCollectionElement(ParserResult<Expr> element);
1592+
16031593
//===--------------------------------------------------------------------===//
16041594
// Statement Parsing
16051595

include/swift/Syntax/Syntax.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,6 @@ class Syntax {
169169
/// Returns true if the node is "present" in the source.
170170
bool isPresent() const;
171171

172-
/// Get the node immediately before this current node that does contain a
173-
/// non-missing token. Return nullptr if we cannot find such node.
174-
Optional<Syntax> getPreviousNode() const;
175172

176173
/// Returns the first non-missing token in this syntax. Returns None if there
177174
/// is no non-missing token.

0 commit comments

Comments
 (0)