Skip to content

Commit ebf7db3

Browse files
author
Manman Ren
committed
[Parser] parsing "<a, b<c>?>" as the generic arguments.
Also enable parsing of operator name "??" in sil mode. Swift SVN r21150
1 parent 1fc7709 commit ebf7db3

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

lib/Parse/Lexer.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,10 @@ void Lexer::lexOperatorIdentifier() {
599599
(void) didStart;
600600

601601
do {
602-
if (CurPtr != BufferEnd && InSILMode &&
602+
if (CurPtr != BufferEnd && InSILBody &&
603603
(*CurPtr == '!' || *CurPtr == '?'))
604-
// In SIL mode, '!' and '?' are special token and can't be in the middle of
605-
// an operator.
604+
// When parsing SIL body, '!' and '?' are special token and can't be
605+
// in the middle of an operator.
606606
break;
607607
} while (advanceIfValidContinuationOfOperator(CurPtr, BufferEnd));
608608
}
@@ -647,6 +647,14 @@ void Lexer::lexOperatorIdentifier() {
647647
return formToken(tok::unknown, TokStart);
648648
}
649649
} else {
650+
// FIXME: when parsing "<a, b<c>?>" as the generic arguments, lexer can't
651+
// return ">?>" as one token. parseType uses consumingStartingGreater, which
652+
// consumes ">", returns a token for "?" only, and silently drops the last
653+
// '>'. For now, we stop the operator token right after '?'.
654+
if (CurPtr-TokStart == 3 && TokStart[0] == '>' && TokStart[1] == '?' &&
655+
TokStart[2] == '>')
656+
CurPtr--;
657+
650658
// If there is a "//" in the middle of an identifier token, it starts
651659
// a single-line comment.
652660
auto Pos = StringRef(TokStart, CurPtr-TokStart).find("//");

test/SIL/Parser/question_mark.swift

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %swift %s -emit-silgen | sil-opt -verify
2+
infix operator ?? {
3+
associativity right
4+
precedence 110
5+
}
6+
7+
struct A<V, E> {
8+
}
9+
10+
struct B<V, E> {
11+
}
12+
13+
struct C {
14+
}
15+
16+
struct V1 {
17+
}
18+
19+
struct E1 {
20+
}
21+
22+
var buffer: A<C, B<V1, E1>?>

0 commit comments

Comments
 (0)