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