Skip to content

Commit 724052d

Browse files
committed
[Parse] Rename Lexer::State to LexerState
1 parent ddac6ab commit 724052d

File tree

4 files changed

+55
-29
lines changed

4 files changed

+55
-29
lines changed

include/swift/Parse/Lexer.h

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/DiagnosticEngine.h"
2121
#include "swift/Basic/SourceLoc.h"
2222
#include "swift/Basic/SourceManager.h"
23+
#include "swift/Parse/LexerState.h"
2324
#include "swift/Parse/Token.h"
2425
#include "swift/Syntax/References.h"
2526
#include "swift/Syntax/Trivia.h"
@@ -59,13 +60,15 @@ enum class ConflictMarkerKind {
5960
/// separated by 4 "="s, and terminated by 4 "<"s.
6061
Perforce
6162
};
62-
63+
6364
class Lexer {
6465
const LangOptions &LangOpts;
6566
const SourceManager &SourceMgr;
6667
DiagnosticEngine *Diags;
6768
const unsigned BufferID;
6869

70+
using State = LexerState;
71+
6972
/// Pointer to the first character of the buffer, even in a lexer that
7073
/// scans a subrange of the buffer.
7174
const char *BufferStart;
@@ -128,28 +131,6 @@ class Lexer {
128131
/// `TriviaRetentionMode::WithTrivia`.
129132
syntax::TriviaList TrailingTrivia;
130133

131-
public:
132-
/// \brief Lexer state can be saved/restored to/from objects of this class.
133-
class State {
134-
public:
135-
State() {}
136-
137-
bool isValid() const {
138-
return Loc.isValid();
139-
}
140-
141-
State advance(unsigned Offset) const {
142-
assert(isValid());
143-
return State(Loc.getAdvancedLoc(Offset));
144-
}
145-
146-
private:
147-
explicit State(SourceLoc Loc) : Loc(Loc) {}
148-
SourceLoc Loc;
149-
friend class Lexer;
150-
};
151-
152-
private:
153134
Lexer(const Lexer&) = delete;
154135
void operator=(const Lexer&) = delete;
155136

include/swift/Parse/LexerState.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===--- LexerState.h - Lexer State -----------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 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+
//
13+
// This file defines the LexerState object.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_LEXERSTATE_H
18+
#define SWIFT_LEXERSTATE_H
19+
20+
#include "swift/Basic/SourceLoc.h"
21+
22+
namespace swift {
23+
class Lexer;
24+
25+
/// \brief Lexer state can be saved/restored to/from objects of this class.
26+
class LexerState {
27+
public:
28+
LexerState() {}
29+
30+
bool isValid() const { return Loc.isValid(); }
31+
32+
LexerState advance(unsigned Offset) const {
33+
assert(isValid());
34+
return LexerState(Loc.getAdvancedLoc(Offset));
35+
}
36+
37+
private:
38+
explicit LexerState(SourceLoc Loc) : Loc(Loc) {}
39+
SourceLoc Loc;
40+
friend class Lexer;
41+
};
42+
43+
} // end namespace swift
44+
45+
#endif

include/swift/Parse/Parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,10 @@ class Parser {
368368
}
369369

370370
private:
371-
ParserPosition(Lexer::State LS, SourceLoc PreviousLoc):
371+
ParserPosition(LexerState LS, SourceLoc PreviousLoc):
372372
LS(LS), PreviousLoc(PreviousLoc)
373373
{}
374-
Lexer::State LS;
374+
LexerState LS;
375375
SourceLoc PreviousLoc;
376376
friend class Parser;
377377
};

lib/Parse/ParseExpr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,13 +1926,13 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
19261926
TmpContext.setDiscard();
19271927

19281928
// Create a temporary lexer that lexes from the body of the string.
1929-
Lexer::State BeginState =
1929+
LexerState BeginState =
19301930
L->getStateForBeginningOfTokenLoc(Segment.Loc);
19311931
// We need to set the EOF at r_paren, to prevent the Lexer from eagerly
19321932
// trying to lex the token beyond it. Parser::parseList() does a special
19331933
// check for a tok::EOF that is spelled with a ')'.
19341934
// FIXME: This seems like a hack, there must be a better way..
1935-
Lexer::State EndState = BeginState.advance(Segment.Length-1);
1935+
LexerState EndState = BeginState.advance(Segment.Length-1);
19361936
Lexer LocalLex(*L, BeginState, EndState);
19371937

19381938
// Temporarily swap out the parser's current lexer with our new one.
@@ -2235,8 +2235,8 @@ Expr *Parser::parseExprEditorPlaceholder(Token PlaceholderTok,
22352235
SourceLoc TypeStartLoc = PlaceholderTok.getLoc().getAdvancedLoc(Offset);
22362236
SourceLoc TypeEndLoc = TypeStartLoc.getAdvancedLoc(TyStr.size());
22372237

2238-
Lexer::State StartState = L->getStateForBeginningOfTokenLoc(TypeStartLoc);
2239-
Lexer::State EndState = L->getStateForBeginningOfTokenLoc(TypeEndLoc);
2238+
LexerState StartState = L->getStateForBeginningOfTokenLoc(TypeStartLoc);
2239+
LexerState EndState = L->getStateForBeginningOfTokenLoc(TypeEndLoc);
22402240

22412241
// Create a lexer for the type sub-string.
22422242
Lexer LocalLex(*L, StartState, EndState);

0 commit comments

Comments
 (0)