Skip to content

Commit 0323409

Browse files
committed
update for review
1 parent b423363 commit 0323409

File tree

9 files changed

+57
-24
lines changed

9 files changed

+57
-24
lines changed

include/swift/Parse/ParseBridging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information

include/swift/Parse/Parser.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ class Parser {
13701370
Diag<> MessageID,
13711371
ParseTypeReason reason);
13721372

1373-
ParserResult<TypeRepr> parseType(bool fromASTGen = false);
1373+
ParserResult<TypeRepr> parseType();
13741374
ParserResult<TypeRepr>
13751375
parseType(Diag<> MessageID,
13761376
ParseTypeReason reason = ParseTypeReason::Unspecified,
@@ -2043,9 +2043,13 @@ class Parser {
20432043
//===--------------------------------------------------------------------===//
20442044
// ASTGen support.
20452045

2046+
/// Parse a TypeRepr from the syntax tree. i.e. SF->getExpxortedSourceFile()
20462047
ParserResult<TypeRepr> parseTypeReprFromSyntaxTree();
2048+
/// Parse a Stmt from the syntax tree. i.e. SF->getExpxortedSourceFile()
20472049
ParserResult<Stmt> parseStmtFromSyntaxTree();
2050+
/// Parse a Decl from the syntax tree. i.e. SF->getExpxortedSourceFile()
20482051
ParserResult<Decl> parseDeclFromSyntaxTree();
2052+
/// Parse an Expr from the syntax tree. i.e. SF->getExpxortedSourceFile()
20492053
ParserResult<Expr> parseExprFromSyntaxTree();
20502054
};
20512055

lib/ASTGen/Sources/ASTGen/Exprs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func isExprMigrated(_ node: ExprSyntax) -> Bool {
5252
_ where current.is(ExprSyntax.self):
5353
return false
5454
default:
55-
break;
55+
break
5656
}
5757
if current.id == node.id {
5858
return true
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
1+
//===--- LegacyParse.swift ------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
113
import ASTBridging
214
import BasicBridging
315
import SwiftSyntax
416
import ParseBridging
517

6-
7-
818
extension ASTGenVisitor {
919

10-
private func bridgedSourceLocForParse(_ node: some SyntaxProtocol) -> BridgedSourceLoc {
11-
return BridgedSourceLoc(at: node.position, in: self.base)
12-
}
13-
1420
func generateWithLegacy(_ node: ExprSyntax) -> BridgedExpr {
1521
// NOTE: Postfix expressions and sequence expressions share the same start
1622
// location with the inner expression. This function must only be called on
17-
// "top" expressions. Even if that expression is migrated.
23+
// the outermost expression that shares the same position.
24+
// See also `isExprMigrated(_:)`
1825

1926
// FIXME: Calculate isExprBasic.
2027
let isExprBasic = false
21-
return legacyParse.parseExpr(self.bridgedSourceLocForParse(node), self.declContext, isExprBasic)
28+
return legacyParse.parseExpr(node.bridgedSourceLoc(in: self), self.declContext, isExprBasic)
2229
}
2330

2431
func generateWithLegacy(_ node: DeclSyntax) -> BridgedDecl {
25-
legacyParse.parseDecl(self.bridgedSourceLocForParse(node), self.declContext)
32+
legacyParse.parseDecl(node.bridgedSourceLoc(in: self), self.declContext)
2633
}
2734

2835
func generateWithLegacy(_ node: StmtSyntax) -> BridgedStmt {
29-
legacyParse.parseStmt(self.bridgedSourceLocForParse(node), self.declContext)
36+
legacyParse.parseStmt(node.bridgedSourceLoc(in: self), self.declContext)
3037
}
3138

3239
func generateWithLegacy(_ node: TypeSyntax) -> BridgedTypeRepr {
33-
legacyParse.parseType(self.bridgedSourceLocForParse(node), self.declContext)
40+
legacyParse.parseType(node.bridgedSourceLoc(in: self), self.declContext)
3441
}
3542

3643
func generateMatchingPatternWithLegacy(_ node: some PatternSyntaxProtocol) {
37-
// legacyParse.parseMatchingPattern(self.bridgedSourceLocForParse(node), self.declContext)
44+
// legacyParse.parseMatchingPattern(node.bridgedSourceLoc(in: self), self.declContext)
3845
}
3946

4047
func generateBindingPatternWithLegacy(_ node: some PatternSyntaxProtocol) {
41-
// legacyParse.parseBindingPattern(self.bridgedSourceLocForParse(node), self.declContext)
48+
// legacyParse.parseBindingPattern(node.bridgedSourceLoc(in: self), self.declContext)
4249
}
4350
}

lib/Parse/ParseBridging.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
1+
//===--- ParseBridging.cpp ------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
212

313
#include "swift/Parse/ParseBridging.h"
414
#include "swift/Bridging/ASTGen.h"
@@ -31,7 +41,8 @@ BridgedExpr BridgedLegacyParser::parseExpr(BridgedSourceLoc loc,
3141
BridgedDeclContext DC,
3242
bool isExprBasic) const {
3343
auto &P = unbridged();
34-
auto PP = P.getParserPosition(loc.unbridged(), loc.unbridged());
44+
auto PP =
45+
P.getParserPosition(loc.unbridged(), /*PreviousLoc=*/loc.unbridged());
3546
P.CurDeclContext = DC.unbridged();
3647
P.restoreParserPosition(PP);
3748
ParserResult<Expr> result =
@@ -47,11 +58,12 @@ BridgedDecl BridgedLegacyParser::parseDecl(BridgedSourceLoc loc,
4758
P.CurDeclContext = DC.unbridged();
4859
P.restoreParserPosition(PP);
4960

50-
SmallVector<Decl *, 2> decls;
61+
// FIXME: IsAtStartOfLineOrPreviousHadSemi should be passed in from ASTGen.
62+
// IfConfigsAreDeclAttrs: true because ASTGen thinks the current location is
63+
// a start of a decl.
5164
ParserResult<Decl> result = P.parseDecl(
5265
/*IsAtStartOfLineOrPreviousHadSemi=*/true,
53-
/*IfConfigsAreDeclAttrs=*/true,
54-
[&](Decl *decl) { decls.push_back(decl); },
66+
/*IfConfigsAreDeclAttrs=*/true, [&](Decl *decl) {},
5567
/*fromASTGen=*/true);
5668
return result.getPtrOrNull();
5769
}

lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5794,6 +5794,9 @@ static Parser::ParseDeclOptions getParseDeclOptions(DeclContext *DC) {
57945794
/// decl-import
57955795
/// decl-operator
57965796
/// \endverbatim
5797+
///
5798+
/// \param fromASTGen If true , this function in called from ASTGen as the
5799+
/// fallback, so do not attempt a callback to ASTGen.
57975800
ParserResult<Decl> Parser::parseDecl(bool IsAtStartOfLineOrPreviousHadSemi,
57985801
bool IfConfigsAreDeclAttrs,
57995802
llvm::function_ref<void(Decl *)> Handler,

lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ using namespace swift;
3838
/// expr-sequence(basic | trailing-closure)
3939
///
4040
/// \param isExprBasic Whether we're only parsing an expr-basic.
41+
/// \param fromASTGen If true , this function in called from ASTGen as the
42+
/// fallback, so do not attempt a callback to ASTGen.
4143
ParserResult<Expr> Parser::parseExprImpl(Diag<> Message, bool isExprBasic,
4244
bool fromASTGen) {
4345
#if SWIFT_BUILD_SWIFT_SYNTAX

lib/Parse/ParseStmt.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,10 @@ static ParserResult<Stmt> recoverFromInvalidCase(Parser &P) {
539539
return nullptr;
540540
}
541541

542+
/// parseStmt
543+
///
544+
/// \param fromASTGen If true , this function in called from ASTGen as the
545+
/// fallback, so do not attempt a callback to ASTGen.
542546
ParserResult<Stmt> Parser::parseStmt(bool fromASTGen) {
543547
AssertParserMadeProgressBeforeLeavingScopeRAII apmp(*this);
544548
#if SWIFT_BUILD_SWIFT_SYNTAX

lib/Parse/ParseType.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,8 @@ ParserResult<TypeRepr> Parser::parseTypeSimple(
318318
return ty;
319319
}
320320

321-
ParserResult<TypeRepr> Parser::parseType(bool fromASTGen) {
322-
return parseType(diag::expected_type, ParseTypeReason::Unspecified,
323-
fromASTGen);
321+
ParserResult<TypeRepr> Parser::parseType() {
322+
return parseType(diag::expected_type);
324323
}
325324

326325
ParserResult<TypeRepr> Parser::parseSILBoxType(GenericParamList *generics,
@@ -602,6 +601,8 @@ ParserResult<TypeRepr> Parser::parseTypeScalar(
602601
/// pack-expansion-type:
603602
/// type-scalar '...'
604603
///
604+
/// \param fromASTGen If true , this function in called from ASTGen as the
605+
/// fallback, so do not attempt a callback to ASTGen.
605606
ParserResult<TypeRepr>
606607
Parser::parseType(Diag<> MessageID, ParseTypeReason reason, bool fromASTGen) {
607608
ParserResult<TypeRepr> ty;

0 commit comments

Comments
 (0)