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

Side by Side Diff: client/dom/scripts/systemnative.py

Issue 9480001: Support named ctors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
« no previous file with comments | « no previous file | client/dom/src/native_FactoryProvidersImplementation.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 self._cpp_declarations_emitter.Emit( 272 self._cpp_declarations_emitter.Emit(
273 '\n' 273 '\n'
274 'void constructorCallback(Dart_NativeArguments);\n') 274 'void constructorCallback(Dart_NativeArguments);\n')
275 return 275 return
276 276
277 raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_ attrs 277 raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_ attrs
278 raises_dart_exceptions = raises_dom_exceptions or len(constructor_info.idl_a rgs) > 0 278 raises_dart_exceptions = raises_dom_exceptions or len(constructor_info.idl_a rgs) > 0
279 type_info = GetIDLTypeInfo(self._interface) 279 type_info = GetIDLTypeInfo(self._interface)
280 arguments = [] 280 arguments = []
281 parameter_definitions_emitter = emitter.Emitter() 281 parameter_definitions_emitter = emitter.Emitter()
282 create_function = 'create'
283 if 'NamedConstructor' in self._interface.ext_attrs:
284 raises_dart_exceptions = True
285 parameter_definitions_emitter.Emit(
286 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIs olate();\n'
287 ' if (!domWindow) {\n'
288 ' exception = Dart_NewString("Failed to fetch domWindow") ;\n'
289 ' goto fail;\n'
290 ' }\n'
291 ' Document* document = domWindow->document();\n')
podivilov 2012/02/27 15:53:48 Our constructors seems to be very simple comparing
antonm 2012/02/27 15:59:36 I am not sure. For example, I am not sure they re
292 arguments.append('document')
293 create_function = 'createForJSConstructor'
282 if 'CallWith' in self._interface.ext_attrs: 294 if 'CallWith' in self._interface.ext_attrs:
283 call_with = self._interface.ext_attrs['CallWith'] 295 call_with = self._interface.ext_attrs['CallWith']
284 if call_with == 'ScriptExecutionContext': 296 if call_with == 'ScriptExecutionContext':
285 raises_dart_exceptions = True 297 raises_dart_exceptions = True
286 parameter_definitions_emitter.Emit( 298 parameter_definitions_emitter.Emit(
287 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' 299 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n'
288 ' if (!context) {\n' 300 ' if (!context) {\n'
289 ' exception = Dart_NewString("Failed to create an object" );\n' 301 ' exception = Dart_NewString("Failed to create an object" );\n'
290 ' goto fail;\n' 302 ' goto fail;\n'
291 ' }\n') 303 ' }\n')
292 arguments.append('context') 304 arguments.append('context')
293 else: 305 else:
294 raise Exception('Unsupported CallWith=%s attribute' % call_with) 306 raise Exception('Unsupported CallWith=%s attribute' % call_with)
295 307
296 # Process constructor arguments. 308 # Process constructor arguments.
297 for (i, arg) in enumerate(constructor_info.idl_args): 309 for (i, arg) in enumerate(constructor_info.idl_args):
298 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1) 310 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1)
299 arguments.append(arg.id) 311 arguments.append(arg.id)
300 312
301 self._GenerateNativeCallback( 313 self._GenerateNativeCallback(
302 callback_name='constructorCallback', 314 callback_name='constructorCallback',
303 idl_node=self._interface, 315 idl_node=self._interface,
304 parameter_definitions=parameter_definitions_emitter.Fragments(), 316 parameter_definitions=parameter_definitions_emitter.Fragments(),
305 needs_receiver=False, function_name='%s::create' % type_info.native_type (), 317 needs_receiver=False, function_name='%s::%s' % (type_info.native_type(), create_function),
306 arguments=arguments, 318 arguments=arguments,
307 idl_return_type=self._interface, 319 idl_return_type=self._interface,
308 raises_dart_exceptions=raises_dart_exceptions, 320 raises_dart_exceptions=raises_dart_exceptions,
309 raises_dom_exceptions=raises_dom_exceptions) 321 raises_dom_exceptions=raises_dom_exceptions)
310 322
311 323
312 def _ImplClassName(self, interface_name): 324 def _ImplClassName(self, interface_name):
313 return interface_name + 'Implementation' 325 return interface_name + 'Implementation'
314 326
315 def _IsConstructable(self): 327 def _IsConstructable(self):
316 # FIXME: support ConstructorTemplate. 328 # FIXME: support ConstructorTemplate.
317 # FIXME: support NamedConstructor. 329 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name dConstructor']) & set(self._interface.ext_attrs)
318 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor']) & se t(self._interface.ext_attrs)
319 330
320 def FinishInterface(self): 331 def FinishInterface(self):
321 base = self._BaseClassName(self._interface) 332 base = self._BaseClassName(self._interface)
322 self._dart_impl_emitter.Emit( 333 self._dart_impl_emitter.Emit(
323 self._templates.Load('dart_implementation.darttemplate'), 334 self._templates.Load('dart_implementation.darttemplate'),
324 CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id, 335 CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id,
325 MEMBERS=self._members_emitter.Fragments()) 336 MEMBERS=self._members_emitter.Fragments())
326 337
327 self._GenerateCppHeader() 338 self._GenerateCppHeader()
328 339
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 callback = emitter.Format(template, **template_parameters) 740 callback = emitter.Format(template, **template_parameters)
730 741
731 self._cpp_definitions_emitter.Emit(callback) 742 self._cpp_definitions_emitter.Emit(callback)
732 743
733 def _GenerateParameterAdapter(self, emitter, idl_argument, index): 744 def _GenerateParameterAdapter(self, emitter, idl_argument, index):
734 type_info = GetIDLTypeInfo(idl_argument.type) 745 type_info = GetIDLTypeInfo(idl_argument.type)
735 (adapter_type, include_name) = type_info.parameter_adapter_info() 746 (adapter_type, include_name) = type_info.parameter_adapter_info()
736 if include_name: 747 if include_name:
737 self._cpp_impl_includes[include_name] = 1 748 self._cpp_impl_includes[include_name] = 1
738 flags = '' 749 flags = ''
739 if idl_argument.ext_attrs.get('Optionial') == 'DefaultIsNullString': 750 if idl_argument.ext_attrs.get('Optional') == 'DefaultIsNullString':
podivilov 2012/02/27 15:53:48 This code is not actually used, do we really want
antonm 2012/02/27 15:59:36 Why it's not used? It's need, e.g., to make (most
podivilov 2012/02/27 16:59:49 Ok, seems like it is used for constructor paramete
740 flags = ', DartUtilities::ConvertNullToEmptyString' 751 flags = ', DartUtilities::ConvertNullToEmptyString'
741 emitter.Emit( 752 emitter.Emit(
742 '\n' 753 '\n'
743 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n' 754 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n'
744 ' if (!$NAME.conversionSuccessful()) {\n' 755 ' if (!$NAME.conversionSuccessful()) {\n'
745 ' exception = $NAME.exception();\n' 756 ' exception = $NAME.exception();\n'
746 ' goto fail;\n' 757 ' goto fail;\n'
747 ' }\n', 758 ' }\n',
748 ADAPTER_TYPE=adapter_type, 759 ADAPTER_TYPE=adapter_type,
749 NAME=idl_argument.id, 760 NAME=idl_argument.id,
(...skipping 29 matching lines...) Expand all
779 namespace = 'HTMLNames' 790 namespace = 'HTMLNames'
780 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', 791 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload',
781 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', 792 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover',
782 'onmouseup', 'onresize', 'onscroll', 'onunload'] 793 'onmouseup', 'onresize', 'onscroll', 'onunload']
783 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: 794 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions:
784 namespace = 'SVGNames' 795 namespace = 'SVGNames'
785 self._cpp_impl_includes[namespace] = 1 796 self._cpp_impl_includes[namespace] = 1
786 797
787 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() 798 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower()
788 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) 799 return 'WebCore::%s::%sAttr' % (namespace, attribute_name)
OLDNEW
« no previous file with comments | « no previous file | client/dom/src/native_FactoryProvidersImplementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698