@@ -34,87 +34,130 @@ class ASTGen {
34
34
35
35
Parser &P;
36
36
37
- // FIXME: remove when Syntax can represent all types and ASTGen can handle them
37
+ // FIXME: remove when Syntax can represent all types and ASTGen can handle
38
+ // them
38
39
// / Types that cannot be represented by Syntax or generated by ASTGen.
39
40
llvm::DenseMap<SourceLoc, TypeRepr *> Types;
40
41
41
42
llvm::DenseMap<SourceLoc, DeclAttributes> ParsedDeclAttrs;
42
43
43
44
public:
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);
45
+ ASTGen (ASTContext &Context, Parser &P) : Context(Context), P(P) {}
78
46
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);
47
+ SourceLoc generate (const syntax::TokenSyntax &Tok, const SourceLoc Loc);
87
48
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);
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);
91
69
92
70
private:
93
- Expr *generateMagicIdentifierLiteralExpression (syntax::TokenSyntax PoundToken,
94
- SourceLoc & Loc);
71
+ Expr *generateMagicIdentifierLiteralExpression (
72
+ const syntax::TokenSyntax &PoundToken, const SourceLoc Loc);
95
73
96
- TupleTypeRepr *generateTuple (syntax::TokenSyntax LParen,
97
- syntax::TupleTypeElementListSyntax Elements,
98
- syntax::TokenSyntax RParen, SourceLoc &Loc,
99
- bool IsFunction = false );
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 );
100
112
101
113
void gatherTypeIdentifierComponents (
102
- syntax::TypeSyntax Component, SourceLoc & Loc,
114
+ const syntax::TypeSyntax & Component, const SourceLoc Loc,
103
115
llvm::SmallVectorImpl<ComponentIdentTypeRepr *> &Components);
104
116
105
117
template <typename T>
106
- TypeRepr *generateSimpleOrMemberIdentifier (T Type, SourceLoc &Loc);
118
+ TypeRepr *generateSimpleOrMemberIdentifier (const T &Type,
119
+ const SourceLoc Loc);
107
120
108
121
template <typename T>
109
- ComponentIdentTypeRepr *generateIdentifier (T Type, SourceLoc &Loc);
122
+ ComponentIdentTypeRepr *generateIdentifier (const T &Type,
123
+ const SourceLoc Loc);
110
124
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:
111
153
StringRef copyAndStripUnderscores (StringRef Orig);
112
154
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.
113
158
static SourceLoc advanceLocBegin (const SourceLoc &Loc,
114
159
const syntax::Syntax &Node);
115
160
116
- static MagicIdentifierLiteralExpr::Kind getMagicIdentifierLiteralKind (tok Kind);
117
-
118
161
ValueDecl *lookupInScope (DeclName Name);
119
162
120
163
void addToScope (ValueDecl *D, bool diagnoseRedefinitions = true );
@@ -124,15 +167,13 @@ class ASTGen {
124
167
TypeRepr *lookupType (syntax::TypeSyntax Type);
125
168
126
169
public:
127
- TypeRepr *addType (TypeRepr *Type, const SourceLoc &Loc);
128
-
129
- bool hasType (const SourceLoc &Loc) const ;
130
-
131
- TypeRepr *getType (const SourceLoc &Loc) const ;
170
+ void addType (TypeRepr *Type, const SourceLoc Loc);
171
+ bool hasType (const SourceLoc Loc) const ;
172
+ TypeRepr *getType (const SourceLoc Loc) const ;
132
173
133
- void addDeclAttributes (DeclAttributes attrs, SourceLoc Loc);
174
+ void addDeclAttributes (DeclAttributes attrs, const SourceLoc Loc);
134
175
bool hasDeclAttributes (SourceLoc Loc) const ;
135
- DeclAttributes getDeclAttributes (SourceLoc Loc) const ;
176
+ DeclAttributes getDeclAttributes (const SourceLoc Loc) const ;
136
177
};
137
178
} // namespace swift
138
179
0 commit comments