Chromium Code Reviews| 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 js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
| 8 | 8 |
| 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
| 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 static final Uri DART_FOREIGN_HELPER = | 228 static final Uri DART_FOREIGN_HELPER = |
| 229 new Uri(scheme: 'dart', path: '_foreign_helper'); | 229 new Uri(scheme: 'dart', path: '_foreign_helper'); |
| 230 static final Uri DART_JS_MIRRORS = | 230 static final Uri DART_JS_MIRRORS = |
| 231 new Uri(scheme: 'dart', path: '_js_mirrors'); | 231 new Uri(scheme: 'dart', path: '_js_mirrors'); |
| 232 static final Uri DART_JS_NAMES = | 232 static final Uri DART_JS_NAMES = |
| 233 new Uri(scheme: 'dart', path: '_js_names'); | 233 new Uri(scheme: 'dart', path: '_js_names'); |
| 234 static final Uri DART_EMBEDDED_NAMES = | 234 static final Uri DART_EMBEDDED_NAMES = |
| 235 new Uri(scheme: 'dart', path: '_js_embedded_names'); | 235 new Uri(scheme: 'dart', path: '_js_embedded_names'); |
| 236 static final Uri DART_ISOLATE_HELPER = | 236 static final Uri DART_ISOLATE_HELPER = |
| 237 new Uri(scheme: 'dart', path: '_isolate_helper'); | 237 new Uri(scheme: 'dart', path: '_isolate_helper'); |
| 238 static final Uri DART_HTML = | 238 static final Uri DART_ASYNC = new Uri(scheme: 'dart', path: 'async'); |
| 239 new Uri(scheme: 'dart', path: 'html'); | 239 static final Uri DART_HTML = new Uri(scheme: 'dart', path: 'html'); |
| 240 | 240 |
| 241 static const String INVOKE_ON = '_getCachedInvocation'; | 241 static const String INVOKE_ON = '_getCachedInvocation'; |
| 242 static const String START_ROOT_ISOLATE = 'startRootIsolate'; | 242 static const String START_ROOT_ISOLATE = 'startRootIsolate'; |
| 243 | 243 |
| 244 | 244 |
| 245 String get patchVersion => emitter.patchVersion; | 245 String get patchVersion => emitter.patchVersion; |
| 246 | 246 |
| 247 bool get supportsReflection => emitter.emitter.supportsReflection; | 247 bool get supportsReflection => emitter.emitter.supportsReflection; |
| 248 | 248 |
| 249 final Annotations annotations; | 249 final Annotations annotations; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 266 /** | 266 /** |
| 267 * The generated code as a js AST for compiled methods. | 267 * The generated code as a js AST for compiled methods. |
| 268 */ | 268 */ |
| 269 Map<Element, jsAst.Expression> get generatedCode { | 269 Map<Element, jsAst.Expression> get generatedCode { |
| 270 return compiler.enqueuer.codegen.generatedCode; | 270 return compiler.enqueuer.codegen.generatedCode; |
| 271 } | 271 } |
| 272 | 272 |
| 273 FunctionInlineCache inlineCache = new FunctionInlineCache(); | 273 FunctionInlineCache inlineCache = new FunctionInlineCache(); |
| 274 | 274 |
| 275 LibraryElement jsHelperLibrary; | 275 LibraryElement jsHelperLibrary; |
| 276 LibraryElement asyncLibrary; | |
| 276 LibraryElement interceptorsLibrary; | 277 LibraryElement interceptorsLibrary; |
| 277 LibraryElement foreignLibrary; | 278 LibraryElement foreignLibrary; |
| 278 LibraryElement isolateHelperLibrary; | 279 LibraryElement isolateHelperLibrary; |
| 279 | 280 |
| 280 ClassElement closureClass; | 281 ClassElement closureClass; |
| 281 ClassElement boundClosureClass; | 282 ClassElement boundClosureClass; |
| 282 Element assertMethod; | 283 Element assertMethod; |
| 283 Element invokeOnMethod; | 284 Element invokeOnMethod; |
| 284 | 285 |
| 285 ClassElement jsInterceptorClass; | 286 ClassElement jsInterceptorClass; |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 FunctionElement resolveExternalFunction(FunctionElement element) { | 663 FunctionElement resolveExternalFunction(FunctionElement element) { |
| 663 if (isForeign(element)) return element; | 664 if (isForeign(element)) return element; |
| 664 return patchResolverTask.measure(() { | 665 return patchResolverTask.measure(() { |
| 665 return patchResolverTask.resolveExternalFunction(element); | 666 return patchResolverTask.resolveExternalFunction(element); |
| 666 }); | 667 }); |
| 667 } | 668 } |
| 668 | 669 |
| 669 // TODO(karlklose): Split into findHelperFunction and findHelperClass and | 670 // TODO(karlklose): Split into findHelperFunction and findHelperClass and |
| 670 // add a check that the element has the expected kind. | 671 // add a check that the element has the expected kind. |
| 671 Element findHelper(String name) => find(jsHelperLibrary, name); | 672 Element findHelper(String name) => find(jsHelperLibrary, name); |
| 673 Element findAsyncAwaitHelper(String name) => find(asyncLibrary, name); | |
|
Lasse Reichstein Nielsen
2015/08/12 09:46:55
Seems like this just looks things up in the async
floitsch
2015/08/12 14:53:44
Done.
| |
| 672 Element findInterceptor(String name) => find(interceptorsLibrary, name); | 674 Element findInterceptor(String name) => find(interceptorsLibrary, name); |
| 673 | 675 |
| 674 Element find(LibraryElement library, String name) { | 676 Element find(LibraryElement library, String name) { |
| 675 Element element = library.findLocal(name); | 677 Element element = library.findLocal(name); |
| 676 assert(invariant(library, element != null, | 678 assert(invariant(library, element != null, |
| 677 message: "Element '$name' not found in '${library.canonicalUri}'.")); | 679 message: "Element '$name' not found in '${library.canonicalUri}'.")); |
| 678 return element; | 680 return element; |
| 679 } | 681 } |
| 680 | 682 |
| 681 bool isForeign(Element element) => element.library == foreignLibrary; | 683 bool isForeign(Element element) => element.library == foreignLibrary; |
| (...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1843 | 1845 |
| 1844 Element getCreateInvocationMirror() { | 1846 Element getCreateInvocationMirror() { |
| 1845 return findHelper(Compiler.CREATE_INVOCATION_MIRROR); | 1847 return findHelper(Compiler.CREATE_INVOCATION_MIRROR); |
| 1846 } | 1848 } |
| 1847 | 1849 |
| 1848 Element getCyclicThrowHelper() { | 1850 Element getCyclicThrowHelper() { |
| 1849 return findHelper("throwCyclicInit"); | 1851 return findHelper("throwCyclicInit"); |
| 1850 } | 1852 } |
| 1851 | 1853 |
| 1852 Element getAsyncHelper() { | 1854 Element getAsyncHelper() { |
| 1853 return findHelper("asyncHelper"); | 1855 return findAsyncAwaitHelper("_asyncHelper"); |
| 1854 } | 1856 } |
| 1855 | 1857 |
| 1856 Element getWrapBody() { | 1858 Element getWrapBody() { |
| 1857 return findHelper("_wrapJsFunctionForAsync"); | 1859 return findAsyncAwaitHelper("_wrapJsFunctionForAsync"); |
| 1858 } | 1860 } |
| 1859 | 1861 |
| 1860 Element getYieldStar() { | 1862 Element getYieldStar() { |
| 1861 ClassElement classElement = findHelper("IterationMarker"); | 1863 ClassElement classElement = findAsyncAwaitHelper("_IterationMarker"); |
| 1862 classElement.ensureResolved(compiler); | 1864 classElement.ensureResolved(compiler); |
| 1863 return classElement.lookupLocalMember("yieldStar"); | 1865 return classElement.lookupLocalMember("yieldStar"); |
| 1864 } | 1866 } |
| 1865 | 1867 |
| 1866 Element getYieldSingle() { | 1868 Element getYieldSingle() { |
| 1867 ClassElement classElement = findHelper("IterationMarker"); | 1869 ClassElement classElement = findAsyncAwaitHelper("_IterationMarker"); |
| 1868 classElement.ensureResolved(compiler); | 1870 classElement.ensureResolved(compiler); |
| 1869 return classElement.lookupLocalMember("yieldSingle"); | 1871 return classElement.lookupLocalMember("yieldSingle"); |
| 1870 } | 1872 } |
| 1871 | 1873 |
| 1872 Element getSyncStarUncaughtError() { | 1874 Element getSyncStarUncaughtError() { |
| 1873 ClassElement classElement = findHelper("IterationMarker"); | 1875 ClassElement classElement = findAsyncAwaitHelper("_IterationMarker"); |
| 1874 classElement.ensureResolved(compiler); | 1876 classElement.ensureResolved(compiler); |
| 1875 return classElement.lookupLocalMember("uncaughtError"); | 1877 return classElement.lookupLocalMember("uncaughtError"); |
| 1876 } | 1878 } |
| 1877 | 1879 |
| 1878 Element getAsyncStarHelper() { | 1880 Element getAsyncStarHelper() { |
| 1879 return findHelper("asyncStarHelper"); | 1881 return findAsyncAwaitHelper("_asyncStarHelper"); |
| 1880 } | 1882 } |
| 1881 | 1883 |
| 1882 Element getStreamOfController() { | 1884 Element getStreamOfController() { |
| 1883 return findHelper("streamOfController"); | 1885 return findAsyncAwaitHelper("_streamOfController"); |
| 1884 } | 1886 } |
| 1885 | 1887 |
| 1886 Element getEndOfIteration() { | 1888 Element getEndOfIteration() { |
| 1887 ClassElement classElement = findHelper("IterationMarker"); | 1889 ClassElement classElement = findAsyncAwaitHelper("_IterationMarker"); |
| 1888 classElement.ensureResolved(compiler); | 1890 classElement.ensureResolved(compiler); |
| 1889 return classElement.lookupLocalMember("endOfIteration"); | 1891 return classElement.lookupLocalMember("endOfIteration"); |
| 1890 } | 1892 } |
| 1891 | 1893 |
| 1892 Element getSyncStarIterable() { | 1894 Element getSyncStarIterable() { |
| 1893 ClassElement classElement = findHelper("SyncStarIterable"); | 1895 ClassElement classElement = findAsyncAwaitHelper("_SyncStarIterable"); |
| 1894 classElement.ensureResolved(compiler); | 1896 classElement.ensureResolved(compiler); |
| 1895 return classElement; | 1897 return classElement; |
| 1896 } | 1898 } |
| 1897 | 1899 |
| 1898 Element getSyncStarIterableConstructor() { | 1900 Element getSyncStarIterableConstructor() { |
| 1899 ClassElement classElement = getSyncStarIterable(); | 1901 ClassElement classElement = getSyncStarIterable(); |
| 1900 classElement.ensureResolved(compiler); | 1902 classElement.ensureResolved(compiler); |
| 1901 return classElement.lookupConstructor(""); | 1903 return classElement.lookupConstructor(""); |
| 1902 } | 1904 } |
| 1903 | 1905 |
| 1904 Element getCompleterConstructor() { | 1906 Element getCompleterConstructor() { |
| 1905 ClassElement classElement = find(compiler.asyncLibrary, "Completer"); | 1907 ClassElement classElement = find(compiler.asyncLibrary, "Completer"); |
| 1906 classElement.ensureResolved(compiler); | 1908 classElement.ensureResolved(compiler); |
| 1907 return classElement.lookupConstructor(""); | 1909 return classElement.lookupConstructor(""); |
| 1908 } | 1910 } |
| 1909 | 1911 |
| 1910 Element getASyncStarController() { | 1912 Element getASyncStarController() { |
| 1911 ClassElement classElement = findHelper("AsyncStarStreamController"); | 1913 ClassElement classElement = |
| 1914 findAsyncAwaitHelper("_AsyncStarStreamController"); | |
| 1912 classElement.ensureResolved(compiler); | 1915 classElement.ensureResolved(compiler); |
| 1913 return classElement; | 1916 return classElement; |
| 1914 } | 1917 } |
| 1915 | 1918 |
| 1916 Element getASyncStarControllerConstructor() { | 1919 Element getASyncStarControllerConstructor() { |
| 1917 ClassElement classElement = getASyncStarController(); | 1920 ClassElement classElement = getASyncStarController(); |
| 1918 return classElement.lookupConstructor(""); | 1921 return classElement.lookupConstructor(""); |
| 1919 } | 1922 } |
| 1920 | 1923 |
| 1921 Element getStreamIteratorConstructor() { | 1924 Element getStreamIteratorConstructor() { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2015 } | 2018 } |
| 2016 return true; | 2019 return true; |
| 2017 } | 2020 } |
| 2018 return false; | 2021 return false; |
| 2019 } | 2022 } |
| 2020 | 2023 |
| 2021 void onLibraryCreated(LibraryElement library) { | 2024 void onLibraryCreated(LibraryElement library) { |
| 2022 Uri uri = library.canonicalUri; | 2025 Uri uri = library.canonicalUri; |
| 2023 if (uri == DART_JS_HELPER) { | 2026 if (uri == DART_JS_HELPER) { |
| 2024 jsHelperLibrary = library; | 2027 jsHelperLibrary = library; |
| 2028 } else if (uri == DART_ASYNC) { | |
| 2029 asyncLibrary = library; | |
| 2025 } else if (uri == DART_INTERNAL) { | 2030 } else if (uri == DART_INTERNAL) { |
| 2026 internalLibrary = library; | 2031 internalLibrary = library; |
| 2027 } else if (uri == DART_INTERCEPTORS) { | 2032 } else if (uri == DART_INTERCEPTORS) { |
| 2028 interceptorsLibrary = library; | 2033 interceptorsLibrary = library; |
| 2029 } else if (uri == DART_FOREIGN_HELPER) { | 2034 } else if (uri == DART_FOREIGN_HELPER) { |
| 2030 foreignLibrary = library; | 2035 foreignLibrary = library; |
| 2031 } else if (uri == DART_ISOLATE_HELPER) { | 2036 } else if (uri == DART_ISOLATE_HELPER) { |
| 2032 isolateHelperLibrary = library; | 2037 isolateHelperLibrary = library; |
| 2033 } | 2038 } |
| 2034 } | 2039 } |
| (...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3079 } | 3084 } |
| 3080 } | 3085 } |
| 3081 | 3086 |
| 3082 /// Records that [constant] is used by the element behind [registry]. | 3087 /// Records that [constant] is used by the element behind [registry]. |
| 3083 class Dependency { | 3088 class Dependency { |
| 3084 final ConstantValue constant; | 3089 final ConstantValue constant; |
| 3085 final Element annotatedElement; | 3090 final Element annotatedElement; |
| 3086 | 3091 |
| 3087 const Dependency(this.constant, this.annotatedElement); | 3092 const Dependency(this.constant, this.annotatedElement); |
| 3088 } | 3093 } |
| OLD | NEW |