Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/backend.dart

Issue 208423012: Add helpers library to dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1816 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 bool hasNoThrows = false; 1827 bool hasNoThrows = false;
1828 bool hasNoSideEffects = false; 1828 bool hasNoSideEffects = false;
1829 for (MetadataAnnotation metadata in element.metadata) { 1829 for (MetadataAnnotation metadata in element.metadata) {
1830 metadata.ensureResolved(compiler); 1830 metadata.ensureResolved(compiler);
1831 if (!metadata.value.isConstructedObject) continue; 1831 if (!metadata.value.isConstructedObject) continue;
1832 ObjectConstant value = metadata.value; 1832 ObjectConstant value = metadata.value;
1833 ClassElement cls = value.type.element; 1833 ClassElement cls = value.type.element;
1834 if (cls == noInlineClass) { 1834 if (cls == noInlineClass) {
1835 hasNoInline = true; 1835 hasNoInline = true;
1836 if (VERBOSE_OPTIMIZER_HINTS) { 1836 if (VERBOSE_OPTIMIZER_HINTS) {
1837 compiler.reportHere(element, "Cannot inline"); 1837 compiler.reportHint(element,
1838 MessageKind.GENERIC,
1839 {'text': "Cannot inline"});
1838 } 1840 }
1839 inlineCache.markAsNonInlinable(element); 1841 inlineCache.markAsNonInlinable(element);
1840 } else if (cls == noThrowsClass) { 1842 } else if (cls == noThrowsClass) {
1841 hasNoThrows = true; 1843 hasNoThrows = true;
1842 if (!Elements.isStaticOrTopLevelFunction(element)) { 1844 if (!Elements.isStaticOrTopLevelFunction(element)) {
1843 compiler.internalError(element, 1845 compiler.internalError(element,
1844 "@NoThrows() is currently limited to top-level" 1846 "@NoThrows() is currently limited to top-level"
1845 " or static functions"); 1847 " or static functions");
1846 } 1848 }
1847 if (VERBOSE_OPTIMIZER_HINTS) { 1849 if (VERBOSE_OPTIMIZER_HINTS) {
1848 compiler.reportHere(element, "Cannot throw"); 1850 compiler.reportHint(element,
1851 MessageKind.GENERIC,
1852 {'text': "Cannot throw"});
1849 } 1853 }
1850 compiler.world.registerCannotThrow(element); 1854 compiler.world.registerCannotThrow(element);
1851 } else if (cls == noSideEffectsClass) { 1855 } else if (cls == noSideEffectsClass) {
1852 hasNoSideEffects = true; 1856 hasNoSideEffects = true;
1853 if (VERBOSE_OPTIMIZER_HINTS) { 1857 if (VERBOSE_OPTIMIZER_HINTS) {
1854 compiler.reportHere(element, "Has no side effects"); 1858 compiler.reportHint(element,
1859 MessageKind.GENERIC,
1860 {'text': "Has no side effects"});
1855 } 1861 }
1856 compiler.world.registerSideEffectsFree(element); 1862 compiler.world.registerSideEffectsFree(element);
1857 } 1863 }
1858 } 1864 }
1859 if (hasNoThrows && !hasNoInline) { 1865 if (hasNoThrows && !hasNoInline) {
1860 compiler.internalError(element, 1866 compiler.internalError(element,
1861 "@NoThrows() should always be combined with @NoInline."); 1867 "@NoThrows() should always be combined with @NoInline.");
1862 } 1868 }
1863 if (hasNoSideEffects && !hasNoInline) { 1869 if (hasNoSideEffects && !hasNoInline) {
1864 compiler.internalError(element, 1870 compiler.internalError(element,
1865 "@NoSideEffects() should always be combined with @NoInline."); 1871 "@NoSideEffects() should always be combined with @NoInline.");
1866 } 1872 }
1867 } 1873 }
1868 1874
1869 CodeBuffer codeOf(Element element) { 1875 CodeBuffer codeOf(Element element) {
1870 return generatedCode.containsKey(element) 1876 return generatedCode.containsKey(element)
1871 ? jsAst.prettyPrint(generatedCode[element], compiler) 1877 ? jsAst.prettyPrint(generatedCode[element], compiler)
1872 : null; 1878 : null;
1873 } 1879 }
1874 } 1880 }
1875 1881
1876 /// Records that [constant] is used by [user.element]. 1882 /// Records that [constant] is used by [user.element].
1877 class Dependency { 1883 class Dependency {
1878 final Constant constant; 1884 final Constant constant;
1879 final TreeElements user; 1885 final TreeElements user;
1880 1886
1881 const Dependency(this.constant, this.user); 1887 const Dependency(this.constant, this.user);
1882 } 1888 }
1883 1889
1884 /// Used to copy metadata to the the actual constant handler.
1885 class ConstantCopier implements ConstantVisitor {
1886 final ConstantHandler target;
1887
1888 ConstantCopier(this.target);
1889
1890 void copy(/* Constant or List<Constant> */ value) {
1891 if (value is Constant) {
1892 target.compiledConstants.add(value);
1893 } else {
1894 target.compiledConstants.addAll(value);
1895 }
1896 }
1897
1898 void visitFunction(FunctionConstant constant) => copy(constant);
1899
1900 void visitNull(NullConstant constant) => copy(constant);
1901
1902 void visitInt(IntConstant constant) => copy(constant);
1903
1904 void visitDouble(DoubleConstant constant) => copy(constant);
1905
1906 void visitTrue(TrueConstant constant) => copy(constant);
1907
1908 void visitFalse(FalseConstant constant) => copy(constant);
1909
1910 void visitString(StringConstant constant) => copy(constant);
1911
1912 void visitType(TypeConstant constant) => copy(constant);
1913
1914 void visitInterceptor(InterceptorConstant constant) => copy(constant);
1915
1916 void visitDummy(DummyConstant constant) => copy(constant);
1917
1918 void visitList(ListConstant constant) {
1919 copy(constant.entries);
1920 copy(constant);
1921 }
1922 void visitMap(MapConstant constant) {
1923 copy(constant.keys);
1924 copy(constant.values);
1925 copy(constant.protoValue);
1926 copy(constant);
1927 }
1928
1929 void visitConstructed(ConstructedConstant constant) {
1930 copy(constant.fields);
1931 copy(constant);
1932 }
1933 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698