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

Side by Side Diff: Source/bindings/scripts/unstable/v8_interface.py

Issue 112303003: IDL compiler: [Constructor] overloading (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Better test case Created 7 years 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
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 # [SpecialWrapFor] 88 # [SpecialWrapFor]
89 if 'SpecialWrapFor' in extended_attributes: 89 if 'SpecialWrapFor' in extended_attributes:
90 special_wrap_for = extended_attributes['SpecialWrapFor'].split('|') 90 special_wrap_for = extended_attributes['SpecialWrapFor'].split('|')
91 else: 91 else:
92 special_wrap_for = [] 92 special_wrap_for = []
93 for special_wrap_interface in special_wrap_for: 93 for special_wrap_interface in special_wrap_for:
94 v8_types.add_includes_for_type(special_wrap_interface) 94 v8_types.add_includes_for_type(special_wrap_interface)
95 95
96 # Constructors 96 # Constructors
97 # [Constructor] 97 constructors = [generate_constructor(interface, constructor)
98 has_constructor = 'Constructor' in extended_attributes 98 for constructor in interface.constructors]
99 if has_constructor: 99 generate_constructor_overloads(constructors)
100 if constructors:
100 includes.add('bindings/v8/V8ObjectConstructor.h') 101 includes.add('bindings/v8/V8ObjectConstructor.h')
101 102
102 # [EventConstructor] 103 # [EventConstructor]
103 has_event_constructor = 'EventConstructor' in extended_attributes 104 has_event_constructor = 'EventConstructor' in extended_attributes
104 any_type_attributes = [attribute for attribute in interface.attributes 105 any_type_attributes = [attribute for attribute in interface.attributes
105 if attribute.idl_type == 'any'] 106 if attribute.idl_type == 'any']
106 if has_event_constructor: 107 if has_event_constructor:
107 includes.update(['bindings/v8/Dictionary.h', 108 includes.update(['bindings/v8/Dictionary.h',
108 'bindings/v8/V8ObjectConstructor.h']) 109 'bindings/v8/V8ObjectConstructor.h'])
109 if any_type_attributes: 110 if any_type_attributes:
110 includes.add('bindings/v8/SerializedScriptValue.h') 111 includes.add('bindings/v8/SerializedScriptValue.h')
111 112
112 template_contents = { 113 template_contents = {
113 'any_type_attributes': any_type_attributes, 114 'any_type_attributes': any_type_attributes,
114 'conditional_string': conditional_string(interface), # [Conditional] 115 'conditional_string': conditional_string(interface), # [Conditional]
115 'constructor_argument_list': constructor_argument_list(interface), 116 'constructors': constructors,
116 'constructor_arguments': constructor_arguments(interface),
117 'constructor_method': {
118 'is_constructor': True,
119 },
120 'cpp_class': cpp_name(interface), 117 'cpp_class': cpp_name(interface),
121 'generate_visit_dom_wrapper_function': generate_visit_dom_wrapper_functi on, 118 'generate_visit_dom_wrapper_function': generate_visit_dom_wrapper_functi on,
122 'has_constructor': has_constructor,
123 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] 119 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction]
124 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'T oV8'), # [Custom=ToV8] 120 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'T oV8'), # [Custom=ToV8]
125 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wr ap'), # [Custom=Wrap] 121 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wr ap'), # [Custom=Wrap]
126 'has_event_constructor': has_event_constructor, 122 'has_event_constructor': has_event_constructor,
127 'has_visit_dom_wrapper': ( 123 'has_visit_dom_wrapper': (
128 # [Custom=Wrap], [GenerateVisitDOMWrapper] 124 # [Custom=Wrap], [GenerateVisitDOMWrapper]
129 has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or 125 has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or
130 'GenerateVisitDOMWrapper' in extended_attributes), 126 'GenerateVisitDOMWrapper' in extended_attributes),
131 'header_includes': header_includes, 127 'header_includes': header_includes,
132 'interface_length': interface_length(interface), 128 'interface_length': interface_length(interface, constructors),
133 'interface_name': interface.name, 129 'interface_name': interface.name,
134 'is_active_dom_object': 'ActiveDOMObject' in extended_attributes, # [Ac tiveDOMObject] 130 'is_active_dom_object': 'ActiveDOMObject' in extended_attributes, # [Ac tiveDOMObject]
135 'is_check_security': is_check_security, 131 'is_check_security': is_check_security,
136 'is_constructor_call_with_document': has_extended_attribute_value( 132 'is_constructor_call_with_document': has_extended_attribute_value(
137 interface, 'ConstructorCallWith', 'Document'), # [ConstructorCallWi th=Document] 133 interface, 'ConstructorCallWith', 'Document'), # [ConstructorCallWi th=Document]
138 'is_constructor_call_with_execution_context': has_extended_attribute_val ue( 134 'is_constructor_call_with_execution_context': has_extended_attribute_val ue(
139 interface, 'ConstructorCallWith', 'ExecutionContext'), # [Construct orCallWith=ExeuctionContext] 135 interface, 'ConstructorCallWith', 'ExecutionContext'), # [Construct orCallWith=ExeuctionContext]
140 'is_constructor_raises_exception': extended_attributes.get('RaisesExcept ion') == 'Constructor', # [RaisesException=Constructor] 136 'is_constructor_raises_exception': extended_attributes.get('RaisesExcept ion') == 'Constructor', # [RaisesException=Constructor]
141 'is_dependent_lifetime': 'DependentLifetime' in extended_attributes, # [DependentLifetime] 137 'is_dependent_lifetime': 'DependentLifetime' in extended_attributes, # [DependentLifetime]
142 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs] 138 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs]
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 if v8_types.is_wrapper_type(idl_type): 304 if v8_types.is_wrapper_type(idl_type):
309 type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate(), worldType(info.GetIsolate()))'.format(idl_type=idl_type, cpp_value=cpp_value) 305 type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate(), worldType(info.GetIsolate()))'.format(idl_type=idl_type, cpp_value=cpp_value)
310 if argument['is_nullable']: 306 if argument['is_nullable']:
311 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) 307 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check])
312 return type_check 308 return type_check
313 return None 309 return None
314 310
315 311
316 # Constructors 312 # Constructors
317 313
318 def constructor_argument_list(interface): 314 # [Constructor]
319 if not interface.constructors: 315 def generate_constructor(interface, constructor):
320 return [] 316 return {
321 constructor = interface.constructors[0] # FIXME: support overloading 317 'argument_list': constructor_argument_list(interface, constructor),
318 'arguments': [constructor_argument(argument, index)
319 for index, argument in enumerate(constructor.arguments)],
320 'is_constructor': True,
321 'is_variadic': False,
haraken 2013/12/13 10:23:31 Do we need to specify these, even though their val
Nils Barth (inactive) 2013/12/16 03:15:57 Added a comment; it's required for overload resolu
322 'number_of_required_arguments':
323 len([argument for argument in constructor.arguments
324 if not argument.is_optional]),
325 }
322 326
327
328 def constructor_argument_list(interface, constructor):
323 arguments = [] 329 arguments = []
324 # [ConstructorCallWith=ExecutionContext] 330 # [ConstructorCallWith=ExecutionContext]
325 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Execution Context'): 331 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Execution Context'):
326 arguments.append('context') 332 arguments.append('context')
327 # [ConstructorCallWith=Document] 333 # [ConstructorCallWith=Document]
328 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document' ): 334 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document' ):
329 arguments.append('document') 335 arguments.append('document')
330 336
331 arguments.extend([argument.name for argument in constructor.arguments]) 337 arguments.extend([argument.name for argument in constructor.arguments])
332 338
333 # [RaisesException=Constructor] 339 # [RaisesException=Constructor]
334 if interface.extended_attributes.get('RaisesException') == 'Constructor': 340 if interface.extended_attributes.get('RaisesException') == 'Constructor':
335 arguments.append('exceptionState') 341 arguments.append('exceptionState')
336 342
337 return arguments 343 return arguments
338 344
339 345
340 def constructor_arguments(interface):
341 if not interface.constructors:
342 return []
343 constructor = interface.constructors[0] # FIXME: support overloading
344 return [constructor_argument(argument, index)
345 for index, argument in enumerate(constructor.arguments)]
346
347
348 def constructor_argument(argument, index): 346 def constructor_argument(argument, index):
349 return { 347 return {
350 'idl_type': argument.idl_type, 348 'idl_type': argument.idl_type,
351 'index': index, 349 'index': index,
350 'is_nullable': False,
Nils Barth (inactive) 2013/12/13 07:04:16 Stubs for overload resolution.
351 'is_optional': argument.is_optional,
352 'is_strict_type_checking': False,
352 'name': argument.name, 353 'name': argument.name,
353 'v8_value_to_local_cpp_value': 354 'v8_value_to_local_cpp_value':
354 v8_methods.v8_value_to_local_cpp_value(argument, index), 355 v8_methods.v8_value_to_local_cpp_value(argument, index),
355 } 356 }
356 357
357 358
358 def interface_length(interface): 359 def generate_constructor_overloads(constructors):
360 if len(constructors) < 2:
haraken 2013/12/13 10:23:31 Nit: I'd prefer '<= 1'
Nils Barth (inactive) 2013/12/16 03:15:57 n/p, done.
361 return
362 for overload_index, constructor in enumerate(constructors):
363 constructor.update({
364 'overload_index': overload_index + 1,
365 'overload_resolution_expression':
366 overload_resolution_expression(constructor),
367 })
368
369
370 def interface_length(interface, constructors):
359 # Docs: http://heycam.github.io/webidl/#es-interface-call 371 # Docs: http://heycam.github.io/webidl/#es-interface-call
360 if 'EventConstructor' in interface.extended_attributes: 372 if 'EventConstructor' in interface.extended_attributes:
361 return 1 373 return 1
362 if not interface.constructors: 374 if not constructors:
363 return 0 375 return 0
364 constructor = interface.constructors[0] # FIXME: support overloading 376 return min(constructor['number_of_required_arguments']
365 return len([argument 377 for constructor in constructors)
366 for argument in constructor.arguments
367 if not argument.is_optional])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698