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 4242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4465 handleJsStringConcat(node); | 4463 handleJsStringConcat(node); |
4466 } else { | 4464 } else { |
4467 reporter.internalError(node, "Unknown foreign: ${element}"); | 4465 reporter.internalError(node, "Unknown foreign: ${element}"); |
4468 } | 4466 } |
4469 } | 4467 } |
4470 | 4468 |
4471 generateDeferredLoaderGet(ast.Send node, FunctionElement deferredLoader, | 4469 generateDeferredLoaderGet(ast.Send node, FunctionElement deferredLoader, |
4472 SourceInformation sourceInformation) { | 4470 SourceInformation sourceInformation) { |
4473 // Until now we only handle these as getters. | 4471 // Until now we only handle these as getters. |
4474 invariant(node, deferredLoader.isDeferredLoaderGetter); | 4472 invariant(node, deferredLoader.isDeferredLoaderGetter); |
4475 Element loadFunction = compiler.loadLibraryFunction; | 4473 Element loadFunction = helpers.loadLibraryWrapper; |
4476 PrefixElement prefixElement = deferredLoader.enclosingElement; | 4474 PrefixElement prefixElement = deferredLoader.enclosingElement; |
4477 String loadId = | 4475 String loadId = |
4478 compiler.deferredLoadTask.getImportDeferName(node, prefixElement); | 4476 compiler.deferredLoadTask.getImportDeferName(node, prefixElement); |
4479 var inputs = [ | 4477 var inputs = [ |
4480 graph.addConstantString(new ast.DartString.literal(loadId), compiler) | 4478 graph.addConstantString(new ast.DartString.literal(loadId), compiler) |
4481 ]; | 4479 ]; |
4482 push(new HInvokeStatic(loadFunction, inputs, backend.nonNullType, | 4480 push(new HInvokeStatic(loadFunction, inputs, backend.nonNullType, |
4483 targetCanThrow: false)..sourceInformation = sourceInformation); | 4481 targetCanThrow: false)..sourceInformation = sourceInformation); |
4484 } | 4482 } |
4485 | 4483 |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4930 } | 4928 } |
4931 } | 4929 } |
4932 | 4930 |
4933 Element constructor = elements[send]; | 4931 Element constructor = elements[send]; |
4934 CallStructure callStructure = elements.getSelector(send).callStructure; | 4932 CallStructure callStructure = elements.getSelector(send).callStructure; |
4935 ConstructorElement constructorDeclaration = constructor; | 4933 ConstructorElement constructorDeclaration = constructor; |
4936 ConstructorElement constructorImplementation = constructor.implementation; | 4934 ConstructorElement constructorImplementation = constructor.implementation; |
4937 constructor = constructorImplementation.effectiveTarget; | 4935 constructor = constructorImplementation.effectiveTarget; |
4938 | 4936 |
4939 final bool isSymbolConstructor = | 4937 final bool isSymbolConstructor = |
4940 constructorDeclaration == compiler.symbolConstructor; | 4938 compiler.commonElements.isSymbolConstructor(constructorDeclaration); |
4941 final bool isJSArrayTypedConstructor = | 4939 final bool isJSArrayTypedConstructor = |
4942 constructorDeclaration == helpers.jsArrayTypedConstructor; | 4940 constructorDeclaration == helpers.jsArrayTypedConstructor; |
4943 | 4941 |
4944 if (isSymbolConstructor) { | 4942 if (isSymbolConstructor) { |
4945 constructor = helpers.symbolValidatedConstructor; | 4943 constructor = helpers.symbolValidatedConstructor; |
4946 assert(invariant(send, constructor != null, | 4944 assert(invariant(send, constructor != null, |
4947 message: 'Constructor Symbol.validated is missing')); | 4945 message: 'Constructor Symbol.validated is missing')); |
4948 callStructure = helpers.symbolValidatedConstructorSelector.callStructure; | 4946 callStructure = helpers.symbolValidatedConstructorSelector.callStructure; |
4949 assert(invariant(send, callStructure != null, | 4947 assert(invariant(send, callStructure != null, |
4950 message: 'Constructor Symbol.validated is missing')); | 4948 message: 'Constructor Symbol.validated is missing')); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5163 visitStaticSend(ast.Send node) { | 5161 visitStaticSend(ast.Send node) { |
5164 internalError(node, "Unexpected visitStaticSend"); | 5162 internalError(node, "Unexpected visitStaticSend"); |
5165 } | 5163 } |
5166 | 5164 |
5167 /// Generate an invocation to the static or top level [function]. | 5165 /// Generate an invocation to the static or top level [function]. |
5168 void generateStaticFunctionInvoke( | 5166 void generateStaticFunctionInvoke( |
5169 ast.Send node, FunctionElement function, CallStructure callStructure) { | 5167 ast.Send node, FunctionElement function, CallStructure callStructure) { |
5170 List<HInstruction> inputs = makeStaticArgumentList( | 5168 List<HInstruction> inputs = makeStaticArgumentList( |
5171 callStructure, node.arguments, function.implementation); | 5169 callStructure, node.arguments, function.implementation); |
5172 | 5170 |
5173 if (function == compiler.identicalFunction) { | 5171 if (function == compiler.commonElements.identicalFunction) { |
5174 pushWithPosition( | 5172 pushWithPosition( |
5175 new HIdentity(inputs[0], inputs[1], null, backend.boolType), node); | 5173 new HIdentity(inputs[0], inputs[1], null, backend.boolType), node); |
5176 return; | 5174 return; |
5177 } else { | 5175 } else { |
5178 pushInvokeStatic(node, function, inputs, | 5176 pushInvokeStatic(node, function, inputs, |
5179 sourceInformation: | 5177 sourceInformation: |
5180 sourceInformationBuilder.buildCall(node, node.selector)); | 5178 sourceInformationBuilder.buildCall(node, node.selector)); |
5181 } | 5179 } |
5182 } | 5180 } |
5183 | 5181 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5487 } | 5485 } |
5488 | 5486 |
5489 @override | 5487 @override |
5490 void bulkHandleNode(ast.Node node, String message, _) { | 5488 void bulkHandleNode(ast.Node node, String message, _) { |
5491 internalError(node, "Unexpected bulk handled node: $node"); | 5489 internalError(node, "Unexpected bulk handled node: $node"); |
5492 } | 5490 } |
5493 | 5491 |
5494 @override | 5492 @override |
5495 void bulkHandleNew(ast.NewExpression node, [_]) { | 5493 void bulkHandleNew(ast.NewExpression node, [_]) { |
5496 Element element = elements[node.send]; | 5494 Element element = elements[node.send]; |
5497 final bool isSymbolConstructor = element == compiler.symbolConstructor; | 5495 final bool isSymbolConstructor = |
| 5496 element == compiler.commonElements.symbolConstructor; |
5498 if (!Elements.isMalformed(element)) { | 5497 if (!Elements.isMalformed(element)) { |
5499 ConstructorElement function = element; | 5498 ConstructorElement function = element; |
5500 element = function.effectiveTarget; | 5499 element = function.effectiveTarget; |
5501 } | 5500 } |
5502 if (Elements.isError(element)) { | 5501 if (Elements.isError(element)) { |
5503 ErroneousElement error = element; | 5502 ErroneousElement error = element; |
5504 if (error.messageKind == MessageKind.CANNOT_FIND_CONSTRUCTOR || | 5503 if (error.messageKind == MessageKind.CANNOT_FIND_CONSTRUCTOR || |
5505 error.messageKind == MessageKind.CANNOT_FIND_UNNAMED_CONSTRUCTOR) { | 5504 error.messageKind == MessageKind.CANNOT_FIND_UNNAMED_CONSTRUCTOR) { |
5506 generateThrowNoSuchMethod( | 5505 generateThrowNoSuchMethod( |
5507 node.send, noSuchMethodTargetSymbolString(error, 'constructor'), | 5506 node.send, noSuchMethodTargetSymbolString(error, 'constructor'), |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5663 | 5662 |
5664 var nativeBehavior = new native.NativeBehavior() | 5663 var nativeBehavior = new native.NativeBehavior() |
5665 ..sideEffects.setAllSideEffects(); | 5664 ..sideEffects.setAllSideEffects(); |
5666 | 5665 |
5667 DartType type = element.isConstructor | 5666 DartType type = element.isConstructor |
5668 ? element.enclosingClass.thisType | 5667 ? element.enclosingClass.thisType |
5669 : element.type.returnType; | 5668 : element.type.returnType; |
5670 // Native behavior effects here are similar to native/behavior.dart. | 5669 // Native behavior effects here are similar to native/behavior.dart. |
5671 // The return type is dynamic if we don't trust js-interop type | 5670 // The return type is dynamic if we don't trust js-interop type |
5672 // declarations. | 5671 // declarations. |
5673 nativeBehavior.typesReturned.add( | 5672 nativeBehavior.typesReturned.add(compiler |
5674 compiler.options.trustJSInteropTypeAnnotations | 5673 .options.trustJSInteropTypeAnnotations ? type : const DynamicType()); |
5675 ? type | |
5676 : const DynamicType()); | |
5677 | 5674 |
5678 // The allocation effects include the declared type if it is native (which | 5675 // The allocation effects include the declared type if it is native (which |
5679 // includes js interop types). | 5676 // includes js interop types). |
5680 if (type.element != null && backend.isNative(type.element)) { | 5677 if (type.element != null && backend.isNative(type.element)) { |
5681 nativeBehavior.typesInstantiated.add(type); | 5678 nativeBehavior.typesInstantiated.add(type); |
5682 } | 5679 } |
5683 | 5680 |
5684 // It also includes any other JS interop type if we don't trust the | 5681 // It also includes any other JS interop type if we don't trust the |
5685 // annotation or if is declared too broad. | 5682 // annotation or if is declared too broad. |
5686 if (!compiler.options.trustJSInteropTypeAnnotations || | 5683 if (!compiler.options.trustJSInteropTypeAnnotations || |
(...skipping 2968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8655 const _LoopTypeVisitor(); | 8652 const _LoopTypeVisitor(); |
8656 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; | 8653 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; |
8657 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; | 8654 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; |
8658 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; | 8655 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; |
8659 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; | 8656 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; |
8660 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; | 8657 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; |
8661 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; | 8658 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; |
8662 int visitSwitchStatement(ast.SwitchStatement node) => | 8659 int visitSwitchStatement(ast.SwitchStatement node) => |
8663 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; | 8660 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; |
8664 } | 8661 } |
OLD | NEW |