| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 | 6 |
| 7 import '../closure.dart'; | 7 import '../closure.dart'; |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
| 10 import '../common/names.dart'; | 10 import '../common/names.dart'; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 Kernel kernel) { | 142 Kernel kernel) { |
| 143 this.compiler = compiler; | 143 this.compiler = compiler; |
| 144 this.loopHandler = new KernelLoopHandler(this); | 144 this.loopHandler = new KernelLoopHandler(this); |
| 145 typeBuilder = new TypeBuilder(this); | 145 typeBuilder = new TypeBuilder(this); |
| 146 graph.element = targetElement; | 146 graph.element = targetElement; |
| 147 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? | 147 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? |
| 148 this.sourceInformationBuilder = | 148 this.sourceInformationBuilder = |
| 149 sourceInformationFactory.createBuilderForContext(resolvedAst); | 149 sourceInformationFactory.createBuilderForContext(resolvedAst); |
| 150 graph.sourceInformation = | 150 graph.sourceInformation = |
| 151 sourceInformationBuilder.buildVariableDeclaration(); | 151 sourceInformationBuilder.buildVariableDeclaration(); |
| 152 this.localsHandler = new LocalsHandler(this, targetElement, null, compiler); | 152 this.localsHandler = new LocalsHandler( |
| 153 this, targetElement, null, backend.nativeData, backend.interceptorData); |
| 153 this.astAdapter = new KernelAstAdapter(kernel, compiler.backend, | 154 this.astAdapter = new KernelAstAdapter(kernel, compiler.backend, |
| 154 resolvedAst, kernel.nodeToAst, kernel.nodeToElement); | 155 resolvedAst, kernel.nodeToAst, kernel.nodeToElement); |
| 155 target = astAdapter.getInitialKernelNode(targetElement); | 156 target = astAdapter.getInitialKernelNode(targetElement); |
| 156 if (targetElement is ConstructorBodyElement) { | 157 if (targetElement is ConstructorBodyElement) { |
| 157 _targetIsConstructorBody = true; | 158 _targetIsConstructorBody = true; |
| 158 } | 159 } |
| 159 } | 160 } |
| 160 | 161 |
| 161 HGraph build() { | 162 HGraph build() { |
| 162 // TODO(het): no reason to do this here... | 163 // TODO(het): no reason to do this here... |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 for (ir.Constructor body in constructorChain.reversed) { | 287 for (ir.Constructor body in constructorChain.reversed) { |
| 287 if (_isEmptyStatement(body.function.body)) continue; | 288 if (_isEmptyStatement(body.function.body)) continue; |
| 288 | 289 |
| 289 List<HInstruction> bodyCallInputs = <HInstruction>[]; | 290 List<HInstruction> bodyCallInputs = <HInstruction>[]; |
| 290 bodyCallInputs.add(newObject); | 291 bodyCallInputs.add(newObject); |
| 291 | 292 |
| 292 // Pass uncaptured arguments first, captured arguments in a box, then type | 293 // Pass uncaptured arguments first, captured arguments in a box, then type |
| 293 // arguments. | 294 // arguments. |
| 294 | 295 |
| 295 ConstructorElement constructorElement = astAdapter.getElement(body); | 296 ConstructorElement constructorElement = astAdapter.getElement(body); |
| 296 ClosureClassMap parameterClosureData = compiler.closureToClassMapper | 297 ClosureClassMap parameterClosureData = closureToClassMapper |
| 297 .getClosureToClassMapping(constructorElement.resolvedAst); | 298 .getClosureToClassMapping(constructorElement.resolvedAst); |
| 298 | 299 |
| 299 var functionSignature = astAdapter.getFunctionSignature(body.function); | 300 var functionSignature = astAdapter.getFunctionSignature(body.function); |
| 300 // Provide the parameters to the generative constructor body. | 301 // Provide the parameters to the generative constructor body. |
| 301 functionSignature.orderedForEachParameter((ParameterElement parameter) { | 302 functionSignature.orderedForEachParameter((ParameterElement parameter) { |
| 302 // If [parameter] is boxed, it will be a field in the box passed as the | 303 // If [parameter] is boxed, it will be a field in the box passed as the |
| 303 // last parameter. So no need to directly pass it. | 304 // last parameter. So no need to directly pass it. |
| 304 if (!localsHandler.isBoxed(parameter)) { | 305 if (!localsHandler.isBoxed(parameter)) { |
| 305 bodyCallInputs.add(localsHandler.readLocal(parameter)); | 306 bodyCallInputs.add(localsHandler.readLocal(parameter)); |
| 306 } | 307 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 // TODO(sra): Re-implement type builder using Kernel types and the | 548 // TODO(sra): Re-implement type builder using Kernel types and the |
| 548 // `target` for context. | 549 // `target` for context. |
| 549 @override | 550 @override |
| 550 Element get sourceElement => _sourceElementForTarget(target); | 551 Element get sourceElement => _sourceElementForTarget(target); |
| 551 | 552 |
| 552 Element _sourceElementForTarget(ir.Node target) { | 553 Element _sourceElementForTarget(ir.Node target) { |
| 553 // For closure-converted (i.e. local functions) the source element is the | 554 // For closure-converted (i.e. local functions) the source element is the |
| 554 // 'call' method of the class that represents the closure. | 555 // 'call' method of the class that represents the closure. |
| 555 if (target is ir.FunctionExpression) { | 556 if (target is ir.FunctionExpression) { |
| 556 LocalFunctionElement element = astAdapter.getElement(target); | 557 LocalFunctionElement element = astAdapter.getElement(target); |
| 557 ClosureClassMap classMap = compiler.closureToClassMapper | 558 ClosureClassMap classMap = |
| 558 .getClosureToClassMapping(element.resolvedAst); | 559 closureToClassMapper.getClosureToClassMapping(element.resolvedAst); |
| 559 return classMap.callElement; | 560 return classMap.callElement; |
| 560 } | 561 } |
| 561 if (target is ir.FunctionDeclaration) { | 562 if (target is ir.FunctionDeclaration) { |
| 562 LocalFunctionElement element = astAdapter.getElement(target); | 563 LocalFunctionElement element = astAdapter.getElement(target); |
| 563 ClosureClassMap classMap = compiler.closureToClassMapper | 564 ClosureClassMap classMap = |
| 564 .getClosureToClassMapping(element.resolvedAst); | 565 closureToClassMapper.getClosureToClassMapping(element.resolvedAst); |
| 565 return classMap.callElement; | 566 return classMap.callElement; |
| 566 } | 567 } |
| 567 Element element = astAdapter.getElement(target); | 568 Element element = astAdapter.getElement(target); |
| 568 return element; | 569 return element; |
| 569 } | 570 } |
| 570 | 571 |
| 571 @override | 572 @override |
| 572 void visitCheckLibraryIsLoaded(ir.CheckLibraryIsLoaded checkLoad) { | 573 void visitCheckLibraryIsLoaded(ir.CheckLibraryIsLoaded checkLoad) { |
| 573 HInstruction prefixConstant = graph.addConstantString( | 574 HInstruction prefixConstant = graph.addConstantString( |
| 574 new DartString.literal(checkLoad.import.name), closedWorld); | 575 new DartString.literal(checkLoad.import.name), closedWorld); |
| (...skipping 1922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2497 astAdapter.getNode(invocation), MessageKind.JS_PLACEHOLDER_CAPTURE); | 2498 astAdapter.getNode(invocation), MessageKind.JS_PLACEHOLDER_CAPTURE); |
| 2498 } | 2499 } |
| 2499 | 2500 |
| 2500 TypeMask ssaType = | 2501 TypeMask ssaType = |
| 2501 astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld); | 2502 astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld); |
| 2502 | 2503 |
| 2503 SourceInformation sourceInformation = null; | 2504 SourceInformation sourceInformation = null; |
| 2504 push(new HForeignCode(nativeBehavior.codeTemplate, ssaType, inputs, | 2505 push(new HForeignCode(nativeBehavior.codeTemplate, ssaType, inputs, |
| 2505 isStatement: !nativeBehavior.codeTemplate.isExpression, | 2506 isStatement: !nativeBehavior.codeTemplate.isExpression, |
| 2506 effects: nativeBehavior.sideEffects, | 2507 effects: nativeBehavior.sideEffects, |
| 2507 nativeBehavior: nativeBehavior)..sourceInformation = sourceInformation); | 2508 nativeBehavior: nativeBehavior) |
| 2509 ..sourceInformation = sourceInformation); |
| 2508 } | 2510 } |
| 2509 | 2511 |
| 2510 void handleJsStringConcat(ir.StaticInvocation invocation) { | 2512 void handleJsStringConcat(ir.StaticInvocation invocation) { |
| 2511 if (_unexpectedForeignArguments(invocation, 2, 2)) { | 2513 if (_unexpectedForeignArguments(invocation, 2, 2)) { |
| 2512 // Result expected on stack. | 2514 // Result expected on stack. |
| 2513 stack.add(graph.addConstantNull(closedWorld)); | 2515 stack.add(graph.addConstantNull(closedWorld)); |
| 2514 return; | 2516 return; |
| 2515 } | 2517 } |
| 2516 List<HInstruction> inputs = _visitPositionalArguments(invocation.arguments); | 2518 List<HInstruction> inputs = _visitPositionalArguments(invocation.arguments); |
| 2517 push(new HStringConcat(inputs[0], inputs[1], commonMasks.stringType)); | 2519 push(new HStringConcat(inputs[0], inputs[1], commonMasks.stringType)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2553 push(new HInvokeDynamicSetter(selector, mask, null, inputs, type)); | 2555 push(new HInvokeDynamicSetter(selector, mask, null, inputs, type)); |
| 2554 } else { | 2556 } else { |
| 2555 push(new HInvokeDynamicMethod( | 2557 push(new HInvokeDynamicMethod( |
| 2556 selector, mask, inputs, type, isIntercepted)); | 2558 selector, mask, inputs, type, isIntercepted)); |
| 2557 } | 2559 } |
| 2558 } | 2560 } |
| 2559 | 2561 |
| 2560 @override | 2562 @override |
| 2561 visitFunctionNode(ir.FunctionNode node) { | 2563 visitFunctionNode(ir.FunctionNode node) { |
| 2562 LocalFunctionElement methodElement = astAdapter.getElement(node); | 2564 LocalFunctionElement methodElement = astAdapter.getElement(node); |
| 2563 ClosureClassMap nestedClosureData = compiler.closureToClassMapper | 2565 ClosureClassMap nestedClosureData = closureToClassMapper |
| 2564 .getClosureToClassMapping(methodElement.resolvedAst); | 2566 .getClosureToClassMapping(methodElement.resolvedAst); |
| 2565 assert(nestedClosureData != null); | 2567 assert(nestedClosureData != null); |
| 2566 assert(nestedClosureData.closureClassElement != null); | 2568 assert(nestedClosureData.closureClassElement != null); |
| 2567 ClosureClassElement closureClassElement = | 2569 ClosureClassElement closureClassElement = |
| 2568 nestedClosureData.closureClassElement; | 2570 nestedClosureData.closureClassElement; |
| 2569 MethodElement callElement = nestedClosureData.callElement; | 2571 MethodElement callElement = nestedClosureData.callElement; |
| 2570 | 2572 |
| 2571 List<HInstruction> capturedVariables = <HInstruction>[]; | 2573 List<HInstruction> capturedVariables = <HInstruction>[]; |
| 2572 closureClassElement.closureFields.forEach((ClosureFieldElement field) { | 2574 closureClassElement.closureFields.forEach((ClosureFieldElement field) { |
| 2573 Local capturedLocal = | 2575 Local capturedLocal = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2601 void visitMethodInvocation(ir.MethodInvocation invocation) { | 2603 void visitMethodInvocation(ir.MethodInvocation invocation) { |
| 2602 // Handle `x == null` specially. When these come from null-aware operators, | 2604 // Handle `x == null` specially. When these come from null-aware operators, |
| 2603 // there is no mapping in the astAdapter. | 2605 // there is no mapping in the astAdapter. |
| 2604 if (_handleEqualsNull(invocation)) return; | 2606 if (_handleEqualsNull(invocation)) return; |
| 2605 invocation.receiver.accept(this); | 2607 invocation.receiver.accept(this); |
| 2606 HInstruction receiver = pop(); | 2608 HInstruction receiver = pop(); |
| 2607 Selector selector = astAdapter.getSelector(invocation); | 2609 Selector selector = astAdapter.getSelector(invocation); |
| 2608 _pushDynamicInvocation( | 2610 _pushDynamicInvocation( |
| 2609 invocation, | 2611 invocation, |
| 2610 astAdapter.typeOfInvocation(invocation, closedWorld), | 2612 astAdapter.typeOfInvocation(invocation, closedWorld), |
| 2611 <HInstruction>[receiver] | 2613 <HInstruction>[receiver]..addAll( |
| 2612 ..addAll( | 2614 _visitArgumentsForDynamicTarget(selector, invocation.arguments))); |
| 2613 _visitArgumentsForDynamicTarget(selector, invocation.arguments))); | |
| 2614 } | 2615 } |
| 2615 | 2616 |
| 2616 bool _handleEqualsNull(ir.MethodInvocation invocation) { | 2617 bool _handleEqualsNull(ir.MethodInvocation invocation) { |
| 2617 if (invocation.name.name == '==') { | 2618 if (invocation.name.name == '==') { |
| 2618 ir.Arguments arguments = invocation.arguments; | 2619 ir.Arguments arguments = invocation.arguments; |
| 2619 if (arguments.types.isEmpty && | 2620 if (arguments.types.isEmpty && |
| 2620 arguments.positional.length == 1 && | 2621 arguments.positional.length == 1 && |
| 2621 arguments.named.isEmpty) { | 2622 arguments.named.isEmpty) { |
| 2622 bool finish(ir.Expression comparand) { | 2623 bool finish(ir.Expression comparand) { |
| 2623 comparand.accept(this); | 2624 comparand.accept(this); |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3226 enterBlock.setBlockFlow( | 3227 enterBlock.setBlockFlow( |
| 3227 new HTryBlockInformation( | 3228 new HTryBlockInformation( |
| 3228 kernelBuilder.wrapStatementGraph(bodyGraph), | 3229 kernelBuilder.wrapStatementGraph(bodyGraph), |
| 3229 exception, | 3230 exception, |
| 3230 kernelBuilder.wrapStatementGraph(catchGraph), | 3231 kernelBuilder.wrapStatementGraph(catchGraph), |
| 3231 kernelBuilder.wrapStatementGraph(finallyGraph)), | 3232 kernelBuilder.wrapStatementGraph(finallyGraph)), |
| 3232 exitBlock); | 3233 exitBlock); |
| 3233 kernelBuilder.inTryStatement = previouslyInTryStatement; | 3234 kernelBuilder.inTryStatement = previouslyInTryStatement; |
| 3234 } | 3235 } |
| 3235 } | 3236 } |
| OLD | NEW |