OLD | NEW |
---|---|
(Empty) | |
1 // 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.
| |
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:kernel/ast.dart' show DartType, TreeNode; | |
6 | |
7 import 'shadow_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. | |
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.
| |
29 /// | |
30 /// TODO(paulberry): in order to interface with analyzer, we'll need to | |
31 /// shadow-ify [DartType], since analyzer ASTs need to be able to record the | |
32 /// exact tokens that were used to specify a type. | |
33 abstract class AstFactory { | |
34 /// Creates a statement block. | |
35 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
| |
36 | |
37 /// Creates an integer literal. | |
38 IntLiteral intLiteral(value, int charOffset); | |
39 | |
40 /// Creates a list literal expression. | |
41 /// | |
42 /// If the list literal did not have an explicitly declared type argument, | |
43 /// [type] should be `null`. | |
scheglov
2017/03/24 03:19:16
[type] -> [typeArgument]?
Paul Berry
2017/03/24 14:55:23
Done.
| |
44 ListLiteral listLiteral(List<Expression> expressions, DartType typeArgument, | |
45 bool isConst, int charOffset); | |
46 | |
47 /// Creates a null literal expression. | |
48 NullLiteral nullLiteral(int charOffset); | |
49 | |
50 /// Creates a return statement. | |
51 Statement returnStatement(Expression expression, int charOffset); | |
52 | |
53 /// Creates a variable declaration statement declaring one variable. | |
54 /// | |
55 /// TODO(paulberry): analyzer makes a distinction between a single variable | |
56 /// declaration and a variable declaration statement (which can contain | |
57 /// multiple variable declarations). Currently this API only makes sense for | |
58 /// 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.
| |
59 /// | |
60 /// If the variable declaration did not have an explicitly declared type, | |
61 /// [type] should be `null`. | |
62 VariableDeclaration variableDeclaration(String name, | |
63 {DartType type, | |
64 Expression initializer, | |
65 int charOffset: TreeNode.noOffset, | |
66 bool isFinal: false, | |
67 bool isConst: false}); | |
68 } | |
OLD | NEW |