Skip to content

Commit 530d937

Browse files
committed
Remove SyntaxContext and Parser Affordances
1 parent 70072a0 commit 530d937

21 files changed

+74
-2496
lines changed

include/swift/Parse/Parser.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -356,22 +356,6 @@ class Parser {
356356
};
357357
friend class StructureMarkerRAII;
358358

359-
/// A RAII object that tells the SyntaxParsingContext to defer Syntax nodes.
360-
class DeferringContextRAII {
361-
SyntaxParsingContext &Ctx;
362-
bool WasDeferring;
363-
364-
public:
365-
explicit DeferringContextRAII(SyntaxParsingContext &SPCtx)
366-
: Ctx(SPCtx), WasDeferring(Ctx.shouldDefer()) {
367-
Ctx.setShouldDefer();
368-
}
369-
370-
~DeferringContextRAII() {
371-
Ctx.setShouldDefer(WasDeferring);
372-
}
373-
};
374-
375359
/// The stack of structure markers indicating the locations of
376360
/// structural elements actively being parsed, including the start
377361
/// of declarations, statements, and opening operators of various
@@ -380,9 +364,6 @@ class Parser {
380364
/// This vector is managed by \c StructureMarkerRAII objects.
381365
llvm::SmallVector<StructureMarker, 16> StructureMarkers;
382366

383-
/// Current syntax parsing context where call backs should be directed to.
384-
SyntaxParsingContext *SyntaxContext;
385-
386367
/// Maps of macro name and version to availability specifications.
387368
typedef llvm::DenseMap<llvm::VersionTuple,
388369
SmallVector<AvailabilitySpec *, 4>>

lib/Parse/CMakeLists.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ add_swift_host_library(swiftParse STATIC
1010
Confusables.cpp
1111
Lexer.cpp
1212
ParseDecl.cpp
13-
ParsedRawSyntaxNode.cpp
14-
ParsedRawSyntaxRecorder.cpp
15-
ParsedTrivia.cpp
1613
ParseExpr.cpp
1714
ParseGeneric.cpp
1815
ParseIfConfig.cpp
@@ -23,17 +20,9 @@ add_swift_host_library(swiftParse STATIC
2320
ParseStmt.cpp
2421
ParseType.cpp
2522
ParseVersion.cpp
26-
PersistentParserState.cpp
27-
SyntaxParsingCache.cpp
28-
SyntaxParsingContext.cpp)
29-
_swift_gyb_target_sources(swiftParse PRIVATE
30-
ParsedSyntaxBuilders.cpp.gyb
31-
ParsedSyntaxNodes.cpp.gyb
32-
ParsedSyntaxRecorder.cpp.gyb)
23+
PersistentParserState.cpp)
3324
target_link_libraries(swiftParse PRIVATE
3425
swiftAST
35-
swiftSyntax
36-
swiftSyntaxParse
3726
)
3827

3928
if (SWIFT_SWIFT_PARSER)
@@ -85,6 +74,4 @@ if (SWIFT_SWIFT_PARSER)
8574
)
8675
endif()
8776

88-
add_dependencies(swiftParse swift-parse-syntax-generated-headers)
89-
9077
set_swift_llvm_is_available(swiftParse)

lib/Parse/Lexer.cpp

Lines changed: 15 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ void Parser_registerRegexLiteralLexingFn(RegexLiteralLexingFn fn) {
4040
}
4141

4242
using namespace swift;
43-
using namespace swift::syntax;
4443

4544
// clang::isAsciiIdentifierStart and clang::isAsciiIdentifierContinue are
4645
// deliberately not in this list as a reminder that they are using C rules for
@@ -179,12 +178,12 @@ uint32_t swift::validateUTF8CharacterAndAdvance(const char *&Ptr,
179178
Lexer::Lexer(const PrincipalTag &, const LangOptions &LangOpts,
180179
const SourceManager &SourceMgr, unsigned BufferID,
181180
DiagnosticEngine *Diags, LexerMode LexMode,
182-
HashbangMode HashbangAllowed, CommentRetentionMode RetainComments,
183-
TriviaRetentionMode TriviaRetention)
181+
HashbangMode HashbangAllowed,
182+
CommentRetentionMode RetainComments)
184183
: LangOpts(LangOpts), SourceMgr(SourceMgr), BufferID(BufferID),
185184
LexMode(LexMode),
186185
IsHashbangAllowed(HashbangAllowed == HashbangMode::Allowed),
187-
RetainComments(RetainComments), TriviaRetention(TriviaRetention) {
186+
RetainComments(RetainComments) {
188187
if (Diags)
189188
DiagQueue.emplace(*Diags, /*emitOnDestruction*/ false);
190189
}
@@ -227,21 +226,20 @@ void Lexer::initialize(unsigned Offset, unsigned EndOffset) {
227226

228227
Lexer::Lexer(const LangOptions &Options, const SourceManager &SourceMgr,
229228
unsigned BufferID, DiagnosticEngine *Diags, LexerMode LexMode,
230-
HashbangMode HashbangAllowed, CommentRetentionMode RetainComments,
231-
TriviaRetentionMode TriviaRetention)
229+
HashbangMode HashbangAllowed,
230+
CommentRetentionMode RetainComments)
232231
: Lexer(PrincipalTag(), Options, SourceMgr, BufferID, Diags, LexMode,
233-
HashbangAllowed, RetainComments, TriviaRetention) {
232+
HashbangAllowed, RetainComments) {
234233
unsigned EndOffset = SourceMgr.getRangeForBuffer(BufferID).getByteLength();
235234
initialize(/*Offset=*/0, EndOffset);
236235
}
237236

238237
Lexer::Lexer(const LangOptions &Options, const SourceManager &SourceMgr,
239238
unsigned BufferID, DiagnosticEngine *Diags, LexerMode LexMode,
240239
HashbangMode HashbangAllowed, CommentRetentionMode RetainComments,
241-
TriviaRetentionMode TriviaRetention, unsigned Offset,
242-
unsigned EndOffset)
240+
unsigned Offset, unsigned EndOffset)
243241
: Lexer(PrincipalTag(), Options, SourceMgr, BufferID, Diags, LexMode,
244-
HashbangAllowed, RetainComments, TriviaRetention) {
242+
HashbangAllowed, RetainComments) {
245243
initialize(Offset, EndOffset);
246244
}
247245

@@ -253,7 +251,7 @@ Lexer::Lexer(const Lexer &Parent, State BeginState, State EndState,
253251
Parent.IsHashbangAllowed
254252
? HashbangMode::Allowed
255253
: HashbangMode::Disallowed,
256-
Parent.RetainComments, Parent.TriviaRetention) {
254+
Parent.RetainComments) {
257255
assert(BufferID == SourceMgr.findBufferContainingLoc(BeginState.Loc) &&
258256
"state for the wrong buffer");
259257
assert(BufferID == SourceMgr.findBufferContainingLoc(EndState.Loc) &&
@@ -277,8 +275,7 @@ Token Lexer::getTokenAt(SourceLoc Loc) {
277275
"location from the wrong buffer");
278276

279277
Lexer L(LangOpts, SourceMgr, BufferID, getUnderlyingDiags(), LexMode,
280-
HashbangMode::Allowed, CommentRetentionMode::None,
281-
TriviaRetentionMode::WithoutTrivia);
278+
HashbangMode::Allowed, CommentRetentionMode::None);
282279
L.restoreState(State(Loc));
283280
return L.peekNextToken();
284281
}
@@ -301,13 +298,6 @@ void Lexer::formToken(tok Kind, const char *TokStart) {
301298
}
302299

303300
StringRef TokenText { TokStart, static_cast<size_t>(CurPtr - TokStart) };
304-
305-
if (TriviaRetention == TriviaRetentionMode::WithTrivia && Kind != tok::eof) {
306-
TrailingTrivia = lexTrivia(/*IsForTrailingTrivia=*/true, CurPtr);
307-
} else {
308-
TrailingTrivia = StringRef();
309-
}
310-
311301
NextToken.setToken(Kind, TokenText, CommentLength);
312302
}
313303

@@ -654,12 +644,12 @@ bool Lexer::isOperator(StringRef string) {
654644
tok Lexer::kindOfIdentifier(StringRef Str, bool InSILMode) {
655645
#define SIL_KEYWORD(kw)
656646
#define KEYWORD(kw) if (Str == #kw) return tok::kw_##kw;
657-
#include "swift/Syntax/TokenKinds.def"
647+
#include "swift/AST/TokenKinds.def"
658648

659649
// SIL keywords are only active in SIL mode.
660650
if (InSILMode) {
661651
#define SIL_KEYWORD(kw) if (Str == #kw) return tok::kw_##kw;
662-
#include "swift/Syntax/TokenKinds.def"
652+
#include "swift/AST/TokenKinds.def"
663653
}
664654
return tok::identifier;
665655
}
@@ -696,7 +686,7 @@ void Lexer::lexHash() {
696686
tok Kind = llvm::StringSwitch<tok>(StringRef(CurPtr, tmpPtr-CurPtr))
697687
#define POUND_KEYWORD(id) \
698688
.Case(#id, tok::pound_##id)
699-
#include "swift/Syntax/TokenKinds.def"
689+
#include "swift/AST/TokenKinds.def"
700690
.Default(tok::pound);
701691

702692
// If we didn't find a match, then just return tok::pound. This is highly
@@ -2615,7 +2605,7 @@ void Lexer::lexImpl() {
26152605
NextToken.setAtStartOfLine(false);
26162606
}
26172607

2618-
LeadingTrivia = lexTrivia(/*IsForTrailingTrivia=*/false, LeadingTriviaStart);
2608+
lexTrivia(/*IsForTrailingTrivia=*/false, LeadingTriviaStart);
26192609

26202610
// Remember the start of the token so we can form the text range.
26212611
const char *TokStart = CurPtr;
@@ -2955,7 +2945,7 @@ static SourceLoc getLocForStartOfTokenInBuf(SourceManager &SM,
29552945

29562946
Lexer L(FakeLangOptions, SM, BufferID, nullptr, LexerMode::Swift,
29572947
HashbangMode::Allowed, CommentRetentionMode::None,
2958-
TriviaRetentionMode::WithoutTrivia, BufferStart, BufferEnd);
2948+
BufferStart, BufferEnd);
29592949

29602950
// Lex tokens until we find the token that contains the source location.
29612951
Token Tok;
@@ -3145,138 +3135,6 @@ bool tryAdvanceToEndOfConflictMarker(const char *&CurPtr,
31453135
return false;
31463136
}
31473137

3148-
ParsedTrivia TriviaLexer::lexTrivia(StringRef TriviaStr) {
3149-
const char *CurPtr = TriviaStr.begin();
3150-
const char *BufferEnd = TriviaStr.end();
3151-
3152-
ParsedTrivia Pieces;
3153-
3154-
while (CurPtr < BufferEnd) {
3155-
// Iterate through the trivia and lex them into pieces. In the switch
3156-
// statement in this loop we can
3157-
// - 'continue' if we have successfully lexed a trivia piece to continue
3158-
// with the next piece. In this case CurPtr points to the next character
3159-
// to be lexed (which is not part of the lexed trivia).
3160-
// - 'break' to perform the default handling defined towards the bottom of
3161-
// the loop.
3162-
3163-
const char *TriviaStart = CurPtr;
3164-
3165-
switch (*CurPtr++) {
3166-
case '\n':
3167-
Pieces.appendOrSquash(TriviaKind::Newline, 1);
3168-
continue;
3169-
case '\r':
3170-
if (CurPtr < BufferEnd && CurPtr[0] == '\n') {
3171-
Pieces.appendOrSquash(TriviaKind::CarriageReturnLineFeed, 2);
3172-
++CurPtr;
3173-
continue;
3174-
} else {
3175-
Pieces.appendOrSquash(TriviaKind::CarriageReturn, 1);
3176-
continue;
3177-
}
3178-
case ' ':
3179-
Pieces.appendOrSquash(TriviaKind::Space, 1);
3180-
continue;
3181-
case '\t':
3182-
Pieces.appendOrSquash(TriviaKind::Tab, 1);
3183-
continue;
3184-
case '\v':
3185-
Pieces.appendOrSquash(TriviaKind::VerticalTab, 1);
3186-
continue;
3187-
case '\f':
3188-
Pieces.appendOrSquash(TriviaKind::Formfeed, 1);
3189-
continue;
3190-
case '/':
3191-
if (CurPtr < BufferEnd && CurPtr[0] == '/') {
3192-
// '// ...' comment.
3193-
bool isDocComment = CurPtr[1] == '/';
3194-
advanceToEndOfLine(CurPtr, BufferEnd);
3195-
size_t Length = CurPtr - TriviaStart;
3196-
Pieces.push_back(isDocComment ? TriviaKind::DocLineComment
3197-
: TriviaKind::LineComment,
3198-
Length);
3199-
continue;
3200-
} else if (CurPtr < BufferEnd && CurPtr[0] == '*') {
3201-
// '/* ... */' comment.
3202-
bool isDocComment = CurPtr[1] == '*';
3203-
skipToEndOfSlashStarComment(CurPtr, BufferEnd);
3204-
size_t Length = CurPtr - TriviaStart;
3205-
Pieces.push_back(isDocComment ? TriviaKind::DocBlockComment
3206-
: TriviaKind::BlockComment,
3207-
Length);
3208-
continue;
3209-
}
3210-
break;
3211-
case '#':
3212-
if (CurPtr < BufferEnd && CurPtr[0] == '!') {
3213-
// Hashbang '#!/path/to/swift'.
3214-
advanceToEndOfLine(CurPtr, BufferEnd);
3215-
size_t Length = CurPtr - TriviaStart;
3216-
Pieces.push_back(TriviaKind::Shebang, Length);
3217-
continue;
3218-
}
3219-
break;
3220-
case '<':
3221-
case '>':
3222-
if (tryAdvanceToEndOfConflictMarker(CurPtr, BufferEnd)) {
3223-
// Conflict marker.
3224-
size_t Length = CurPtr - TriviaStart;
3225-
Pieces.push_back(TriviaKind::UnexpectedText, Length);
3226-
continue;
3227-
}
3228-
break;
3229-
case '\xEF':
3230-
if ((CurPtr + 1) < BufferEnd && CurPtr[0] == '\xBB' && CurPtr[1] == '\xBF') {
3231-
// BOM marker.
3232-
CurPtr = CurPtr + 2;
3233-
size_t Length = CurPtr - TriviaStart;
3234-
Pieces.push_back(TriviaKind::UnexpectedText, Length);
3235-
continue;
3236-
}
3237-
break;
3238-
case 0: {
3239-
size_t Length = CurPtr - TriviaStart;
3240-
Pieces.push_back(TriviaKind::UnexpectedText, Length);
3241-
continue;
3242-
}
3243-
default:
3244-
break;
3245-
}
3246-
3247-
// Default handling for anything that didn't 'continue' in the above switch
3248-
// statement.
3249-
3250-
for (; CurPtr < BufferEnd; ++CurPtr) {
3251-
bool HasFoundNextTriviaStart = false;
3252-
switch (*CurPtr) {
3253-
case '\n':
3254-
case '\r':
3255-
case ' ':
3256-
case '\t':
3257-
case '\v':
3258-
case '\f':
3259-
case '/':
3260-
case 0:
3261-
HasFoundNextTriviaStart = true;
3262-
break;
3263-
}
3264-
if (HasFoundNextTriviaStart) {
3265-
break;
3266-
}
3267-
}
3268-
3269-
size_t Length = CurPtr - TriviaStart;
3270-
Pieces.push_back(TriviaKind::UnexpectedText, Length);
3271-
continue;
3272-
}
3273-
3274-
assert(Pieces.getLength() == TriviaStr.size() &&
3275-
"Not all characters in the source string have been used in trivia "
3276-
"pieces");
3277-
return Pieces;
3278-
}
3279-
32803138
ArrayRef<Token> swift::
32813139
slice_token_array(ArrayRef<Token> AllTokens, SourceLoc StartLoc,
32823140
SourceLoc EndLoc) {

0 commit comments

Comments
 (0)