OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 """Generate template values for methods. | 29 """Generate template values for methods. |
30 | 30 |
31 Extends IdlType and IdlUnionType with property |union_arguments|. | 31 Extends IdlType and IdlUnionType with property |union_arguments|. |
32 | 32 |
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
34 """ | 34 """ |
35 | 35 |
36 from idl_types import IdlType, IdlUnionType, inherits_interface | 36 from idl_types import IdlTypeBase, IdlType, IdlUnionType, inherits_interface, Id
lArrayOrSequenceType, IdlArrayType |
37 import dart_types | 37 import dart_types |
| 38 from idl_definitions import IdlArgument |
38 from dart_utilities import DartUtilities | 39 from dart_utilities import DartUtilities |
39 from v8_globals import includes | 40 from v8_globals import includes |
40 | 41 |
41 | 42 |
42 def generate_method(interface, method): | 43 def generate_method(interface, method): |
43 arguments = method.arguments | 44 arguments = method.arguments |
44 extended_attributes = method.extended_attributes | 45 extended_attributes = method.extended_attributes |
45 idl_type = method.idl_type | 46 idl_type = method.idl_type |
46 is_static = method.is_static | 47 is_static = method.is_static |
47 name = method.name | 48 name = method.name |
48 | 49 |
49 idl_type.add_includes_for_type() | 50 idl_type.add_includes_for_type() |
50 this_cpp_value = cpp_value(interface, method, len(arguments)) | 51 this_cpp_value = cpp_value(interface, method, len(arguments)) |
51 | 52 |
52 def function_template(): | 53 def function_template(): |
53 if is_static: | 54 if is_static: |
54 return 'functionTemplate' | 55 return 'functionTemplate' |
55 if 'Unforgeable' in extended_attributes: | 56 if 'Unforgeable' in extended_attributes: |
56 return 'instanceTemplate' | 57 return 'instanceTemplate' |
57 return 'prototypeTemplate' | 58 return 'prototypeTemplate' |
58 | 59 |
59 is_call_with_script_arguments = DartUtilities.has_extended_attribute_value(m
ethod, 'CallWith', 'ScriptArguments') | 60 is_call_with_script_arguments = DartUtilities.has_extended_attribute_value(m
ethod, 'CallWith', 'ScriptArguments') |
60 if is_call_with_script_arguments: | 61 if is_call_with_script_arguments: |
61 includes.update(['bindings/v8/ScriptCallStackFactory.h', | 62 includes.update(['bindings/core/v8/ScriptCallStackFactory.h', |
62 'core/inspector/ScriptArguments.h']) | 63 'core/inspector/ScriptArguments.h']) |
63 is_call_with_script_state = DartUtilities.has_extended_attribute_value(metho
d, 'CallWith', 'ScriptState') | 64 is_call_with_script_state = DartUtilities.has_extended_attribute_value(metho
d, 'CallWith', 'ScriptState') |
64 if is_call_with_script_state: | 65 if is_call_with_script_state: |
65 includes.add('bindings/dart/DartScriptState.h') | 66 includes.add('bindings/core/dart/DartScriptState.h') |
66 is_check_security_for_node = 'CheckSecurity' in extended_attributes | 67 is_check_security_for_node = 'CheckSecurity' in extended_attributes |
67 if is_check_security_for_node: | 68 if is_check_security_for_node: |
68 includes.add('bindings/common/BindingSecurity.h') | 69 includes.add('bindings/common/BindingSecurity.h') |
69 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s | 70 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s |
70 if is_custom_element_callbacks: | 71 if is_custom_element_callbacks: |
71 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') | 72 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') |
72 | 73 |
73 has_event_listener_argument = any( | 74 has_event_listener_argument = any( |
74 argument for argument in arguments | 75 argument for argument in arguments |
75 if argument.idl_type.name == 'EventListener') | 76 if argument.idl_type.name == 'EventListener') |
76 is_check_security_for_frame = ( | 77 is_check_security_for_frame = ( |
77 'CheckSecurity' in interface.extended_attributes and | 78 'CheckSecurity' in interface.extended_attributes and |
78 'DoNotCheckSecurity' not in extended_attributes) | 79 'DoNotCheckSecurity' not in extended_attributes) |
79 is_raises_exception = 'RaisesException' in extended_attributes | 80 is_raises_exception = 'RaisesException' in extended_attributes |
80 | 81 |
81 if idl_type.union_arguments and len(idl_type.union_arguments) > 0: | 82 if idl_type.union_arguments and len(idl_type.union_arguments) > 0: |
82 this_cpp_type = [] | 83 this_cpp_type = [] |
83 for cpp_type in idl_type.member_types: | 84 for cpp_type in idl_type.member_types: |
| 85 # FIXMEDART: we shouldn't just assume RefPtr. We should append |
| 86 # WillBeGC as appropriate. |
84 this_cpp_type.append("RefPtr<%s>" % cpp_type) | 87 this_cpp_type.append("RefPtr<%s>" % cpp_type) |
85 else: | 88 else: |
86 this_cpp_type = idl_type.cpp_type | 89 this_cpp_type = idl_type.cpp_type |
87 | 90 |
88 is_auto_scope = not 'DartNoAutoScope' in extended_attributes | 91 is_auto_scope = not 'DartNoAutoScope' in extended_attributes |
89 | 92 |
90 number_of_arguments = len(arguments) | 93 number_of_arguments = len(arguments) |
91 | 94 |
92 number_of_required_arguments = \ | 95 number_of_required_arguments = \ |
93 len([ | 96 len([ |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 this_has_default = 'Default' in extended_attributes | 178 this_has_default = 'Default' in extended_attributes |
176 arg_index = index + 1 if not method.is_static else index | 179 arg_index = index + 1 if not method.is_static else index |
177 preprocessed_type = str(idl_type.preprocessed_type) | 180 preprocessed_type = str(idl_type.preprocessed_type) |
178 # FIXMEDART: handle the drift between preprocessed type names in 1847 and | 181 # FIXMEDART: handle the drift between preprocessed type names in 1847 and |
179 # 1985 dartium builds in a more generic way. | 182 # 1985 dartium builds in a more generic way. |
180 if preprocessed_type == 'unrestricted float': | 183 if preprocessed_type == 'unrestricted float': |
181 preprocessed_type = 'float' | 184 preprocessed_type = 'float' |
182 if preprocessed_type == 'unrestricted double': | 185 if preprocessed_type == 'unrestricted double': |
183 preprocessed_type = 'double' | 186 preprocessed_type = 'double' |
184 argument_data = { | 187 argument_data = { |
185 'cpp_type': idl_type.cpp_type_args(used_in_cpp_sequence=use_heap_vector_
type), | 188 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, |
| 189 raw_type=True, |
| 190 used_in_cpp_sequence=use_heap_vector_
type), |
186 'cpp_value': this_cpp_value, | 191 'cpp_value': this_cpp_value, |
187 'local_cpp_type': idl_type.cpp_type_args(argument.extended_attributes, u
sed_as_argument=True), | 192 'local_cpp_type': idl_type.cpp_type_args(argument.extended_attributes, r
aw_type=True), |
188 # FIXME: check that the default value's type is compatible with the argu
ment's | 193 # FIXME: check that the default value's type is compatible with the argu
ment's |
189 'default_value': str(argument.default_value) if argument.default_value e
lse None, | 194 'default_value': str(argument.default_value) if argument.default_value e
lse None, |
190 'enum_validation_expression': idl_type.enum_validation_expression, | 195 'enum_validation_expression': idl_type.enum_validation_expression, |
191 # Ignore 'Default' in extended_attributes not exposed in dart:html. | 196 # Ignore 'Default' in extended_attributes not exposed in dart:html. |
192 'has_default': False, | 197 'has_default': False, |
193 'has_event_listener_argument': any( | 198 'has_event_listener_argument': any( |
194 argument_so_far for argument_so_far in method.arguments[:index] | 199 argument_so_far for argument_so_far in method.arguments[:index] |
195 if argument_so_far.idl_type.name == 'EventListener'), | 200 if argument_so_far.idl_type.name == 'EventListener'), |
196 'idl_type_object': idl_type, | 201 'idl_type_object': idl_type, |
197 'preprocessed_type': preprocessed_type, | 202 'preprocessed_type': preprocessed_type, |
198 # Dictionary is special-cased, but arrays and sequences shouldn't be | 203 # Dictionary is special-cased, but arrays and sequences shouldn't be |
199 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, | 204 'idl_type': idl_type.base_type, |
200 'index': index, | 205 'index': index, |
201 'is_array_or_sequence_type': not not idl_type.array_or_sequence_type, | 206 'is_array_or_sequence_type': not not idl_type.native_array_element_type, |
202 'is_clamp': 'Clamp' in extended_attributes, | 207 'is_clamp': 'Clamp' in extended_attributes, |
203 'is_callback_interface': idl_type.is_callback_interface, | 208 'is_callback_interface': idl_type.is_callback_interface, |
204 'is_nullable': idl_type.is_nullable, | 209 'is_nullable': idl_type.is_nullable, |
205 # Only expose as optional if no default value. | 210 # Only expose as optional if no default value. |
206 'is_optional': argument.is_optional and not (this_has_default or argumen
t.default_value), | 211 'is_optional': argument.is_optional and not (this_has_default or argumen
t.default_value), |
207 'is_strict_type_checking': 'DartStrictTypeChecking' in extended_attribut
es, | 212 'is_strict_type_checking': 'DartStrictTypeChecking' in extended_attribut
es, |
208 'is_variadic_wrapper_type': is_variadic_wrapper_type, | 213 'is_variadic_wrapper_type': is_variadic_wrapper_type, |
209 'vector_type': 'WillBeHeapVector' if use_heap_vector_type else 'Vector', | 214 'vector_type': 'WillBeHeapVector' if use_heap_vector_type else 'Vector', |
210 'is_wrapper_type': idl_type.is_wrapper_type, | 215 'is_wrapper_type': idl_type.is_wrapper_type, |
211 'name': argument.name, | 216 'name': argument.name, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 property_attributes_list = [] | 336 property_attributes_list = [] |
332 if 'NotEnumerable' in extended_attributes: | 337 if 'NotEnumerable' in extended_attributes: |
333 property_attributes_list.append('v8::DontEnum') | 338 property_attributes_list.append('v8::DontEnum') |
334 if 'ReadOnly' in extended_attributes: | 339 if 'ReadOnly' in extended_attributes: |
335 property_attributes_list.append('v8::ReadOnly') | 340 property_attributes_list.append('v8::ReadOnly') |
336 if property_attributes_list: | 341 if property_attributes_list: |
337 property_attributes_list.insert(0, 'v8::DontDelete') | 342 property_attributes_list.insert(0, 'v8::DontDelete') |
338 return property_attributes_list | 343 return property_attributes_list |
339 | 344 |
340 | 345 |
| 346 # FIXMEDART: better align this method with the v8 version. |
| 347 def union_member_argument_context(idl_type, index): |
| 348 """Returns a context of union member for argument.""" |
| 349 return 'result%d' % index |
| 350 |
341 def union_arguments(idl_type): | 351 def union_arguments(idl_type): |
342 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u
nion types, for use in setting return value""" | 352 return [union_member_argument_context(member_idl_type, index) |
343 return [arg | 353 for index, member_idl_type |
344 for i in range(len(idl_type.member_types)) | 354 in enumerate(idl_type.member_types)] |
345 for arg in ['result%sEnabled' % i, 'result%s' % i]] | |
346 | 355 |
347 IdlType.union_arguments = property(lambda self: None) | 356 |
| 357 def argument_default_cpp_value(argument): |
| 358 if not argument.default_value: |
| 359 return None |
| 360 return argument.idl_type.literal_cpp_value(argument.default_value) |
| 361 |
| 362 |
| 363 IdlTypeBase.union_arguments = None |
348 IdlUnionType.union_arguments = property(union_arguments) | 364 IdlUnionType.union_arguments = property(union_arguments) |
| 365 IdlArgument.default_cpp_value = property(argument_default_cpp_value) |
| 366 #IdlType.union_arguments = property(lambda self: None) |
| 367 #IdlUnionType.union_arguments = property(union_arguments) |
OLD | NEW |