| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """This module generates Dart APIs from the IDL database.""" | 6 """This module generates Dart APIs from the IDL database.""" |
| 7 | 7 |
| 8 import emitter | 8 import emitter |
| 9 import idlnode | 9 import idlnode |
| 10 import logging | 10 import logging |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 # Object, or inject SSV into the appropriate types. | 46 # Object, or inject SSV into the appropriate types. |
| 47 'SerializedScriptValue': 'String', | 47 'SerializedScriptValue': 'String', |
| 48 # TODO(vsm): Automatically recognize types defined in src. | 48 # TODO(vsm): Automatically recognize types defined in src. |
| 49 'TimeoutHandler': 'TimeoutHandler', | 49 'TimeoutHandler': 'TimeoutHandler', |
| 50 'RequestAnimationFrameCallback': 'RequestAnimationFrameCallback', | 50 'RequestAnimationFrameCallback': 'RequestAnimationFrameCallback', |
| 51 } | 51 } |
| 52 | 52 |
| 53 _dart_to_idl_type_conversions = dict((v,k) for k, v in | 53 _dart_to_idl_type_conversions = dict((v,k) for k, v in |
| 54 _idl_to_dart_type_conversions.iteritems()) | 54 _idl_to_dart_type_conversions.iteritems()) |
| 55 | 55 |
| 56 |
| 57 # |
| 58 # Identifiers that are used in the IDL than need to be treated specially because |
| 59 # *some* JavaScript processors forbid them as properties. |
| 60 # |
| 61 _javascript_keywords = ['delete', 'continue'] |
| 62 |
| 56 # | 63 # |
| 57 # Types with user-invocable constructors. We do not have enough | 64 # Types with user-invocable constructors. We do not have enough |
| 58 # information in IDL to create the signature. | 65 # information in IDL to create the signature. |
| 59 # | 66 # |
| 60 # Each entry is of the form: | 67 # Each entry is of the form: |
| 61 # type name: constructor parameters | 68 # type name: constructor parameters |
| 62 _constructable_types = { | 69 _constructable_types = { |
| 63 'AudioContext': '', | 70 'AudioContext': '', |
| 64 'FileReader': '', | 71 'FileReader': '', |
| 65 'XMLHttpRequest': '', | 72 'XMLHttpRequest': '', |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 template = ''.join(open('template_wrapping_dom_externs.js').readlines()) | 923 template = ''.join(open('template_wrapping_dom_externs.js').readlines()) |
| 917 namespace = 'dom_externs' | 924 namespace = 'dom_externs' |
| 918 members = code.Emit(template, NAMESPACE=namespace) | 925 members = code.Emit(template, NAMESPACE=namespace) |
| 919 | 926 |
| 920 # TODO: Filter out externs that are known to the JavaScript back-end. Some | 927 # TODO: Filter out externs that are known to the JavaScript back-end. Some |
| 921 # of the known externs have useful declarations like @nosideeffects that | 928 # of the known externs have useful declarations like @nosideeffects that |
| 922 # might improve back-end analysis. | 929 # might improve back-end analysis. |
| 923 | 930 |
| 924 names = dict() # maps name to (interface, kind) | 931 names = dict() # maps name to (interface, kind) |
| 925 for (interface, name, kind) in self._wrapping_externs: | 932 for (interface, name, kind) in self._wrapping_externs: |
| 926 if name not in names: | 933 if name not in _javascript_keywords: |
| 927 names[name] = set() | 934 if name not in names: |
| 928 names[name].add((interface, kind)) | 935 names[name] = set() |
| 936 names[name].add((interface, kind)) |
| 929 | 937 |
| 930 for name in sorted(names.keys()): | 938 for name in sorted(names.keys()): |
| 931 # Simply export the property name. | 939 # Simply export the property name. |
| 932 extern = emitter.Format('$NAMESPACE.$NAME;', | 940 extern = emitter.Format('$NAMESPACE.$NAME;', |
| 933 NAMESPACE=namespace, NAME=name) | 941 NAMESPACE=namespace, NAME=name) |
| 934 members.EmitRaw(extern) | 942 members.EmitRaw(extern) |
| 935 # Add a big comment of all the attributes and operations contributing to | 943 # Add a big comment of all the attributes and operations contributing to |
| 936 # the export. | 944 # the export. |
| 937 filler = ' ' * (40 - 2 - len(extern)) # '2' for 2 spaces before comment. | 945 filler = ' ' * (40 - 2 - len(extern)) # '2' for 2 spaces before comment. |
| 938 separator = filler + ' //' | 946 separator = filler + ' //' |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 ' }\n' | 1641 ' }\n' |
| 1634 '}\n', | 1642 '}\n', |
| 1635 CLASS=self._class_name, | 1643 CLASS=self._class_name, |
| 1636 NAME=info.name, | 1644 NAME=info.name, |
| 1637 JSNAME1=js_name_1, | 1645 JSNAME1=js_name_1, |
| 1638 JSNAME2=js_name_2, | 1646 JSNAME2=js_name_2, |
| 1639 NATIVENAME=native_name, | 1647 NATIVENAME=native_name, |
| 1640 PARAMS=', '.join(['_this'] + arg_names), | 1648 PARAMS=', '.join(['_this'] + arg_names), |
| 1641 ARGS=', '.join(['_this.$dom'] + unwrap_args)) | 1649 ARGS=', '.join(['_this.$dom'] + unwrap_args)) |
| 1642 else: | 1650 else: |
| 1643 if info.js_name in ['delete', 'continue']: | 1651 if info.js_name in _javascript_keywords: |
| 1644 access = "['%s']" % info.js_name | 1652 access = "['%s']" % info.js_name |
| 1645 else: | 1653 else: |
| 1646 access = ".%s" % info.js_name | 1654 access = ".%s" % info.js_name |
| 1647 self._js_code.Emit( | 1655 self._js_code.Emit( |
| 1648 '\n' | 1656 '\n' |
| 1649 'function native_$(CLASS)_$(NATIVENAME)($PARAMS) {\n' | 1657 'function native_$(CLASS)_$(NATIVENAME)($PARAMS) {\n' |
| 1650 ' try {\n' | 1658 ' try {\n' |
| 1651 ' return __dom_wrap(_this.$dom$ACCESS($ARGS));\n' | 1659 ' return __dom_wrap(_this.$dom$ACCESS($ARGS));\n' |
| 1652 ' } catch (e) {\n' | 1660 ' } catch (e) {\n' |
| 1653 ' throw __dom_wrap_exception(e);\n' | 1661 ' throw __dom_wrap_exception(e);\n' |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1968 Arguments: | 1976 Arguments: |
| 1969 info: An OperationInfo object. | 1977 info: An OperationInfo object. |
| 1970 """ | 1978 """ |
| 1971 # TODO(vsm): Handle overloads. | 1979 # TODO(vsm): Handle overloads. |
| 1972 self._members_emitter.Emit( | 1980 self._members_emitter.Emit( |
| 1973 '\n' | 1981 '\n' |
| 1974 ' $TYPE $NAME($ARGS) native;\n', | 1982 ' $TYPE $NAME($ARGS) native;\n', |
| 1975 TYPE=info.type_name, | 1983 TYPE=info.type_name, |
| 1976 NAME=info.name, | 1984 NAME=info.name, |
| 1977 ARGS=info.arg_implementation_declaration) | 1985 ARGS=info.arg_implementation_declaration) |
| OLD | NEW |