| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 class SsaFunctionCompiler implements FunctionCompiler { | 7 class SsaFunctionCompiler implements FunctionCompiler { |
| 8 final SsaCodeGeneratorTask generator; | 8 final SsaCodeGeneratorTask generator; |
| 9 final SsaBuilderTask builder; | 9 final SsaBuilderTask builder; |
| 10 final SsaOptimizerTask optimizer; | 10 final SsaOptimizerTask optimizer; |
| (...skipping 2453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2464 return new HTypeConversion.withTypeRepresentation(type, kind, subtype, | 2464 return new HTypeConversion.withTypeRepresentation(type, kind, subtype, |
| 2465 original, typeVariable); | 2465 original, typeVariable); |
| 2466 } else if (type.isFunctionType) { | 2466 } else if (type.isFunctionType) { |
| 2467 String name = kind == HTypeConversion.CAST_TYPE_CHECK | 2467 String name = kind == HTypeConversion.CAST_TYPE_CHECK |
| 2468 ? '_asCheck' : '_assertCheck'; | 2468 ? '_asCheck' : '_assertCheck'; |
| 2469 | 2469 |
| 2470 List<HInstruction> arguments = | 2470 List<HInstruction> arguments = |
| 2471 <HInstruction>[buildFunctionType(type), original]; | 2471 <HInstruction>[buildFunctionType(type), original]; |
| 2472 pushInvokeDynamic( | 2472 pushInvokeDynamic( |
| 2473 null, | 2473 null, |
| 2474 new Selector.call(name, backend.jsHelperLibrary, 1), | 2474 new Selector.call(new Name(name, backend.jsHelperLibrary), 1), |
| 2475 null, | 2475 null, |
| 2476 arguments); | 2476 arguments); |
| 2477 | 2477 |
| 2478 return new HTypeConversion(type, kind, original.instructionType, pop()); | 2478 return new HTypeConversion(type, kind, original.instructionType, pop()); |
| 2479 } else { | 2479 } else { |
| 2480 return original.convertType(compiler, type, kind); | 2480 return original.convertType(compiler, type, kind); |
| 2481 } | 2481 } |
| 2482 } | 2482 } |
| 2483 | 2483 |
| 2484 HInstruction _trustType(HInstruction original, DartType type) { | 2484 HInstruction _trustType(HInstruction original, DartType type) { |
| (...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3739 } | 3739 } |
| 3740 | 3740 |
| 3741 HInstruction buildIsNode(ast.Node node, | 3741 HInstruction buildIsNode(ast.Node node, |
| 3742 DartType type, | 3742 DartType type, |
| 3743 HInstruction expression) { | 3743 HInstruction expression) { |
| 3744 type = localsHandler.substInContext(type).unalias(compiler); | 3744 type = localsHandler.substInContext(type).unalias(compiler); |
| 3745 if (type.isFunctionType) { | 3745 if (type.isFunctionType) { |
| 3746 List arguments = [buildFunctionType(type), expression]; | 3746 List arguments = [buildFunctionType(type), expression]; |
| 3747 pushInvokeDynamic( | 3747 pushInvokeDynamic( |
| 3748 node, | 3748 node, |
| 3749 new Selector.call('_isTest', backend.jsHelperLibrary, 1), | 3749 new Selector.call(new Name('_isTest', backend.jsHelperLibrary), 1), |
| 3750 null, | 3750 null, |
| 3751 arguments); | 3751 arguments); |
| 3752 return new HIs.compound(type, expression, pop(), backend.boolType); | 3752 return new HIs.compound(type, expression, pop(), backend.boolType); |
| 3753 } else if (type.isTypeVariable) { | 3753 } else if (type.isTypeVariable) { |
| 3754 HInstruction runtimeType = addTypeVariableReference(type); | 3754 HInstruction runtimeType = addTypeVariableReference(type); |
| 3755 Element helper = backend.getCheckSubtypeOfRuntimeType(); | 3755 Element helper = backend.getCheckSubtypeOfRuntimeType(); |
| 3756 List<HInstruction> inputs = <HInstruction>[expression, runtimeType]; | 3756 List<HInstruction> inputs = <HInstruction>[expression, runtimeType]; |
| 3757 pushInvokeStatic(null, helper, inputs, typeMask: backend.boolType); | 3757 pushInvokeStatic(null, helper, inputs, typeMask: backend.boolType); |
| 3758 HInstruction call = pop(); | 3758 HInstruction call = pop(); |
| 3759 return new HIs.variable(type, expression, call, backend.boolType); | 3759 return new HIs.variable(type, expression, call, backend.boolType); |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4393 targetCanThrow: false) | 4393 targetCanThrow: false) |
| 4394 ..sourceInformation = sourceInformation); | 4394 ..sourceInformation = sourceInformation); |
| 4395 } | 4395 } |
| 4396 | 4396 |
| 4397 generateSuperNoSuchMethodSend(ast.Send node, | 4397 generateSuperNoSuchMethodSend(ast.Send node, |
| 4398 Selector selector, | 4398 Selector selector, |
| 4399 List<HInstruction> arguments) { | 4399 List<HInstruction> arguments) { |
| 4400 String name = selector.name; | 4400 String name = selector.name; |
| 4401 | 4401 |
| 4402 ClassElement cls = currentNonClosureClass; | 4402 ClassElement cls = currentNonClosureClass; |
| 4403 Element element = cls.lookupSuperMember(Compiler.NO_SUCH_METHOD); | 4403 Element element = cls.lookupSuperMember(Identifiers.noSuchMethod_); |
| 4404 if (compiler.enabledInvokeOn | 4404 if (compiler.enabledInvokeOn |
| 4405 && element.enclosingElement.declaration != compiler.objectClass) { | 4405 && element.enclosingElement.declaration != compiler.objectClass) { |
| 4406 // Register the call as dynamic if [noSuchMethod] on the super | 4406 // Register the call as dynamic if [noSuchMethod] on the super |
| 4407 // class is _not_ the default implementation from [Object], in | 4407 // class is _not_ the default implementation from [Object], in |
| 4408 // case the [noSuchMethod] implementation calls | 4408 // case the [noSuchMethod] implementation calls |
| 4409 // [JSInvocationMirror._invokeOn]. | 4409 // [JSInvocationMirror._invokeOn]. |
| 4410 registry.registerSelectorUse(selector); | 4410 registry.registerSelectorUse(selector); |
| 4411 } | 4411 } |
| 4412 String publicName = name; | 4412 String publicName = name; |
| 4413 if (selector.isSetter) publicName += '='; | 4413 if (selector.isSetter) publicName += '='; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 4436 pushInvokeStatic(null, | 4436 pushInvokeStatic(null, |
| 4437 createInvocationMirror, | 4437 createInvocationMirror, |
| 4438 [graph.addConstant(nameConstant, compiler), | 4438 [graph.addConstant(nameConstant, compiler), |
| 4439 graph.addConstantStringFromName(internalName, compiler), | 4439 graph.addConstantStringFromName(internalName, compiler), |
| 4440 graph.addConstant(kindConstant, compiler), | 4440 graph.addConstant(kindConstant, compiler), |
| 4441 argumentsInstruction, | 4441 argumentsInstruction, |
| 4442 argumentNamesInstruction], | 4442 argumentNamesInstruction], |
| 4443 typeMask: backend.dynamicType); | 4443 typeMask: backend.dynamicType); |
| 4444 | 4444 |
| 4445 var inputs = <HInstruction>[pop()]; | 4445 var inputs = <HInstruction>[pop()]; |
| 4446 push(buildInvokeSuper(compiler.noSuchMethodSelector, element, inputs)); | 4446 push(buildInvokeSuper(Selectors.noSuchMethod_, element, inputs)); |
| 4447 } | 4447 } |
| 4448 | 4448 |
| 4449 /// Generate a call to a super method or constructor. | 4449 /// Generate a call to a super method or constructor. |
| 4450 void generateSuperInvoke(ast.Send node, | 4450 void generateSuperInvoke(ast.Send node, |
| 4451 FunctionElement function, | 4451 FunctionElement function, |
| 4452 SourceInformation sourceInformation) { | 4452 SourceInformation sourceInformation) { |
| 4453 // TODO(5347): Try to avoid the need for calling [implementation] before | 4453 // TODO(5347): Try to avoid the need for calling [implementation] before |
| 4454 // calling [makeStaticArgumentList]. | 4454 // calling [makeStaticArgumentList]. |
| 4455 Selector selector = elements.getSelector(node); | 4455 Selector selector = elements.getSelector(node); |
| 4456 assert(invariant(node, | 4456 assert(invariant(node, |
| (...skipping 2662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7119 void buildUpdate() {}; | 7119 void buildUpdate() {}; |
| 7120 | 7120 |
| 7121 buildProtectedByFinally(() { | 7121 buildProtectedByFinally(() { |
| 7122 handleLoop(node, | 7122 handleLoop(node, |
| 7123 buildInitializer, | 7123 buildInitializer, |
| 7124 buildCondition, | 7124 buildCondition, |
| 7125 buildUpdate, | 7125 buildUpdate, |
| 7126 buildBody); | 7126 buildBody); |
| 7127 }, () { | 7127 }, () { |
| 7128 pushInvokeDynamic(node, | 7128 pushInvokeDynamic(node, |
| 7129 new Selector.call("cancel", null, 0), | 7129 Selectors.cancel, |
| 7130 null, | 7130 null, |
| 7131 [streamIterator]); | 7131 [streamIterator]); |
| 7132 push(new HAwait(pop(), new TypeMask.subclass(compiler.objectClass, | 7132 push(new HAwait(pop(), new TypeMask.subclass(compiler.objectClass, |
| 7133 compiler.world))); | 7133 compiler.world))); |
| 7134 pop(); | 7134 pop(); |
| 7135 }); | 7135 }); |
| 7136 } | 7136 } |
| 7137 | 7137 |
| 7138 visitSyncForIn(ast.SyncForIn node) { | 7138 visitSyncForIn(ast.SyncForIn node) { |
| 7139 // The 'get iterator' selector for this node has the inferred receiver type. | 7139 // The 'get iterator' selector for this node has the inferred receiver type. |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8291 // conversions. | 8291 // conversions. |
| 8292 // 2. The value can be primitive, because the library stringifier has | 8292 // 2. The value can be primitive, because the library stringifier has |
| 8293 // fast-path code for most primitives. | 8293 // fast-path code for most primitives. |
| 8294 if (expression.canBePrimitive(compiler)) { | 8294 if (expression.canBePrimitive(compiler)) { |
| 8295 append(stringify(node, expression)); | 8295 append(stringify(node, expression)); |
| 8296 return; | 8296 return; |
| 8297 } | 8297 } |
| 8298 | 8298 |
| 8299 // If the `toString` method is guaranteed to return a string we can call it | 8299 // If the `toString` method is guaranteed to return a string we can call it |
| 8300 // directly. | 8300 // directly. |
| 8301 Selector selector = new Selector.call('toString', null, 0); | 8301 Selector selector = Selectors.toString_; |
| 8302 TypeMask type = TypeMaskFactory.inferredTypeForSelector( | 8302 TypeMask type = TypeMaskFactory.inferredTypeForSelector( |
| 8303 selector, expression.instructionType, compiler); | 8303 selector, expression.instructionType, compiler); |
| 8304 if (type.containsOnlyString(compiler.world)) { | 8304 if (type.containsOnlyString(compiler.world)) { |
| 8305 builder.pushInvokeDynamic( | 8305 builder.pushInvokeDynamic( |
| 8306 node, selector, expression.instructionType, <HInstruction>[expression]
); | 8306 node, selector, |
| 8307 expression.instructionType, <HInstruction>[expression]); |
| 8307 append(builder.pop()); | 8308 append(builder.pop()); |
| 8308 return; | 8309 return; |
| 8309 } | 8310 } |
| 8310 | 8311 |
| 8311 append(stringify(node, expression)); | 8312 append(stringify(node, expression)); |
| 8312 } | 8313 } |
| 8313 | 8314 |
| 8314 void visitStringInterpolation(ast.StringInterpolation node) { | 8315 void visitStringInterpolation(ast.StringInterpolation node) { |
| 8315 node.visitChildren(this); | 8316 node.visitChildren(this); |
| 8316 } | 8317 } |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8853 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 8854 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
| 8854 unaliased.accept(this, builder); | 8855 unaliased.accept(this, builder); |
| 8855 } | 8856 } |
| 8856 | 8857 |
| 8857 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 8858 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
| 8858 JavaScriptBackend backend = builder.compiler.backend; | 8859 JavaScriptBackend backend = builder.compiler.backend; |
| 8859 ClassElement cls = backend.findHelper('DynamicRuntimeType'); | 8860 ClassElement cls = backend.findHelper('DynamicRuntimeType'); |
| 8860 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 8861 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
| 8861 } | 8862 } |
| 8862 } | 8863 } |
| OLD | NEW |