OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, 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 provides shared functionality for the systems to generate | 6 """This module provides shared functionality for the systems to generate |
7 native binding from the IDL database.""" | 7 native binding from the IDL database.""" |
8 | 8 |
9 import emitter | 9 import emitter |
10 import os | 10 import os |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 for (type, member) in _cpp_overloaded_callback_map.keys(): | 86 for (type, member) in _cpp_overloaded_callback_map.keys(): |
87 if type not in _cpp_partial_map: | 87 if type not in _cpp_partial_map: |
88 _cpp_partial_map[type] = set([]) | 88 _cpp_partial_map[type] = set([]) |
89 _cpp_partial_map[type].add(_cpp_overloaded_callback_map[(type, member)]) | 89 _cpp_partial_map[type].add(_cpp_overloaded_callback_map[(type, member)]) |
90 | 90 |
91 if interface_name in _cpp_partial_map: | 91 if interface_name in _cpp_partial_map: |
92 return _cpp_partial_map[interface_name] | 92 return _cpp_partial_map[interface_name] |
93 else: | 93 else: |
94 return set([]) | 94 return set([]) |
95 | 95 |
96 def array_type(data_type): | |
97 matched = re.match(r'([\w\d_\s]+)\[\]', data_type) | |
98 if not matched: | |
99 return None | |
100 return matched.group(1) | |
101 | |
102 def _GetCPPTypeName(interface_name, callback_name, cpp_name): | 96 def _GetCPPTypeName(interface_name, callback_name, cpp_name): |
103 # TODO(vsm): We need to track the original IDL file name in order to recover | 97 # TODO(vsm): We need to track the original IDL file name in order to recover |
104 # the proper CPP name. | 98 # the proper CPP name. |
105 | 99 |
106 cpp_tuple = (interface_name, callback_name) | 100 cpp_tuple = (interface_name, callback_name) |
107 if cpp_tuple in _cpp_callback_map: | 101 if cpp_tuple in _cpp_callback_map: |
108 cpp_type_name = _cpp_callback_map[cpp_tuple] | 102 cpp_type_name = _cpp_callback_map[cpp_tuple] |
109 elif (interface_name, cpp_name) in _cpp_overloaded_callback_map: | 103 elif (interface_name, cpp_name) in _cpp_overloaded_callback_map: |
110 cpp_type_name = _cpp_overloaded_callback_map[(interface_name, cpp_name)] | 104 cpp_type_name = _cpp_overloaded_callback_map[(interface_name, cpp_name)] |
111 else: | 105 else: |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 ext_attrs.get('ConstructorCallWith') == 'Script
Arguments') | 707 ext_attrs.get('ConstructorCallWith') == 'Script
Arguments') |
714 if requires_script_arguments: | 708 if requires_script_arguments: |
715 raises_exceptions = True | 709 raises_exceptions = True |
716 cpp_arguments = ['scriptArguments.release()'] | 710 cpp_arguments = ['scriptArguments.release()'] |
717 # WebKit uses scriptArguments to reconstruct last argument, so | 711 # WebKit uses scriptArguments to reconstruct last argument, so |
718 # it's not needed and should be just removed. | 712 # it's not needed and should be just removed. |
719 arguments = arguments[:-1] | 713 arguments = arguments[:-1] |
720 | 714 |
721 requires_script_execution_context = (ext_attrs.get('CallWith') == 'ScriptExe
cutionContext' or | 715 requires_script_execution_context = (ext_attrs.get('CallWith') == 'ScriptExe
cutionContext' or |
722 ext_attrs.get('ConstructorCallWith') ==
'ScriptExecutionContext') | 716 ext_attrs.get('ConstructorCallWith') ==
'ScriptExecutionContext') |
723 | |
724 requires_document = ext_attrs.get('ConstructorCallWith') == 'Document' | |
725 | |
726 if requires_script_execution_context: | 717 if requires_script_execution_context: |
727 raises_exceptions = True | 718 raises_exceptions = True |
728 cpp_arguments = ['context'] | 719 cpp_arguments = ['context'] |
729 | 720 |
730 requires_script_state = (ext_attrs.get('CallWith') == 'ScriptState' or | 721 requires_script_state = (ext_attrs.get('CallWith') == 'ScriptState' or |
731 ext_attrs.get('ConstructorCallWith') == 'ScriptStat
e') | 722 ext_attrs.get('ConstructorCallWith') == 'ScriptStat
e') |
732 if requires_script_state: | 723 if requires_script_state: |
733 raises_exceptions = True | 724 raises_exceptions = True |
734 cpp_arguments = ['&state'] | 725 cpp_arguments = ['&state'] |
735 | 726 |
736 requires_dom_window = 'NamedConstructor' in ext_attrs | 727 requires_dom_window = 'NamedConstructor' in ext_attrs |
737 if requires_dom_window or requires_document: | 728 if requires_dom_window: |
738 raises_exceptions = True | 729 raises_exceptions = True |
739 cpp_arguments = ['document'] | 730 cpp_arguments = ['document'] |
740 | 731 |
741 if 'ImplementedBy' in ext_attrs: | 732 if 'ImplementedBy' in ext_attrs: |
742 assert needs_receiver | 733 assert needs_receiver |
743 self._cpp_impl_includes.add('"%s.h"' % ext_attrs['ImplementedBy']) | 734 self._cpp_impl_includes.add('"%s.h"' % ext_attrs['ImplementedBy']) |
744 cpp_arguments.append('receiver') | 735 cpp_arguments.append('receiver') |
745 | 736 |
746 if 'Reflect' in ext_attrs: | 737 if 'Reflect' in ext_attrs: |
747 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)] | 738 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)] |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 | 803 |
813 if requires_script_state: | 804 if requires_script_state: |
814 body_emitter.Emit( | 805 body_emitter.Emit( |
815 ' ScriptState* currentState = ScriptState::current();\n' | 806 ' ScriptState* currentState = ScriptState::current();\n' |
816 ' if (!currentState) {\n' | 807 ' if (!currentState) {\n' |
817 ' exception = Dart_NewStringFromCString("Failed to retrieve
a script state");\n' | 808 ' exception = Dart_NewStringFromCString("Failed to retrieve
a script state");\n' |
818 ' goto fail;\n' | 809 ' goto fail;\n' |
819 ' }\n' | 810 ' }\n' |
820 ' ScriptState& state = *currentState;\n\n') | 811 ' ScriptState& state = *currentState;\n\n') |
821 | 812 |
822 if requires_dom_window or requires_document: | 813 if requires_dom_window: |
823 self._cpp_impl_includes.add('"DOMWindow.h"') | 814 self._cpp_impl_includes.add('"DOMWindow.h"') |
824 body_emitter.Emit( | 815 body_emitter.Emit( |
825 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIsol
ate();\n' | 816 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIsol
ate();\n' |
826 ' if (!domWindow) {\n' | 817 ' if (!domWindow) {\n' |
827 ' exception = Dart_NewStringFromCString("Failed to fetch do
mWindow");\n' | 818 ' exception = Dart_NewStringFromCString("Failed to fetch do
mWindow");\n' |
828 ' goto fail;\n' | 819 ' goto fail;\n' |
829 ' }\n' | 820 ' }\n' |
830 ' Document* document = domWindow->document();\n') | 821 ' Document* document = domWindow->document();\n') |
831 | 822 |
832 if needs_receiver: | 823 if needs_receiver: |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' | 1116 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' |
1126 ' return func;\n', | 1117 ' return func;\n', |
1127 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 1118 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
1128 | 1119 |
1129 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 1120 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
1130 return ( | 1121 return ( |
1131 interface.id.endswith('Event') and | 1122 interface.id.endswith('Event') and |
1132 operation.id.startswith('init') and | 1123 operation.id.startswith('init') and |
1133 argument.ext_attrs.get('Default') == 'Undefined' and | 1124 argument.ext_attrs.get('Default') == 'Undefined' and |
1134 argument.type.id == 'DOMString') | 1125 argument.type.id == 'DOMString') |
OLD | NEW |