Skip to content

Commit 0e8010d

Browse files
committed
Revert "Merge pull request swiftlang#27592 from rintaro/syntaxparse-exprtuple"
This reverts commit cdfd1ab, reversing changes made to eb02f20.
1 parent b56c543 commit 0e8010d

File tree

16 files changed

+149
-260
lines changed

16 files changed

+149
-260
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,6 @@ ERROR(expected_expr_throw,PointsToFirstBadToken,
970970
// Yield Statment
971971
ERROR(expected_expr_yield,PointsToFirstBadToken,
972972
"expected expression in 'yield' statement", ())
973-
ERROR(unexpected_arg_label_yield,none,
974-
"unexpected argument label in 'yield' statement", ())
975973

976974
// Defer Statement
977975
ERROR(expected_lbrace_after_defer,PointsToFirstBadToken,

include/swift/Parse/ASTGen.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class ASTGen {
8787
Expr *generate(const syntax::SuperRefExprSyntax &Expr, const SourceLoc Loc);
8888
Expr *generate(const syntax::ArrayExprSyntax &Expr, const SourceLoc Loc);
8989
Expr *generate(const syntax::DictionaryExprSyntax &Expr, const SourceLoc Loc);
90-
Expr *generate(const syntax::TupleExprSyntax &E, const SourceLoc Loc);
9190
Expr *generate(const syntax::EditorPlaceholderExprSyntax &Expr,
9291
const SourceLoc Loc);
9392
Expr *generate(const syntax::SpecializeExprSyntax &Expr, const SourceLoc Loc);
@@ -113,12 +112,6 @@ class ASTGen {
113112
const Optional<syntax::DeclNameArgumentsSyntax> &args,
114113
const SourceLoc Loc);
115114

116-
void generateExprTupleElementList(const syntax::TupleExprElementListSyntax &elements,
117-
const SourceLoc Loc, bool isForCallArguments,
118-
SmallVectorImpl<Expr *> &exprs,
119-
SmallVectorImpl<Identifier> &exprLabels,
120-
SmallVectorImpl<SourceLoc> &exprLabelLocs);
121-
122115
private:
123116
void validateCollectionElement(Expr *elementExpr);
124117

include/swift/Parse/Parser.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,11 +1558,8 @@ class Parser {
15581558
SourceLoc &inLoc);
15591559

15601560
Expr *parseExprAnonClosureArg();
1561-
ParserResult<Expr> parseExprParenOrTuple();
1562-
ParsedSyntaxResult<ParsedExprSyntax> parseExprTupleSyntax();
1563-
ParserStatus parseExprTupleElementListSyntax(
1564-
SmallVectorImpl<ParsedTupleExprElementSyntax> &elements,
1565-
llvm::function_ref<bool()> isAtCloseTok);
1561+
ParserResult<Expr> parseExprList(tok LeftTok, tok RightTok,
1562+
syntax::SyntaxKind Kind);
15661563

15671564
/// Parse an expression list, keeping all of the pieces separated.
15681565
ParserStatus parseExprList(tok leftTok, tok rightTok,
@@ -1573,7 +1570,8 @@ class Parser {
15731570
SmallVectorImpl<Identifier> &exprLabels,
15741571
SmallVectorImpl<SourceLoc> &exprLabelLocs,
15751572
SourceLoc &rightLoc,
1576-
Expr *&trailingClosure);
1573+
Expr *&trailingClosure,
1574+
syntax::SyntaxKind Kind);
15771575

15781576
ParserResult<Expr> parseTrailingClosure(SourceRange calleeRange);
15791577

lib/Parse/ASTGen.cpp

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,6 @@ Expr *ASTGen::generate(const ExprSyntax &E, const SourceLoc Loc) {
248248
result = generate(*arrayExpr, Loc);
249249
else if (auto dictionaryExpr = E.getAs<DictionaryExprSyntax>())
250250
result = generate(*dictionaryExpr, Loc);
251-
else if (auto tupleExpr = E.getAs<TupleExprSyntax>())
252-
result = generate(*tupleExpr, Loc);
253251
else if (auto integerLiteralExpr = E.getAs<IntegerLiteralExprSyntax>())
254252
result = generate(*integerLiteralExpr, Loc);
255253
else if (auto floatLiteralExpr = E.getAs<FloatLiteralExprSyntax>())
@@ -528,72 +526,6 @@ Expr *ASTGen::generate(const DictionaryExprSyntax &E, const SourceLoc Loc) {
528526
RSquareLoc);
529527
}
530528

531-
Expr *ASTGen::generate(const TupleExprSyntax &E, const SourceLoc Loc) {
532-
SmallVector<Expr *, 2> exprs;
533-
SmallVector<Identifier, 2> exprLabels;
534-
SmallVector<SourceLoc, 2> exprLabelLocs;
535-
generateExprTupleElementList(E.getElementList(), Loc,
536-
/*isForCallArguments=*/false, exprs, exprLabels,
537-
exprLabelLocs);
538-
539-
SourceLoc leftLoc = advanceLocBegin(Loc, E.getLeftParen());
540-
SourceLoc rightLoc = advanceLocEnd(Loc, E);
541-
542-
// A tuple with a single, unlabeled element is just parentheses.
543-
if (exprs.size() == 1 && exprLabels.empty()) {
544-
return new (Context) ParenExpr(leftLoc, exprs[0], rightLoc,
545-
/*hasTrailingClosure=*/false);
546-
}
547-
548-
return TupleExpr::create(Context, leftLoc, exprs, exprLabels, exprLabelLocs,
549-
rightLoc, /*HasTrailingClosure=*/false,
550-
/*Implicit=*/false);
551-
}
552-
553-
void ASTGen::generateExprTupleElementList(const TupleExprElementListSyntax &elements,
554-
const SourceLoc Loc, bool isForCallArguments,
555-
SmallVectorImpl<Expr *> &exprs,
556-
SmallVectorImpl<Identifier> &exprLabels,
557-
SmallVectorImpl<SourceLoc> &exprLabelLocs) {
558-
auto isFirst = true;
559-
for (auto elem : elements) {
560-
auto *subExpr = generate(elem.getExpression(), Loc);
561-
if (!subExpr)
562-
continue;
563-
564-
// Handle call arguments specially because it may need argument labels.
565-
if (P.CodeCompletion && isForCallArguments && !elem.getLabel())
566-
if (auto CCExpr = elem.getExpression().getAs<CodeCompletionExprSyntax>())
567-
if (!CCExpr->getBase() && !CCExpr->getPeriodOrParen())
568-
P.CodeCompletion->completeCallArg(cast<CodeCompletionExpr>(subExpr),
569-
isFirst);
570-
isFirst = false;
571-
572-
Identifier fieldName;
573-
SourceLoc fieldNameLoc;
574-
if (auto label = elem.getLabel()) {
575-
fieldNameLoc = advanceLocBegin(Loc, *label);
576-
if (label->getTokenKind() == tok::identifier)
577-
fieldName = Context.getIdentifier(label->getIdentifierText());
578-
}
579-
580-
// Don't populate label vectors unless we see at least one label.
581-
if (!exprLabels.empty()) {
582-
exprLabels.push_back(fieldName);
583-
exprLabelLocs.push_back(fieldNameLoc);
584-
} else if (fieldNameLoc.isValid()) {
585-
exprLabels.resize(exprs.size());
586-
exprLabelLocs.resize(exprs.size());
587-
exprLabels.push_back(fieldName);
588-
exprLabelLocs.push_back(fieldNameLoc);
589-
}
590-
exprs.push_back(subExpr);
591-
}
592-
assert((exprLabels.size() == 0 || exprs.size() == exprLabels.size()) &&
593-
exprLabels.size() == exprLabelLocs.size());
594-
}
595-
596-
597529
Expr *ASTGen::generate(const IntegerLiteralExprSyntax &Expr,
598530
const SourceLoc Loc) {
599531
auto Digits = Expr.getDigits();

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,8 @@ ParserStatus Parser::parseDeclAttribute(DeclAttributes &Attributes, SourceLoc At
17841784
status |= parseExprList(tok::l_paren, tok::r_paren,
17851785
/*isPostfix=*/false, /*isExprBasic=*/true,
17861786
lParenLoc, args, argLabels, argLabelLocs,
1787-
rParenLoc, trailingClosure);
1787+
rParenLoc, trailingClosure,
1788+
SyntaxKind::TupleExprElementList);
17881789
assert(!trailingClosure && "Cannot parse a trailing closure here");
17891790
hasInitializer = true;
17901791
}

0 commit comments

Comments
 (0)