Skip to content

Commit 0165b4f

Browse files
committed
Revert "Merge pull request swiftlang#27291 from rintaro/syntaxparses-astgen-signature"
This reverts commit e315b6f, reversing changes made to 079a1a4.
1 parent 045593d commit 0165b4f

File tree

6 files changed

+127
-190
lines changed

6 files changed

+127
-190
lines changed

include/swift/Parse/ASTGen.h

Lines changed: 64 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -34,130 +34,87 @@ class ASTGen {
3434

3535
Parser &P;
3636

37-
// FIXME: remove when Syntax can represent all types and ASTGen can handle
38-
// them
37+
// FIXME: remove when Syntax can represent all types and ASTGen can handle them
3938
/// Types that cannot be represented by Syntax or generated by ASTGen.
4039
llvm::DenseMap<SourceLoc, TypeRepr *> Types;
4140

4241
llvm::DenseMap<SourceLoc, DeclAttributes> ParsedDeclAttrs;
4342

4443
public:
45-
ASTGen(ASTContext &Context, Parser &P) : Context(Context), P(P) {}
44+
ASTGen(ASTContext &Context, Parser &P)
45+
: Context(Context), P(P) {}
46+
47+
SourceLoc generate(syntax::TokenSyntax Tok, SourceLoc &Loc);
48+
49+
Expr *generate(syntax::IntegerLiteralExprSyntax &Expr, SourceLoc &Loc);
50+
Expr *generate(syntax::FloatLiteralExprSyntax &Expr, SourceLoc &Loc);
51+
Expr *generate(syntax::NilLiteralExprSyntax &Expr, SourceLoc &Loc);
52+
Expr *generate(syntax::BooleanLiteralExprSyntax &Expr, SourceLoc &Loc);
53+
Expr *generate(syntax::PoundFileExprSyntax &Expr, SourceLoc &Loc);
54+
Expr *generate(syntax::PoundLineExprSyntax &Expr, SourceLoc &Loc);
55+
Expr *generate(syntax::PoundColumnExprSyntax &Expr, SourceLoc &Loc);
56+
Expr *generate(syntax::PoundFunctionExprSyntax &Expr, SourceLoc &Loc);
57+
Expr *generate(syntax::PoundDsohandleExprSyntax &Expr, SourceLoc &Loc);
58+
Expr *generate(syntax::UnknownExprSyntax &Expr, SourceLoc &Loc);
59+
60+
TypeRepr *generate(syntax::TypeSyntax Type, SourceLoc &Loc);
61+
TypeRepr *generate(syntax::SomeTypeSyntax Type, SourceLoc &Loc);
62+
TypeRepr *generate(syntax::CompositionTypeSyntax Type, SourceLoc &Loc);
63+
TypeRepr *generate(syntax::SimpleTypeIdentifierSyntax Type, SourceLoc &Loc);
64+
TypeRepr *generate(syntax::MemberTypeIdentifierSyntax Type, SourceLoc &Loc);
65+
TypeRepr *generate(syntax::DictionaryTypeSyntax Type, SourceLoc &Loc);
66+
TypeRepr *generate(syntax::ArrayTypeSyntax Type, SourceLoc &Loc);
67+
TypeRepr *generate(syntax::TupleTypeSyntax Type, SourceLoc &Loc);
68+
TypeRepr *generate(syntax::AttributedTypeSyntax Type, SourceLoc &Loc);
69+
TypeRepr *generate(syntax::FunctionTypeSyntax Type, SourceLoc &Loc);
70+
TypeRepr *generate(syntax::MetatypeTypeSyntax Type, SourceLoc &Loc);
71+
TypeRepr *generate(syntax::OptionalTypeSyntax Type, SourceLoc &Loc);
72+
TypeRepr *generate(syntax::ImplicitlyUnwrappedOptionalTypeSyntax Type, SourceLoc &Loc);
73+
TypeRepr *generate(syntax::UnknownTypeSyntax Type, SourceLoc &Loc);
74+
75+
TypeRepr *generate(syntax::GenericArgumentSyntax Arg, SourceLoc &Loc);
76+
llvm::SmallVector<TypeRepr *, 4>
77+
generate(syntax::GenericArgumentListSyntax Args, SourceLoc &Loc);
4678

47-
SourceLoc generate(const syntax::TokenSyntax &Tok, const SourceLoc Loc);
79+
GenericParamList *
80+
generate(syntax::GenericParameterClauseListSyntax clause, SourceLoc &Loc);
81+
GenericParamList *
82+
generate(syntax::GenericParameterClauseSyntax clause, SourceLoc &Loc);
83+
Optional<RequirementRepr>
84+
generate(syntax::GenericRequirementSyntax req, SourceLoc &Loc);
85+
LayoutConstraint
86+
generate(syntax::LayoutConstraintSyntax req, SourceLoc &Loc);
4887

49-
public:
50-
//===--------------------------------------------------------------------===//
51-
// Expressions.
52-
53-
Expr *generate(const syntax::IntegerLiteralExprSyntax &Expr,
54-
const SourceLoc Loc);
55-
Expr *generate(const syntax::FloatLiteralExprSyntax &Expr,
56-
const SourceLoc Loc);
57-
Expr *generate(const syntax::NilLiteralExprSyntax &Expr, const SourceLoc Loc);
58-
Expr *generate(const syntax::BooleanLiteralExprSyntax &Expr,
59-
const SourceLoc Loc);
60-
Expr *generate(const syntax::PoundFileExprSyntax &Expr, const SourceLoc Loc);
61-
Expr *generate(const syntax::PoundLineExprSyntax &Expr, const SourceLoc Loc);
62-
Expr *generate(const syntax::PoundColumnExprSyntax &Expr,
63-
const SourceLoc Loc);
64-
Expr *generate(const syntax::PoundFunctionExprSyntax &Expr,
65-
const SourceLoc Loc);
66-
Expr *generate(const syntax::PoundDsohandleExprSyntax &Expr,
67-
const SourceLoc Loc);
68-
Expr *generate(const syntax::UnknownExprSyntax &Expr, const SourceLoc Loc);
88+
/// Copy a numeric literal value into AST-owned memory, stripping underscores
89+
/// so the semantic part of the value can be parsed by APInt/APFloat parsers.
90+
static StringRef copyAndStripUnderscores(StringRef Orig, ASTContext &Context);
6991

7092
private:
71-
Expr *generateMagicIdentifierLiteralExpression(
72-
const syntax::TokenSyntax &PoundToken, const SourceLoc Loc);
93+
Expr *generateMagicIdentifierLiteralExpression(syntax::TokenSyntax PoundToken,
94+
SourceLoc &Loc);
7395

74-
static MagicIdentifierLiteralExpr::Kind
75-
getMagicIdentifierLiteralKind(tok Kind);
76-
77-
public:
78-
//===--------------------------------------------------------------------===//
79-
// Types.
80-
81-
TypeRepr *generate(const syntax::TypeSyntax &Type, const SourceLoc Loc);
82-
TypeRepr *generate(const syntax::SomeTypeSyntax &Type, const SourceLoc Loc);
83-
TypeRepr *generate(const syntax::CompositionTypeSyntax &Type,
84-
const SourceLoc Loc);
85-
TypeRepr *generate(const syntax::SimpleTypeIdentifierSyntax &Type,
86-
const SourceLoc Loc);
87-
TypeRepr *generate(const syntax::MemberTypeIdentifierSyntax &Type,
88-
const SourceLoc Loc);
89-
TypeRepr *generate(const syntax::DictionaryTypeSyntax &Type,
90-
const SourceLoc Loc);
91-
TypeRepr *generate(const syntax::ArrayTypeSyntax &Type, const SourceLoc Loc);
92-
TypeRepr *generate(const syntax::TupleTypeSyntax &Type, const SourceLoc Loc);
93-
TypeRepr *generate(const syntax::AttributedTypeSyntax &Type,
94-
const SourceLoc Loc);
95-
TypeRepr *generate(const syntax::FunctionTypeSyntax &Type,
96-
const SourceLoc Loc);
97-
TypeRepr *generate(const syntax::MetatypeTypeSyntax &Type,
98-
const SourceLoc Loc);
99-
TypeRepr *generate(const syntax::OptionalTypeSyntax &Type,
100-
const SourceLoc Loc);
101-
TypeRepr *generate(const syntax::ImplicitlyUnwrappedOptionalTypeSyntax &Type,
102-
const SourceLoc Loc);
103-
TypeRepr *generate(const syntax::UnknownTypeSyntax &Type,
104-
const SourceLoc Loc);
105-
106-
private:
107-
TupleTypeRepr *
108-
generateTuple(const syntax::TokenSyntax &LParen,
109-
const syntax::TupleTypeElementListSyntax &Elements,
110-
const syntax::TokenSyntax &RParen, const SourceLoc Loc,
111-
bool IsFunction = false);
96+
TupleTypeRepr *generateTuple(syntax::TokenSyntax LParen,
97+
syntax::TupleTypeElementListSyntax Elements,
98+
syntax::TokenSyntax RParen, SourceLoc &Loc,
99+
bool IsFunction = false);
112100

113101
void gatherTypeIdentifierComponents(
114-
const syntax::TypeSyntax &Component, const SourceLoc Loc,
102+
syntax::TypeSyntax Component, SourceLoc &Loc,
115103
llvm::SmallVectorImpl<ComponentIdentTypeRepr *> &Components);
116104

117105
template <typename T>
118-
TypeRepr *generateSimpleOrMemberIdentifier(const T &Type,
119-
const SourceLoc Loc);
106+
TypeRepr *generateSimpleOrMemberIdentifier(T Type, SourceLoc &Loc);
120107

121108
template <typename T>
122-
ComponentIdentTypeRepr *generateIdentifier(const T &Type,
123-
const SourceLoc Loc);
109+
ComponentIdentTypeRepr *generateIdentifier(T Type, SourceLoc &Loc);
124110

125-
public:
126-
//===--------------------------------------------------------------------===//
127-
// Generics.
128-
129-
TypeRepr *generate(const syntax::GenericArgumentSyntax &Arg,
130-
const SourceLoc Loc);
131-
llvm::SmallVector<TypeRepr *, 4>
132-
generate(const syntax::GenericArgumentListSyntax &Args, const SourceLoc Loc);
133-
134-
GenericParamList *
135-
generate(const syntax::GenericParameterClauseListSyntax &clause,
136-
const SourceLoc Loc);
137-
GenericParamList *generate(const syntax::GenericParameterClauseSyntax &clause,
138-
const SourceLoc Loc);
139-
Optional<RequirementRepr>
140-
generate(const syntax::GenericRequirementSyntax &req, const SourceLoc Loc);
141-
LayoutConstraint generate(const syntax::LayoutConstraintSyntax &req,
142-
const SourceLoc Loc);
143-
144-
public:
145-
//===--------------------------------------------------------------------===//
146-
// Utilities.
147-
148-
/// Copy a numeric literal value into AST-owned memory, stripping underscores
149-
/// so the semantic part of the value can be parsed by APInt/APFloat parsers.
150-
static StringRef copyAndStripUnderscores(StringRef Orig, ASTContext &Context);
151-
152-
private:
153111
StringRef copyAndStripUnderscores(StringRef Orig);
154112

155-
/// Advance \p Loc to the first token of the \p Node.
156-
/// \p Loc must be the leading trivia of the first token in the tree in which
157-
/// \p Node resides.
158113
static SourceLoc advanceLocBegin(const SourceLoc &Loc,
159114
const syntax::Syntax &Node);
160115

116+
static MagicIdentifierLiteralExpr::Kind getMagicIdentifierLiteralKind(tok Kind);
117+
161118
ValueDecl *lookupInScope(DeclName Name);
162119

163120
void addToScope(ValueDecl *D, bool diagnoseRedefinitions = true);
@@ -167,13 +124,15 @@ class ASTGen {
167124
TypeRepr *lookupType(syntax::TypeSyntax Type);
168125

169126
public:
170-
void addType(TypeRepr *Type, const SourceLoc Loc);
171-
bool hasType(const SourceLoc Loc) const;
172-
TypeRepr *getType(const SourceLoc Loc) const;
127+
TypeRepr *addType(TypeRepr *Type, const SourceLoc &Loc);
128+
129+
bool hasType(const SourceLoc &Loc) const;
130+
131+
TypeRepr *getType(const SourceLoc &Loc) const;
173132

174-
void addDeclAttributes(DeclAttributes attrs, const SourceLoc Loc);
133+
void addDeclAttributes(DeclAttributes attrs, SourceLoc Loc);
175134
bool hasDeclAttributes(SourceLoc Loc) const;
176-
DeclAttributes getDeclAttributes(const SourceLoc Loc) const;
135+
DeclAttributes getDeclAttributes(SourceLoc Loc) const;
177136
};
178137
} // namespace swift
179138

include/swift/Syntax/Syntax.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ class Syntax {
172172

173173
/// Returns the first non-missing token in this syntax. Returns None if there
174174
/// is no non-missing token.
175-
Optional<TokenSyntax> getFirstToken() const;
175+
Optional<TokenSyntax> getFirstToken();
176176

177177
/// Returns the last non-missing token in this syntax. Returns None if there
178178
/// is no non-missing token.
179-
Optional<TokenSyntax> getLastToken() const;
179+
Optional<TokenSyntax> getLastToken();
180180

181181
/// Print the syntax node with full fidelity to the given output stream.
182182
void print(llvm::raw_ostream &OS, SyntaxPrintOptions Opts = SyntaxPrintOptions()) const;

include/swift/Syntax/SyntaxNodes.h.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public:
8181
/// ${line}
8282
% end
8383
% if child.is_optional:
84-
llvm::Optional<${child.type_name}> get${child.name}() const;
84+
llvm::Optional<${child.type_name}> get${child.name}();
8585
% else:
86-
${child.type_name} get${child.name}() const;
86+
${child.type_name} get${child.name}();
8787
% end
8888

8989
% child_node = NODE_MAP.get(child.syntax_kind)

0 commit comments

Comments
 (0)