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

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

Issue 2841863002: Change accessors and AstFactory to use tokens rather than file offsets. (Closed)
Patch Set: Created 3 years, 8 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
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:front_end/src/fasta/scanner/token.dart' show Token;
ahe 2017/04/26 08:34:36 If you import package:front_end/src/fasta/scanner.
Paul Berry 2017/04/26 20:20:52 Done.
5 import 'package:kernel/ast.dart'; 6 import 'package:kernel/ast.dart';
6 7
7 /// An abstract class containing factory methods that create AST objects. 8 /// An abstract class containing factory methods that create AST objects.
8 /// 9 ///
9 /// Itended for use by [BodyBuilder] so that it can create either analyzer or 10 /// Itended for use by [BodyBuilder] so that it can create either analyzer or
10 /// kernel ASTs depending on which concrete factory it is connected to. 11 /// kernel ASTs depending on which concrete factory it is connected to.
11 /// 12 ///
12 /// This class is defined in terms of the builder's shadow AST mixins (which are 13 /// This class is defined in terms of the builder's shadow AST mixins (which are
13 /// shared between kernel and analyzer shadow AST representations). 14 /// shared between kernel and analyzer shadow AST representations).
14 /// 15 ///
(...skipping 12 matching lines...) Expand all
27 /// for many AST constructs, not just one. Note also that for kernel codegen 28 /// for many AST constructs, not just one. Note also that for kernel codegen
28 /// we want to be very careful not to keep tokens around too long, so consider 29 /// we want to be very careful not to keep tokens around too long, so consider
29 /// having a `toLocation` method on AstFactory that changes tokens to an 30 /// having a `toLocation` method on AstFactory that changes tokens to an
30 /// abstract type (`int` for kernel, `Token` for analyzer). 31 /// abstract type (`int` for kernel, `Token` for analyzer).
31 /// 32 ///
32 /// TODO(paulberry): in order to interface with analyzer, we'll need to 33 /// TODO(paulberry): in order to interface with analyzer, we'll need to
33 /// shadow-ify [DartType], since analyzer ASTs need to be able to record the 34 /// shadow-ify [DartType], since analyzer ASTs need to be able to record the
34 /// exact tokens that were used to specify a type. 35 /// exact tokens that were used to specify a type.
35 abstract class AstFactory { 36 abstract class AstFactory {
36 /// Creates a statement block. 37 /// Creates a statement block.
37 Block block(List<Statement> statements, int charOffset); 38 Block block(List<Statement> statements, Token beginToken);
38 39
39 /// Creates a field. 40 /// Creates a field.
40 Field field(Name name, int charOffset, {String fileUri}); 41 Field field(Name name, int charOffset, {String fileUri});
Paul Berry 2017/04/25 12:37:52 Note: I realized as I was going through this exerc
41 42
42 /// Creates an integer literal. 43 /// Creates an integer literal.
43 IntLiteral intLiteral(value, int charOffset); 44 IntLiteral intLiteral(value, Token token);
44 45
45 /// Creates a list literal expression. 46 /// Creates a list literal expression.
46 /// 47 ///
47 /// If the list literal did not have an explicitly declared type argument, 48 /// If the list literal did not have an explicitly declared type argument,
48 /// [typeArgument] should be `null`. 49 /// [typeArgument] should be `null`.
49 ListLiteral listLiteral(List<Expression> expressions, DartType typeArgument, 50 ListLiteral listLiteral(List<Expression> expressions, DartType typeArgument,
50 bool isConst, int charOffset); 51 bool isConst, Token token);
51 52
52 /// Creates a null literal expression. 53 /// Creates a null literal expression.
53 NullLiteral nullLiteral(int charOffset); 54 NullLiteral nullLiteral(Token token);
54 55
55 /// Creates a return statement. 56 /// Creates a return statement.
56 Statement returnStatement(Expression expression, int charOffset); 57 Statement returnStatement(Expression expression, Token token);
57 58
58 /// Creates a read of a static variable. 59 /// Creates a read of a static variable.
59 StaticGet staticGet(Member readTarget, int offset); 60 StaticGet staticGet(Member readTarget, Token token);
60 61
61 /// Creates a variable declaration statement declaring one variable. 62 /// Creates a variable declaration statement declaring one variable.
62 /// 63 ///
63 /// TODO(paulberry): analyzer makes a distinction between a single variable 64 /// TODO(paulberry): analyzer makes a distinction between a single variable
64 /// declaration and a variable declaration statement (which can contain 65 /// declaration and a variable declaration statement (which can contain
65 /// multiple variable declarations). Currently this API only makes sense for 66 /// multiple variable declarations). Currently this API only makes sense for
66 /// kernel, which desugars each variable declaration to its own statement. 67 /// kernel, which desugars each variable declaration to its own statement.
67 /// 68 ///
68 /// If the variable declaration did not have an explicitly declared type, 69 /// If the variable declaration did not have an explicitly declared type,
69 /// [type] should be `null`. 70 /// [type] should be `null`.
70 VariableDeclaration variableDeclaration(String name, int charOffset, 71 VariableDeclaration variableDeclaration(String name, Token token,
71 {DartType type, 72 {DartType type,
72 Expression initializer, 73 Expression initializer,
73 int equalsCharOffset = TreeNode.noOffset, 74 Token equalsToken,
74 bool isFinal: false, 75 bool isFinal: false,
75 bool isConst: false}); 76 bool isConst: false});
76 } 77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698