Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: pkg/front_end/lib/src/fasta/builder/ast_factory.dart

Issue 2904673003: Remove AstFactory from the front end. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:front_end/src/fasta/scanner.dart' show Token;
6 import 'package:front_end/src/fasta/type_inference/type_promotion.dart';
7 import 'package:kernel/ast.dart';
8
9 /// An abstract class containing factory methods that create AST objects.
10 ///
11 /// Itended for use by [BodyBuilder] so that it can create either analyzer or
12 /// kernel ASTs depending on which concrete factory it is connected to.
13 ///
14 /// This class is defined in terms of the builder's shadow AST mixins (which are
15 /// shared between kernel and analyzer shadow AST representations).
16 ///
17 /// Note that the analyzer AST representation closely parallels Dart syntax,
18 /// whereas the kernel AST representation is desugared. The factory methods in
19 /// this class correspond to the full language (prior to desugaring). If
20 /// desugaring is needed, it will be performed by the concrete factory class.
21 ///
22 /// TODO(paulberry): add missing methods.
23 ///
24 /// TODO(paulberry): modify [BodyBuilder] so that it creates all kernel objects
25 /// using this interface.
26 ///
27 /// TODO(paulberry): change the API to use tokens rather than charOffset, since
28 /// that's what analyzer ASTs need. Note that analyzer needs multiple tokens
29 /// for many AST constructs, not just one. Note also that for kernel codegen
30 /// we want to be very careful not to keep tokens around too long, so consider
31 /// having a `toLocation` method on AstFactory that changes tokens to an
32 /// abstract type (`int` for kernel, `Token` for analyzer).
33 ///
34 /// TODO(paulberry): in order to interface with analyzer, we'll need to
35 /// shadow-ify [DartType], since analyzer ASTs need to be able to record the
36 /// exact tokens that were used to specify a type.
37 abstract class AstFactory<V> {
38 /// Creates an [Arguments] data structure.
39 Arguments arguments(List<Expression> positional,
40 {List<DartType> types, List<NamedExpression> named});
41
42 /// Creates an `as` expression.
43 AsExpression asExpression(Expression operand, Token operator, DartType type);
44
45 /// Creates an `await` expression.
46 AwaitExpression awaitExpression(Token keyword, Expression operand);
47
48 /// Creates a statement block.
49 Block block(List<Statement> statements, Token beginToken);
50
51 /// Creates a boolean literal.
52 BoolLiteral boolLiteral(bool value, Token token);
53
54 /// Creates a conditional expression.
55 ConditionalExpression conditionalExpression(Expression condition,
56 Expression thenExpression, Expression elseExpression);
57
58 /// Creates a constructor invocation.
59 ConstructorInvocation constructorInvocation(
60 Constructor target, Arguments arguments,
61 {bool isConst: false});
62
63 /// Creates a direct method invocation.
64 DirectMethodInvocation directMethodInvocation(
65 Expression receiver, Procedure target, Arguments arguments);
66
67 /// Creates a direct property get.
68 DirectPropertyGet directPropertyGet(Expression receiver, Member target);
69
70 /// Creates a direct property get.
71 DirectPropertySet directPropertySet(
72 Expression receiver, Member target, Expression value);
73
74 /// Creates a double literal.
75 DoubleLiteral doubleLiteral(double value, Token token);
76
77 /// Creates an expression statement.
78 ExpressionStatement expressionStatement(Expression expression);
79
80 /// Creates a function expression.
81 FunctionExpression functionExpression(FunctionNode function, Token token);
82
83 /// Creates an `if` statement.
84 Statement ifStatement(
85 Expression condition, Statement thenPart, Statement elsePart);
86
87 /// Creates an integer literal.
88 IntLiteral intLiteral(int value, Token token);
89
90 /// Creates an `is` expression.
91 Expression isExpression(
92 Expression expression, DartType type, Token token, bool isInverted);
93
94 /// Creates a list literal expression.
95 ///
96 /// If the list literal did not have an explicitly declared type argument,
97 /// [typeArgument] should be `null`.
98 ListLiteral listLiteral(List<Expression> expressions, DartType typeArgument,
99 bool isConst, Token token);
100
101 /// Creates a logical expression in for of `x && y` or `x || y`.
102 LogicalExpression logicalExpression(
103 Expression left, String operator, Expression right);
104
105 /// Creates a map literal expression.
106 ///
107 /// If the map literal did not have an explicitly declared type argument,
108 /// [keyType] and [valueType] should be `null`.
109 MapLiteral mapLiteral(
110 Token beginToken, Token constKeyword, List<MapEntry> entries,
111 {DartType keyType: const DynamicType(),
112 DartType valueType: const DynamicType()});
113
114 /// Creates a method invocation of form `x.foo(y)`.
115 MethodInvocation methodInvocation(
116 Expression receiver, Name name, Arguments arguments,
117 [Procedure interfaceTarget]);
118
119 /// Create an expression of form `!x`.
120 Not not(Token token, Expression operand);
121
122 /// Creates a null literal expression.
123 NullLiteral nullLiteral(Token token);
124
125 /// Creates a read of a property.
126 PropertyGet propertyGet(Expression receiver, Name name,
127 [Member interfaceTarget]);
128
129 /// Creates a write of a property.
130 PropertySet propertySet(Expression receiver, Name name, Expression value,
131 [Member interfaceTarget]);
132
133 /// Create a `rethrow` expression.
134 Rethrow rethrowExpression(Token keyword);
135
136 /// Creates a return statement.
137 Statement returnStatement(Expression expression, Token token);
138
139 /// Updates an [Arguments] data structure with the given generic [types].
140 /// Should only be used when [types] were specified explicitly.
141 void setExplicitArgumentTypes(Arguments arguments, List<DartType> types);
142
143 /// Creates a read of a static variable.
144 StaticGet staticGet(Member readTarget, Token token);
145
146 /// Creates a static invocation.
147 StaticInvocation staticInvocation(Procedure target, Arguments arguments,
148 {bool isConst: false});
149
150 /// Creates a string concatenation.
151 StringConcatenation stringConcatenation(
152 List<Expression> expressions, Token token);
153
154 /// Creates a string literal.
155 StringLiteral stringLiteral(String value, Token token);
156
157 /// Creates a super method invocation.
158 SuperMethodInvocation superMethodInvocation(
159 Token beginToken, Name name, Arguments arguments,
160 [Procedure interfaceTarget]);
161
162 /// Create an expression of form `super.field`.
163 SuperPropertyGet superPropertyGet(Name name, [Member interfaceTarget]);
164
165 /// Create an expression of form `#foo.bar`.
166 SymbolLiteral symbolLiteral(Token hashToken, String value);
167
168 /// Create an expression of form `this`.
169 ThisExpression thisExpression(Token keyword);
170
171 /// Create a `throw` expression.
172 Throw throwExpression(Token keyword, Expression expression);
173
174 /// Create a type literal expression.
175 TypeLiteral typeLiteral(DartType type);
176
177 /// Creates a variable declaration statement declaring one variable.
178 ///
179 /// TODO(paulberry): analyzer makes a distinction between a single variable
180 /// declaration and a variable declaration statement (which can contain
181 /// multiple variable declarations). Currently this API only makes sense for
182 /// kernel, which desugars each variable declaration to its own statement.
183 ///
184 /// If the variable declaration did not have an explicitly declared type,
185 /// [type] should be `null`.
186 VariableDeclaration variableDeclaration(
187 String name, Token token, int functionNestingLevel,
188 {DartType type,
189 Expression initializer,
190 Token equalsToken,
191 bool isFinal: false,
192 bool isConst: false,
193 bool isLocalFunction: false});
194
195 /// Creates a read of a local variable.
196 VariableGet variableGet(VariableDeclaration variable,
197 TypePromotionFact<V> fact, TypePromotionScope scope, Token token);
198
199 /// Creates a write of a local variable.
200 VariableSet variableSet(VariableDeclaration variable, Expression value);
201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698