| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library analyzer2dart.cps_generator; | 5 library analyzer2dart.cps_generator; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 | 8 |
| 9 import 'package:compiler/src/dart_types.dart' as dart2js; | 9 import 'package:compiler/src/dart_types.dart' as dart2js; |
| 10 import 'package:compiler/src/elements/elements.dart' as dart2js; | 10 import 'package:compiler/src/elements/elements.dart' as dart2js; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 analyzer.TopLevelVariableElement element) { | 43 analyzer.TopLevelVariableElement element) { |
| 44 CpsGeneratingVisitor visitor = new CpsGeneratingVisitor(converter, element); | 44 CpsGeneratingVisitor visitor = new CpsGeneratingVisitor(converter, element); |
| 45 VariableDeclaration variableDeclaration = node; | 45 VariableDeclaration variableDeclaration = node; |
| 46 return visitor.handleFieldDeclaration(element, variableDeclaration); | 46 return visitor.handleFieldDeclaration(element, variableDeclaration); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 /// Visitor that converts analyzer AST nodes into CPS ir nodes. | 50 /// Visitor that converts analyzer AST nodes into CPS ir nodes. |
| 51 class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> | 51 class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
| 52 with IrBuilderMixin<AstNode> { | 52 with IrBuilderMixin<AstNode> { |
| 53 /// Promote the type of [irBuilder] to [DartIrBuilder]. |
| 54 /// The JS backend requires closure conversion which we do not support yet. |
| 55 DartIrBuilder get irBuilder => super.irBuilder; |
| 53 final analyzer.Element element; | 56 final analyzer.Element element; |
| 54 final ElementConverter converter; | 57 final ElementConverter converter; |
| 55 | 58 |
| 56 CpsGeneratingVisitor(this.converter, this.element); | 59 CpsGeneratingVisitor(this.converter, this.element); |
| 57 | 60 |
| 58 Source get currentSource => element.source; | 61 Source get currentSource => element.source; |
| 59 | 62 |
| 60 analyzer.LibraryElement get currentLibrary => element.library; | 63 analyzer.LibraryElement get currentLibrary => element.library; |
| 61 | 64 |
| 62 ir.Node visit(AstNode node) => node.accept(this); | 65 ir.Node visit(AstNode node) => node.accept(this); |
| 63 | 66 |
| 64 ir.FieldDefinition handleFieldDeclaration( | 67 ir.FieldDefinition handleFieldDeclaration( |
| 65 analyzer.PropertyInducingElement field, VariableDeclaration node) { | 68 analyzer.PropertyInducingElement field, VariableDeclaration node) { |
| 66 dart2js.FieldElement element = converter.convertElement(field); | 69 dart2js.FieldElement element = converter.convertElement(field); |
| 67 return withBuilder( | 70 return withBuilder( |
| 68 new DartIrBuilder(DART_CONSTANT_SYSTEM, | 71 new DartIrBuilder(DART_CONSTANT_SYSTEM, |
| 69 element, | 72 element, |
| 70 // TODO(johnniwinther): Supported closure variables. | 73 // TODO(johnniwinther): Supported closure variables. |
| 71 new NullClosureVariableInfo()), | 74 new NullCapturedVariableInfo()), |
| 72 () { | 75 () { |
| 73 irBuilder.buildFieldInitializerHeader(); | 76 irBuilder.buildFieldInitializerHeader(); |
| 74 ir.Primitive initializer = build(node.initializer); | 77 ir.Primitive initializer = build(node.initializer); |
| 75 return irBuilder.makeFieldDefinition(initializer); | 78 return irBuilder.makeFieldDefinition(initializer); |
| 76 }); | 79 }); |
| 77 } | 80 } |
| 78 | 81 |
| 79 ir.FunctionDefinition handleFunctionDeclaration( | 82 ir.FunctionDefinition handleFunctionDeclaration( |
| 80 analyzer.FunctionElement function, FunctionExpression node) { | 83 analyzer.FunctionElement function, FunctionExpression node) { |
| 81 dart2js.FunctionElement element = converter.convertElement(function); | 84 dart2js.FunctionElement element = converter.convertElement(function); |
| 82 return withBuilder( | 85 return withBuilder( |
| 83 new DartIrBuilder(DART_CONSTANT_SYSTEM, | 86 new DartIrBuilder(DART_CONSTANT_SYSTEM, |
| 84 element, | 87 element, |
| 85 // TODO(johnniwinther): Supported closure variables. | 88 // TODO(johnniwinther): Supported closure variables. |
| 86 new NullClosureVariableInfo()), | 89 new NullCapturedVariableInfo()), |
| 87 () { | 90 () { |
| 88 irBuilder.buildFunctionHeader( | 91 irBuilder.buildFunctionHeader( |
| 89 function.parameters.map(converter.convertElement)); | 92 function.parameters.map(converter.convertElement)); |
| 90 // Visit the body directly to avoid processing the signature as | 93 // Visit the body directly to avoid processing the signature as |
| 91 // expressions. | 94 // expressions. |
| 92 visit(node.body); | 95 visit(node.body); |
| 93 return irBuilder.makeFunctionDefinition(const []); | 96 return irBuilder.makeFunctionDefinition(const []); |
| 94 }); | 97 }); |
| 95 } | 98 } |
| 96 | 99 |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 521 |
| 519 @override | 522 @override |
| 520 ir.Primitive visitAsExpression(AsExpression node) { | 523 ir.Primitive visitAsExpression(AsExpression node) { |
| 521 return irBuilder.buildTypeOperator( | 524 return irBuilder.buildTypeOperator( |
| 522 visit(node.expression), | 525 visit(node.expression), |
| 523 converter.convertType(node.type.type), | 526 converter.convertType(node.type.type), |
| 524 isTypeTest: false); | 527 isTypeTest: false); |
| 525 } | 528 } |
| 526 } | 529 } |
| 527 | 530 |
| 528 class NullClosureVariableInfo extends ClosureVariableInfo { | 531 class NullCapturedVariableInfo extends DartCapturedVariableInfo { |
| 529 Iterable get capturedVariables => const []; | 532 Iterable get capturedVariables => const []; |
| 530 } | 533 } |
| OLD | NEW |