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

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: Address code review comments, rebase 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
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/body_builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.dart' show Token;
5 import 'package:front_end/src/fasta/type_inference/type_promotion.dart'; 6 import 'package:front_end/src/fasta/type_inference/type_promotion.dart';
6 import 'package:kernel/ast.dart'; 7 import 'package:kernel/ast.dart';
7 8
8 /// An abstract class containing factory methods that create AST objects. 9 /// An abstract class containing factory methods that create AST objects.
9 /// 10 ///
10 /// Itended for use by [BodyBuilder] so that it can create either analyzer or 11 /// Itended for use by [BodyBuilder] so that it can create either analyzer or
11 /// kernel ASTs depending on which concrete factory it is connected to. 12 /// kernel ASTs depending on which concrete factory it is connected to.
12 /// 13 ///
13 /// This class is defined in terms of the builder's shadow AST mixins (which are 14 /// This class is defined in terms of the builder's shadow AST mixins (which are
14 /// shared between kernel and analyzer shadow AST representations). 15 /// shared between kernel and analyzer shadow AST representations).
(...skipping 13 matching lines...) Expand all
28 /// for many AST constructs, not just one. Note also that for kernel codegen 29 /// for many AST constructs, not just one. Note also that for kernel codegen
29 /// we want to be very careful not to keep tokens around too long, so consider 30 /// we want to be very careful not to keep tokens around too long, so consider
30 /// having a `toLocation` method on AstFactory that changes tokens to an 31 /// having a `toLocation` method on AstFactory that changes tokens to an
31 /// abstract type (`int` for kernel, `Token` for analyzer). 32 /// abstract type (`int` for kernel, `Token` for analyzer).
32 /// 33 ///
33 /// TODO(paulberry): in order to interface with analyzer, we'll need to 34 /// TODO(paulberry): in order to interface with analyzer, we'll need to
34 /// shadow-ify [DartType], since analyzer ASTs need to be able to record the 35 /// shadow-ify [DartType], since analyzer ASTs need to be able to record the
35 /// exact tokens that were used to specify a type. 36 /// exact tokens that were used to specify a type.
36 abstract class AstFactory<V> { 37 abstract class AstFactory<V> {
37 /// Creates a statement block. 38 /// Creates a statement block.
38 Block block(List<Statement> statements, int charOffset); 39 Block block(List<Statement> statements, Token beginToken);
39 40
40 /// Creates an expression statement. 41 /// Creates an expression statement.
41 ExpressionStatement expressionStatement(Expression expression); 42 ExpressionStatement expressionStatement(Expression expression);
42 43
43 /// Creates a field. 44 /// Creates a field.
44 Field field(Name name, int charOffset, {String fileUri}); 45 Field field(Name name, int charOffset, {String fileUri});
45 46
46 /// Creates a function expression. 47 /// Creates a function expression.
47 FunctionExpression functionExpression(FunctionNode function, int charOffset); 48 FunctionExpression functionExpression(FunctionNode function, Token token);
48 49
49 /// Creates an `if` statement. 50 /// Creates an `if` statement.
50 Statement ifStatement( 51 Statement ifStatement(
51 Expression condition, Statement thenPart, Statement elsePart); 52 Expression condition, Statement thenPart, Statement elsePart);
52 53
53 /// Creates an integer literal. 54 /// Creates an integer literal.
54 IntLiteral intLiteral(value, int charOffset); 55 IntLiteral intLiteral(value, Token token);
55 56
56 /// Creates an `is` expression. 57 /// Creates an `is` expression.
57 Expression isExpression( 58 Expression isExpression(
58 Expression expression, DartType type, int charOffset, bool isInverted); 59 Expression expression, DartType type, Token token, bool isInverted);
59 60
60 /// Creates a list literal expression. 61 /// Creates a list literal expression.
61 /// 62 ///
62 /// If the list literal did not have an explicitly declared type argument, 63 /// If the list literal did not have an explicitly declared type argument,
63 /// [typeArgument] should be `null`. 64 /// [typeArgument] should be `null`.
64 ListLiteral listLiteral(List<Expression> expressions, DartType typeArgument, 65 ListLiteral listLiteral(List<Expression> expressions, DartType typeArgument,
65 bool isConst, int charOffset); 66 bool isConst, Token token);
66 67
67 /// Creates a null literal expression. 68 /// Creates a null literal expression.
68 NullLiteral nullLiteral(int charOffset); 69 NullLiteral nullLiteral(Token token);
69 70
70 /// Creates a return statement. 71 /// Creates a return statement.
71 Statement returnStatement(Expression expression, int charOffset); 72 Statement returnStatement(Expression expression, Token token);
72 73
73 /// Creates a read of a static variable. 74 /// Creates a read of a static variable.
74 StaticGet staticGet(Member readTarget, int offset); 75 StaticGet staticGet(Member readTarget, Token token);
75 76
76 /// Creates a variable declaration statement declaring one variable. 77 /// Creates a variable declaration statement declaring one variable.
77 /// 78 ///
78 /// TODO(paulberry): analyzer makes a distinction between a single variable 79 /// TODO(paulberry): analyzer makes a distinction between a single variable
79 /// declaration and a variable declaration statement (which can contain 80 /// declaration and a variable declaration statement (which can contain
80 /// multiple variable declarations). Currently this API only makes sense for 81 /// multiple variable declarations). Currently this API only makes sense for
81 /// kernel, which desugars each variable declaration to its own statement. 82 /// kernel, which desugars each variable declaration to its own statement.
82 /// 83 ///
83 /// If the variable declaration did not have an explicitly declared type, 84 /// If the variable declaration did not have an explicitly declared type,
84 /// [type] should be `null`. 85 /// [type] should be `null`.
85 VariableDeclaration variableDeclaration( 86 VariableDeclaration variableDeclaration(
86 String name, int charOffset, int functionNestingLevel, 87 String name, Token token, int functionNestingLevel,
87 {DartType type, 88 {DartType type,
88 Expression initializer, 89 Expression initializer,
89 int equalsCharOffset = TreeNode.noOffset, 90 Token equalsToken,
90 bool isFinal: false, 91 bool isFinal: false,
91 bool isConst: false}); 92 bool isConst: false});
92 93
93 /// Creates a read of a local variable. 94 /// Creates a read of a local variable.
94 variableGet(VariableDeclaration variable, TypePromotionFact<V> fact, 95 variableGet(VariableDeclaration variable, TypePromotionFact<V> fact,
95 TypePromotionScope scope, int charOffset); 96 TypePromotionScope scope, Token token);
96 } 97 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/body_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698