Skip to content

Commit f450f0c

Browse files
committed
Revert "Preserve whitespace and comments during lexing as Trivia"
This reverts commit d6e2b58.
1 parent 44f1555 commit f450f0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1049
-1817
lines changed

include/swift/AST/ASTContext.h

+2
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ class ASTContext {
783783

784784
private:
785785
friend class Decl;
786+
Optional<RawComment> getRawComment(const Decl *D);
787+
void setRawComment(const Decl *D, RawComment RC);
786788

787789
Optional<StringRef> getBriefComment(const Decl *D);
788790
void setBriefComment(const Decl *D, StringRef Comment);

include/swift/AST/Attr.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "swift/AST/KnownProtocols.h"
2929
#include "swift/AST/Ownership.h"
3030
#include "swift/AST/PlatformKind.h"
31-
#include "swift/AST/RawComment.h"
3231
#include "llvm/ADT/SmallVector.h"
3332
#include "llvm/ADT/StringRef.h"
3433
#include "llvm/Support/ErrorHandling.h"
@@ -959,15 +958,15 @@ class OwnershipAttr : public DeclAttribute {
959958
class RawDocCommentAttr : public DeclAttribute {
960959
/// Source range of the attached comment. This comment is located before
961960
/// the declaration.
962-
const RawComment Comment;
961+
CharSourceRange CommentRange;
963962

964963
public:
965-
RawDocCommentAttr(RawComment Comment)
964+
RawDocCommentAttr(CharSourceRange CommentRange)
966965
: DeclAttribute(DAK_RawDocComment, SourceLoc(), SourceRange(),
967966
/*Implicit=*/false),
968-
Comment(Comment) {}
967+
CommentRange(CommentRange) {}
969968

970-
const RawComment &getComment() const { return Comment; }
969+
CharSourceRange getCommentRange() const { return CommentRange; }
971970

972971
static bool classof(const DeclAttribute *DA) {
973972
return DA->getKind() == DAK_RawDocComment;

include/swift/Basic/String.h

-94
This file was deleted.

include/swift/IDE/SyntaxModel.h

-6
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ namespace swift {
2424
class ModuleDecl;
2525
class SourceFile;
2626

27-
namespace syntax {
28-
class Trivia;
29-
}
30-
3127
namespace ide {
3228

3329
enum class SyntaxNodeKind : uint8_t {
@@ -186,8 +182,6 @@ class SyntaxModelContext {
186182
struct Implementation;
187183
Implementation &Impl;
188184

189-
void addTrivia(const syntax::Trivia &T, std::vector<SyntaxNode> &Nodes);
190-
191185
public:
192186
explicit SyntaxModelContext(SourceFile &SrcFile);
193187
~SyntaxModelContext();

include/swift/Parse/Lexer.h

+12-30
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919

2020
#include "swift/Basic/SourceLoc.h"
2121
#include "swift/Basic/SourceManager.h"
22-
#include "swift/Syntax/Token.h"
23-
#include "swift/Syntax/Syntax.h"
22+
#include "swift/Parse/Token.h"
2423
#include "swift/AST/DiagnosticEngine.h"
2524
#include "llvm/ADT/SmallVector.h"
2625

27-
#include <deque>
28-
2926
namespace swift {
3027
class DiagnosticEngine;
3128
class InFlightDiagnostic;
@@ -91,7 +88,7 @@ class Lexer {
9188

9289
/// @}
9390

94-
syntax::Token NextToken;
91+
Token NextToken;
9592

9693
/// \brief This is true if we're lexing a .sil file instead of a .swift
9794
/// file. This enables the 'sil' keyword.
@@ -102,13 +99,6 @@ class Lexer {
10299
/// InSILBody - This is true when we're lexing the body of a SIL declaration
103100
/// in a SIL file. This enables some context-sensitive lexing.
104101
bool InSILBody = false;
105-
106-
/// The source trivia leading up to the current token.
107-
std::deque<syntax::Trivia> LeadingTrivia;
108-
109-
/// The source trivia after the current token, up to and including the first
110-
/// newline after the token.
111-
std::deque<syntax::Trivia> TrailingTrivia;
112102

113103
public:
114104
/// \brief Lexer state can be saved/restored to/from objects of this class.
@@ -202,11 +192,10 @@ class Lexer {
202192
return CodeCompletionPtr != nullptr;
203193
}
204194

205-
syntax::Token lex() {
206-
auto Result = NextToken;
195+
void lex(Token &Result) {
196+
Result = NextToken;
207197
if (Result.isNot(tok::eof))
208198
lexImpl();
209-
return Result;
210199
}
211200

212201
bool isKeepingComments() const {
@@ -217,7 +206,7 @@ class Lexer {
217206

218207
/// peekNextToken - Return the next token to be returned by Lex without
219208
/// actually lexing it.
220-
const syntax::Token &peekNextToken() const { return NextToken; }
209+
const Token &peekNextToken() const { return NextToken; }
221210

222211
/// \brief Returns the lexer state for the beginning of the given token
223212
/// location. After restoring the state, lexer will return this token and
@@ -227,11 +216,11 @@ class Lexer {
227216
/// \brief Returns the lexer state for the beginning of the given token.
228217
/// After restoring the state, lexer will return this token and continue from
229218
/// there.
230-
State getStateForBeginningOfToken(syntax::Token Tok) const {
219+
State getStateForBeginningOfToken(const Token &Tok) const {
231220
// If the token has a comment attached to it, rewind to before the comment,
232221
// not just the start of the token. This ensures that we will re-lex and
233222
// reattach the comment to the token if rewound to this state.
234-
auto TokStart = Tok.getAbsoluteTriviaStart();
223+
SourceLoc TokStart = Tok.getCommentStart();
235224
if (TokStart.isInvalid())
236225
TokStart = Tok.getLoc();
237226
return getStateForBeginningOfTokenLoc(TokStart);
@@ -267,8 +256,8 @@ class Lexer {
267256
/// resides.
268257
///
269258
/// \param Loc The source location of the beginning of a token.
270-
static Optional<syntax::Token>
271-
getTokenAtLocation(const SourceManager &SM, SourceLoc Loc);
259+
static Token getTokenAtLocation(const SourceManager &SM, SourceLoc Loc);
260+
272261

273262
/// \brief Retrieve the source location that points just past the
274263
/// end of the token referred to by \c Loc.
@@ -379,11 +368,11 @@ class Lexer {
379368
/// \brief Given a string literal token, separate it into string/expr segments
380369
/// of a potentially interpolated string.
381370
static void getStringLiteralSegments(
382-
const syntax::Token &Str,
371+
const Token &Str,
383372
SmallVectorImpl<StringSegment> &Segments,
384373
DiagnosticEngine *Diags);
385374

386-
void getStringLiteralSegments(const syntax::Token &Str,
375+
void getStringLiteralSegments(const Token &Str,
387376
SmallVectorImpl<StringSegment> &Segments) {
388377
return getStringLiteralSegments(Str, Segments, Diags);
389378
}
@@ -393,7 +382,7 @@ class Lexer {
393382
}
394383

395384
/// Get the token that starts at the given location.
396-
syntax::Token getTokenAt(SourceLoc Loc);
385+
Token getTokenAt(SourceLoc Loc);
397386

398387
/// SILBodyRAII - This helper class is used when parsing a SIL body to inform
399388
/// the lexer that SIL-specific lexing should be enabled.
@@ -437,7 +426,6 @@ class Lexer {
437426

438427
void formToken(tok Kind, const char *TokStart);
439428

440-
void skipUpToEndOfLine();
441429
void skipToEndOfLine();
442430

443431
/// Skip to the end of the line of a // comment.
@@ -453,12 +441,6 @@ class Lexer {
453441
void lexOperatorIdentifier();
454442
void lexHexNumber();
455443
void lexNumber();
456-
void lexTrivia(std::deque<syntax::Trivia> &T, bool StopAtFirstNewline = false);
457-
Optional<syntax::Trivia> lexWhitespace(bool StopAtFirstNewline);
458-
Optional<syntax::Trivia> lexComment();
459-
Optional<syntax::Trivia> lexSingleLineComment(syntax::TriviaKind Kind);
460-
Optional<syntax::Trivia> lexBlockComment(syntax::TriviaKind Kind);
461-
Optional<syntax::Trivia> lexDocComment();
462444
static unsigned lexUnicodeEscape(const char *&CurPtr, Lexer *Diags);
463445

464446
unsigned lexCharacter(const char *&CurPtr,

0 commit comments

Comments
 (0)