Skip to content

Commit bbd8e35

Browse files
committed
---
yaml --- r: 348917 b: refs/heads/master c: 242f9a7 h: refs/heads/master i: 348915: 104baca
1 parent 86495a2 commit bbd8e35

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 0d4cf76ed0b6dfed4b13c58f7ee5a13473d10e3e
2+
refs/heads/master: 242f9a72733f0973be85434c89d2c889c877e403
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/Parse/ASTGen.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ 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+
4043
/// Decl attributes that cannot be represented by Syntax or generated by
4144
/// ASTGen.
4245
llvm::DenseMap<SourceLoc, DeclAttributes> ParsedDeclAttrs;
@@ -220,6 +223,10 @@ class ASTGen {
220223
TypeRepr *lookupType(syntax::TypeSyntax Type);
221224

222225
public:
226+
void addExpr(Expr *Expr, const SourceLoc Loc);
227+
bool hasExpr(const SourceLoc Loc) const;
228+
Expr *getExpr(const SourceLoc Loc) const;
229+
223230
void addDeclAttributes(DeclAttributes attrs, const SourceLoc Loc);
224231
bool hasDeclAttributes(SourceLoc Loc) const;
225232
DeclAttributes getDeclAttributes(const SourceLoc Loc) const;

trunk/include/swift/Parse/Parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,7 @@ class Parser {
14281428

14291429
//===--------------------------------------------------------------------===//
14301430
// Expression Parsing
1431+
ParsedSyntaxResult<ParsedExprSyntax> parseExpressionSyntax(Diag<> ID);
14311432
ParserResult<Expr> parseExpr(Diag<> ID) {
14321433
return parseExprImpl(ID, /*isExprBasic=*/false);
14331434
}

trunk/lib/Parse/ASTGen.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ TrailingWhereClause *ASTGen::generate(const GenericWhereClauseSyntax &syntax,
232232
Expr *ASTGen::generate(const ExprSyntax &E, const SourceLoc Loc) {
233233
Expr *result = nullptr;
234234

235+
auto exprLoc = advanceLocBegin(Loc, E);
236+
if (hasExpr(exprLoc))
237+
return getExpr(exprLoc);
238+
235239
if (auto identifierExpr = E.getAs<IdentifierExprSyntax>())
236240
result = generate(*identifierExpr, Loc);
237241
else if (auto superRefExpr = E.getAs<SuperRefExprSyntax>())
@@ -1351,6 +1355,30 @@ TypeRepr *ASTGen::lookupType(TypeSyntax Type) {
13511355
return Found != TypeCache.end() ? Found->second : nullptr;
13521356
}
13531357

1358+
void ASTGen::addExpr(Expr *E, const SourceLoc Loc) {
1359+
#ifndef NDEBUG
1360+
if (hasExpr(Loc)) {
1361+
bool PrevIsSubExpr = false;
1362+
Expr *Prev = Exprs.find(Loc)->second;
1363+
E->forEachChildExpr([&](Expr *Child) {
1364+
if (Child == Prev)
1365+
PrevIsSubExpr = true;
1366+
return Child;
1367+
});
1368+
assert(PrevIsSubExpr);
1369+
}
1370+
#endif
1371+
Exprs.insert({Loc, E});
1372+
}
1373+
1374+
bool ASTGen::hasExpr(const SourceLoc Loc) const {
1375+
return Exprs.find(Loc) != Exprs.end();
1376+
}
1377+
1378+
Expr *ASTGen::getExpr(const SourceLoc Loc) const {
1379+
return Exprs.find(Loc)->second;
1380+
}
1381+
13541382
void ASTGen::addDeclAttributes(DeclAttributes attrs, SourceLoc Loc) {
13551383
ParsedDeclAttrs.insert({Loc, attrs});
13561384
}

trunk/lib/Parse/ParseExpr.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@
3535
using namespace swift;
3636
using namespace swift::syntax;
3737

38+
ParsedSyntaxResult<ParsedExprSyntax> Parser::parseExpressionSyntax(Diag<> ID) {
39+
SourceLoc ExprLoc = Tok.getLoc();
40+
SyntaxParsingContext ExprParsingContext(SyntaxContext,
41+
SyntaxContextKind::Expr);
42+
ExprParsingContext.setTransparent();
43+
ParserResult<Expr> Result = parseExpr(ID);
44+
if (auto ParsedExpr = ExprParsingContext.popIf<ParsedExprSyntax>()) {
45+
Generator.addExpr(Result.getPtrOrNull(), ExprLoc);
46+
return makeParsedResult(std::move(*ParsedExpr), Result.getStatus());
47+
}
48+
return Result.getStatus();
49+
}
50+
3851
/// parseExpr
3952
///
4053
/// expr:

0 commit comments

Comments
 (0)