Skip to content

Commit 1584e87

Browse files
authored
Revert "[SyntaxParse] Parse generic parameter clause and generic where clause"
1 parent 4804444 commit 1584e87

33 files changed

+364
-634
lines changed

cmake/modules/SwiftHandleGybSources.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
121121
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/DeclNodes.py"
122122
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/ExprNodes.py"
123123
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/GenericNodes.py"
124-
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/NodeSerializationCodes.py"
125124
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/PatternNodes.py"
126-
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/SILOnlyNodes.py"
127125
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/StmtNodes.py"
128126
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/TypeNodes.py"
129127
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/Token.py"

include/swift/Parse/ASTGen.h

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,21 @@
2222

2323
namespace swift {
2424
/// Generates AST nodes from Syntax nodes.
25-
class Parser;
2625
class ASTGen {
2726
ASTContext &Context;
2827

2928
/// Type cache to prevent multiple transformations of the same syntax node.
3029
llvm::DenseMap<syntax::SyntaxNodeId, TypeRepr *> TypeCache;
3130

32-
Parser &P;
31+
PersistentParserState **ParserState;
3332

3433
// FIXME: remove when Syntax can represent all types and ASTGen can handle them
3534
/// Types that cannot be represented by Syntax or generated by ASTGen.
3635
llvm::DenseMap<SourceLoc, TypeRepr *> Types;
3736

38-
llvm::DenseMap<SourceLoc, DeclAttributes> ParsedDeclAttrs;
39-
4037
public:
41-
ASTGen(ASTContext &Context, Parser &P)
42-
: Context(Context), P(P) {}
38+
ASTGen(ASTContext &Context, PersistentParserState **ParserState)
39+
: Context(Context), ParserState(ParserState) {}
4340

4441
SourceLoc generate(syntax::TokenSyntax Tok, SourceLoc &Loc);
4542

@@ -73,15 +70,6 @@ class ASTGen {
7370
llvm::SmallVector<TypeRepr *, 4>
7471
generate(syntax::GenericArgumentListSyntax Args, SourceLoc &Loc);
7572

76-
GenericParamList *
77-
generate(syntax::GenericParameterClauseListSyntax clause, SourceLoc &Loc);
78-
GenericParamList *
79-
generate(syntax::GenericParameterClauseSyntax clause, SourceLoc &Loc);
80-
Optional<RequirementRepr>
81-
generate(syntax::GenericRequirementSyntax req, SourceLoc &Loc);
82-
LayoutConstraint
83-
generate(syntax::LayoutConstraintSyntax req, SourceLoc &Loc);
84-
8573
/// Copy a numeric literal value into AST-owned memory, stripping underscores
8674
/// so the semantic part of the value can be parsed by APInt/APFloat parsers.
8775
static StringRef copyAndStripUnderscores(StringRef Orig, ASTContext &Context);
@@ -114,8 +102,6 @@ class ASTGen {
114102

115103
ValueDecl *lookupInScope(DeclName Name);
116104

117-
void addToScope(ValueDecl *D, bool diagnoseRedefinitions = true);
118-
119105
TypeRepr *cacheType(syntax::TypeSyntax Type, TypeRepr *TypeAST);
120106

121107
TypeRepr *lookupType(syntax::TypeSyntax Type);
@@ -126,10 +112,6 @@ class ASTGen {
126112
bool hasType(const SourceLoc &Loc) const;
127113

128114
TypeRepr *getType(const SourceLoc &Loc) const;
129-
130-
void addDeclAttributes(DeclAttributes attrs, SourceLoc Loc);
131-
bool hasDeclAttributes(SourceLoc Loc) const;
132-
DeclAttributes getDeclAttributes(SourceLoc Loc) const;
133115
};
134116
} // namespace swift
135117

include/swift/Parse/Lexer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ class Lexer {
200200
ParsedTrivia &TrailingTriviaResult) {
201201
Result = NextToken;
202202
if (TriviaRetention == TriviaRetentionMode::WithTrivia) {
203-
std::swap(LeadingTriviaResult, LeadingTrivia);
204-
std::swap(TrailingTriviaResult, TrailingTrivia);
203+
LeadingTriviaResult = {LeadingTrivia};
204+
TrailingTriviaResult = {TrailingTrivia};
205205
}
206206
if (Result.isNot(tok::eof))
207207
lexImpl();

include/swift/Parse/ParsedSyntaxBuilders.h.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace swift {
3030
class ParsedRawSyntaxRecorder;
3131
class SyntaxParsingContext;
3232

33-
% for node in SYNTAX_NODES + SILONLY_NODES:
33+
% for node in SYNTAX_NODES:
3434
% if node.is_buildable():
3535
% child_count = len(node.children)
3636
class Parsed${node.name}Builder {

include/swift/Parse/ParsedSyntaxNodes.h.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ namespace swift {
2828
% # Emit the non-collection classes first, then emit the collection classes
2929
% # that reference these classes.
3030

31-
% for node in SYNTAX_NODES + SILONLY_NODES:
31+
% for node in SYNTAX_NODES:
3232
% if not node.is_syntax_collection():
3333
class Parsed${node.name};
3434
% end
3535
% end
3636

37-
% for node in SYNTAX_NODES + SILONLY_NODES:
37+
% for node in SYNTAX_NODES:
3838
% if node.is_syntax_collection():
3939
using Parsed${node.name} =
4040
ParsedSyntaxCollection<syntax::SyntaxKind::${node.syntax_kind}>;
4141
% end
4242
% end
4343

44-
% for node in SYNTAX_NODES + SILONLY_NODES:
44+
% for node in SYNTAX_NODES:
4545
% if not node.is_syntax_collection():
4646
% qualifier = "" if node.is_base() else "final"
4747
% for line in dedented_lines(node.description):

include/swift/Parse/ParsedSyntaxRecorder.h.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SyntaxParsingContext;
3131

3232
struct ParsedSyntaxRecorder {
3333

34-
% for node in SYNTAX_NODES + SILONLY_NODES:
34+
% for node in SYNTAX_NODES:
3535
% if node.children:
3636
% child_params = []
3737
% for child in node.children:

include/swift/Parse/Parser.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -695,19 +695,11 @@ class Parser {
695695
/// plain Tok.is(T1) check).
696696
bool skipUntilTokenOrEndOfLine(tok T1);
697697

698-
//-------------------------------------------------------------------------//
699-
// Ignore token APIs.
700-
// This is used when we skip gabage text in the source text.
701-
702-
/// Ignore the current single token.
703698
void ignoreToken();
704699
void ignoreToken(tok Kind) {
705-
/// Ignore the current single token asserting its kind.
706700
assert(Tok.is(Kind));
707701
ignoreToken();
708702
}
709-
/// Conditionally ignore the current single token if it matches with the \p
710-
/// Kind.
711703
bool ignoreIf(tok Kind) {
712704
if (!Tok.is(Kind))
713705
return false;
@@ -1181,8 +1173,7 @@ class Parser {
11811173
using TypeASTResult = ParserResult<TypeRepr>;
11821174
using TypeResult = ParsedSyntaxResult<ParsedTypeSyntax>;
11831175

1184-
ParsedSyntaxResult<ParsedLayoutConstraintSyntax>
1185-
parseLayoutConstraintSyntax();
1176+
LayoutConstraint parseLayoutConstraint(Identifier LayoutConstraintID);
11861177

11871178
TypeResult parseTypeSyntax();
11881179
TypeResult parseTypeSyntax(Diag<> MessageID, bool HandleCodeCompletion = true,
@@ -1606,19 +1597,8 @@ class Parser {
16061597
//===--------------------------------------------------------------------===//
16071598
// Generics Parsing
16081599

1609-
ParserResult<GenericParamList> parseSILGenericParams();
1610-
1611-
ParserStatus parseSILGenericParamsSyntax(
1612-
Optional<ParsedGenericParameterClauseListSyntax> &result);
1613-
1614-
ParsedSyntaxResult<ParsedGenericParameterClauseSyntax>
1615-
parseGenericParameterClauseSyntax();
1616-
1617-
ParsedSyntaxResult<ParsedGenericWhereClauseSyntax>
1618-
parseGenericWhereClauseSyntax(bool &FirstTypeInComplete,
1619-
bool AllowLayoutConstraints = false);
1620-
16211600
ParserResult<GenericParamList> parseGenericParameters();
1601+
ParserResult<GenericParamList> parseGenericParameters(SourceLoc LAngleLoc);
16221602
ParserStatus parseGenericParametersBeforeWhere(SourceLoc LAngleLoc,
16231603
SmallVectorImpl<GenericTypeParamDecl *> &GenericParams);
16241604
ParserResult<GenericParamList> maybeParseGenericParams();

include/swift/Syntax/SyntaxBuilders.h.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace syntax {
2929

3030
class SyntaxArena;
3131

32-
% for node in SYNTAX_NODES + SILONLY_NODES:
32+
% for node in SYNTAX_NODES:
3333
% if node.is_buildable():
3434
% child_count = len(node.children)
3535
class ${node.name}Builder {

include/swift/Syntax/SyntaxFactory.h.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct SyntaxFactory {
7171
static Syntax
7272
makeBlankCollectionSyntax(SyntaxKind Kind);
7373

74-
% for node in SYNTAX_NODES + SILONLY_NODES:
74+
% for node in SYNTAX_NODES:
7575
% if node.children:
7676
% child_params = []
7777
% for child in node.children:

include/swift/Syntax/SyntaxKind.h.gyb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from gyb_syntax_support import *
33
from gyb_syntax_support.kinds import SYNTAX_BASE_KINDS
44
grouped_nodes = { kind: [] for kind in SYNTAX_BASE_KINDS }
5-
for node in SYNTAX_NODES + SILONLY_NODES:
5+
for node in SYNTAX_NODES:
66
grouped_nodes[node.base_kind].append(node)
77
# -*- mode: C++ -*-
88
# Ignore the following admonition; it applies to the resulting .h file only
@@ -89,14 +89,12 @@ struct WrapperTypeTraits<syntax::SyntaxKind> {
8989
return 0;
9090
case syntax::SyntaxKind::Unknown:
9191
return 1;
92-
% for node in SYNTAX_NODES:
92+
% for name, nodes in grouped_nodes.items():
93+
% for node in nodes:
9394
case syntax::SyntaxKind::${node.syntax_kind}:
9495
return ${SYNTAX_NODE_SERIALIZATION_CODES[node.syntax_kind]};
96+
% end
9597
% end
96-
% for node in SILONLY_NODES:
97-
case syntax::SyntaxKind::${node.syntax_kind}:
98-
% end
99-
llvm_unreachable("unserializable syntax kind");
10098
}
10199
llvm_unreachable("unhandled kind");
102100
}
@@ -124,10 +122,6 @@ struct ScalarReferenceTraits<syntax::SyntaxKind> {
124122
case syntax::SyntaxKind::${node.syntax_kind}:
125123
return "\"${node.syntax_kind}\"";
126124
% end
127-
% for node in SILONLY_NODES:
128-
case syntax::SyntaxKind::${node.syntax_kind}:
129-
% end
130-
llvm_unreachable("unserializable syntax kind");
131125
}
132126
llvm_unreachable("unhandled kind");
133127
}

include/swift/Syntax/SyntaxNodes.h.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ namespace syntax {
3232
% # Emit the non-collection classes first, then emit the collection classes
3333
% # that reference these classes.
3434

35-
% for node in SYNTAX_NODES + SILONLY_NODES:
35+
% for node in SYNTAX_NODES:
3636
% if not node.is_syntax_collection():
3737
class ${node.name};
3838
% end
3939
% end
4040

41-
% for node in SYNTAX_NODES + SILONLY_NODES:
41+
% for node in SYNTAX_NODES:
4242
% if node.is_syntax_collection():
4343
using ${node.name} =
4444
SyntaxCollection<SyntaxKind::${node.syntax_kind},
4545
${node.collection_element_type}>;
4646
% end
4747
% end
4848

49-
% for node in SYNTAX_NODES + SILONLY_NODES:
49+
% for node in SYNTAX_NODES:
5050
% if not node.is_syntax_collection():
5151
% qualifier = "" if node.is_base() else "final"
5252
% for line in dedented_lines(node.description):

include/swift/Syntax/SyntaxVisitor.h.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace syntax {
3232
struct SyntaxVisitor {
3333
virtual ~SyntaxVisitor() {}
3434

35-
% for node in SYNTAX_NODES + SILONLY_NODES:
35+
% for node in SYNTAX_NODES:
3636
% if is_visitable(node):
3737
virtual void visit(${node.name} node);
3838
% end

0 commit comments

Comments
 (0)