Skip to content

Commit e7b002f

Browse files
author
Greg Parker
authored
Merge pull request #12517 from gparker42/revert-ee7a062
Revert "libSyntax: create a basic infrastructure for generating libSy…
2 parents ce153ea + 48a6b9d commit e7b002f

File tree

16 files changed

+39
-473
lines changed

16 files changed

+39
-473
lines changed

include/swift/AST/Module.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#include "swift/Basic/SourceLoc.h"
2929
#include "swift/Basic/STLExtras.h"
3030
#include "swift/Parse/Token.h"
31-
#include "swift/Syntax/SyntaxNodes.h"
32-
#include "swift/Syntax/SyntaxParsingContext.h"
3331
#include "llvm/ADT/ArrayRef.h"
3432
#include "llvm/ADT/DenseSet.h"
3533
#include "llvm/ADT/SetVector.h"
@@ -1084,23 +1082,9 @@ class SourceFile final : public FileUnit {
10841082
return (bool)AllCorrectedTokens;
10851083
}
10861084

1087-
syntax::SourceFileSyntax getSyntaxRoot() const {
1088-
assert(SyntaxRoot && "no syntax root is set.");
1089-
return *SyntaxRoot;
1090-
}
1091-
10921085
private:
1093-
friend class syntax::SyntaxParsingContext;
1094-
friend class syntax::SyntaxParsingContextRoot;
1095-
10961086
/// If not None, the underlying vector should contain tokens of this source file.
10971087
Optional<std::vector<Token>> AllCorrectedTokens;
1098-
1099-
/// All of the raw token syntax nodes in the underlying source.
1100-
std::vector<syntax::RawTokenInfo> AllRawTokenSyntax;
1101-
1102-
/// The root of the syntax tree representing the source file.
1103-
Optional<syntax::SourceFileSyntax> SyntaxRoot;
11041088
};
11051089

11061090

include/swift/Basic/OwnedString.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class OwnedString {
4949
assert(Length >= 0 && "expected length to be non-negative");
5050

5151
if (Ownership == StringOwnership::Copied && Data) {
52+
assert(
53+
Length <= strlen(Data) &&
54+
"expected length to be a valid index, within the length of the string");
55+
5256
char *substring = static_cast<char *>(malloc(Length + 1));
5357
assert(substring && "expected successful malloc of copy");
5458

include/swift/Parse/Lexer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "swift/Parse/Token.h"
2424
#include "swift/Syntax/References.h"
2525
#include "swift/Syntax/Trivia.h"
26-
#include "swift/Syntax/SyntaxParsingContext.h"
2726
#include "llvm/ADT/SmallVector.h"
2827
#include "llvm/Support/SaveAndRestore.h"
2928

@@ -246,7 +245,7 @@ class Lexer {
246245
}
247246

248247
/// Lex a full token including leading and trailing trivia.
249-
syntax::RawTokenInfo fullLex();
248+
RC<syntax::RawTokenSyntax> fullLex();
250249

251250
bool isKeepingComments() const {
252251
return RetainComments == CommentRetentionMode::ReturnAsTokens;

include/swift/Parse/Parser.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include "swift/AST/Module.h"
2626
#include "swift/AST/Pattern.h"
2727
#include "swift/AST/Stmt.h"
28-
#include "swift/Syntax/RawTokenSyntax.h"
29-
#include "swift/Syntax/SyntaxParsingContext.h"
3028
#include "swift/Basic/OptionSet.h"
3129
#include "swift/Parse/Lexer.h"
3230
#include "swift/Parse/LocalContext.h"
@@ -327,9 +325,6 @@ class Parser {
327325
/// This vector is managed by \c StructureMarkerRAII objects.
328326
llvm::SmallVector<StructureMarker, 16> StructureMarkers;
329327

330-
/// Current syntax parsing context where call backs should be directed to.
331-
syntax::SyntaxParsingContext *SyntaxContext;
332-
333328
public:
334329
Parser(unsigned BufferID, SourceFile &SF, SILParserTUStateBase *SIL,
335330
PersistentParserState *PersistentState = nullptr);
@@ -1422,11 +1417,6 @@ tokenizeWithTrivia(const LangOptions &LangOpts,
14221417
unsigned Offset = 0,
14231418
unsigned EndOffset = 0);
14241419

1425-
1426-
void populateTokenSyntaxMap(const LangOptions &LangOpts,
1427-
const SourceManager &SM,
1428-
unsigned BufferID,
1429-
std::vector<syntax::RawTokenInfo> &Result);
14301420
} // end namespace swift
14311421

14321422
#endif

include/swift/Syntax/Syntax.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ class Syntax {
127127
/// if it has one, otherwise 0.
128128
CursorIndex getIndexInParent() const;
129129

130-
/// Returns true if this syntax node represents a token.
131-
bool isToken() const;
132-
133130
/// Returns true if this syntax node represents a statement.
134131
bool isStmt() const;
135132

@@ -155,6 +152,9 @@ class Syntax {
155152
/// Returns true if the node is "present" in the source.
156153
bool isPresent() const;
157154

155+
156+
bool isToken() const;
157+
158158
/// Print the syntax node with full fidelity to the given output stream.
159159
void print(llvm::raw_ostream &OS) const;
160160

include/swift/Syntax/SyntaxFactory.h.gyb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ struct SyntaxFactory {
5454
static Optional<Syntax>
5555
createSyntax(SyntaxKind Kind, llvm::ArrayRef<Syntax> Elements);
5656

57-
static SyntaxKind getUnknownKind(SyntaxKind Kind);
58-
5957
% for node in SYNTAX_NODES:
6058
% if node.children:
6159
% child_params = []
@@ -107,7 +105,7 @@ struct SyntaxFactory {
107105
llvm::Optional<TokenSyntax> TrailingComma = llvm::None);
108106

109107
/// Creates a TypeIdentifierSyntax with the provided name and leading/trailing
110-
/// trivia.
108+
/// trivia.
111109
static TypeIdentifierSyntax makeTypeIdentifier(OwnedString TypeName,
112110
const Trivia &LeadingTrivia = {}, const Trivia &TrailingTrivia = {});
113111

@@ -119,7 +117,7 @@ struct SyntaxFactory {
119117
/// Creates a TypeIdentifierSyntax for the `Any` type.
120118
static TypeIdentifierSyntax makeAnyTypeIdentifier(
121119
const Trivia &LeadingTrivia = {}, const Trivia &TrailingTrivia = {});
122-
120+
123121
/// Creates a TypeIdentifierSyntax for the `Self` type.
124122
static TypeIdentifierSyntax makeSelfTypeIdentifier(
125123
const Trivia &LeadingTrivia = {}, const Trivia &TrailingTrivia = {});

include/swift/Syntax/SyntaxParsingContext.h

Lines changed: 0 additions & 110 deletions
This file was deleted.

lib/Parse/Lexer.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "swift/AST/Identifier.h"
2121
#include "swift/Basic/LangOptions.h"
2222
#include "swift/Basic/SourceManager.h"
23-
#include "swift/Syntax/SyntaxParsingContext.h"
23+
#include "swift/Syntax/TokenSyntax.h"
2424
#include "llvm/Support/Compiler.h"
2525
#include "llvm/Support/MathExtras.h"
2626
#include "llvm/Support/MemoryBuffer.h"
@@ -737,12 +737,11 @@ static bool rangeContainsPlaceholderEnd(const char *CurPtr,
737737
return false;
738738
}
739739

740-
syntax::RawTokenInfo Lexer::fullLex() {
740+
RC<syntax::RawTokenSyntax> Lexer::fullLex() {
741741
if (NextToken.isEscapedIdentifier()) {
742742
LeadingTrivia.push_back(syntax::TriviaPiece::backtick());
743743
TrailingTrivia.push_front(syntax::TriviaPiece::backtick());
744744
}
745-
auto Loc = NextToken.getLoc();
746745
auto Result = syntax::RawTokenSyntax::make(NextToken.getKind(),
747746
OwnedString(NextToken.getText()).copy(),
748747
syntax::SourcePresence::Present,
@@ -752,7 +751,7 @@ syntax::RawTokenInfo Lexer::fullLex() {
752751
if (NextToken.isNot(tok::eof)) {
753752
lexImpl();
754753
}
755-
return {Loc, Result};
754+
return Result;
756755
}
757756

758757
/// lexOperatorIdentifier - Match identifiers formed out of punctuation.

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
#include "swift/AST/DiagnosticsParse.h"
1919
#include "swift/Basic/EditorPlaceholder.h"
2020
#include "swift/Parse/CodeCompletionCallbacks.h"
21-
#include "swift/Syntax/SyntaxFactory.h"
22-
#include "swift/Syntax/TokenSyntax.h"
23-
#include "swift/Syntax/SyntaxParsingContext.h"
2421
#include "llvm/ADT/SmallString.h"
2522
#include "llvm/ADT/StringSwitch.h"
2623
#include "llvm/ADT/Twine.h"
@@ -30,7 +27,6 @@
3027
#include "llvm/Support/raw_ostream.h"
3128

3229
using namespace swift;
33-
using namespace swift::syntax;
3430

3531
/// parseExpr
3632
///
@@ -39,9 +35,6 @@ using namespace swift::syntax;
3935
///
4036
/// \param isExprBasic Whether we're only parsing an expr-basic.
4137
ParserResult<Expr> Parser::parseExprImpl(Diag<> Message, bool isExprBasic) {
42-
// Start a context for creating expression syntax.
43-
SyntaxParsingContextChild ExprParsingContext(SyntaxContext, SyntaxKind::Expr);
44-
4538
// If we are parsing a refutable pattern, check to see if this is the start
4639
// of a let/var/is pattern. If so, parse it to an UnresolvedPatternExpr and
4740
// name binding will perform final validation.
@@ -472,7 +465,6 @@ ParserResult<Expr> Parser::parseExprUnary(Diag<> Message, bool isExprBasic) {
472465
Tok.setKind(tok::oper_prefix);
473466
LLVM_FALLTHROUGH;
474467
case tok::oper_prefix:
475-
SyntaxContext->addTokenSyntax(Tok.getLoc());
476468
Operator = parseExprOperator();
477469
break;
478470
case tok::oper_binary_spaced:
@@ -765,6 +757,7 @@ UnresolvedDeclRefExpr *Parser::parseExprOperator() {
765757
SourceLoc loc = Tok.getLoc();
766758
Identifier name = Context.getIdentifier(Tok.getText());
767759
consumeToken();
760+
768761
// Bypass local lookup.
769762
return new (Context) UnresolvedDeclRefExpr(name, refKind, DeclNameLoc(loc));
770763
}
@@ -1388,8 +1381,6 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
13881381
case tok::integer_literal: {
13891382
StringRef Text = copyAndStripUnderscores(Context, Tok.getText());
13901383
SourceLoc Loc = consumeToken(tok::integer_literal);
1391-
SyntaxContext->addTokenSyntax(Loc);
1392-
SyntaxContext->makeNode(SyntaxKind::IntegerLiteralExpr);
13931384
Result = makeParserResult(new (Context) IntegerLiteralExpr(Text, Loc,
13941385
/*Implicit=*/false));
13951386
break;
@@ -1795,20 +1786,11 @@ createStringLiteralExprFromSegment(ASTContext &Ctx,
17951786
/// expr-literal:
17961787
/// string_literal
17971788
ParserResult<Expr> Parser::parseExprStringLiteral() {
1798-
17991789
SmallVector<Lexer::StringSegment, 1> Segments;
18001790
L->getStringLiteralSegments(Tok, Segments);
18011791

18021792
Token EntireTok = Tok;
18031793

1804-
// Create a syntax node for string literal.
1805-
SyntaxContext->addTokenSyntax(Tok.getLoc());
1806-
SyntaxContext->makeNode(SyntaxKind::StringLiteralExpr);
1807-
SyntaxParsingContextChild LocalContext(SyntaxContext, SyntaxKind::Expr);
1808-
1809-
// FIXME: Avoid creating syntax nodes for string interpolation.
1810-
LocalContext.disable();
1811-
18121794
// The start location of the entire string literal.
18131795
SourceLoc Loc = Tok.getLoc();
18141796

0 commit comments

Comments
 (0)