mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:20:31 +00:00
[kernel] Make accept methods generic
Change-Id: I50f3c2b5c09a1266811e1fe5a5b2042c77584e43 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114514 Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
6eed35b60d
commit
4122034ada
20 changed files with 514 additions and 435 deletions
|
@ -392,7 +392,7 @@ class TypeVariableTypeWithContext implements ir.Node {
|
|||
this.type, this.context, this.kind, this.typeDeclaration);
|
||||
|
||||
@override
|
||||
accept(ir.Visitor v) {
|
||||
R accept<R>(ir.Visitor<R> v) {
|
||||
throw new UnsupportedError('TypeVariableTypeWithContext.accept');
|
||||
}
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ class ConstantReference extends ir.TreeNode {
|
|||
}
|
||||
|
||||
@override
|
||||
accept(ir.TreeVisitor v) {
|
||||
R accept<R>(ir.TreeVisitor<R> v) {
|
||||
throw new UnsupportedError("ConstantReference.accept");
|
||||
}
|
||||
|
||||
|
|
|
@ -2503,8 +2503,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
}
|
||||
|
||||
/// Emits a Dart [type] into code.
|
||||
js_ast.Expression _emitType(DartType type) =>
|
||||
type.accept(this) as js_ast.Expression;
|
||||
js_ast.Expression _emitType(DartType type) => type.accept(this);
|
||||
|
||||
js_ast.Expression _emitInvalidNode(Node node, [String message = '']) {
|
||||
if (message.isNotEmpty) message += ' ';
|
||||
|
@ -3085,7 +3084,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
|
||||
js_ast.Statement _visitStatement(Statement s) {
|
||||
if (s == null) return null;
|
||||
var result = s.accept(this) as js_ast.Statement;
|
||||
var result = s.accept(this);
|
||||
// TODO(jmesserly): is the `is! Block` still necessary?
|
||||
if (s is! Block) result.sourceInformation = _nodeStart(s);
|
||||
|
||||
|
@ -3156,7 +3155,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
if (e is ConstantExpression) {
|
||||
return visitConstant(e.constant);
|
||||
}
|
||||
var result = e.accept(this) as js_ast.Expression;
|
||||
var result = e.accept(this);
|
||||
result.sourceInformation ??= _nodeStart(e);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -53,8 +53,7 @@ class NullableInference extends ExpressionVisitor<bool> {
|
|||
void exitFunction(FunctionNode fn) => _variableInference.exitFunction(fn);
|
||||
|
||||
/// Returns true if [expr] can be null.
|
||||
bool isNullable(Expression expr) =>
|
||||
expr != null ? expr.accept(this) as bool : false;
|
||||
bool isNullable(Expression expr) => expr != null ? expr.accept(this) : false;
|
||||
|
||||
@override
|
||||
defaultExpression(Expression node) => true;
|
||||
|
@ -230,7 +229,7 @@ class NullableInference extends ExpressionVisitor<bool> {
|
|||
@override
|
||||
visitConstantExpression(ConstantExpression node) {
|
||||
var c = node.constant;
|
||||
if (c is UnevaluatedConstant) return c.expression.accept(this) as bool;
|
||||
if (c is UnevaluatedConstant) return c.expression.accept(this);
|
||||
if (c is PrimitiveConstant) return c.value == null;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -50,10 +50,10 @@ mixin ControlFlowElement on Expression {
|
|||
}
|
||||
|
||||
@override
|
||||
accept(ExpressionVisitor<Object> v) => v.defaultExpression(this);
|
||||
R accept<R>(ExpressionVisitor<R> v) => v.defaultExpression(this);
|
||||
|
||||
@override
|
||||
accept1(ExpressionVisitor1<Object, Object> v, arg) =>
|
||||
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) =>
|
||||
v.defaultExpression(this, arg);
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ class SpreadElement extends Expression with ControlFlowElement {
|
|||
@override
|
||||
transformChildren(Transformer v) {
|
||||
if (expression != null) {
|
||||
expression = expression.accept(v);
|
||||
expression = expression.accept<TreeNode>(v);
|
||||
expression?.parent = this;
|
||||
}
|
||||
}
|
||||
|
@ -108,15 +108,15 @@ class IfElement extends Expression with ControlFlowElement {
|
|||
@override
|
||||
transformChildren(Transformer v) {
|
||||
if (condition != null) {
|
||||
condition = condition.accept(v);
|
||||
condition = condition.accept<TreeNode>(v);
|
||||
condition?.parent = this;
|
||||
}
|
||||
if (then != null) {
|
||||
then = then.accept(v);
|
||||
then = then.accept<TreeNode>(v);
|
||||
then?.parent = this;
|
||||
}
|
||||
if (otherwise != null) {
|
||||
otherwise = otherwise.accept(v);
|
||||
otherwise = otherwise.accept<TreeNode>(v);
|
||||
otherwise?.parent = this;
|
||||
}
|
||||
}
|
||||
|
@ -148,12 +148,12 @@ class ForElement extends Expression with ControlFlowElement {
|
|||
transformChildren(Transformer v) {
|
||||
transformList(variables, v, this);
|
||||
if (condition != null) {
|
||||
condition = condition.accept(v);
|
||||
condition = condition.accept<TreeNode>(v);
|
||||
condition?.parent = this;
|
||||
}
|
||||
transformList(updates, v, this);
|
||||
if (body != null) {
|
||||
body = body.accept(v);
|
||||
body = body.accept<TreeNode>(v);
|
||||
body?.parent = this;
|
||||
}
|
||||
}
|
||||
|
@ -188,23 +188,23 @@ class ForInElement extends Expression with ControlFlowElement {
|
|||
|
||||
transformChildren(Transformer v) {
|
||||
if (variable != null) {
|
||||
variable = variable.accept(v);
|
||||
variable = variable.accept<TreeNode>(v);
|
||||
variable?.parent = this;
|
||||
}
|
||||
if (iterable != null) {
|
||||
iterable = iterable.accept(v);
|
||||
iterable = iterable.accept<TreeNode>(v);
|
||||
iterable?.parent = this;
|
||||
}
|
||||
if (prologue != null) {
|
||||
prologue = prologue.accept(v);
|
||||
prologue = prologue.accept<TreeNode>(v);
|
||||
prologue?.parent = this;
|
||||
}
|
||||
if (body != null) {
|
||||
body = body.accept(v);
|
||||
body = body.accept<TreeNode>(v);
|
||||
body?.parent = this;
|
||||
}
|
||||
if (problem != null) {
|
||||
problem = problem.accept(v);
|
||||
problem = problem.accept<TreeNode>(v);
|
||||
problem?.parent = this;
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ mixin ControlFlowMapEntry implements MapEntry {
|
|||
}
|
||||
|
||||
@override
|
||||
accept(TreeVisitor<Object> v) => v.defaultTreeNode(this);
|
||||
R accept<R>(TreeVisitor<R> v) => v.defaultTreeNode(this);
|
||||
}
|
||||
|
||||
/// A spread element in a map literal.
|
||||
|
@ -258,7 +258,7 @@ class SpreadMapEntry extends TreeNode with ControlFlowMapEntry {
|
|||
@override
|
||||
transformChildren(Transformer v) {
|
||||
if (expression != null) {
|
||||
expression = expression.accept(v);
|
||||
expression = expression.accept<TreeNode>(v);
|
||||
expression?.parent = this;
|
||||
}
|
||||
}
|
||||
|
@ -286,15 +286,15 @@ class IfMapEntry extends TreeNode with ControlFlowMapEntry {
|
|||
@override
|
||||
transformChildren(Transformer v) {
|
||||
if (condition != null) {
|
||||
condition = condition.accept(v);
|
||||
condition = condition.accept<TreeNode>(v);
|
||||
condition?.parent = this;
|
||||
}
|
||||
if (then != null) {
|
||||
then = then.accept(v);
|
||||
then = then.accept<TreeNode>(v);
|
||||
then?.parent = this;
|
||||
}
|
||||
if (otherwise != null) {
|
||||
otherwise = otherwise.accept(v);
|
||||
otherwise = otherwise.accept<TreeNode>(v);
|
||||
otherwise?.parent = this;
|
||||
}
|
||||
}
|
||||
|
@ -326,12 +326,12 @@ class ForMapEntry extends TreeNode with ControlFlowMapEntry {
|
|||
transformChildren(Transformer v) {
|
||||
transformList(variables, v, this);
|
||||
if (condition != null) {
|
||||
condition = condition.accept(v);
|
||||
condition = condition.accept<TreeNode>(v);
|
||||
condition?.parent = this;
|
||||
}
|
||||
transformList(updates, v, this);
|
||||
if (body != null) {
|
||||
body = body.accept(v);
|
||||
body = body.accept<TreeNode>(v);
|
||||
body?.parent = this;
|
||||
}
|
||||
}
|
||||
|
@ -366,23 +366,23 @@ class ForInMapEntry extends TreeNode with ControlFlowMapEntry {
|
|||
|
||||
transformChildren(Transformer v) {
|
||||
if (variable != null) {
|
||||
variable = variable.accept(v);
|
||||
variable = variable.accept<TreeNode>(v);
|
||||
variable?.parent = this;
|
||||
}
|
||||
if (iterable != null) {
|
||||
iterable = iterable.accept(v);
|
||||
iterable = iterable.accept<TreeNode>(v);
|
||||
iterable?.parent = this;
|
||||
}
|
||||
if (prologue != null) {
|
||||
prologue = prologue.accept(v);
|
||||
prologue = prologue.accept<TreeNode>(v);
|
||||
prologue?.parent = this;
|
||||
}
|
||||
if (body != null) {
|
||||
body = body.accept(v);
|
||||
body = body.accept<TreeNode>(v);
|
||||
body?.parent = this;
|
||||
}
|
||||
if (problem != null) {
|
||||
problem = problem.accept(v);
|
||||
problem = problem.accept<TreeNode>(v);
|
||||
problem?.parent = this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ class ConstantsTransformer extends Transformer {
|
|||
Procedure visitProcedure(Procedure node) {
|
||||
constantEvaluator.withNewEnvironment(() {
|
||||
transformAnnotations(node.annotations, node);
|
||||
node.function = node.function.accept(this)..parent = node;
|
||||
node.function = node.function.accept<TreeNode>(this)..parent = node;
|
||||
});
|
||||
return node;
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ class ConstantsTransformer extends Transformer {
|
|||
constantEvaluator.withNewEnvironment(() {
|
||||
transformAnnotations(node.annotations, node);
|
||||
transformList(node.initializers, this, node);
|
||||
node.function = node.function.accept(this)..parent = node;
|
||||
node.function = node.function.accept<TreeNode>(this)..parent = node;
|
||||
});
|
||||
return node;
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ class ConstantsTransformer extends Transformer {
|
|||
}
|
||||
}
|
||||
if (node.body != null) {
|
||||
node.body = node.body.accept(this)..parent = node;
|
||||
node.body = node.body.accept<TreeNode>(this)..parent = node;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
@ -322,7 +322,8 @@ class ConstantsTransformer extends Transformer {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
node.initializer = node.initializer.accept(this)..parent = node;
|
||||
node.initializer = node.initializer.accept<TreeNode>(this)
|
||||
..parent = node;
|
||||
}
|
||||
}
|
||||
return node;
|
||||
|
@ -344,7 +345,8 @@ class ConstantsTransformer extends Transformer {
|
|||
} else {
|
||||
transformAnnotations(node.annotations, node);
|
||||
if (node.initializer != null) {
|
||||
node.initializer = node.initializer.accept(this)..parent = node;
|
||||
node.initializer = node.initializer.accept<TreeNode>(this)
|
||||
..parent = node;
|
||||
}
|
||||
}
|
||||
return node;
|
||||
|
|
|
@ -737,19 +737,19 @@ class _VariablesDeclaration extends Statement {
|
|||
setParents(declarations, this);
|
||||
}
|
||||
|
||||
accept(v) {
|
||||
unsupported("accept", fileOffset, uri);
|
||||
R accept<R>(v) {
|
||||
throw unsupported("accept", fileOffset, uri);
|
||||
}
|
||||
|
||||
accept1(v, arg) {
|
||||
unsupported("accept1", fileOffset, uri);
|
||||
R accept1<R, A>(v, arg) {
|
||||
throw unsupported("accept1", fileOffset, uri);
|
||||
}
|
||||
|
||||
visitChildren(v) {
|
||||
unsupported("visitChildren", fileOffset, uri);
|
||||
throw unsupported("visitChildren", fileOffset, uri);
|
||||
}
|
||||
|
||||
transformChildren(v) {
|
||||
unsupported("transformChildren", fileOffset, uri);
|
||||
throw unsupported("transformChildren", fileOffset, uri);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,12 @@ class ImplicitFieldType extends DartType {
|
|||
|
||||
ImplicitFieldType(this.member, this.initializerToken);
|
||||
|
||||
accept(DartTypeVisitor<Object> v) {
|
||||
unsupported("accept", member.charOffset, member.fileUri);
|
||||
R accept<R>(DartTypeVisitor<R> v) {
|
||||
throw unsupported("accept", member.charOffset, member.fileUri);
|
||||
}
|
||||
|
||||
accept1(DartTypeVisitor1<Object, Object> v, arg) {
|
||||
unsupported("accept1", member.charOffset, member.fileUri);
|
||||
R accept1<R, A>(DartTypeVisitor1<R, A> v, arg) {
|
||||
throw unsupported("accept1", member.charOffset, member.fileUri);
|
||||
}
|
||||
|
||||
visitChildren(Visitor<Object> v) {
|
||||
|
|
|
@ -21,13 +21,13 @@ class ImplicitTypeArgument extends DartType {
|
|||
get nullability => unsupported("nullability", -1, null);
|
||||
|
||||
@override
|
||||
accept(DartTypeVisitor<Object> v) {
|
||||
unhandled("$runtimeType", "${v.runtimeType}", -1, null);
|
||||
R accept<R>(DartTypeVisitor<R> v) {
|
||||
throw unhandled("$runtimeType", "${v.runtimeType}", -1, null);
|
||||
}
|
||||
|
||||
@override
|
||||
accept1(DartTypeVisitor1<Object, Object> v, arg) {
|
||||
unhandled("$runtimeType", "${v.runtimeType}", -1, null);
|
||||
R accept1<R, A>(DartTypeVisitor1<R, A> v, A arg) {
|
||||
throw unhandled("$runtimeType", "${v.runtimeType}", -1, null);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -1395,17 +1395,17 @@ class SyntheticExpressionJudgment extends Let implements ExpressionJudgment {
|
|||
}
|
||||
|
||||
@override
|
||||
accept(ExpressionVisitor<dynamic> v) {
|
||||
R accept<R>(ExpressionVisitor<R> v) {
|
||||
// This is designed to throw an exception during serialization. It can also
|
||||
// lead to exceptions during transformations, but we have to accept a
|
||||
// [Transformer] as this is used to implement `replaceChild`.
|
||||
if (v is Transformer) return super.accept(v);
|
||||
unsupported("accept", fileOffset, getFileUri(this));
|
||||
throw unsupported("accept", fileOffset, getFileUri(this));
|
||||
}
|
||||
|
||||
@override
|
||||
accept1(ExpressionVisitor1<dynamic, dynamic> v, arg) {
|
||||
unsupported("accept1", fileOffset, getFileUri(this));
|
||||
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) {
|
||||
throw unsupported("accept1", fileOffset, getFileUri(this));
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -1863,9 +1863,9 @@ class _ComplexAssignmentInferenceResult {
|
|||
}
|
||||
|
||||
class _UnfinishedCascade extends Expression {
|
||||
accept(v) => unsupported("accept", -1, null);
|
||||
R accept<R>(v) => unsupported("accept", -1, null);
|
||||
|
||||
accept1(v, arg) => unsupported("accept1", -1, null);
|
||||
R accept1<R, A>(v, arg) => unsupported("accept1", -1, null);
|
||||
|
||||
getStaticType(types) => unsupported("getStaticType", -1, null);
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ class CollectionTransformer extends Transformer {
|
|||
int i = 0;
|
||||
for (; i < elements.length; ++i) {
|
||||
if (elements[i] is ControlFlowElement) break;
|
||||
elements[i] = elements[i].accept(this)..parent = node;
|
||||
elements[i] = elements[i].accept<TreeNode>(this)..parent = node;
|
||||
}
|
||||
|
||||
// If there were only expressions, we are done.
|
||||
|
@ -159,7 +159,8 @@ class CollectionTransformer extends Transformer {
|
|||
} else if (element is ForInElement) {
|
||||
_translateForInElement(element, elementType, isSet, result, body);
|
||||
} else {
|
||||
_addExpressionElement(element.accept(this), isSet, result, body);
|
||||
_addExpressionElement(
|
||||
element.accept<TreeNode>(this), isSet, result, body);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,7 +191,8 @@ class CollectionTransformer extends Transformer {
|
|||
? elseStatements.first
|
||||
: new Block(elseStatements);
|
||||
}
|
||||
body.add(new IfStatement(element.condition.accept(this), thenBody, elseBody)
|
||||
body.add(new IfStatement(
|
||||
element.condition.accept<TreeNode>(this), thenBody, elseBody)
|
||||
..fileOffset = element.fileOffset);
|
||||
}
|
||||
|
||||
|
@ -201,7 +203,7 @@ class CollectionTransformer extends Transformer {
|
|||
Statement loopBody =
|
||||
statements.length == 1 ? statements.first : new Block(statements);
|
||||
ForStatement loop = new ForStatement(element.variables,
|
||||
element.condition?.accept(this), element.updates, loopBody)
|
||||
element.condition?.accept<TreeNode>(this), element.updates, loopBody)
|
||||
..fileOffset = element.fileOffset;
|
||||
transformList(loop.variables, this, loop);
|
||||
transformList(loop.updates, this, loop);
|
||||
|
@ -215,7 +217,7 @@ class CollectionTransformer extends Transformer {
|
|||
if (prologue == null) {
|
||||
statements = <Statement>[];
|
||||
} else {
|
||||
prologue = prologue.accept(this);
|
||||
prologue = prologue.accept<TreeNode>(this);
|
||||
statements =
|
||||
prologue is Block ? prologue.statements : <Statement>[prologue];
|
||||
}
|
||||
|
@ -223,17 +225,17 @@ class CollectionTransformer extends Transformer {
|
|||
Statement loopBody =
|
||||
statements.length == 1 ? statements.first : new Block(statements);
|
||||
if (element.problem != null) {
|
||||
body.add(new ExpressionStatement(element.problem.accept(this)));
|
||||
body.add(new ExpressionStatement(element.problem.accept<TreeNode>(this)));
|
||||
}
|
||||
body.add(new ForInStatement(
|
||||
element.variable, element.iterable.accept(this), loopBody,
|
||||
element.variable, element.iterable.accept<TreeNode>(this), loopBody,
|
||||
isAsync: element.isAsync)
|
||||
..fileOffset = element.fileOffset);
|
||||
}
|
||||
|
||||
void _translateSpreadElement(SpreadElement element, DartType elementType,
|
||||
bool isSet, VariableDeclaration result, List<Statement> body) {
|
||||
Expression value = element.expression.accept(this);
|
||||
Expression value = element.expression.accept<TreeNode>(this);
|
||||
// Null-aware spreads require testing the subexpression's value.
|
||||
VariableDeclaration temp;
|
||||
if (element.isNullAware) {
|
||||
|
@ -314,7 +316,7 @@ class CollectionTransformer extends Transformer {
|
|||
int i = 0;
|
||||
for (; i < node.entries.length; ++i) {
|
||||
if (node.entries[i] is ControlFlowMapEntry) break;
|
||||
node.entries[i] = node.entries[i].accept(this)..parent = node;
|
||||
node.entries[i] = node.entries[i].accept<TreeNode>(this)..parent = node;
|
||||
}
|
||||
|
||||
// If there were no control-flow entries we are done.
|
||||
|
@ -350,7 +352,7 @@ class CollectionTransformer extends Transformer {
|
|||
} else if (entry is ForInMapEntry) {
|
||||
_translateForInEntry(entry, keyType, valueType, result, body);
|
||||
} else {
|
||||
_addNormalEntry(entry.accept(this), result, body);
|
||||
_addNormalEntry(entry.accept<TreeNode>(this), result, body);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -380,7 +382,7 @@ class CollectionTransformer extends Transformer {
|
|||
elseBody.length == 1 ? elseBody.first : new Block(elseBody);
|
||||
}
|
||||
body.add(new IfStatement(
|
||||
entry.condition.accept(this), thenStatement, elseStatement));
|
||||
entry.condition.accept<TreeNode>(this), thenStatement, elseStatement));
|
||||
}
|
||||
|
||||
void _translateForEntry(ForMapEntry entry, DartType keyType,
|
||||
|
@ -389,8 +391,8 @@ class CollectionTransformer extends Transformer {
|
|||
_translateEntry(entry.body, keyType, valueType, result, statements);
|
||||
Statement loopBody =
|
||||
statements.length == 1 ? statements.first : new Block(statements);
|
||||
ForStatement loop = new ForStatement(
|
||||
entry.variables, entry.condition?.accept(this), entry.updates, loopBody)
|
||||
ForStatement loop = new ForStatement(entry.variables,
|
||||
entry.condition?.accept<TreeNode>(this), entry.updates, loopBody)
|
||||
..fileOffset = entry.fileOffset;
|
||||
transformList(loop.variables, this, loop);
|
||||
transformList(loop.updates, this, loop);
|
||||
|
@ -404,7 +406,7 @@ class CollectionTransformer extends Transformer {
|
|||
if (prologue == null) {
|
||||
statements = <Statement>[];
|
||||
} else {
|
||||
prologue = prologue.accept(this);
|
||||
prologue = prologue.accept<TreeNode>(this);
|
||||
statements =
|
||||
prologue is Block ? prologue.statements : <Statement>[prologue];
|
||||
}
|
||||
|
@ -412,17 +414,17 @@ class CollectionTransformer extends Transformer {
|
|||
Statement loopBody =
|
||||
statements.length == 1 ? statements.first : new Block(statements);
|
||||
if (entry.problem != null) {
|
||||
body.add(new ExpressionStatement(entry.problem.accept(this)));
|
||||
body.add(new ExpressionStatement(entry.problem.accept<TreeNode>(this)));
|
||||
}
|
||||
body.add(new ForInStatement(
|
||||
entry.variable, entry.iterable.accept(this), loopBody,
|
||||
entry.variable, entry.iterable.accept<TreeNode>(this), loopBody,
|
||||
isAsync: entry.isAsync)
|
||||
..fileOffset = entry.fileOffset);
|
||||
}
|
||||
|
||||
void _translateSpreadEntry(SpreadMapEntry entry, DartType keyType,
|
||||
DartType valueType, VariableDeclaration result, List<Statement> body) {
|
||||
Expression value = entry.expression.accept(this);
|
||||
Expression value = entry.expression.accept<TreeNode>(this);
|
||||
// Null-aware spreads require testing the subexpression's value.
|
||||
VariableDeclaration temp;
|
||||
if (entry.isNullAware) {
|
||||
|
@ -499,7 +501,7 @@ class CollectionTransformer extends Transformer {
|
|||
int i = 0;
|
||||
for (; i < elements.length; ++i) {
|
||||
if (elements[i] is ControlFlowElement) break;
|
||||
elements[i] = elements[i].accept(this)..parent = node;
|
||||
elements[i] = elements[i].accept<TreeNode>(this)..parent = node;
|
||||
}
|
||||
|
||||
// If there were only expressions, we are done.
|
||||
|
@ -524,7 +526,7 @@ class CollectionTransformer extends Transformer {
|
|||
parts.add(makeLiteral(currentPart));
|
||||
currentPart = null;
|
||||
}
|
||||
Expression spreadExpression = element.expression.accept(this);
|
||||
Expression spreadExpression = element.expression.accept<TreeNode>(this);
|
||||
if (element.isNullAware) {
|
||||
VariableDeclaration temp =
|
||||
new VariableDeclaration(null, initializer: spreadExpression);
|
||||
|
@ -544,10 +546,10 @@ class CollectionTransformer extends Transformer {
|
|||
parts.add(makeLiteral(currentPart));
|
||||
currentPart = null;
|
||||
}
|
||||
Expression condition = element.condition.accept(this);
|
||||
Expression then = makeLiteral([element.then]).accept(this);
|
||||
Expression condition = element.condition.accept<TreeNode>(this);
|
||||
Expression then = makeLiteral([element.then]).accept<TreeNode>(this);
|
||||
Expression otherwise = element.otherwise != null
|
||||
? makeLiteral([element.otherwise]).accept(this)
|
||||
? makeLiteral([element.otherwise]).accept<TreeNode>(this)
|
||||
: makeLiteral([]);
|
||||
parts.add(new ConditionalExpression(
|
||||
condition, then, otherwise, const DynamicType()));
|
||||
|
@ -557,7 +559,7 @@ class CollectionTransformer extends Transformer {
|
|||
element.fileOffset, getFileUri(element));
|
||||
} else {
|
||||
currentPart ??= <Expression>[];
|
||||
currentPart.add(element.accept(this));
|
||||
currentPart.add(element.accept<TreeNode>(this));
|
||||
}
|
||||
}
|
||||
if (currentPart != null) {
|
||||
|
@ -573,7 +575,7 @@ class CollectionTransformer extends Transformer {
|
|||
int i = 0;
|
||||
for (; i < node.entries.length; ++i) {
|
||||
if (node.entries[i] is ControlFlowMapEntry) break;
|
||||
node.entries[i] = node.entries[i].accept(this)..parent = node;
|
||||
node.entries[i] = node.entries[i].accept<TreeNode>(this)..parent = node;
|
||||
}
|
||||
|
||||
// If there were no control-flow entries we are done.
|
||||
|
@ -595,7 +597,7 @@ class CollectionTransformer extends Transformer {
|
|||
parts.add(makeLiteral(currentPart));
|
||||
currentPart = null;
|
||||
}
|
||||
Expression spreadExpression = entry.expression.accept(this);
|
||||
Expression spreadExpression = entry.expression.accept<TreeNode>(this);
|
||||
if (entry.isNullAware) {
|
||||
VariableDeclaration temp =
|
||||
new VariableDeclaration(null, initializer: spreadExpression);
|
||||
|
@ -615,10 +617,10 @@ class CollectionTransformer extends Transformer {
|
|||
parts.add(makeLiteral(currentPart));
|
||||
currentPart = null;
|
||||
}
|
||||
Expression condition = entry.condition.accept(this);
|
||||
Expression then = makeLiteral([entry.then]).accept(this);
|
||||
Expression condition = entry.condition.accept<TreeNode>(this);
|
||||
Expression then = makeLiteral([entry.then]).accept<TreeNode>(this);
|
||||
Expression otherwise = entry.otherwise != null
|
||||
? makeLiteral([entry.otherwise]).accept(this)
|
||||
? makeLiteral([entry.otherwise]).accept<TreeNode>(this)
|
||||
: makeLiteral([]);
|
||||
parts.add(new ConditionalExpression(
|
||||
condition, then, otherwise, const DynamicType()));
|
||||
|
@ -628,7 +630,7 @@ class CollectionTransformer extends Transformer {
|
|||
entry.fileOffset, getFileUri(entry));
|
||||
} else {
|
||||
currentPart ??= <MapEntry>[];
|
||||
currentPart.add(entry.accept(this));
|
||||
currentPart.add(entry.accept<TreeNode>(this));
|
||||
}
|
||||
}
|
||||
if (currentPart != null) {
|
||||
|
|
|
@ -62,7 +62,7 @@ class SetLiteralTransformer extends Transformer {
|
|||
Expression setExp = new VariableGet(setVar);
|
||||
for (int i = node.expressions.length - 1; i >= 0; i--) {
|
||||
// let _ = setVar.add(expression) in rest
|
||||
Expression entry = node.expressions[i].accept(this);
|
||||
Expression entry = node.expressions[i].accept<TreeNode>(this);
|
||||
setExp = new Let(
|
||||
new VariableDeclaration.forValue(new MethodInvocation(
|
||||
new VariableGet(setVar),
|
||||
|
|
|
@ -12,14 +12,15 @@ import 'package:kernel/clone.dart' show CloneVisitor;
|
|||
|
||||
import 'package:kernel/ast.dart'
|
||||
show
|
||||
Class,
|
||||
Component,
|
||||
DartType,
|
||||
Library,
|
||||
Component,
|
||||
Procedure,
|
||||
Class,
|
||||
Supertype,
|
||||
TreeNode,
|
||||
TypeParameter,
|
||||
TypeParameterType,
|
||||
Supertype;
|
||||
TypeParameterType;
|
||||
|
||||
import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
|
||||
|
||||
|
@ -101,7 +102,7 @@ Component createExpressionEvaluationComponent(Procedure procedure) {
|
|||
typeSubstitution: typeSubstitution, typeParams: typeParams);
|
||||
|
||||
for (TypeParameter typeParam in realClass.typeParameters) {
|
||||
fakeClass.typeParameters.add(typeParam.accept(cloner));
|
||||
fakeClass.typeParameters.add(typeParam.accept<TreeNode>(cloner));
|
||||
}
|
||||
|
||||
if (realClass.supertype != null) {
|
||||
|
@ -112,7 +113,7 @@ Component createExpressionEvaluationComponent(Procedure procedure) {
|
|||
}
|
||||
|
||||
// Rebind the type parameters in the procedure.
|
||||
procedure = procedure.accept(cloner);
|
||||
procedure = procedure.accept<TreeNode>(cloner);
|
||||
procedure.parent = fakeClass;
|
||||
fakeClass.procedures.add(procedure);
|
||||
fakeLibrary.classes.add(fakeClass);
|
||||
|
|
|
@ -77,8 +77,8 @@ class UnknownType extends DartType {
|
|||
}
|
||||
|
||||
@override
|
||||
accept(DartTypeVisitor<dynamic> v) {
|
||||
if (v is TypeSchemaVisitor<dynamic>) {
|
||||
R accept<R>(DartTypeVisitor<R> v) {
|
||||
if (v is TypeSchemaVisitor<R>) {
|
||||
return v.visitUnknownType(this);
|
||||
} else {
|
||||
// Note: in principle it seems like this should throw, since any visitor
|
||||
|
@ -91,7 +91,7 @@ class UnknownType extends DartType {
|
|||
}
|
||||
|
||||
@override
|
||||
accept1(DartTypeVisitor1<dynamic, dynamic> v, arg) =>
|
||||
R accept1<R, A>(DartTypeVisitor1<R, A> v, arg) =>
|
||||
v.defaultDartType(this, arg);
|
||||
|
||||
@override
|
||||
|
|
|
@ -1997,6 +1997,7 @@ precisely
|
|||
precision
|
||||
preclude
|
||||
precondition
|
||||
predefined
|
||||
predicate
|
||||
preemptively
|
||||
prefer
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -13,7 +13,7 @@ import 'type_algebra.dart';
|
|||
///
|
||||
/// It is safe to clone members, but cloning a class or library is not
|
||||
/// supported.
|
||||
class CloneVisitor implements TreeVisitor {
|
||||
class CloneVisitor implements TreeVisitor<TreeNode> {
|
||||
final Map<VariableDeclaration, VariableDeclaration> variables =
|
||||
<VariableDeclaration, VariableDeclaration>{};
|
||||
final Map<LabeledStatement, LabeledStatement> labels =
|
||||
|
|
|
@ -94,7 +94,7 @@ class ExpressionLifter extends Transformer {
|
|||
assert(statements.isEmpty);
|
||||
var saved = seenAwait;
|
||||
seenAwait = false;
|
||||
Expression result = expression.accept(this);
|
||||
Expression result = expression.accept<TreeNode>(this);
|
||||
outer.addAll(statements.reversed);
|
||||
statements.clear();
|
||||
seenAwait = seenAwait || saved;
|
||||
|
@ -213,25 +213,25 @@ class ExpressionLifter extends Transformer {
|
|||
|
||||
TreeNode visitPropertySet(PropertySet expr) {
|
||||
return transform(expr, () {
|
||||
expr.value = expr.value.accept(this)..parent = expr;
|
||||
expr.receiver = expr.receiver.accept(this)..parent = expr;
|
||||
expr.value = expr.value.accept<TreeNode>(this)..parent = expr;
|
||||
expr.receiver = expr.receiver.accept<TreeNode>(this)..parent = expr;
|
||||
});
|
||||
}
|
||||
|
||||
TreeNode visitDirectPropertySet(DirectPropertySet expr) {
|
||||
return transform(expr, () {
|
||||
expr.value = expr.value.accept(this)..parent = expr;
|
||||
expr.receiver = expr.receiver.accept(this)..parent = expr;
|
||||
expr.value = expr.value.accept<TreeNode>(this)..parent = expr;
|
||||
expr.receiver = expr.receiver.accept<TreeNode>(this)..parent = expr;
|
||||
});
|
||||
}
|
||||
|
||||
TreeNode visitArguments(Arguments args) {
|
||||
for (var named in args.named.reversed) {
|
||||
named.value = named.value.accept(this)..parent = named;
|
||||
named.value = named.value.accept<TreeNode>(this)..parent = named;
|
||||
}
|
||||
var positional = args.positional;
|
||||
for (var i = positional.length - 1; i >= 0; --i) {
|
||||
positional[i] = positional[i].accept(this)..parent = args;
|
||||
positional[i] = positional[i].accept<TreeNode>(this)..parent = args;
|
||||
}
|
||||
// Returns the arguments, which is assumed at the call sites because they do
|
||||
// not replace the arguments or set parent pointers.
|
||||
|
@ -241,14 +241,14 @@ class ExpressionLifter extends Transformer {
|
|||
TreeNode visitMethodInvocation(MethodInvocation expr) {
|
||||
return transform(expr, () {
|
||||
visitArguments(expr.arguments);
|
||||
expr.receiver = expr.receiver.accept(this)..parent = expr;
|
||||
expr.receiver = expr.receiver.accept<TreeNode>(this)..parent = expr;
|
||||
});
|
||||
}
|
||||
|
||||
TreeNode visitDirectMethodInvocation(DirectMethodInvocation expr) {
|
||||
return transform(expr, () {
|
||||
visitArguments(expr.arguments);
|
||||
expr.receiver = expr.receiver.accept(this)..parent = expr;
|
||||
expr.receiver = expr.receiver.accept<TreeNode>(this)..parent = expr;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ class ExpressionLifter extends Transformer {
|
|||
return transform(expr, () {
|
||||
var expressions = expr.expressions;
|
||||
for (var i = expressions.length - 1; i >= 0; --i) {
|
||||
expressions[i] = expressions[i].accept(this)..parent = expr;
|
||||
expressions[i] = expressions[i].accept<TreeNode>(this)..parent = expr;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -283,7 +283,8 @@ class ExpressionLifter extends Transformer {
|
|||
return transform(expr, () {
|
||||
var expressions = expr.expressions;
|
||||
for (var i = expressions.length - 1; i >= 0; --i) {
|
||||
expressions[i] = expr.expressions[i].accept(this)..parent = expr;
|
||||
expressions[i] = expr.expressions[i].accept<TreeNode>(this)
|
||||
..parent = expr;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -291,8 +292,8 @@ class ExpressionLifter extends Transformer {
|
|||
TreeNode visitMapLiteral(MapLiteral expr) {
|
||||
return transform(expr, () {
|
||||
for (var entry in expr.entries.reversed) {
|
||||
entry.value = entry.value.accept(this)..parent = entry;
|
||||
entry.key = entry.key.accept(this)..parent = entry;
|
||||
entry.value = entry.value.accept<TreeNode>(this)..parent = entry;
|
||||
entry.key = entry.key.accept<TreeNode>(this)..parent = entry;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -304,15 +305,16 @@ class ExpressionLifter extends Transformer {
|
|||
// Right is delimited because it is conditionally evaluated.
|
||||
var rightStatements = <Statement>[];
|
||||
seenAwait = false;
|
||||
expr.right = delimit(() => expr.right.accept(this), rightStatements)
|
||||
..parent = expr;
|
||||
expr.right =
|
||||
delimit(() => expr.right.accept<TreeNode>(this), rightStatements)
|
||||
..parent = expr;
|
||||
var rightAwait = seenAwait;
|
||||
|
||||
if (rightStatements.isEmpty) {
|
||||
// Easy case: right did not emit any statements.
|
||||
seenAwait = shouldName;
|
||||
return transform(expr, () {
|
||||
expr.left = expr.left.accept(this)..parent = expr;
|
||||
expr.left = expr.left.accept<TreeNode>(this)..parent = expr;
|
||||
seenAwait = seenAwait || rightAwait;
|
||||
});
|
||||
}
|
||||
|
@ -350,7 +352,7 @@ class ExpressionLifter extends Transformer {
|
|||
statements.add(new ExpressionStatement(new VariableSet(result, test)));
|
||||
|
||||
seenAwait = false;
|
||||
test.receiver = test.receiver.accept(this)..parent = test;
|
||||
test.receiver = test.receiver.accept<TreeNode>(this)..parent = test;
|
||||
|
||||
++nameIndex;
|
||||
seenAwait = seenAwait || rightAwait;
|
||||
|
@ -364,22 +366,22 @@ class ExpressionLifter extends Transformer {
|
|||
|
||||
var thenStatements = <Statement>[];
|
||||
seenAwait = false;
|
||||
expr.then = delimit(() => expr.then.accept(this), thenStatements)
|
||||
expr.then = delimit(() => expr.then.accept<TreeNode>(this), thenStatements)
|
||||
..parent = expr;
|
||||
var thenAwait = seenAwait;
|
||||
|
||||
var otherwiseStatements = <Statement>[];
|
||||
seenAwait = false;
|
||||
expr.otherwise =
|
||||
delimit(() => expr.otherwise.accept(this), otherwiseStatements)
|
||||
..parent = expr;
|
||||
expr.otherwise = delimit(
|
||||
() => expr.otherwise.accept<TreeNode>(this), otherwiseStatements)
|
||||
..parent = expr;
|
||||
var otherwiseAwait = seenAwait;
|
||||
|
||||
if (thenStatements.isEmpty && otherwiseStatements.isEmpty) {
|
||||
// Easy case: neither then nor otherwise emitted any statements.
|
||||
seenAwait = shouldName;
|
||||
return transform(expr, () {
|
||||
expr.condition = expr.condition.accept(this)..parent = expr;
|
||||
expr.condition = expr.condition.accept<TreeNode>(this)..parent = expr;
|
||||
seenAwait = seenAwait || thenAwait || otherwiseAwait;
|
||||
});
|
||||
}
|
||||
|
@ -403,7 +405,7 @@ class ExpressionLifter extends Transformer {
|
|||
statements.add(branch);
|
||||
|
||||
seenAwait = false;
|
||||
branch.condition = branch.condition.accept(this)..parent = branch;
|
||||
branch.condition = branch.condition.accept<TreeNode>(this)..parent = branch;
|
||||
|
||||
++nameIndex;
|
||||
seenAwait = seenAwait || thenAwait || otherwiseAwait;
|
||||
|
@ -447,7 +449,8 @@ class ExpressionLifter extends Transformer {
|
|||
|
||||
seenAwait = false;
|
||||
var index = nameIndex;
|
||||
arguments.positional[0] = expr.operand.accept(this)..parent = arguments;
|
||||
arguments.positional[0] = expr.operand.accept<TreeNode>(this)
|
||||
..parent = arguments;
|
||||
|
||||
if (shouldName && index + 1 > nameIndex) nameIndex = index + 1;
|
||||
seenAwait = true;
|
||||
|
@ -460,7 +463,7 @@ class ExpressionLifter extends Transformer {
|
|||
}
|
||||
|
||||
TreeNode visitLet(Let expr) {
|
||||
var body = expr.body.accept(this);
|
||||
var body = expr.body.accept<TreeNode>(this);
|
||||
|
||||
VariableDeclaration variable = expr.variable;
|
||||
if (seenAwait) {
|
||||
|
@ -481,7 +484,7 @@ class ExpressionLifter extends Transformer {
|
|||
statements.add(variable);
|
||||
var index = nameIndex;
|
||||
seenAwait = false;
|
||||
variable.initializer = variable.initializer.accept(this)
|
||||
variable.initializer = variable.initializer.accept<TreeNode>(this)
|
||||
..parent = variable;
|
||||
// Temporaries used in the initializer or the body are not live but the
|
||||
// temporary used for the body is.
|
||||
|
@ -494,7 +497,7 @@ class ExpressionLifter extends Transformer {
|
|||
return transform(expr, () {
|
||||
// The body has already been translated.
|
||||
expr.body = body..parent = expr;
|
||||
variable.initializer = variable.initializer.accept(this)
|
||||
variable.initializer = variable.initializer.accept<TreeNode>(this)
|
||||
..parent = variable;
|
||||
});
|
||||
}
|
||||
|
@ -508,10 +511,10 @@ class ExpressionLifter extends Transformer {
|
|||
|
||||
TreeNode visitBlockExpression(BlockExpression expr) {
|
||||
return transform(expr, () {
|
||||
expr.value = expr.value.accept(this)..parent = expr;
|
||||
expr.value = expr.value.accept<TreeNode>(this)..parent = expr;
|
||||
List<Statement> body = <Statement>[];
|
||||
for (Statement stmt in expr.body.statements.reversed) {
|
||||
Statement translation = stmt.accept(this);
|
||||
Statement translation = stmt.accept<TreeNode>(this);
|
||||
if (translation != null) body.add(translation);
|
||||
}
|
||||
expr.body = new Block(body.reversed.toList())..parent = expr;
|
||||
|
|
|
@ -60,11 +60,11 @@ class RecursiveContinuationRewriter extends Transformer {
|
|||
RecursiveContinuationRewriter(this.helper);
|
||||
|
||||
Component rewriteComponent(Component node) {
|
||||
return node.accept(this);
|
||||
return node.accept<TreeNode>(this);
|
||||
}
|
||||
|
||||
Library rewriteLibrary(Library node) {
|
||||
return node.accept(this);
|
||||
return node.accept<TreeNode>(this);
|
||||
}
|
||||
|
||||
visitProcedure(Procedure node) {
|
||||
|
@ -136,7 +136,7 @@ abstract class ContinuationRewriterBase extends RecursiveContinuationRewriter {
|
|||
TreeNode visitTryCatch(TryCatch node) {
|
||||
if (node.body != null) {
|
||||
++currentTryDepth;
|
||||
node.body = node.body.accept(this);
|
||||
node.body = node.body.accept<TreeNode>(this);
|
||||
node.body?.parent = node;
|
||||
--currentTryDepth;
|
||||
}
|
||||
|
@ -150,13 +150,13 @@ abstract class ContinuationRewriterBase extends RecursiveContinuationRewriter {
|
|||
TreeNode visitTryFinally(TryFinally node) {
|
||||
if (node.body != null) {
|
||||
++currentTryDepth;
|
||||
node.body = node.body.accept(this);
|
||||
node.body = node.body.accept<TreeNode>(this);
|
||||
node.body?.parent = node;
|
||||
--currentTryDepth;
|
||||
}
|
||||
if (node.finalizer != null) {
|
||||
++currentCatchDepth;
|
||||
node.finalizer = node.finalizer.accept(this);
|
||||
node.finalizer = node.finalizer.accept<TreeNode>(this);
|
||||
node.finalizer?.parent = node;
|
||||
--currentCatchDepth;
|
||||
}
|
||||
|
@ -234,14 +234,14 @@ class SyncStarFunctionRewriter extends ContinuationRewriterBase {
|
|||
// :iterator.isYieldEach=
|
||||
// and return `true` as long as it did something and `false` when it's done.
|
||||
return new Block(<Statement>[
|
||||
enclosingFunction.body.accept(this),
|
||||
enclosingFunction.body.accept<TreeNode>(this),
|
||||
new ReturnStatement(new BoolLiteral(false))
|
||||
..fileOffset = enclosingFunction.fileEndOffset
|
||||
]);
|
||||
}
|
||||
|
||||
visitYieldStatement(YieldStatement node) {
|
||||
Expression transformedExpression = node.expression.accept(this);
|
||||
Expression transformedExpression = node.expression.accept<TreeNode>(this);
|
||||
|
||||
var statements = <Statement>[];
|
||||
if (node.isYieldStar) {
|
||||
|
@ -399,7 +399,7 @@ abstract class AsyncRewriterBase extends ContinuationRewriterBase {
|
|||
var saved = statements;
|
||||
statements = <Statement>[];
|
||||
for (var statement in stmt.statements) {
|
||||
statement.accept(this);
|
||||
statement.accept<TreeNode>(this);
|
||||
}
|
||||
saved.add(new Block(statements));
|
||||
statements = saved;
|
||||
|
@ -415,7 +415,7 @@ abstract class AsyncRewriterBase extends ContinuationRewriterBase {
|
|||
var saved = statements;
|
||||
statements = <Statement>[];
|
||||
for (var statement in stmt.statements) {
|
||||
statement.accept(this);
|
||||
statement.accept<TreeNode>(this);
|
||||
}
|
||||
saved.add(new Block(statements));
|
||||
statements = saved;
|
||||
|
@ -484,7 +484,7 @@ abstract class AsyncRewriterBase extends ContinuationRewriterBase {
|
|||
Statement visitDelimited(Statement stmt) {
|
||||
var saved = statements;
|
||||
statements = <Statement>[];
|
||||
stmt.accept(this);
|
||||
stmt.accept<TreeNode>(this);
|
||||
Statement result =
|
||||
statements.length == 1 ? statements.first : new Block(statements);
|
||||
statements = saved;
|
||||
|
@ -812,7 +812,7 @@ abstract class AsyncRewriterBase extends ContinuationRewriterBase {
|
|||
iteratorVariable,
|
||||
tryFinally
|
||||
]);
|
||||
block.accept(this);
|
||||
block.accept<TreeNode>(this);
|
||||
} else {
|
||||
stmt.iterable = expressionRewriter.rewrite(stmt.iterable, statements)
|
||||
..parent = stmt;
|
||||
|
@ -893,7 +893,7 @@ abstract class AsyncRewriterBase extends ContinuationRewriterBase {
|
|||
}
|
||||
|
||||
TreeNode visitFunctionDeclaration(FunctionDeclaration stmt) {
|
||||
stmt.function = stmt.function.accept(this)..parent = stmt;
|
||||
stmt.function = stmt.function.accept<TreeNode>(this)..parent = stmt;
|
||||
statements.add(stmt);
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -403,7 +403,7 @@ class _ConstantCallbackVisitor<R> implements ConstantVisitor<R> {
|
|||
/// value for each subnode. The visitor caches the computed values ensuring that
|
||||
/// each subnode is only visited once.
|
||||
class ComputeOnceConstantVisitor<R> implements _ConstantCallback<R> {
|
||||
_ConstantCallbackVisitor _visitor;
|
||||
_ConstantCallbackVisitor<R> _visitor;
|
||||
Map<Constant, R> cache = new LinkedHashMap.identity();
|
||||
|
||||
ComputeOnceConstantVisitor() {
|
||||
|
|
Loading…
Reference in a new issue