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 library kernel.transformations.continuation; | 5 library kernel.transformations.continuation; |
6 | 6 |
7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
8 | 8 |
9 import '../ast.dart'; | 9 import '../ast.dart'; |
10 import '../core_types.dart'; | 10 import '../core_types.dart'; |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 this.syncIterableConstructor, | 886 this.syncIterableConstructor, |
887 this.streamIteratorConstructor, | 887 this.streamIteratorConstructor, |
888 this.futureMicrotaskConstructor, | 888 this.futureMicrotaskConstructor, |
889 this.streamControllerConstructor, | 889 this.streamControllerConstructor, |
890 this.asyncThenWrapper, | 890 this.asyncThenWrapper, |
891 this.asyncErrorWrapper, | 891 this.asyncErrorWrapper, |
892 this.awaitHelper, | 892 this.awaitHelper, |
893 this.coreTypes); | 893 this.coreTypes); |
894 | 894 |
895 factory HelperNodes.fromProgram(Program program) { | 895 factory HelperNodes.fromProgram(Program program) { |
896 Library findLibrary(String name) { | 896 var coreTypes = new CoreTypes(program); |
897 Uri uri = Uri.parse(name); | |
898 for (var library in program.libraries) { | |
899 if (library.importUri == uri) return library; | |
900 } | |
901 throw 'Library "$name" not found'; | |
902 } | |
903 | |
904 Class findClass(Library library, String name) { | |
905 for (var klass in library.classes) { | |
906 if (klass.name == name) return klass; | |
907 } | |
908 throw 'Class "$name" not found'; | |
909 } | |
910 | |
911 Procedure findFactoryConstructor(Class klass, String name) { | |
912 for (var procedure in klass.procedures) { | |
913 if (procedure.isStatic && procedure.name.name == name) return procedure; | |
914 } | |
915 throw 'Factory constructor "$klass.$name" not found'; | |
916 } | |
917 | |
918 Constructor findConstructor(Class klass, String name) { | |
919 for (var constructor in klass.constructors) { | |
920 if (constructor.name.name == name) return constructor; | |
921 } | |
922 throw 'Constructor "$klass.$name" not found'; | |
923 } | |
924 | |
925 Procedure findProcedure(Library library, String name) { | |
926 for (var procedure in library.procedures) { | |
927 if (procedure.name.name == name || | |
928 procedure.name.name == '${library.name}::${name}') { | |
929 return procedure; | |
930 } | |
931 } | |
932 throw 'Procedure "$name" not found'; | |
933 } | |
934 | |
935 var asyncLibrary = findLibrary('dart:async'); | |
936 var coreLibrary = findLibrary('dart:core'); | |
937 | |
938 var completerClass = findClass(asyncLibrary, 'Completer'); | |
939 var futureClass = findClass(asyncLibrary, 'Future'); | |
940 var iteratorClass = findClass(coreLibrary, 'Iterator'); | |
941 | |
942 // The VM's dart:async implementation has renamed _StreamIteratorImpl to | |
943 // _StreamIterator. To support both old and new library implementations we | |
944 // look for the old name first and then the new name. | |
945 var streamIteratorClass; | |
946 try { | |
947 streamIteratorClass = findClass(asyncLibrary, '_StreamIteratorImpl'); | |
948 } catch (e) { | |
949 if (e == 'Class "_StreamIteratorImpl" not found') { | |
950 streamIteratorClass = findClass(asyncLibrary, '_StreamIterator'); | |
951 } else { | |
952 rethrow; | |
953 } | |
954 } | |
955 | |
956 var syncIterableClass = findClass(coreLibrary, '_SyncIterable'); | |
957 var streamControllerClass = | |
958 findClass(asyncLibrary, '_AsyncStarStreamController'); | |
959 | |
960 return new HelperNodes( | 897 return new HelperNodes( |
961 asyncLibrary, | 898 coreTypes.getLibrary('dart:async'), |
962 coreLibrary, | 899 coreTypes.getLibrary('dart:core'), |
963 iteratorClass, | 900 coreTypes.getClass('dart:core', 'Iterator'), |
964 futureClass, | 901 coreTypes.getClass('dart:async', 'Future'), |
965 completerClass, | 902 coreTypes.getClass('dart:async', 'Completer'), |
966 findProcedure(coreLibrary, 'print'), | 903 coreTypes.getTopLevelMember('dart:core', 'print'), |
967 findFactoryConstructor(completerClass, 'sync'), | 904 coreTypes.getMember('dart:async', 'Completer', 'sync'), |
968 findConstructor(syncIterableClass, ''), | 905 coreTypes.getMember('dart:core', '_SyncIterable', ''), |
969 findConstructor(streamIteratorClass, ''), | 906 coreTypes.getMember('dart:async', '_StreamIterator', ''), |
970 findFactoryConstructor(futureClass, 'microtask'), | 907 coreTypes.getMember('dart:async', 'Future', 'microtask'), |
971 findConstructor(streamControllerClass, ''), | 908 coreTypes.getMember('dart:async', '_AsyncStarStreamController', ''), |
972 findProcedure(asyncLibrary, '_asyncThenWrapperHelper'), | 909 coreTypes.getTopLevelMember('dart:async', '_asyncThenWrapperHelper'), |
973 findProcedure(asyncLibrary, '_asyncErrorWrapperHelper'), | 910 coreTypes.getTopLevelMember('dart:async', '_asyncErrorWrapperHelper'), |
974 findProcedure(asyncLibrary, '_awaitHelper'), | 911 coreTypes.getTopLevelMember('dart:async', '_awaitHelper'), |
975 new CoreTypes(program)); | 912 coreTypes); |
976 } | 913 } |
977 } | 914 } |
OLD | NEW |