| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 FIXME: Not currently used in build. | 31 FIXME: Not currently used in build. |
| 32 This is a rewrite of the Perl IDL compiler in Python, but is not complete. | 32 This is a rewrite of the Perl IDL compiler in Python, but is not complete. |
| 33 Once it is complete, we will switch all IDL files over to Python at once. | 33 Once it is complete, we will switch all IDL files over to Python at once. |
| 34 Until then, please work on the Perl IDL compiler. | 34 Until then, please work on the Perl IDL compiler. |
| 35 For details, see bug http://crbug.com/239771 | 35 For details, see bug http://crbug.com/239771 |
| 36 """ | 36 """ |
| 37 | 37 |
| 38 import v8_types | 38 import v8_types |
| 39 import v8_utilities | 39 import v8_utilities |
| 40 from v8_utilities import cpp_method_name, generate_conditional_string, uncapital
ize | 40 from v8_utilities import generate_conditional_string, uncapitalize |
| 41 | 41 |
| 42 | 42 |
| 43 def generate_attributes(interface): | 43 def generate_attributes(interface): |
| 44 def generate_attribute(attribute): | 44 def generate_attribute(attribute): |
| 45 attribute_contents, attribute_includes = generate_attribute_and_includes
(attribute) | 45 attribute_contents, attribute_includes = generate_attribute_and_includes
(interface, attribute) |
| 46 includes.update(attribute_includes) | 46 includes.update(attribute_includes) |
| 47 return attribute_contents | 47 return attribute_contents |
| 48 | 48 |
| 49 includes = set() | 49 includes = set() |
| 50 contents = generate_attributes_common(interface) | 50 contents = generate_attributes_common(interface) |
| 51 contents['attributes'] = [generate_attribute(attribute) for attribute in int
erface.attributes] | 51 contents['attributes'] = [generate_attribute(attribute) for attribute in int
erface.attributes] |
| 52 return contents, includes | 52 return contents, includes |
| 53 | 53 |
| 54 | 54 |
| 55 def generate_attributes_common(interface): | 55 def generate_attributes_common(interface): |
| 56 attributes = interface.attributes | 56 attributes = interface.attributes |
| 57 v8_class_name = v8_utilities.v8_class_name(interface) | 57 v8_class_name = v8_utilities.v8_class_name(interface) |
| 58 return { | 58 return { |
| 59 # Size 0 constant array is not allowed in VC++ | 59 # Size 0 constant array is not allowed in VC++ |
| 60 'number_of_attributes': 'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class_name
if attributes else '0', | 60 'number_of_attributes': 'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class_name
if attributes else '0', |
| 61 'attribute_templates': '%sAttributes' % v8_class_name if attributes else
'0', | 61 'attribute_templates': '%sAttributes' % v8_class_name if attributes else
'0', |
| 62 } | 62 } |
| 63 | 63 |
| 64 | 64 |
| 65 def generate_attribute_and_includes(attribute): | 65 def generate_attribute_and_includes(interface, attribute): |
| 66 idl_type = attribute.data_type | 66 idl_type = attribute.data_type |
| 67 this_getter_name = getter_name(interface, attribute) |
| 68 cpp_value = '%s()' % this_getter_name |
| 67 this_is_keep_alive_for_gc = is_keep_alive_for_gc(attribute) | 69 this_is_keep_alive_for_gc = is_keep_alive_for_gc(attribute) |
| 68 contents = { | 70 contents = { |
| 71 'conditional_string': generate_conditional_string(attribute), |
| 72 'cpp_type': v8_types.cpp_type(idl_type), |
| 73 'cpp_value': cpp_value, |
| 74 'is_keep_alive_for_gc': this_is_keep_alive_for_gc, |
| 75 'is_static': attribute.is_static, |
| 69 'name': attribute.name, | 76 'name': attribute.name, |
| 70 'conditional_string': generate_conditional_string(attribute), | |
| 71 'cpp_method_name': cpp_method_name(attribute), | |
| 72 'cpp_type': v8_types.cpp_type(idl_type), | |
| 73 'is_keep_alive_for_gc': this_is_keep_alive_for_gc, | |
| 74 'v8_type': v8_types.v8_type(idl_type), | 77 'v8_type': v8_types.v8_type(idl_type), |
| 75 } | 78 } |
| 76 if this_is_keep_alive_for_gc: | 79 if this_is_keep_alive_for_gc: |
| 77 includes = v8_types.includes_for_type(idl_type) | 80 includes = v8_types.includes_for_type(idl_type) |
| 78 includes.add('bindings/v8/V8HiddenPropertyName.h') | 81 includes.add('bindings/v8/V8HiddenPropertyName.h') |
| 79 else: | 82 else: |
| 80 cpp_value = 'imp->%s()' % uncapitalize(attribute.name) | |
| 81 return_v8_value_statement, includes = v8_types.v8_set_return_value(idl_t
ype, cpp_value, callback_info='info', isolate='info.GetIsolate()', extended_attr
ibutes=attribute.extended_attributes, script_wrappable='imp') | 83 return_v8_value_statement, includes = v8_types.v8_set_return_value(idl_t
ype, cpp_value, callback_info='info', isolate='info.GetIsolate()', extended_attr
ibutes=attribute.extended_attributes, script_wrappable='imp') |
| 82 contents['return_v8_value_statement'] = return_v8_value_statement | 84 contents['return_v8_value_statement'] = return_v8_value_statement |
| 83 return contents, includes | 85 return contents, includes |
| 84 | 86 |
| 85 | 87 |
| 88 def getter_name(interface, attribute): |
| 89 getter_method_name = uncapitalize(attribute.name) |
| 90 if attribute.is_static: |
| 91 return '%s::%s' % (interface.name, getter_method_name) |
| 92 return 'imp->%s' % getter_method_name |
| 93 |
| 94 |
| 86 def is_keep_alive_for_gc(attribute): | 95 def is_keep_alive_for_gc(attribute): |
| 87 idl_type = attribute.data_type | 96 idl_type = attribute.data_type |
| 88 extended_attributes = attribute.extended_attributes | 97 extended_attributes = attribute.extended_attributes |
| 89 return ( | 98 return ( |
| 90 'KeepAttributeAliveForGC' in extended_attributes or | 99 'KeepAttributeAliveForGC' in extended_attributes or |
| 91 # For readonly attributes, for performance reasons we keep the attribute | 100 # For readonly attributes, for performance reasons we keep the attribute |
| 92 # wrapper alive while the owner wrapper is alive, because the attribute | 101 # wrapper alive while the owner wrapper is alive, because the attribute |
| 93 # never changes. | 102 # never changes. |
| 94 (attribute.is_read_only and | 103 (attribute.is_read_only and |
| 95 v8_types.wrapper_type(idl_type) and | 104 v8_types.wrapper_type(idl_type) and |
| 96 # There are some exceptions, however: | 105 # There are some exceptions, however: |
| 97 not( | 106 not( |
| 98 # Node lifetime is managed by object grouping. | 107 # Node lifetime is managed by object grouping. |
| 99 v8_types.dom_node_type(idl_type) or | 108 v8_types.dom_node_type(idl_type) or |
| 100 # A self-reference is unnecessary. | 109 # A self-reference is unnecessary. |
| 101 attribute.name == 'self' or | 110 attribute.name == 'self' or |
| 102 # FIXME: Remove these hard-coded hacks. | 111 # FIXME: Remove these hard-coded hacks. |
| 103 idl_type in ['SerializedScriptValue', 'Window'] or | 112 idl_type in ['SerializedScriptValue', 'Window'] or |
| 104 idl_type.startswith('HTML')))) | 113 idl_type.startswith('HTML')))) |
| OLD | NEW |