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 a27b429ebe750b96651950d8dbe2d8b87f8cdb56..05e0afbed542e2ec8d0d5d7a6d2ca67518dbecee 100644 |
| --- a/pkg/analyzer2dart/lib/src/cps_generator.dart |
| +++ b/pkg/analyzer2dart/lib/src/cps_generator.dart |
| @@ -35,10 +35,18 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| ir.Node visit(AstNode node) => node.accept(this); |
| - @override |
| - ir.Primitive visitFunctionExpression(FunctionExpression node) { |
| - return irBuilder.buildFunctionExpression( |
| - handleFunctionDeclaration(node.element, node)); |
| + ir.FieldDefinition handleFieldDeclaration( |
| + analyzer.PropertyInducingElement field, VariableDeclaration node) { |
| + dart2js.FieldElement element = converter.convertElement(field); |
| + return withBuilder( |
| + new IrBuilder(DART_CONSTANT_SYSTEM, |
| + element, |
| + // TODO(johnniwinther): Supported closure variables. |
| + const <dart2js.Local>[]), |
| + () { |
| + ir.Primitive initializer = build(node.initializer); |
| + return irBuilder.makeFieldDefinition(initializer); |
| + }); |
| } |
| ir.FunctionDefinition handleFunctionDeclaration( |
| @@ -58,11 +66,17 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| // Visit the body directly to avoid processing the signature as |
| // expressions. |
| visit(node.body); |
| - return irBuilder.buildFunctionDefinition(const []); |
| + return irBuilder.makeFunctionDefinition(const []); |
| }); |
| } |
| @override |
| + ir.Primitive visitFunctionExpression(FunctionExpression node) { |
| + return irBuilder.buildFunctionExpression( |
| + handleFunctionDeclaration(node.element, node)); |
| + } |
| + |
| + @override |
| ir.FunctionDefinition visitFunctionDeclaration(FunctionDeclaration node) { |
| return handleFunctionDeclaration(node.element, node.functionExpression); |
| } |
| @@ -245,11 +259,17 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| @override |
| visitVariableDeclaration(VariableDeclaration node) { |
| - // TODO(johnniwinther): Handle constant local variables. |
| - ir.Node initialValue = build(node.initializer); |
| - irBuilder.declareLocalVariable( |
| - converter.convertElement(node.element), |
| - initialValue: initialValue); |
| + if (hasIrBuilder) { |
|
sigurdm
2014/12/01 09:06:00
Perhaps make a getter encapsulating this check
Johnni Winther
2014/12/01 13:00:39
Done.
|
| + // Local variable declaration. |
| + // TODO(johnniwinther): Handle constant local variables. |
| + ir.Node initialValue = build(node.initializer); |
| + irBuilder.declareLocalVariable( |
| + converter.convertElement(node.element), |
| + initialValue: initialValue); |
| + } else { |
| + // Field declaration. |
| + return handleFieldDeclaration(node.element, node); |
| + } |
| } |
| dart2js.Element getLocal(AstNode node, AccessSemantics semantics) { |
| @@ -292,6 +312,24 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| } |
| @override |
| + ir.Node visitStaticFieldAssignment(AssignmentExpression node, |
| + AccessSemantics semantics) { |
| + if (node.operator.lexeme != '=') { |
| + return giveUp(node, 'Assignment operator: ${node.operator.lexeme}'); |
| + } |
| + analyzer.Element element = semantics.element; |
| + dart2js.Element target = converter.convertElement(element); |
| + // TODO(johnniwinther): Selector information should be computed in the |
| + // [TreeShaker] and shared with the [CpsGeneratingVisitor]. |
| + assert(invariant(node, target.isTopLevel || target.isStatic, |
| + '$target expected to be top-level or static.')); |
| + return irBuilder.buildStaticSet( |
| + target, |
| + new Selector.setter(target.name, target.library), |
| + build(node.rightHandSide)); |
| + } |
| + |
| + @override |
| ir.Node visitDynamicAccess(AstNode node, AccessSemantics semantics) { |
| // TODO(johnniwinther): Handle implicit `this`. |
| ir.Primitive receiver = build(semantics.target); |