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 import 'dart:collection'; | 5 import 'dart:collection'; |
6 | 6 |
7 import 'package:js_runtime/shared/embedded_names.dart'; | 7 import 'package:js_runtime/shared/embedded_names.dart'; |
8 | 8 |
9 import '../closure.dart'; | 9 import '../closure.dart'; |
10 import '../common.dart'; | 10 import '../common.dart'; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 /// might not be in scope or from the current instance. | 199 /// might not be in scope or from the current instance. |
200 /// | 200 /// |
201 final InterfaceType instanceType; | 201 final InterfaceType instanceType; |
202 | 202 |
203 SourceInformationBuilder get sourceInformationBuilder { | 203 SourceInformationBuilder get sourceInformationBuilder { |
204 return builder.sourceInformationBuilder; | 204 return builder.sourceInformationBuilder; |
205 } | 205 } |
206 | 206 |
207 LocalsHandler( | 207 LocalsHandler( |
208 this.builder, this.executableContext, InterfaceType instanceType) | 208 this.builder, this.executableContext, InterfaceType instanceType) |
209 : this.instanceType = | 209 : this.instanceType = instanceType == null || |
210 instanceType == null || instanceType.containsTypeVariables | 210 instanceType.containsTypeVariables ? null : instanceType; |
211 ? null | |
212 : instanceType; | |
213 | 211 |
214 /// Substituted type variables occurring in [type] into the context of | 212 /// Substituted type variables occurring in [type] into the context of |
215 /// [contextClass]. | 213 /// [contextClass]. |
216 DartType substInContext(DartType type) { | 214 DartType substInContext(DartType type) { |
217 if (contextClass != null) { | 215 if (contextClass != null) { |
218 ClassElement typeContext = Types.getClassContext(type); | 216 ClassElement typeContext = Types.getClassContext(type); |
219 if (typeContext != null) { | 217 if (typeContext != null) { |
220 type = type.substByContext(contextClass.asInstanceOf(typeContext)); | 218 type = type.substByContext(contextClass.asInstanceOf(typeContext)); |
221 } | 219 } |
222 } | 220 } |
(...skipping 4227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4450 handleJsStringConcat(node); | 4448 handleJsStringConcat(node); |
4451 } else { | 4449 } else { |
4452 reporter.internalError(node, "Unknown foreign: ${element}"); | 4450 reporter.internalError(node, "Unknown foreign: ${element}"); |
4453 } | 4451 } |
4454 } | 4452 } |
4455 | 4453 |
4456 generateDeferredLoaderGet(ast.Send node, FunctionElement deferredLoader, | 4454 generateDeferredLoaderGet(ast.Send node, FunctionElement deferredLoader, |
4457 SourceInformation sourceInformation) { | 4455 SourceInformation sourceInformation) { |
4458 // Until now we only handle these as getters. | 4456 // Until now we only handle these as getters. |
4459 invariant(node, deferredLoader.isDeferredLoaderGetter); | 4457 invariant(node, deferredLoader.isDeferredLoaderGetter); |
4460 Element loadFunction = compiler.loadLibraryFunction; | 4458 Element loadFunction = helpers.loadLibraryWrapper; |
4461 PrefixElement prefixElement = deferredLoader.enclosingElement; | 4459 PrefixElement prefixElement = deferredLoader.enclosingElement; |
4462 String loadId = | 4460 String loadId = |
4463 compiler.deferredLoadTask.getImportDeferName(node, prefixElement); | 4461 compiler.deferredLoadTask.getImportDeferName(node, prefixElement); |
4464 var inputs = [ | 4462 var inputs = [ |
4465 graph.addConstantString(new ast.DartString.literal(loadId), compiler) | 4463 graph.addConstantString(new ast.DartString.literal(loadId), compiler) |
4466 ]; | 4464 ]; |
4467 push(new HInvokeStatic(loadFunction, inputs, backend.nonNullType, | 4465 push(new HInvokeStatic(loadFunction, inputs, backend.nonNullType, |
4468 targetCanThrow: false)..sourceInformation = sourceInformation); | 4466 targetCanThrow: false)..sourceInformation = sourceInformation); |
4469 } | 4467 } |
4470 | 4468 |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4915 } | 4913 } |
4916 } | 4914 } |
4917 | 4915 |
4918 Element constructor = elements[send]; | 4916 Element constructor = elements[send]; |
4919 CallStructure callStructure = elements.getSelector(send).callStructure; | 4917 CallStructure callStructure = elements.getSelector(send).callStructure; |
4920 ConstructorElement constructorDeclaration = constructor; | 4918 ConstructorElement constructorDeclaration = constructor; |
4921 ConstructorElement constructorImplementation = constructor.implementation; | 4919 ConstructorElement constructorImplementation = constructor.implementation; |
4922 constructor = constructorImplementation.effectiveTarget; | 4920 constructor = constructorImplementation.effectiveTarget; |
4923 | 4921 |
4924 final bool isSymbolConstructor = | 4922 final bool isSymbolConstructor = |
4925 constructorDeclaration == compiler.symbolConstructor; | 4923 compiler.commonElements.isSymbolConstructor(constructorDeclaration); |
4926 final bool isJSArrayTypedConstructor = | 4924 final bool isJSArrayTypedConstructor = |
4927 constructorDeclaration == helpers.jsArrayTypedConstructor; | 4925 constructorDeclaration == helpers.jsArrayTypedConstructor; |
4928 | 4926 |
4929 if (isSymbolConstructor) { | 4927 if (isSymbolConstructor) { |
4930 constructor = helpers.symbolValidatedConstructor; | 4928 constructor = helpers.symbolValidatedConstructor; |
4931 assert(invariant(send, constructor != null, | 4929 assert(invariant(send, constructor != null, |
4932 message: 'Constructor Symbol.validated is missing')); | 4930 message: 'Constructor Symbol.validated is missing')); |
4933 callStructure = helpers.symbolValidatedConstructorSelector.callStructure; | 4931 callStructure = helpers.symbolValidatedConstructorSelector.callStructure; |
4934 assert(invariant(send, callStructure != null, | 4932 assert(invariant(send, callStructure != null, |
4935 message: 'Constructor Symbol.validated is missing')); | 4933 message: 'Constructor Symbol.validated is missing')); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5148 visitStaticSend(ast.Send node) { | 5146 visitStaticSend(ast.Send node) { |
5149 internalError(node, "Unexpected visitStaticSend"); | 5147 internalError(node, "Unexpected visitStaticSend"); |
5150 } | 5148 } |
5151 | 5149 |
5152 /// Generate an invocation to the static or top level [function]. | 5150 /// Generate an invocation to the static or top level [function]. |
5153 void generateStaticFunctionInvoke( | 5151 void generateStaticFunctionInvoke( |
5154 ast.Send node, FunctionElement function, CallStructure callStructure) { | 5152 ast.Send node, FunctionElement function, CallStructure callStructure) { |
5155 List<HInstruction> inputs = makeStaticArgumentList( | 5153 List<HInstruction> inputs = makeStaticArgumentList( |
5156 callStructure, node.arguments, function.implementation); | 5154 callStructure, node.arguments, function.implementation); |
5157 | 5155 |
5158 if (function == compiler.identicalFunction) { | 5156 if (function == compiler.commonElements.identicalFunction) { |
5159 pushWithPosition( | 5157 pushWithPosition( |
5160 new HIdentity(inputs[0], inputs[1], null, backend.boolType), node); | 5158 new HIdentity(inputs[0], inputs[1], null, backend.boolType), node); |
5161 return; | 5159 return; |
5162 } else { | 5160 } else { |
5163 pushInvokeStatic(node, function, inputs, | 5161 pushInvokeStatic(node, function, inputs, |
5164 sourceInformation: | 5162 sourceInformation: |
5165 sourceInformationBuilder.buildCall(node, node.selector)); | 5163 sourceInformationBuilder.buildCall(node, node.selector)); |
5166 } | 5164 } |
5167 } | 5165 } |
5168 | 5166 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5472 } | 5470 } |
5473 | 5471 |
5474 @override | 5472 @override |
5475 void bulkHandleNode(ast.Node node, String message, _) { | 5473 void bulkHandleNode(ast.Node node, String message, _) { |
5476 internalError(node, "Unexpected bulk handled node: $node"); | 5474 internalError(node, "Unexpected bulk handled node: $node"); |
5477 } | 5475 } |
5478 | 5476 |
5479 @override | 5477 @override |
5480 void bulkHandleNew(ast.NewExpression node, [_]) { | 5478 void bulkHandleNew(ast.NewExpression node, [_]) { |
5481 Element element = elements[node.send]; | 5479 Element element = elements[node.send]; |
5482 final bool isSymbolConstructor = element == compiler.symbolConstructor; | 5480 final bool isSymbolConstructor = |
| 5481 element == compiler.commonElements.symbolConstructor; |
5483 if (!Elements.isMalformed(element)) { | 5482 if (!Elements.isMalformed(element)) { |
5484 ConstructorElement function = element; | 5483 ConstructorElement function = element; |
5485 element = function.effectiveTarget; | 5484 element = function.effectiveTarget; |
5486 } | 5485 } |
5487 if (Elements.isError(element)) { | 5486 if (Elements.isError(element)) { |
5488 ErroneousElement error = element; | 5487 ErroneousElement error = element; |
5489 if (error.messageKind == MessageKind.CANNOT_FIND_CONSTRUCTOR || | 5488 if (error.messageKind == MessageKind.CANNOT_FIND_CONSTRUCTOR || |
5490 error.messageKind == MessageKind.CANNOT_FIND_UNNAMED_CONSTRUCTOR) { | 5489 error.messageKind == MessageKind.CANNOT_FIND_UNNAMED_CONSTRUCTOR) { |
5491 generateThrowNoSuchMethod( | 5490 generateThrowNoSuchMethod( |
5492 node.send, noSuchMethodTargetSymbolString(error, 'constructor'), | 5491 node.send, noSuchMethodTargetSymbolString(error, 'constructor'), |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5648 | 5647 |
5649 var nativeBehavior = new native.NativeBehavior() | 5648 var nativeBehavior = new native.NativeBehavior() |
5650 ..sideEffects.setAllSideEffects(); | 5649 ..sideEffects.setAllSideEffects(); |
5651 | 5650 |
5652 DartType type = element.isConstructor | 5651 DartType type = element.isConstructor |
5653 ? element.enclosingClass.thisType | 5652 ? element.enclosingClass.thisType |
5654 : element.type.returnType; | 5653 : element.type.returnType; |
5655 // Native behavior effects here are similar to native/behavior.dart. | 5654 // Native behavior effects here are similar to native/behavior.dart. |
5656 // The return type is dynamic if we don't trust js-interop type | 5655 // The return type is dynamic if we don't trust js-interop type |
5657 // declarations. | 5656 // declarations. |
5658 nativeBehavior.typesReturned.add( | 5657 nativeBehavior.typesReturned.add(compiler |
5659 compiler.options.trustJSInteropTypeAnnotations | 5658 .options.trustJSInteropTypeAnnotations ? type : const DynamicType()); |
5660 ? type | |
5661 : const DynamicType()); | |
5662 | 5659 |
5663 // The allocation effects include the declared type if it is native (which | 5660 // The allocation effects include the declared type if it is native (which |
5664 // includes js interop types). | 5661 // includes js interop types). |
5665 if (type.element != null && backend.isNative(type.element)) { | 5662 if (type.element != null && backend.isNative(type.element)) { |
5666 nativeBehavior.typesInstantiated.add(type); | 5663 nativeBehavior.typesInstantiated.add(type); |
5667 } | 5664 } |
5668 | 5665 |
5669 // It also includes any other JS interop type if we don't trust the | 5666 // It also includes any other JS interop type if we don't trust the |
5670 // annotation or if is declared too broad. | 5667 // annotation or if is declared too broad. |
5671 if (!compiler.options.trustJSInteropTypeAnnotations || | 5668 if (!compiler.options.trustJSInteropTypeAnnotations || |
(...skipping 2968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8640 const _LoopTypeVisitor(); | 8637 const _LoopTypeVisitor(); |
8641 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; | 8638 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; |
8642 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; | 8639 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; |
8643 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; | 8640 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; |
8644 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; | 8641 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; |
8645 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; | 8642 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; |
8646 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; | 8643 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; |
8647 int visitSwitchStatement(ast.SwitchStatement node) => | 8644 int visitSwitchStatement(ast.SwitchStatement node) => |
8648 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; | 8645 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; |
8649 } | 8646 } |
OLD | NEW |