Chromium Code Reviews| Index: pkg/analyzer2dart/lib/src/cps_generator.dart |
| diff --git a/pkg/analyzer2dart/lib/src/cps_generator.dart b/pkg/analyzer2dart/lib/src/cps_generator.dart |
| index c81513aec444dcd9c6952b0dfda90ead040c827b..02f639a7c630f89d5f49f8a63a0a76faeeaf3087 100644 |
| --- a/pkg/analyzer2dart/lib/src/cps_generator.dart |
| +++ b/pkg/analyzer2dart/lib/src/cps_generator.dart |
| @@ -30,6 +30,14 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| Source get currentSource => element.source; |
| + ir.Node visit(AstNode node) => node != null ? node.accept(this) : null; |
|
sigurdm
2014/10/20 10:48:32
This is not what I expect "visit" to do - it shoul
Johnni Winther
2014/10/20 12:25:13
Done.
|
| + |
| + /// Returns a closure that takes an [IrBuilder] and visits [node] in its |
| + /// context. |
| + build(AstNode node) { |
|
sigurdm
2014/10/20 10:48:32
I don't really like the name - the function does n
Johnni Winther
2014/10/20 12:25:13
Done.
|
| + return (IrBuilder builder) => withBuilder(builder, () => visit(node)); |
| + } |
| + |
| @override |
| ir.FunctionDefinition visitFunctionDeclaration(FunctionDeclaration node) { |
| analyzer.FunctionElement function = node.element; |
| @@ -48,7 +56,7 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| }); |
| // Visit the body directly to avoid processing the signature as |
| // expressions. |
| - node.functionExpression.body.accept(this); |
| + visit(node.functionExpression.body); |
| return irBuilder.buildFunctionDefinition(element, const []); |
| }); |
| } |
| @@ -56,7 +64,7 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| List<ir.Definition> visitArguments(ArgumentList argumentList) { |
| List<ir.Definition> arguments = <ir.Definition>[]; |
| for (Expression argument in argumentList.arguments) { |
| - ir.Definition value = argument.accept(this); |
| + ir.Definition value = visit(argument); |
| if (value == null) { |
| giveUp(argument, |
| 'Unsupported argument: $argument (${argument.runtimeType}).'); |
| @@ -70,7 +78,7 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| ir.Primitive visitDynamicInvocation(MethodInvocation node, |
| AccessSemantics semantics) { |
| // TODO(johnniwinther): Handle implicit `this`. |
| - ir.Primitive receiver = semantics.target.accept(this); |
| + ir.Primitive receiver = visit(semantics.target); |
| List<ir.Definition> arguments = visitArguments(node.argumentList); |
| return irBuilder.buildDynamicInvocation( |
| receiver, |
| @@ -131,11 +139,7 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| @override |
| visitReturnStatement(ReturnStatement node) { |
| - if (node.expression != null) { |
| - irBuilder.buildReturn(node.expression.accept(this)); |
| - } else { |
| - irBuilder.buildReturn(); |
| - } |
| + irBuilder.buildReturn(visit(node.expression)); |
| } |
| @override |
| @@ -151,10 +155,7 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| @override |
| visitVariableDeclaration(VariableDeclaration node) { |
| // TODO(johnniwinther): Handle constant local variables. |
| - ir.Node initialValue; |
| - if (node.initializer != null) { |
| - initialValue = node.initializer.accept(this); |
| - } |
| + ir.Node initialValue = visit(node.initializer); |
| irBuilder.declareLocalVariable( |
| converter.convertElement(node.element), |
| initialValue: initialValue); |
| @@ -170,7 +171,7 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| @override |
| ir.Node visitDynamicAccess(AstNode node, AccessSemantics semantics) { |
| // TODO(johnniwinther): Handle implicit `this`. |
| - ir.Primitive receiver = semantics.target.accept(this); |
| + ir.Primitive receiver = visit(semantics.target); |
| return irBuilder.buildDynamicGet(receiver, |
| new Selector.getter(semantics.identifier.name, |
| converter.convertElement(element.library))); |
| @@ -190,20 +191,18 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| ir.Primitive handleBinaryExpression(BinaryExpression node, |
| String op) { |
| - ir.Primitive left = node.leftOperand.accept(this); |
| - ir.Primitive right = node.rightOperand.accept(this); |
| + ir.Primitive left = visit(node.leftOperand); |
| + ir.Primitive right = visit(node.rightOperand); |
| Selector selector = new Selector.binaryOperator(op); |
| return irBuilder.buildDynamicInvocation( |
| left, selector, <ir.Definition>[right]); |
| } |
| ir.Node handleLazyOperator(BinaryExpression node, {bool isLazyOr: false}) { |
| - ir.Primitive left = node.leftOperand.accept(this); |
| - ir.Primitive buildRightValue(IrBuilder builder) { |
| - return withBuilder(builder, () => node.rightOperand.accept(this)); |
| - } |
| return irBuilder.buildLogicalOperator( |
| - left, buildRightValue, isLazyOr: isLazyOr); |
| + visit(node.leftOperand), |
| + build(node.rightOperand), |
| + isLazyOr: isLazyOr); |
| } |
| @override |
| @@ -223,19 +222,18 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| } |
| @override |
| - visitIfStatement(IfStatement node) { |
| - ir.Primitive condition = node.condition.accept(this); |
| - |
| - void buildThenPart(IrBuilder thenBuilder) { |
| - withBuilder(thenBuilder, () => node.thenStatement.accept(this)); |
| - } |
| - |
| - void buildElsePart(IrBuilder elseBuilder) { |
| - if (node.elseStatement != null) { |
| - withBuilder(elseBuilder, () => node.elseStatement.accept(this)); |
| - } |
| - } |
| + ir.Node visitConditionalExpression(ConditionalExpression node) { |
| + return irBuilder.buildConditional( |
| + visit(node.condition), |
| + build(node.thenExpression), |
| + build(node.elseExpression)); |
| + } |
| - irBuilder.buildIf(condition, buildThenPart, buildElsePart); |
| + @override |
| + visitIfStatement(IfStatement node) { |
| + irBuilder.buildIf( |
| + visit(node.condition), |
| + build(node.thenStatement), |
| + build(node.elseStatement)); |
| } |
| } |