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