Skip to content

Commit bf5aa0a

Browse files
committed
Revert "Merge pull request swiftlang#27325 from rintaro/syntaxparse-cctype"
This reverts commit 439b911, reversing changes made to 4e476ff.
1 parent 402e791 commit bf5aa0a

24 files changed

+153
-185
lines changed

cmake/modules/SwiftHandleGybSources.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
118118
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/AttributeNodes.py"
119119
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/AvailabilityNodes.py"
120120
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/CommonNodes.py"
121-
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/CompletionOnlyNodes.py"
122121
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/DeclNodes.py"
123122
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/ExprNodes.py"
124123
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/GenericNodes.py"

include/swift/Parse/ASTGen.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ class ASTGen {
100100
const SourceLoc Loc);
101101
TypeRepr *generate(const syntax::ImplicitlyUnwrappedOptionalTypeSyntax &Type,
102102
const SourceLoc Loc);
103-
TypeRepr *generate(const syntax::CodeCompletionTypeSyntax &Type,
104-
const SourceLoc Loc);
105103
TypeRepr *generate(const syntax::UnknownTypeSyntax &Type,
106104
const SourceLoc Loc);
107105

include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class CodeCompletionCallbacks {
4040
/// completion. This declaration contained the code completion token.
4141
Decl *ParsedDecl = nullptr;
4242

43-
TypeLoc ParsedTypeLoc;
44-
4543
/// True if code completion is done inside a raw value expression of an enum
4644
/// case.
4745
bool InEnumElementRawValue = false;
@@ -78,10 +76,6 @@ class CodeCompletionCallbacks {
7876
ParsedDecl = D;
7977
}
8078

81-
void setParsedTypeLoc(TypeLoc TyLoc) {
82-
ParsedTypeLoc = TyLoc;
83-
}
84-
8579
void setLeadingSequenceExprs(ArrayRef<Expr *> exprs) {
8680
leadingSequenceExprs.assign(exprs.begin(), exprs.end());
8781
}
@@ -165,10 +159,10 @@ class CodeCompletionCallbacks {
165159
virtual void completeTypeSimpleBeginning() {};
166160

167161
/// Complete a given type-identifier after we have consumed the dot.
168-
virtual void completeTypeIdentifierWithDot() {};
162+
virtual void completeTypeIdentifierWithDot(IdentTypeRepr *ITR) {};
169163

170164
/// Complete a given type-identifier when there is no trailing dot.
171-
virtual void completeTypeIdentifierWithoutDot() {};
165+
virtual void completeTypeIdentifierWithoutDot(IdentTypeRepr *ITR) {};
172166

173167
/// Complete the beginning of a case statement at the top of switch stmt.
174168
virtual void completeCaseStmtKeyword() {};

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 + PARSEONLY_NODES:
33+
% for node in SYNTAX_NODES + SILONLY_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 + PARSEONLY_NODES:
31+
% for node in SYNTAX_NODES + SILONLY_NODES:
3232
% if not node.is_syntax_collection():
3333
class Parsed${node.name};
3434
% end
3535
% end
3636

37-
% for node in SYNTAX_NODES + PARSEONLY_NODES:
37+
% for node in SYNTAX_NODES + SILONLY_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 + PARSEONLY_NODES:
44+
% for node in SYNTAX_NODES + SILONLY_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 + PARSEONLY_NODES:
34+
% for node in SYNTAX_NODES + SILONLY_NODES:
3535
% if node.children:
3636
% child_params = []
3737
% for child in node.children:

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 + PARSEONLY_NODES:
32+
% for node in SYNTAX_NODES + SILONLY_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 + PARSEONLY_NODES:
74+
% for node in SYNTAX_NODES + SILONLY_NODES:
7575
% if node.children:
7676
% child_params = []
7777
% for child in node.children:

include/swift/Syntax/SyntaxKind.h.gyb

Lines changed: 3 additions & 3 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 + PARSEONLY_NODES:
5+
for node in SYNTAX_NODES + SILONLY_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
@@ -93,7 +93,7 @@ struct WrapperTypeTraits<syntax::SyntaxKind> {
9393
case syntax::SyntaxKind::${node.syntax_kind}:
9494
return ${SYNTAX_NODE_SERIALIZATION_CODES[node.syntax_kind]};
9595
% end
96-
% for node in PARSEONLY_NODES:
96+
% for node in SILONLY_NODES:
9797
case syntax::SyntaxKind::${node.syntax_kind}:
9898
% end
9999
llvm_unreachable("unserializable syntax kind");
@@ -124,7 +124,7 @@ struct ScalarReferenceTraits<syntax::SyntaxKind> {
124124
case syntax::SyntaxKind::${node.syntax_kind}:
125125
return "\"${node.syntax_kind}\"";
126126
% end
127-
% for node in PARSEONLY_NODES:
127+
% for node in SILONLY_NODES:
128128
case syntax::SyntaxKind::${node.syntax_kind}:
129129
% end
130130
llvm_unreachable("unserializable syntax kind");

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 + PARSEONLY_NODES:
35+
% for node in SYNTAX_NODES + SILONLY_NODES:
3636
% if not node.is_syntax_collection():
3737
class ${node.name};
3838
% end
3939
% end
4040

41-
% for node in SYNTAX_NODES + PARSEONLY_NODES:
41+
% for node in SYNTAX_NODES + SILONLY_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 + PARSEONLY_NODES:
49+
% for node in SYNTAX_NODES + SILONLY_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 + PARSEONLY_NODES:
35+
% for node in SYNTAX_NODES + SILONLY_NODES:
3636
% if is_visitable(node):
3737
virtual void visit(${node.name} node);
3838
% end

lib/IDE/CodeCompletion.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
12171217
CompletionKind Kind = CompletionKind::None;
12181218
Expr *ParsedExpr = nullptr;
12191219
SourceLoc DotLoc;
1220+
TypeLoc ParsedTypeLoc;
12201221
DeclContext *CurDeclContext = nullptr;
12211222
DeclAttrKind AttrKind;
12221223

@@ -1350,8 +1351,8 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13501351

13511352
void completeTypeDeclResultBeginning() override;
13521353
void completeTypeSimpleBeginning() override;
1353-
void completeTypeIdentifierWithDot() override;
1354-
void completeTypeIdentifierWithoutDot() override;
1354+
void completeTypeIdentifierWithDot(IdentTypeRepr *ITR) override;
1355+
void completeTypeIdentifierWithoutDot(IdentTypeRepr *ITR) override;
13551356

13561357
void completeCaseStmtKeyword() override;
13571358
void completeCaseStmtBeginning(CodeCompletionExpr *E) override;
@@ -4599,13 +4600,22 @@ void CodeCompletionCallbacksImpl::completeInPrecedenceGroup(SyntaxKind SK) {
45994600
CurDeclContext = P.CurDeclContext;
46004601
}
46014602

4602-
void CodeCompletionCallbacksImpl::completeTypeIdentifierWithDot() {
4603+
void CodeCompletionCallbacksImpl::completeTypeIdentifierWithDot(
4604+
IdentTypeRepr *ITR) {
4605+
if (!ITR) {
4606+
completeTypeSimpleBeginning();
4607+
return;
4608+
}
46034609
Kind = CompletionKind::TypeIdentifierWithDot;
4610+
ParsedTypeLoc = TypeLoc(ITR);
46044611
CurDeclContext = P.CurDeclContext;
46054612
}
46064613

4607-
void CodeCompletionCallbacksImpl::completeTypeIdentifierWithoutDot() {
4614+
void CodeCompletionCallbacksImpl::completeTypeIdentifierWithoutDot(
4615+
IdentTypeRepr *ITR) {
4616+
assert(ITR);
46084617
Kind = CompletionKind::TypeIdentifierWithoutDot;
4618+
ParsedTypeLoc = TypeLoc(ITR);
46094619
CurDeclContext = P.CurDeclContext;
46104620
}
46114621

lib/Parse/ASTGen.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "swift/Basic/SourceManager.h"
1616

1717
#include "swift/Basic/SourceManager.h"
18-
#include "swift/Parse/CodeCompletionCallbacks.h"
1918
#include "swift/Parse/Parser.h"
2019

2120
using namespace swift;
@@ -126,8 +125,6 @@ TypeRepr *ASTGen::generate(const TypeSyntax &Type, const SourceLoc Loc) {
126125
TypeAST = generate(*Unwrapped, Loc);
127126
else if (auto Attributed = Type.getAs<AttributedTypeSyntax>())
128127
TypeAST = generate(*Attributed, Loc);
129-
else if (auto CompletionTy = Type.getAs<CodeCompletionTypeSyntax>())
130-
TypeAST = generate(*CompletionTy, Loc);
131128
else if (auto Unknown = Type.getAs<UnknownTypeSyntax>())
132129
TypeAST = generate(*Unknown, Loc);
133130

@@ -450,44 +447,34 @@ TypeRepr *ASTGen::generate(const ImplicitlyUnwrappedOptionalTypeSyntax &Type,
450447
ImplicitlyUnwrappedOptionalTypeRepr(WrappedType, ExclamationLoc);
451448
}
452449

453-
TypeRepr *ASTGen::generate(const CodeCompletionTypeSyntax &Type,
454-
const SourceLoc Loc) {
455-
auto base = Type.getBase();
456-
if (!base)
457-
return nullptr;
458-
459-
TypeRepr *parsedTyR = generate(*base, Loc);
460-
if (parsedTyR) {
461-
if (P.CodeCompletion)
462-
P.CodeCompletion->setParsedTypeLoc(parsedTyR);
463-
}
464-
return parsedTyR;
465-
}
466-
467450
TypeRepr *ASTGen::generate(const UnknownTypeSyntax &Type, const SourceLoc Loc) {
468451
auto ChildrenCount = Type.getNumChildren();
469452

470453
// Recover from old-style protocol composition:
471454
// `protocol` `<` protocols `>`
472455
if (ChildrenCount >= 2) {
473-
auto keyword = Type.getChild(0)->getAs<TokenSyntax>();
456+
auto Protocol = Type.getChild(0)->getAs<TokenSyntax>();
474457

475-
if (keyword && keyword->getText() == "protocol") {
476-
auto keywordLoc = advanceLocBegin(Loc, *keyword);
458+
if (Protocol && Protocol->getText() == "protocol") {
477459
auto LAngle = Type.getChild(1);
460+
461+
SmallVector<TypeSyntax, 4> Protocols;
462+
for (unsigned i = 2; i < Type.getNumChildren(); i++)
463+
if (auto PType = Type.getChild(i)->getAs<TypeSyntax>())
464+
Protocols.push_back(*PType);
465+
478466
auto RAngle = Type.getChild(ChildrenCount - 1);
479467

468+
auto ProtocolLoc = advanceLocBegin(Loc, *Protocol);
480469
auto LAngleLoc = advanceLocBegin(Loc, *LAngle);
481470
auto RAngleLoc = advanceLocBegin(Loc, *RAngle);
482471

483-
SmallVector<TypeRepr *, 4> protocols;
484-
for (unsigned i = 2; i < Type.getNumChildren(); i++) {
485-
if (auto elem = Type.getChild(i)->getAs<TypeSyntax>())
486-
if (auto proto = generate(*elem, Loc))
487-
protocols.push_back(proto);
488-
}
472+
SmallVector<TypeRepr *, 4> ProtocolTypes;
473+
for (auto &&P : llvm::reverse(Protocols))
474+
ProtocolTypes.push_back(generate(P, Loc));
475+
std::reverse(std::begin(ProtocolTypes), std::end(ProtocolTypes));
489476

490-
return CompositionTypeRepr::create(Context, protocols, keywordLoc,
477+
return CompositionTypeRepr::create(Context, ProtocolTypes, ProtocolLoc,
491478
{LAngleLoc, RAngleLoc});
492479
}
493480
}

0 commit comments

Comments
 (0)