16
16
#include " swift/AST/ASTContext.h"
17
17
#include " swift/AST/Decl.h"
18
18
#include " swift/AST/Expr.h"
19
- #include " swift/AST/TypeRepr.h"
20
19
#include " swift/Parse/PersistentParserState.h"
21
20
#include " swift/Syntax/SyntaxNodes.h"
22
21
#include " llvm/ADT/DenseMap.h"
@@ -32,158 +31,87 @@ class ASTGen {
32
31
33
32
Parser &P;
34
33
35
- // FIXME: remove when Syntax can represent all types and ASTGen can handle
36
- // them
34
+ // FIXME: remove when Syntax can represent all types and ASTGen can handle them
37
35
// / Types that cannot be represented by Syntax or generated by ASTGen.
38
36
llvm::DenseMap<SourceLoc, TypeRepr *> Types;
39
37
40
38
llvm::DenseMap<SourceLoc, DeclAttributes> ParsedDeclAttrs;
41
39
42
40
public:
43
- ASTGen (ASTContext &Context, Parser &P) : Context(Context), P(P) {}
44
-
45
- SourceLoc generate (const syntax::TokenSyntax &Tok, const SourceLoc Loc);
46
-
47
- SourceLoc generateIdentifierDeclName (const syntax::TokenSyntax &Tok,
48
- const SourceLoc, Identifier &Identifier);
49
-
50
- public:
51
- // ===--------------------------------------------------------------------===//
52
- // Decls.
53
-
54
- Decl *generate (const syntax::DeclSyntax &Decl, const SourceLoc Loc);
55
- TypeDecl *generate (const syntax::AssociatedtypeDeclSyntax &Decl,
56
- const SourceLoc Loc);
57
-
58
- TrailingWhereClause *generate (const syntax::GenericWhereClauseSyntax &syntax,
59
- const SourceLoc Loc);
60
- MutableArrayRef<TypeLoc>
61
- generate (const syntax::TypeInheritanceClauseSyntax &syntax,
62
- const SourceLoc Loc, bool allowClassRequirement);
41
+ ASTGen (ASTContext &Context, Parser &P)
42
+ : Context(Context), P(P) {}
43
+
44
+ SourceLoc generate (syntax::TokenSyntax Tok, SourceLoc &Loc);
45
+
46
+ Expr *generate (syntax::IntegerLiteralExprSyntax &Expr, SourceLoc &Loc);
47
+ Expr *generate (syntax::FloatLiteralExprSyntax &Expr, SourceLoc &Loc);
48
+ Expr *generate (syntax::NilLiteralExprSyntax &Expr, SourceLoc &Loc);
49
+ Expr *generate (syntax::BooleanLiteralExprSyntax &Expr, SourceLoc &Loc);
50
+ Expr *generate (syntax::PoundFileExprSyntax &Expr, SourceLoc &Loc);
51
+ Expr *generate (syntax::PoundLineExprSyntax &Expr, SourceLoc &Loc);
52
+ Expr *generate (syntax::PoundColumnExprSyntax &Expr, SourceLoc &Loc);
53
+ Expr *generate (syntax::PoundFunctionExprSyntax &Expr, SourceLoc &Loc);
54
+ Expr *generate (syntax::PoundDsohandleExprSyntax &Expr, SourceLoc &Loc);
55
+ Expr *generate (syntax::UnknownExprSyntax &Expr, SourceLoc &Loc);
56
+
57
+ TypeRepr *generate (syntax::TypeSyntax Type, SourceLoc &Loc);
58
+ TypeRepr *generate (syntax::SomeTypeSyntax Type, SourceLoc &Loc);
59
+ TypeRepr *generate (syntax::CompositionTypeSyntax Type, SourceLoc &Loc);
60
+ TypeRepr *generate (syntax::SimpleTypeIdentifierSyntax Type, SourceLoc &Loc);
61
+ TypeRepr *generate (syntax::MemberTypeIdentifierSyntax Type, SourceLoc &Loc);
62
+ TypeRepr *generate (syntax::DictionaryTypeSyntax Type, SourceLoc &Loc);
63
+ TypeRepr *generate (syntax::ArrayTypeSyntax Type, SourceLoc &Loc);
64
+ TypeRepr *generate (syntax::TupleTypeSyntax Type, SourceLoc &Loc);
65
+ TypeRepr *generate (syntax::AttributedTypeSyntax Type, SourceLoc &Loc);
66
+ TypeRepr *generate (syntax::FunctionTypeSyntax Type, SourceLoc &Loc);
67
+ TypeRepr *generate (syntax::MetatypeTypeSyntax Type, SourceLoc &Loc);
68
+ TypeRepr *generate (syntax::OptionalTypeSyntax Type, SourceLoc &Loc);
69
+ TypeRepr *generate (syntax::ImplicitlyUnwrappedOptionalTypeSyntax Type, SourceLoc &Loc);
70
+ TypeRepr *generate (syntax::UnknownTypeSyntax Type, SourceLoc &Loc);
71
+
72
+ TypeRepr *generate (syntax::GenericArgumentSyntax Arg, SourceLoc &Loc);
73
+ llvm::SmallVector<TypeRepr *, 4 >
74
+ generate (syntax::GenericArgumentListSyntax Args, SourceLoc &Loc);
63
75
64
- private:
65
- DeclAttributes
66
- generateDeclAttributes (const syntax::DeclSyntax &D,
67
- const Optional<syntax::AttributeListSyntax> &attrs,
68
- const Optional<syntax::ModifierListSyntax> &modifiers,
69
- SourceLoc Loc, bool includeComments);
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);
70
84
71
- public:
72
- // ===--------------------------------------------------------------------===//
73
- // Expressions.
74
-
75
- Expr *generate (const syntax::IntegerLiteralExprSyntax &Expr,
76
- const SourceLoc Loc);
77
- Expr *generate (const syntax::FloatLiteralExprSyntax &Expr,
78
- const SourceLoc Loc);
79
- Expr *generate (const syntax::NilLiteralExprSyntax &Expr, const SourceLoc Loc);
80
- Expr *generate (const syntax::BooleanLiteralExprSyntax &Expr,
81
- const SourceLoc Loc);
82
- Expr *generate (const syntax::PoundFileExprSyntax &Expr, const SourceLoc Loc);
83
- Expr *generate (const syntax::PoundLineExprSyntax &Expr, const SourceLoc Loc);
84
- Expr *generate (const syntax::PoundColumnExprSyntax &Expr,
85
- const SourceLoc Loc);
86
- Expr *generate (const syntax::PoundFunctionExprSyntax &Expr,
87
- const SourceLoc Loc);
88
- Expr *generate (const syntax::PoundDsohandleExprSyntax &Expr,
89
- const SourceLoc Loc);
90
- Expr *generate (const syntax::UnknownExprSyntax &Expr, const SourceLoc Loc);
85
+ // / Copy a numeric literal value into AST-owned memory, stripping underscores
86
+ // / so the semantic part of the value can be parsed by APInt/APFloat parsers.
87
+ static StringRef copyAndStripUnderscores (StringRef Orig, ASTContext &Context);
91
88
92
89
private:
93
- Expr *generateMagicIdentifierLiteralExpression (
94
- const syntax::TokenSyntax &PoundToken, const SourceLoc Loc);
95
-
96
- static MagicIdentifierLiteralExpr::Kind
97
- getMagicIdentifierLiteralKind (tok Kind);
98
-
99
- public:
100
- // ===--------------------------------------------------------------------===//
101
- // Types.
102
-
103
- TypeRepr *generate (const syntax::TypeSyntax &Type, const SourceLoc Loc);
104
- TypeRepr *generate (const syntax::SomeTypeSyntax &Type, const SourceLoc Loc);
105
- TypeRepr *generate (const syntax::CompositionTypeSyntax &Type,
106
- const SourceLoc Loc);
107
- TypeRepr *generate (const syntax::SimpleTypeIdentifierSyntax &Type,
108
- const SourceLoc Loc);
109
- TypeRepr *generate (const syntax::MemberTypeIdentifierSyntax &Type,
110
- const SourceLoc Loc);
111
- TypeRepr *generate (const syntax::DictionaryTypeSyntax &Type,
112
- const SourceLoc Loc);
113
- TypeRepr *generate (const syntax::ArrayTypeSyntax &Type, const SourceLoc Loc);
114
- TypeRepr *generate (const syntax::TupleTypeSyntax &Type, const SourceLoc Loc);
115
- TypeRepr *generate (const syntax::AttributedTypeSyntax &Type,
116
- const SourceLoc Loc);
117
- TypeRepr *generate (const syntax::FunctionTypeSyntax &Type,
118
- const SourceLoc Loc);
119
- TypeRepr *generate (const syntax::MetatypeTypeSyntax &Type,
120
- const SourceLoc Loc);
121
- TypeRepr *generate (const syntax::OptionalTypeSyntax &Type,
122
- const SourceLoc Loc);
123
- TypeRepr *generate (const syntax::ImplicitlyUnwrappedOptionalTypeSyntax &Type,
124
- const SourceLoc Loc);
125
- TypeRepr *generate (const syntax::ClassRestrictionTypeSyntax &Type,
126
- const SourceLoc Loc);
127
- TypeRepr *generate (const syntax::CodeCompletionTypeSyntax &Type,
128
- const SourceLoc Loc);
129
- TypeRepr *generate (const syntax::UnknownTypeSyntax &Type,
130
- const SourceLoc Loc);
90
+ Expr *generateMagicIdentifierLiteralExpression (syntax::TokenSyntax PoundToken,
91
+ SourceLoc &Loc);
131
92
132
- private:
133
- TupleTypeRepr *
134
- generateTuple (const syntax::TokenSyntax &LParen,
135
- const syntax::TupleTypeElementListSyntax &Elements,
136
- const syntax::TokenSyntax &RParen, const SourceLoc Loc,
137
- bool IsFunction = false );
93
+ TupleTypeRepr *generateTuple (syntax::TokenSyntax LParen,
94
+ syntax::TupleTypeElementListSyntax Elements,
95
+ syntax::TokenSyntax RParen, SourceLoc &Loc,
96
+ bool IsFunction = false );
138
97
139
98
void gatherTypeIdentifierComponents (
140
- const syntax::TypeSyntax & Component, const SourceLoc Loc,
99
+ syntax::TypeSyntax Component, SourceLoc & Loc,
141
100
llvm::SmallVectorImpl<ComponentIdentTypeRepr *> &Components);
142
101
143
102
template <typename T>
144
- TypeRepr *generateSimpleOrMemberIdentifier (const T &Type,
145
- const SourceLoc Loc);
103
+ TypeRepr *generateSimpleOrMemberIdentifier (T Type, SourceLoc &Loc);
146
104
147
105
template <typename T>
148
- ComponentIdentTypeRepr *generateIdentifier (const T &Type,
149
- const SourceLoc Loc);
150
-
151
- public:
152
- // ===--------------------------------------------------------------------===//
153
- // Generics.
154
-
155
- TypeRepr *generate (const syntax::GenericArgumentSyntax &Arg,
156
- const SourceLoc Loc);
157
- llvm::SmallVector<TypeRepr *, 4 >
158
- generate (const syntax::GenericArgumentListSyntax &Args, const SourceLoc Loc);
159
-
160
- GenericParamList *
161
- generate (const syntax::GenericParameterClauseListSyntax &clause,
162
- const SourceLoc Loc);
163
- GenericParamList *generate (const syntax::GenericParameterClauseSyntax &clause,
164
- const SourceLoc Loc);
165
- Optional<RequirementRepr>
166
- generate (const syntax::GenericRequirementSyntax &req, const SourceLoc Loc);
167
- LayoutConstraint generate (const syntax::LayoutConstraintSyntax &req,
168
- const SourceLoc Loc);
169
-
170
- public:
171
- // ===--------------------------------------------------------------------===//
172
- // Utilities.
173
-
174
- // / Copy a numeric literal value into AST-owned memory, stripping underscores
175
- // / so the semantic part of the value can be parsed by APInt/APFloat parsers.
176
- static StringRef copyAndStripUnderscores (StringRef Orig, ASTContext &Context);
106
+ ComponentIdentTypeRepr *generateIdentifier (T Type, SourceLoc &Loc);
177
107
178
- private:
179
108
StringRef copyAndStripUnderscores (StringRef Orig);
180
109
181
- // / Advance \p Loc to the first token of the \p Node.
182
- // / \p Loc must be the leading trivia of the first token in the tree in which
183
- // / \p Node resides.
184
110
static SourceLoc advanceLocBegin (const SourceLoc &Loc,
185
111
const syntax::Syntax &Node);
186
112
113
+ static MagicIdentifierLiteralExpr::Kind getMagicIdentifierLiteralKind (tok Kind);
114
+
187
115
ValueDecl *lookupInScope (DeclName Name);
188
116
189
117
void addToScope (ValueDecl *D, bool diagnoseRedefinitions = true );
@@ -193,13 +121,15 @@ class ASTGen {
193
121
TypeRepr *lookupType (syntax::TypeSyntax Type);
194
122
195
123
public:
196
- void addType (TypeRepr *Type, const SourceLoc Loc);
197
- bool hasType (const SourceLoc Loc) const ;
198
- TypeRepr *getType (const SourceLoc Loc) const ;
124
+ TypeRepr *addType (TypeRepr *Type, const SourceLoc &Loc);
125
+
126
+ bool hasType (const SourceLoc &Loc) const ;
127
+
128
+ TypeRepr *getType (const SourceLoc &Loc) const ;
199
129
200
- void addDeclAttributes (DeclAttributes attrs, const SourceLoc Loc);
130
+ void addDeclAttributes (DeclAttributes attrs, SourceLoc Loc);
201
131
bool hasDeclAttributes (SourceLoc Loc) const ;
202
- DeclAttributes getDeclAttributes (const SourceLoc Loc) const ;
132
+ DeclAttributes getDeclAttributes (SourceLoc Loc) const ;
203
133
};
204
134
} // namespace swift
205
135
0 commit comments