| 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'; |
| 11 import '../common/tasks.dart' show CompilerTask; | 11 import '../common/tasks.dart' show CompilerTask; |
| 12 import '../compiler.dart'; | 12 import '../compiler.dart'; |
| 13 import '../constants/values.dart' | 13 import '../constants/values.dart' |
| 14 show | 14 show |
| 15 ConstantValue, | 15 ConstantValue, |
| 16 InterceptorConstantValue, | 16 InterceptorConstantValue, |
| 17 StringConstantValue, | 17 StringConstantValue, |
| 18 TypeConstantValue; | 18 TypeConstantValue; |
| 19 import '../elements/elements.dart'; | 19 import '../elements/elements.dart'; |
| 20 import '../elements/entities.dart'; | 20 import '../elements/entities.dart'; |
| 21 import '../elements/resolution_types.dart'; | 21 import '../elements/resolution_types.dart'; |
| 22 import '../io/source_information.dart'; | 22 import '../io/source_information.dart'; |
| 23 import '../js/js.dart' as js; | 23 import '../js/js.dart' as js; |
| 24 import '../js_backend/backend.dart' show JavaScriptBackend; | 24 import '../js_backend/backend.dart' show JavaScriptBackend; |
| 25 import '../kernel/kernel.dart'; | 25 import '../kernel/kernel.dart'; |
| 26 import '../native/native.dart' as native; | 26 import '../native/native.dart' as native; |
| 27 import '../resolution/tree_elements.dart'; | 27 import '../resolution/tree_elements.dart'; |
| 28 import '../tree/dartstring.dart'; | |
| 29 import '../tree/nodes.dart' show Node; | 28 import '../tree/nodes.dart' show Node; |
| 30 import '../types/masks.dart'; | 29 import '../types/masks.dart'; |
| 31 import '../universe/selector.dart'; | 30 import '../universe/selector.dart'; |
| 32 import '../universe/side_effects.dart' show SideEffects; | 31 import '../universe/side_effects.dart' show SideEffects; |
| 33 import '../universe/use.dart' show DynamicUse; | 32 import '../universe/use.dart' show DynamicUse; |
| 34 import '../world.dart'; | 33 import '../world.dart'; |
| 35 import 'graph_builder.dart'; | 34 import 'graph_builder.dart'; |
| 36 import 'jump_handler.dart'; | 35 import 'jump_handler.dart'; |
| 37 import 'kernel_ast_adapter.dart'; | 36 import 'kernel_ast_adapter.dart'; |
| 38 import 'kernel_string_builder.dart'; | 37 import 'kernel_string_builder.dart'; |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 } | 701 } |
| 703 | 702 |
| 704 @override | 703 @override |
| 705 void defaultStatement(ir.Statement statement) { | 704 void defaultStatement(ir.Statement statement) { |
| 706 _trap('Unhandled ir.${statement.runtimeType} $statement'); | 705 _trap('Unhandled ir.${statement.runtimeType} $statement'); |
| 707 pop(); | 706 pop(); |
| 708 } | 707 } |
| 709 | 708 |
| 710 void _trap(String message) { | 709 void _trap(String message) { |
| 711 HInstruction nullValue = graph.addConstantNull(closedWorld); | 710 HInstruction nullValue = graph.addConstantNull(closedWorld); |
| 712 HInstruction errorMessage = | 711 HInstruction errorMessage = graph.addConstantString(message, closedWorld); |
| 713 graph.addConstantString(new DartString.literal(message), closedWorld); | |
| 714 HInstruction trap = new HForeignCode(js.js.parseForeignJS("#.#"), | 712 HInstruction trap = new HForeignCode(js.js.parseForeignJS("#.#"), |
| 715 commonMasks.dynamicType, <HInstruction>[nullValue, errorMessage]); | 713 commonMasks.dynamicType, <HInstruction>[nullValue, errorMessage]); |
| 716 trap.sideEffects | 714 trap.sideEffects |
| 717 ..setAllSideEffects() | 715 ..setAllSideEffects() |
| 718 ..setDependsOnSomething(); | 716 ..setDependsOnSomething(); |
| 719 push(trap); | 717 push(trap); |
| 720 } | 718 } |
| 721 | 719 |
| 722 /// Returns the current source element. This is used by the type builder. | 720 /// Returns the current source element. This is used by the type builder. |
| 723 /// | 721 /// |
| (...skipping 21 matching lines...) Expand all Loading... |
| 745 } | 743 } |
| 746 if (target is ir.FunctionDeclaration) { | 744 if (target is ir.FunctionDeclaration) { |
| 747 return callMethodOfClosureClass(); | 745 return callMethodOfClosureClass(); |
| 748 } | 746 } |
| 749 Element element = astAdapter.getElement(target); | 747 Element element = astAdapter.getElement(target); |
| 750 return element; | 748 return element; |
| 751 } | 749 } |
| 752 | 750 |
| 753 @override | 751 @override |
| 754 void visitCheckLibraryIsLoaded(ir.CheckLibraryIsLoaded checkLoad) { | 752 void visitCheckLibraryIsLoaded(ir.CheckLibraryIsLoaded checkLoad) { |
| 755 HInstruction prefixConstant = graph.addConstantString( | 753 HInstruction prefixConstant = |
| 756 new DartString.literal(checkLoad.import.name), closedWorld); | 754 graph.addConstantString(checkLoad.import.name, closedWorld); |
| 757 var prefixElement = astAdapter.getElement(checkLoad.import); | 755 var prefixElement = astAdapter.getElement(checkLoad.import); |
| 758 HInstruction uriConstant = graph.addConstantString( | 756 HInstruction uriConstant = graph.addConstantString( |
| 759 new DartString.literal(prefixElement.deferredImport.uri.toString()), | 757 prefixElement.deferredImport.uri.toString(), closedWorld); |
| 760 closedWorld); | |
| 761 _pushStaticInvocation(astAdapter.checkDeferredIsLoaded, | 758 _pushStaticInvocation(astAdapter.checkDeferredIsLoaded, |
| 762 [prefixConstant, uriConstant], astAdapter.checkDeferredIsLoadedType); | 759 [prefixConstant, uriConstant], astAdapter.checkDeferredIsLoadedType); |
| 763 } | 760 } |
| 764 | 761 |
| 765 @override | 762 @override |
| 766 void visitLoadLibrary(ir.LoadLibrary loadLibrary) { | 763 void visitLoadLibrary(ir.LoadLibrary loadLibrary) { |
| 767 // TODO(efortuna): Source information! | 764 // TODO(efortuna): Source information! |
| 768 push(new HInvokeStatic( | 765 push(new HInvokeStatic( |
| 769 commonElements.loadLibraryWrapper, | 766 commonElements.loadLibraryWrapper, |
| 770 [ | 767 [graph.addConstantString(loadLibrary.import.name, closedWorld)], |
| 771 graph.addConstantString( | |
| 772 new DartString.literal(loadLibrary.import.name), closedWorld) | |
| 773 ], | |
| 774 commonMasks.nonNullType, | 768 commonMasks.nonNullType, |
| 775 targetCanThrow: false)); | 769 targetCanThrow: false)); |
| 776 } | 770 } |
| 777 | 771 |
| 778 @override | 772 @override |
| 779 void visitBlock(ir.Block block) { | 773 void visitBlock(ir.Block block) { |
| 780 assert(!isAborted()); | 774 assert(!isAborted()); |
| 781 for (ir.Statement statement in block.statements) { | 775 for (ir.Statement statement in block.statements) { |
| 782 statement.accept(this); | 776 statement.accept(this); |
| 783 if (!isReachable) { | 777 if (!isReachable) { |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 HTypeConversion.CAST_TYPE_CHECK); | 1332 HTypeConversion.CAST_TYPE_CHECK); |
| 1339 if (converted != expressionInstruction) { | 1333 if (converted != expressionInstruction) { |
| 1340 add(converted); | 1334 add(converted); |
| 1341 } | 1335 } |
| 1342 stack.add(converted); | 1336 stack.add(converted); |
| 1343 } | 1337 } |
| 1344 } | 1338 } |
| 1345 | 1339 |
| 1346 void generateError( | 1340 void generateError( |
| 1347 ir.Node node, ir.Procedure procedure, String message, TypeMask typeMask) { | 1341 ir.Node node, ir.Procedure procedure, String message, TypeMask typeMask) { |
| 1348 HInstruction errorMessage = | 1342 HInstruction errorMessage = graph.addConstantString(message, closedWorld); |
| 1349 graph.addConstantString(new DartString.literal(message), closedWorld); | |
| 1350 // TODO(sra): Associate source info from [node]. | 1343 // TODO(sra): Associate source info from [node]. |
| 1351 _pushStaticInvocation(procedure, [errorMessage], typeMask); | 1344 _pushStaticInvocation(procedure, [errorMessage], typeMask); |
| 1352 } | 1345 } |
| 1353 | 1346 |
| 1354 void generateTypeError(ir.Node node, String message) { | 1347 void generateTypeError(ir.Node node, String message) { |
| 1355 generateError(node, astAdapter.throwTypeError, message, | 1348 generateError(node, astAdapter.throwTypeError, message, |
| 1356 astAdapter.throwTypeErrorType); | 1349 astAdapter.throwTypeErrorType); |
| 1357 } | 1350 } |
| 1358 | 1351 |
| 1359 @override | 1352 @override |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1828 stack.add(graph.addConstantDouble(doubleLiteral.value, closedWorld)); | 1821 stack.add(graph.addConstantDouble(doubleLiteral.value, closedWorld)); |
| 1829 } | 1822 } |
| 1830 | 1823 |
| 1831 @override | 1824 @override |
| 1832 void visitBoolLiteral(ir.BoolLiteral boolLiteral) { | 1825 void visitBoolLiteral(ir.BoolLiteral boolLiteral) { |
| 1833 stack.add(graph.addConstantBool(boolLiteral.value, closedWorld)); | 1826 stack.add(graph.addConstantBool(boolLiteral.value, closedWorld)); |
| 1834 } | 1827 } |
| 1835 | 1828 |
| 1836 @override | 1829 @override |
| 1837 void visitStringLiteral(ir.StringLiteral stringLiteral) { | 1830 void visitStringLiteral(ir.StringLiteral stringLiteral) { |
| 1838 stack.add(graph.addConstantString( | 1831 stack.add(graph.addConstantString(stringLiteral.value, closedWorld)); |
| 1839 new DartString.literal(stringLiteral.value), closedWorld)); | |
| 1840 } | 1832 } |
| 1841 | 1833 |
| 1842 @override | 1834 @override |
| 1843 void visitSymbolLiteral(ir.SymbolLiteral symbolLiteral) { | 1835 void visitSymbolLiteral(ir.SymbolLiteral symbolLiteral) { |
| 1844 stack.add(graph.addConstant( | 1836 stack.add(graph.addConstant( |
| 1845 astAdapter.getConstantForSymbol(symbolLiteral), closedWorld)); | 1837 astAdapter.getConstantForSymbol(symbolLiteral), closedWorld)); |
| 1846 registry?.registerConstSymbol(symbolLiteral.value); | 1838 registry?.registerConstSymbol(symbolLiteral.value); |
| 1847 } | 1839 } |
| 1848 | 1840 |
| 1849 @override | 1841 @override |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2376 reporter.reportErrorMessage( | 2368 reporter.reportErrorMessage( |
| 2377 astAdapter.getNode(argument), MessageKind.GENERIC, { | 2369 astAdapter.getNode(argument), MessageKind.GENERIC, { |
| 2378 'text': "Error: Expected String constant as ${adjective}argument " | 2370 'text': "Error: Expected String constant as ${adjective}argument " |
| 2379 "to '$methodName'." | 2371 "to '$methodName'." |
| 2380 }); | 2372 }); |
| 2381 return null; | 2373 return null; |
| 2382 } | 2374 } |
| 2383 | 2375 |
| 2384 HConstant hConstant = instruction; | 2376 HConstant hConstant = instruction; |
| 2385 StringConstantValue stringConstant = hConstant.constant; | 2377 StringConstantValue stringConstant = hConstant.constant; |
| 2386 return stringConstant.primitiveValue.slowToString(); | 2378 return stringConstant.primitiveValue; |
| 2387 } | 2379 } |
| 2388 | 2380 |
| 2389 void handleForeignJsCurrentIsolateContext(ir.StaticInvocation invocation) { | 2381 void handleForeignJsCurrentIsolateContext(ir.StaticInvocation invocation) { |
| 2390 if (_unexpectedForeignArguments(invocation, 0, 0)) { | 2382 if (_unexpectedForeignArguments(invocation, 0, 0)) { |
| 2391 // Result expected on stack. | 2383 // Result expected on stack. |
| 2392 stack.add(graph.addConstantNull(closedWorld)); | 2384 stack.add(graph.addConstantNull(closedWorld)); |
| 2393 return; | 2385 return; |
| 2394 } | 2386 } |
| 2395 | 2387 |
| 2396 if (!backendUsage.isIsolateInUse) { | 2388 if (!backendUsage.isIsolateInUse) { |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2882 _containingClass(noSuchMethod) != astAdapter.objectClass) { | 2874 _containingClass(noSuchMethod) != astAdapter.objectClass) { |
| 2883 // Register the call as dynamic if [noSuchMethod] on the super | 2875 // Register the call as dynamic if [noSuchMethod] on the super |
| 2884 // class is _not_ the default implementation from [Object] (it might be | 2876 // class is _not_ the default implementation from [Object] (it might be |
| 2885 // overridden in the super class, but it might have a different number of | 2877 // overridden in the super class, but it might have a different number of |
| 2886 // arguments), in case the [noSuchMethod] implementation calls | 2878 // arguments), in case the [noSuchMethod] implementation calls |
| 2887 // [JSInvocationMirror._invokeOn]. | 2879 // [JSInvocationMirror._invokeOn]. |
| 2888 // TODO(johnniwinther): Register this more precisely. | 2880 // TODO(johnniwinther): Register this more precisely. |
| 2889 registry?.registerDynamicUse(new DynamicUse(selector, null)); | 2881 registry?.registerDynamicUse(new DynamicUse(selector, null)); |
| 2890 } | 2882 } |
| 2891 | 2883 |
| 2892 ConstantValue nameConstant = | 2884 ConstantValue nameConstant = constantSystem.createString(publicName); |
| 2893 constantSystem.createString(new DartString.literal(publicName)); | |
| 2894 | 2885 |
| 2895 js.Name internalName = namer.invocationName(selector); | 2886 js.Name internalName = namer.invocationName(selector); |
| 2896 | 2887 |
| 2897 var argumentsInstruction = | 2888 var argumentsInstruction = |
| 2898 new HLiteralList(arguments, commonMasks.extendableArrayType); | 2889 new HLiteralList(arguments, commonMasks.extendableArrayType); |
| 2899 add(argumentsInstruction); | 2890 add(argumentsInstruction); |
| 2900 | 2891 |
| 2901 var argumentNames = new List<HInstruction>(); | 2892 var argumentNames = new List<HInstruction>(); |
| 2902 for (String argumentName in selector.namedArguments) { | 2893 for (String argumentName in selector.namedArguments) { |
| 2903 ConstantValue argumentNameConstant = | 2894 ConstantValue argumentNameConstant = |
| 2904 constantSystem.createString(new DartString.literal(argumentName)); | 2895 constantSystem.createString(argumentName); |
| 2905 argumentNames.add(graph.addConstant(argumentNameConstant, closedWorld)); | 2896 argumentNames.add(graph.addConstant(argumentNameConstant, closedWorld)); |
| 2906 } | 2897 } |
| 2907 var argumentNamesInstruction = | 2898 var argumentNamesInstruction = |
| 2908 new HLiteralList(argumentNames, commonMasks.extendableArrayType); | 2899 new HLiteralList(argumentNames, commonMasks.extendableArrayType); |
| 2909 add(argumentNamesInstruction); | 2900 add(argumentNamesInstruction); |
| 2910 | 2901 |
| 2911 ConstantValue kindConstant = | 2902 ConstantValue kindConstant = |
| 2912 constantSystem.createInt(selector.invocationMirrorKind); | 2903 constantSystem.createInt(selector.invocationMirrorKind); |
| 2913 | 2904 |
| 2914 _pushStaticInvocation( | 2905 _pushStaticInvocation( |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3421 enterBlock.setBlockFlow( | 3412 enterBlock.setBlockFlow( |
| 3422 new HTryBlockInformation( | 3413 new HTryBlockInformation( |
| 3423 kernelBuilder.wrapStatementGraph(bodyGraph), | 3414 kernelBuilder.wrapStatementGraph(bodyGraph), |
| 3424 exception, | 3415 exception, |
| 3425 kernelBuilder.wrapStatementGraph(catchGraph), | 3416 kernelBuilder.wrapStatementGraph(catchGraph), |
| 3426 kernelBuilder.wrapStatementGraph(finallyGraph)), | 3417 kernelBuilder.wrapStatementGraph(finallyGraph)), |
| 3427 exitBlock); | 3418 exitBlock); |
| 3428 kernelBuilder.inTryStatement = previouslyInTryStatement; | 3419 kernelBuilder.inTryStatement = previouslyInTryStatement; |
| 3429 } | 3420 } |
| 3430 } | 3421 } |
| OLD | NEW |