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 class Interceptors { | 5 class Interceptors { |
| 6 Compiler compiler; | 6 Compiler compiler; |
| 7 Interceptors(Compiler this.compiler); | 7 Interceptors(Compiler this.compiler); |
| 8 | 8 |
| 9 SourceString mapOperatorToMethodName(Operator op) { | 9 SourceString mapOperatorToMethodName(Operator op) { |
| 10 String name = op.source.stringValue; | 10 String name = op.source.stringValue; |
| (...skipping 1768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1779 | 1779 |
| 1780 void handleForeignJs(Send node) { | 1780 void handleForeignJs(Send node) { |
| 1781 Link<Node> link = node.arguments; | 1781 Link<Node> link = node.arguments; |
| 1782 // If the invoke is on foreign code, don't visit the first | 1782 // If the invoke is on foreign code, don't visit the first |
| 1783 // argument, which is the type, and the second argument, | 1783 // argument, which is the type, and the second argument, |
| 1784 // which is the foreign code. | 1784 // which is the foreign code. |
| 1785 link = link.tail.tail; | 1785 link = link.tail.tail; |
| 1786 List<HInstruction> inputs = <HInstruction>[]; | 1786 List<HInstruction> inputs = <HInstruction>[]; |
| 1787 addGenericSendArgumentsToList(link, inputs); | 1787 addGenericSendArgumentsToList(link, inputs); |
| 1788 LiteralString type = node.arguments.head; | 1788 LiteralString type = node.arguments.head; |
| 1789 LiteralString literal = node.arguments.tail.head; | 1789 StringNode literal = node.arguments.tail.head; |
| 1790 compiler.ensure(literal is LiteralString); | 1790 if (literal is !StringNode || literal.dynamic.isInterpolation) { |
|
Lasse Reichstein Nielsen
2012/03/20 12:01:23
this .dynamic should be unnecessary. "isInterpolat
ngeoffray
2012/03/20 12:09:05
Good point. But I should actually not type the nod
| |
| 1791 compiler.ensure(type is LiteralString); | 1791 compiler.cancel('JS code must be a string literal', node: literal); |
| 1792 } | |
| 1793 if (type is !LiteralString) { | |
| 1794 compiler.cancel( | |
| 1795 'The type of a JS expression must be a string literal', node: type); | |
| 1796 } | |
| 1792 push(new HForeign(literal.dartString, type.dartString, inputs)); | 1797 push(new HForeign(literal.dartString, type.dartString, inputs)); |
| 1793 } | 1798 } |
| 1794 | 1799 |
| 1795 void handleForeignUnintercepted(Send node) { | 1800 void handleForeignUnintercepted(Send node) { |
| 1796 Link<Node> link = node.arguments; | 1801 Link<Node> link = node.arguments; |
| 1797 if (!link.tail.isEmpty()) { | 1802 if (!link.tail.isEmpty()) { |
| 1798 compiler.cancel( | 1803 compiler.cancel( |
| 1799 'More than one expression in UNINTERCEPTED()', node: node); | 1804 'More than one expression in UNINTERCEPTED()', node: node); |
| 1800 } | 1805 } |
| 1801 Expression expression = link.head; | 1806 Expression expression = link.head; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1865 'Isolate library and compiler mismatch', node: node); | 1870 'Isolate library and compiler mismatch', node: node); |
| 1866 } | 1871 } |
| 1867 HStatic target = new HStatic(element); | 1872 HStatic target = new HStatic(element); |
| 1868 add(target); | 1873 add(target); |
| 1869 List<HInstruction> inputs = <HInstruction>[target]; | 1874 List<HInstruction> inputs = <HInstruction>[target]; |
| 1870 addGenericSendArgumentsToList(link, inputs); | 1875 addGenericSendArgumentsToList(link, inputs); |
| 1871 push(new HInvokeStatic(Selector.INVOCATION_0, inputs)); | 1876 push(new HInvokeStatic(Selector.INVOCATION_0, inputs)); |
| 1872 } | 1877 } |
| 1873 } | 1878 } |
| 1874 | 1879 |
| 1880 void handleForeignJsToClosure(Send node) { | |
| 1881 Node closure = node.arguments.head; | |
| 1882 if (!node.arguments.tail.isEmpty()) { | |
| 1883 compiler.cancel( | |
| 1884 'Invalid number of arguments in JS_TO_CLOSURE', | |
| 1885 node: node); | |
| 1886 } | |
| 1887 Element element = elements[closure]; | |
| 1888 if (!Elements.isStaticOrTopLevelFunction(element)) { | |
| 1889 compiler.cancel( | |
| 1890 'JS_TO_CLOSURE requires a static or top-level method', | |
| 1891 node: closure); | |
| 1892 } | |
| 1893 FunctionElement function = element; | |
| 1894 FunctionParameters parameters = element.computeParameters(compiler); | |
| 1895 if (parameters.optionalParameterCount !== 0) { | |
| 1896 compiler.cancel( | |
| 1897 'JS_TO_CLOSURE does not handle closure with optional parameters', | |
| 1898 node: closure); | |
| 1899 } | |
| 1900 visit(closure); | |
| 1901 List<HInstruction> inputs = <HInstruction>[pop()]; | |
| 1902 String invocationName = compiler.namer.closureInvocationName( | |
| 1903 new Selector(SelectorKind.INVOCATION, | |
| 1904 parameters.requiredParameterCount)); | |
| 1905 push(new HForeign(new SourceString('#.$invocationName'), | |
| 1906 const SourceString('var'), | |
| 1907 inputs)); | |
| 1908 } | |
| 1909 | |
| 1875 handleForeignSend(Send node) { | 1910 handleForeignSend(Send node) { |
| 1876 Element element = elements[node]; | 1911 Element element = elements[node]; |
| 1877 if (element === compiler.findHelper(const SourceString('JS'))) { | 1912 if (element === compiler.findHelper(const SourceString('JS'))) { |
| 1878 handleForeignJs(node); | 1913 handleForeignJs(node); |
| 1879 } else if (element === compiler.findHelper( | 1914 } else if (element === compiler.findHelper( |
| 1880 const SourceString('UNINTERCEPTED'))) { | 1915 const SourceString('UNINTERCEPTED'))) { |
| 1881 handleForeignUnintercepted(node); | 1916 handleForeignUnintercepted(node); |
| 1882 } else if (element === compiler.findHelper( | 1917 } else if (element === compiler.findHelper( |
| 1883 const SourceString('JS_HAS_EQUALS'))) { | 1918 const SourceString('JS_HAS_EQUALS'))) { |
| 1884 handleForeignJsHasEquals(node); | 1919 handleForeignJsHasEquals(node); |
| 1885 } else if (element === compiler.findHelper( | 1920 } else if (element === compiler.findHelper( |
| 1886 const SourceString('JS_CURRENT_ISOLATE'))) { | 1921 const SourceString('JS_CURRENT_ISOLATE'))) { |
| 1887 handleForeignJsCurrentIsolate(node); | 1922 handleForeignJsCurrentIsolate(node); |
| 1888 } else if (element === compiler.findHelper( | 1923 } else if (element === compiler.findHelper( |
| 1889 const SourceString('JS_CALL_IN_ISOLATE'))) { | 1924 const SourceString('JS_CALL_IN_ISOLATE'))) { |
| 1890 handleForeignJsCallInIsolate(node); | 1925 handleForeignJsCallInIsolate(node); |
| 1926 } else if (element === compiler.findHelper( | |
| 1927 const SourceString('JS_TO_CLOSURE'))) { | |
| 1928 handleForeignJsToClosure(node); | |
| 1891 } else if (element === currentLibrary.find(const SourceString('native'))) { | 1929 } else if (element === currentLibrary.find(const SourceString('native'))) { |
| 1892 native.handleSsaNative(this, node); | 1930 native.handleSsaNative(this, node); |
| 1893 } else { | 1931 } else { |
| 1894 throw "Unknown foreign: ${node.selector}"; | 1932 throw "Unknown foreign: ${node.selector}"; |
| 1895 } | 1933 } |
| 1896 } | 1934 } |
| 1897 | 1935 |
| 1898 visitSuperSend(Send node) { | 1936 visitSuperSend(Send node) { |
| 1899 Selector selector = elements.getSelector(node); | 1937 Selector selector = elements.getSelector(node); |
| 1900 Element element = elements[node]; | 1938 Element element = elements[node]; |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2805 HInstruction concat = new HAdd(target, left, right); | 2843 HInstruction concat = new HAdd(target, left, right); |
| 2806 builder.add(concat); | 2844 builder.add(concat); |
| 2807 return concat; | 2845 return concat; |
| 2808 } | 2846 } |
| 2809 | 2847 |
| 2810 HInstruction result() { | 2848 HInstruction result() { |
| 2811 flushAccumulator(); | 2849 flushAccumulator(); |
| 2812 return prefix; | 2850 return prefix; |
| 2813 } | 2851 } |
| 2814 } | 2852 } |
| OLD | NEW |