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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 self._emitters.FileEmitter(cpp_impl_path), | 52 self._emitters.FileEmitter(cpp_impl_path), |
53 self._BaseDefines(interface), | 53 self._BaseDefines(interface), |
54 self._templates) | 54 self._templates) |
55 | 55 |
56 def ProcessCallback(self, interface, info): | 56 def ProcessCallback(self, interface, info): |
57 self._interface = interface | 57 self._interface = interface |
58 | 58 |
59 dart_interface_path = self._FilePathForDartInterface(self._interface.id) | 59 dart_interface_path = self._FilePathForDartInterface(self._interface.id) |
60 self._dom_public_files.append(dart_interface_path) | 60 self._dom_public_files.append(dart_interface_path) |
61 | 61 |
62 cpp_impl_includes = set() | |
62 cpp_header_handlers_emitter = emitter.Emitter() | 63 cpp_header_handlers_emitter = emitter.Emitter() |
63 cpp_impl_handlers_emitter = emitter.Emitter() | 64 cpp_impl_handlers_emitter = emitter.Emitter() |
64 class_name = 'Dart%s' % self._interface.id | 65 class_name = 'Dart%s' % self._interface.id |
65 for operation in interface.operations: | 66 for operation in interface.operations: |
66 if operation.type.id == 'void': | 67 if operation.type.id == 'void': |
67 return_type = 'void' | 68 return_type = 'void' |
68 return_prefix = '' | 69 return_prefix = '' |
69 else: | 70 else: |
70 return_type = 'bool' | 71 return_type = 'bool' |
71 return_prefix = 'return ' | 72 return_prefix = 'return ' |
72 | 73 |
73 parameters = [] | 74 parameters = [] |
74 arguments = [] | 75 arguments = [] |
75 for argument in operation.arguments: | 76 for argument in operation.arguments: |
76 argument_type_info = GetIDLTypeInfo(argument.type) | 77 argument_type_info = GetIDLTypeInfo(argument.type) |
77 parameters.append('%s %s' % (argument_type_info.parameter_type(), | 78 parameters.append('%s %s' % (argument_type_info.parameter_type(), |
78 argument.id)) | 79 argument.id)) |
79 arguments.append(argument.id) | 80 arguments.append(argument.id) |
81 cpp_impl_includes |= set(argument_type_info.conversion_includes()) | |
antonm
2012/03/01 15:44:50
or cpp_impl_includes.update(argument_type_info.con
| |
80 | 82 |
81 cpp_header_handlers_emitter.Emit( | 83 cpp_header_handlers_emitter.Emit( |
82 '\n' | 84 '\n' |
83 ' virtual $TYPE handleEvent($PARAMETERS);\n', | 85 ' virtual $TYPE handleEvent($PARAMETERS);\n', |
84 TYPE=return_type, PARAMETERS=', '.join(parameters)) | 86 TYPE=return_type, PARAMETERS=', '.join(parameters)) |
85 | 87 |
86 cpp_impl_handlers_emitter.Emit( | 88 cpp_impl_handlers_emitter.Emit( |
87 '\n' | 89 '\n' |
88 '$TYPE $CLASS_NAME::handleEvent($PARAMETERS)\n' | 90 '$TYPE $CLASS_NAME::handleEvent($PARAMETERS)\n' |
89 '{\n' | 91 '{\n' |
(...skipping 10 matching lines...) Expand all Loading... | |
100 cpp_header_emitter.Emit( | 102 cpp_header_emitter.Emit( |
101 self._templates.Load('cpp_callback_header.template'), | 103 self._templates.Load('cpp_callback_header.template'), |
102 INTERFACE=self._interface.id, | 104 INTERFACE=self._interface.id, |
103 HANDLERS=cpp_header_handlers_emitter.Fragments()) | 105 HANDLERS=cpp_header_handlers_emitter.Fragments()) |
104 | 106 |
105 cpp_impl_path = self._FilePathForCppImplementation(self._interface.id) | 107 cpp_impl_path = self._FilePathForCppImplementation(self._interface.id) |
106 self._cpp_impl_files.append(cpp_impl_path) | 108 self._cpp_impl_files.append(cpp_impl_path) |
107 cpp_impl_emitter = self._emitters.FileEmitter(cpp_impl_path) | 109 cpp_impl_emitter = self._emitters.FileEmitter(cpp_impl_path) |
108 cpp_impl_emitter.Emit( | 110 cpp_impl_emitter.Emit( |
109 self._templates.Load('cpp_callback_implementation.template'), | 111 self._templates.Load('cpp_callback_implementation.template'), |
112 INCLUDES=_GenerateCPPIncludes(cpp_impl_includes), | |
110 INTERFACE=self._interface.id, | 113 INTERFACE=self._interface.id, |
111 HANDLERS=cpp_impl_handlers_emitter.Fragments()) | 114 HANDLERS=cpp_impl_handlers_emitter.Fragments()) |
112 | 115 |
113 def GenerateLibraries(self, lib_dir): | 116 def GenerateLibraries(self, lib_dir): |
114 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) | 117 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) |
115 | 118 |
116 # Generate dom_public.dart. | 119 # Generate dom_public.dart. |
117 self._GenerateLibFile( | 120 self._GenerateLibFile( |
118 'dom_public.darttemplate', | 121 'dom_public.darttemplate', |
119 os.path.join(self._output_dir, 'dom_public.dart'), | 122 os.path.join(self._output_dir, 'dom_public.dart'), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n' | 156 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n' |
154 ' return func;\n', | 157 ' return func;\n', |
155 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 158 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
156 | 159 |
157 cpp_resolver_emitter = self._emitters.FileEmitter(cpp_resolver_path) | 160 cpp_resolver_emitter = self._emitters.FileEmitter(cpp_resolver_path) |
158 cpp_resolver_emitter.Emit( | 161 cpp_resolver_emitter.Emit( |
159 self._templates.Load('cpp_resolver.template'), | 162 self._templates.Load('cpp_resolver.template'), |
160 INCLUDES=includes_emitter.Fragments(), | 163 INCLUDES=includes_emitter.Fragments(), |
161 RESOLVER_BODY=resolver_body_emitter.Fragments()) | 164 RESOLVER_BODY=resolver_body_emitter.Fragments()) |
162 | 165 |
163 # Generate DartDerivedSourcesAll.cpp | 166 # Generate DartDerivedSourcesXX.cpp. |
164 cpp_all_in_one_path = os.path.join(self._output_dir, | 167 partitions = 20 # FIXME: this should be configurable. |
165 'DartDerivedSourcesAll.cpp') | 168 sources_count = len(self._cpp_impl_files) |
169 for i in range(0, partitions): | |
170 derived_sources_path = os.path.join(self._output_dir, | |
171 'DartDerivedSources%02i.cpp' % (i + 1)) | |
166 | 172 |
167 includes_emitter = emitter.Emitter() | 173 includes_emitter = emitter.Emitter() |
168 for file in self._cpp_impl_files: | 174 for impl_file in self._cpp_impl_files[i::partitions]: |
169 path = os.path.relpath(file, os.path.dirname(cpp_all_in_one_path)) | 175 path = os.path.relpath(impl_file, os.path.dirname(cpp_all_in_one_path) ) |
170 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 176 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
171 | 177 |
172 cpp_all_in_one_emitter = self._emitters.FileEmitter(cpp_all_in_one_path) | 178 cpp_all_in_one_emitter = self._emitters.FileEmitter(derived_sources_path) |
antonm
2012/03/01 15:44:50
cpp_all_in_one, cpp_all_in_one, la-la
| |
173 cpp_all_in_one_emitter.Emit( | 179 cpp_all_in_one_emitter.Emit( |
174 self._templates.Load('cpp_all_in_one.template'), | 180 self._templates.Load('cpp_all_in_one.template'), |
175 INCLUDES=includes_emitter.Fragments()) | 181 INCLUDES=includes_emitter.Fragments()) |
176 | 182 |
177 # Generate DartResolver.cpp | 183 # Generate DartResolver.cpp. |
178 cpp_resolver_path = os.path.join(self._output_dir, 'DartResolver.cpp') | 184 cpp_resolver_path = os.path.join(self._output_dir, 'DartResolver.cpp') |
179 | 185 |
180 includes_emitter = emitter.Emitter() | 186 includes_emitter = emitter.Emitter() |
181 resolver_body_emitter = emitter.Emitter() | 187 resolver_body_emitter = emitter.Emitter() |
182 for file in self._cpp_header_files: | 188 for file in self._cpp_header_files: |
183 path = os.path.relpath(file, os.path.dirname(cpp_resolver_path)) | 189 path = os.path.relpath(file, os.path.dirname(cpp_resolver_path)) |
184 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 190 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
185 resolver_body_emitter.Emit( | 191 resolver_body_emitter.Emit( |
186 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n' | 192 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n' |
187 ' return func;\n', | 193 ' return func;\n', |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 self._cpp_impl_emitter = cpp_impl_emitter | 247 self._cpp_impl_emitter = cpp_impl_emitter |
242 self._base_members = base_members | 248 self._base_members = base_members |
243 self._templates = templates | 249 self._templates = templates |
244 self._current_secondary_parent = None | 250 self._current_secondary_parent = None |
245 | 251 |
246 def StartInterface(self): | 252 def StartInterface(self): |
247 self._class_name = self._ImplClassName(self._interface.id) | 253 self._class_name = self._ImplClassName(self._interface.id) |
248 self._interface_type_info = GetIDLTypeInfoByName(self._interface.id) | 254 self._interface_type_info = GetIDLTypeInfoByName(self._interface.id) |
249 self._members_emitter = emitter.Emitter() | 255 self._members_emitter = emitter.Emitter() |
250 self._cpp_declarations_emitter = emitter.Emitter() | 256 self._cpp_declarations_emitter = emitter.Emitter() |
251 self._cpp_impl_includes = {} | 257 self._cpp_impl_includes = set() |
252 self._cpp_definitions_emitter = emitter.Emitter() | 258 self._cpp_definitions_emitter = emitter.Emitter() |
253 self._cpp_resolver_emitter = emitter.Emitter() | 259 self._cpp_resolver_emitter = emitter.Emitter() |
254 | 260 |
255 self._GenerateConstructors() | 261 self._GenerateConstructors() |
256 | 262 |
257 def _GenerateConstructors(self): | 263 def _GenerateConstructors(self): |
258 if not self._IsConstructable(): | 264 if not self._IsConstructable(): |
259 return | 265 return |
260 | 266 |
261 # TODO(antonm): currently we don't have information about number of argument s expected by | 267 # TODO(antonm): currently we don't have information about number of argument s expected by |
(...skipping 19 matching lines...) Expand all Loading... | |
281 create_function = 'create' | 287 create_function = 'create' |
282 if 'NamedConstructor' in self._interface.ext_attrs: | 288 if 'NamedConstructor' in self._interface.ext_attrs: |
283 raises_dart_exceptions = True | 289 raises_dart_exceptions = True |
284 parameter_definitions_emitter.Emit( | 290 parameter_definitions_emitter.Emit( |
285 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIs olate();\n' | 291 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIs olate();\n' |
286 ' if (!domWindow) {\n' | 292 ' if (!domWindow) {\n' |
287 ' exception = Dart_NewString("Failed to fetch domWindow") ;\n' | 293 ' exception = Dart_NewString("Failed to fetch domWindow") ;\n' |
288 ' goto fail;\n' | 294 ' goto fail;\n' |
289 ' }\n' | 295 ' }\n' |
290 ' Document* document = domWindow->document();\n') | 296 ' Document* document = domWindow->document();\n') |
297 self._cpp_impl_includes.add('DOMWindow') | |
291 arguments.append('document') | 298 arguments.append('document') |
292 create_function = 'createForJSConstructor' | 299 create_function = 'createForJSConstructor' |
293 if 'CallWith' in self._interface.ext_attrs: | 300 if 'CallWith' in self._interface.ext_attrs: |
294 call_with = self._interface.ext_attrs['CallWith'] | 301 call_with = self._interface.ext_attrs['CallWith'] |
295 if call_with == 'ScriptExecutionContext': | 302 if call_with == 'ScriptExecutionContext': |
296 raises_dart_exceptions = True | 303 raises_dart_exceptions = True |
297 parameter_definitions_emitter.Emit( | 304 parameter_definitions_emitter.Emit( |
298 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' | 305 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' |
299 ' if (!context) {\n' | 306 ' if (!context) {\n' |
300 ' exception = Dart_NewString("Failed to create an object" );\n' | 307 ' exception = Dart_NewString("Failed to create an object" );\n' |
(...skipping 28 matching lines...) Expand all Loading... | |
329 self._dart_impl_emitter.Emit( | 336 self._dart_impl_emitter.Emit( |
330 self._templates.Load('dart_implementation.darttemplate'), | 337 self._templates.Load('dart_implementation.darttemplate'), |
331 CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id, | 338 CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id, |
332 MEMBERS=self._members_emitter.Fragments()) | 339 MEMBERS=self._members_emitter.Fragments()) |
333 | 340 |
334 self._GenerateCppHeader() | 341 self._GenerateCppHeader() |
335 | 342 |
336 self._cpp_impl_emitter.Emit( | 343 self._cpp_impl_emitter.Emit( |
337 self._templates.Load('cpp_implementation.template'), | 344 self._templates.Load('cpp_implementation.template'), |
338 INTERFACE=self._interface.id, | 345 INTERFACE=self._interface.id, |
339 INCLUDES=''.join(['#include "%s.h"\n' % | 346 INCLUDES=_GenerateCPPIncludes(self._cpp_impl_includes), |
340 k for k in self._cpp_impl_includes.keys()]), | |
341 CALLBACKS=self._cpp_definitions_emitter.Fragments(), | 347 CALLBACKS=self._cpp_definitions_emitter.Fragments(), |
342 RESOLVER=self._cpp_resolver_emitter.Fragments()) | 348 RESOLVER=self._cpp_resolver_emitter.Fragments()) |
343 | 349 |
344 def _GenerateCppHeader(self): | 350 def _GenerateCppHeader(self): |
345 webcore_include = self._interface_type_info.webcore_include() | 351 webcore_includes = _GenerateCPPIncludes(self._interface_type_info.webcore_in cludes()) |
346 if webcore_include: | |
347 webcore_include = '#include "%s.h"\n' % webcore_include | |
348 else: | |
349 webcore_include = '' | |
350 | 352 |
351 if ('CustomToJS' in self._interface.ext_attrs or | 353 if ('CustomToJS' in self._interface.ext_attrs or |
352 'CustomToJSObject' in self._interface.ext_attrs or | 354 'CustomToJSObject' in self._interface.ext_attrs or |
353 'PureInterface' in self._interface.ext_attrs or | 355 'PureInterface' in self._interface.ext_attrs or |
354 'CPPPureInterface' in self._interface.ext_attrs or | 356 'CPPPureInterface' in self._interface.ext_attrs or |
355 self._interface_type_info.custom_to_dart()): | 357 self._interface_type_info.custom_to_dart()): |
356 to_dart_value_template = ( | 358 to_dart_value_template = ( |
357 'Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value);\n') | 359 'Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value);\n') |
358 else: | 360 else: |
359 to_dart_value_template = ( | 361 to_dart_value_template = ( |
360 'inline Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value)\n' | 362 'inline Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value)\n' |
361 '{\n' | 363 '{\n' |
362 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' | 364 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' |
363 '}\n') | 365 '}\n') |
364 to_dart_value_emitter = emitter.Emitter() | 366 to_dart_value_emitter = emitter.Emitter() |
365 to_dart_value_emitter.Emit( | 367 to_dart_value_emitter.Emit( |
366 to_dart_value_template, | 368 to_dart_value_template, |
367 INTERFACE=self._interface.id, | 369 INTERFACE=self._interface.id, |
368 WEBCORE_CLASS_NAME=self._interface_type_info.native_type()) | 370 WEBCORE_CLASS_NAME=self._interface_type_info.native_type()) |
369 | 371 |
370 self._cpp_header_emitter.Emit( | 372 self._cpp_header_emitter.Emit( |
371 self._templates.Load('cpp_header.template'), | 373 self._templates.Load('cpp_header.template'), |
372 INTERFACE=self._interface.id, | 374 INTERFACE=self._interface.id, |
373 WEBCORE_INCLUDE=webcore_include, | 375 WEBCORE_INCLUDES=webcore_includes, |
374 ADDITIONAL_INCLUDES='', | |
375 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), | 376 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), |
376 TO_DART_VALUE=to_dart_value_emitter.Fragments(), | 377 TO_DART_VALUE=to_dart_value_emitter.Fragments(), |
377 DECLARATIONS=self._cpp_declarations_emitter.Fragments()) | 378 DECLARATIONS=self._cpp_declarations_emitter.Fragments()) |
378 | 379 |
379 def AddAttribute(self, getter, setter): | 380 def AddAttribute(self, getter, setter): |
380 # FIXME: Dartium does not support attribute event listeners. However, JS | 381 # FIXME: Dartium does not support attribute event listeners. However, JS |
381 # implementation falls back to them when addEventListener is not available. | 382 # implementation falls back to them when addEventListener is not available. |
382 # Make sure addEventListener is available in all EventTargets and remove | 383 # Make sure addEventListener is available in all EventTargets and remove |
383 # this check. | 384 # this check. |
384 if (getter or setter).type.id == 'EventListener': | 385 if (getter or setter).type.id == 'EventListener': |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 if 'CallWith' in operation.ext_attrs: | 577 if 'CallWith' in operation.ext_attrs: |
577 call_with = operation.ext_attrs['CallWith'] | 578 call_with = operation.ext_attrs['CallWith'] |
578 if call_with == 'ScriptExecutionContext': | 579 if call_with == 'ScriptExecutionContext': |
579 parameter_definitions_emitter.Emit( | 580 parameter_definitions_emitter.Emit( |
580 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' | 581 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' |
581 ' if (!context)\n' | 582 ' if (!context)\n' |
582 ' return;\n') | 583 ' return;\n') |
583 arguments.append('context') | 584 arguments.append('context') |
584 elif call_with == 'ScriptArguments|CallStack': | 585 elif call_with == 'ScriptArguments|CallStack': |
585 raises_dart_exceptions = True | 586 raises_dart_exceptions = True |
586 self._cpp_impl_includes['ScriptArguments'] = 1 | 587 self._cpp_impl_includes.add('DOMWindow') |
587 self._cpp_impl_includes['ScriptCallStack'] = 1 | 588 self._cpp_impl_includes.add('ScriptArguments') |
588 self._cpp_impl_includes['V8Proxy'] = 1 | 589 self._cpp_impl_includes.add('ScriptCallStack') |
589 self._cpp_impl_includes['v8'] = 1 | 590 self._cpp_impl_includes.add('V8Proxy') |
591 self._cpp_impl_includes.add('v8') | |
590 parameter_definitions_emitter.Emit( | 592 parameter_definitions_emitter.Emit( |
591 ' v8::HandleScope handleScope;\n' | 593 ' v8::HandleScope handleScope;\n' |
592 ' v8::Context::Scope scope(V8Proxy::mainWorldContext(DartUtil ities::domWindowForCurrentIsolate()->frame()));\n' | 594 ' v8::Context::Scope scope(V8Proxy::mainWorldContext(DartUtil ities::domWindowForCurrentIsolate()->frame()));\n' |
593 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $ INDEX);\n' | 595 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $ INDEX);\n' |
594 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::crea teScriptArguments(customArgument, exception));\n' | 596 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::crea teScriptArguments(customArgument, exception));\n' |
595 ' if (!scriptArguments)\n' | 597 ' if (!scriptArguments)\n' |
596 ' goto fail;\n' | 598 ' goto fail;\n' |
597 ' RefPtr<ScriptCallStack> scriptCallStack(DartUtilities::crea teScriptCallStack());\n' | 599 ' RefPtr<ScriptCallStack> scriptCallStack(DartUtilities::crea teScriptCallStack());\n' |
598 ' if (!scriptCallStack->size())\n' | 600 ' if (!scriptCallStack->size())\n' |
599 ' return;\n', | 601 ' return;\n', |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
668 ' DartApiScope dartApiScope;\n' | 670 ' DartApiScope dartApiScope;\n' |
669 '$BODY' | 671 '$BODY' |
670 '}\n', | 672 '}\n', |
671 CALLBACK_NAME=callback_name, | 673 CALLBACK_NAME=callback_name, |
672 BODY=body) | 674 BODY=body) |
673 | 675 |
674 def _GenerateParameterAdapter(self, emitter, idl_argument, index): | 676 def _GenerateParameterAdapter(self, emitter, idl_argument, index): |
675 type_info = GetIDLTypeInfo(idl_argument.type) | 677 type_info = GetIDLTypeInfo(idl_argument.type) |
676 (adapter_type, include_name) = type_info.parameter_adapter_info() | 678 (adapter_type, include_name) = type_info.parameter_adapter_info() |
677 if include_name: | 679 if include_name: |
678 self._cpp_impl_includes[include_name] = 1 | 680 self._cpp_impl_includes.add(include_name) |
679 flags = '' | 681 flags = '' |
680 if (idl_argument.ext_attrs.get('Optional') == 'DefaultIsNullString' or | 682 if (idl_argument.ext_attrs.get('Optional') == 'DefaultIsNullString' or |
681 ('Optional' in idl_argument.ext_attrs and 'Callback' in idl_argument.ext _attrs)): | 683 ('Optional' in idl_argument.ext_attrs and 'Callback' in idl_argument.ext _attrs)): |
682 flags = ', DartUtilities::ConvertNullToDefaultValue' | 684 flags = ', DartUtilities::ConvertNullToDefaultValue' |
683 emitter.Emit( | 685 emitter.Emit( |
684 '\n' | 686 '\n' |
685 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n' | 687 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n' |
686 ' if (!$NAME.conversionSuccessful()) {\n' | 688 ' if (!$NAME.conversionSuccessful()) {\n' |
687 ' exception = $NAME.exception();\n' | 689 ' exception = $NAME.exception();\n' |
688 ' goto fail;\n' | 690 ' goto fail;\n' |
(...skipping 28 matching lines...) Expand all Loading... | |
717 | 719 |
718 return cpp_callback_name | 720 return cpp_callback_name |
719 | 721 |
720 def _GenerateWebCoreReflectionAttributeName(self, attr): | 722 def _GenerateWebCoreReflectionAttributeName(self, attr): |
721 namespace = 'HTMLNames' | 723 namespace = 'HTMLNames' |
722 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', | 724 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', |
723 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', | 725 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', |
724 'onmouseup', 'onresize', 'onscroll', 'onunload'] | 726 'onmouseup', 'onresize', 'onscroll', 'onunload'] |
725 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: | 727 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: |
726 namespace = 'SVGNames' | 728 namespace = 'SVGNames' |
727 self._cpp_impl_includes[namespace] = 1 | 729 self._cpp_impl_includes.add(namespace) |
728 | 730 |
729 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() | 731 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() |
730 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) | 732 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) |
731 | 733 |
732 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node): | 734 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node): |
733 if 'ImplementedBy' in idl_node.ext_attrs: | 735 if 'ImplementedBy' in idl_node.ext_attrs: |
734 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) | 736 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) |
735 return '%s%s' % (self._interface_type_info.receiver(), function_name) | 737 return '%s%s' % (self._interface_type_info.receiver(), function_name) |
736 | 738 |
737 def _GenerateWebCoreInvocation(self, function_expression, arguments, | 739 def _GenerateWebCoreInvocation(self, function_expression, arguments, |
738 idl_return_type, attributes, raises_dom_exceptions): | 740 idl_return_type, attributes, raises_dom_exceptions): |
739 invocation_template = ' $FUNCTION_CALL;\n' | 741 invocation_template = ' $FUNCTION_CALL;\n' |
740 if idl_return_type and idl_return_type.id != 'void': | 742 if idl_return_type and idl_return_type.id != 'void': |
741 return_type_info = GetIDLTypeInfo(idl_return_type) | 743 return_type_info = GetIDLTypeInfo(idl_return_type) |
742 if return_type_info.conversion_include(): | 744 self._cpp_impl_includes |= set(return_type_info.conversion_includes()) |
antonm
2012/03/01 15:44:50
ditto
| |
743 self._cpp_impl_includes[return_type_info.conversion_include()] = 1 | |
744 | 745 |
745 # Generate C++ cast based on idl return type. | 746 # Generate C++ cast based on idl return type. |
746 conversion_cast = return_type_info.conversion_cast('$FUNCTION_CALL') | 747 conversion_cast = return_type_info.conversion_cast('$FUNCTION_CALL') |
747 if isinstance(return_type_info, SVGTearOffIDLTypeInfo): | 748 if isinstance(return_type_info, SVGTearOffIDLTypeInfo): |
748 svg_primitive_types = ['SVGAngle', 'SVGLength', 'SVGMatrix', | 749 svg_primitive_types = ['SVGAngle', 'SVGLength', 'SVGMatrix', |
749 'SVGNumber', 'SVGPoint', 'SVGRect', 'SVGTransform'] | 750 'SVGNumber', 'SVGPoint', 'SVGRect', 'SVGTransform'] |
750 conversion_cast = '%s::create($FUNCTION_CALL)' | 751 conversion_cast = '%s::create($FUNCTION_CALL)' |
751 if self._interface.id.startswith('SVGAnimated'): | 752 if self._interface.id.startswith('SVGAnimated'): |
752 conversion_cast = 'static_cast<%s*>($FUNCTION_CALL)' | 753 conversion_cast = 'static_cast<%s*>($FUNCTION_CALL)' |
753 elif return_type_info.idl_type() == 'SVGStringList': | 754 elif return_type_info.idl_type() == 'SVGStringList': |
(...skipping 25 matching lines...) Expand all Loading... | |
779 ' ExceptionCode ec = 0;\n' | 780 ' ExceptionCode ec = 0;\n' |
780 '$INVOCATION' | 781 '$INVOCATION' |
781 ' if (UNLIKELY(ec)) {\n' | 782 ' if (UNLIKELY(ec)) {\n' |
782 ' exception = DartDOMWrapper::exceptionCodeToDartException( ec);\n' | 783 ' exception = DartDOMWrapper::exceptionCodeToDartException( ec);\n' |
783 ' goto fail;\n' | 784 ' goto fail;\n' |
784 ' }\n', | 785 ' }\n', |
785 INVOCATION=invocation_template) | 786 INVOCATION=invocation_template) |
786 | 787 |
787 if 'ImplementedBy' in attributes: | 788 if 'ImplementedBy' in attributes: |
788 arguments.insert(0, 'receiver') | 789 arguments.insert(0, 'receiver') |
789 self._cpp_impl_includes[attributes['ImplementedBy']] = 1 | 790 self._cpp_impl_includes.add(attributes['ImplementedBy']) |
790 | 791 |
791 return emitter.Format(invocation_template, | 792 return emitter.Format(invocation_template, |
792 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) | 793 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) |
794 | |
795 def _GenerateCPPIncludes(includes): | |
796 return ''.join(['#include "%s.h"\n' % include for include in includes]) | |
OLD | NEW |