| OLD | NEW |
| (Empty) |
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | |
| 2 # | |
| 3 # Redistribution and use in source and binary forms, with or without | |
| 4 # modification, are permitted provided that the following conditions are | |
| 5 # met: | |
| 6 # | |
| 7 # * Redistributions of source code must retain the above copyright | |
| 8 # notice, this list of conditions and the following disclaimer. | |
| 9 # * Redistributions in binary form must reproduce the above | |
| 10 # copyright notice, this list of conditions and the following disclaimer | |
| 11 # in the documentation and/or other materials provided with the | |
| 12 # distribution. | |
| 13 # * Neither the name of Google Inc. nor the names of its | |
| 14 # contributors may be used to endorse or promote products derived from | |
| 15 # this software without specific prior written permission. | |
| 16 # | |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 28 | |
| 29 """Generate template values for an interface.""" | |
| 30 | |
| 31 import v8_attributes | |
| 32 from v8_utilities import cpp_class_name, runtime_enable_function_name, v8_class_
name | |
| 33 | |
| 34 | |
| 35 INTERFACE_H_INCLUDES = set([ | |
| 36 'bindings/v8/V8Binding.h', | |
| 37 'bindings/v8/V8DOMWrapper.h', # FIXME: necessary? | |
| 38 'bindings/v8/WrapperTypeInfo.h', # FIXME: necessary? | |
| 39 ]) | |
| 40 INTERFACE_CPP_INCLUDES = set([ | |
| 41 'RuntimeEnabledFeatures.h', | |
| 42 'bindings/v8/ScriptController.h', | |
| 43 'bindings/v8/V8Binding.h', | |
| 44 'bindings/v8/V8DOMConfiguration.h', # FIXME: necessary? | |
| 45 'bindings/v8/V8DOMWrapper.h', # FIXME: necessary? | |
| 46 'core/dom/ContextFeatures.h', | |
| 47 'core/dom/Document.h', | |
| 48 'core/platform/chromium/TraceEvent.h', | |
| 49 'wtf/UnusedParam.h', | |
| 50 ]) | |
| 51 | |
| 52 | |
| 53 def generate_interface(interface): | |
| 54 header_includes = INTERFACE_H_INCLUDES | |
| 55 cpp_includes = INTERFACE_CPP_INCLUDES | |
| 56 | |
| 57 template_contents = { | |
| 58 'interface_name': interface.name, | |
| 59 'cpp_class_name': cpp_class_name(interface), | |
| 60 'v8_class_name': v8_class_name(interface), | |
| 61 'constants': [generate_constant(constant) for constant in interface.cons
tants], | |
| 62 'do_not_check_constants': 'DoNotCheckConstants' in interface.extended_at
tributes, | |
| 63 # Includes are modified in-place after generating members | |
| 64 'header_includes': header_includes, | |
| 65 'cpp_includes': cpp_includes, | |
| 66 } | |
| 67 attributes_contents, attributes_includes = v8_attributes.generate_attributes
(interface) | |
| 68 template_contents.update(attributes_contents) | |
| 69 cpp_includes |= attributes_includes | |
| 70 return template_contents | |
| 71 | |
| 72 | |
| 73 def generate_constant(constant): | |
| 74 # Extended Attributes: DeprecateAs, EnabledAtRuntime, Reflect | |
| 75 # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted | |
| 76 # in C++. | |
| 77 if constant.data_type == 'DOMString': | |
| 78 value = '"%s"' % constant.value | |
| 79 else: | |
| 80 value = constant.value | |
| 81 reflected_name = constant.extended_attributes.get('Reflect', constant.name) | |
| 82 | |
| 83 enabled_at_runtime = 'EnabledAtRuntime' in constant.extended_attributes | |
| 84 constant_parameter = { | |
| 85 'name': constant.name, | |
| 86 # FIXME: use 'reflected_name' as correct 'name' | |
| 87 'reflected_name': reflected_name, | |
| 88 'value': value, | |
| 89 'enabled_at_runtime': enabled_at_runtime, | |
| 90 'runtime_enable_function_name': runtime_enable_function_name(constant) i
f enabled_at_runtime else None, | |
| 91 } | |
| 92 return constant_parameter | |
| OLD | NEW |