Index: pkg/front_end/lib/src/fasta/builder/ast_factory.dart |
diff --git a/pkg/front_end/lib/src/fasta/builder/ast_factory.dart b/pkg/front_end/lib/src/fasta/builder/ast_factory.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..991f1c8602ecb4af35b1530e60688c6ef29ac414 |
--- /dev/null |
+++ b/pkg/front_end/lib/src/fasta/builder/ast_factory.dart |
@@ -0,0 +1,68 @@ |
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
scheglov
2017/03/24 03:19:16
2017
Paul Berry
2017/03/24 14:55:23
Done.
|
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+import 'package:kernel/ast.dart' show DartType, TreeNode; |
+ |
+import 'shadow_ast.dart'; |
+ |
+/// An abstract class containing factory methods that create AST objects. |
+/// |
+/// Itended for use by [BodyBuilder] so that it can create either analyzer or |
+/// kernel ASTs depending on which concrete factory it is connected to. |
+/// |
+/// This class is defined in terms of the builder's shadow AST mixins (which are |
+/// shared between kernel and analyzer shadow AST representations). |
+/// |
+/// Note that the analyzer AST representation closely parallels Dart syntax, |
+/// whereas the kernel AST representation is desugared. The factory methods in |
+/// this class correspond to the full language (prior to desugaring). If |
+/// desugaring is needed, it will be performed by the concrete factory class. |
+/// |
+/// TODO(paulberry): add missing methods. |
+/// |
+/// TODO(paulberry): modify [BodyBuilder] so that it creates all kernel objects |
+/// using this interface. |
+/// |
+/// TODO(paulberry): change the API to use tokens rather than charOffset, since |
+/// that's what analyzer ASTs need. |
scheglov
2017/03/24 03:19:16
Probably not only offsets, but also modifiers like
ahe
2017/03/24 12:00:40
As I'm nervous about accidentally storing tokens i
Paul Berry
2017/03/24 14:55:23
Good point. I'll try this in a follow-up CL.
Paul Berry
2017/03/24 14:55:23
Agreed. Updated the TODO comment.
|
+/// |
+/// TODO(paulberry): in order to interface with analyzer, we'll need to |
+/// shadow-ify [DartType], since analyzer ASTs need to be able to record the |
+/// exact tokens that were used to specify a type. |
+abstract class AstFactory { |
+ /// Creates a statement block. |
+ Block block(List<Statement> statements, int charOffset); |
scheglov
2017/03/24 03:19:16
What is charOffset?
Paul Berry
2017/03/24 14:55:23
The location of the opening `{` token. I'll clean
|
+ |
+ /// Creates an integer literal. |
+ IntLiteral intLiteral(value, int charOffset); |
+ |
+ /// Creates a list literal expression. |
+ /// |
+ /// If the list literal did not have an explicitly declared type argument, |
+ /// [type] should be `null`. |
scheglov
2017/03/24 03:19:16
[type] -> [typeArgument]?
Paul Berry
2017/03/24 14:55:23
Done.
|
+ ListLiteral listLiteral(List<Expression> expressions, DartType typeArgument, |
+ bool isConst, int charOffset); |
+ |
+ /// Creates a null literal expression. |
+ NullLiteral nullLiteral(int charOffset); |
+ |
+ /// Creates a return statement. |
+ Statement returnStatement(Expression expression, int charOffset); |
+ |
+ /// Creates a variable declaration statement declaring one variable. |
+ /// |
+ /// TODO(paulberry): analyzer makes a distinction between a single variable |
+ /// declaration and a variable declaration statement (which can contain |
+ /// multiple variable declarations). Currently this API only makes sense for |
+ /// kernel, which desugars each variable declaration to its own statement. |
ahe
2017/03/24 12:00:40
FYI: The parser does generate a plural event for v
Paul Berry
2017/03/24 14:55:23
Acknowledged.
|
+ /// |
+ /// If the variable declaration did not have an explicitly declared type, |
+ /// [type] should be `null`. |
+ VariableDeclaration variableDeclaration(String name, |
+ {DartType type, |
+ Expression initializer, |
+ int charOffset: TreeNode.noOffset, |
+ bool isFinal: false, |
+ bool isConst: false}); |
+} |